From 781a47ee12483acae3046b67211e98c09eeedbfa Mon Sep 17 00:00:00 2001 From: Harry Wray Date: Thu, 31 Oct 2024 11:16:21 -0400 Subject: [PATCH 01/29] Initial commit --- proto/dydxprotocol/perpetuals/tx.proto | 17 + protocol/x/clob/keeper/deleveraging.go | 19 + ...r_upgrade_market_from_isolated_to_cross.go | 67 +++ protocol/x/perpetuals/keeper/perpetual.go | 2 +- ...e_upgrade_market_from_isolated_to_cross.go | 25 + ...rade_market_from_isolated_to_cross_test.go | 39 ++ protocol/x/perpetuals/types/tx.pb.go | 454 ++++++++++++++++-- protocol/x/perpetuals/types/types.go | 4 + 8 files changed, 586 insertions(+), 41 deletions(-) create mode 100644 protocol/x/perpetuals/keeper/msg_server_upgrade_market_from_isolated_to_cross.go create mode 100644 protocol/x/perpetuals/types/message_upgrade_market_from_isolated_to_cross.go create mode 100644 protocol/x/perpetuals/types/message_upgrade_market_from_isolated_to_cross_test.go diff --git a/proto/dydxprotocol/perpetuals/tx.proto b/proto/dydxprotocol/perpetuals/tx.proto index 3a9847cd81..19e79c4f0d 100644 --- a/proto/dydxprotocol/perpetuals/tx.proto +++ b/proto/dydxprotocol/perpetuals/tx.proto @@ -25,6 +25,8 @@ service Msg { returns (MsgUpdatePerpetualParamsResponse); // UpdateParams updates the parameters of perpetuals module. rpc UpdateParams(MsgUpdateParams) returns (MsgUpdateParamsResponse); + // UpgradeMarketFromIsolatedToCross upgrades a perpetual from isolated to cross margin. + rpc UpgradeMarketFromIsolatedToCross(MsgUpgradeMarketFromIsolatedToCross) returns (MsgUpgradeMarketFromIsolatedToCrossResponse); } // MsgCreatePerpetual is a message used by x/gov to create a new perpetual. @@ -103,3 +105,18 @@ message MsgUpdateParams { // MsgUpdateParamsResponse defines the UpdateParams response type. message MsgUpdateParamsResponse {} + +// MsgUpgradeMarketFromIsolatedToCross is used to upgrade a market from isolated +// margin to cross margin. +message MsgUpgradeMarketFromIsolatedToCross { + // Authority is the address that controls the module. + option (cosmos.msg.v1.signer) = "authority"; + + string authority = 1 [ (cosmos_proto.scalar) = "cosmos.AddressString" ]; + + // ID of the perpetual to be upgraded to CROSS + uint32 perpetual_id = 2; +} + +// MsgUpgradeMarketFromIsolatedToCrossResponse defines the UpgradeMarketFromIsolatedToCross response type. +message MsgUpgradeMarketFromIsolatedToCrossResponse {} \ No newline at end of file diff --git a/protocol/x/clob/keeper/deleveraging.go b/protocol/x/clob/keeper/deleveraging.go index c088887747..3e698c5960 100644 --- a/protocol/x/clob/keeper/deleveraging.go +++ b/protocol/x/clob/keeper/deleveraging.go @@ -167,6 +167,25 @@ func (k Keeper) GetCrossInsuranceFundBalance(ctx sdk.Context) (balance *big.Int) return insuranceFundBalance.Amount.BigInt() } +func (k Keeper) TransferIsolatedInsuranceFundsToCross(ctx sdk.Context, perpetualId uint32) (balance *big.Int) { + usdcAsset, exists := k.assetsKeeper.GetAsset(ctx, assettypes.AssetUsdc.Id) + if !exists { + panic("GetInsuranceFundBalance: Usdc asset not found in state") + } + insuranceFundAddr, err := k.perpetualsKeeper.GetInsuranceFundModuleAddress(ctx, perpetualId) + if err != nil { + return nil + } + insuranceFundBalance := k.bankKeeper.GetBalance( + ctx, + insuranceFundAddr, + usdcAsset.Denom, + ) + + // Return as big.Int. + return insuranceFundBalance.Amount.BigInt() +} + // CanDeleverageSubaccount returns true if a subaccount can be deleveraged. // This function returns two booleans, shouldDeleverageAtBankruptcyPrice and shouldDeleverageAtOraclePrice. // - shouldDeleverageAtBankruptcyPrice is true if the subaccount has negative TNC. diff --git a/protocol/x/perpetuals/keeper/msg_server_upgrade_market_from_isolated_to_cross.go b/protocol/x/perpetuals/keeper/msg_server_upgrade_market_from_isolated_to_cross.go new file mode 100644 index 0000000000..21805a8bff --- /dev/null +++ b/protocol/x/perpetuals/keeper/msg_server_upgrade_market_from_isolated_to_cross.go @@ -0,0 +1,67 @@ +package keeper + +import ( + "context" + "math/big" + + errorsmod "cosmossdk.io/errors" + govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" + "github.com/dydxprotocol/v4-chain/protocol/lib" + "github.com/dydxprotocol/v4-chain/protocol/x/perpetuals/types" +) + +func (k msgServer) UpgradeMarketFromIsolatedToCross( + goCtx context.Context, + msg *types.MsgUpgradeMarketFromIsolatedToCross, +) (*types.MsgUpgradeMarketFromIsolatedToCrossResponse, error) { + if !k.Keeper.HasAuthority(msg.Authority) { + return nil, errorsmod.Wrapf( + govtypes.ErrInvalidSigner, + "invalid authority %s", + msg.Authority, + ) + } + + ctx := lib.UnwrapSDKContext(goCtx, types.ModuleName) + + isolatedInsuranceFundAddress, err := k.Keeper.GetInsuranceFundModuleAddress(ctx, msg.PerpetualId) + if err != nil { + return nil, err + } + + _, err = k.Keeper.SetPerpetualMarketType( + ctx, + msg.PerpetualId, + types.PerpetualMarketType_PERPETUAL_MARKET_TYPE_CROSS, + ) + if err != nil { + return nil, err + } + + crossInsuranceFundAddress, err := k.Keeper.GetInsuranceFundModuleAddress(ctx, msg.PerpetualId) + if err != nil { + return nil, err + } + + _, coinToTransfer, err := k.assetsKeeper.ConvertAssetToCoin( + ctx, + assettypes.AssetUsdc.Id, + new(big.Int).Abs(insuranceFundDelta), + ) + + // TODO Move insurance fund for perpetual to primary insurance fund + return k.bankKeeper.SendCoins( + ctx, + isolatedInsuranceFundAddress, + crossInsuranceFundAddress, + []sdk.Coin{coinToTransfer}, + ) + + // clob/keeper/deleveraging.go func (k Keeper) GetInsuranceFundBalance(ctx sdk.Context, perpetualId uint32) (balance *big.Int) { + + // TODO Move collateral pool for perpetual to subaccounts module + + // TODO Propagate changes to indexer + + return &types.MsgUpgradeMarketFromIsolatedToCrossResponse{}, nil +} diff --git a/protocol/x/perpetuals/keeper/perpetual.go b/protocol/x/perpetuals/keeper/perpetual.go index 834f67e96a..6a75e83723 100644 --- a/protocol/x/perpetuals/keeper/perpetual.go +++ b/protocol/x/perpetuals/keeper/perpetual.go @@ -197,7 +197,7 @@ func (k Keeper) SetPerpetualMarketType( return perpetual, err } - if perpetual.Params.MarketType != types.PerpetualMarketType_PERPETUAL_MARKET_TYPE_UNSPECIFIED { + if perpetual.Params.MarketType == types.PerpetualMarketType_PERPETUAL_MARKET_TYPE_CROSS { return types.Perpetual{}, errorsmod.Wrap( types.ErrInvalidMarketType, fmt.Sprintf("perpetual %d already has market type %v", perpetualId, perpetual.Params.MarketType), diff --git a/protocol/x/perpetuals/types/message_upgrade_market_from_isolated_to_cross.go b/protocol/x/perpetuals/types/message_upgrade_market_from_isolated_to_cross.go new file mode 100644 index 0000000000..bbd00e27a8 --- /dev/null +++ b/protocol/x/perpetuals/types/message_upgrade_market_from_isolated_to_cross.go @@ -0,0 +1,25 @@ +package types + +import ( + "fmt" + + errorsmod "cosmossdk.io/errors" + sdk "github.com/cosmos/cosmos-sdk/types" +) + +var _ sdk.Msg = &MsgUpgradeMarketFromIsolatedToCross{} + +func (msg *MsgUpgradeMarketFromIsolatedToCross) ValidateBasic() error { + if _, err := sdk.AccAddressFromBech32(msg.Authority); err != nil { + return errorsmod.Wrap( + ErrInvalidAuthority, + fmt.Sprintf( + "authority '%s' must be a valid bech32 address, but got error '%v'", + msg.Authority, + err.Error(), + ), + ) + } + // TODO Validation? Do we need to check if the PerpetualId is valid? + return nil +} diff --git a/protocol/x/perpetuals/types/message_upgrade_market_from_isolated_to_cross_test.go b/protocol/x/perpetuals/types/message_upgrade_market_from_isolated_to_cross_test.go new file mode 100644 index 0000000000..c1d9a4e030 --- /dev/null +++ b/protocol/x/perpetuals/types/message_upgrade_market_from_isolated_to_cross_test.go @@ -0,0 +1,39 @@ +package types_test + +import ( + "testing" + + types "github.com/dydxprotocol/v4-chain/protocol/x/perpetuals/types" + "github.com/stretchr/testify/require" +) + +func TestMsgUpgradeMarketFromIsolatedToCross_ValidateBasic(t *testing.T) { + tests := map[string]struct { + msg types.MsgUpgradeMarketFromIsolatedToCross + expectedErr string + }{ + "Success": { + msg: types.MsgUpgradeMarketFromIsolatedToCross{ + Authority: validAuthority, + PerpetualId: 1, + }, + }, + "Failure: Invalid authority": { + msg: types.MsgUpgradeMarketFromIsolatedToCross{ + Authority: "", + }, + expectedErr: "Authority is invalid", + }, + } + + for name, tc := range tests { + t.Run(name, func(t *testing.T) { + err := tc.msg.ValidateBasic() + if tc.expectedErr == "" { + require.NoError(t, err) + } else { + require.ErrorContains(t, err, tc.expectedErr) + } + }) + } +} diff --git a/protocol/x/perpetuals/types/tx.pb.go b/protocol/x/perpetuals/types/tx.pb.go index 89cc1abbcf..39415fa7da 100644 --- a/protocol/x/perpetuals/types/tx.pb.go +++ b/protocol/x/perpetuals/types/tx.pb.go @@ -540,6 +540,102 @@ func (m *MsgUpdateParamsResponse) XXX_DiscardUnknown() { var xxx_messageInfo_MsgUpdateParamsResponse proto.InternalMessageInfo +// MsgUpgradeMarketFromIsolatedToCross is used to upgrade a market from isolated +// margin to cross margin. +type MsgUpgradeMarketFromIsolatedToCross struct { + Authority string `protobuf:"bytes,1,opt,name=authority,proto3" json:"authority,omitempty"` + // ID of the perpetual to be upgraded to CROSS + PerpetualId uint32 `protobuf:"varint,2,opt,name=perpetual_id,json=perpetualId,proto3" json:"perpetual_id,omitempty"` +} + +func (m *MsgUpgradeMarketFromIsolatedToCross) Reset() { *m = MsgUpgradeMarketFromIsolatedToCross{} } +func (m *MsgUpgradeMarketFromIsolatedToCross) String() string { return proto.CompactTextString(m) } +func (*MsgUpgradeMarketFromIsolatedToCross) ProtoMessage() {} +func (*MsgUpgradeMarketFromIsolatedToCross) Descriptor() ([]byte, []int) { + return fileDescriptor_daed24c15760c356, []int{11} +} +func (m *MsgUpgradeMarketFromIsolatedToCross) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgUpgradeMarketFromIsolatedToCross) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgUpgradeMarketFromIsolatedToCross.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *MsgUpgradeMarketFromIsolatedToCross) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgUpgradeMarketFromIsolatedToCross.Merge(m, src) +} +func (m *MsgUpgradeMarketFromIsolatedToCross) XXX_Size() int { + return m.Size() +} +func (m *MsgUpgradeMarketFromIsolatedToCross) XXX_DiscardUnknown() { + xxx_messageInfo_MsgUpgradeMarketFromIsolatedToCross.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgUpgradeMarketFromIsolatedToCross proto.InternalMessageInfo + +func (m *MsgUpgradeMarketFromIsolatedToCross) GetAuthority() string { + if m != nil { + return m.Authority + } + return "" +} + +func (m *MsgUpgradeMarketFromIsolatedToCross) GetPerpetualId() uint32 { + if m != nil { + return m.PerpetualId + } + return 0 +} + +// MsgUpgradeMarketFromIsolatedToCrossResponse defines the UpgradeMarketFromIsolatedToCross response type. +type MsgUpgradeMarketFromIsolatedToCrossResponse struct { +} + +func (m *MsgUpgradeMarketFromIsolatedToCrossResponse) Reset() { + *m = MsgUpgradeMarketFromIsolatedToCrossResponse{} +} +func (m *MsgUpgradeMarketFromIsolatedToCrossResponse) String() string { + return proto.CompactTextString(m) +} +func (*MsgUpgradeMarketFromIsolatedToCrossResponse) ProtoMessage() {} +func (*MsgUpgradeMarketFromIsolatedToCrossResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_daed24c15760c356, []int{12} +} +func (m *MsgUpgradeMarketFromIsolatedToCrossResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgUpgradeMarketFromIsolatedToCrossResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgUpgradeMarketFromIsolatedToCrossResponse.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *MsgUpgradeMarketFromIsolatedToCrossResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgUpgradeMarketFromIsolatedToCrossResponse.Merge(m, src) +} +func (m *MsgUpgradeMarketFromIsolatedToCrossResponse) XXX_Size() int { + return m.Size() +} +func (m *MsgUpgradeMarketFromIsolatedToCrossResponse) XXX_DiscardUnknown() { + xxx_messageInfo_MsgUpgradeMarketFromIsolatedToCrossResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgUpgradeMarketFromIsolatedToCrossResponse proto.InternalMessageInfo + func init() { proto.RegisterType((*MsgCreatePerpetual)(nil), "dydxprotocol.perpetuals.MsgCreatePerpetual") proto.RegisterType((*MsgCreatePerpetualResponse)(nil), "dydxprotocol.perpetuals.MsgCreatePerpetualResponse") @@ -552,51 +648,57 @@ func init() { proto.RegisterType((*MsgAddPremiumVotesResponse)(nil), "dydxprotocol.perpetuals.MsgAddPremiumVotesResponse") proto.RegisterType((*MsgUpdateParams)(nil), "dydxprotocol.perpetuals.MsgUpdateParams") proto.RegisterType((*MsgUpdateParamsResponse)(nil), "dydxprotocol.perpetuals.MsgUpdateParamsResponse") + proto.RegisterType((*MsgUpgradeMarketFromIsolatedToCross)(nil), "dydxprotocol.perpetuals.MsgUpgradeMarketFromIsolatedToCross") + proto.RegisterType((*MsgUpgradeMarketFromIsolatedToCrossResponse)(nil), "dydxprotocol.perpetuals.MsgUpgradeMarketFromIsolatedToCrossResponse") } func init() { proto.RegisterFile("dydxprotocol/perpetuals/tx.proto", fileDescriptor_daed24c15760c356) } var fileDescriptor_daed24c15760c356 = []byte{ - // 620 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xa4, 0x55, 0x4d, 0x6b, 0x13, 0x41, - 0x18, 0xce, 0xd8, 0x0f, 0xe8, 0x9b, 0x36, 0x29, 0x6b, 0x25, 0xe9, 0xaa, 0x9b, 0x18, 0xc4, 0x06, - 0xb5, 0x59, 0x9b, 0x16, 0x41, 0xd1, 0x43, 0x53, 0x28, 0x08, 0x06, 0x42, 0x52, 0x0b, 0xf5, 0x12, - 0xb6, 0xd9, 0x61, 0x33, 0x92, 0xcd, 0x8e, 0x3b, 0xb3, 0x21, 0xb9, 0x0a, 0xde, 0x3d, 0xfa, 0x03, - 0xfc, 0x01, 0x22, 0x5e, 0xbd, 0xf7, 0x58, 0x3c, 0x09, 0x82, 0x48, 0x72, 0xf0, 0x6f, 0x48, 0xf6, - 0x2b, 0xd9, 0x4d, 0x36, 0x24, 0xed, 0x69, 0x67, 0xdf, 0x79, 0xde, 0xf7, 0x79, 0x9e, 0x77, 0xbe, - 0x20, 0xab, 0xf6, 0xd4, 0x2e, 0x35, 0x0d, 0x6e, 0x34, 0x8c, 0x96, 0x4c, 0xb1, 0x49, 0x31, 0xb7, - 0x94, 0x16, 0x93, 0x79, 0xb7, 0x60, 0x87, 0x85, 0xd4, 0x38, 0xa2, 0x30, 0x42, 0x88, 0xdb, 0x0d, - 0x83, 0xe9, 0x06, 0xab, 0xdb, 0x73, 0xb2, 0xf3, 0xe3, 0xe4, 0x88, 0x29, 0xe7, 0x4f, 0xd6, 0x99, - 0x26, 0x77, 0xf6, 0x86, 0x1f, 0x77, 0x62, 0x4b, 0x33, 0x34, 0xc3, 0x49, 0x18, 0x8e, 0xdc, 0xe8, - 0xfd, 0x28, 0x11, 0x54, 0x31, 0x15, 0xdd, 0x2b, 0xba, 0x13, 0x89, 0xf2, 0x86, 0x0e, 0x30, 0xf7, - 0x05, 0x81, 0x50, 0x66, 0xda, 0x91, 0x89, 0x15, 0x8e, 0x2b, 0xde, 0xa4, 0xf0, 0x14, 0xd6, 0x14, - 0x8b, 0x37, 0x0d, 0x93, 0xf0, 0x5e, 0x1a, 0x65, 0x51, 0x7e, 0xad, 0x94, 0xfe, 0xf9, 0x7d, 0x77, - 0xcb, 0x55, 0x7e, 0xa8, 0xaa, 0x26, 0x66, 0xac, 0xc6, 0x4d, 0xd2, 0xd6, 0xaa, 0x23, 0xa8, 0x70, - 0x0c, 0xab, 0x8e, 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x5b, 0xf6, 0x23, 0xdd, 0xc0, 0x63, 0xdb, 0xa3, 0x98, 0x9d, 0xaf, 0xda, 0x93, 0xfb, 0xff, 0x03, - 0x00, 0x00, 0xff, 0xff, 0x2c, 0x4e, 0x17, 0x56, 0x94, 0x07, 0x00, 0x00, + // 685 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xa4, 0x56, 0xcd, 0x4f, 0x13, 0x4f, + 0x18, 0xee, 0xc0, 0x0f, 0x12, 0xde, 0xf2, 0x95, 0xfd, 0x61, 0x28, 0xab, 0x96, 0x5a, 0x8d, 0x34, + 0x22, 0x5d, 0xf9, 0x88, 0x89, 0x06, 0x0f, 0x80, 0x21, 0x21, 0xb1, 0x49, 0x53, 0x90, 0x04, 0x2f, + 0xcd, 0xd2, 0x99, 0x2c, 0xa3, 0xdd, 0xce, 0x38, 0x33, 0x6d, 0xe8, 0xd5, 0xe8, 0x9d, 0xa3, 0x7f, + 0x80, 0xf1, 0x6c, 0x8c, 0x57, 0xef, 0x1c, 0x89, 0x27, 0x4f, 0xc6, 0xc0, 0xc1, 0x7f, 0xc3, 0x74, + 0xbf, 0x4a, 0x77, 0xd9, 0xb5, 0xc0, 0x69, 0x67, 0xdf, 0xf7, 0x79, 0xdf, 0xe7, 0x79, 0xe6, 0xdd, + 0x99, 0x2c, 0xe4, 0x70, 0x1b, 0x1f, 0x72, 0xc1, 0x14, 0xab, 0xb1, 0xba, 0xc1, 0x89, 0xe0, 0x44, + 0x35, 0xcd, 0xba, 0x34, 0xd4, 0x61, 0xd1, 0x09, 0x6b, 0xd3, 0xe7, 0x11, 0xc5, 0x2e, 0x42, 0x9f, + 0xa9, 0x31, 0x69, 0x33, 0x59, 0x75, 0x72, 0x86, 0xfb, 0xe2, 0xd6, 0xe8, 0xd3, 0xee, 0x9b, 0x61, + 0x4b, 0xcb, 0x68, 0x2d, 0x76, 0x1e, 0x5e, 0x62, 0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x98, 0x08, 0x4f, 0x7d, 0x3e, 0x76, 0xdb, 0xa2, 0x73, 0xd4, 0x97, + 0x2f, 0x01, 0xf6, 0xc9, 0x3b, 0xa4, 0xe1, 0xcb, 0x33, 0x91, 0x34, 0x04, 0x4e, 0x26, 0x8d, 0xb9, + 0xf0, 0xb4, 0x16, 0x4c, 0x46, 0x2e, 0xbb, 0x87, 0x49, 0x8d, 0xc2, 0x68, 0x7d, 0xe5, 0x32, 0xe8, + 0x80, 0xf7, 0x03, 0x82, 0x1b, 0x17, 0xdf, 0x48, 0x8b, 0x49, 0xfd, 0x2e, 0x2c, 0xd1, 0x9f, 0x5c, + 0xba, 0x24, 0xd0, 0xf1, 0x1a, 0x46, 0x7b, 0x4e, 0x59, 0xa1, 0x8f, 0x56, 0x2e, 0xe9, 0xa3, 0x7e, + 0x91, 0x01, 0xd7, 0x67, 0x04, 0xb9, 0x7f, 0x1e, 0x8e, 0xd5, 0xe4, 0xb6, 0xc9, 0xd5, 0xfa, 0xf3, + 0xeb, 0x54, 0xfb, 0x42, 0xd7, 0x77, 0x8f, 0x4f, 0xb3, 0xe8, 0xe4, 0x34, 0x8b, 0x7e, 0x9f, 0x66, + 0xd1, 0xd1, 0x59, 0x36, 0x75, 0x72, 0x96, 0x4d, 0xfd, 0x3c, 0xcb, 0xa6, 0x5e, 0xad, 0x5a, 0x54, + 0x1d, 0x34, 0xf7, 0x8b, 0x35, 0x66, 0x1b, 0x3d, 0x3f, 0x06, 0xad, 0x95, 0x85, 0xda, 0x81, 0x49, + 0x1b, 0x46, 0x10, 0x39, 0xec, 0xf9, 0xaf, 0x69, 0x73, 0x22, 0xf7, 0x87, 0x9d, 0xe4, 0xf2, 0xdf, + 0x00, 0x00, 0x00, 0xff, 0xff, 0x40, 0xf6, 0x63, 0x5c, 0xff, 0x08, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -623,6 +725,8 @@ type MsgClient interface { UpdatePerpetualParams(ctx context.Context, in *MsgUpdatePerpetualParams, opts ...grpc.CallOption) (*MsgUpdatePerpetualParamsResponse, error) // UpdateParams updates the parameters of perpetuals module. UpdateParams(ctx context.Context, in *MsgUpdateParams, opts ...grpc.CallOption) (*MsgUpdateParamsResponse, error) + // UpgradeMarketFromIsolatedToCross upgrades a perpetual from isolated to cross margin. + UpgradeMarketFromIsolatedToCross(ctx context.Context, in *MsgUpgradeMarketFromIsolatedToCross, opts ...grpc.CallOption) (*MsgUpgradeMarketFromIsolatedToCrossResponse, error) } type msgClient struct { @@ -678,6 +782,15 @@ func (c *msgClient) UpdateParams(ctx context.Context, in *MsgUpdateParams, opts return out, nil } +func (c *msgClient) UpgradeMarketFromIsolatedToCross(ctx context.Context, in *MsgUpgradeMarketFromIsolatedToCross, opts ...grpc.CallOption) (*MsgUpgradeMarketFromIsolatedToCrossResponse, error) { + out := new(MsgUpgradeMarketFromIsolatedToCrossResponse) + err := c.cc.Invoke(ctx, "/dydxprotocol.perpetuals.Msg/UpgradeMarketFromIsolatedToCross", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + // MsgServer is the server API for Msg service. type MsgServer interface { // AddPremiumVotes add new samples of the funding premiums to the @@ -692,6 +805,8 @@ type MsgServer interface { UpdatePerpetualParams(context.Context, *MsgUpdatePerpetualParams) (*MsgUpdatePerpetualParamsResponse, error) // UpdateParams updates the parameters of perpetuals module. UpdateParams(context.Context, *MsgUpdateParams) (*MsgUpdateParamsResponse, error) + // UpgradeMarketFromIsolatedToCross upgrades a perpetual from isolated to cross margin. + UpgradeMarketFromIsolatedToCross(context.Context, *MsgUpgradeMarketFromIsolatedToCross) (*MsgUpgradeMarketFromIsolatedToCrossResponse, error) } // UnimplementedMsgServer can be embedded to have forward compatible implementations. @@ -713,6 +828,9 @@ func (*UnimplementedMsgServer) UpdatePerpetualParams(ctx context.Context, req *M func (*UnimplementedMsgServer) UpdateParams(ctx context.Context, req *MsgUpdateParams) (*MsgUpdateParamsResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method UpdateParams not implemented") } +func (*UnimplementedMsgServer) UpgradeMarketFromIsolatedToCross(ctx context.Context, req *MsgUpgradeMarketFromIsolatedToCross) (*MsgUpgradeMarketFromIsolatedToCrossResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method UpgradeMarketFromIsolatedToCross not implemented") +} func RegisterMsgServer(s grpc1.Server, srv MsgServer) { s.RegisterService(&_Msg_serviceDesc, srv) @@ -808,6 +926,24 @@ func _Msg_UpdateParams_Handler(srv interface{}, ctx context.Context, dec func(in return interceptor(ctx, in, info, handler) } +func _Msg_UpgradeMarketFromIsolatedToCross_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(MsgUpgradeMarketFromIsolatedToCross) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(MsgServer).UpgradeMarketFromIsolatedToCross(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/dydxprotocol.perpetuals.Msg/UpgradeMarketFromIsolatedToCross", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(MsgServer).UpgradeMarketFromIsolatedToCross(ctx, req.(*MsgUpgradeMarketFromIsolatedToCross)) + } + return interceptor(ctx, in, info, handler) +} + var _Msg_serviceDesc = grpc.ServiceDesc{ ServiceName: "dydxprotocol.perpetuals.Msg", HandlerType: (*MsgServer)(nil), @@ -832,6 +968,10 @@ var _Msg_serviceDesc = grpc.ServiceDesc{ MethodName: "UpdateParams", Handler: _Msg_UpdateParams_Handler, }, + { + MethodName: "UpgradeMarketFromIsolatedToCross", + Handler: _Msg_UpgradeMarketFromIsolatedToCross_Handler, + }, }, Streams: []grpc.StreamDesc{}, Metadata: "dydxprotocol/perpetuals/tx.proto", @@ -1182,6 +1322,64 @@ func (m *MsgUpdateParamsResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) return len(dAtA) - i, nil } +func (m *MsgUpgradeMarketFromIsolatedToCross) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *MsgUpgradeMarketFromIsolatedToCross) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgUpgradeMarketFromIsolatedToCross) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.PerpetualId != 0 { + i = encodeVarintTx(dAtA, i, uint64(m.PerpetualId)) + i-- + dAtA[i] = 0x10 + } + if len(m.Authority) > 0 { + i -= len(m.Authority) + copy(dAtA[i:], m.Authority) + i = encodeVarintTx(dAtA, i, uint64(len(m.Authority))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *MsgUpgradeMarketFromIsolatedToCrossResponse) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *MsgUpgradeMarketFromIsolatedToCrossResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgUpgradeMarketFromIsolatedToCrossResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + return len(dAtA) - i, nil +} + func encodeVarintTx(dAtA []byte, offset int, v uint64) int { offset -= sovTx(v) base := offset @@ -1328,6 +1526,31 @@ func (m *MsgUpdateParamsResponse) Size() (n int) { return n } +func (m *MsgUpgradeMarketFromIsolatedToCross) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Authority) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + if m.PerpetualId != 0 { + n += 1 + sovTx(uint64(m.PerpetualId)) + } + return n +} + +func (m *MsgUpgradeMarketFromIsolatedToCrossResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + return n +} + func sovTx(x uint64) (n int) { return (math_bits.Len64(x|1) + 6) / 7 } @@ -2216,6 +2439,157 @@ func (m *MsgUpdateParamsResponse) Unmarshal(dAtA []byte) error { } return nil } +func (m *MsgUpgradeMarketFromIsolatedToCross) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: MsgUpgradeMarketFromIsolatedToCross: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgUpgradeMarketFromIsolatedToCross: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Authority", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Authority = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field PerpetualId", wireType) + } + m.PerpetualId = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.PerpetualId |= uint32(b&0x7F) << shift + if b < 0x80 { + break + } + } + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *MsgUpgradeMarketFromIsolatedToCrossResponse) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: MsgUpgradeMarketFromIsolatedToCrossResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgUpgradeMarketFromIsolatedToCrossResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} func skipTx(dAtA []byte) (n int, err error) { l := len(dAtA) iNdEx := 0 diff --git a/protocol/x/perpetuals/types/types.go b/protocol/x/perpetuals/types/types.go index 7268ec81a9..1f6a95908f 100644 --- a/protocol/x/perpetuals/types/types.go +++ b/protocol/x/perpetuals/types/types.go @@ -118,6 +118,10 @@ type PerpetualsKeeper interface { ctx sdk.Context, perpetual Perpetual, ) error + GetInsuranceFundModuleAddress( + ctx sdk.Context, + perpetualId uint32, + ) (sdk.AccAddress, error) } // OpenInterestDelta represents a (perpId, openInterestDelta) tuple. From bc632af1e4de267c09ab1434f6482ee37a6f0f7c Mon Sep 17 00:00:00 2001 From: Harry Wray Date: Thu, 31 Oct 2024 11:24:45 -0400 Subject: [PATCH 02/29] Update --- proto/dydxprotocol/perpetuals/tx.proto | 15 +- ...er_upgrade_isolated_perpetual_to_cross.go} | 10 +- ...ge_upgrade_isolated_perpetual_to_cross.go} | 4 +- ...grade_isolated_perpetual_to_cross_test.go} | 8 +- protocol/x/perpetuals/types/tx.pb.go | 221 +++++++++--------- 5 files changed, 131 insertions(+), 127 deletions(-) rename protocol/x/perpetuals/keeper/{msg_server_upgrade_market_from_isolated_to_cross.go => msg_server_upgrade_isolated_perpetual_to_cross.go} (84%) rename protocol/x/perpetuals/types/{message_upgrade_market_from_isolated_to_cross.go => message_upgrade_isolated_perpetual_to_cross.go} (77%) rename protocol/x/perpetuals/types/{message_upgrade_market_from_isolated_to_cross_test.go => message_upgrade_isolated_perpetual_to_cross_test.go} (72%) diff --git a/proto/dydxprotocol/perpetuals/tx.proto b/proto/dydxprotocol/perpetuals/tx.proto index 19e79c4f0d..c48c1a1c2e 100644 --- a/proto/dydxprotocol/perpetuals/tx.proto +++ b/proto/dydxprotocol/perpetuals/tx.proto @@ -25,8 +25,8 @@ service Msg { returns (MsgUpdatePerpetualParamsResponse); // UpdateParams updates the parameters of perpetuals module. rpc UpdateParams(MsgUpdateParams) returns (MsgUpdateParamsResponse); - // UpgradeMarketFromIsolatedToCross upgrades a perpetual from isolated to cross margin. - rpc UpgradeMarketFromIsolatedToCross(MsgUpgradeMarketFromIsolatedToCross) returns (MsgUpgradeMarketFromIsolatedToCrossResponse); + // UpgradeIsolatedPerpetualToCross upgrades a perpetual from isolated to cross margin. + rpc UpgradeIsolatedPerpetualToCross(MsgUpgradeIsolatedPerpetualToCross) returns (MsgUpgradeIsolatedPerpetualToCrossResponse); } // MsgCreatePerpetual is a message used by x/gov to create a new perpetual. @@ -106,9 +106,9 @@ message MsgUpdateParams { // MsgUpdateParamsResponse defines the UpdateParams response type. message MsgUpdateParamsResponse {} -// MsgUpgradeMarketFromIsolatedToCross is used to upgrade a market from isolated -// margin to cross margin. -message MsgUpgradeMarketFromIsolatedToCross { +// MsgUpgradeIsolatedPerpetualToCross is used to upgrade a market from +// isolated margin to cross margin. +message MsgUpgradeIsolatedPerpetualToCross { // Authority is the address that controls the module. option (cosmos.msg.v1.signer) = "authority"; @@ -118,5 +118,6 @@ message MsgUpgradeMarketFromIsolatedToCross { uint32 perpetual_id = 2; } -// MsgUpgradeMarketFromIsolatedToCrossResponse defines the UpgradeMarketFromIsolatedToCross response type. -message MsgUpgradeMarketFromIsolatedToCrossResponse {} \ No newline at end of file +// MsgUpgradeIsolatedPerpetualToCrossResponse defines the +// UpgradeIsolatedPerpetualToCross response type. +message MsgUpgradeIsolatedPerpetualToCrossResponse {} diff --git a/protocol/x/perpetuals/keeper/msg_server_upgrade_market_from_isolated_to_cross.go b/protocol/x/perpetuals/keeper/msg_server_upgrade_isolated_perpetual_to_cross.go similarity index 84% rename from protocol/x/perpetuals/keeper/msg_server_upgrade_market_from_isolated_to_cross.go rename to protocol/x/perpetuals/keeper/msg_server_upgrade_isolated_perpetual_to_cross.go index 21805a8bff..5ce492f49c 100644 --- a/protocol/x/perpetuals/keeper/msg_server_upgrade_market_from_isolated_to_cross.go +++ b/protocol/x/perpetuals/keeper/msg_server_upgrade_isolated_perpetual_to_cross.go @@ -10,10 +10,10 @@ import ( "github.com/dydxprotocol/v4-chain/protocol/x/perpetuals/types" ) -func (k msgServer) UpgradeMarketFromIsolatedToCross( +func (k msgServer) UpgradeIsolatedPerpetualToCross( goCtx context.Context, - msg *types.MsgUpgradeMarketFromIsolatedToCross, -) (*types.MsgUpgradeMarketFromIsolatedToCrossResponse, error) { + msg *types.MsgUpgradeIsolatedPerpetualToCross, +) (*types.MsgUpgradeIsolatedPerpetualToCrossResponse, error) { if !k.Keeper.HasAuthority(msg.Authority) { return nil, errorsmod.Wrapf( govtypes.ErrInvalidSigner, @@ -43,6 +43,8 @@ func (k msgServer) UpgradeMarketFromIsolatedToCross( return nil, err } + isolatedInsuranceFundBalance := k.Keeper. + _, coinToTransfer, err := k.assetsKeeper.ConvertAssetToCoin( ctx, assettypes.AssetUsdc.Id, @@ -63,5 +65,5 @@ func (k msgServer) UpgradeMarketFromIsolatedToCross( // TODO Propagate changes to indexer - return &types.MsgUpgradeMarketFromIsolatedToCrossResponse{}, nil + return &types.MsgUpgradeIsolatedPerpetualToCrossResponse{}, nil } diff --git a/protocol/x/perpetuals/types/message_upgrade_market_from_isolated_to_cross.go b/protocol/x/perpetuals/types/message_upgrade_isolated_perpetual_to_cross.go similarity index 77% rename from protocol/x/perpetuals/types/message_upgrade_market_from_isolated_to_cross.go rename to protocol/x/perpetuals/types/message_upgrade_isolated_perpetual_to_cross.go index bbd00e27a8..bcd4ae6c52 100644 --- a/protocol/x/perpetuals/types/message_upgrade_market_from_isolated_to_cross.go +++ b/protocol/x/perpetuals/types/message_upgrade_isolated_perpetual_to_cross.go @@ -7,9 +7,9 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" ) -var _ sdk.Msg = &MsgUpgradeMarketFromIsolatedToCross{} +var _ sdk.Msg = &MsgUpgradeIsolatedPerpetualToCross{} -func (msg *MsgUpgradeMarketFromIsolatedToCross) ValidateBasic() error { +func (msg *MsgUpgradeIsolatedPerpetualToCross) ValidateBasic() error { if _, err := sdk.AccAddressFromBech32(msg.Authority); err != nil { return errorsmod.Wrap( ErrInvalidAuthority, diff --git a/protocol/x/perpetuals/types/message_upgrade_market_from_isolated_to_cross_test.go b/protocol/x/perpetuals/types/message_upgrade_isolated_perpetual_to_cross_test.go similarity index 72% rename from protocol/x/perpetuals/types/message_upgrade_market_from_isolated_to_cross_test.go rename to protocol/x/perpetuals/types/message_upgrade_isolated_perpetual_to_cross_test.go index c1d9a4e030..5aa72e93b1 100644 --- a/protocol/x/perpetuals/types/message_upgrade_market_from_isolated_to_cross_test.go +++ b/protocol/x/perpetuals/types/message_upgrade_isolated_perpetual_to_cross_test.go @@ -7,19 +7,19 @@ import ( "github.com/stretchr/testify/require" ) -func TestMsgUpgradeMarketFromIsolatedToCross_ValidateBasic(t *testing.T) { +func TestMsgUpgradeIsolatedPerpetualToCross_ValidateBasic(t *testing.T) { tests := map[string]struct { - msg types.MsgUpgradeMarketFromIsolatedToCross + msg types.MsgUpgradeIsolatedPerpetualToCross expectedErr string }{ "Success": { - msg: types.MsgUpgradeMarketFromIsolatedToCross{ + msg: types.MsgUpgradeIsolatedPerpetualToCross{ Authority: validAuthority, PerpetualId: 1, }, }, "Failure: Invalid authority": { - msg: types.MsgUpgradeMarketFromIsolatedToCross{ + msg: types.MsgUpgradeIsolatedPerpetualToCross{ Authority: "", }, expectedErr: "Authority is invalid", diff --git a/protocol/x/perpetuals/types/tx.pb.go b/protocol/x/perpetuals/types/tx.pb.go index 39415fa7da..dac961582a 100644 --- a/protocol/x/perpetuals/types/tx.pb.go +++ b/protocol/x/perpetuals/types/tx.pb.go @@ -540,26 +540,26 @@ func (m *MsgUpdateParamsResponse) XXX_DiscardUnknown() { var xxx_messageInfo_MsgUpdateParamsResponse proto.InternalMessageInfo -// MsgUpgradeMarketFromIsolatedToCross is used to upgrade a market from isolated -// margin to cross margin. -type MsgUpgradeMarketFromIsolatedToCross struct { +// MsgUpgradeIsolatedPerpetualToCross is used to upgrade a market from +// isolated margin to cross margin. +type MsgUpgradeIsolatedPerpetualToCross struct { Authority string `protobuf:"bytes,1,opt,name=authority,proto3" json:"authority,omitempty"` // ID of the perpetual to be upgraded to CROSS PerpetualId uint32 `protobuf:"varint,2,opt,name=perpetual_id,json=perpetualId,proto3" json:"perpetual_id,omitempty"` } -func (m *MsgUpgradeMarketFromIsolatedToCross) Reset() { *m = MsgUpgradeMarketFromIsolatedToCross{} } -func (m *MsgUpgradeMarketFromIsolatedToCross) String() string { return proto.CompactTextString(m) } -func (*MsgUpgradeMarketFromIsolatedToCross) ProtoMessage() {} -func (*MsgUpgradeMarketFromIsolatedToCross) Descriptor() ([]byte, []int) { +func (m *MsgUpgradeIsolatedPerpetualToCross) Reset() { *m = MsgUpgradeIsolatedPerpetualToCross{} } +func (m *MsgUpgradeIsolatedPerpetualToCross) String() string { return proto.CompactTextString(m) } +func (*MsgUpgradeIsolatedPerpetualToCross) ProtoMessage() {} +func (*MsgUpgradeIsolatedPerpetualToCross) Descriptor() ([]byte, []int) { return fileDescriptor_daed24c15760c356, []int{11} } -func (m *MsgUpgradeMarketFromIsolatedToCross) XXX_Unmarshal(b []byte) error { +func (m *MsgUpgradeIsolatedPerpetualToCross) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) } -func (m *MsgUpgradeMarketFromIsolatedToCross) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { +func (m *MsgUpgradeIsolatedPerpetualToCross) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { if deterministic { - return xxx_messageInfo_MsgUpgradeMarketFromIsolatedToCross.Marshal(b, m, deterministic) + return xxx_messageInfo_MsgUpgradeIsolatedPerpetualToCross.Marshal(b, m, deterministic) } else { b = b[:cap(b)] n, err := m.MarshalToSizedBuffer(b) @@ -569,52 +569,53 @@ func (m *MsgUpgradeMarketFromIsolatedToCross) XXX_Marshal(b []byte, deterministi return b[:n], nil } } -func (m *MsgUpgradeMarketFromIsolatedToCross) XXX_Merge(src proto.Message) { - xxx_messageInfo_MsgUpgradeMarketFromIsolatedToCross.Merge(m, src) +func (m *MsgUpgradeIsolatedPerpetualToCross) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgUpgradeIsolatedPerpetualToCross.Merge(m, src) } -func (m *MsgUpgradeMarketFromIsolatedToCross) XXX_Size() int { +func (m *MsgUpgradeIsolatedPerpetualToCross) XXX_Size() int { return m.Size() } -func (m *MsgUpgradeMarketFromIsolatedToCross) XXX_DiscardUnknown() { - xxx_messageInfo_MsgUpgradeMarketFromIsolatedToCross.DiscardUnknown(m) +func (m *MsgUpgradeIsolatedPerpetualToCross) XXX_DiscardUnknown() { + xxx_messageInfo_MsgUpgradeIsolatedPerpetualToCross.DiscardUnknown(m) } -var xxx_messageInfo_MsgUpgradeMarketFromIsolatedToCross proto.InternalMessageInfo +var xxx_messageInfo_MsgUpgradeIsolatedPerpetualToCross proto.InternalMessageInfo -func (m *MsgUpgradeMarketFromIsolatedToCross) GetAuthority() string { +func (m *MsgUpgradeIsolatedPerpetualToCross) GetAuthority() string { if m != nil { return m.Authority } return "" } -func (m *MsgUpgradeMarketFromIsolatedToCross) GetPerpetualId() uint32 { +func (m *MsgUpgradeIsolatedPerpetualToCross) GetPerpetualId() uint32 { if m != nil { return m.PerpetualId } return 0 } -// MsgUpgradeMarketFromIsolatedToCrossResponse defines the UpgradeMarketFromIsolatedToCross response type. -type MsgUpgradeMarketFromIsolatedToCrossResponse struct { +// MsgUpgradeIsolatedPerpetualToCrossResponse defines the +// UpgradeIsolatedPerpetualToCross response type. +type MsgUpgradeIsolatedPerpetualToCrossResponse struct { } -func (m *MsgUpgradeMarketFromIsolatedToCrossResponse) Reset() { - *m = MsgUpgradeMarketFromIsolatedToCrossResponse{} +func (m *MsgUpgradeIsolatedPerpetualToCrossResponse) Reset() { + *m = MsgUpgradeIsolatedPerpetualToCrossResponse{} } -func (m *MsgUpgradeMarketFromIsolatedToCrossResponse) String() string { +func (m *MsgUpgradeIsolatedPerpetualToCrossResponse) String() string { return proto.CompactTextString(m) } -func (*MsgUpgradeMarketFromIsolatedToCrossResponse) ProtoMessage() {} -func (*MsgUpgradeMarketFromIsolatedToCrossResponse) Descriptor() ([]byte, []int) { +func (*MsgUpgradeIsolatedPerpetualToCrossResponse) ProtoMessage() {} +func (*MsgUpgradeIsolatedPerpetualToCrossResponse) Descriptor() ([]byte, []int) { return fileDescriptor_daed24c15760c356, []int{12} } -func (m *MsgUpgradeMarketFromIsolatedToCrossResponse) XXX_Unmarshal(b []byte) error { +func (m *MsgUpgradeIsolatedPerpetualToCrossResponse) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) } -func (m *MsgUpgradeMarketFromIsolatedToCrossResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { +func (m *MsgUpgradeIsolatedPerpetualToCrossResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { if deterministic { - return xxx_messageInfo_MsgUpgradeMarketFromIsolatedToCrossResponse.Marshal(b, m, deterministic) + return xxx_messageInfo_MsgUpgradeIsolatedPerpetualToCrossResponse.Marshal(b, m, deterministic) } else { b = b[:cap(b)] n, err := m.MarshalToSizedBuffer(b) @@ -624,17 +625,17 @@ func (m *MsgUpgradeMarketFromIsolatedToCrossResponse) XXX_Marshal(b []byte, dete return b[:n], nil } } -func (m *MsgUpgradeMarketFromIsolatedToCrossResponse) XXX_Merge(src proto.Message) { - xxx_messageInfo_MsgUpgradeMarketFromIsolatedToCrossResponse.Merge(m, src) +func (m *MsgUpgradeIsolatedPerpetualToCrossResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgUpgradeIsolatedPerpetualToCrossResponse.Merge(m, src) } -func (m *MsgUpgradeMarketFromIsolatedToCrossResponse) XXX_Size() int { +func (m *MsgUpgradeIsolatedPerpetualToCrossResponse) XXX_Size() int { return m.Size() } -func (m *MsgUpgradeMarketFromIsolatedToCrossResponse) XXX_DiscardUnknown() { - xxx_messageInfo_MsgUpgradeMarketFromIsolatedToCrossResponse.DiscardUnknown(m) +func (m *MsgUpgradeIsolatedPerpetualToCrossResponse) XXX_DiscardUnknown() { + xxx_messageInfo_MsgUpgradeIsolatedPerpetualToCrossResponse.DiscardUnknown(m) } -var xxx_messageInfo_MsgUpgradeMarketFromIsolatedToCrossResponse proto.InternalMessageInfo +var xxx_messageInfo_MsgUpgradeIsolatedPerpetualToCrossResponse proto.InternalMessageInfo func init() { proto.RegisterType((*MsgCreatePerpetual)(nil), "dydxprotocol.perpetuals.MsgCreatePerpetual") @@ -648,57 +649,57 @@ func init() { proto.RegisterType((*MsgAddPremiumVotesResponse)(nil), "dydxprotocol.perpetuals.MsgAddPremiumVotesResponse") proto.RegisterType((*MsgUpdateParams)(nil), "dydxprotocol.perpetuals.MsgUpdateParams") proto.RegisterType((*MsgUpdateParamsResponse)(nil), "dydxprotocol.perpetuals.MsgUpdateParamsResponse") - proto.RegisterType((*MsgUpgradeMarketFromIsolatedToCross)(nil), "dydxprotocol.perpetuals.MsgUpgradeMarketFromIsolatedToCross") - proto.RegisterType((*MsgUpgradeMarketFromIsolatedToCrossResponse)(nil), "dydxprotocol.perpetuals.MsgUpgradeMarketFromIsolatedToCrossResponse") + proto.RegisterType((*MsgUpgradeIsolatedPerpetualToCross)(nil), "dydxprotocol.perpetuals.MsgUpgradeIsolatedPerpetualToCross") + proto.RegisterType((*MsgUpgradeIsolatedPerpetualToCrossResponse)(nil), "dydxprotocol.perpetuals.MsgUpgradeIsolatedPerpetualToCrossResponse") } func init() { proto.RegisterFile("dydxprotocol/perpetuals/tx.proto", fileDescriptor_daed24c15760c356) } var fileDescriptor_daed24c15760c356 = []byte{ - // 685 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xa4, 0x56, 0xcd, 0x4f, 0x13, 0x4f, - 0x18, 0xee, 0xc0, 0x0f, 0x12, 0xde, 0xf2, 0x95, 0xfd, 0x61, 0x28, 0xab, 0x96, 0x5a, 0x8d, 0x34, - 0x22, 0x5d, 0xf9, 0x88, 0x89, 0x06, 0x0f, 0x80, 0x21, 0x21, 0xb1, 0x49, 0x53, 0x90, 0x04, 0x2f, - 0xcd, 0xd2, 0x99, 0x2c, 0xa3, 0xdd, 0xce, 0x38, 0x33, 0x6d, 0xe8, 0xd5, 0xe8, 0x9d, 0xa3, 0x7f, - 0x80, 0xf1, 0x6c, 0x8c, 0x57, 0xef, 0x1c, 0x89, 0x27, 0x4f, 0xc6, 0xc0, 0xc1, 0x7f, 0xc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 0xd1, 0xd1, 0x59, 0x36, 0x75, 0x72, 0x96, 0x4d, 0xfd, 0x3c, 0xcb, 0xa6, 0x5e, 0xad, 0x5a, 0x54, - 0x1d, 0x34, 0xf7, 0x8b, 0x35, 0x66, 0x1b, 0x3d, 0x3f, 0x06, 0xad, 0x95, 0x85, 0xda, 0x81, 0x49, - 0x1b, 0x46, 0x10, 0x39, 0xec, 0xf9, 0xaf, 0x69, 0x73, 0x22, 0xf7, 0x87, 0x9d, 0xe4, 0xf2, 0xdf, - 0x00, 0x00, 0x00, 0xff, 0xff, 0x40, 0xf6, 0x63, 0x5c, 0xff, 0x08, 0x00, 0x00, + // 678 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xa4, 0x56, 0xcd, 0x6b, 0x13, 0x41, + 0x14, 0xcf, 0xb4, 0xb6, 0xd0, 0x97, 0x7e, 0xb1, 0x56, 0x9a, 0xae, 0x9a, 0xc4, 0x20, 0x36, 0xd4, + 0x36, 0x6b, 0x3f, 0x10, 0xfc, 0x3a, 0xb4, 0x81, 0x42, 0xc1, 0x40, 0x48, 0x6b, 0xa1, 0x5e, 0xc2, + 0x36, 0x33, 0x6c, 0x57, 0xb2, 0x99, 0x71, 0x66, 0x12, 0x9a, 0xa3, 0x82, 0x67, 0x3d, 0x7a, 0xd7, + 0x3f, 0x40, 0xc4, 0xab, 0xf7, 0x1e, 0x8b, 0x27, 0x4f, 0x22, 0xed, 0xc1, 0x7f, 0x43, 0xb2, 0x1f, + 0x93, 0x66, 0xb7, 0x9b, 0x7e, 0xe4, 0xb4, 0xb3, 0xef, 0xfd, 0xde, 0xfb, 0xfd, 0x7e, 0xf3, 0x76, + 0x86, 0x85, 0x2c, 0x6e, 0xe3, 0x43, 0xc6, 0xa9, 0xa4, 0x35, 0x5a, 0x37, 0x18, 0xe1, 0x8c, 0xc8, + 0xa6, 0x59, 0x17, 0x86, 0x3c, 0x2c, 0xb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xfd, 0x1f, 0x00, 0x00, 0xff, 0xff, 0xb6, 0xd1, + 0x34, 0xcd, 0xfa, 0x08, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -725,8 +726,8 @@ type MsgClient interface { UpdatePerpetualParams(ctx context.Context, in *MsgUpdatePerpetualParams, opts ...grpc.CallOption) (*MsgUpdatePerpetualParamsResponse, error) // UpdateParams updates the parameters of perpetuals module. UpdateParams(ctx context.Context, in *MsgUpdateParams, opts ...grpc.CallOption) (*MsgUpdateParamsResponse, error) - // UpgradeMarketFromIsolatedToCross upgrades a perpetual from isolated to cross margin. - UpgradeMarketFromIsolatedToCross(ctx context.Context, in *MsgUpgradeMarketFromIsolatedToCross, opts ...grpc.CallOption) (*MsgUpgradeMarketFromIsolatedToCrossResponse, error) + // UpgradeIsolatedPerpetualToCross upgrades a perpetual from isolated to cross margin. + UpgradeIsolatedPerpetualToCross(ctx context.Context, in *MsgUpgradeIsolatedPerpetualToCross, opts ...grpc.CallOption) (*MsgUpgradeIsolatedPerpetualToCrossResponse, error) } type msgClient struct { @@ -782,9 +783,9 @@ func (c *msgClient) UpdateParams(ctx context.Context, in *MsgUpdateParams, opts return out, nil } -func (c *msgClient) UpgradeMarketFromIsolatedToCross(ctx context.Context, in *MsgUpgradeMarketFromIsolatedToCross, opts ...grpc.CallOption) (*MsgUpgradeMarketFromIsolatedToCrossResponse, error) { - out := new(MsgUpgradeMarketFromIsolatedToCrossResponse) - err := c.cc.Invoke(ctx, "/dydxprotocol.perpetuals.Msg/UpgradeMarketFromIsolatedToCross", in, out, opts...) +func (c *msgClient) UpgradeIsolatedPerpetualToCross(ctx context.Context, in *MsgUpgradeIsolatedPerpetualToCross, opts ...grpc.CallOption) (*MsgUpgradeIsolatedPerpetualToCrossResponse, error) { + out := new(MsgUpgradeIsolatedPerpetualToCrossResponse) + err := c.cc.Invoke(ctx, "/dydxprotocol.perpetuals.Msg/UpgradeIsolatedPerpetualToCross", in, out, opts...) if err != nil { return nil, err } @@ -805,8 +806,8 @@ type MsgServer interface { UpdatePerpetualParams(context.Context, *MsgUpdatePerpetualParams) (*MsgUpdatePerpetualParamsResponse, error) // UpdateParams updates the parameters of perpetuals module. UpdateParams(context.Context, *MsgUpdateParams) (*MsgUpdateParamsResponse, error) - // UpgradeMarketFromIsolatedToCross upgrades a perpetual from isolated to cross margin. - UpgradeMarketFromIsolatedToCross(context.Context, *MsgUpgradeMarketFromIsolatedToCross) (*MsgUpgradeMarketFromIsolatedToCrossResponse, error) + // UpgradeIsolatedPerpetualToCross upgrades a perpetual from isolated to cross margin. + UpgradeIsolatedPerpetualToCross(context.Context, *MsgUpgradeIsolatedPerpetualToCross) (*MsgUpgradeIsolatedPerpetualToCrossResponse, error) } // UnimplementedMsgServer can be embedded to have forward compatible implementations. @@ -828,8 +829,8 @@ func (*UnimplementedMsgServer) UpdatePerpetualParams(ctx context.Context, req *M func (*UnimplementedMsgServer) UpdateParams(ctx context.Context, req *MsgUpdateParams) (*MsgUpdateParamsResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method UpdateParams not implemented") } -func (*UnimplementedMsgServer) UpgradeMarketFromIsolatedToCross(ctx context.Context, req *MsgUpgradeMarketFromIsolatedToCross) (*MsgUpgradeMarketFromIsolatedToCrossResponse, error) { - return nil, status.Errorf(codes.Unimplemented, "method UpgradeMarketFromIsolatedToCross not implemented") +func (*UnimplementedMsgServer) UpgradeIsolatedPerpetualToCross(ctx context.Context, req *MsgUpgradeIsolatedPerpetualToCross) (*MsgUpgradeIsolatedPerpetualToCrossResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method UpgradeIsolatedPerpetualToCross not implemented") } func RegisterMsgServer(s grpc1.Server, srv MsgServer) { @@ -926,20 +927,20 @@ func _Msg_UpdateParams_Handler(srv interface{}, ctx context.Context, dec func(in return interceptor(ctx, in, info, handler) } -func _Msg_UpgradeMarketFromIsolatedToCross_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(MsgUpgradeMarketFromIsolatedToCross) +func _Msg_UpgradeIsolatedPerpetualToCross_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(MsgUpgradeIsolatedPerpetualToCross) if err := dec(in); err != nil { return nil, err } if interceptor == nil { - return srv.(MsgServer).UpgradeMarketFromIsolatedToCross(ctx, in) + return srv.(MsgServer).UpgradeIsolatedPerpetualToCross(ctx, in) } info := &grpc.UnaryServerInfo{ Server: srv, - FullMethod: "/dydxprotocol.perpetuals.Msg/UpgradeMarketFromIsolatedToCross", + FullMethod: "/dydxprotocol.perpetuals.Msg/UpgradeIsolatedPerpetualToCross", } handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(MsgServer).UpgradeMarketFromIsolatedToCross(ctx, req.(*MsgUpgradeMarketFromIsolatedToCross)) + return srv.(MsgServer).UpgradeIsolatedPerpetualToCross(ctx, req.(*MsgUpgradeIsolatedPerpetualToCross)) } return interceptor(ctx, in, info, handler) } @@ -969,8 +970,8 @@ var _Msg_serviceDesc = grpc.ServiceDesc{ Handler: _Msg_UpdateParams_Handler, }, { - MethodName: "UpgradeMarketFromIsolatedToCross", - Handler: _Msg_UpgradeMarketFromIsolatedToCross_Handler, + MethodName: "UpgradeIsolatedPerpetualToCross", + Handler: _Msg_UpgradeIsolatedPerpetualToCross_Handler, }, }, Streams: []grpc.StreamDesc{}, @@ -1322,7 +1323,7 @@ func (m *MsgUpdateParamsResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) return len(dAtA) - i, nil } -func (m *MsgUpgradeMarketFromIsolatedToCross) Marshal() (dAtA []byte, err error) { +func (m *MsgUpgradeIsolatedPerpetualToCross) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) n, err := m.MarshalToSizedBuffer(dAtA[:size]) @@ -1332,12 +1333,12 @@ func (m *MsgUpgradeMarketFromIsolatedToCross) Marshal() (dAtA []byte, err error) return dAtA[:n], nil } -func (m *MsgUpgradeMarketFromIsolatedToCross) MarshalTo(dAtA []byte) (int, error) { +func (m *MsgUpgradeIsolatedPerpetualToCross) MarshalTo(dAtA []byte) (int, error) { size := m.Size() return m.MarshalToSizedBuffer(dAtA[:size]) } -func (m *MsgUpgradeMarketFromIsolatedToCross) MarshalToSizedBuffer(dAtA []byte) (int, error) { +func (m *MsgUpgradeIsolatedPerpetualToCross) MarshalToSizedBuffer(dAtA []byte) (int, error) { i := len(dAtA) _ = i var l int @@ -1357,7 +1358,7 @@ func (m *MsgUpgradeMarketFromIsolatedToCross) MarshalToSizedBuffer(dAtA []byte) return len(dAtA) - i, nil } -func (m *MsgUpgradeMarketFromIsolatedToCrossResponse) Marshal() (dAtA []byte, err error) { +func (m *MsgUpgradeIsolatedPerpetualToCrossResponse) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) n, err := m.MarshalToSizedBuffer(dAtA[:size]) @@ -1367,12 +1368,12 @@ func (m *MsgUpgradeMarketFromIsolatedToCrossResponse) Marshal() (dAtA []byte, er return dAtA[:n], nil } -func (m *MsgUpgradeMarketFromIsolatedToCrossResponse) MarshalTo(dAtA []byte) (int, error) { +func (m *MsgUpgradeIsolatedPerpetualToCrossResponse) MarshalTo(dAtA []byte) (int, error) { size := m.Size() return m.MarshalToSizedBuffer(dAtA[:size]) } -func (m *MsgUpgradeMarketFromIsolatedToCrossResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { +func (m *MsgUpgradeIsolatedPerpetualToCrossResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { i := len(dAtA) _ = i var l int @@ -1526,7 +1527,7 @@ func (m *MsgUpdateParamsResponse) Size() (n int) { return n } -func (m *MsgUpgradeMarketFromIsolatedToCross) Size() (n int) { +func (m *MsgUpgradeIsolatedPerpetualToCross) Size() (n int) { if m == nil { return 0 } @@ -1542,7 +1543,7 @@ func (m *MsgUpgradeMarketFromIsolatedToCross) Size() (n int) { return n } -func (m *MsgUpgradeMarketFromIsolatedToCrossResponse) Size() (n int) { +func (m *MsgUpgradeIsolatedPerpetualToCrossResponse) Size() (n int) { if m == nil { return 0 } @@ -2439,7 +2440,7 @@ func (m *MsgUpdateParamsResponse) Unmarshal(dAtA []byte) error { } return nil } -func (m *MsgUpgradeMarketFromIsolatedToCross) Unmarshal(dAtA []byte) error { +func (m *MsgUpgradeIsolatedPerpetualToCross) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 for iNdEx < l { @@ -2462,10 +2463,10 @@ func (m *MsgUpgradeMarketFromIsolatedToCross) Unmarshal(dAtA []byte) error { fieldNum := int32(wire >> 3) wireType := int(wire & 0x7) if wireType == 4 { - return fmt.Errorf("proto: MsgUpgradeMarketFromIsolatedToCross: wiretype end group for non-group") + return fmt.Errorf("proto: MsgUpgradeIsolatedPerpetualToCross: wiretype end group for non-group") } if fieldNum <= 0 { - return fmt.Errorf("proto: MsgUpgradeMarketFromIsolatedToCross: illegal tag %d (wire type %d)", fieldNum, wire) + return fmt.Errorf("proto: MsgUpgradeIsolatedPerpetualToCross: illegal tag %d (wire type %d)", fieldNum, wire) } switch fieldNum { case 1: @@ -2540,7 +2541,7 @@ func (m *MsgUpgradeMarketFromIsolatedToCross) Unmarshal(dAtA []byte) error { } return nil } -func (m *MsgUpgradeMarketFromIsolatedToCrossResponse) Unmarshal(dAtA []byte) error { +func (m *MsgUpgradeIsolatedPerpetualToCrossResponse) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 for iNdEx < l { @@ -2563,10 +2564,10 @@ func (m *MsgUpgradeMarketFromIsolatedToCrossResponse) Unmarshal(dAtA []byte) err fieldNum := int32(wire >> 3) wireType := int(wire & 0x7) if wireType == 4 { - return fmt.Errorf("proto: MsgUpgradeMarketFromIsolatedToCrossResponse: wiretype end group for non-group") + return fmt.Errorf("proto: MsgUpgradeIsolatedPerpetualToCrossResponse: wiretype end group for non-group") } if fieldNum <= 0 { - return fmt.Errorf("proto: MsgUpgradeMarketFromIsolatedToCrossResponse: illegal tag %d (wire type %d)", fieldNum, wire) + return fmt.Errorf("proto: MsgUpgradeIsolatedPerpetualToCrossResponse: illegal tag %d (wire type %d)", fieldNum, wire) } switch fieldNum { default: From 8dc1e4f30ff00f101d5249eda4b15887956430a4 Mon Sep 17 00:00:00 2001 From: Harry Wray Date: Thu, 31 Oct 2024 12:07:17 -0400 Subject: [PATCH 03/29] Update --- protocol/x/clob/keeper/deleveraging.go | 31 ++++++++++------ protocol/x/clob/types/expected_keepers.go | 2 ++ ...ver_upgrade_isolated_perpetual_to_cross.go | 36 +------------------ protocol/x/perpetuals/keeper/perpetual.go | 23 ++++++++++++ .../x/perpetuals/types/expected_keepers.go | 6 ++++ protocol/x/perpetuals/types/types.go | 6 ++-- 6 files changed, 55 insertions(+), 49 deletions(-) diff --git a/protocol/x/clob/keeper/deleveraging.go b/protocol/x/clob/keeper/deleveraging.go index 3e698c5960..702bea0c1a 100644 --- a/protocol/x/clob/keeper/deleveraging.go +++ b/protocol/x/clob/keeper/deleveraging.go @@ -167,23 +167,32 @@ func (k Keeper) GetCrossInsuranceFundBalance(ctx sdk.Context) (balance *big.Int) return insuranceFundBalance.Amount.BigInt() } -func (k Keeper) TransferIsolatedInsuranceFundsToCross(ctx sdk.Context, perpetualId uint32) (balance *big.Int) { - usdcAsset, exists := k.assetsKeeper.GetAsset(ctx, assettypes.AssetUsdc.Id) - if !exists { - panic("GetInsuranceFundBalance: Usdc asset not found in state") +// TODO This probably shouldn't live in deleveraging.go +func (k Keeper) TransferIsolatedInsuranceFundToCross(ctx sdk.Context, perpetualId uint32) error { + isolatedInsuranceFundBalance := k.GetInsuranceFundBalance(ctx, perpetualId) + + _, coinToTransfer, err := k.assetsKeeper.ConvertAssetToCoin( + ctx, + assettypes.AssetUsdc.Id, + new(big.Int).Abs(isolatedInsuranceFundBalance), + ) + if err != nil { + panic(err) } - insuranceFundAddr, err := k.perpetualsKeeper.GetInsuranceFundModuleAddress(ctx, perpetualId) + + isolatedInsuranceFundAddr, err := k.perpetualsKeeper.GetInsuranceFundModuleAddress(ctx, perpetualId) if err != nil { return nil } - insuranceFundBalance := k.bankKeeper.GetBalance( + + crossInsuranceFundAddr := perptypes.InsuranceFundModuleAddress + + return k.bankKeeper.SendCoins( ctx, - insuranceFundAddr, - usdcAsset.Denom, + isolatedInsuranceFundAddr, + crossInsuranceFundAddr, + []sdk.Coin{coinToTransfer}, ) - - // Return as big.Int. - return insuranceFundBalance.Amount.BigInt() } // CanDeleverageSubaccount returns true if a subaccount can be deleveraged. diff --git a/protocol/x/clob/types/expected_keepers.go b/protocol/x/clob/types/expected_keepers.go index 846cc7d539..cf85a638e8 100644 --- a/protocol/x/clob/types/expected_keepers.go +++ b/protocol/x/clob/types/expected_keepers.go @@ -91,6 +91,7 @@ type SubaccountsKeeper interface { type AssetsKeeper interface { GetAsset(ctx sdk.Context, id uint32) (val assettypes.Asset, exists bool) + ConvertAssetToCoin(ctx sdk.Context, assetId uint32, quantums *big.Int) (*big.Int, sdk.Coin, error) } type BlockTimeKeeper interface { @@ -157,6 +158,7 @@ type AccountKeeper interface { type BankKeeper interface { SpendableCoins(ctx context.Context, addr sdk.AccAddress) sdk.Coins GetBalance(ctx context.Context, addr sdk.AccAddress, denom string) sdk.Coin + SendCoins(ctx context.Context, fromAddr, toAddr sdk.AccAddress, amt sdk.Coins) error } type RewardsKeeper interface { diff --git a/protocol/x/perpetuals/keeper/msg_server_upgrade_isolated_perpetual_to_cross.go b/protocol/x/perpetuals/keeper/msg_server_upgrade_isolated_perpetual_to_cross.go index 5ce492f49c..4ef89a1572 100644 --- a/protocol/x/perpetuals/keeper/msg_server_upgrade_isolated_perpetual_to_cross.go +++ b/protocol/x/perpetuals/keeper/msg_server_upgrade_isolated_perpetual_to_cross.go @@ -2,7 +2,6 @@ package keeper import ( "context" - "math/big" errorsmod "cosmossdk.io/errors" govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" @@ -24,46 +23,13 @@ func (k msgServer) UpgradeIsolatedPerpetualToCross( ctx := lib.UnwrapSDKContext(goCtx, types.ModuleName) - isolatedInsuranceFundAddress, err := k.Keeper.GetInsuranceFundModuleAddress(ctx, msg.PerpetualId) - if err != nil { - return nil, err - } - - _, err = k.Keeper.SetPerpetualMarketType( + err := k.Keeper.UpgradeIsolatedPerpetualToCross( ctx, msg.PerpetualId, - types.PerpetualMarketType_PERPETUAL_MARKET_TYPE_CROSS, ) if err != nil { return nil, err } - crossInsuranceFundAddress, err := k.Keeper.GetInsuranceFundModuleAddress(ctx, msg.PerpetualId) - if err != nil { - return nil, err - } - - isolatedInsuranceFundBalance := k.Keeper. - - _, coinToTransfer, err := k.assetsKeeper.ConvertAssetToCoin( - ctx, - assettypes.AssetUsdc.Id, - new(big.Int).Abs(insuranceFundDelta), - ) - - // TODO Move insurance fund for perpetual to primary insurance fund - return k.bankKeeper.SendCoins( - ctx, - isolatedInsuranceFundAddress, - crossInsuranceFundAddress, - []sdk.Coin{coinToTransfer}, - ) - - // clob/keeper/deleveraging.go func (k Keeper) GetInsuranceFundBalance(ctx sdk.Context, perpetualId uint32) (balance *big.Int) { - - // TODO Move collateral pool for perpetual to subaccounts module - - // TODO Propagate changes to indexer - return &types.MsgUpgradeIsolatedPerpetualToCrossResponse{}, nil } diff --git a/protocol/x/perpetuals/keeper/perpetual.go b/protocol/x/perpetuals/keeper/perpetual.go index 6a75e83723..16bd4a444d 100644 --- a/protocol/x/perpetuals/keeper/perpetual.go +++ b/protocol/x/perpetuals/keeper/perpetual.go @@ -251,6 +251,29 @@ func (k Keeper) GetAllPerpetuals(ctx sdk.Context) (list []types.Perpetual) { return list } +func (k Keeper) UpgradeIsolatedPerpetualToCross( + ctx sdk.Context, + id uint32, +) error { + err := k.clobKeeper.TransferIsolatedInsuranceFundToCross(ctx, id) + + _, err = k.SetPerpetualMarketType( + ctx, + id, + types.PerpetualMarketType_PERPETUAL_MARKET_TYPE_CROSS, + ) + if err != nil { + return err + } + + // TODO Move collateral pool for perpetual to subaccounts module + // See transferCollateralForIsolatedPerpetual()? + + // TODO Propagate changes to indexer + + return nil +} + // processStoredPremiums combines all stored premiums into a single premium value // for each `MarketPremiums` in the premium storage. // Returns a mapping from perpetual Id to summarized premium value. diff --git a/protocol/x/perpetuals/types/expected_keepers.go b/protocol/x/perpetuals/types/expected_keepers.go index d83f970b2b..0356f681fb 100644 --- a/protocol/x/perpetuals/types/expected_keepers.go +++ b/protocol/x/perpetuals/types/expected_keepers.go @@ -33,6 +33,12 @@ type PerpetualsClobKeeper interface { isActive bool, err error, ) + TransferIsolatedInsuranceFundToCross( + ctx sdk.Context, + perpetualId uint32, + ) ( + err error, + ) } // EpochsKeeper defines the expected epochs keeper to get epoch info. diff --git a/protocol/x/perpetuals/types/types.go b/protocol/x/perpetuals/types/types.go index 1f6a95908f..cefbfa8dec 100644 --- a/protocol/x/perpetuals/types/types.go +++ b/protocol/x/perpetuals/types/types.go @@ -118,10 +118,10 @@ type PerpetualsKeeper interface { ctx sdk.Context, perpetual Perpetual, ) error - GetInsuranceFundModuleAddress( + UpgradeIsolatedPerpetualToCross( ctx sdk.Context, - perpetualId uint32, - ) (sdk.AccAddress, error) + id uint32, + ) error } // OpenInterestDelta represents a (perpId, openInterestDelta) tuple. From 226004a3305e5cec3347167b5764288bb98cf434 Mon Sep 17 00:00:00 2001 From: Harry Wray Date: Thu, 31 Oct 2024 12:13:26 -0400 Subject: [PATCH 04/29] Update --- protocol/x/perpetuals/keeper/perpetual.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/protocol/x/perpetuals/keeper/perpetual.go b/protocol/x/perpetuals/keeper/perpetual.go index 16bd4a444d..6738daf453 100644 --- a/protocol/x/perpetuals/keeper/perpetual.go +++ b/protocol/x/perpetuals/keeper/perpetual.go @@ -256,6 +256,9 @@ func (k Keeper) UpgradeIsolatedPerpetualToCross( id uint32, ) error { err := k.clobKeeper.TransferIsolatedInsuranceFundToCross(ctx, id) + if err != nil { + return err + } _, err = k.SetPerpetualMarketType( ctx, From 62ac96eabc46ce20164749be7f5d3db3dcef82c4 Mon Sep 17 00:00:00 2001 From: Harry Wray Date: Mon, 4 Nov 2024 14:45:14 -0500 Subject: [PATCH 05/29] Update --- proto/dydxprotocol/listing/tx.proto | 22 +- proto/dydxprotocol/perpetuals/tx.proto | 18 - protocol/x/clob/keeper/deleveraging.go | 52 +- protocol/x/clob/types/expected_keepers.go | 6 +- protocol/x/clob/types/liquidations_keeper.go | 5 +- protocol/x/listing/keeper/listing.go | 26 + ...ver_upgrade_isolated_perpetual_to_cross.go | 2 +- ...sg_upgrade_isolated_perpetual_to_cross.go} | 2 +- ...grade_isolated_perpetual_to_cross_test.go} | 4 +- protocol/x/listing/types/expected_keepers.go | 5 + protocol/x/listing/types/tx.pb.go | 445 ++++++++++++-- protocol/x/perpetuals/keeper/perpetual.go | 26 - .../x/perpetuals/types/expected_keepers.go | 6 - protocol/x/perpetuals/types/tx.pb.go | 455 ++------------ protocol/x/perpetuals/types/types.go | 4 - .../subaccounts/keeper/isolated_subaccount.go | 52 ++ protocol/x/subaccounts/types/tx.pb.go | 578 ++++++++++++++++++ 17 files changed, 1145 insertions(+), 563 deletions(-) rename protocol/x/{perpetuals => listing}/keeper/msg_server_upgrade_isolated_perpetual_to_cross.go (92%) rename protocol/x/{perpetuals/types/message_upgrade_isolated_perpetual_to_cross.go => listing/keeper/msg_upgrade_isolated_perpetual_to_cross.go} (97%) rename protocol/x/{perpetuals/types/message_upgrade_isolated_perpetual_to_cross_test.go => listing/keeper/msg_upgrade_isolated_perpetual_to_cross_test.go} (89%) create mode 100644 protocol/x/subaccounts/types/tx.pb.go diff --git a/proto/dydxprotocol/listing/tx.proto b/proto/dydxprotocol/listing/tx.proto index 8f0808de9e..56ae5f525b 100644 --- a/proto/dydxprotocol/listing/tx.proto +++ b/proto/dydxprotocol/listing/tx.proto @@ -22,6 +22,10 @@ service Msg { // SetListingVaultDepositParams sets PML megavault deposit params rpc SetListingVaultDepositParams(MsgSetListingVaultDepositParams) returns (MsgSetListingVaultDepositParamsResponse); + + // UpgradeIsolatedPerpetualToCross upgrades a perpetual from isolated to cross margin + rpc UpgradeIsolatedPerpetualToCross(MsgUpgradeIsolatedPerpetualToCross) + returns (MsgUpgradeIsolatedPerpetualToCrossResponse); } // MsgSetMarketsHardCap is used to set a hard cap on the number of markets @@ -69,4 +73,20 @@ message MsgSetListingVaultDepositParams { // MsgSetListingVaultDepositParamsResponse defines the // MsgSetListingVaultDepositParams response -message MsgSetListingVaultDepositParamsResponse {} \ No newline at end of file +message MsgSetListingVaultDepositParamsResponse {} + +// MsgUpgradeIsolatedPerpetualToCross is used to upgrade a market from +// isolated margin to cross margin. +message MsgUpgradeIsolatedPerpetualToCross { + // Authority is the address that controls the module. + option (cosmos.msg.v1.signer) = "authority"; + + string authority = 1 [ (cosmos_proto.scalar) = "cosmos.AddressString" ]; + + // ID of the perpetual to be upgraded to CROSS + uint32 perpetual_id = 2; +} + +// MsgUpgradeIsolatedPerpetualToCrossResponse defines the +// UpgradeIsolatedPerpetualToCross response type. +message MsgUpgradeIsolatedPerpetualToCrossResponse {} \ No newline at end of file diff --git a/proto/dydxprotocol/perpetuals/tx.proto b/proto/dydxprotocol/perpetuals/tx.proto index c48c1a1c2e..3a9847cd81 100644 --- a/proto/dydxprotocol/perpetuals/tx.proto +++ b/proto/dydxprotocol/perpetuals/tx.proto @@ -25,8 +25,6 @@ service Msg { returns (MsgUpdatePerpetualParamsResponse); // UpdateParams updates the parameters of perpetuals module. rpc UpdateParams(MsgUpdateParams) returns (MsgUpdateParamsResponse); - // UpgradeIsolatedPerpetualToCross upgrades a perpetual from isolated to cross margin. - rpc UpgradeIsolatedPerpetualToCross(MsgUpgradeIsolatedPerpetualToCross) returns (MsgUpgradeIsolatedPerpetualToCrossResponse); } // MsgCreatePerpetual is a message used by x/gov to create a new perpetual. @@ -105,19 +103,3 @@ message MsgUpdateParams { // MsgUpdateParamsResponse defines the UpdateParams response type. message MsgUpdateParamsResponse {} - -// MsgUpgradeIsolatedPerpetualToCross is used to upgrade a market from -// isolated margin to cross margin. -message MsgUpgradeIsolatedPerpetualToCross { - // Authority is the address that controls the module. - option (cosmos.msg.v1.signer) = "authority"; - - string authority = 1 [ (cosmos_proto.scalar) = "cosmos.AddressString" ]; - - // ID of the perpetual to be upgraded to CROSS - uint32 perpetual_id = 2; -} - -// MsgUpgradeIsolatedPerpetualToCrossResponse defines the -// UpgradeIsolatedPerpetualToCross response type. -message MsgUpgradeIsolatedPerpetualToCrossResponse {} diff --git a/protocol/x/clob/keeper/deleveraging.go b/protocol/x/clob/keeper/deleveraging.go index 702bea0c1a..49954d29e5 100644 --- a/protocol/x/clob/keeper/deleveraging.go +++ b/protocol/x/clob/keeper/deleveraging.go @@ -130,28 +130,6 @@ func (k Keeper) MaybeDeleverageSubaccount( return quantumsDeleveraged, err } -// GetInsuranceFundBalance returns the current balance of the specific insurance fund based on the -// perpetual (in quote quantums). -// This calls the Bank Keeper’s GetBalance() function for the Module Address of the insurance fund. -func (k Keeper) GetInsuranceFundBalance(ctx sdk.Context, perpetualId uint32) (balance *big.Int) { - usdcAsset, exists := k.assetsKeeper.GetAsset(ctx, assettypes.AssetUsdc.Id) - if !exists { - panic("GetInsuranceFundBalance: Usdc asset not found in state") - } - insuranceFundAddr, err := k.perpetualsKeeper.GetInsuranceFundModuleAddress(ctx, perpetualId) - if err != nil { - return nil - } - insuranceFundBalance := k.bankKeeper.GetBalance( - ctx, - insuranceFundAddr, - usdcAsset.Denom, - ) - - // Return as big.Int. - return insuranceFundBalance.Amount.BigInt() -} - func (k Keeper) GetCrossInsuranceFundBalance(ctx sdk.Context) (balance *big.Int) { usdcAsset, exists := k.assetsKeeper.GetAsset(ctx, assettypes.AssetUsdc.Id) if !exists { @@ -167,34 +145,6 @@ func (k Keeper) GetCrossInsuranceFundBalance(ctx sdk.Context) (balance *big.Int) return insuranceFundBalance.Amount.BigInt() } -// TODO This probably shouldn't live in deleveraging.go -func (k Keeper) TransferIsolatedInsuranceFundToCross(ctx sdk.Context, perpetualId uint32) error { - isolatedInsuranceFundBalance := k.GetInsuranceFundBalance(ctx, perpetualId) - - _, coinToTransfer, err := k.assetsKeeper.ConvertAssetToCoin( - ctx, - assettypes.AssetUsdc.Id, - new(big.Int).Abs(isolatedInsuranceFundBalance), - ) - if err != nil { - panic(err) - } - - isolatedInsuranceFundAddr, err := k.perpetualsKeeper.GetInsuranceFundModuleAddress(ctx, perpetualId) - if err != nil { - return nil - } - - crossInsuranceFundAddr := perptypes.InsuranceFundModuleAddress - - return k.bankKeeper.SendCoins( - ctx, - isolatedInsuranceFundAddr, - crossInsuranceFundAddr, - []sdk.Coin{coinToTransfer}, - ) -} - // CanDeleverageSubaccount returns true if a subaccount can be deleveraged. // This function returns two booleans, shouldDeleverageAtBankruptcyPrice and shouldDeleverageAtOraclePrice. // - shouldDeleverageAtBankruptcyPrice is true if the subaccount has negative TNC. @@ -307,7 +257,7 @@ func (k Keeper) IsValidInsuranceFundDelta(ctx sdk.Context, insuranceFundDelta *b // The insurance fund delta is valid if the insurance fund balance is non-negative after adding // the delta. - currentInsuranceFundBalance := k.GetInsuranceFundBalance(ctx, perpetualId) + currentInsuranceFundBalance := k.subaccountsKeeper.GetInsuranceFundBalance(ctx, perpetualId) return new(big.Int).Add(currentInsuranceFundBalance, insuranceFundDelta).Sign() >= 0 } diff --git a/protocol/x/clob/types/expected_keepers.go b/protocol/x/clob/types/expected_keepers.go index cf85a638e8..7ff3d1c9f5 100644 --- a/protocol/x/clob/types/expected_keepers.go +++ b/protocol/x/clob/types/expected_keepers.go @@ -87,11 +87,14 @@ type SubaccountsKeeper interface { revSharesForFill revsharetypes.RevSharesForFill, fillForProcess FillForProcess, ) error + GetInsuranceFundBalance( + ctx sdk.Context, + perpetualId uint32, + ) *big.Int } type AssetsKeeper interface { GetAsset(ctx sdk.Context, id uint32) (val assettypes.Asset, exists bool) - ConvertAssetToCoin(ctx sdk.Context, assetId uint32, quantums *big.Int) (*big.Int, sdk.Coin, error) } type BlockTimeKeeper interface { @@ -158,7 +161,6 @@ type AccountKeeper interface { type BankKeeper interface { SpendableCoins(ctx context.Context, addr sdk.AccAddress) sdk.Coins GetBalance(ctx context.Context, addr sdk.AccAddress, denom string) sdk.Coin - SendCoins(ctx context.Context, fromAddr, toAddr sdk.AccAddress, amt sdk.Coins) error } type RewardsKeeper interface { diff --git a/protocol/x/clob/types/liquidations_keeper.go b/protocol/x/clob/types/liquidations_keeper.go index b649a8e6c8..7b72d364ea 100644 --- a/protocol/x/clob/types/liquidations_keeper.go +++ b/protocol/x/clob/types/liquidations_keeper.go @@ -51,7 +51,10 @@ type LiquidationsKeeper interface { fillablePrice *big.Rat, err error, ) - GetInsuranceFundBalance(ctx sdk.Context, perpetualId uint32) (balance *big.Int) + GetInsuranceFundBalance( + ctx sdk.Context, + perpetualId uint32, + ) (balance *big.Int) GetLiquidationInsuranceFundDelta( ctx sdk.Context, subaccountId satypes.SubaccountId, diff --git a/protocol/x/listing/keeper/listing.go b/protocol/x/listing/keeper/listing.go index 1a126dd527..12aa61a446 100644 --- a/protocol/x/listing/keeper/listing.go +++ b/protocol/x/listing/keeper/listing.go @@ -152,6 +152,32 @@ func (k Keeper) CreatePerpetual( return perpetual.GetId(), nil } +func (k Keeper) UpgradeIsolatedPerpetualToCross( + ctx sdk.Context, + id uint32, +) error { + err := k.clobKeeper.TransferIsolatedInsuranceFundToCross(ctx, id) + if err != nil { + return err + } + + _, err = k.PerpetualsKeeper.SetPerpetualMarketType( + ctx, + id, + perpetualtypes.PerpetualMarketType_PERPETUAL_MARKET_TYPE_CROSS, + ) + if err != nil { + return err + } + + // TODO Move collateral pool for perpetual to subaccounts module + // See transferCollateralForIsolatedPerpetual()? + + // TODO Propagate changes to indexer + + return nil +} + // Function to set listing vault deposit params in module store func (k Keeper) SetListingVaultDepositParams( ctx sdk.Context, diff --git a/protocol/x/perpetuals/keeper/msg_server_upgrade_isolated_perpetual_to_cross.go b/protocol/x/listing/keeper/msg_server_upgrade_isolated_perpetual_to_cross.go similarity index 92% rename from protocol/x/perpetuals/keeper/msg_server_upgrade_isolated_perpetual_to_cross.go rename to protocol/x/listing/keeper/msg_server_upgrade_isolated_perpetual_to_cross.go index 4ef89a1572..70c7341a64 100644 --- a/protocol/x/perpetuals/keeper/msg_server_upgrade_isolated_perpetual_to_cross.go +++ b/protocol/x/listing/keeper/msg_server_upgrade_isolated_perpetual_to_cross.go @@ -6,7 +6,7 @@ import ( errorsmod "cosmossdk.io/errors" govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" "github.com/dydxprotocol/v4-chain/protocol/lib" - "github.com/dydxprotocol/v4-chain/protocol/x/perpetuals/types" + "github.com/dydxprotocol/v4-chain/protocol/x/subaccounts/types" ) func (k msgServer) UpgradeIsolatedPerpetualToCross( diff --git a/protocol/x/perpetuals/types/message_upgrade_isolated_perpetual_to_cross.go b/protocol/x/listing/keeper/msg_upgrade_isolated_perpetual_to_cross.go similarity index 97% rename from protocol/x/perpetuals/types/message_upgrade_isolated_perpetual_to_cross.go rename to protocol/x/listing/keeper/msg_upgrade_isolated_perpetual_to_cross.go index bcd4ae6c52..ba1c809f5a 100644 --- a/protocol/x/perpetuals/types/message_upgrade_isolated_perpetual_to_cross.go +++ b/protocol/x/listing/keeper/msg_upgrade_isolated_perpetual_to_cross.go @@ -1,4 +1,4 @@ -package types +package keeper import ( "fmt" diff --git a/protocol/x/perpetuals/types/message_upgrade_isolated_perpetual_to_cross_test.go b/protocol/x/listing/keeper/msg_upgrade_isolated_perpetual_to_cross_test.go similarity index 89% rename from protocol/x/perpetuals/types/message_upgrade_isolated_perpetual_to_cross_test.go rename to protocol/x/listing/keeper/msg_upgrade_isolated_perpetual_to_cross_test.go index 5aa72e93b1..f855b3ef30 100644 --- a/protocol/x/perpetuals/types/message_upgrade_isolated_perpetual_to_cross_test.go +++ b/protocol/x/listing/keeper/msg_upgrade_isolated_perpetual_to_cross_test.go @@ -1,9 +1,9 @@ -package types_test +package keeper_test import ( "testing" - types "github.com/dydxprotocol/v4-chain/protocol/x/perpetuals/types" + types "github.com/dydxprotocol/v4-chain/protocol/x/listing/types" "github.com/stretchr/testify/require" ) diff --git a/protocol/x/listing/types/expected_keepers.go b/protocol/x/listing/types/expected_keepers.go index e5a8b6693a..65bcdcb7d8 100644 --- a/protocol/x/listing/types/expected_keepers.go +++ b/protocol/x/listing/types/expected_keepers.go @@ -65,6 +65,11 @@ type PerpetualsKeeper interface { ) (perpetualtypes.Perpetual, error) AcquireNextPerpetualID(ctx sdk.Context) uint32 GetAllPerpetuals(ctx sdk.Context) (list []perpetualtypes.Perpetual) + SetPerpetualMarketType( + ctx sdk.Context, + id uint32, + marketType perpetualtypes.PerpetualMarketType, + ) (perpetualtypes.Perpetual, error) } type VaultKeeper interface { diff --git a/protocol/x/listing/types/tx.pb.go b/protocol/x/listing/types/tx.pb.go index 4d8ce4644e..a694d8fd17 100644 --- a/protocol/x/listing/types/tx.pb.go +++ b/protocol/x/listing/types/tx.pb.go @@ -312,6 +312,103 @@ func (m *MsgSetListingVaultDepositParamsResponse) XXX_DiscardUnknown() { var xxx_messageInfo_MsgSetListingVaultDepositParamsResponse proto.InternalMessageInfo +// MsgUpgradeIsolatedPerpetualToCross is used to upgrade a market from +// isolated margin to cross margin. +type MsgUpgradeIsolatedPerpetualToCross struct { + Authority string `protobuf:"bytes,1,opt,name=authority,proto3" json:"authority,omitempty"` + // ID of the perpetual to be upgraded to CROSS + PerpetualId uint32 `protobuf:"varint,2,opt,name=perpetual_id,json=perpetualId,proto3" json:"perpetual_id,omitempty"` +} + +func (m *MsgUpgradeIsolatedPerpetualToCross) Reset() { *m = MsgUpgradeIsolatedPerpetualToCross{} } +func (m *MsgUpgradeIsolatedPerpetualToCross) String() string { return proto.CompactTextString(m) } +func (*MsgUpgradeIsolatedPerpetualToCross) ProtoMessage() {} +func (*MsgUpgradeIsolatedPerpetualToCross) Descriptor() ([]byte, []int) { + return fileDescriptor_144a579c1e2dcb94, []int{6} +} +func (m *MsgUpgradeIsolatedPerpetualToCross) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgUpgradeIsolatedPerpetualToCross) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgUpgradeIsolatedPerpetualToCross.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *MsgUpgradeIsolatedPerpetualToCross) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgUpgradeIsolatedPerpetualToCross.Merge(m, src) +} +func (m *MsgUpgradeIsolatedPerpetualToCross) XXX_Size() int { + return m.Size() +} +func (m *MsgUpgradeIsolatedPerpetualToCross) XXX_DiscardUnknown() { + xxx_messageInfo_MsgUpgradeIsolatedPerpetualToCross.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgUpgradeIsolatedPerpetualToCross proto.InternalMessageInfo + +func (m *MsgUpgradeIsolatedPerpetualToCross) GetAuthority() string { + if m != nil { + return m.Authority + } + return "" +} + +func (m *MsgUpgradeIsolatedPerpetualToCross) GetPerpetualId() uint32 { + if m != nil { + return m.PerpetualId + } + return 0 +} + +// MsgUpgradeIsolatedPerpetualToCrossResponse defines the +// UpgradeIsolatedPerpetualToCross response type. +type MsgUpgradeIsolatedPerpetualToCrossResponse struct { +} + +func (m *MsgUpgradeIsolatedPerpetualToCrossResponse) Reset() { + *m = MsgUpgradeIsolatedPerpetualToCrossResponse{} +} +func (m *MsgUpgradeIsolatedPerpetualToCrossResponse) String() string { + return proto.CompactTextString(m) +} +func (*MsgUpgradeIsolatedPerpetualToCrossResponse) ProtoMessage() {} +func (*MsgUpgradeIsolatedPerpetualToCrossResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_144a579c1e2dcb94, []int{7} +} +func (m *MsgUpgradeIsolatedPerpetualToCrossResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgUpgradeIsolatedPerpetualToCrossResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgUpgradeIsolatedPerpetualToCrossResponse.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *MsgUpgradeIsolatedPerpetualToCrossResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgUpgradeIsolatedPerpetualToCrossResponse.Merge(m, src) +} +func (m *MsgUpgradeIsolatedPerpetualToCrossResponse) XXX_Size() int { + return m.Size() +} +func (m *MsgUpgradeIsolatedPerpetualToCrossResponse) XXX_DiscardUnknown() { + xxx_messageInfo_MsgUpgradeIsolatedPerpetualToCrossResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgUpgradeIsolatedPerpetualToCrossResponse proto.InternalMessageInfo + func init() { proto.RegisterType((*MsgSetMarketsHardCap)(nil), "dydxprotocol.listing.MsgSetMarketsHardCap") proto.RegisterType((*MsgSetMarketsHardCapResponse)(nil), "dydxprotocol.listing.MsgSetMarketsHardCapResponse") @@ -319,46 +416,52 @@ func init() { proto.RegisterType((*MsgCreateMarketPermissionlessResponse)(nil), "dydxprotocol.listing.MsgCreateMarketPermissionlessResponse") proto.RegisterType((*MsgSetListingVaultDepositParams)(nil), "dydxprotocol.listing.MsgSetListingVaultDepositParams") proto.RegisterType((*MsgSetListingVaultDepositParamsResponse)(nil), "dydxprotocol.listing.MsgSetListingVaultDepositParamsResponse") + proto.RegisterType((*MsgUpgradeIsolatedPerpetualToCross)(nil), "dydxprotocol.listing.MsgUpgradeIsolatedPerpetualToCross") + proto.RegisterType((*MsgUpgradeIsolatedPerpetualToCrossResponse)(nil), "dydxprotocol.listing.MsgUpgradeIsolatedPerpetualToCrossResponse") } func init() { proto.RegisterFile("dydxprotocol/listing/tx.proto", fileDescriptor_144a579c1e2dcb94) } var fileDescriptor_144a579c1e2dcb94 = []byte{ - // 535 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x54, 0xcd, 0x6e, 0xd3, 0x40, - 0x10, 0xce, 0x52, 0x54, 0xa9, 0x0b, 0x45, 0xaa, 0x15, 0x41, 0xb0, 0x5a, 0xb7, 0x44, 0x82, 0xfe, - 0x48, 0xb5, 0x45, 0x0a, 0x48, 0x14, 0x71, 0x20, 0x45, 0x08, 0x04, 0x91, 0x2a, 0x47, 0xe2, 0xc0, - 0xc5, 0xda, 0xd8, 0x8b, 0xbd, 0x6a, 0xec, 0xb5, 0x76, 0xd6, 0x55, 0x72, 0xe5, 0x01, 0x80, 0x03, - 0x07, 0xce, 0x3c, 0x01, 0x07, 0x0e, 0x3c, 0x42, 0x8f, 0x15, 0x27, 0x4e, 0x08, 0x25, 0x07, 0x5e, - 0x03, 0xc5, 0xbb, 0xf9, 0x53, 0x9d, 0x80, 0x72, 0xf2, 0xce, 0xce, 0x7c, 0xdf, 0x7c, 0xe3, 0x6f, - 0xb4, 0x78, 0x23, 0xe8, 0x06, 0x9d, 0x54, 0x70, 0xc9, 0x7d, 0xde, 0x76, 0xda, 0x0c, 0x24, 0x4b, - 0x42, 0x47, 0x76, 0xec, 0xfc, 0xce, 0x28, 0x4f, 0xa6, 0x6d, 0x9d, 0x36, 0x6f, 0xfa, 0x1c, 0x62, - 0x0e, 0x5e, 0x9e, 0x70, 0x54, 0xa0, 0x00, 0xe6, 0x0d, 0x15, 0x39, 0x31, 0x84, 0xce, 0xe9, 0xdd, - 0xc1, 0x47, 0x27, 0xca, 0x21, 0x0f, 0xb9, 0x02, 0x0c, 0x4e, 0xfa, 0x76, 0x77, 0xaa, 0x3d, 0x64, - 0x2d, 0xe2, 0xfb, 0x3c, 0x4b, 0x24, 0x4c, 0x9c, 0x75, 0xe9, 0xad, 0x42, 0xa5, 0x29, 0x11, 0x24, - 0xd6, 0xcd, 0xab, 0x1f, 0x10, 0x2e, 0x37, 0x20, 0x6c, 0x52,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x30, 0x79, 0x9c, 0xfb, 0xb3, 0xb0, 0x01, 0x0d, 0xbc, 0xac, 0x1c, 0xd6, 0xe3, 0x39, 0x76, - 0xd1, 0x42, 0xda, 0x33, 0x1b, 0xd7, 0x2f, 0x9f, 0xfd, 0xda, 0x2c, 0xb9, 0x9a, 0xe4, 0x82, 0x3d, - 0xbb, 0x78, 0xfb, 0x1f, 0xca, 0x87, 0x53, 0xd6, 0xbe, 0x2c, 0xe1, 0xa5, 0x06, 0x84, 0x06, 0xe0, - 0xb5, 0x8b, 0xfb, 0xb5, 0x57, 0x2c, 0xab, 0xc8, 0x7a, 0xb3, 0xf6, 0xff, 0xb5, 0xc3, 0xe6, 0xc6, - 0x7b, 0x84, 0xcd, 0x39, 0x3b, 0x72, 0x30, 0x93, 0x72, 0x36, 0xc8, 0x7c, 0xb4, 0x00, 0x68, 0x24, - 0xe8, 0x13, 0xc2, 0xeb, 0x73, 0x0d, 0xbf, 0x3f, 0x6f, 0xca, 0x99, 0x30, 0xf3, 0xf1, 0x42, 0xb0, - 0xa1, 0xac, 0x7a, 0xf3, 0xac, 0x67, 0xa1, 0xf3, 0x9e, 0x85, 0x7e, 0xf7, 0x2c, 0xf4, 0xb1, 0x6f, - 0x95, 0xce, 0xfb, 0x56, 0xe9, 0x67, 0xdf, 0x2a, 0xbd, 0x79, 0x18, 0x32, 0x19, 0x65, 0x2d, 0xdb, - 0xe7, 0xb1, 0x33, 0xf5, 0x90, 0x9c, 0xde, 0xdb, 0xf7, 0x23, 0xc2, 0x12, 0x67, 0x74, 0xd3, 0x19, - 0x3f, 0x83, 0xdd, 0x94, 0x42, 0x6b, 0x39, 0xcf, 0x1c, 0xfc, 0x0d, 0x00, 0x00, 0xff, 0xff, 0xfa, - 0xd7, 0x13, 0x8c, 0x2b, 0x05, 0x00, 0x00, + // 607 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x55, 0x3f, 0x6f, 0xd3, 0x40, + 0x14, 0xcf, 0x41, 0x55, 0xa9, 0xd7, 0x06, 0xa9, 0x56, 0x04, 0xc1, 0x6a, 0x9d, 0x36, 0x12, 0xb4, + 0x8d, 0xa8, 0x2d, 0x52, 0x40, 0x50, 0x84, 0x04, 0x09, 0x42, 0x44, 0x60, 0x29, 0x72, 0x80, 0x81, + 0x25, 0xba, 0xd8, 0x87, 0x63, 0xd5, 0xf6, 0x59, 0xf7, 0xce, 0x55, 0xb2, 0xf2, 0x01, 0x28, 0x03, + 0x03, 0x0b, 0xdf, 0x81, 0x81, 0x81, 0x99, 0xa9, 0x63, 0xc5, 0xc4, 0x84, 0x50, 0x32, 0xf0, 0x35, + 0x50, 0x62, 0xc7, 0x49, 0x94, 0x7f, 0x28, 0x93, 0xef, 0xfd, 0xf9, 0xbd, 0xf7, 0x7b, 0xf7, 0x7b, + 0xb6, 0xf1, 0xb6, 0xd5, 0xb6, 0x5a, 0x01, 0x67, 0x82, 0x99, 0xcc, 0xd5, 0x5c, 0x07, 0x84, 0xe3, + 0xdb, 0x9a, 0x68, 0xa9, 0x7d, 0x9f, 0x94, 0x19, 0x0d, 0xab, 0x71, 0x58, 0xbe, 0x6e, 0x32, 0xf0, + 0x18, 0xd4, 0xfb, 0x01, 0x2d, 0x32, 0x22, 0x80, 0x7c, 0x2d, 0xb2, 0x34, 0x0f, 0x6c, 0xed, 0xf4, + 0x76, 0xef, 0x11, 0x07, 0x32, 0x36, 0xb3, 0x59, 0x04, 0xe8, 0x9d, 0x62, 0xef, 0xc1, 0x58, 0x7b, + 0x08, 0x1b, 0xc4, 0x34, 0x59, 0xe8, 0x0b, 0x18, 0x39, 0xc7, 0xa9, 0xbb, 0x53, 0x99, 0x06, 0x84, + 0x13, 0x2f, 0x6e, 0x9e, 0x3f, 0x43, 0x38, 0xa3, 0x83, 0x5d, 0xa3, 0x42, 0x27, 0xfc, 0x84, 0x0a, + 0x78, 0x4e, 0xb8, 0x55, 0x26, 0x81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7, 0x0f, 0x6c, 0x47, 0x34, 0xc3, 0x86, 0x6a, 0x32, 0x4f, 0x1b, 0xfb, 0x50, 0x9f, 0xde, 0x39, + 0x34, 0x9b, 0xc4, 0xf1, 0xb5, 0xc4, 0xd3, 0x1a, 0xfe, 0x66, 0xda, 0x01, 0x85, 0xc6, 0x6a, 0x3f, + 0x72, 0xf4, 0x2f, 0x00, 0x00, 0xff, 0xff, 0x92, 0xf4, 0x1f, 0x1d, 0x8b, 0x06, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -379,6 +482,8 @@ type MsgClient interface { CreateMarketPermissionless(ctx context.Context, in *MsgCreateMarketPermissionless, opts ...grpc.CallOption) (*MsgCreateMarketPermissionlessResponse, error) // SetListingVaultDepositParams sets PML megavault deposit params SetListingVaultDepositParams(ctx context.Context, in *MsgSetListingVaultDepositParams, opts ...grpc.CallOption) (*MsgSetListingVaultDepositParamsResponse, error) + // UpgradeIsolatedPerpetualToCross upgrades a perpetual from isolated to cross margin + UpgradeIsolatedPerpetualToCross(ctx context.Context, in *MsgUpgradeIsolatedPerpetualToCross, opts ...grpc.CallOption) (*MsgUpgradeIsolatedPerpetualToCrossResponse, error) } type msgClient struct { @@ -416,6 +521,15 @@ func (c *msgClient) SetListingVaultDepositParams(ctx context.Context, in *MsgSet return out, nil } +func (c *msgClient) UpgradeIsolatedPerpetualToCross(ctx context.Context, in *MsgUpgradeIsolatedPerpetualToCross, opts ...grpc.CallOption) (*MsgUpgradeIsolatedPerpetualToCrossResponse, error) { + out := new(MsgUpgradeIsolatedPerpetualToCrossResponse) + err := c.cc.Invoke(ctx, "/dydxprotocol.listing.Msg/UpgradeIsolatedPerpetualToCross", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + // MsgServer is the server API for Msg service. type MsgServer interface { // SetMarketsHardCap sets a hard cap on the number of markets listed @@ -424,6 +538,8 @@ type MsgServer interface { CreateMarketPermissionless(context.Context, *MsgCreateMarketPermissionless) (*MsgCreateMarketPermissionlessResponse, error) // SetListingVaultDepositParams sets PML megavault deposit params SetListingVaultDepositParams(context.Context, *MsgSetListingVaultDepositParams) (*MsgSetListingVaultDepositParamsResponse, error) + // UpgradeIsolatedPerpetualToCross upgrades a perpetual from isolated to cross margin + UpgradeIsolatedPerpetualToCross(context.Context, *MsgUpgradeIsolatedPerpetualToCross) (*MsgUpgradeIsolatedPerpetualToCrossResponse, error) } // UnimplementedMsgServer can be embedded to have forward compatible implementations. @@ -439,6 +555,9 @@ func (*UnimplementedMsgServer) CreateMarketPermissionless(ctx context.Context, r func (*UnimplementedMsgServer) SetListingVaultDepositParams(ctx context.Context, req *MsgSetListingVaultDepositParams) (*MsgSetListingVaultDepositParamsResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method SetListingVaultDepositParams not implemented") } +func (*UnimplementedMsgServer) UpgradeIsolatedPerpetualToCross(ctx context.Context, req *MsgUpgradeIsolatedPerpetualToCross) (*MsgUpgradeIsolatedPerpetualToCrossResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method UpgradeIsolatedPerpetualToCross not implemented") +} func RegisterMsgServer(s grpc1.Server, srv MsgServer) { s.RegisterService(&_Msg_serviceDesc, srv) @@ -498,6 +617,24 @@ func _Msg_SetListingVaultDepositParams_Handler(srv interface{}, ctx context.Cont return interceptor(ctx, in, info, handler) } +func _Msg_UpgradeIsolatedPerpetualToCross_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(MsgUpgradeIsolatedPerpetualToCross) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(MsgServer).UpgradeIsolatedPerpetualToCross(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/dydxprotocol.listing.Msg/UpgradeIsolatedPerpetualToCross", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(MsgServer).UpgradeIsolatedPerpetualToCross(ctx, req.(*MsgUpgradeIsolatedPerpetualToCross)) + } + return interceptor(ctx, in, info, handler) +} + var _Msg_serviceDesc = grpc.ServiceDesc{ ServiceName: "dydxprotocol.listing.Msg", HandlerType: (*MsgServer)(nil), @@ -514,6 +651,10 @@ var _Msg_serviceDesc = grpc.ServiceDesc{ MethodName: "SetListingVaultDepositParams", Handler: _Msg_SetListingVaultDepositParams_Handler, }, + { + MethodName: "UpgradeIsolatedPerpetualToCross", + Handler: _Msg_UpgradeIsolatedPerpetualToCross_Handler, + }, }, Streams: []grpc.StreamDesc{}, Metadata: "dydxprotocol/listing/tx.proto", @@ -705,6 +846,64 @@ func (m *MsgSetListingVaultDepositParamsResponse) MarshalToSizedBuffer(dAtA []by return len(dAtA) - i, nil } +func (m *MsgUpgradeIsolatedPerpetualToCross) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *MsgUpgradeIsolatedPerpetualToCross) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgUpgradeIsolatedPerpetualToCross) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.PerpetualId != 0 { + i = encodeVarintTx(dAtA, i, uint64(m.PerpetualId)) + i-- + dAtA[i] = 0x10 + } + if len(m.Authority) > 0 { + i -= len(m.Authority) + copy(dAtA[i:], m.Authority) + i = encodeVarintTx(dAtA, i, uint64(len(m.Authority))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *MsgUpgradeIsolatedPerpetualToCrossResponse) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *MsgUpgradeIsolatedPerpetualToCrossResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgUpgradeIsolatedPerpetualToCrossResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + return len(dAtA) - i, nil +} + func encodeVarintTx(dAtA []byte, offset int, v uint64) int { offset -= sovTx(v) base := offset @@ -791,6 +990,31 @@ func (m *MsgSetListingVaultDepositParamsResponse) Size() (n int) { return n } +func (m *MsgUpgradeIsolatedPerpetualToCross) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Authority) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + if m.PerpetualId != 0 { + n += 1 + sovTx(uint64(m.PerpetualId)) + } + return n +} + +func (m *MsgUpgradeIsolatedPerpetualToCrossResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + return n +} + func sovTx(x uint64) (n int) { return (math_bits.Len64(x|1) + 6) / 7 } @@ -1281,6 +1505,157 @@ func (m *MsgSetListingVaultDepositParamsResponse) Unmarshal(dAtA []byte) error { } return nil } +func (m *MsgUpgradeIsolatedPerpetualToCross) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: MsgUpgradeIsolatedPerpetualToCross: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgUpgradeIsolatedPerpetualToCross: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Authority", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Authority = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field PerpetualId", wireType) + } + m.PerpetualId = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.PerpetualId |= uint32(b&0x7F) << shift + if b < 0x80 { + break + } + } + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *MsgUpgradeIsolatedPerpetualToCrossResponse) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: MsgUpgradeIsolatedPerpetualToCrossResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgUpgradeIsolatedPerpetualToCrossResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} func skipTx(dAtA []byte) (n int, err error) { l := len(dAtA) iNdEx := 0 diff --git a/protocol/x/perpetuals/keeper/perpetual.go b/protocol/x/perpetuals/keeper/perpetual.go index 6738daf453..6a75e83723 100644 --- a/protocol/x/perpetuals/keeper/perpetual.go +++ b/protocol/x/perpetuals/keeper/perpetual.go @@ -251,32 +251,6 @@ func (k Keeper) GetAllPerpetuals(ctx sdk.Context) (list []types.Perpetual) { return list } -func (k Keeper) UpgradeIsolatedPerpetualToCross( - ctx sdk.Context, - id uint32, -) error { - err := k.clobKeeper.TransferIsolatedInsuranceFundToCross(ctx, id) - if err != nil { - return err - } - - _, err = k.SetPerpetualMarketType( - ctx, - id, - types.PerpetualMarketType_PERPETUAL_MARKET_TYPE_CROSS, - ) - if err != nil { - return err - } - - // TODO Move collateral pool for perpetual to subaccounts module - // See transferCollateralForIsolatedPerpetual()? - - // TODO Propagate changes to indexer - - return nil -} - // processStoredPremiums combines all stored premiums into a single premium value // for each `MarketPremiums` in the premium storage. // Returns a mapping from perpetual Id to summarized premium value. diff --git a/protocol/x/perpetuals/types/expected_keepers.go b/protocol/x/perpetuals/types/expected_keepers.go index 0356f681fb..d83f970b2b 100644 --- a/protocol/x/perpetuals/types/expected_keepers.go +++ b/protocol/x/perpetuals/types/expected_keepers.go @@ -33,12 +33,6 @@ type PerpetualsClobKeeper interface { isActive bool, err error, ) - TransferIsolatedInsuranceFundToCross( - ctx sdk.Context, - perpetualId uint32, - ) ( - err error, - ) } // EpochsKeeper defines the expected epochs keeper to get epoch info. diff --git a/protocol/x/perpetuals/types/tx.pb.go b/protocol/x/perpetuals/types/tx.pb.go index dac961582a..89cc1abbcf 100644 --- a/protocol/x/perpetuals/types/tx.pb.go +++ b/protocol/x/perpetuals/types/tx.pb.go @@ -540,103 +540,6 @@ func (m *MsgUpdateParamsResponse) XXX_DiscardUnknown() { var xxx_messageInfo_MsgUpdateParamsResponse proto.InternalMessageInfo -// MsgUpgradeIsolatedPerpetualToCross is used to upgrade a market from -// isolated margin to cross margin. -type MsgUpgradeIsolatedPerpetualToCross struct { - Authority string `protobuf:"bytes,1,opt,name=authority,proto3" json:"authority,omitempty"` - // ID of the perpetual to be upgraded to CROSS - PerpetualId uint32 `protobuf:"varint,2,opt,name=perpetual_id,json=perpetualId,proto3" json:"perpetual_id,omitempty"` -} - -func (m *MsgUpgradeIsolatedPerpetualToCross) Reset() { *m = MsgUpgradeIsolatedPerpetualToCross{} } -func (m *MsgUpgradeIsolatedPerpetualToCross) String() string { return proto.CompactTextString(m) } -func (*MsgUpgradeIsolatedPerpetualToCross) ProtoMessage() {} -func (*MsgUpgradeIsolatedPerpetualToCross) Descriptor() ([]byte, []int) { - return fileDescriptor_daed24c15760c356, []int{11} -} -func (m *MsgUpgradeIsolatedPerpetualToCross) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *MsgUpgradeIsolatedPerpetualToCross) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_MsgUpgradeIsolatedPerpetualToCross.Marshal(b, m, deterministic) - } else { - b = b[:cap(b)] - n, err := m.MarshalToSizedBuffer(b) - if err != nil { - return nil, err - } - return b[:n], nil - } -} -func (m *MsgUpgradeIsolatedPerpetualToCross) XXX_Merge(src proto.Message) { - xxx_messageInfo_MsgUpgradeIsolatedPerpetualToCross.Merge(m, src) -} -func (m *MsgUpgradeIsolatedPerpetualToCross) XXX_Size() int { - return m.Size() -} -func (m *MsgUpgradeIsolatedPerpetualToCross) XXX_DiscardUnknown() { - xxx_messageInfo_MsgUpgradeIsolatedPerpetualToCross.DiscardUnknown(m) -} - -var xxx_messageInfo_MsgUpgradeIsolatedPerpetualToCross proto.InternalMessageInfo - -func (m *MsgUpgradeIsolatedPerpetualToCross) GetAuthority() string { - if m != nil { - return m.Authority - } - return "" -} - -func (m *MsgUpgradeIsolatedPerpetualToCross) GetPerpetualId() uint32 { - if m != nil { - return m.PerpetualId - } - return 0 -} - -// MsgUpgradeIsolatedPerpetualToCrossResponse defines the -// UpgradeIsolatedPerpetualToCross response type. -type MsgUpgradeIsolatedPerpetualToCrossResponse struct { -} - -func (m *MsgUpgradeIsolatedPerpetualToCrossResponse) Reset() { - *m = MsgUpgradeIsolatedPerpetualToCrossResponse{} -} -func (m *MsgUpgradeIsolatedPerpetualToCrossResponse) String() string { - return proto.CompactTextString(m) -} -func (*MsgUpgradeIsolatedPerpetualToCrossResponse) ProtoMessage() {} -func (*MsgUpgradeIsolatedPerpetualToCrossResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_daed24c15760c356, []int{12} -} -func (m *MsgUpgradeIsolatedPerpetualToCrossResponse) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *MsgUpgradeIsolatedPerpetualToCrossResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_MsgUpgradeIsolatedPerpetualToCrossResponse.Marshal(b, m, deterministic) - } else { - b = b[:cap(b)] - n, err := m.MarshalToSizedBuffer(b) - if err != nil { - return nil, err - } - return b[:n], nil - } -} -func (m *MsgUpgradeIsolatedPerpetualToCrossResponse) XXX_Merge(src proto.Message) { - xxx_messageInfo_MsgUpgradeIsolatedPerpetualToCrossResponse.Merge(m, src) -} -func (m *MsgUpgradeIsolatedPerpetualToCrossResponse) XXX_Size() int { - return m.Size() -} -func (m *MsgUpgradeIsolatedPerpetualToCrossResponse) XXX_DiscardUnknown() { - xxx_messageInfo_MsgUpgradeIsolatedPerpetualToCrossResponse.DiscardUnknown(m) -} - -var xxx_messageInfo_MsgUpgradeIsolatedPerpetualToCrossResponse proto.InternalMessageInfo - func init() { proto.RegisterType((*MsgCreatePerpetual)(nil), "dydxprotocol.perpetuals.MsgCreatePerpetual") proto.RegisterType((*MsgCreatePerpetualResponse)(nil), "dydxprotocol.perpetuals.MsgCreatePerpetualResponse") @@ -649,57 +552,51 @@ func init() { proto.RegisterType((*MsgAddPremiumVotesResponse)(nil), "dydxprotocol.perpetuals.MsgAddPremiumVotesResponse") proto.RegisterType((*MsgUpdateParams)(nil), "dydxprotocol.perpetuals.MsgUpdateParams") proto.RegisterType((*MsgUpdateParamsResponse)(nil), "dydxprotocol.perpetuals.MsgUpdateParamsResponse") - proto.RegisterType((*MsgUpgradeIsolatedPerpetualToCross)(nil), "dydxprotocol.perpetuals.MsgUpgradeIsolatedPerpetualToCross") - proto.RegisterType((*MsgUpgradeIsolatedPerpetualToCrossResponse)(nil), "dydxprotocol.perpetuals.MsgUpgradeIsolatedPerpetualToCrossResponse") } func init() { proto.RegisterFile("dydxprotocol/perpetuals/tx.proto", fileDescriptor_daed24c15760c356) } var fileDescriptor_daed24c15760c356 = []byte{ - // 678 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xa4, 0x56, 0xcd, 0x6b, 0x13, 0x41, - 0x14, 0xcf, 0xb4, 0xb6, 0xd0, 0x97, 0x7e, 0xb1, 0x56, 0x9a, 0xae, 0x9a, 0xc4, 0x20, 0x36, 0xd4, - 0x36, 0x6b, 0x3f, 0x10, 0xfc, 0x3a, 0xb4, 0x81, 0x42, 0xc1, 0x40, 0x48, 0x6b, 0xa1, 0x5e, 0xc2, - 0x36, 0x33, 0x6c, 0x57, 0xb2, 0x99, 0x71, 0x66, 0x12, 0x9a, 0xa3, 0x82, 0x67, 0x3d, 0x7a, 0xd7, - 0x3f, 0x40, 0xc4, 0xab, 0xf7, 0x1e, 0x8b, 0x27, 0x4f, 0x22, 0xed, 0xc1, 0x7f, 0x43, 0xb2, 0x1f, - 0x93,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, 0x69, 0x3a, 0xf1, 0xfa, 0xb9, 0x65, 0xcb, 0x83, 0xe6, 0x7e, 0xa1, 0x46, 0x1d, - 0xa3, 0xe7, 0x9f, 0xa0, 0xb5, 0xb6, 0x54, 0x3b, 0x30, 0xed, 0x86, 0xa1, 0x22, 0x87, 0x3d, 0xbf, - 0x34, 0x6d, 0x46, 0xc4, 0xfe, 0xa8, 0x9b, 0x5c, 0xfd, 0x1f, 0x00, 0x00, 0xff, 0xff, 0xb6, 0xd1, - 0x34, 0xcd, 0xfa, 0x08, 0x00, 0x00, + // 620 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xa4, 0x55, 0x4d, 0x6b, 0x13, 0x41, + 0x18, 0xce, 0xd8, 0x0f, 0xe8, 0x9b, 0x36, 0x29, 0x6b, 0x25, 0xe9, 0xaa, 0x9b, 0x18, 0xc4, 0x06, + 0xb5, 0x59, 0x9b, 0x16, 0x41, 0xd1, 0x43, 0x53, 0x28, 0x08, 0x06, 0x42, 0x52, 0x0b, 0xf5, 0x12, + 0xb6, 0xd9, 0x61, 0x33, 0x92, 0xcd, 0x8e, 0x3b, 0xb3, 0x21, 0xb9, 0x0a, 0xde, 0x3d, 0xfa, 0x03, + 0xfc, 0x01, 0x22, 0x5e, 0xbd, 0xf7, 0x58, 0x3c, 0x09, 0x82, 0x48, 0x72, 0xf0, 0x6f, 0x48, 0xf6, + 0x2b, 0xd9, 0x4d, 0x36, 0x24, 0xed, 0x69, 0x67, 0xdf, 0x79, 0xde, 0xf7, 0x79, 0x9e, 0x77, 0xbe, + 0x20, 0xab, 0xf6, 0xd4, 0x2e, 0x35, 0x0d, 0x6e, 0x34, 0x8c, 0x96, 0x4c, 0xb1, 0x49, 0x31, 0xb7, + 0x94, 0x16, 0x93, 0x79, 0xb7, 0x60, 0x87, 0x85, 0xd4, 0x38, 0xa2, 0x30, 0x42, 0x88, 0xdb, 0x0d, + 0x83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10, 0x78, + 0x36, 0x69, 0xc4, 0x75, 0x21, 0x74, 0x60, 0x73, 0xe2, 0xaa, 0x78, 0x3c, 0xab, 0x50, 0x18, 0x2d, + 0x1e, 0x2c, 0x82, 0xf6, 0x79, 0x3f, 0x22, 0xb8, 0x35, 0xfd, 0x3c, 0xef, 0xcd, 0xaa, 0x37, 0x35, + 0x45, 0x7c, 0xb6, 0x70, 0x8a, 0xaf, 0xe3, 0x1d, 0xac, 0x07, 0xf6, 0x68, 0x7e, 0x8e, 0x52, 0x0e, + 0xe9, 0x93, 0x79, 0x91, 0x1e, 0x57, 0xe9, 0xf4, 0xa2, 0x2f, 0xa1, 0xcb, 0xbe, 0x84, 0xfe, 0xf6, + 0x25, 0xf4, 0x69, 0x20, 0xc5, 0x2e, 0x07, 0x52, 0xec, 0xd7, 0x40, 0x8a, 0xbd, 0x7d, 0xa1, 0x11, + 0xde, 0xb4, 0xce, 0x0b, 0x0d, 0x43, 0x97, 0x03, 0xaf, 0x55, 0xe7, 0x60, 0xb7, 0xd1, 0x54, 0x48, + 0x5b, 0xf6, 0x23, 0xdd, 0xc0, 0x63, 0xdb, 0xa3, 0x98, 0x9d, 0xaf, 0xda, 0x93, 0xfb, 0xff, 0x03, + 0x00, 0x00, 0xff, 0xff, 0x2c, 0x4e, 0x17, 0x56, 0x94, 0x07, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -726,8 +623,6 @@ type MsgClient interface { UpdatePerpetualParams(ctx context.Context, in *MsgUpdatePerpetualParams, opts ...grpc.CallOption) (*MsgUpdatePerpetualParamsResponse, error) // UpdateParams updates the parameters of perpetuals module. UpdateParams(ctx context.Context, in *MsgUpdateParams, opts ...grpc.CallOption) (*MsgUpdateParamsResponse, error) - // UpgradeIsolatedPerpetualToCross upgrades a perpetual from isolated to cross margin. - UpgradeIsolatedPerpetualToCross(ctx context.Context, in *MsgUpgradeIsolatedPerpetualToCross, opts ...grpc.CallOption) (*MsgUpgradeIsolatedPerpetualToCrossResponse, error) } type msgClient struct { @@ -783,15 +678,6 @@ func (c *msgClient) UpdateParams(ctx context.Context, in *MsgUpdateParams, opts return out, nil } -func (c *msgClient) UpgradeIsolatedPerpetualToCross(ctx context.Context, in *MsgUpgradeIsolatedPerpetualToCross, opts ...grpc.CallOption) (*MsgUpgradeIsolatedPerpetualToCrossResponse, error) { - out := new(MsgUpgradeIsolatedPerpetualToCrossResponse) - err := c.cc.Invoke(ctx, "/dydxprotocol.perpetuals.Msg/UpgradeIsolatedPerpetualToCross", in, out, opts...) - if err != nil { - return nil, err - } - return out, nil -} - // MsgServer is the server API for Msg service. type MsgServer interface { // AddPremiumVotes add new samples of the funding premiums to the @@ -806,8 +692,6 @@ type MsgServer interface { UpdatePerpetualParams(context.Context, *MsgUpdatePerpetualParams) (*MsgUpdatePerpetualParamsResponse, error) // UpdateParams updates the parameters of perpetuals module. UpdateParams(context.Context, *MsgUpdateParams) (*MsgUpdateParamsResponse, error) - // UpgradeIsolatedPerpetualToCross upgrades a perpetual from isolated to cross margin. - UpgradeIsolatedPerpetualToCross(context.Context, *MsgUpgradeIsolatedPerpetualToCross) (*MsgUpgradeIsolatedPerpetualToCrossResponse, error) } // UnimplementedMsgServer can be embedded to have forward compatible implementations. @@ -829,9 +713,6 @@ func (*UnimplementedMsgServer) UpdatePerpetualParams(ctx context.Context, req *M func (*UnimplementedMsgServer) UpdateParams(ctx context.Context, req *MsgUpdateParams) (*MsgUpdateParamsResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method UpdateParams not implemented") } -func (*UnimplementedMsgServer) UpgradeIsolatedPerpetualToCross(ctx context.Context, req *MsgUpgradeIsolatedPerpetualToCross) (*MsgUpgradeIsolatedPerpetualToCrossResponse, error) { - return nil, status.Errorf(codes.Unimplemented, "method UpgradeIsolatedPerpetualToCross not implemented") -} func RegisterMsgServer(s grpc1.Server, srv MsgServer) { s.RegisterService(&_Msg_serviceDesc, srv) @@ -927,24 +808,6 @@ func _Msg_UpdateParams_Handler(srv interface{}, ctx context.Context, dec func(in return interceptor(ctx, in, info, handler) } -func _Msg_UpgradeIsolatedPerpetualToCross_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(MsgUpgradeIsolatedPerpetualToCross) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(MsgServer).UpgradeIsolatedPerpetualToCross(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: "/dydxprotocol.perpetuals.Msg/UpgradeIsolatedPerpetualToCross", - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(MsgServer).UpgradeIsolatedPerpetualToCross(ctx, req.(*MsgUpgradeIsolatedPerpetualToCross)) - } - return interceptor(ctx, in, info, handler) -} - var _Msg_serviceDesc = grpc.ServiceDesc{ ServiceName: "dydxprotocol.perpetuals.Msg", HandlerType: (*MsgServer)(nil), @@ -969,10 +832,6 @@ var _Msg_serviceDesc = grpc.ServiceDesc{ MethodName: "UpdateParams", Handler: _Msg_UpdateParams_Handler, }, - { - MethodName: "UpgradeIsolatedPerpetualToCross", - Handler: _Msg_UpgradeIsolatedPerpetualToCross_Handler, - }, }, Streams: []grpc.StreamDesc{}, Metadata: "dydxprotocol/perpetuals/tx.proto", @@ -1323,64 +1182,6 @@ func (m *MsgUpdateParamsResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) return len(dAtA) - i, nil } -func (m *MsgUpgradeIsolatedPerpetualToCross) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalToSizedBuffer(dAtA[:size]) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *MsgUpgradeIsolatedPerpetualToCross) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *MsgUpgradeIsolatedPerpetualToCross) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - if m.PerpetualId != 0 { - i = encodeVarintTx(dAtA, i, uint64(m.PerpetualId)) - i-- - dAtA[i] = 0x10 - } - if len(m.Authority) > 0 { - i -= len(m.Authority) - copy(dAtA[i:], m.Authority) - i = encodeVarintTx(dAtA, i, uint64(len(m.Authority))) - i-- - dAtA[i] = 0xa - } - return len(dAtA) - i, nil -} - -func (m *MsgUpgradeIsolatedPerpetualToCrossResponse) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalToSizedBuffer(dAtA[:size]) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *MsgUpgradeIsolatedPerpetualToCrossResponse) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *MsgUpgradeIsolatedPerpetualToCrossResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - return len(dAtA) - i, nil -} - func encodeVarintTx(dAtA []byte, offset int, v uint64) int { offset -= sovTx(v) base := offset @@ -1527,31 +1328,6 @@ func (m *MsgUpdateParamsResponse) Size() (n int) { return n } -func (m *MsgUpgradeIsolatedPerpetualToCross) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - l = len(m.Authority) - if l > 0 { - n += 1 + l + sovTx(uint64(l)) - } - if m.PerpetualId != 0 { - n += 1 + sovTx(uint64(m.PerpetualId)) - } - return n -} - -func (m *MsgUpgradeIsolatedPerpetualToCrossResponse) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - return n -} - func sovTx(x uint64) (n int) { return (math_bits.Len64(x|1) + 6) / 7 } @@ -2440,157 +2216,6 @@ func (m *MsgUpdateParamsResponse) Unmarshal(dAtA []byte) error { } return nil } -func (m *MsgUpgradeIsolatedPerpetualToCross) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowTx - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: MsgUpgradeIsolatedPerpetualToCross: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: MsgUpgradeIsolatedPerpetualToCross: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Authority", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowTx - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthTx - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthTx - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Authority = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 2: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field PerpetualId", wireType) - } - m.PerpetualId = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowTx - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.PerpetualId |= uint32(b&0x7F) << shift - if b < 0x80 { - break - } - } - default: - iNdEx = preIndex - skippy, err := skipTx(dAtA[iNdEx:]) - if err != nil { - return err - } - if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLengthTx - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *MsgUpgradeIsolatedPerpetualToCrossResponse) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowTx - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: MsgUpgradeIsolatedPerpetualToCrossResponse: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: MsgUpgradeIsolatedPerpetualToCrossResponse: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - default: - iNdEx = preIndex - skippy, err := skipTx(dAtA[iNdEx:]) - if err != nil { - return err - } - if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLengthTx - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} func skipTx(dAtA []byte) (n int, err error) { l := len(dAtA) iNdEx := 0 diff --git a/protocol/x/perpetuals/types/types.go b/protocol/x/perpetuals/types/types.go index cefbfa8dec..7268ec81a9 100644 --- a/protocol/x/perpetuals/types/types.go +++ b/protocol/x/perpetuals/types/types.go @@ -118,10 +118,6 @@ type PerpetualsKeeper interface { ctx sdk.Context, perpetual Perpetual, ) error - UpgradeIsolatedPerpetualToCross( - ctx sdk.Context, - id uint32, - ) error } // OpenInterestDelta represents a (perpId, openInterestDelta) tuple. diff --git a/protocol/x/subaccounts/keeper/isolated_subaccount.go b/protocol/x/subaccounts/keeper/isolated_subaccount.go index af628f19fc..5da702ad69 100644 --- a/protocol/x/subaccounts/keeper/isolated_subaccount.go +++ b/protocol/x/subaccounts/keeper/isolated_subaccount.go @@ -213,6 +213,58 @@ func GetIsolatedPerpetualStateTransition( return nil, nil } +// GetInsuranceFundBalance returns the current balance of the specific insurance fund based on the +// perpetual (in quote quantums). +// This calls the Bank Keeper’s GetBalance() function for the Module Address of the insurance fund. +func (k Keeper) GetInsuranceFundBalance(ctx sdk.Context, perpetualId uint32) (balance *big.Int) { + usdcAsset, exists := k.assetsKeeper.GetAsset(ctx, assettypes.AssetUsdc.Id) + if !exists { + panic("GetInsuranceFundBalance: Usdc asset not found in state") + } + insuranceFundAddr, err := k.perpetualsKeeper.GetInsuranceFundModuleAddress(ctx, perpetualId) + if err != nil { + return nil + } + insuranceFundBalance := k.bankKeeper.GetBalance( + ctx, + insuranceFundAddr, + usdcAsset.Denom, + ) + + // Return as big.Int. + return insuranceFundBalance.Amount.BigInt() +} + +// TransferInsuranceFundsForIsolatedPerpetual transfers funds from an isolated insurance fund +// to the cross-perpetual insurance fund based +// Note: This uses the `x/bank` keeper and modifies `x/bank` state. +func (k Keeper) TransferInsuranceFundsForIsolatedPerpetual(ctx sdk.Context, perpetualId uint32) error { + isolatedInsuranceFundBalance := k.GetInsuranceFundBalance(ctx, perpetualId) + + _, coinToTransfer, err := k.assetsKeeper.ConvertAssetToCoin( + ctx, + assettypes.AssetUsdc.Id, + new(big.Int).Abs(isolatedInsuranceFundBalance), + ) + if err != nil { + panic(err) + } + + isolatedInsuranceFundAddr, err := k.perpetualsKeeper.GetInsuranceFundModuleAddress(ctx, perpetualId) + if err != nil { + return nil + } + + crossInsuranceFundAddr := perptypes.InsuranceFundModuleAddress + + return k.bankKeeper.SendCoins( + ctx, + isolatedInsuranceFundAddr, + crossInsuranceFundAddr, + []sdk.Coin{coinToTransfer}, + ) +} + // transferCollateralForIsolatedPerpetual transfers collateral between an isolated collateral pool // and the cross-perpetual collateral pool based on whether an isolated perpetual position was // opened or closed in a subaccount. diff --git a/protocol/x/subaccounts/types/tx.pb.go b/protocol/x/subaccounts/types/tx.pb.go new file mode 100644 index 0000000000..307aea4a53 --- /dev/null +++ b/protocol/x/subaccounts/types/tx.pb.go @@ -0,0 +1,578 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: dydxprotocol/subaccounts/tx.proto + +package types + +import ( + context "context" + fmt "fmt" + _ "github.com/cosmos/cosmos-proto" + _ "github.com/cosmos/cosmos-sdk/types/msgservice" + _ "github.com/cosmos/gogoproto/gogoproto" + grpc1 "github.com/cosmos/gogoproto/grpc" + proto "github.com/cosmos/gogoproto/proto" + grpc "google.golang.org/grpc" + codes "google.golang.org/grpc/codes" + status "google.golang.org/grpc/status" + io "io" + math "math" + math_bits "math/bits" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package + +// MsgUpgradeIsolatedPerpetualToCross is used to upgrade a market from +// isolated margin to cross margin. +type MsgUpgradeIsolatedPerpetualToCross struct { + Authority string `protobuf:"bytes,1,opt,name=authority,proto3" json:"authority,omitempty"` + // ID of the perpetual to be upgraded to CROSS + PerpetualId uint32 `protobuf:"varint,2,opt,name=perpetual_id,json=perpetualId,proto3" json:"perpetual_id,omitempty"` +} + +func (m *MsgUpgradeIsolatedPerpetualToCross) Reset() { *m = MsgUpgradeIsolatedPerpetualToCross{} } +func (m *MsgUpgradeIsolatedPerpetualToCross) String() string { return proto.CompactTextString(m) } +func (*MsgUpgradeIsolatedPerpetualToCross) ProtoMessage() {} +func (*MsgUpgradeIsolatedPerpetualToCross) Descriptor() ([]byte, []int) { + return fileDescriptor_16edbf88307684e5, []int{0} +} +func (m *MsgUpgradeIsolatedPerpetualToCross) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgUpgradeIsolatedPerpetualToCross) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgUpgradeIsolatedPerpetualToCross.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *MsgUpgradeIsolatedPerpetualToCross) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgUpgradeIsolatedPerpetualToCross.Merge(m, src) +} +func (m *MsgUpgradeIsolatedPerpetualToCross) XXX_Size() int { + return m.Size() +} +func (m *MsgUpgradeIsolatedPerpetualToCross) XXX_DiscardUnknown() { + xxx_messageInfo_MsgUpgradeIsolatedPerpetualToCross.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgUpgradeIsolatedPerpetualToCross proto.InternalMessageInfo + +func (m *MsgUpgradeIsolatedPerpetualToCross) GetAuthority() string { + if m != nil { + return m.Authority + } + return "" +} + +func (m *MsgUpgradeIsolatedPerpetualToCross) GetPerpetualId() uint32 { + if m != nil { + return m.PerpetualId + } + return 0 +} + +// MsgUpgradeIsolatedPerpetualToCrossResponse defines the +// UpgradeIsolatedPerpetualToCross response type. +type MsgUpgradeIsolatedPerpetualToCrossResponse struct { +} + +func (m *MsgUpgradeIsolatedPerpetualToCrossResponse) Reset() { + *m = MsgUpgradeIsolatedPerpetualToCrossResponse{} +} +func (m *MsgUpgradeIsolatedPerpetualToCrossResponse) String() string { + return proto.CompactTextString(m) +} +func (*MsgUpgradeIsolatedPerpetualToCrossResponse) ProtoMessage() {} +func (*MsgUpgradeIsolatedPerpetualToCrossResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_16edbf88307684e5, []int{1} +} +func (m *MsgUpgradeIsolatedPerpetualToCrossResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgUpgradeIsolatedPerpetualToCrossResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgUpgradeIsolatedPerpetualToCrossResponse.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *MsgUpgradeIsolatedPerpetualToCrossResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgUpgradeIsolatedPerpetualToCrossResponse.Merge(m, src) +} +func (m *MsgUpgradeIsolatedPerpetualToCrossResponse) XXX_Size() int { + return m.Size() +} +func (m *MsgUpgradeIsolatedPerpetualToCrossResponse) XXX_DiscardUnknown() { + xxx_messageInfo_MsgUpgradeIsolatedPerpetualToCrossResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgUpgradeIsolatedPerpetualToCrossResponse proto.InternalMessageInfo + +func init() { + proto.RegisterType((*MsgUpgradeIsolatedPerpetualToCross)(nil), "dydxprotocol.subaccounts.MsgUpgradeIsolatedPerpetualToCross") + proto.RegisterType((*MsgUpgradeIsolatedPerpetualToCrossResponse)(nil), "dydxprotocol.subaccounts.MsgUpgradeIsolatedPerpetualToCrossResponse") +} + +func init() { proto.RegisterFile("dydxprotocol/subaccounts/tx.proto", fileDescriptor_16edbf88307684e5) } + +var fileDescriptor_16edbf88307684e5 = []byte{ + // 328 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x52, 0x4c, 0xa9, 0x4c, 0xa9, + 0x28, 0x28, 0xca, 0x2f, 0xc9, 0x4f, 0xce, 0xcf, 0xd1, 0x2f, 0x2e, 0x4d, 0x4a, 0x4c, 0x4e, 0xce, + 0x2f, 0xcd, 0x2b, 0x29, 0xd6, 0x2f, 0xa9, 0xd0, 0x03, 0x8b, 0x0b, 0x49, 0x20, 0x2b, 0xd1, 0x43, + 0x52, 0x22, 0x25, 0x99, 0x9c, 0x5f, 0x9c, 0x9b, 0x5f, 0x1c, 0x0f, 0x96, 0xd4, 0x87, 0x70, 0x20, + 0x9a, 0xa4, 0xc4, 0x21, 0x3c, 0xfd, 0xdc, 0xe2, 0x74, 0xfd, 0x32, 0x43, 0x10, 0x05, 0x95, 0x10, + 0x49, 0xcf, 0x4f, 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xc7, 0x70, 0xe1, 0xb1, 0x1c, 0xc3, 0x8d, + 0xc7, 0x72, 0x0c, 0x51, 0xb6, 0xe9, 0x99, 0x25, 0x19, 0xa5, 0x49, 0x7a, 0xc9, 0xf9, 0xb9, 0xfa, + 0x28, 0x69, 0xa3, 0xcc, 0x44, 0x37, 0x39, 0x23, 0x31, 0x33, 0x4f, 0x1f, 0x2e, 0x52, 0x81, 0x9a, + 0x5e, 0x2a, 0x0b, 0x52, 0x8b, 0x93, 0xd8, 0xc0, 0xb2, 0xc6, 0x80, 0x00, 0x00, 0x00, 0xff, 0xff, + 0xa1, 0x2b, 0x66, 0x7f, 0x58, 0x02, 0x00, 0x00, +} + +// Reference imports to suppress errors if they are not otherwise used. +var _ context.Context +var _ grpc.ClientConn + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the grpc package it is being compiled against. +const _ = grpc.SupportPackageIsVersion4 + +// MsgClient is the client API for Msg service. +// +// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. +type MsgClient interface { + // UpgradeIsolatedPerpetualToCross upgrades a perpetual from isolated to cross margin. + UpgradeIsolatedPerpetualToCross(ctx context.Context, in *MsgUpgradeIsolatedPerpetualToCross, opts ...grpc.CallOption) (*MsgUpgradeIsolatedPerpetualToCrossResponse, error) +} + +type msgClient struct { + cc grpc1.ClientConn +} + +func NewMsgClient(cc grpc1.ClientConn) MsgClient { + return &msgClient{cc} +} + +func (c *msgClient) UpgradeIsolatedPerpetualToCross(ctx context.Context, in *MsgUpgradeIsolatedPerpetualToCross, opts ...grpc.CallOption) (*MsgUpgradeIsolatedPerpetualToCrossResponse, error) { + out := new(MsgUpgradeIsolatedPerpetualToCrossResponse) + err := c.cc.Invoke(ctx, "/dydxprotocol.subaccounts.Msg/UpgradeIsolatedPerpetualToCross", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +// MsgServer is the server API for Msg service. +type MsgServer interface { + // UpgradeIsolatedPerpetualToCross upgrades a perpetual from isolated to cross margin. + UpgradeIsolatedPerpetualToCross(context.Context, *MsgUpgradeIsolatedPerpetualToCross) (*MsgUpgradeIsolatedPerpetualToCrossResponse, error) +} + +// UnimplementedMsgServer can be embedded to have forward compatible implementations. +type UnimplementedMsgServer struct { +} + +func (*UnimplementedMsgServer) UpgradeIsolatedPerpetualToCross(ctx context.Context, req *MsgUpgradeIsolatedPerpetualToCross) (*MsgUpgradeIsolatedPerpetualToCrossResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method UpgradeIsolatedPerpetualToCross not implemented") +} + +func RegisterMsgServer(s grpc1.Server, srv MsgServer) { + s.RegisterService(&_Msg_serviceDesc, srv) +} + +func _Msg_UpgradeIsolatedPerpetualToCross_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(MsgUpgradeIsolatedPerpetualToCross) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(MsgServer).UpgradeIsolatedPerpetualToCross(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/dydxprotocol.subaccounts.Msg/UpgradeIsolatedPerpetualToCross", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(MsgServer).UpgradeIsolatedPerpetualToCross(ctx, req.(*MsgUpgradeIsolatedPerpetualToCross)) + } + return interceptor(ctx, in, info, handler) +} + +var _Msg_serviceDesc = grpc.ServiceDesc{ + ServiceName: "dydxprotocol.subaccounts.Msg", + HandlerType: (*MsgServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "UpgradeIsolatedPerpetualToCross", + Handler: _Msg_UpgradeIsolatedPerpetualToCross_Handler, + }, + }, + Streams: []grpc.StreamDesc{}, + Metadata: "dydxprotocol/subaccounts/tx.proto", +} + +func (m *MsgUpgradeIsolatedPerpetualToCross) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *MsgUpgradeIsolatedPerpetualToCross) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgUpgradeIsolatedPerpetualToCross) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.PerpetualId != 0 { + i = encodeVarintTx(dAtA, i, uint64(m.PerpetualId)) + i-- + dAtA[i] = 0x10 + } + if len(m.Authority) > 0 { + i -= len(m.Authority) + copy(dAtA[i:], m.Authority) + i = encodeVarintTx(dAtA, i, uint64(len(m.Authority))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *MsgUpgradeIsolatedPerpetualToCrossResponse) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *MsgUpgradeIsolatedPerpetualToCrossResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgUpgradeIsolatedPerpetualToCrossResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + return len(dAtA) - i, nil +} + +func encodeVarintTx(dAtA []byte, offset int, v uint64) int { + offset -= sovTx(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *MsgUpgradeIsolatedPerpetualToCross) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Authority) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + if m.PerpetualId != 0 { + n += 1 + sovTx(uint64(m.PerpetualId)) + } + return n +} + +func (m *MsgUpgradeIsolatedPerpetualToCrossResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + return n +} + +func sovTx(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozTx(x uint64) (n int) { + return sovTx(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *MsgUpgradeIsolatedPerpetualToCross) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: MsgUpgradeIsolatedPerpetualToCross: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgUpgradeIsolatedPerpetualToCross: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Authority", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Authority = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field PerpetualId", wireType) + } + m.PerpetualId = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.PerpetualId |= uint32(b&0x7F) << shift + if b < 0x80 { + break + } + } + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *MsgUpgradeIsolatedPerpetualToCrossResponse) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: MsgUpgradeIsolatedPerpetualToCrossResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgUpgradeIsolatedPerpetualToCrossResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipTx(dAtA []byte) (n int, err error) { + l := len(dAtA) + iNdEx := 0 + depth := 0 + for iNdEx < l { + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowTx + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + wireType := int(wire & 0x7) + switch wireType { + case 0: + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowTx + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + iNdEx++ + if dAtA[iNdEx-1] < 0x80 { + break + } + } + case 1: + iNdEx += 8 + case 2: + var length int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowTx + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + length |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + if length < 0 { + return 0, ErrInvalidLengthTx + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupTx + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthTx + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthTx = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowTx = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupTx = fmt.Errorf("proto: unexpected end of group") +) From 8dc6937977d4995c5a660bc0d94d1b6abb977d4d Mon Sep 17 00:00:00 2001 From: Harry Wray Date: Mon, 4 Nov 2024 16:02:40 -0500 Subject: [PATCH 06/29] Update --- proto/dydxprotocol/listing/tx.proto | 2 +- protocol/x/clob/keeper/deleveraging.go | 18 +---- protocol/x/clob/keeper/keeper.go | 5 ++ protocol/x/clob/types/expected_keepers.go | 15 ++-- protocol/x/clob/types/liquidations_keeper.go | 4 -- protocol/x/listing/keeper/listing.go | 6 +- protocol/x/listing/types/expected_keepers.go | 7 ++ .../subaccounts/keeper/isolated_subaccount.go | 52 -------------- protocol/x/subaccounts/keeper/transfer.go | 68 +++++++++++++++++++ .../x/subaccounts/types/expected_keepers.go | 9 +++ 10 files changed, 105 insertions(+), 81 deletions(-) diff --git a/proto/dydxprotocol/listing/tx.proto b/proto/dydxprotocol/listing/tx.proto index 56ae5f525b..ff6078ffc7 100644 --- a/proto/dydxprotocol/listing/tx.proto +++ b/proto/dydxprotocol/listing/tx.proto @@ -89,4 +89,4 @@ message MsgUpgradeIsolatedPerpetualToCross { // MsgUpgradeIsolatedPerpetualToCrossResponse defines the // UpgradeIsolatedPerpetualToCross response type. -message MsgUpgradeIsolatedPerpetualToCrossResponse {} \ No newline at end of file +message MsgUpgradeIsolatedPerpetualToCrossResponse {} diff --git a/protocol/x/clob/keeper/deleveraging.go b/protocol/x/clob/keeper/deleveraging.go index 49954d29e5..d07a8dcdf6 100644 --- a/protocol/x/clob/keeper/deleveraging.go +++ b/protocol/x/clob/keeper/deleveraging.go @@ -18,7 +18,6 @@ import ( assettypes "github.com/dydxprotocol/v4-chain/protocol/x/assets/types" "github.com/dydxprotocol/v4-chain/protocol/x/clob/types" perplib "github.com/dydxprotocol/v4-chain/protocol/x/perpetuals/lib" - perptypes "github.com/dydxprotocol/v4-chain/protocol/x/perpetuals/types" satypes "github.com/dydxprotocol/v4-chain/protocol/x/subaccounts/types" ) @@ -130,21 +129,6 @@ func (k Keeper) MaybeDeleverageSubaccount( return quantumsDeleveraged, err } -func (k Keeper) GetCrossInsuranceFundBalance(ctx sdk.Context) (balance *big.Int) { - usdcAsset, exists := k.assetsKeeper.GetAsset(ctx, assettypes.AssetUsdc.Id) - if !exists { - panic("GetCrossInsuranceFundBalance: Usdc asset not found in state") - } - insuranceFundBalance := k.bankKeeper.GetBalance( - ctx, - perptypes.InsuranceFundModuleAddress, - usdcAsset.Denom, - ) - - // Return as big.Int. - return insuranceFundBalance.Amount.BigInt() -} - // CanDeleverageSubaccount returns true if a subaccount can be deleveraged. // This function returns two booleans, shouldDeleverageAtBankruptcyPrice and shouldDeleverageAtOraclePrice. // - shouldDeleverageAtBankruptcyPrice is true if the subaccount has negative TNC. @@ -257,7 +241,7 @@ func (k Keeper) IsValidInsuranceFundDelta(ctx sdk.Context, insuranceFundDelta *b // The insurance fund delta is valid if the insurance fund balance is non-negative after adding // the delta. - currentInsuranceFundBalance := k.subaccountsKeeper.GetInsuranceFundBalance(ctx, perpetualId) + currentInsuranceFundBalance := k.GetInsuranceFundBalance(ctx, perpetualId) return new(big.Int).Add(currentInsuranceFundBalance, insuranceFundDelta).Sign() >= 0 } diff --git a/protocol/x/clob/keeper/keeper.go b/protocol/x/clob/keeper/keeper.go index 633a0725b9..e371e91039 100644 --- a/protocol/x/clob/keeper/keeper.go +++ b/protocol/x/clob/keeper/keeper.go @@ -3,6 +3,7 @@ package keeper import ( "errors" "fmt" + "math/big" "sync/atomic" "github.com/dydxprotocol/v4-chain/protocol/finalizeblock" @@ -162,6 +163,10 @@ func (k Keeper) GetFullNodeStreamingManager() streamingtypes.FullNodeStreamingMa return k.streamingManager } +func (k Keeper) GetCrossInsuranceFundBalance(ctx sdk.Context) *big.Int { + return k.subaccountsKeeper.GetCrossInsuranceFundBalance(ctx) +} + func (k Keeper) Logger(ctx sdk.Context) log.Logger { return ctx.Logger().With( log.ModuleKey, "x/clob", diff --git a/protocol/x/clob/types/expected_keepers.go b/protocol/x/clob/types/expected_keepers.go index 7ff3d1c9f5..a1e3bafd3a 100644 --- a/protocol/x/clob/types/expected_keepers.go +++ b/protocol/x/clob/types/expected_keepers.go @@ -77,6 +77,17 @@ type SubaccountsKeeper interface { amount *big.Int, perpetualId uint32, ) error + GetInsuranceFundBalance( + ctx sdk.Context, + perpetualId uint32, + ) ( + balance *big.Int, + ) + GetCrossInsuranceFundBalance( + ctx sdk.Context, + ) ( + balance *big.Int, + ) GetCollateralPoolFromPerpetualId( ctx sdk.Context, perpetualId uint32, @@ -87,10 +98,6 @@ type SubaccountsKeeper interface { revSharesForFill revsharetypes.RevSharesForFill, fillForProcess FillForProcess, ) error - GetInsuranceFundBalance( - ctx sdk.Context, - perpetualId uint32, - ) *big.Int } type AssetsKeeper interface { diff --git a/protocol/x/clob/types/liquidations_keeper.go b/protocol/x/clob/types/liquidations_keeper.go index 7b72d364ea..6bdf9f7a72 100644 --- a/protocol/x/clob/types/liquidations_keeper.go +++ b/protocol/x/clob/types/liquidations_keeper.go @@ -51,10 +51,6 @@ type LiquidationsKeeper interface { fillablePrice *big.Rat, err error, ) - GetInsuranceFundBalance( - ctx sdk.Context, - perpetualId uint32, - ) (balance *big.Int) GetLiquidationInsuranceFundDelta( ctx sdk.Context, subaccountId satypes.SubaccountId, diff --git a/protocol/x/listing/keeper/listing.go b/protocol/x/listing/keeper/listing.go index 12aa61a446..901bc01fd9 100644 --- a/protocol/x/listing/keeper/listing.go +++ b/protocol/x/listing/keeper/listing.go @@ -154,16 +154,16 @@ func (k Keeper) CreatePerpetual( func (k Keeper) UpgradeIsolatedPerpetualToCross( ctx sdk.Context, - id uint32, + perpetualId uint32, ) error { - err := k.clobKeeper.TransferIsolatedInsuranceFundToCross(ctx, id) + err := k.SubaccountsKeeper.TransferIsolatedInsuranceFundToCross(ctx, perpetualId) if err != nil { return err } _, err = k.PerpetualsKeeper.SetPerpetualMarketType( ctx, - id, + perpetualId, perpetualtypes.PerpetualMarketType_PERPETUAL_MARKET_TYPE_CROSS, ) if err != nil { diff --git a/protocol/x/listing/types/expected_keepers.go b/protocol/x/listing/types/expected_keepers.go index 65bcdcb7d8..50feb21efb 100644 --- a/protocol/x/listing/types/expected_keepers.go +++ b/protocol/x/listing/types/expected_keepers.go @@ -95,3 +95,10 @@ type VaultKeeper interface { status vaulttypes.VaultStatus, ) error } + +type SubaccountsKeeper interface { + GetInsuranceFundBalance( + ctx sdk.Context, + perpetualId uint32, + ) *big.Int +} diff --git a/protocol/x/subaccounts/keeper/isolated_subaccount.go b/protocol/x/subaccounts/keeper/isolated_subaccount.go index 5da702ad69..af628f19fc 100644 --- a/protocol/x/subaccounts/keeper/isolated_subaccount.go +++ b/protocol/x/subaccounts/keeper/isolated_subaccount.go @@ -213,58 +213,6 @@ func GetIsolatedPerpetualStateTransition( return nil, nil } -// GetInsuranceFundBalance returns the current balance of the specific insurance fund based on the -// perpetual (in quote quantums). -// This calls the Bank Keeper’s GetBalance() function for the Module Address of the insurance fund. -func (k Keeper) GetInsuranceFundBalance(ctx sdk.Context, perpetualId uint32) (balance *big.Int) { - usdcAsset, exists := k.assetsKeeper.GetAsset(ctx, assettypes.AssetUsdc.Id) - if !exists { - panic("GetInsuranceFundBalance: Usdc asset not found in state") - } - insuranceFundAddr, err := k.perpetualsKeeper.GetInsuranceFundModuleAddress(ctx, perpetualId) - if err != nil { - return nil - } - insuranceFundBalance := k.bankKeeper.GetBalance( - ctx, - insuranceFundAddr, - usdcAsset.Denom, - ) - - // Return as big.Int. - return insuranceFundBalance.Amount.BigInt() -} - -// TransferInsuranceFundsForIsolatedPerpetual transfers funds from an isolated insurance fund -// to the cross-perpetual insurance fund based -// Note: This uses the `x/bank` keeper and modifies `x/bank` state. -func (k Keeper) TransferInsuranceFundsForIsolatedPerpetual(ctx sdk.Context, perpetualId uint32) error { - isolatedInsuranceFundBalance := k.GetInsuranceFundBalance(ctx, perpetualId) - - _, coinToTransfer, err := k.assetsKeeper.ConvertAssetToCoin( - ctx, - assettypes.AssetUsdc.Id, - new(big.Int).Abs(isolatedInsuranceFundBalance), - ) - if err != nil { - panic(err) - } - - isolatedInsuranceFundAddr, err := k.perpetualsKeeper.GetInsuranceFundModuleAddress(ctx, perpetualId) - if err != nil { - return nil - } - - crossInsuranceFundAddr := perptypes.InsuranceFundModuleAddress - - return k.bankKeeper.SendCoins( - ctx, - isolatedInsuranceFundAddr, - crossInsuranceFundAddr, - []sdk.Coin{coinToTransfer}, - ) -} - // transferCollateralForIsolatedPerpetual transfers collateral between an isolated collateral pool // and the cross-perpetual collateral pool based on whether an isolated perpetual position was // opened or closed in a subaccount. diff --git a/protocol/x/subaccounts/keeper/transfer.go b/protocol/x/subaccounts/keeper/transfer.go index 52ffedce14..8d813fa9b7 100644 --- a/protocol/x/subaccounts/keeper/transfer.go +++ b/protocol/x/subaccounts/keeper/transfer.go @@ -11,6 +11,7 @@ import ( "github.com/dydxprotocol/v4-chain/protocol/lib/metrics" assettypes "github.com/dydxprotocol/v4-chain/protocol/x/assets/types" clobtypes "github.com/dydxprotocol/v4-chain/protocol/x/clob/types" + perptypes "github.com/dydxprotocol/v4-chain/protocol/x/perpetuals/types" revsharetypes "github.com/dydxprotocol/v4-chain/protocol/x/revshare/types" "github.com/dydxprotocol/v4-chain/protocol/x/subaccounts/types" ) @@ -503,3 +504,70 @@ func (k Keeper) TransferFundsFromSubaccountToSubaccount( types.Transfer, ) } + +// GetInsuranceFundBalance returns the current balance of the specific insurance fund based on the +// perpetual (in quote quantums). +// This calls the Bank Keeper’s GetBalance() function for the Module Address of the insurance fund. +func (k Keeper) GetInsuranceFundBalance(ctx sdk.Context, perpetualId uint32) (balance *big.Int) { + usdcAsset, exists := k.assetsKeeper.GetAsset(ctx, assettypes.AssetUsdc.Id) + if !exists { + panic("GetInsuranceFundBalance: Usdc asset not found in state") + } + insuranceFundAddr, err := k.perpetualsKeeper.GetInsuranceFundModuleAddress(ctx, perpetualId) + if err != nil { + return nil + } + insuranceFundBalance := k.bankKeeper.GetBalance( + ctx, + insuranceFundAddr, + usdcAsset.Denom, + ) + + // Return as big.Int. + return insuranceFundBalance.Amount.BigInt() +} + +func (k Keeper) GetCrossInsuranceFundBalance(ctx sdk.Context) (balance *big.Int) { + usdcAsset, exists := k.assetsKeeper.GetAsset(ctx, assettypes.AssetUsdc.Id) + if !exists { + panic("GetCrossInsuranceFundBalance: Usdc asset not found in state") + } + insuranceFundBalance := k.bankKeeper.GetBalance( + ctx, + perptypes.InsuranceFundModuleAddress, + usdcAsset.Denom, + ) + + // Return as big.Int. + return insuranceFundBalance.Amount.BigInt() +} + +// TransferInsuranceFundsForIsolatedPerpetual transfers funds from an isolated perpetual +// insurance fund to the cross-perpetual insurance fund. +// Note: This uses the `x/bank` keeper and modifies `x/bank` state. +func (k Keeper) TransferInsuranceFundsForIsolatedPerpetual(ctx sdk.Context, perpetualId uint32) error { + isolatedInsuranceFundBalance := k.GetInsuranceFundBalance(ctx, perpetualId) + + _, coinToTransfer, err := k.assetsKeeper.ConvertAssetToCoin( + ctx, + assettypes.AssetUsdc.Id, + new(big.Int).Abs(isolatedInsuranceFundBalance), + ) + if err != nil { + panic(err) + } + + isolatedInsuranceFundAddr, err := k.perpetualsKeeper.GetInsuranceFundModuleAddress(ctx, perpetualId) + if err != nil { + return nil + } + + crossInsuranceFundAddr := perptypes.InsuranceFundModuleAddress + + return k.bankKeeper.SendCoins( + ctx, + isolatedInsuranceFundAddr, + crossInsuranceFundAddr, + []sdk.Coin{coinToTransfer}, + ) +} diff --git a/protocol/x/subaccounts/types/expected_keepers.go b/protocol/x/subaccounts/types/expected_keepers.go index a9e3f88f94..1a4a97ced3 100644 --- a/protocol/x/subaccounts/types/expected_keepers.go +++ b/protocol/x/subaccounts/types/expected_keepers.go @@ -6,6 +6,7 @@ import ( "time" sdk "github.com/cosmos/cosmos-sdk/types" + assettypes "github.com/dydxprotocol/v4-chain/protocol/x/assets/types" blocktimetypes "github.com/dydxprotocol/v4-chain/protocol/x/blocktime/types" perptypes "github.com/dydxprotocol/v4-chain/protocol/x/perpetuals/types" pricestypes "github.com/dydxprotocol/v4-chain/protocol/x/prices/types" @@ -28,6 +29,13 @@ type AssetsKeeper interface { coin sdk.Coin, err error, ) + GetAsset( + ctx sdk.Context, + id uint32, + ) ( + val assettypes.Asset, + exists bool, + ) } type PerpetualsKeeper interface { @@ -91,6 +99,7 @@ type BankKeeper interface { ) error SendCoinsFromModuleToModule(ctx context.Context, senderModule, recipientModule string, amt sdk.Coins) error SendCoins(ctx context.Context, fromAddr, toAddr sdk.AccAddress, amt sdk.Coins) error + GetBalance(ctx context.Context, addr sdk.AccAddress, denom string) sdk.Coin } type BlocktimeKeeper interface { From b14e6b917f02f409d9a8f1461655993961c5a645 Mon Sep 17 00:00:00 2001 From: Harry Wray Date: Mon, 4 Nov 2024 16:10:29 -0500 Subject: [PATCH 07/29] Update --- protocol/x/clob/keeper/deleveraging.go | 2 +- protocol/x/listing/keeper/keeper.go | 35 +++++++++++--------- protocol/x/listing/types/expected_keepers.go | 4 +-- protocol/x/subaccounts/keeper/transfer.go | 2 +- 4 files changed, 23 insertions(+), 20 deletions(-) diff --git a/protocol/x/clob/keeper/deleveraging.go b/protocol/x/clob/keeper/deleveraging.go index d07a8dcdf6..a525deb521 100644 --- a/protocol/x/clob/keeper/deleveraging.go +++ b/protocol/x/clob/keeper/deleveraging.go @@ -241,7 +241,7 @@ func (k Keeper) IsValidInsuranceFundDelta(ctx sdk.Context, insuranceFundDelta *b // The insurance fund delta is valid if the insurance fund balance is non-negative after adding // the delta. - currentInsuranceFundBalance := k.GetInsuranceFundBalance(ctx, perpetualId) + currentInsuranceFundBalance := k.subaccountsKeeper.GetInsuranceFundBalance(ctx, perpetualId) return new(big.Int).Add(currentInsuranceFundBalance, insuranceFundDelta).Sign() >= 0 } diff --git a/protocol/x/listing/keeper/keeper.go b/protocol/x/listing/keeper/keeper.go index 881fa63fe5..662fea98f4 100644 --- a/protocol/x/listing/keeper/keeper.go +++ b/protocol/x/listing/keeper/keeper.go @@ -13,14 +13,15 @@ import ( type ( Keeper struct { - cdc codec.BinaryCodec - storeKey storetypes.StoreKey - authorities map[string]struct{} - PricesKeeper types.PricesKeeper - ClobKeeper types.ClobKeeper - MarketMapKeeper types.MarketMapKeeper - PerpetualsKeeper types.PerpetualsKeeper - VaultKeeper types.VaultKeeper + cdc codec.BinaryCodec + storeKey storetypes.StoreKey + authorities map[string]struct{} + PricesKeeper types.PricesKeeper + ClobKeeper types.ClobKeeper + MarketMapKeeper types.MarketMapKeeper + PerpetualsKeeper types.PerpetualsKeeper + SubaccountsKeeper types.SubaccountsKeeper + VaultKeeper types.VaultKeeper } ) @@ -32,17 +33,19 @@ func NewKeeper( clobKeeper types.ClobKeeper, marketMapKeeper types.MarketMapKeeper, perpetualsKeeper types.PerpetualsKeeper, + subaccountsKeeper types.SubaccountsKeeper, vaultKeeper types.VaultKeeper, ) *Keeper { return &Keeper{ - cdc: cdc, - storeKey: storeKey, - authorities: lib.UniqueSliceToSet(authorities), - PricesKeeper: pricesKeeper, - ClobKeeper: clobKeeper, - MarketMapKeeper: marketMapKeeper, - PerpetualsKeeper: perpetualsKeeper, - VaultKeeper: vaultKeeper, + cdc: cdc, + storeKey: storeKey, + authorities: lib.UniqueSliceToSet(authorities), + PricesKeeper: pricesKeeper, + ClobKeeper: clobKeeper, + MarketMapKeeper: marketMapKeeper, + PerpetualsKeeper: perpetualsKeeper, + SubaccountsKeeper: subaccountsKeeper, + VaultKeeper: vaultKeeper, } } diff --git a/protocol/x/listing/types/expected_keepers.go b/protocol/x/listing/types/expected_keepers.go index 50feb21efb..c46b65bc23 100644 --- a/protocol/x/listing/types/expected_keepers.go +++ b/protocol/x/listing/types/expected_keepers.go @@ -97,8 +97,8 @@ type VaultKeeper interface { } type SubaccountsKeeper interface { - GetInsuranceFundBalance( + TransferIsolatedInsuranceFundToCross( ctx sdk.Context, perpetualId uint32, - ) *big.Int + ) error } diff --git a/protocol/x/subaccounts/keeper/transfer.go b/protocol/x/subaccounts/keeper/transfer.go index 8d813fa9b7..f6a90b11f2 100644 --- a/protocol/x/subaccounts/keeper/transfer.go +++ b/protocol/x/subaccounts/keeper/transfer.go @@ -545,7 +545,7 @@ func (k Keeper) GetCrossInsuranceFundBalance(ctx sdk.Context) (balance *big.Int) // TransferInsuranceFundsForIsolatedPerpetual transfers funds from an isolated perpetual // insurance fund to the cross-perpetual insurance fund. // Note: This uses the `x/bank` keeper and modifies `x/bank` state. -func (k Keeper) TransferInsuranceFundsForIsolatedPerpetual(ctx sdk.Context, perpetualId uint32) error { +func (k Keeper) TransferIsolatedInsuranceFundToCross(ctx sdk.Context, perpetualId uint32) error { isolatedInsuranceFundBalance := k.GetInsuranceFundBalance(ctx, perpetualId) _, coinToTransfer, err := k.assetsKeeper.ConvertAssetToCoin( From 3d3044ae2527836ffd68e0cb78fce6eb24a76998 Mon Sep 17 00:00:00 2001 From: Harry Wray Date: Thu, 7 Nov 2024 15:19:43 -0500 Subject: [PATCH 08/29] Update --- protocol/x/listing/keeper/listing.go | 13 +- ...ver_upgrade_isolated_perpetual_to_cross.go | 2 +- ...grade_isolated_perpetual_to_cross_test.go} | 0 protocol/x/listing/types/expected_keepers.go | 4 + protocol/x/subaccounts/keeper/transfer.go | 31 +- protocol/x/subaccounts/types/tx.pb.go | 578 ------------------ 6 files changed, 44 insertions(+), 584 deletions(-) rename protocol/x/listing/keeper/{msg_upgrade_isolated_perpetual_to_cross_test.go => msg_server_upgrade_isolated_perpetual_to_cross_test.go} (100%) delete mode 100644 protocol/x/subaccounts/types/tx.pb.go diff --git a/protocol/x/listing/keeper/listing.go b/protocol/x/listing/keeper/listing.go index 901bc01fd9..29f3814d39 100644 --- a/protocol/x/listing/keeper/listing.go +++ b/protocol/x/listing/keeper/listing.go @@ -161,6 +161,12 @@ func (k Keeper) UpgradeIsolatedPerpetualToCross( return err } + // TODO Move collateral pool for perpetual to subaccounts module + err = k.SubaccountsKeeper.TransferIsolatedCollateralToCross(ctx, perpetualId) + if err != nil { + return err + } + _, err = k.PerpetualsKeeper.SetPerpetualMarketType( ctx, perpetualId, @@ -170,10 +176,11 @@ func (k Keeper) UpgradeIsolatedPerpetualToCross( return err } - // TODO Move collateral pool for perpetual to subaccounts module - // See transferCollateralForIsolatedPerpetual()? - // TODO Propagate changes to indexer + // See perpetual.go, modifyperpetual + // Put the proto code for the new message in events.proto + // And requires changes to indexer to process the new event - write typescript handler in indexer/services/ender/src/handlers + // And also some SQL handlers in scripts/handlers return nil } diff --git a/protocol/x/listing/keeper/msg_server_upgrade_isolated_perpetual_to_cross.go b/protocol/x/listing/keeper/msg_server_upgrade_isolated_perpetual_to_cross.go index 70c7341a64..a7599eb65f 100644 --- a/protocol/x/listing/keeper/msg_server_upgrade_isolated_perpetual_to_cross.go +++ b/protocol/x/listing/keeper/msg_server_upgrade_isolated_perpetual_to_cross.go @@ -6,7 +6,7 @@ import ( errorsmod "cosmossdk.io/errors" govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" "github.com/dydxprotocol/v4-chain/protocol/lib" - "github.com/dydxprotocol/v4-chain/protocol/x/subaccounts/types" + "github.com/dydxprotocol/v4-chain/protocol/x/listing/types" ) func (k msgServer) UpgradeIsolatedPerpetualToCross( diff --git a/protocol/x/listing/keeper/msg_upgrade_isolated_perpetual_to_cross_test.go b/protocol/x/listing/keeper/msg_server_upgrade_isolated_perpetual_to_cross_test.go similarity index 100% rename from protocol/x/listing/keeper/msg_upgrade_isolated_perpetual_to_cross_test.go rename to protocol/x/listing/keeper/msg_server_upgrade_isolated_perpetual_to_cross_test.go diff --git a/protocol/x/listing/types/expected_keepers.go b/protocol/x/listing/types/expected_keepers.go index c46b65bc23..ddf9cb0913 100644 --- a/protocol/x/listing/types/expected_keepers.go +++ b/protocol/x/listing/types/expected_keepers.go @@ -101,4 +101,8 @@ type SubaccountsKeeper interface { ctx sdk.Context, perpetualId uint32, ) error + TransferIsolatedCollateralToCross( + ctx sdk.Context, + perpetualId uint32, + ) error } diff --git a/protocol/x/subaccounts/keeper/transfer.go b/protocol/x/subaccounts/keeper/transfer.go index f6a90b11f2..2ea2e23c45 100644 --- a/protocol/x/subaccounts/keeper/transfer.go +++ b/protocol/x/subaccounts/keeper/transfer.go @@ -542,7 +542,7 @@ func (k Keeper) GetCrossInsuranceFundBalance(ctx sdk.Context) (balance *big.Int) return insuranceFundBalance.Amount.BigInt() } -// TransferInsuranceFundsForIsolatedPerpetual transfers funds from an isolated perpetual +// TransferIsolatedInsuranceFundToCross transfers funds from an isolated perpetual's // insurance fund to the cross-perpetual insurance fund. // Note: This uses the `x/bank` keeper and modifies `x/bank` state. func (k Keeper) TransferIsolatedInsuranceFundToCross(ctx sdk.Context, perpetualId uint32) error { @@ -551,7 +551,7 @@ func (k Keeper) TransferIsolatedInsuranceFundToCross(ctx sdk.Context, perpetualI _, coinToTransfer, err := k.assetsKeeper.ConvertAssetToCoin( ctx, assettypes.AssetUsdc.Id, - new(big.Int).Abs(isolatedInsuranceFundBalance), + isolatedInsuranceFundBalance, ) if err != nil { panic(err) @@ -571,3 +571,30 @@ func (k Keeper) TransferIsolatedInsuranceFundToCross(ctx sdk.Context, perpetualI []sdk.Coin{coinToTransfer}, ) } + +func (k Keeper) TransferIsolatedCollateralToCross(ctx sdk.Context, perpetualId uint32) error { + isolatedCollateralPoolAddr, err := k.GetCollateralPoolFromPerpetualId(ctx, perpetualId) + if err != nil { + return err + } + + crossCollateralPoolAddr := types.ModuleAddress + + usdcAsset, exists := k.assetsKeeper.GetAsset(ctx, assettypes.AssetUsdc.Id) + if !exists { + panic("TransferIsolatedCollateralToCross: Usdc asset not found in state") + } + + isolatedCollateralPoolBalance := k.bankKeeper.GetBalance( + ctx, + isolatedCollateralPoolAddr, + usdcAsset.Denom, + ) + + return k.bankKeeper.SendCoins( + ctx, + isolatedCollateralPoolAddr, + crossCollateralPoolAddr, + []sdk.Coin{isolatedCollateralPoolBalance}, + ) +} diff --git a/protocol/x/subaccounts/types/tx.pb.go b/protocol/x/subaccounts/types/tx.pb.go deleted file mode 100644 index 307aea4a53..0000000000 --- a/protocol/x/subaccounts/types/tx.pb.go +++ /dev/null @@ -1,578 +0,0 @@ -// Code generated by protoc-gen-gogo. DO NOT EDIT. -// source: dydxprotocol/subaccounts/tx.proto - -package types - -import ( - context "context" - fmt "fmt" - _ "github.com/cosmos/cosmos-proto" - _ "github.com/cosmos/cosmos-sdk/types/msgservice" - _ "github.com/cosmos/gogoproto/gogoproto" - grpc1 "github.com/cosmos/gogoproto/grpc" - proto "github.com/cosmos/gogoproto/proto" - grpc "google.golang.org/grpc" - codes "google.golang.org/grpc/codes" - status "google.golang.org/grpc/status" - io "io" - math "math" - math_bits "math/bits" -) - -// Reference imports to suppress errors if they are not otherwise used. -var _ = proto.Marshal -var _ = fmt.Errorf -var _ = math.Inf - -// This is a compile-time assertion to ensure that this generated file -// is compatible with the proto package it is being compiled against. -// A compilation error at this line likely means your copy of the -// proto package needs to be updated. -const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package - -// MsgUpgradeIsolatedPerpetualToCross is used to upgrade a market from -// isolated margin to cross margin. -type MsgUpgradeIsolatedPerpetualToCross struct { - Authority string `protobuf:"bytes,1,opt,name=authority,proto3" json:"authority,omitempty"` - // ID of the perpetual to be upgraded to CROSS - PerpetualId uint32 `protobuf:"varint,2,opt,name=perpetual_id,json=perpetualId,proto3" json:"perpetual_id,omitempty"` -} - -func (m *MsgUpgradeIsolatedPerpetualToCross) Reset() { *m = MsgUpgradeIsolatedPerpetualToCross{} } -func (m *MsgUpgradeIsolatedPerpetualToCross) String() string { return proto.CompactTextString(m) } -func (*MsgUpgradeIsolatedPerpetualToCross) ProtoMessage() {} -func (*MsgUpgradeIsolatedPerpetualToCross) Descriptor() ([]byte, []int) { - return fileDescriptor_16edbf88307684e5, []int{0} -} -func (m *MsgUpgradeIsolatedPerpetualToCross) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *MsgUpgradeIsolatedPerpetualToCross) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_MsgUpgradeIsolatedPerpetualToCross.Marshal(b, m, deterministic) - } else { - b = b[:cap(b)] - n, err := m.MarshalToSizedBuffer(b) - if err != nil { - return nil, err - } - return b[:n], nil - } -} -func (m *MsgUpgradeIsolatedPerpetualToCross) XXX_Merge(src proto.Message) { - xxx_messageInfo_MsgUpgradeIsolatedPerpetualToCross.Merge(m, src) -} -func (m *MsgUpgradeIsolatedPerpetualToCross) XXX_Size() int { - return m.Size() -} -func (m *MsgUpgradeIsolatedPerpetualToCross) XXX_DiscardUnknown() { - xxx_messageInfo_MsgUpgradeIsolatedPerpetualToCross.DiscardUnknown(m) -} - -var xxx_messageInfo_MsgUpgradeIsolatedPerpetualToCross proto.InternalMessageInfo - -func (m *MsgUpgradeIsolatedPerpetualToCross) GetAuthority() string { - if m != nil { - return m.Authority - } - return "" -} - -func (m *MsgUpgradeIsolatedPerpetualToCross) GetPerpetualId() uint32 { - if m != nil { - return m.PerpetualId - } - return 0 -} - -// MsgUpgradeIsolatedPerpetualToCrossResponse defines the -// UpgradeIsolatedPerpetualToCross response type. -type MsgUpgradeIsolatedPerpetualToCrossResponse struct { -} - -func (m *MsgUpgradeIsolatedPerpetualToCrossResponse) Reset() { - *m = MsgUpgradeIsolatedPerpetualToCrossResponse{} -} -func (m *MsgUpgradeIsolatedPerpetualToCrossResponse) String() string { - return proto.CompactTextString(m) -} -func (*MsgUpgradeIsolatedPerpetualToCrossResponse) ProtoMessage() {} -func (*MsgUpgradeIsolatedPerpetualToCrossResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_16edbf88307684e5, []int{1} -} -func (m *MsgUpgradeIsolatedPerpetualToCrossResponse) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *MsgUpgradeIsolatedPerpetualToCrossResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_MsgUpgradeIsolatedPerpetualToCrossResponse.Marshal(b, m, deterministic) - } else { - b = b[:cap(b)] - n, err := m.MarshalToSizedBuffer(b) - if err != nil { - return nil, err - } - return b[:n], nil - } -} -func (m *MsgUpgradeIsolatedPerpetualToCrossResponse) XXX_Merge(src proto.Message) { - xxx_messageInfo_MsgUpgradeIsolatedPerpetualToCrossResponse.Merge(m, src) -} -func (m *MsgUpgradeIsolatedPerpetualToCrossResponse) XXX_Size() int { - return m.Size() -} -func (m *MsgUpgradeIsolatedPerpetualToCrossResponse) XXX_DiscardUnknown() { - xxx_messageInfo_MsgUpgradeIsolatedPerpetualToCrossResponse.DiscardUnknown(m) -} - -var xxx_messageInfo_MsgUpgradeIsolatedPerpetualToCrossResponse proto.InternalMessageInfo - -func init() { - proto.RegisterType((*MsgUpgradeIsolatedPerpetualToCross)(nil), "dydxprotocol.subaccounts.MsgUpgradeIsolatedPerpetualToCross") - proto.RegisterType((*MsgUpgradeIsolatedPerpetualToCrossResponse)(nil), "dydxprotocol.subaccounts.MsgUpgradeIsolatedPerpetualToCrossResponse") -} - -func init() { proto.RegisterFile("dydxprotocol/subaccounts/tx.proto", fileDescriptor_16edbf88307684e5) } - -var fileDescriptor_16edbf88307684e5 = []byte{ - // 328 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x52, 0x4c, 0xa9, 0x4c, 0xa9, - 0x28, 0x28, 0xca, 0x2f, 0xc9, 0x4f, 0xce, 0xcf, 0xd1, 0x2f, 0x2e, 0x4d, 0x4a, 0x4c, 0x4e, 0xce, - 0x2f, 0xcd, 0x2b, 0x29, 0xd6, 0x2f, 0xa9, 0xd0, 0x03, 0x8b, 0x0b, 0x49, 0x20, 0x2b, 0xd1, 0x43, - 0x52, 0x22, 0x25, 0x99, 0x9c, 0x5f, 0x9c, 0x9b, 0x5f, 0x1c, 0x0f, 0x96, 0xd4, 0x87, 0x70, 0x20, - 0x9a, 0xa4, 0xc4, 0x21, 0x3c, 0xfd, 0xdc, 0xe2, 0x74, 0xfd, 0x32, 0x43, 0x10, 0x05, 0x95, 0x10, - 0x49, 0xcf, 0x4f, 0xcf, 0x87, 0x68, 0x00, 0xb1, 0x20, 0xa2, 0x4a, 0xfd, 0x8c, 0x5c, 0x4a, 0xbe, - 0xc5, 0xe9, 0xa1, 0x05, 0xe9, 0x45, 0x89, 0x29, 0xa9, 0x9e, 0xc5, 0xf9, 0x39, 0x89, 0x25, 0xa9, - 0x29, 0x01, 0xa9, 0x45, 0x05, 0xa9, 0x25, 0xa5, 0x89, 0x39, 0x21, 0xf9, 0xce, 0x45, 0xf9, 0xc5, - 0xc5, 0x42, 0x66, 0x5c, 0x9c, 0x89, 0xa5, 0x25, 0x19, 0xf9, 0x45, 0x99, 0x25, 0x95, 0x12, 0x8c, - 0x0a, 0x8c, 0x1a, 0x9c, 0x4e, 0x12, 0x97, 0xb6, 0xe8, 0x8a, 0x40, 0xad, 0x76, 0x4c, 0x49, 0x29, - 0x4a, 0x2d, 0x2e, 0x0e, 0x2e, 0x29, 0xca, 0xcc, 0x4b, 0x0f, 0x42, 0x28, 0x15, 0x52, 0xe4, 0xe2, - 0x29, 0x80, 0x99, 0x15, 0x9f, 0x99, 0x22, 0xc1, 0xa4, 0xc0, 0xa8, 0xc1, 0x1b, 0xc4, 0x0d, 0x17, - 0xf3, 0x4c, 0xb1, 0xe2, 0x6b, 0x7a, 0xbe, 0x41, 0x0b, 0xa1, 0x45, 0x49, 0x87, 0x4b, 0x8b, 0xb0, - 0x83, 0x82, 0x52, 0x8b, 0x0b, 0xf2, 0xf3, 0x8a, 0x53, 0x8d, 0xd6, 0x32, 0x72, 0x31, 0xfb, 0x16, - 0xa7, 0x0b, 0x2d, 0x65, 0xe4, 0x92, 0x27, 0xe4, 0x09, 0x1b, 0x3d, 0x5c, 0x01, 0xaa, 0x47, 0xd8, - 0x46, 0x29, 0x17, 0x4a, 0x74, 0xc3, 0xdc, 0xeb, 0x14, 0x7e, 0xe2, 0x91, 0x1c, 0xe3, 0x85, 0x47, - 0x72, 0x8c, 0x0f, 0x1e, 0xc9, 0x31, 0x4e, 0x78, 0x2c, 0xc7, 0x70, 0xe1, 0xb1, 0x1c, 0xc3, 0x8d, - 0xc7, 0x72, 0x0c, 0x51, 0xb6, 0xe9, 0x99, 0x25, 0x19, 0xa5, 0x49, 0x7a, 0xc9, 0xf9, 0xb9, 0xfa, - 0x28, 0x69, 0xa3, 0xcc, 0x44, 0x37, 0x39, 0x23, 0x31, 0x33, 0x4f, 0x1f, 0x2e, 0x52, 0x81, 0x9a, - 0x5e, 0x2a, 0x0b, 0x52, 0x8b, 0x93, 0xd8, 0xc0, 0xb2, 0xc6, 0x80, 0x00, 0x00, 0x00, 0xff, 0xff, - 0xa1, 0x2b, 0x66, 0x7f, 0x58, 0x02, 0x00, 0x00, -} - -// Reference imports to suppress errors if they are not otherwise used. -var _ context.Context -var _ grpc.ClientConn - -// This is a compile-time assertion to ensure that this generated file -// is compatible with the grpc package it is being compiled against. -const _ = grpc.SupportPackageIsVersion4 - -// MsgClient is the client API for Msg service. -// -// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. -type MsgClient interface { - // UpgradeIsolatedPerpetualToCross upgrades a perpetual from isolated to cross margin. - UpgradeIsolatedPerpetualToCross(ctx context.Context, in *MsgUpgradeIsolatedPerpetualToCross, opts ...grpc.CallOption) (*MsgUpgradeIsolatedPerpetualToCrossResponse, error) -} - -type msgClient struct { - cc grpc1.ClientConn -} - -func NewMsgClient(cc grpc1.ClientConn) MsgClient { - return &msgClient{cc} -} - -func (c *msgClient) UpgradeIsolatedPerpetualToCross(ctx context.Context, in *MsgUpgradeIsolatedPerpetualToCross, opts ...grpc.CallOption) (*MsgUpgradeIsolatedPerpetualToCrossResponse, error) { - out := new(MsgUpgradeIsolatedPerpetualToCrossResponse) - err := c.cc.Invoke(ctx, "/dydxprotocol.subaccounts.Msg/UpgradeIsolatedPerpetualToCross", in, out, opts...) - if err != nil { - return nil, err - } - return out, nil -} - -// MsgServer is the server API for Msg service. -type MsgServer interface { - // UpgradeIsolatedPerpetualToCross upgrades a perpetual from isolated to cross margin. - UpgradeIsolatedPerpetualToCross(context.Context, *MsgUpgradeIsolatedPerpetualToCross) (*MsgUpgradeIsolatedPerpetualToCrossResponse, error) -} - -// UnimplementedMsgServer can be embedded to have forward compatible implementations. -type UnimplementedMsgServer struct { -} - -func (*UnimplementedMsgServer) UpgradeIsolatedPerpetualToCross(ctx context.Context, req *MsgUpgradeIsolatedPerpetualToCross) (*MsgUpgradeIsolatedPerpetualToCrossResponse, error) { - return nil, status.Errorf(codes.Unimplemented, "method UpgradeIsolatedPerpetualToCross not implemented") -} - -func RegisterMsgServer(s grpc1.Server, srv MsgServer) { - s.RegisterService(&_Msg_serviceDesc, srv) -} - -func _Msg_UpgradeIsolatedPerpetualToCross_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(MsgUpgradeIsolatedPerpetualToCross) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(MsgServer).UpgradeIsolatedPerpetualToCross(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: "/dydxprotocol.subaccounts.Msg/UpgradeIsolatedPerpetualToCross", - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(MsgServer).UpgradeIsolatedPerpetualToCross(ctx, req.(*MsgUpgradeIsolatedPerpetualToCross)) - } - return interceptor(ctx, in, info, handler) -} - -var _Msg_serviceDesc = grpc.ServiceDesc{ - ServiceName: "dydxprotocol.subaccounts.Msg", - HandlerType: (*MsgServer)(nil), - Methods: []grpc.MethodDesc{ - { - MethodName: "UpgradeIsolatedPerpetualToCross", - Handler: _Msg_UpgradeIsolatedPerpetualToCross_Handler, - }, - }, - Streams: []grpc.StreamDesc{}, - Metadata: "dydxprotocol/subaccounts/tx.proto", -} - -func (m *MsgUpgradeIsolatedPerpetualToCross) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalToSizedBuffer(dAtA[:size]) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *MsgUpgradeIsolatedPerpetualToCross) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *MsgUpgradeIsolatedPerpetualToCross) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - if m.PerpetualId != 0 { - i = encodeVarintTx(dAtA, i, uint64(m.PerpetualId)) - i-- - dAtA[i] = 0x10 - } - if len(m.Authority) > 0 { - i -= len(m.Authority) - copy(dAtA[i:], m.Authority) - i = encodeVarintTx(dAtA, i, uint64(len(m.Authority))) - i-- - dAtA[i] = 0xa - } - return len(dAtA) - i, nil -} - -func (m *MsgUpgradeIsolatedPerpetualToCrossResponse) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalToSizedBuffer(dAtA[:size]) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *MsgUpgradeIsolatedPerpetualToCrossResponse) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *MsgUpgradeIsolatedPerpetualToCrossResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - return len(dAtA) - i, nil -} - -func encodeVarintTx(dAtA []byte, offset int, v uint64) int { - offset -= sovTx(v) - base := offset - for v >= 1<<7 { - dAtA[offset] = uint8(v&0x7f | 0x80) - v >>= 7 - offset++ - } - dAtA[offset] = uint8(v) - return base -} -func (m *MsgUpgradeIsolatedPerpetualToCross) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - l = len(m.Authority) - if l > 0 { - n += 1 + l + sovTx(uint64(l)) - } - if m.PerpetualId != 0 { - n += 1 + sovTx(uint64(m.PerpetualId)) - } - return n -} - -func (m *MsgUpgradeIsolatedPerpetualToCrossResponse) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - return n -} - -func sovTx(x uint64) (n int) { - return (math_bits.Len64(x|1) + 6) / 7 -} -func sozTx(x uint64) (n int) { - return sovTx(uint64((x << 1) ^ uint64((int64(x) >> 63)))) -} -func (m *MsgUpgradeIsolatedPerpetualToCross) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowTx - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: MsgUpgradeIsolatedPerpetualToCross: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: MsgUpgradeIsolatedPerpetualToCross: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Authority", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowTx - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthTx - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthTx - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Authority = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 2: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field PerpetualId", wireType) - } - m.PerpetualId = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowTx - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.PerpetualId |= uint32(b&0x7F) << shift - if b < 0x80 { - break - } - } - default: - iNdEx = preIndex - skippy, err := skipTx(dAtA[iNdEx:]) - if err != nil { - return err - } - if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLengthTx - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *MsgUpgradeIsolatedPerpetualToCrossResponse) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowTx - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: MsgUpgradeIsolatedPerpetualToCrossResponse: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: MsgUpgradeIsolatedPerpetualToCrossResponse: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - default: - iNdEx = preIndex - skippy, err := skipTx(dAtA[iNdEx:]) - if err != nil { - return err - } - if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLengthTx - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func skipTx(dAtA []byte) (n int, err error) { - l := len(dAtA) - iNdEx := 0 - depth := 0 - for iNdEx < l { - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowTx - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - wireType := int(wire & 0x7) - switch wireType { - case 0: - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowTx - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - iNdEx++ - if dAtA[iNdEx-1] < 0x80 { - break - } - } - case 1: - iNdEx += 8 - case 2: - var length int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowTx - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - length |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if length < 0 { - return 0, ErrInvalidLengthTx - } - iNdEx += length - case 3: - depth++ - case 4: - if depth == 0 { - return 0, ErrUnexpectedEndOfGroupTx - } - depth-- - case 5: - iNdEx += 4 - default: - return 0, fmt.Errorf("proto: illegal wireType %d", wireType) - } - if iNdEx < 0 { - return 0, ErrInvalidLengthTx - } - if depth == 0 { - return iNdEx, nil - } - } - return 0, io.ErrUnexpectedEOF -} - -var ( - ErrInvalidLengthTx = fmt.Errorf("proto: negative length found during unmarshaling") - ErrIntOverflowTx = fmt.Errorf("proto: integer overflow") - ErrUnexpectedEndOfGroupTx = fmt.Errorf("proto: unexpected end of group") -) From 4adf03dc19bb107445f97781d60692cbc7050d25 Mon Sep 17 00:00:00 2001 From: Harry Wray Date: Thu, 7 Nov 2024 15:25:59 -0500 Subject: [PATCH 09/29] Update --- protocol/mocks/AssetsKeeper.go | 2 +- protocol/mocks/ClobKeeper.go | 20 --- protocol/mocks/DelayMsgKeeper.go | 239 ---------------------------- protocol/mocks/MsgRouter.go | 49 ------ protocol/mocks/PerpetualsKeeper.go | 37 +---- protocol/mocks/SubaccountsKeeper.go | 5 - protocol/mocks/TxBuilder.go | 151 ------------------ 7 files changed, 3 insertions(+), 500 deletions(-) diff --git a/protocol/mocks/AssetsKeeper.go b/protocol/mocks/AssetsKeeper.go index b117d6596b..6942c91773 100644 --- a/protocol/mocks/AssetsKeeper.go +++ b/protocol/mocks/AssetsKeeper.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.44.1. DO NOT EDIT. +// Code generated by mockery v2.46.0. DO NOT EDIT. package mocks diff --git a/protocol/mocks/ClobKeeper.go b/protocol/mocks/ClobKeeper.go index 2a7b5cfd9c..0bc8520214 100644 --- a/protocol/mocks/ClobKeeper.go +++ b/protocol/mocks/ClobKeeper.go @@ -332,26 +332,6 @@ func (_m *ClobKeeper) GetIndexerEventManager() indexer_manager.IndexerEventManag return r0 } -// GetInsuranceFundBalance provides a mock function with given fields: ctx, perpetualId -func (_m *ClobKeeper) GetInsuranceFundBalance(ctx types.Context, perpetualId uint32) *big.Int { - ret := _m.Called(ctx, perpetualId) - - if len(ret) == 0 { - panic("no return value specified for GetInsuranceFundBalance") - } - - var r0 *big.Int - if rf, ok := ret.Get(0).(func(types.Context, uint32) *big.Int); ok { - r0 = rf(ctx, perpetualId) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(*big.Int) - } - } - - return r0 -} - // GetLiquidationInsuranceFundDelta provides a mock function with given fields: ctx, subaccountId, perpetualId, isBuy, fillAmount, subticks func (_m *ClobKeeper) GetLiquidationInsuranceFundDelta(ctx types.Context, subaccountId subaccountstypes.SubaccountId, perpetualId uint32, isBuy bool, fillAmount uint64, subticks clobtypes.Subticks) (*big.Int, error) { ret := _m.Called(ctx, subaccountId, perpetualId, isBuy, fillAmount, subticks) diff --git a/protocol/mocks/DelayMsgKeeper.go b/protocol/mocks/DelayMsgKeeper.go index 04d6e65d68..e69de29bb2 100644 --- a/protocol/mocks/DelayMsgKeeper.go +++ b/protocol/mocks/DelayMsgKeeper.go @@ -1,239 +0,0 @@ - -// Code generated by mockery v2.44.1. DO NOT EDIT. - -package mocks - -import ( - lib "github.com/dydxprotocol/v4-chain/protocol/lib" - delaymsgtypes "github.com/dydxprotocol/v4-chain/protocol/x/delaymsg/types" - - log "cosmossdk.io/log" - - mock "github.com/stretchr/testify/mock" - - proto "github.com/cosmos/gogoproto/proto" - - types "github.com/cosmos/cosmos-sdk/types" -) - -// DelayMsgKeeper is an autogenerated mock type for the DelayMsgKeeper type -type DelayMsgKeeper struct { - mock.Mock -} - -// DelayMessageByBlocks provides a mock function with given fields: ctx, msg, blockDelay -func (_m *DelayMsgKeeper) DelayMessageByBlocks(ctx types.Context, msg proto.Message, blockDelay uint32) (uint32, error) { - ret := _m.Called(ctx, msg, blockDelay) - - if len(ret) == 0 { - panic("no return value specified for DelayMessageByBlocks") - } - - var r0 uint32 - var r1 error - if rf, ok := ret.Get(0).(func(types.Context, proto.Message, uint32) (uint32, error)); ok { - return rf(ctx, msg, blockDelay) - } - if rf, ok := ret.Get(0).(func(types.Context, proto.Message, uint32) uint32); ok { - r0 = rf(ctx, msg, blockDelay) - } else { - r0 = ret.Get(0).(uint32) - } - - if rf, ok := ret.Get(1).(func(types.Context, proto.Message, uint32) error); ok { - r1 = rf(ctx, msg, blockDelay) - } else { - r1 = ret.Error(1) - } - - return r0, r1 -} - -// DeleteMessage provides a mock function with given fields: ctx, id -func (_m *DelayMsgKeeper) DeleteMessage(ctx types.Context, id uint32) error { - ret := _m.Called(ctx, id) - - if len(ret) == 0 { - panic("no return value specified for DeleteMessage") - } - - var r0 error - if rf, ok := ret.Get(0).(func(types.Context, uint32) error); ok { - r0 = rf(ctx, id) - } else { - r0 = ret.Error(0) - } - - return r0 -} - -// GetAllDelayedMessages provides a mock function with given fields: ctx -func (_m *DelayMsgKeeper) GetAllDelayedMessages(ctx types.Context) []*delaymsgtypes.DelayedMessage { - ret := _m.Called(ctx) - - if len(ret) == 0 { - panic("no return value specified for GetAllDelayedMessages") - } - - var r0 []*delaymsgtypes.DelayedMessage - if rf, ok := ret.Get(0).(func(types.Context) []*delaymsgtypes.DelayedMessage); ok { - r0 = rf(ctx) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).([]*delaymsgtypes.DelayedMessage) - } - } - - return r0 -} - -// GetBlockMessageIds provides a mock function with given fields: ctx, blockHeight -func (_m *DelayMsgKeeper) GetBlockMessageIds(ctx types.Context, blockHeight uint32) (delaymsgtypes.BlockMessageIds, bool) { - ret := _m.Called(ctx, blockHeight) - - if len(ret) == 0 { - panic("no return value specified for GetBlockMessageIds") - } - - var r0 delaymsgtypes.BlockMessageIds - var r1 bool - if rf, ok := ret.Get(0).(func(types.Context, uint32) (delaymsgtypes.BlockMessageIds, bool)); ok { - return rf(ctx, blockHeight) - } - if rf, ok := ret.Get(0).(func(types.Context, uint32) delaymsgtypes.BlockMessageIds); ok { - r0 = rf(ctx, blockHeight) - } else { - r0 = ret.Get(0).(delaymsgtypes.BlockMessageIds) - } - - if rf, ok := ret.Get(1).(func(types.Context, uint32) bool); ok { - r1 = rf(ctx, blockHeight) - } else { - r1 = ret.Get(1).(bool) - } - - return r0, r1 -} - -// GetMessage provides a mock function with given fields: ctx, id -func (_m *DelayMsgKeeper) GetMessage(ctx types.Context, id uint32) (delaymsgtypes.DelayedMessage, bool) { - ret := _m.Called(ctx, id) - - if len(ret) == 0 { - panic("no return value specified for GetMessage") - } - - var r0 delaymsgtypes.DelayedMessage - var r1 bool - if rf, ok := ret.Get(0).(func(types.Context, uint32) (delaymsgtypes.DelayedMessage, bool)); ok { - return rf(ctx, id) - } - if rf, ok := ret.Get(0).(func(types.Context, uint32) delaymsgtypes.DelayedMessage); ok { - r0 = rf(ctx, id) - } else { - r0 = ret.Get(0).(delaymsgtypes.DelayedMessage) - } - - if rf, ok := ret.Get(1).(func(types.Context, uint32) bool); ok { - r1 = rf(ctx, id) - } else { - r1 = ret.Get(1).(bool) - } - - return r0, r1 -} - -// HasAuthority provides a mock function with given fields: authority -func (_m *DelayMsgKeeper) HasAuthority(authority string) bool { - ret := _m.Called(authority) - - if len(ret) == 0 { - panic("no return value specified for HasAuthority") - } - - var r0 bool - if rf, ok := ret.Get(0).(func(string) bool); ok { - r0 = rf(authority) - } else { - r0 = ret.Get(0).(bool) - } - - return r0 -} - -// Logger provides a mock function with given fields: ctx -func (_m *DelayMsgKeeper) Logger(ctx types.Context) log.Logger { - ret := _m.Called(ctx) - - if len(ret) == 0 { - panic("no return value specified for Logger") - } - - var r0 log.Logger - if rf, ok := ret.Get(0).(func(types.Context) log.Logger); ok { - r0 = rf(ctx) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(log.Logger) - } - } - - return r0 -} - -// Router provides a mock function with given fields: -func (_m *DelayMsgKeeper) Router() lib.MsgRouter { - ret := _m.Called() - - if len(ret) == 0 { - panic("no return value specified for Router") - } - - var r0 lib.MsgRouter - if rf, ok := ret.Get(0).(func() lib.MsgRouter); ok { - r0 = rf() - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(lib.MsgRouter) - } - } - - return r0 -} - -// SetDelayedMessage provides a mock function with given fields: ctx, msg -func (_m *DelayMsgKeeper) SetDelayedMessage(ctx types.Context, msg *delaymsgtypes.DelayedMessage) error { - ret := _m.Called(ctx, msg) - - if len(ret) == 0 { - panic("no return value specified for SetDelayedMessage") - } - - var r0 error - if rf, ok := ret.Get(0).(func(types.Context, *delaymsgtypes.DelayedMessage) error); ok { - r0 = rf(ctx, msg) - } else { - r0 = ret.Error(0) - } - - return r0 -} - -// SetNextDelayedMessageId provides a mock function with given fields: ctx, nextDelayedMessageId -func (_m *DelayMsgKeeper) SetNextDelayedMessageId(ctx types.Context, nextDelayedMessageId uint32) { - _m.Called(ctx, nextDelayedMessageId) -} - -// NewDelayMsgKeeper creates a new instance of DelayMsgKeeper. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. -// The first argument is typically a *testing.T value. -func NewDelayMsgKeeper(t interface { - mock.TestingT - Cleanup(func()) -}) *DelayMsgKeeper { - mock := &DelayMsgKeeper{} - mock.Mock.Test(t) - - t.Cleanup(func() { mock.AssertExpectations(t) }) - - return mock -} diff --git a/protocol/mocks/MsgRouter.go b/protocol/mocks/MsgRouter.go index 4c81bc9494..e69de29bb2 100644 --- a/protocol/mocks/MsgRouter.go +++ b/protocol/mocks/MsgRouter.go @@ -1,49 +0,0 @@ -// Code generated by mockery v2.44.1. DO NOT EDIT. - -package mocks - -import ( - proto "github.com/cosmos/gogoproto/proto" - mock "github.com/stretchr/testify/mock" - - types "github.com/cosmos/cosmos-sdk/types" -) - -// MsgRouter is an autogenerated mock type for the MsgRouter type -type MsgRouter struct { - mock.Mock -} - -// Handler provides a mock function with given fields: msg -func (_m *MsgRouter) Handler(msg proto.Message) func(types.Context, proto.Message) (*types.Result, error) { - ret := _m.Called(msg) - - if len(ret) == 0 { - panic("no return value specified for Handler") - } - - var r0 func(types.Context, proto.Message) (*types.Result, error) - if rf, ok := ret.Get(0).(func(proto.Message) func(types.Context, proto.Message) (*types.Result, error)); ok { - r0 = rf(msg) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(func(types.Context, proto.Message) (*types.Result, error)) - } - } - - return r0 -} - -// NewMsgRouter creates a new instance of MsgRouter. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. -// The first argument is typically a *testing.T value. -func NewMsgRouter(t interface { - mock.TestingT - Cleanup(func()) -}) *MsgRouter { - mock := &MsgRouter{} - mock.Mock.Test(t) - - t.Cleanup(func() { mock.AssertExpectations(t) }) - - return mock -} \ No newline at end of file diff --git a/protocol/mocks/PerpetualsKeeper.go b/protocol/mocks/PerpetualsKeeper.go index 38721a5f1e..2b1a22c43d 100644 --- a/protocol/mocks/PerpetualsKeeper.go +++ b/protocol/mocks/PerpetualsKeeper.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.44.1. DO NOT EDIT. +// Code generated by mockery v2.46.0. DO NOT EDIT. package mocks @@ -122,34 +122,6 @@ func (_m *PerpetualsKeeper) GetAllPerpetuals(ctx types.Context) []perpetualstype return r0 } -// GetLiquidityTier provides a mock function with given fields: ctx, id -func (_m *PerpetualsKeeper) GetLiquidityTier(ctx types.Context, id uint32) (perpetualstypes.LiquidityTier, error) { - ret := _m.Called(ctx, id) - - if len(ret) == 0 { - panic("no return value specified for GetLiquidityTier") - } - - var r0 perpetualstypes.LiquidityTier - var r1 error - if rf, ok := ret.Get(0).(func(types.Context, uint32) (perpetualstypes.LiquidityTier, error)); ok { - return rf(ctx, id) - } - if rf, ok := ret.Get(0).(func(types.Context, uint32) perpetualstypes.LiquidityTier); ok { - r0 = rf(ctx, id) - } else { - r0 = ret.Get(0).(perpetualstypes.LiquidityTier) - } - - if rf, ok := ret.Get(1).(func(types.Context, uint32) error); ok { - r1 = rf(ctx, id) - } else { - r1 = ret.Error(1) - } - - return r0, r1 -} - // GetNetCollateral provides a mock function with given fields: ctx, id, bigQuantums func (_m *PerpetualsKeeper) GetNetCollateral(ctx types.Context, id uint32, bigQuantums *big.Int) (*big.Int, error) { ret := _m.Called(ctx, id, bigQuantums) @@ -360,11 +332,6 @@ func (_m *PerpetualsKeeper) PerformStatefulPremiumVotesValidation(ctx types.Cont return r0 } -// SendOIUpdatesToIndexer provides a mock function with given fields: ctx -func (_m *PerpetualsKeeper) SendOIUpdatesToIndexer(ctx types.Context) { - _m.Called(ctx) -} - // SetLiquidityTier provides a mock function with given fields: ctx, id, name, initialMarginPpm, maintenanceFractionPpm, impactNotional, openInterestLowerCap, openInterestUpperCap func (_m *PerpetualsKeeper) SetLiquidityTier(ctx types.Context, id uint32, name string, initialMarginPpm uint32, maintenanceFractionPpm uint32, impactNotional uint64, openInterestLowerCap uint64, openInterestUpperCap uint64) (perpetualstypes.LiquidityTier, error) { ret := _m.Called(ctx, id, name, initialMarginPpm, maintenanceFractionPpm, impactNotional, openInterestLowerCap, openInterestUpperCap) @@ -469,4 +436,4 @@ func NewPerpetualsKeeper(t interface { t.Cleanup(func() { mock.AssertExpectations(t) }) return mock -} \ No newline at end of file +} diff --git a/protocol/mocks/SubaccountsKeeper.go b/protocol/mocks/SubaccountsKeeper.go index 13460f3180..58340ac8e7 100644 --- a/protocol/mocks/SubaccountsKeeper.go +++ b/protocol/mocks/SubaccountsKeeper.go @@ -250,11 +250,6 @@ func (_m *SubaccountsKeeper) LegacyGetNegativeTncSubaccountSeenAtBlock(ctx types return r0, r1 } -// SendFinalizedSubaccountUpdates provides a mock function with given fields: ctx, subaccountUpdates -func (_m *SubaccountsKeeper) SendFinalizedSubaccountUpdates(ctx types.Context, subaccountUpdates []subaccountstypes.StreamSubaccountUpdate) { - _m.Called(ctx, subaccountUpdates) -} - // SetNegativeTncSubaccountSeenAtBlock provides a mock function with given fields: ctx, perpetualId, blockHeight func (_m *SubaccountsKeeper) SetNegativeTncSubaccountSeenAtBlock(ctx types.Context, perpetualId uint32, blockHeight uint32) error { ret := _m.Called(ctx, perpetualId, blockHeight) diff --git a/protocol/mocks/TxBuilder.go b/protocol/mocks/TxBuilder.go index a67246abc7..e69de29bb2 100644 --- a/protocol/mocks/TxBuilder.go +++ b/protocol/mocks/TxBuilder.go @@ -1,151 +0,0 @@ -// Code generated by mockery v2.44.1. DO NOT EDIT. - -package mocks - -import ( - proto "github.com/cosmos/gogoproto/proto" - mock "github.com/stretchr/testify/mock" - - signing "github.com/cosmos/cosmos-sdk/x/auth/signing" - - tx "github.com/cosmos/cosmos-sdk/types/tx" - - txsigning "github.com/cosmos/cosmos-sdk/types/tx/signing" - - types "github.com/cosmos/cosmos-sdk/types" -) - -// TxBuilder is an autogenerated mock type for the TxBuilder type -type TxBuilder struct { - mock.Mock -} - -// AddAuxSignerData provides a mock function with given fields: _a0 -func (_m *TxBuilder) AddAuxSignerData(_a0 tx.AuxSignerData) error { - ret := _m.Called(_a0) - - if len(ret) == 0 { - panic("no return value specified for AddAuxSignerData") - } - - var r0 error - if rf, ok := ret.Get(0).(func(tx.AuxSignerData) error); ok { - r0 = rf(_a0) - } else { - r0 = ret.Error(0) - } - - return r0 -} - -// GetTx provides a mock function with given fields: -func (_m *TxBuilder) GetTx() signing.Tx { - ret := _m.Called() - - if len(ret) == 0 { - panic("no return value specified for GetTx") - } - - var r0 signing.Tx - if rf, ok := ret.Get(0).(func() signing.Tx); ok { - r0 = rf() - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(signing.Tx) - } - } - - return r0 -} - -// SetFeeAmount provides a mock function with given fields: amount -func (_m *TxBuilder) SetFeeAmount(amount types.Coins) { - _m.Called(amount) -} - -// SetFeeGranter provides a mock function with given fields: feeGranter -func (_m *TxBuilder) SetFeeGranter(feeGranter types.AccAddress) { - _m.Called(feeGranter) -} - -// SetFeePayer provides a mock function with given fields: feePayer -func (_m *TxBuilder) SetFeePayer(feePayer types.AccAddress) { - _m.Called(feePayer) -} - -// SetGasLimit provides a mock function with given fields: limit -func (_m *TxBuilder) SetGasLimit(limit uint64) { - _m.Called(limit) -} - -// SetMemo provides a mock function with given fields: memo -func (_m *TxBuilder) SetMemo(memo string) { - _m.Called(memo) -} - -// SetMsgs provides a mock function with given fields: msgs -func (_m *TxBuilder) SetMsgs(msgs ...proto.Message) error { - _va := make([]interface{}, len(msgs)) - for _i := range msgs { - _va[_i] = msgs[_i] - } - var _ca []interface{} - _ca = append(_ca, _va...) - ret := _m.Called(_ca...) - - if len(ret) == 0 { - panic("no return value specified for SetMsgs") - } - - var r0 error - if rf, ok := ret.Get(0).(func(...proto.Message) error); ok { - r0 = rf(msgs...) - } else { - r0 = ret.Error(0) - } - - return r0 -} - -// SetSignatures provides a mock function with given fields: signatures -func (_m *TxBuilder) SetSignatures(signatures ...txsigning.SignatureV2) error { - _va := make([]interface{}, len(signatures)) - for _i := range signatures { - _va[_i] = signatures[_i] - } - var _ca []interface{} - _ca = append(_ca, _va...) - ret := _m.Called(_ca...) - - if len(ret) == 0 { - panic("no return value specified for SetSignatures") - } - - var r0 error - if rf, ok := ret.Get(0).(func(...txsigning.SignatureV2) error); ok { - r0 = rf(signatures...) - } else { - r0 = ret.Error(0) - } - - return r0 -} - -// SetTimeoutHeight provides a mock function with given fields: height -func (_m *TxBuilder) SetTimeoutHeight(height uint64) { - _m.Called(height) -} - -// NewTxBuilder creates a new instance of TxBuilder. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. -// The first argument is typically a *testing.T value. -func NewTxBuilder(t interface { - mock.TestingT - Cleanup(func()) -}) *TxBuilder { - mock := &TxBuilder{} - mock.Mock.Test(t) - - t.Cleanup(func() { mock.AssertExpectations(t) }) - - return mock -} \ No newline at end of file From 3b8f226348ec225ba844564b324a0bee714c29a9 Mon Sep 17 00:00:00 2001 From: Harry Wray Date: Wed, 13 Nov 2024 11:40:48 -0500 Subject: [PATCH 10/29] Update --- proto/dydxprotocol/listing/tx.proto | 2 +- protocol/x/clob/keeper/deleveraging_test.go | 130 ----------------- .../x/subaccounts/keeper/transfer_test.go | 135 ++++++++++++++++++ 3 files changed, 136 insertions(+), 131 deletions(-) diff --git a/proto/dydxprotocol/listing/tx.proto b/proto/dydxprotocol/listing/tx.proto index ff6078ffc7..0221cadbbb 100644 --- a/proto/dydxprotocol/listing/tx.proto +++ b/proto/dydxprotocol/listing/tx.proto @@ -78,7 +78,7 @@ message MsgSetListingVaultDepositParamsResponse {} // MsgUpgradeIsolatedPerpetualToCross is used to upgrade a market from // isolated margin to cross margin. message MsgUpgradeIsolatedPerpetualToCross { - // Authority is the address that controls the module. + // Authority is the address that controls the module. option (cosmos.msg.v1.signer) = "authority"; string authority = 1 [ (cosmos_proto.scalar) = "cosmos.AddressString" ]; diff --git a/protocol/x/clob/keeper/deleveraging_test.go b/protocol/x/clob/keeper/deleveraging_test.go index d3e6cb1ff0..f36f730061 100644 --- a/protocol/x/clob/keeper/deleveraging_test.go +++ b/protocol/x/clob/keeper/deleveraging_test.go @@ -1,8 +1,6 @@ package keeper_test import ( - "errors" - "math" "math/big" "testing" "time" @@ -19,7 +17,6 @@ import ( keepertest "github.com/dydxprotocol/v4-chain/protocol/testutil/keeper" perptest "github.com/dydxprotocol/v4-chain/protocol/testutil/perpetuals" testutil "github.com/dydxprotocol/v4-chain/protocol/testutil/util" - assettypes "github.com/dydxprotocol/v4-chain/protocol/x/assets/types" blocktimetypes "github.com/dydxprotocol/v4-chain/protocol/x/blocktime/types" "github.com/dydxprotocol/v4-chain/protocol/x/clob/memclob" "github.com/dydxprotocol/v4-chain/protocol/x/clob/types" @@ -30,133 +27,6 @@ import ( "github.com/stretchr/testify/require" ) -func TestGetInsuranceFundBalance(t *testing.T) { - tests := map[string]struct { - // Setup - assets []assettypes.Asset - insuranceFundBalance *big.Int - perpetualId uint32 - perpetual *perptypes.Perpetual - - // Expectations. - expectedInsuranceFundBalance *big.Int - expectedError error - }{ - "can get zero balance": { - assets: []assettypes.Asset{ - *constants.Usdc, - }, - perpetualId: 0, - insuranceFundBalance: new(big.Int), - expectedInsuranceFundBalance: big.NewInt(0), - }, - "can get positive balance": { - assets: []assettypes.Asset{ - *constants.Usdc, - }, - perpetualId: 0, - insuranceFundBalance: big.NewInt(100), - expectedInsuranceFundBalance: big.NewInt(100), - }, - "can get greater than MaxUint64 balance": { - assets: []assettypes.Asset{ - *constants.Usdc, - }, - perpetualId: 0, - insuranceFundBalance: new(big.Int).Add( - new(big.Int).SetUint64(math.MaxUint64), - new(big.Int).SetUint64(math.MaxUint64), - ), - expectedInsuranceFundBalance: new(big.Int).Add( - new(big.Int).SetUint64(math.MaxUint64), - new(big.Int).SetUint64(math.MaxUint64), - ), - }, - "can get zero balance - isolated market": { - assets: []assettypes.Asset{ - *constants.Usdc, - }, - perpetualId: 3, // Isolated market. - insuranceFundBalance: new(big.Int), - expectedInsuranceFundBalance: big.NewInt(0), - }, - "can get positive balance - isolated market": { - assets: []assettypes.Asset{ - *constants.Usdc, - }, - perpetualId: 3, // Isolated market. - insuranceFundBalance: big.NewInt(100), - expectedInsuranceFundBalance: big.NewInt(100), - }, - "panics when asset not found in state": { - assets: []assettypes.Asset{}, - perpetualId: 0, - expectedError: errors.New("GetInsuranceFundBalance: Usdc asset not found in state"), - }, - } - - for name, tc := range tests { - t.Run(name, func(t *testing.T) { - // Setup keeper state. - memClob := memclob.NewMemClobPriceTimePriority(false) - bankMock := &mocks.BankKeeper{} - ks := keepertest.NewClobKeepersTestContext(t, memClob, bankMock, &mocks.IndexerEventManager{}) - - ctx := ks.Ctx.WithIsCheckTx(true) - // Create the default markets. - keepertest.CreateTestMarkets(t, ctx, ks.PricesKeeper) - - // Create liquidity tiers. - keepertest.CreateTestLiquidityTiers(t, ctx, ks.PerpetualsKeeper) - - keepertest.CreateTestPerpetuals(t, ctx, ks.PerpetualsKeeper) - - for _, a := range tc.assets { - _, err := ks.AssetsKeeper.CreateAsset( - ks.Ctx, - a.Id, - a.Symbol, - a.Denom, - a.DenomExponent, - a.HasMarket, - a.MarketId, - a.AtomicResolution, - ) - require.NoError(t, err) - } - - insuranceFundAddr, err := ks.PerpetualsKeeper.GetInsuranceFundModuleAddress(ks.Ctx, tc.perpetualId) - require.NoError(t, err) - if tc.insuranceFundBalance != nil { - bankMock.On( - "GetBalance", - mock.Anything, - insuranceFundAddr, - constants.Usdc.Denom, - ).Return( - sdk.NewCoin(constants.Usdc.Denom, sdkmath.NewIntFromBigInt(tc.insuranceFundBalance)), - ) - } - - if tc.expectedError != nil { - require.PanicsWithValue( - t, - tc.expectedError.Error(), - func() { - ks.ClobKeeper.GetInsuranceFundBalance(ks.Ctx, tc.perpetualId) - }, - ) - } else { - require.Equal( - t, - tc.expectedInsuranceFundBalance, - ks.ClobKeeper.GetInsuranceFundBalance(ks.Ctx, tc.perpetualId), - ) - } - }) - } -} - func TestIsValidInsuranceFundDelta(t *testing.T) { tests := map[string]struct { // Setup diff --git a/protocol/x/subaccounts/keeper/transfer_test.go b/protocol/x/subaccounts/keeper/transfer_test.go index eefe09c4d3..5e7a66d1b4 100644 --- a/protocol/x/subaccounts/keeper/transfer_test.go +++ b/protocol/x/subaccounts/keeper/transfer_test.go @@ -1,10 +1,12 @@ package keeper_test import ( + "errors" "math" "math/big" "testing" + "github.com/dydxprotocol/v4-chain/protocol/mocks" perptypes "github.com/dydxprotocol/v4-chain/protocol/x/perpetuals/types" errorsmod "cosmossdk.io/errors" @@ -24,9 +26,142 @@ import ( clobtypes "github.com/dydxprotocol/v4-chain/protocol/x/clob/types" revsharetypes "github.com/dydxprotocol/v4-chain/protocol/x/revshare/types" "github.com/dydxprotocol/v4-chain/protocol/x/subaccounts/types" + "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" ) +func TestGetInsuranceFundBalance(t *testing.T) { + tests := map[string]struct { + // Setup + assets []asstypes.Asset + insuranceFundBalance *big.Int + perpetualId uint32 + perpetual *perptypes.Perpetual + + // Expectations. + expectedInsuranceFundBalance *big.Int + expectedError error + }{ + "can get zero balance": { + assets: []asstypes.Asset{ + *constants.Usdc, + }, + perpetualId: 0, + insuranceFundBalance: new(big.Int), + expectedInsuranceFundBalance: big.NewInt(0), + }, + "can get positive balance": { + assets: []asstypes.Asset{ + *constants.Usdc, + }, + perpetualId: 0, + insuranceFundBalance: big.NewInt(100), + expectedInsuranceFundBalance: big.NewInt(100), + }, + "can get greater than MaxUint64 balance": { + assets: []asstypes.Asset{ + *constants.Usdc, + }, + perpetualId: 0, + insuranceFundBalance: new(big.Int).Add( + new(big.Int).SetUint64(math.MaxUint64), + new(big.Int).SetUint64(math.MaxUint64), + ), + expectedInsuranceFundBalance: new(big.Int).Add( + new(big.Int).SetUint64(math.MaxUint64), + new(big.Int).SetUint64(math.MaxUint64), + ), + }, + "can get zero balance - isolated market": { + assets: []asstypes.Asset{ + *constants.Usdc, + }, + perpetualId: 3, // Isolated market. + insuranceFundBalance: new(big.Int), + expectedInsuranceFundBalance: big.NewInt(0), + }, + "can get positive balance - isolated market": { + assets: []asstypes.Asset{ + *constants.Usdc, + }, + perpetualId: 3, // Isolated market. + insuranceFundBalance: big.NewInt(100), + expectedInsuranceFundBalance: big.NewInt(100), + }, + "panics when asset not found in state": { + assets: []asstypes.Asset{}, + perpetualId: 0, + expectedError: errors.New("GetInsuranceFundBalance: Usdc asset not found in state"), + }, + } + + for name, tc := range tests { + t.Run(name, func(t *testing.T) { + // Setup keeper state. + // memClob := memclob.NewMemClobPriceTimePriority(false) + bankMock := &mocks.BankKeeper{} + // ks := keepertest.NewClobKeepersTestContext(t, memClob, bankMock, &mocks.IndexerEventManager{}) + + // ctx := ks.Ctx.WithIsCheckTx(true) + + // TODO TODO TODO INTEGRATE THE BELOW (taken from other transfer tests) to update these tests + ctx, keeper, pricesKeeper, perpetualsKeeper, _, _, assetsKeeper, _, _, _, _ := + keepertest.SubaccountsKeepers(t, true) + + // Create the default markets. + keepertest.CreateTestMarkets(t, ctx, pricesKeeper) + + // Create liquidity tiers. + keepertest.CreateTestLiquidityTiers(t, ctx, perpetualsKeeper) + + keepertest.CreateTestPerpetuals(t, ctx, perpetualsKeeper) + + for _, a := range tc.assets { + _, err := assetsKeeper.CreateAsset( + ctx, + a.Id, + a.Symbol, + a.Denom, + a.DenomExponent, + a.HasMarket, + a.MarketId, + a.AtomicResolution, + ) + require.NoError(t, err) + } + + insuranceFundAddr, err := perpetualsKeeper.GetInsuranceFundModuleAddress(ctx, tc.perpetualId) + require.NoError(t, err) + if tc.insuranceFundBalance != nil { + bankMock.On( + "GetBalance", + mock.Anything, + insuranceFundAddr, + constants.Usdc.Denom, + ).Return( + sdk.NewCoin(constants.Usdc.Denom, sdkmath.NewIntFromBigInt(tc.insuranceFundBalance)), + ) + } + + if tc.expectedError != nil { + require.PanicsWithValue( + t, + tc.expectedError.Error(), + func() { + keeper.GetInsuranceFundBalance(ctx, tc.perpetualId) + }, + ) + } else { + require.Equal( + t, + tc.expectedInsuranceFundBalance, + keeper.GetInsuranceFundBalance(ctx, tc.perpetualId), + ) + } + }) + } +} + func TestWithdrawFundsFromSubaccountToAccount_DepositFundsFromAccountToSubaccount_Success(t *testing.T) { tests := map[string]struct { testTransferFundToAccount bool From 5128ca8752f89454decfb884d68cff01ac2022c9 Mon Sep 17 00:00:00 2001 From: Harry Wray Date: Wed, 13 Nov 2024 11:46:48 -0500 Subject: [PATCH 11/29] Revert clobbered mock files --- protocol/mocks/AssetsKeeper.go | 2 +- protocol/mocks/DelayMsgKeeper.go | 239 ++++++++++++++++++++++++++++ protocol/mocks/MsgRouter.go | 49 ++++++ protocol/mocks/PerpetualsKeeper.go | 37 ++++- protocol/mocks/SubaccountsKeeper.go | 5 + protocol/mocks/TxBuilder.go | 151 ++++++++++++++++++ 6 files changed, 480 insertions(+), 3 deletions(-) diff --git a/protocol/mocks/AssetsKeeper.go b/protocol/mocks/AssetsKeeper.go index 6942c91773..b117d6596b 100644 --- a/protocol/mocks/AssetsKeeper.go +++ b/protocol/mocks/AssetsKeeper.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.46.0. DO NOT EDIT. +// Code generated by mockery v2.44.1. DO NOT EDIT. package mocks diff --git a/protocol/mocks/DelayMsgKeeper.go b/protocol/mocks/DelayMsgKeeper.go index e69de29bb2..04d6e65d68 100644 --- a/protocol/mocks/DelayMsgKeeper.go +++ b/protocol/mocks/DelayMsgKeeper.go @@ -0,0 +1,239 @@ + +// Code generated by mockery v2.44.1. DO NOT EDIT. + +package mocks + +import ( + lib "github.com/dydxprotocol/v4-chain/protocol/lib" + delaymsgtypes "github.com/dydxprotocol/v4-chain/protocol/x/delaymsg/types" + + log "cosmossdk.io/log" + + mock "github.com/stretchr/testify/mock" + + proto "github.com/cosmos/gogoproto/proto" + + types "github.com/cosmos/cosmos-sdk/types" +) + +// DelayMsgKeeper is an autogenerated mock type for the DelayMsgKeeper type +type DelayMsgKeeper struct { + mock.Mock +} + +// DelayMessageByBlocks provides a mock function with given fields: ctx, msg, blockDelay +func (_m *DelayMsgKeeper) DelayMessageByBlocks(ctx types.Context, msg proto.Message, blockDelay uint32) (uint32, error) { + ret := _m.Called(ctx, msg, blockDelay) + + if len(ret) == 0 { + panic("no return value specified for DelayMessageByBlocks") + } + + var r0 uint32 + var r1 error + if rf, ok := ret.Get(0).(func(types.Context, proto.Message, uint32) (uint32, error)); ok { + return rf(ctx, msg, blockDelay) + } + if rf, ok := ret.Get(0).(func(types.Context, proto.Message, uint32) uint32); ok { + r0 = rf(ctx, msg, blockDelay) + } else { + r0 = ret.Get(0).(uint32) + } + + if rf, ok := ret.Get(1).(func(types.Context, proto.Message, uint32) error); ok { + r1 = rf(ctx, msg, blockDelay) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// DeleteMessage provides a mock function with given fields: ctx, id +func (_m *DelayMsgKeeper) DeleteMessage(ctx types.Context, id uint32) error { + ret := _m.Called(ctx, id) + + if len(ret) == 0 { + panic("no return value specified for DeleteMessage") + } + + var r0 error + if rf, ok := ret.Get(0).(func(types.Context, uint32) error); ok { + r0 = rf(ctx, id) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// GetAllDelayedMessages provides a mock function with given fields: ctx +func (_m *DelayMsgKeeper) GetAllDelayedMessages(ctx types.Context) []*delaymsgtypes.DelayedMessage { + ret := _m.Called(ctx) + + if len(ret) == 0 { + panic("no return value specified for GetAllDelayedMessages") + } + + var r0 []*delaymsgtypes.DelayedMessage + if rf, ok := ret.Get(0).(func(types.Context) []*delaymsgtypes.DelayedMessage); ok { + r0 = rf(ctx) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]*delaymsgtypes.DelayedMessage) + } + } + + return r0 +} + +// GetBlockMessageIds provides a mock function with given fields: ctx, blockHeight +func (_m *DelayMsgKeeper) GetBlockMessageIds(ctx types.Context, blockHeight uint32) (delaymsgtypes.BlockMessageIds, bool) { + ret := _m.Called(ctx, blockHeight) + + if len(ret) == 0 { + panic("no return value specified for GetBlockMessageIds") + } + + var r0 delaymsgtypes.BlockMessageIds + var r1 bool + if rf, ok := ret.Get(0).(func(types.Context, uint32) (delaymsgtypes.BlockMessageIds, bool)); ok { + return rf(ctx, blockHeight) + } + if rf, ok := ret.Get(0).(func(types.Context, uint32) delaymsgtypes.BlockMessageIds); ok { + r0 = rf(ctx, blockHeight) + } else { + r0 = ret.Get(0).(delaymsgtypes.BlockMessageIds) + } + + if rf, ok := ret.Get(1).(func(types.Context, uint32) bool); ok { + r1 = rf(ctx, blockHeight) + } else { + r1 = ret.Get(1).(bool) + } + + return r0, r1 +} + +// GetMessage provides a mock function with given fields: ctx, id +func (_m *DelayMsgKeeper) GetMessage(ctx types.Context, id uint32) (delaymsgtypes.DelayedMessage, bool) { + ret := _m.Called(ctx, id) + + if len(ret) == 0 { + panic("no return value specified for GetMessage") + } + + var r0 delaymsgtypes.DelayedMessage + var r1 bool + if rf, ok := ret.Get(0).(func(types.Context, uint32) (delaymsgtypes.DelayedMessage, bool)); ok { + return rf(ctx, id) + } + if rf, ok := ret.Get(0).(func(types.Context, uint32) delaymsgtypes.DelayedMessage); ok { + r0 = rf(ctx, id) + } else { + r0 = ret.Get(0).(delaymsgtypes.DelayedMessage) + } + + if rf, ok := ret.Get(1).(func(types.Context, uint32) bool); ok { + r1 = rf(ctx, id) + } else { + r1 = ret.Get(1).(bool) + } + + return r0, r1 +} + +// HasAuthority provides a mock function with given fields: authority +func (_m *DelayMsgKeeper) HasAuthority(authority string) bool { + ret := _m.Called(authority) + + if len(ret) == 0 { + panic("no return value specified for HasAuthority") + } + + var r0 bool + if rf, ok := ret.Get(0).(func(string) bool); ok { + r0 = rf(authority) + } else { + r0 = ret.Get(0).(bool) + } + + return r0 +} + +// Logger provides a mock function with given fields: ctx +func (_m *DelayMsgKeeper) Logger(ctx types.Context) log.Logger { + ret := _m.Called(ctx) + + if len(ret) == 0 { + panic("no return value specified for Logger") + } + + var r0 log.Logger + if rf, ok := ret.Get(0).(func(types.Context) log.Logger); ok { + r0 = rf(ctx) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(log.Logger) + } + } + + return r0 +} + +// Router provides a mock function with given fields: +func (_m *DelayMsgKeeper) Router() lib.MsgRouter { + ret := _m.Called() + + if len(ret) == 0 { + panic("no return value specified for Router") + } + + var r0 lib.MsgRouter + if rf, ok := ret.Get(0).(func() lib.MsgRouter); ok { + r0 = rf() + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(lib.MsgRouter) + } + } + + return r0 +} + +// SetDelayedMessage provides a mock function with given fields: ctx, msg +func (_m *DelayMsgKeeper) SetDelayedMessage(ctx types.Context, msg *delaymsgtypes.DelayedMessage) error { + ret := _m.Called(ctx, msg) + + if len(ret) == 0 { + panic("no return value specified for SetDelayedMessage") + } + + var r0 error + if rf, ok := ret.Get(0).(func(types.Context, *delaymsgtypes.DelayedMessage) error); ok { + r0 = rf(ctx, msg) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// SetNextDelayedMessageId provides a mock function with given fields: ctx, nextDelayedMessageId +func (_m *DelayMsgKeeper) SetNextDelayedMessageId(ctx types.Context, nextDelayedMessageId uint32) { + _m.Called(ctx, nextDelayedMessageId) +} + +// NewDelayMsgKeeper creates a new instance of DelayMsgKeeper. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewDelayMsgKeeper(t interface { + mock.TestingT + Cleanup(func()) +}) *DelayMsgKeeper { + mock := &DelayMsgKeeper{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/protocol/mocks/MsgRouter.go b/protocol/mocks/MsgRouter.go index e69de29bb2..4c81bc9494 100644 --- a/protocol/mocks/MsgRouter.go +++ b/protocol/mocks/MsgRouter.go @@ -0,0 +1,49 @@ +// Code generated by mockery v2.44.1. DO NOT EDIT. + +package mocks + +import ( + proto "github.com/cosmos/gogoproto/proto" + mock "github.com/stretchr/testify/mock" + + types "github.com/cosmos/cosmos-sdk/types" +) + +// MsgRouter is an autogenerated mock type for the MsgRouter type +type MsgRouter struct { + mock.Mock +} + +// Handler provides a mock function with given fields: msg +func (_m *MsgRouter) Handler(msg proto.Message) func(types.Context, proto.Message) (*types.Result, error) { + ret := _m.Called(msg) + + if len(ret) == 0 { + panic("no return value specified for Handler") + } + + var r0 func(types.Context, proto.Message) (*types.Result, error) + if rf, ok := ret.Get(0).(func(proto.Message) func(types.Context, proto.Message) (*types.Result, error)); ok { + r0 = rf(msg) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(func(types.Context, proto.Message) (*types.Result, error)) + } + } + + return r0 +} + +// NewMsgRouter creates a new instance of MsgRouter. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewMsgRouter(t interface { + mock.TestingT + Cleanup(func()) +}) *MsgRouter { + mock := &MsgRouter{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} \ No newline at end of file diff --git a/protocol/mocks/PerpetualsKeeper.go b/protocol/mocks/PerpetualsKeeper.go index 2b1a22c43d..38721a5f1e 100644 --- a/protocol/mocks/PerpetualsKeeper.go +++ b/protocol/mocks/PerpetualsKeeper.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.46.0. DO NOT EDIT. +// Code generated by mockery v2.44.1. DO NOT EDIT. package mocks @@ -122,6 +122,34 @@ func (_m *PerpetualsKeeper) GetAllPerpetuals(ctx types.Context) []perpetualstype return r0 } +// GetLiquidityTier provides a mock function with given fields: ctx, id +func (_m *PerpetualsKeeper) GetLiquidityTier(ctx types.Context, id uint32) (perpetualstypes.LiquidityTier, error) { + ret := _m.Called(ctx, id) + + if len(ret) == 0 { + panic("no return value specified for GetLiquidityTier") + } + + var r0 perpetualstypes.LiquidityTier + var r1 error + if rf, ok := ret.Get(0).(func(types.Context, uint32) (perpetualstypes.LiquidityTier, error)); ok { + return rf(ctx, id) + } + if rf, ok := ret.Get(0).(func(types.Context, uint32) perpetualstypes.LiquidityTier); ok { + r0 = rf(ctx, id) + } else { + r0 = ret.Get(0).(perpetualstypes.LiquidityTier) + } + + if rf, ok := ret.Get(1).(func(types.Context, uint32) error); ok { + r1 = rf(ctx, id) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + // GetNetCollateral provides a mock function with given fields: ctx, id, bigQuantums func (_m *PerpetualsKeeper) GetNetCollateral(ctx types.Context, id uint32, bigQuantums *big.Int) (*big.Int, error) { ret := _m.Called(ctx, id, bigQuantums) @@ -332,6 +360,11 @@ func (_m *PerpetualsKeeper) PerformStatefulPremiumVotesValidation(ctx types.Cont return r0 } +// SendOIUpdatesToIndexer provides a mock function with given fields: ctx +func (_m *PerpetualsKeeper) SendOIUpdatesToIndexer(ctx types.Context) { + _m.Called(ctx) +} + // SetLiquidityTier provides a mock function with given fields: ctx, id, name, initialMarginPpm, maintenanceFractionPpm, impactNotional, openInterestLowerCap, openInterestUpperCap func (_m *PerpetualsKeeper) SetLiquidityTier(ctx types.Context, id uint32, name string, initialMarginPpm uint32, maintenanceFractionPpm uint32, impactNotional uint64, openInterestLowerCap uint64, openInterestUpperCap uint64) (perpetualstypes.LiquidityTier, error) { ret := _m.Called(ctx, id, name, initialMarginPpm, maintenanceFractionPpm, impactNotional, openInterestLowerCap, openInterestUpperCap) @@ -436,4 +469,4 @@ func NewPerpetualsKeeper(t interface { t.Cleanup(func() { mock.AssertExpectations(t) }) return mock -} +} \ No newline at end of file diff --git a/protocol/mocks/SubaccountsKeeper.go b/protocol/mocks/SubaccountsKeeper.go index 58340ac8e7..13460f3180 100644 --- a/protocol/mocks/SubaccountsKeeper.go +++ b/protocol/mocks/SubaccountsKeeper.go @@ -250,6 +250,11 @@ func (_m *SubaccountsKeeper) LegacyGetNegativeTncSubaccountSeenAtBlock(ctx types return r0, r1 } +// SendFinalizedSubaccountUpdates provides a mock function with given fields: ctx, subaccountUpdates +func (_m *SubaccountsKeeper) SendFinalizedSubaccountUpdates(ctx types.Context, subaccountUpdates []subaccountstypes.StreamSubaccountUpdate) { + _m.Called(ctx, subaccountUpdates) +} + // SetNegativeTncSubaccountSeenAtBlock provides a mock function with given fields: ctx, perpetualId, blockHeight func (_m *SubaccountsKeeper) SetNegativeTncSubaccountSeenAtBlock(ctx types.Context, perpetualId uint32, blockHeight uint32) error { ret := _m.Called(ctx, perpetualId, blockHeight) diff --git a/protocol/mocks/TxBuilder.go b/protocol/mocks/TxBuilder.go index e69de29bb2..a67246abc7 100644 --- a/protocol/mocks/TxBuilder.go +++ b/protocol/mocks/TxBuilder.go @@ -0,0 +1,151 @@ +// Code generated by mockery v2.44.1. DO NOT EDIT. + +package mocks + +import ( + proto "github.com/cosmos/gogoproto/proto" + mock "github.com/stretchr/testify/mock" + + signing "github.com/cosmos/cosmos-sdk/x/auth/signing" + + tx "github.com/cosmos/cosmos-sdk/types/tx" + + txsigning "github.com/cosmos/cosmos-sdk/types/tx/signing" + + types "github.com/cosmos/cosmos-sdk/types" +) + +// TxBuilder is an autogenerated mock type for the TxBuilder type +type TxBuilder struct { + mock.Mock +} + +// AddAuxSignerData provides a mock function with given fields: _a0 +func (_m *TxBuilder) AddAuxSignerData(_a0 tx.AuxSignerData) error { + ret := _m.Called(_a0) + + if len(ret) == 0 { + panic("no return value specified for AddAuxSignerData") + } + + var r0 error + if rf, ok := ret.Get(0).(func(tx.AuxSignerData) error); ok { + r0 = rf(_a0) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// GetTx provides a mock function with given fields: +func (_m *TxBuilder) GetTx() signing.Tx { + ret := _m.Called() + + if len(ret) == 0 { + panic("no return value specified for GetTx") + } + + var r0 signing.Tx + if rf, ok := ret.Get(0).(func() signing.Tx); ok { + r0 = rf() + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(signing.Tx) + } + } + + return r0 +} + +// SetFeeAmount provides a mock function with given fields: amount +func (_m *TxBuilder) SetFeeAmount(amount types.Coins) { + _m.Called(amount) +} + +// SetFeeGranter provides a mock function with given fields: feeGranter +func (_m *TxBuilder) SetFeeGranter(feeGranter types.AccAddress) { + _m.Called(feeGranter) +} + +// SetFeePayer provides a mock function with given fields: feePayer +func (_m *TxBuilder) SetFeePayer(feePayer types.AccAddress) { + _m.Called(feePayer) +} + +// SetGasLimit provides a mock function with given fields: limit +func (_m *TxBuilder) SetGasLimit(limit uint64) { + _m.Called(limit) +} + +// SetMemo provides a mock function with given fields: memo +func (_m *TxBuilder) SetMemo(memo string) { + _m.Called(memo) +} + +// SetMsgs provides a mock function with given fields: msgs +func (_m *TxBuilder) SetMsgs(msgs ...proto.Message) error { + _va := make([]interface{}, len(msgs)) + for _i := range msgs { + _va[_i] = msgs[_i] + } + var _ca []interface{} + _ca = append(_ca, _va...) + ret := _m.Called(_ca...) + + if len(ret) == 0 { + panic("no return value specified for SetMsgs") + } + + var r0 error + if rf, ok := ret.Get(0).(func(...proto.Message) error); ok { + r0 = rf(msgs...) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// SetSignatures provides a mock function with given fields: signatures +func (_m *TxBuilder) SetSignatures(signatures ...txsigning.SignatureV2) error { + _va := make([]interface{}, len(signatures)) + for _i := range signatures { + _va[_i] = signatures[_i] + } + var _ca []interface{} + _ca = append(_ca, _va...) + ret := _m.Called(_ca...) + + if len(ret) == 0 { + panic("no return value specified for SetSignatures") + } + + var r0 error + if rf, ok := ret.Get(0).(func(...txsigning.SignatureV2) error); ok { + r0 = rf(signatures...) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// SetTimeoutHeight provides a mock function with given fields: height +func (_m *TxBuilder) SetTimeoutHeight(height uint64) { + _m.Called(height) +} + +// NewTxBuilder creates a new instance of TxBuilder. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewTxBuilder(t interface { + mock.TestingT + Cleanup(func()) +}) *TxBuilder { + mock := &TxBuilder{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} \ No newline at end of file From d3b27bc3923f6e43502d4dcbc3f375a9604acec8 Mon Sep 17 00:00:00 2001 From: Harry Wray Date: Wed, 13 Nov 2024 14:58:05 -0500 Subject: [PATCH 12/29] Update tests --- protocol/app/app.go | 1 + protocol/testutil/keeper/listing.go | 4 + protocol/x/listing/keeper/listing.go | 5 - ...pgrade_isolated_perpetual_to_cross_test.go | 42 ++++-- ...msg_upgrade_isolated_perpetual_to_cross.go | 10 +- protocol/x/perpetuals/keeper/perpetual.go | 2 +- .../x/perpetuals/keeper/perpetual_test.go | 17 ++- protocol/x/subaccounts/keeper/subaccount.go | 38 +++++ .../x/subaccounts/keeper/subaccount_test.go | 127 ++++++++++++++++ protocol/x/subaccounts/keeper/transfer.go | 37 ----- .../x/subaccounts/keeper/transfer_test.go | 135 ------------------ 11 files changed, 221 insertions(+), 197 deletions(-) diff --git a/protocol/app/app.go b/protocol/app/app.go index 89a10ce846..042bac91ea 100644 --- a/protocol/app/app.go +++ b/protocol/app/app.go @@ -1242,6 +1242,7 @@ func New( app.ClobKeeper, &app.MarketMapKeeper, app.PerpetualsKeeper, + app.SubaccountsKeeper, app.VaultKeeper, ) listingModule := listingmodule.NewAppModule( diff --git a/protocol/testutil/keeper/listing.go b/protocol/testutil/keeper/listing.go index 98f8e7f69f..17af514ab1 100644 --- a/protocol/testutil/keeper/listing.go +++ b/protocol/testutil/keeper/listing.go @@ -14,6 +14,7 @@ import ( clobkeeper "github.com/dydxprotocol/v4-chain/protocol/x/clob/keeper" perpetualskeeper "github.com/dydxprotocol/v4-chain/protocol/x/perpetuals/keeper" priceskeeper "github.com/dydxprotocol/v4-chain/protocol/x/prices/keeper" + subaccountskeeper "github.com/dydxprotocol/v4-chain/protocol/x/subaccounts/keeper" vaultkeeper "github.com/dydxprotocol/v4-chain/protocol/x/vault/keeper" marketmapkeeper "github.com/skip-mev/connect/v2/x/marketmap/keeper" "github.com/stretchr/testify/mock" @@ -173,6 +174,7 @@ func ListingKeepers( perpetualsKeeper, clobKeeper, marketMapKeeper, + subaccountsKeeper, vaultKeeper, ) @@ -191,6 +193,7 @@ func createListingKeeper( perpetualsKeeper *perpetualskeeper.Keeper, clobKeeper *clobkeeper.Keeper, marketMapKeeper *marketmapkeeper.Keeper, + subaccountsKeeper *subaccountskeeper.Keeper, vaultkeeper *vaultkeeper.Keeper, ) ( *keeper.Keeper, @@ -211,6 +214,7 @@ func createListingKeeper( clobKeeper, marketMapKeeper, perpetualsKeeper, + subaccountsKeeper, vaultkeeper, ) diff --git a/protocol/x/listing/keeper/listing.go b/protocol/x/listing/keeper/listing.go index 29f3814d39..fbd2b09e1c 100644 --- a/protocol/x/listing/keeper/listing.go +++ b/protocol/x/listing/keeper/listing.go @@ -161,7 +161,6 @@ func (k Keeper) UpgradeIsolatedPerpetualToCross( return err } - // TODO Move collateral pool for perpetual to subaccounts module err = k.SubaccountsKeeper.TransferIsolatedCollateralToCross(ctx, perpetualId) if err != nil { return err @@ -177,10 +176,6 @@ func (k Keeper) UpgradeIsolatedPerpetualToCross( } // TODO Propagate changes to indexer - // See perpetual.go, modifyperpetual - // Put the proto code for the new message in events.proto - // And requires changes to indexer to process the new event - write typescript handler in indexer/services/ender/src/handlers - // And also some SQL handlers in scripts/handlers return nil } diff --git a/protocol/x/listing/keeper/msg_server_upgrade_isolated_perpetual_to_cross_test.go b/protocol/x/listing/keeper/msg_server_upgrade_isolated_perpetual_to_cross_test.go index f855b3ef30..049a8cc86e 100644 --- a/protocol/x/listing/keeper/msg_server_upgrade_isolated_perpetual_to_cross_test.go +++ b/protocol/x/listing/keeper/msg_server_upgrade_isolated_perpetual_to_cross_test.go @@ -3,8 +3,13 @@ package keeper_test import ( "testing" + "github.com/dydxprotocol/v4-chain/protocol/testutil/constants" types "github.com/dydxprotocol/v4-chain/protocol/x/listing/types" - "github.com/stretchr/testify/require" +) + +var ( + // validAuthority is a valid bech32 address. + validAuthority = constants.AliceAccAddress.String() ) func TestMsgUpgradeIsolatedPerpetualToCross_ValidateBasic(t *testing.T) { @@ -26,14 +31,35 @@ func TestMsgUpgradeIsolatedPerpetualToCross_ValidateBasic(t *testing.T) { }, } - for name, tc := range tests { + for name, _ := range tests { t.Run(name, func(t *testing.T) { - err := tc.msg.ValidateBasic() - if tc.expectedErr == "" { - require.NoError(t, err) - } else { - require.ErrorContains(t, err, tc.expectedErr) - } + /* + err := tc.msg.ValidateBasic() + if tc.expectedErr == "" { + require.NoError(t, err) + } else { + require.ErrorContains(t, err, tc.expectedErr) + } + */ }) } } + +/* +var _ sdk.Msg = &types.MsgUpgradeIsolatedPerpetualToCross{} + +func (msg *types.MsgUpgradeIsolatedPerpetualToCross) ValidateBasic() error { + if _, err := sdk.AccAddressFromBech32(msg.Authority); err != nil { + return errorsmod.Wrap( + ErrInvalidAuthority, + fmt.Sprintf( + "authority '%s' must be a valid bech32 address, but got error '%v'", + msg.Authority, + err.Error(), + ), + ) + } + // TODO Validation? Do we need to check if the PerpetualId is valid? + return nil +} +*/ diff --git a/protocol/x/listing/keeper/msg_upgrade_isolated_perpetual_to_cross.go b/protocol/x/listing/keeper/msg_upgrade_isolated_perpetual_to_cross.go index ba1c809f5a..6682568bee 100644 --- a/protocol/x/listing/keeper/msg_upgrade_isolated_perpetual_to_cross.go +++ b/protocol/x/listing/keeper/msg_upgrade_isolated_perpetual_to_cross.go @@ -1,15 +1,14 @@ package keeper import ( - "fmt" - - errorsmod "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" + types "github.com/dydxprotocol/v4-chain/protocol/x/listing/types" ) -var _ sdk.Msg = &MsgUpgradeIsolatedPerpetualToCross{} +var _ sdk.Msg = &types.MsgUpgradeIsolatedPerpetualToCross{} -func (msg *MsgUpgradeIsolatedPerpetualToCross) ValidateBasic() error { +/* +func (msg *types.MsgUpgradeIsolatedPerpetualToCross) ValidateBasic() error { if _, err := sdk.AccAddressFromBech32(msg.Authority); err != nil { return errorsmod.Wrap( ErrInvalidAuthority, @@ -23,3 +22,4 @@ func (msg *MsgUpgradeIsolatedPerpetualToCross) ValidateBasic() error { // TODO Validation? Do we need to check if the PerpetualId is valid? return nil } +*/ diff --git a/protocol/x/perpetuals/keeper/perpetual.go b/protocol/x/perpetuals/keeper/perpetual.go index 6a75e83723..eb7f6c4cf2 100644 --- a/protocol/x/perpetuals/keeper/perpetual.go +++ b/protocol/x/perpetuals/keeper/perpetual.go @@ -200,7 +200,7 @@ func (k Keeper) SetPerpetualMarketType( if perpetual.Params.MarketType == types.PerpetualMarketType_PERPETUAL_MARKET_TYPE_CROSS { return types.Perpetual{}, errorsmod.Wrap( types.ErrInvalidMarketType, - fmt.Sprintf("perpetual %d already has market type %v", perpetualId, perpetual.Params.MarketType), + fmt.Sprintf("perpetual %d already has market type %v and cannot be changed", perpetualId, types.PerpetualMarketType_PERPETUAL_MARKET_TYPE_CROSS), ) } diff --git a/protocol/x/perpetuals/keeper/perpetual_test.go b/protocol/x/perpetuals/keeper/perpetual_test.go index 30cce2fa32..08e859de1d 100644 --- a/protocol/x/perpetuals/keeper/perpetual_test.go +++ b/protocol/x/perpetuals/keeper/perpetual_test.go @@ -323,11 +323,16 @@ func TestSetPerpetualMarketType(t *testing.T) { errorExpected bool expectedError error }{ - "success": { + "success - set unspecified to cross": { currType: types.PerpetualMarketType_PERPETUAL_MARKET_TYPE_UNSPECIFIED, newType: types.PerpetualMarketType_PERPETUAL_MARKET_TYPE_CROSS, errorExpected: false, }, + "success - set isolated to cross": { + currType: types.PerpetualMarketType_PERPETUAL_MARKET_TYPE_ISOLATED, + newType: types.PerpetualMarketType_PERPETUAL_MARKET_TYPE_CROSS, + errorExpected: false, + }, "failure - setting to unspecified": { currType: types.PerpetualMarketType_PERPETUAL_MARKET_TYPE_CROSS, newType: types.PerpetualMarketType_PERPETUAL_MARKET_TYPE_UNSPECIFIED, @@ -340,16 +345,16 @@ func TestSetPerpetualMarketType(t *testing.T) { ), ), }, - "failure - market type already set": { - currType: types.PerpetualMarketType_PERPETUAL_MARKET_TYPE_ISOLATED, - newType: types.PerpetualMarketType_PERPETUAL_MARKET_TYPE_CROSS, + "failure - market type already set to cross": { + currType: types.PerpetualMarketType_PERPETUAL_MARKET_TYPE_CROSS, + newType: types.PerpetualMarketType_PERPETUAL_MARKET_TYPE_ISOLATED, errorExpected: true, expectedError: errorsmod.Wrap( types.ErrInvalidMarketType, fmt.Sprintf( - "perpetual %d already has market type %v", + "perpetual %d already has market type %v and cannot be changed", 0, - types.PerpetualMarketType_PERPETUAL_MARKET_TYPE_ISOLATED, + types.PerpetualMarketType_PERPETUAL_MARKET_TYPE_CROSS, ), ), }, diff --git a/protocol/x/subaccounts/keeper/subaccount.go b/protocol/x/subaccounts/keeper/subaccount.go index a047d9e2c9..f195e2dbf3 100644 --- a/protocol/x/subaccounts/keeper/subaccount.go +++ b/protocol/x/subaccounts/keeper/subaccount.go @@ -8,6 +8,7 @@ import ( "time" streamingtypes "github.com/dydxprotocol/v4-chain/protocol/streaming/types" + assettypes "github.com/dydxprotocol/v4-chain/protocol/x/assets/types" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" @@ -825,3 +826,40 @@ func (k Keeper) GetAllRelevantPerpetuals( func (k Keeper) GetFullNodeStreamingManager() streamingtypes.FullNodeStreamingManager { return k.streamingManager } + +// GetInsuranceFundBalance returns the current balance of the specific insurance fund based on the +// perpetual (in quote quantums). +// This calls the Bank Keeper’s GetBalance() function for the Module Address of the insurance fund. +func (k Keeper) GetInsuranceFundBalance(ctx sdk.Context, perpetualId uint32) (balance *big.Int) { + usdcAsset, exists := k.assetsKeeper.GetAsset(ctx, assettypes.AssetUsdc.Id) + if !exists { + panic("GetInsuranceFundBalance: Usdc asset not found in state") + } + insuranceFundAddr, err := k.perpetualsKeeper.GetInsuranceFundModuleAddress(ctx, perpetualId) + if err != nil { + return nil + } + insuranceFundBalance := k.bankKeeper.GetBalance( + ctx, + insuranceFundAddr, + usdcAsset.Denom, + ) + + // Return as big.Int. + return insuranceFundBalance.Amount.BigInt() +} + +func (k Keeper) GetCrossInsuranceFundBalance(ctx sdk.Context) (balance *big.Int) { + usdcAsset, exists := k.assetsKeeper.GetAsset(ctx, assettypes.AssetUsdc.Id) + if !exists { + panic("GetCrossInsuranceFundBalance: Usdc asset not found in state") + } + insuranceFundBalance := k.bankKeeper.GetBalance( + ctx, + perptypes.InsuranceFundModuleAddress, + usdcAsset.Denom, + ) + + // Return as big.Int. + return insuranceFundBalance.Amount.BigInt() +} diff --git a/protocol/x/subaccounts/keeper/subaccount_test.go b/protocol/x/subaccounts/keeper/subaccount_test.go index 1eb7141fda..0c28eafd95 100644 --- a/protocol/x/subaccounts/keeper/subaccount_test.go +++ b/protocol/x/subaccounts/keeper/subaccount_test.go @@ -1,6 +1,7 @@ package keeper_test import ( + "errors" "math" "math/big" "strconv" @@ -6131,3 +6132,129 @@ func TestGetAllRelevantPerpetuals_Deterministic(t *testing.T) { }) } } + +func TestGetInsuranceFundBalance(t *testing.T) { + tests := map[string]struct { + // Setup + assets []asstypes.Asset + insuranceFundBalance *big.Int + perpetualId uint32 + perpetual *perptypes.Perpetual + + // Expectations. + expectedInsuranceFundBalance *big.Int + expectedError error + }{ + "can get zero balance": { + assets: []asstypes.Asset{ + *constants.Usdc, + }, + perpetualId: 0, + insuranceFundBalance: new(big.Int), + expectedInsuranceFundBalance: big.NewInt(0), + }, + "can get positive balance": { + assets: []asstypes.Asset{ + *constants.Usdc, + }, + perpetualId: 0, + insuranceFundBalance: big.NewInt(100), + expectedInsuranceFundBalance: big.NewInt(100), + }, + "can get greater than MaxUint64 balance": { + assets: []asstypes.Asset{ + *constants.Usdc, + }, + perpetualId: 0, + insuranceFundBalance: new(big.Int).Add( + new(big.Int).SetUint64(math.MaxUint64), + new(big.Int).SetUint64(math.MaxUint64), + ), + expectedInsuranceFundBalance: new(big.Int).Add( + new(big.Int).SetUint64(math.MaxUint64), + new(big.Int).SetUint64(math.MaxUint64), + ), + }, + "can get zero balance - isolated market": { + assets: []asstypes.Asset{ + *constants.Usdc, + }, + perpetualId: 3, // Isolated market. + insuranceFundBalance: new(big.Int), + expectedInsuranceFundBalance: big.NewInt(0), + }, + "can get positive balance - isolated market": { + assets: []asstypes.Asset{ + *constants.Usdc, + }, + perpetualId: 3, // Isolated market. + insuranceFundBalance: big.NewInt(100), + expectedInsuranceFundBalance: big.NewInt(100), + }, + "panics when asset not found in state": { + assets: []asstypes.Asset{}, + perpetualId: 0, + expectedError: errors.New("GetInsuranceFundBalance: Usdc asset not found in state"), + }, + } + + for name, tc := range tests { + t.Run(name, func(t *testing.T) { + // Setup keeper state. + ctx, keeper, pricesKeeper, perpetualsKeeper, _, bankKeeper, assetsKeeper, _, _, _, _ := + keepertest.SubaccountsKeepers(t, true) + + // Create the default markets. + keepertest.CreateTestMarkets(t, ctx, pricesKeeper) + + // Create liquidity tiers. + keepertest.CreateTestLiquidityTiers(t, ctx, perpetualsKeeper) + + keepertest.CreateTestPerpetuals(t, ctx, perpetualsKeeper) + + for _, a := range tc.assets { + _, err := assetsKeeper.CreateAsset( + ctx, + a.Id, + a.Symbol, + a.Denom, + a.DenomExponent, + a.HasMarket, + a.MarketId, + a.AtomicResolution, + ) + require.NoError(t, err) + } + + insuranceFundAddr, err := perpetualsKeeper.GetInsuranceFundModuleAddress(ctx, tc.perpetualId) + require.NoError(t, err) + if tc.insuranceFundBalance != nil && tc.insuranceFundBalance.Cmp(big.NewInt(0)) != 0 { + err := bank_testutil.FundAccount( + ctx, + insuranceFundAddr, + sdk.Coins{ + sdk.NewCoin(asstypes.AssetUsdc.Denom, sdkmath.NewIntFromBigInt(tc.insuranceFundBalance)), + }, + *bankKeeper, + ) + require.NoError(t, err) + } + + if tc.expectedError != nil { + require.PanicsWithValue( + t, + tc.expectedError.Error(), + func() { + keeper.GetInsuranceFundBalance(ctx, tc.perpetualId) + }, + ) + } else { + require.Equal( + t, + tc.expectedInsuranceFundBalance, + keeper.GetInsuranceFundBalance(ctx, tc.perpetualId), + ) + } + }) + } +} diff --git a/protocol/x/subaccounts/keeper/transfer.go b/protocol/x/subaccounts/keeper/transfer.go index 2ea2e23c45..339654307a 100644 --- a/protocol/x/subaccounts/keeper/transfer.go +++ b/protocol/x/subaccounts/keeper/transfer.go @@ -505,43 +505,6 @@ func (k Keeper) TransferFundsFromSubaccountToSubaccount( ) } -// GetInsuranceFundBalance returns the current balance of the specific insurance fund based on the -// perpetual (in quote quantums). -// This calls the Bank Keeper’s GetBalance() function for the Module Address of the insurance fund. -func (k Keeper) GetInsuranceFundBalance(ctx sdk.Context, perpetualId uint32) (balance *big.Int) { - usdcAsset, exists := k.assetsKeeper.GetAsset(ctx, assettypes.AssetUsdc.Id) - if !exists { - panic("GetInsuranceFundBalance: Usdc asset not found in state") - } - insuranceFundAddr, err := k.perpetualsKeeper.GetInsuranceFundModuleAddress(ctx, perpetualId) - if err != nil { - return nil - } - insuranceFundBalance := k.bankKeeper.GetBalance( - ctx, - insuranceFundAddr, - usdcAsset.Denom, - ) - - // Return as big.Int. - return insuranceFundBalance.Amount.BigInt() -} - -func (k Keeper) GetCrossInsuranceFundBalance(ctx sdk.Context) (balance *big.Int) { - usdcAsset, exists := k.assetsKeeper.GetAsset(ctx, assettypes.AssetUsdc.Id) - if !exists { - panic("GetCrossInsuranceFundBalance: Usdc asset not found in state") - } - insuranceFundBalance := k.bankKeeper.GetBalance( - ctx, - perptypes.InsuranceFundModuleAddress, - usdcAsset.Denom, - ) - - // Return as big.Int. - return insuranceFundBalance.Amount.BigInt() -} - // TransferIsolatedInsuranceFundToCross transfers funds from an isolated perpetual's // insurance fund to the cross-perpetual insurance fund. // Note: This uses the `x/bank` keeper and modifies `x/bank` state. diff --git a/protocol/x/subaccounts/keeper/transfer_test.go b/protocol/x/subaccounts/keeper/transfer_test.go index 5e7a66d1b4..eefe09c4d3 100644 --- a/protocol/x/subaccounts/keeper/transfer_test.go +++ b/protocol/x/subaccounts/keeper/transfer_test.go @@ -1,12 +1,10 @@ package keeper_test import ( - "errors" "math" "math/big" "testing" - "github.com/dydxprotocol/v4-chain/protocol/mocks" perptypes "github.com/dydxprotocol/v4-chain/protocol/x/perpetuals/types" errorsmod "cosmossdk.io/errors" @@ -26,142 +24,9 @@ import ( clobtypes "github.com/dydxprotocol/v4-chain/protocol/x/clob/types" revsharetypes "github.com/dydxprotocol/v4-chain/protocol/x/revshare/types" "github.com/dydxprotocol/v4-chain/protocol/x/subaccounts/types" - "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" ) -func TestGetInsuranceFundBalance(t *testing.T) { - tests := map[string]struct { - // Setup - assets []asstypes.Asset - insuranceFundBalance *big.Int - perpetualId uint32 - perpetual *perptypes.Perpetual - - // Expectations. - expectedInsuranceFundBalance *big.Int - expectedError error - }{ - "can get zero balance": { - assets: []asstypes.Asset{ - *constants.Usdc, - }, - perpetualId: 0, - insuranceFundBalance: new(big.Int), - expectedInsuranceFundBalance: big.NewInt(0), - }, - "can get positive balance": { - assets: []asstypes.Asset{ - *constants.Usdc, - }, - perpetualId: 0, - insuranceFundBalance: big.NewInt(100), - expectedInsuranceFundBalance: big.NewInt(100), - }, - "can get greater than MaxUint64 balance": { - assets: []asstypes.Asset{ - *constants.Usdc, - }, - perpetualId: 0, - insuranceFundBalance: new(big.Int).Add( - new(big.Int).SetUint64(math.MaxUint64), - new(big.Int).SetUint64(math.MaxUint64), - ), - expectedInsuranceFundBalance: new(big.Int).Add( - new(big.Int).SetUint64(math.MaxUint64), - new(big.Int).SetUint64(math.MaxUint64), - ), - }, - "can get zero balance - isolated market": { - assets: []asstypes.Asset{ - *constants.Usdc, - }, - perpetualId: 3, // Isolated market. - insuranceFundBalance: new(big.Int), - expectedInsuranceFundBalance: big.NewInt(0), - }, - "can get positive balance - isolated market": { - assets: []asstypes.Asset{ - *constants.Usdc, - }, - perpetualId: 3, // Isolated market. - insuranceFundBalance: big.NewInt(100), - expectedInsuranceFundBalance: big.NewInt(100), - }, - "panics when asset not found in state": { - assets: []asstypes.Asset{}, - perpetualId: 0, - expectedError: errors.New("GetInsuranceFundBalance: Usdc asset not found in state"), - }, - } - - for name, tc := range tests { - t.Run(name, func(t *testing.T) { - // Setup keeper state. - // memClob := memclob.NewMemClobPriceTimePriority(false) - bankMock := &mocks.BankKeeper{} - // ks := keepertest.NewClobKeepersTestContext(t, memClob, bankMock, &mocks.IndexerEventManager{}) - - // ctx := ks.Ctx.WithIsCheckTx(true) - - // TODO TODO TODO INTEGRATE THE BELOW (taken from other transfer tests) to update these tests - ctx, keeper, pricesKeeper, perpetualsKeeper, _, _, assetsKeeper, _, _, _, _ := - keepertest.SubaccountsKeepers(t, true) - - // Create the default markets. - keepertest.CreateTestMarkets(t, ctx, pricesKeeper) - - // Create liquidity tiers. - keepertest.CreateTestLiquidityTiers(t, ctx, perpetualsKeeper) - - keepertest.CreateTestPerpetuals(t, ctx, perpetualsKeeper) - - for _, a := range tc.assets { - _, err := assetsKeeper.CreateAsset( - ctx, - a.Id, - a.Symbol, - a.Denom, - a.DenomExponent, - a.HasMarket, - a.MarketId, - a.AtomicResolution, - ) - require.NoError(t, err) - } - - insuranceFundAddr, err := perpetualsKeeper.GetInsuranceFundModuleAddress(ctx, tc.perpetualId) - require.NoError(t, err) - if tc.insuranceFundBalance != nil { - bankMock.On( - "GetBalance", - mock.Anything, - insuranceFundAddr, - constants.Usdc.Denom, - ).Return( - sdk.NewCoin(constants.Usdc.Denom, sdkmath.NewIntFromBigInt(tc.insuranceFundBalance)), - ) - } - - if tc.expectedError != nil { - require.PanicsWithValue( - t, - tc.expectedError.Error(), - func() { - keeper.GetInsuranceFundBalance(ctx, tc.perpetualId) - }, - ) - } else { - require.Equal( - t, - tc.expectedInsuranceFundBalance, - keeper.GetInsuranceFundBalance(ctx, tc.perpetualId), - ) - } - }) - } -} - func TestWithdrawFundsFromSubaccountToAccount_DepositFundsFromAccountToSubaccount_Success(t *testing.T) { tests := map[string]struct { testTransferFundToAccount bool From 1f242630b9297514baeb1cb942bb4def625ac9ea Mon Sep 17 00:00:00 2001 From: Harry Wray Date: Wed, 13 Nov 2024 15:23:46 -0500 Subject: [PATCH 13/29] Format protobufs --- proto/dydxprotocol/listing/tx.proto | 11 ++--- ...pgrade_isolated_perpetual_to_cross_test.go | 44 +++++++------------ protocol/x/listing/types/errors.go | 6 +++ ...msg_upgrade_isolated_perpetual_to_cross.go | 14 +++--- 4 files changed, 34 insertions(+), 41 deletions(-) rename protocol/x/listing/{keeper => types}/msg_upgrade_isolated_perpetual_to_cross.go (52%) diff --git a/proto/dydxprotocol/listing/tx.proto b/proto/dydxprotocol/listing/tx.proto index 0221cadbbb..aa7d998452 100644 --- a/proto/dydxprotocol/listing/tx.proto +++ b/proto/dydxprotocol/listing/tx.proto @@ -23,9 +23,10 @@ service Msg { rpc SetListingVaultDepositParams(MsgSetListingVaultDepositParams) returns (MsgSetListingVaultDepositParamsResponse); - // UpgradeIsolatedPerpetualToCross upgrades a perpetual from isolated to cross margin + // UpgradeIsolatedPerpetualToCross upgrades a perpetual from isolated to cross + // margin rpc UpgradeIsolatedPerpetualToCross(MsgUpgradeIsolatedPerpetualToCross) - returns (MsgUpgradeIsolatedPerpetualToCrossResponse); + returns (MsgUpgradeIsolatedPerpetualToCrossResponse); } // MsgSetMarketsHardCap is used to set a hard cap on the number of markets @@ -80,11 +81,11 @@ message MsgSetListingVaultDepositParamsResponse {} message MsgUpgradeIsolatedPerpetualToCross { // Authority is the address that controls the module. option (cosmos.msg.v1.signer) = "authority"; - + string authority = 1 [ (cosmos_proto.scalar) = "cosmos.AddressString" ]; - + // ID of the perpetual to be upgraded to CROSS - uint32 perpetual_id = 2; + uint32 perpetual_id = 2; } // MsgUpgradeIsolatedPerpetualToCrossResponse defines the diff --git a/protocol/x/listing/keeper/msg_server_upgrade_isolated_perpetual_to_cross_test.go b/protocol/x/listing/keeper/msg_server_upgrade_isolated_perpetual_to_cross_test.go index 049a8cc86e..ea55caad92 100644 --- a/protocol/x/listing/keeper/msg_server_upgrade_isolated_perpetual_to_cross_test.go +++ b/protocol/x/listing/keeper/msg_server_upgrade_isolated_perpetual_to_cross_test.go @@ -5,6 +5,7 @@ import ( "github.com/dydxprotocol/v4-chain/protocol/testutil/constants" types "github.com/dydxprotocol/v4-chain/protocol/x/listing/types" + "github.com/stretchr/testify/require" ) var ( @@ -23,43 +24,28 @@ func TestMsgUpgradeIsolatedPerpetualToCross_ValidateBasic(t *testing.T) { PerpetualId: 1, }, }, - "Failure: Invalid authority": { + "Failure: Empty authority": { msg: types.MsgUpgradeIsolatedPerpetualToCross{ Authority: "", }, expectedErr: "Authority is invalid", }, + "Failure: Invaid authority": { + msg: types.MsgUpgradeIsolatedPerpetualToCross{ + Authority: "invalid", + }, + expectedErr: "Authority is invalid", + }, } - for name, _ := range tests { + for name, tc := range tests { t.Run(name, func(t *testing.T) { - /* - err := tc.msg.ValidateBasic() - if tc.expectedErr == "" { - require.NoError(t, err) - } else { - require.ErrorContains(t, err, tc.expectedErr) - } - */ + err := tc.msg.ValidateBasic() + if tc.expectedErr == "" { + require.NoError(t, err) + } else { + require.ErrorContains(t, err, tc.expectedErr) + } }) } } - -/* -var _ sdk.Msg = &types.MsgUpgradeIsolatedPerpetualToCross{} - -func (msg *types.MsgUpgradeIsolatedPerpetualToCross) ValidateBasic() error { - if _, err := sdk.AccAddressFromBech32(msg.Authority); err != nil { - return errorsmod.Wrap( - ErrInvalidAuthority, - fmt.Sprintf( - "authority '%s' must be a valid bech32 address, but got error '%v'", - msg.Authority, - err.Error(), - ), - ) - } - // TODO Validation? Do we need to check if the PerpetualId is valid? - return nil -} -*/ diff --git a/protocol/x/listing/types/errors.go b/protocol/x/listing/types/errors.go index 8213fdd738..29c5bb8653 100644 --- a/protocol/x/listing/types/errors.go +++ b/protocol/x/listing/types/errors.go @@ -39,4 +39,10 @@ var ( 6, "invalid market map ticker metadata", ) + + ErrInvalidAuthority = errorsmod.Register( + ModuleName, + 7, + "Authority is invalid", + ) ) diff --git a/protocol/x/listing/keeper/msg_upgrade_isolated_perpetual_to_cross.go b/protocol/x/listing/types/msg_upgrade_isolated_perpetual_to_cross.go similarity index 52% rename from protocol/x/listing/keeper/msg_upgrade_isolated_perpetual_to_cross.go rename to protocol/x/listing/types/msg_upgrade_isolated_perpetual_to_cross.go index 6682568bee..453d954b3e 100644 --- a/protocol/x/listing/keeper/msg_upgrade_isolated_perpetual_to_cross.go +++ b/protocol/x/listing/types/msg_upgrade_isolated_perpetual_to_cross.go @@ -1,14 +1,16 @@ -package keeper +package types import ( + fmt "fmt" + + errorsmod "cosmossdk.io/errors" + sdk "github.com/cosmos/cosmos-sdk/types" - types "github.com/dydxprotocol/v4-chain/protocol/x/listing/types" ) -var _ sdk.Msg = &types.MsgUpgradeIsolatedPerpetualToCross{} +var _ sdk.Msg = &MsgUpgradeIsolatedPerpetualToCross{} -/* -func (msg *types.MsgUpgradeIsolatedPerpetualToCross) ValidateBasic() error { +func (msg *MsgUpgradeIsolatedPerpetualToCross) ValidateBasic() error { if _, err := sdk.AccAddressFromBech32(msg.Authority); err != nil { return errorsmod.Wrap( ErrInvalidAuthority, @@ -19,7 +21,5 @@ func (msg *types.MsgUpgradeIsolatedPerpetualToCross) ValidateBasic() error { ), ) } - // TODO Validation? Do we need to check if the PerpetualId is valid? return nil } -*/ From f55e601c56e4b03e48d809e73c62c405d48c4061 Mon Sep 17 00:00:00 2001 From: Harry Wray Date: Wed, 13 Nov 2024 15:30:48 -0500 Subject: [PATCH 14/29] Regen and format protobufs --- protocol/x/listing/types/tx.pb.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/protocol/x/listing/types/tx.pb.go b/protocol/x/listing/types/tx.pb.go index a694d8fd17..c1ba7f2abf 100644 --- a/protocol/x/listing/types/tx.pb.go +++ b/protocol/x/listing/types/tx.pb.go @@ -482,7 +482,8 @@ type MsgClient interface { CreateMarketPermissionless(ctx context.Context, in *MsgCreateMarketPermissionless, opts ...grpc.CallOption) (*MsgCreateMarketPermissionlessResponse, error) // SetListingVaultDepositParams sets PML megavault deposit params SetListingVaultDepositParams(ctx context.Context, in *MsgSetListingVaultDepositParams, opts ...grpc.CallOption) (*MsgSetListingVaultDepositParamsResponse, error) - // UpgradeIsolatedPerpetualToCross upgrades a perpetual from isolated to cross margin + // UpgradeIsolatedPerpetualToCross upgrades a perpetual from isolated to cross + // margin UpgradeIsolatedPerpetualToCross(ctx context.Context, in *MsgUpgradeIsolatedPerpetualToCross, opts ...grpc.CallOption) (*MsgUpgradeIsolatedPerpetualToCrossResponse, error) } @@ -538,7 +539,8 @@ type MsgServer interface { CreateMarketPermissionless(context.Context, *MsgCreateMarketPermissionless) (*MsgCreateMarketPermissionlessResponse, error) // SetListingVaultDepositParams sets PML megavault deposit params SetListingVaultDepositParams(context.Context, *MsgSetListingVaultDepositParams) (*MsgSetListingVaultDepositParamsResponse, error) - // UpgradeIsolatedPerpetualToCross upgrades a perpetual from isolated to cross margin + // UpgradeIsolatedPerpetualToCross upgrades a perpetual from isolated to cross + // margin UpgradeIsolatedPerpetualToCross(context.Context, *MsgUpgradeIsolatedPerpetualToCross) (*MsgUpgradeIsolatedPerpetualToCrossResponse, error) } From dad50271551eff04020aeb622a2d0b97c54451f4 Mon Sep 17 00:00:00 2001 From: Harry Wray Date: Wed, 13 Nov 2024 15:43:54 -0500 Subject: [PATCH 15/29] Regenerate node protos --- .../dydxprotocol/listing/tx.rpc.msg.ts | 15 ++- .../src/codegen/dydxprotocol/listing/tx.ts | 123 ++++++++++++++++++ protocol/app/msgs/all_msgs.go | 1 + 3 files changed, 138 insertions(+), 1 deletion(-) diff --git a/indexer/packages/v4-protos/src/codegen/dydxprotocol/listing/tx.rpc.msg.ts b/indexer/packages/v4-protos/src/codegen/dydxprotocol/listing/tx.rpc.msg.ts index 170cf4f3bf..61a0bdf54b 100644 --- a/indexer/packages/v4-protos/src/codegen/dydxprotocol/listing/tx.rpc.msg.ts +++ b/indexer/packages/v4-protos/src/codegen/dydxprotocol/listing/tx.rpc.msg.ts @@ -1,6 +1,6 @@ import { Rpc } from "../../helpers"; import * as _m0 from "protobufjs/minimal"; -import { MsgSetMarketsHardCap, MsgSetMarketsHardCapResponse, MsgCreateMarketPermissionless, MsgCreateMarketPermissionlessResponse, MsgSetListingVaultDepositParams, MsgSetListingVaultDepositParamsResponse } from "./tx"; +import { MsgSetMarketsHardCap, MsgSetMarketsHardCapResponse, MsgCreateMarketPermissionless, MsgCreateMarketPermissionlessResponse, MsgSetListingVaultDepositParams, MsgSetListingVaultDepositParamsResponse, MsgUpgradeIsolatedPerpetualToCross, MsgUpgradeIsolatedPerpetualToCrossResponse } from "./tx"; /** Msg defines the Msg service. */ export interface Msg { @@ -12,6 +12,12 @@ export interface Msg { /** SetListingVaultDepositParams sets PML megavault deposit params */ setListingVaultDepositParams(request: MsgSetListingVaultDepositParams): Promise; + /** + * UpgradeIsolatedPerpetualToCross upgrades a perpetual from isolated to cross + * margin + */ + + upgradeIsolatedPerpetualToCross(request: MsgUpgradeIsolatedPerpetualToCross): Promise; } export class MsgClientImpl implements Msg { private readonly rpc: Rpc; @@ -21,6 +27,7 @@ export class MsgClientImpl implements Msg { this.setMarketsHardCap = this.setMarketsHardCap.bind(this); this.createMarketPermissionless = this.createMarketPermissionless.bind(this); this.setListingVaultDepositParams = this.setListingVaultDepositParams.bind(this); + this.upgradeIsolatedPerpetualToCross = this.upgradeIsolatedPerpetualToCross.bind(this); } setMarketsHardCap(request: MsgSetMarketsHardCap): Promise { @@ -41,4 +48,10 @@ export class MsgClientImpl implements Msg { return promise.then(data => MsgSetListingVaultDepositParamsResponse.decode(new _m0.Reader(data))); } + upgradeIsolatedPerpetualToCross(request: MsgUpgradeIsolatedPerpetualToCross): Promise { + const data = MsgUpgradeIsolatedPerpetualToCross.encode(request).finish(); + const promise = this.rpc.request("dydxprotocol.listing.Msg", "UpgradeIsolatedPerpetualToCross", data); + return promise.then(data => MsgUpgradeIsolatedPerpetualToCrossResponse.decode(new _m0.Reader(data))); + } + } \ No newline at end of file diff --git a/indexer/packages/v4-protos/src/codegen/dydxprotocol/listing/tx.ts b/indexer/packages/v4-protos/src/codegen/dydxprotocol/listing/tx.ts index 7e8d14a123..111d29fc37 100644 --- a/indexer/packages/v4-protos/src/codegen/dydxprotocol/listing/tx.ts +++ b/indexer/packages/v4-protos/src/codegen/dydxprotocol/listing/tx.ts @@ -100,6 +100,40 @@ export interface MsgSetListingVaultDepositParamsResponse {} */ export interface MsgSetListingVaultDepositParamsResponseSDKType {} +/** + * MsgUpgradeIsolatedPerpetualToCross is used to upgrade a market from + * isolated margin to cross margin. + */ + +export interface MsgUpgradeIsolatedPerpetualToCross { + authority: string; + /** ID of the perpetual to be upgraded to CROSS */ + + perpetualId: number; +} +/** + * MsgUpgradeIsolatedPerpetualToCross is used to upgrade a market from + * isolated margin to cross margin. + */ + +export interface MsgUpgradeIsolatedPerpetualToCrossSDKType { + authority: string; + /** ID of the perpetual to be upgraded to CROSS */ + + perpetual_id: number; +} +/** + * MsgUpgradeIsolatedPerpetualToCrossResponse defines the + * UpgradeIsolatedPerpetualToCross response type. + */ + +export interface MsgUpgradeIsolatedPerpetualToCrossResponse {} +/** + * MsgUpgradeIsolatedPerpetualToCrossResponse defines the + * UpgradeIsolatedPerpetualToCross response type. + */ + +export interface MsgUpgradeIsolatedPerpetualToCrossResponseSDKType {} function createBaseMsgSetMarketsHardCap(): MsgSetMarketsHardCap { return { @@ -366,4 +400,93 @@ export const MsgSetListingVaultDepositParamsResponse = { return message; } +}; + +function createBaseMsgUpgradeIsolatedPerpetualToCross(): MsgUpgradeIsolatedPerpetualToCross { + return { + authority: "", + perpetualId: 0 + }; +} + +export const MsgUpgradeIsolatedPerpetualToCross = { + encode(message: MsgUpgradeIsolatedPerpetualToCross, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { + if (message.authority !== "") { + writer.uint32(10).string(message.authority); + } + + if (message.perpetualId !== 0) { + writer.uint32(16).uint32(message.perpetualId); + } + + return writer; + }, + + decode(input: _m0.Reader | Uint8Array, length?: number): MsgUpgradeIsolatedPerpetualToCross { + const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input); + let end = length === undefined ? reader.len : reader.pos + length; + const message = createBaseMsgUpgradeIsolatedPerpetualToCross(); + + while (reader.pos < end) { + const tag = reader.uint32(); + + switch (tag >>> 3) { + case 1: + message.authority = reader.string(); + break; + + case 2: + message.perpetualId = reader.uint32(); + break; + + default: + reader.skipType(tag & 7); + break; + } + } + + return message; + }, + + fromPartial(object: DeepPartial): MsgUpgradeIsolatedPerpetualToCross { + const message = createBaseMsgUpgradeIsolatedPerpetualToCross(); + message.authority = object.authority ?? ""; + message.perpetualId = object.perpetualId ?? 0; + return message; + } + +}; + +function createBaseMsgUpgradeIsolatedPerpetualToCrossResponse(): MsgUpgradeIsolatedPerpetualToCrossResponse { + return {}; +} + +export const MsgUpgradeIsolatedPerpetualToCrossResponse = { + encode(_: MsgUpgradeIsolatedPerpetualToCrossResponse, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { + return writer; + }, + + decode(input: _m0.Reader | Uint8Array, length?: number): MsgUpgradeIsolatedPerpetualToCrossResponse { + const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input); + let end = length === undefined ? reader.len : reader.pos + length; + const message = createBaseMsgUpgradeIsolatedPerpetualToCrossResponse(); + + while (reader.pos < end) { + const tag = reader.uint32(); + + switch (tag >>> 3) { + default: + reader.skipType(tag & 7); + break; + } + } + + return message; + }, + + fromPartial(_: DeepPartial): MsgUpgradeIsolatedPerpetualToCrossResponse { + const message = createBaseMsgUpgradeIsolatedPerpetualToCrossResponse(); + return message; + } + }; \ No newline at end of file diff --git a/protocol/app/msgs/all_msgs.go b/protocol/app/msgs/all_msgs.go index 2369ef1056..7a86c06fc8 100644 --- a/protocol/app/msgs/all_msgs.go +++ b/protocol/app/msgs/all_msgs.go @@ -234,6 +234,7 @@ var ( "/dydxprotocol.listing.MsgCreateMarketPermissionlessResponse": {}, "/dydxprotocol.listing.MsgSetListingVaultDepositParams": {}, "/dydxprotocol.listing.MsgSetListingVaultDepositParamsResponse": {}, + // TODO TODO TODO // perpetuals "/dydxprotocol.perpetuals.MsgAddPremiumVotes": {}, From 913ddd94798a8379a09beef3a2eed35da12131b9 Mon Sep 17 00:00:00 2001 From: Harry Wray Date: Wed, 13 Nov 2024 15:45:14 -0500 Subject: [PATCH 16/29] Add new message to all_msgs.go --- protocol/app/msgs/all_msgs.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/protocol/app/msgs/all_msgs.go b/protocol/app/msgs/all_msgs.go index 7a86c06fc8..f592322f64 100644 --- a/protocol/app/msgs/all_msgs.go +++ b/protocol/app/msgs/all_msgs.go @@ -234,7 +234,7 @@ var ( "/dydxprotocol.listing.MsgCreateMarketPermissionlessResponse": {}, "/dydxprotocol.listing.MsgSetListingVaultDepositParams": {}, "/dydxprotocol.listing.MsgSetListingVaultDepositParamsResponse": {}, - // TODO TODO TODO + "/dydxprotocol.listing.MsgUpgradeIsolatedPerpetualToCross": {}, // perpetuals "/dydxprotocol.perpetuals.MsgAddPremiumVotes": {}, From 837ee009b6c965ffbb6dcf934f1ebfdbe282a568 Mon Sep 17 00:00:00 2001 From: Harry Wray Date: Wed, 13 Nov 2024 16:50:57 -0500 Subject: [PATCH 17/29] Lint --- protocol/x/perpetuals/keeper/perpetual.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/protocol/x/perpetuals/keeper/perpetual.go b/protocol/x/perpetuals/keeper/perpetual.go index eb7f6c4cf2..b97c359426 100644 --- a/protocol/x/perpetuals/keeper/perpetual.go +++ b/protocol/x/perpetuals/keeper/perpetual.go @@ -200,7 +200,8 @@ func (k Keeper) SetPerpetualMarketType( if perpetual.Params.MarketType == types.PerpetualMarketType_PERPETUAL_MARKET_TYPE_CROSS { return types.Perpetual{}, errorsmod.Wrap( types.ErrInvalidMarketType, - fmt.Sprintf("perpetual %d already has market type %v and cannot be changed", perpetualId, types.PerpetualMarketType_PERPETUAL_MARKET_TYPE_CROSS), + fmt.Sprintf("perpetual %d already has market type %v and cannot be changed", + perpetualId, types.PerpetualMarketType_PERPETUAL_MARKET_TYPE_CROSS), ) } From 4718c6d0e862d30224d91c757b9bcd6f98ca8a4a Mon Sep 17 00:00:00 2001 From: Harry Wray Date: Fri, 15 Nov 2024 11:26:11 -0500 Subject: [PATCH 18/29] Update --- protocol/app/msgs/all_msgs.go | 15 ++++++----- protocol/x/listing/keeper/listing.go | 12 ++++++++- protocol/x/listing/types/errors.go | 6 +++++ protocol/x/listing/types/expected_keepers.go | 4 +++ ...grade_isolated_perpetual_to_cross_test.go} | 3 +++ protocol/x/subaccounts/keeper/transfer.go | 27 ++++++++++++++++++- 6 files changed, 58 insertions(+), 9 deletions(-) rename protocol/x/listing/types/{msg_upgrade_isolated_perpetual_to_cross.go => msg_upgrade_isolated_perpetual_to_cross_test.go} (89%) diff --git a/protocol/app/msgs/all_msgs.go b/protocol/app/msgs/all_msgs.go index f592322f64..9a6e072df0 100644 --- a/protocol/app/msgs/all_msgs.go +++ b/protocol/app/msgs/all_msgs.go @@ -228,13 +228,14 @@ var ( "/dydxprotocol.govplus.MsgSlashValidatorResponse": {}, // listing - "/dydxprotocol.listing.MsgSetMarketsHardCap": {}, - "/dydxprotocol.listing.MsgSetMarketsHardCapResponse": {}, - "/dydxprotocol.listing.MsgCreateMarketPermissionless": {}, - "/dydxprotocol.listing.MsgCreateMarketPermissionlessResponse": {}, - "/dydxprotocol.listing.MsgSetListingVaultDepositParams": {}, - "/dydxprotocol.listing.MsgSetListingVaultDepositParamsResponse": {}, - "/dydxprotocol.listing.MsgUpgradeIsolatedPerpetualToCross": {}, + "/dydxprotocol.listing.MsgSetMarketsHardCap": {}, + "/dydxprotocol.listing.MsgSetMarketsHardCapResponse": {}, + "/dydxprotocol.listing.MsgCreateMarketPermissionless": {}, + "/dydxprotocol.listing.MsgCreateMarketPermissionlessResponse": {}, + "/dydxprotocol.listing.MsgSetListingVaultDepositParams": {}, + "/dydxprotocol.listing.MsgSetListingVaultDepositParamsResponse": {}, + "/dydxprotocol.listing.MsgUpgradeIsolatedPerpetualToCross": {}, + "/dydxprotocol.listing.MsgUpgradeIsolatedPerpetualToCrossResponse": {}, // perpetuals "/dydxprotocol.perpetuals.MsgAddPremiumVotes": {}, diff --git a/protocol/x/listing/keeper/listing.go b/protocol/x/listing/keeper/listing.go index fbd2b09e1c..e8329344a8 100644 --- a/protocol/x/listing/keeper/listing.go +++ b/protocol/x/listing/keeper/listing.go @@ -2,6 +2,7 @@ package keeper import ( "context" + "fmt" "math" "math/big" @@ -156,7 +157,16 @@ func (k Keeper) UpgradeIsolatedPerpetualToCross( ctx sdk.Context, perpetualId uint32, ) error { - err := k.SubaccountsKeeper.TransferIsolatedInsuranceFundToCross(ctx, perpetualId) + // Validate perpetual exists and is in isolated mode + perpetual, err := k.PerpetualsKeeper.GetPerpetual(ctx, perpetualId) + if err != nil { + return err + } + if perpetual.Params.GetMarketType() != perpetualtypes.PerpetualMarketType_PERPETUAL_MARKET_TYPE_ISOLATED { + return fmt.Errorf("perpetual %d is not an isolated perpetual and cannot be upgraded to cross", perpetualId) + } + + err = k.SubaccountsKeeper.TransferIsolatedInsuranceFundToCross(ctx, perpetualId) if err != nil { return err } diff --git a/protocol/x/listing/types/errors.go b/protocol/x/listing/types/errors.go index 29c5bb8653..0633784e88 100644 --- a/protocol/x/listing/types/errors.go +++ b/protocol/x/listing/types/errors.go @@ -45,4 +45,10 @@ var ( 7, "Authority is invalid", ) + + ErrInvalidPerpetualId = errorsmod.Register( + ModuleName, + 8, + "Invalid perpetual ID", + ) ) diff --git a/protocol/x/listing/types/expected_keepers.go b/protocol/x/listing/types/expected_keepers.go index ddf9cb0913..5fd30efa1b 100644 --- a/protocol/x/listing/types/expected_keepers.go +++ b/protocol/x/listing/types/expected_keepers.go @@ -64,6 +64,10 @@ type PerpetualsKeeper interface { marketType perpetualtypes.PerpetualMarketType, ) (perpetualtypes.Perpetual, error) AcquireNextPerpetualID(ctx sdk.Context) uint32 + GetPerpetual( + ctx sdk.Context, + id uint32, + ) (val perpetualtypes.Perpetual, err error) GetAllPerpetuals(ctx sdk.Context) (list []perpetualtypes.Perpetual) SetPerpetualMarketType( ctx sdk.Context, diff --git a/protocol/x/listing/types/msg_upgrade_isolated_perpetual_to_cross.go b/protocol/x/listing/types/msg_upgrade_isolated_perpetual_to_cross_test.go similarity index 89% rename from protocol/x/listing/types/msg_upgrade_isolated_perpetual_to_cross.go rename to protocol/x/listing/types/msg_upgrade_isolated_perpetual_to_cross_test.go index 453d954b3e..1db4d70557 100644 --- a/protocol/x/listing/types/msg_upgrade_isolated_perpetual_to_cross.go +++ b/protocol/x/listing/types/msg_upgrade_isolated_perpetual_to_cross_test.go @@ -21,5 +21,8 @@ func (msg *MsgUpgradeIsolatedPerpetualToCross) ValidateBasic() error { ), ) } + if msg.PerpetualId == 0 { + return ErrInvalidPerpetualId + } return nil } diff --git a/protocol/x/subaccounts/keeper/transfer.go b/protocol/x/subaccounts/keeper/transfer.go index 339654307a..f4c53fede5 100644 --- a/protocol/x/subaccounts/keeper/transfer.go +++ b/protocol/x/subaccounts/keeper/transfer.go @@ -509,20 +509,31 @@ func (k Keeper) TransferFundsFromSubaccountToSubaccount( // insurance fund to the cross-perpetual insurance fund. // Note: This uses the `x/bank` keeper and modifies `x/bank` state. func (k Keeper) TransferIsolatedInsuranceFundToCross(ctx sdk.Context, perpetualId uint32) error { + // Validate perpetual exists + if _, err := k.perpetualsKeeper.GetPerpetual(ctx, perpetualId); err != nil { + return err + } + isolatedInsuranceFundBalance := k.GetInsuranceFundBalance(ctx, perpetualId) + // Skip if balance is zero + if isolatedInsuranceFundBalance.Sign() == 0 { + return nil + } + _, coinToTransfer, err := k.assetsKeeper.ConvertAssetToCoin( ctx, assettypes.AssetUsdc.Id, isolatedInsuranceFundBalance, ) if err != nil { + // Panic if USDC does not exist. panic(err) } isolatedInsuranceFundAddr, err := k.perpetualsKeeper.GetInsuranceFundModuleAddress(ctx, perpetualId) if err != nil { - return nil + return err } crossInsuranceFundAddr := perptypes.InsuranceFundModuleAddress @@ -535,7 +546,16 @@ func (k Keeper) TransferIsolatedInsuranceFundToCross(ctx sdk.Context, perpetualI ) } +// TransferIsolatedCollateralToCross transfers the collateral balance from an isolated perpetual's +// collateral pool to the cross-margin collateral pool. This is used during the upgrade process +// from isolated perpetuals to cross-margin. +// Note: This uses the `x/bank` keeper and modifies `x/bank` state. func (k Keeper) TransferIsolatedCollateralToCross(ctx sdk.Context, perpetualId uint32) error { + // Validate perpetual exists + if _, err := k.perpetualsKeeper.GetPerpetual(ctx, perpetualId); err != nil { + return err + } + isolatedCollateralPoolAddr, err := k.GetCollateralPoolFromPerpetualId(ctx, perpetualId) if err != nil { return err @@ -554,6 +574,11 @@ func (k Keeper) TransferIsolatedCollateralToCross(ctx sdk.Context, perpetualId u usdcAsset.Denom, ) + // Skip if balance is zero + if isolatedCollateralPoolBalance.IsZero() { + return nil + } + return k.bankKeeper.SendCoins( ctx, isolatedCollateralPoolAddr, From 90cf19c01df862a58792130aeb45696714c41672 Mon Sep 17 00:00:00 2001 From: Harry Wray Date: Fri, 15 Nov 2024 11:29:56 -0500 Subject: [PATCH 19/29] Update --- .../types/msg_upgrade_isolated_perpetual_to_cross_test.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/protocol/x/listing/types/msg_upgrade_isolated_perpetual_to_cross_test.go b/protocol/x/listing/types/msg_upgrade_isolated_perpetual_to_cross_test.go index 1db4d70557..79d56f2d93 100644 --- a/protocol/x/listing/types/msg_upgrade_isolated_perpetual_to_cross_test.go +++ b/protocol/x/listing/types/msg_upgrade_isolated_perpetual_to_cross_test.go @@ -10,6 +10,11 @@ import ( var _ sdk.Msg = &MsgUpgradeIsolatedPerpetualToCross{} +func (msg *MsgUpgradeIsolatedPerpetualToCross) GetSigners() []sdk.AccAddress { + addr, _ := sdk.AccAddressFromBech32(msg.Authority) + return []sdk.AccAddress{addr} +} + func (msg *MsgUpgradeIsolatedPerpetualToCross) ValidateBasic() error { if _, err := sdk.AccAddressFromBech32(msg.Authority); err != nil { return errorsmod.Wrap( From 12d449a0a3c79a4f5e089e01949c8a765c91ad7d Mon Sep 17 00:00:00 2001 From: Harry Wray Date: Fri, 15 Nov 2024 12:49:06 -0500 Subject: [PATCH 20/29] Update --- ...rver_upgrade_isolated_perpetual_to_cross_test.go | 13 +++++++++++-- ...o => msg_upgrade_isolated_perpetual_to_cross.go} | 0 2 files changed, 11 insertions(+), 2 deletions(-) rename protocol/x/listing/types/{msg_upgrade_isolated_perpetual_to_cross_test.go => msg_upgrade_isolated_perpetual_to_cross.go} (100%) diff --git a/protocol/x/listing/keeper/msg_server_upgrade_isolated_perpetual_to_cross_test.go b/protocol/x/listing/keeper/msg_server_upgrade_isolated_perpetual_to_cross_test.go index ea55caad92..ca8e9759b0 100644 --- a/protocol/x/listing/keeper/msg_server_upgrade_isolated_perpetual_to_cross_test.go +++ b/protocol/x/listing/keeper/msg_server_upgrade_isolated_perpetual_to_cross_test.go @@ -26,16 +26,25 @@ func TestMsgUpgradeIsolatedPerpetualToCross_ValidateBasic(t *testing.T) { }, "Failure: Empty authority": { msg: types.MsgUpgradeIsolatedPerpetualToCross{ - Authority: "", + Authority: "", + PerpetualId: 1, }, expectedErr: "Authority is invalid", }, "Failure: Invaid authority": { msg: types.MsgUpgradeIsolatedPerpetualToCross{ - Authority: "invalid", + Authority: "invalid", + PerpetualId: 1, }, expectedErr: "Authority is invalid", }, + "Failure: Invaid perpetual ID": { + msg: types.MsgUpgradeIsolatedPerpetualToCross{ + Authority: validAuthority, + PerpetualId: 0, + }, + expectedErr: "Invalid perpetual ID", + }, } for name, tc := range tests { diff --git a/protocol/x/listing/types/msg_upgrade_isolated_perpetual_to_cross_test.go b/protocol/x/listing/types/msg_upgrade_isolated_perpetual_to_cross.go similarity index 100% rename from protocol/x/listing/types/msg_upgrade_isolated_perpetual_to_cross_test.go rename to protocol/x/listing/types/msg_upgrade_isolated_perpetual_to_cross.go From 9fb48dc7e86f602198417eaa0da9734e5089e216 Mon Sep 17 00:00:00 2001 From: Harry Wray Date: Fri, 15 Nov 2024 14:21:44 -0500 Subject: [PATCH 21/29] Add new message to unsupported_msgs.go --- protocol/app/msgs/unsupported_msgs.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/protocol/app/msgs/unsupported_msgs.go b/protocol/app/msgs/unsupported_msgs.go index 885917819c..28594b2009 100644 --- a/protocol/app/msgs/unsupported_msgs.go +++ b/protocol/app/msgs/unsupported_msgs.go @@ -5,6 +5,7 @@ import ( gov "github.com/cosmos/cosmos-sdk/x/gov/types/v1" govbeta "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1" icacontrollertypes "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/controller/types" + listingtypes "github.com/dydxprotocol/v4-chain/protocol/x/listing/types" vaulttypes "github.com/dydxprotocol/v4-chain/protocol/x/vault/types" ) @@ -30,6 +31,10 @@ var ( MsgUpdateParams{}, "/ibc.applications.interchain_accounts.controller.v1.MsgUpdateParamsResponse": nil, + // WIP + "/dydxprotocol.listing.MsgUpgradeIsolatedPerpetualToCross": &listingtypes.MsgUpgradeIsolatedPerpetualToCross{}, + "/dydxprotocol.listing.MsgUpgradeIsolatedPerpetualToCrossResponse": nil, + // vault // MsgSetVaultQuotingParams is deprecated since v6.x and replaced by MsgSetVaultParams. // nolint:staticcheck From 8161136708de420a919ac1202b315d22fc8ea72a Mon Sep 17 00:00:00 2001 From: Harry Wray Date: Fri, 15 Nov 2024 14:58:12 -0500 Subject: [PATCH 22/29] Update --- protocol/app/msgs/unsupported_msgs.go | 3 ++- protocol/app/msgs/unsupported_msgs_test.go | 4 ++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/protocol/app/msgs/unsupported_msgs.go b/protocol/app/msgs/unsupported_msgs.go index 28594b2009..7b24098a9a 100644 --- a/protocol/app/msgs/unsupported_msgs.go +++ b/protocol/app/msgs/unsupported_msgs.go @@ -32,7 +32,8 @@ var ( "/ibc.applications.interchain_accounts.controller.v1.MsgUpdateParamsResponse": nil, // WIP - "/dydxprotocol.listing.MsgUpgradeIsolatedPerpetualToCross": &listingtypes.MsgUpgradeIsolatedPerpetualToCross{}, + "/dydxprotocol.listing.MsgUpgradeIsolatedPerpetualToCross": &listingtypes. + MsgUpgradeIsolatedPerpetualToCross{}, "/dydxprotocol.listing.MsgUpgradeIsolatedPerpetualToCrossResponse": nil, // vault diff --git a/protocol/app/msgs/unsupported_msgs_test.go b/protocol/app/msgs/unsupported_msgs_test.go index 3ba4e9041f..8f3b329f35 100644 --- a/protocol/app/msgs/unsupported_msgs_test.go +++ b/protocol/app/msgs/unsupported_msgs_test.go @@ -19,6 +19,10 @@ func TestUnsupportedMsgSamples_Key(t *testing.T) { "/dydxprotocol.vault.MsgSetVaultQuotingParams", "/dydxprotocol.vault.MsgUpdateParams", + // WIP + "/dydxprotocol.listing.MsgUpgradeIsolatedPerpetualToCross", + "/dydxprotocol.listing.MsgUpgradeIsolatedPerpetualToCrossResponse", + // ICA Controller messages "/ibc.applications.interchain_accounts.controller.v1.MsgRegisterInterchainAccount", "/ibc.applications.interchain_accounts.controller.v1.MsgRegisterInterchainAccountResponse", From c1edfaf340d9b0736ac3ec33ed6ca8b983392d9f Mon Sep 17 00:00:00 2001 From: Harry Wray Date: Fri, 15 Nov 2024 15:15:56 -0500 Subject: [PATCH 23/29] Update --- protocol/lib/ante/nested_msg_test.go | 4 +++- protocol/lib/ante/unsupported_msgs.go | 5 ++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/protocol/lib/ante/nested_msg_test.go b/protocol/lib/ante/nested_msg_test.go index 0a98a94b84..a3f4dea79b 100644 --- a/protocol/lib/ante/nested_msg_test.go +++ b/protocol/lib/ante/nested_msg_test.go @@ -12,6 +12,7 @@ import ( "github.com/dydxprotocol/v4-chain/protocol/lib" "github.com/dydxprotocol/v4-chain/protocol/lib/ante" testmsgs "github.com/dydxprotocol/v4-chain/protocol/testutil/msgs" + listingtypes "github.com/dydxprotocol/v4-chain/protocol/x/listing/types" vaulttypes "github.com/dydxprotocol/v4-chain/protocol/x/vault/types" "github.com/stretchr/testify/require" @@ -76,7 +77,8 @@ func TestIsDydxMsg_Invalid(t *testing.T) { // nolint:staticcheck "/dydxprotocol.vault.MsgSetVaultQuotingParams": &vaulttypes.MsgSetVaultQuotingParams{}, // nolint:staticcheck - "/dydxprotocol.vault.MsgUpdateParams": &vaulttypes.MsgUpdateParams{}, + "/dydxprotocol.vault.MsgUpdateParams": &vaulttypes.MsgUpdateParams{}, + "/dydxprotocol.listing.MsgUpgradeIsolatedPerpetualToCross": &listingtypes.MsgUpgradeIsolatedPerpetualToCross{}, }, ) allMsgsMinusDydx := lib.MergeAllMapsMustHaveDistinctKeys(appmsgs.AllowMsgs, appmsgs.DisallowMsgs) diff --git a/protocol/lib/ante/unsupported_msgs.go b/protocol/lib/ante/unsupported_msgs.go index 8dd69cdf6d..ea49127c85 100644 --- a/protocol/lib/ante/unsupported_msgs.go +++ b/protocol/lib/ante/unsupported_msgs.go @@ -5,6 +5,7 @@ import ( gov "github.com/cosmos/cosmos-sdk/x/gov/types/v1" govbeta "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1" icacontrollertypes "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/controller/types" + listingtypes "github.com/dydxprotocol/v4-chain/protocol/x/listing/types" vaulttypes "github.com/dydxprotocol/v4-chain/protocol/x/vault/types" ) @@ -25,7 +26,9 @@ func IsUnsupportedMsg(msg sdk.Msg) bool { // nolint:staticcheck *vaulttypes.MsgSetVaultQuotingParams, // nolint:staticcheck - *vaulttypes.MsgUpdateParams: + *vaulttypes.MsgUpdateParams, + // WIP + *listingtypes.MsgUpgradeIsolatedPerpetualToCross: return true } return false From 15d37f9ae81d5bcf33fbe329c8206c6c58e6c0e8 Mon Sep 17 00:00:00 2001 From: Harry Wray Date: Fri, 15 Nov 2024 15:40:03 -0500 Subject: [PATCH 24/29] Update --- protocol/app/msgs/internal_msgs.go | 10 ++++++---- protocol/app/msgs/internal_msgs_test.go | 2 ++ protocol/app/msgs/unsupported_msgs.go | 6 ------ protocol/app/msgs/unsupported_msgs_test.go | 4 ---- protocol/lib/ante/internal_msg.go | 1 + protocol/lib/ante/nested_msg_test.go | 4 +--- protocol/lib/ante/unsupported_msgs.go | 5 +---- 7 files changed, 11 insertions(+), 21 deletions(-) diff --git a/protocol/app/msgs/internal_msgs.go b/protocol/app/msgs/internal_msgs.go index 9c0e58f9f6..8587ff5e4c 100644 --- a/protocol/app/msgs/internal_msgs.go +++ b/protocol/app/msgs/internal_msgs.go @@ -156,10 +156,12 @@ var ( "/dydxprotocol.govplus.MsgSlashValidatorResponse": nil, // listing - "/dydxprotocol.listing.MsgSetMarketsHardCap": &listing.MsgSetMarketsHardCap{}, - "/dydxprotocol.listing.MsgSetMarketsHardCapResponse": nil, - "/dydxprotocol.listing.MsgSetListingVaultDepositParams": &listing.MsgSetListingVaultDepositParams{}, - "/dydxprotocol.listing.MsgSetListingVaultDepositParamsResponse": nil, + "/dydxprotocol.listing.MsgSetMarketsHardCap": &listing.MsgSetMarketsHardCap{}, + "/dydxprotocol.listing.MsgSetMarketsHardCapResponse": nil, + "/dydxprotocol.listing.MsgSetListingVaultDepositParams": &listing.MsgSetListingVaultDepositParams{}, + "/dydxprotocol.listing.MsgSetListingVaultDepositParamsResponse": nil, + "/dydxprotocol.listing.MsgUpgradeIsolatedPerpetualToCross": &listing.MsgUpgradeIsolatedPerpetualToCross{}, + "/dydxprotocol.listing.MsgUpgradeIsolatedPerpetualToCrossResponse": nil, // perpetuals "/dydxprotocol.perpetuals.MsgCreatePerpetual": &perpetuals.MsgCreatePerpetual{}, diff --git a/protocol/app/msgs/internal_msgs_test.go b/protocol/app/msgs/internal_msgs_test.go index 70e3549fe5..00bcbdc912 100644 --- a/protocol/app/msgs/internal_msgs_test.go +++ b/protocol/app/msgs/internal_msgs_test.go @@ -116,6 +116,8 @@ func TestInternalMsgSamples_Gov_Key(t *testing.T) { "/dydxprotocol.listing.MsgSetListingVaultDepositParamsResponse", "/dydxprotocol.listing.MsgSetMarketsHardCap", "/dydxprotocol.listing.MsgSetMarketsHardCapResponse", + "/dydxprotocol.listing.MsgUpgradeIsolatedPerpetualToCross", + "/dydxprotocol.listing.MsgUpgradeIsolatedPerpetualToCrossResponse", // perpeutals "/dydxprotocol.perpetuals.MsgCreatePerpetual", diff --git a/protocol/app/msgs/unsupported_msgs.go b/protocol/app/msgs/unsupported_msgs.go index 7b24098a9a..885917819c 100644 --- a/protocol/app/msgs/unsupported_msgs.go +++ b/protocol/app/msgs/unsupported_msgs.go @@ -5,7 +5,6 @@ import ( gov "github.com/cosmos/cosmos-sdk/x/gov/types/v1" govbeta "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1" icacontrollertypes "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/controller/types" - listingtypes "github.com/dydxprotocol/v4-chain/protocol/x/listing/types" vaulttypes "github.com/dydxprotocol/v4-chain/protocol/x/vault/types" ) @@ -31,11 +30,6 @@ var ( MsgUpdateParams{}, "/ibc.applications.interchain_accounts.controller.v1.MsgUpdateParamsResponse": nil, - // WIP - "/dydxprotocol.listing.MsgUpgradeIsolatedPerpetualToCross": &listingtypes. - MsgUpgradeIsolatedPerpetualToCross{}, - "/dydxprotocol.listing.MsgUpgradeIsolatedPerpetualToCrossResponse": nil, - // vault // MsgSetVaultQuotingParams is deprecated since v6.x and replaced by MsgSetVaultParams. // nolint:staticcheck diff --git a/protocol/app/msgs/unsupported_msgs_test.go b/protocol/app/msgs/unsupported_msgs_test.go index 8f3b329f35..3ba4e9041f 100644 --- a/protocol/app/msgs/unsupported_msgs_test.go +++ b/protocol/app/msgs/unsupported_msgs_test.go @@ -19,10 +19,6 @@ func TestUnsupportedMsgSamples_Key(t *testing.T) { "/dydxprotocol.vault.MsgSetVaultQuotingParams", "/dydxprotocol.vault.MsgUpdateParams", - // WIP - "/dydxprotocol.listing.MsgUpgradeIsolatedPerpetualToCross", - "/dydxprotocol.listing.MsgUpgradeIsolatedPerpetualToCrossResponse", - // ICA Controller messages "/ibc.applications.interchain_accounts.controller.v1.MsgRegisterInterchainAccount", "/ibc.applications.interchain_accounts.controller.v1.MsgRegisterInterchainAccountResponse", diff --git a/protocol/lib/ante/internal_msg.go b/protocol/lib/ante/internal_msg.go index 4d578d4f10..3e1b44a917 100644 --- a/protocol/lib/ante/internal_msg.go +++ b/protocol/lib/ante/internal_msg.go @@ -103,6 +103,7 @@ func IsInternalMsg(msg sdk.Msg) bool { // listing *listing.MsgSetMarketsHardCap, *listing.MsgSetListingVaultDepositParams, + *listing.MsgUpgradeIsolatedPerpetualToCross, // perpetuals *perpetuals.MsgCreatePerpetual, diff --git a/protocol/lib/ante/nested_msg_test.go b/protocol/lib/ante/nested_msg_test.go index a3f4dea79b..0a98a94b84 100644 --- a/protocol/lib/ante/nested_msg_test.go +++ b/protocol/lib/ante/nested_msg_test.go @@ -12,7 +12,6 @@ import ( "github.com/dydxprotocol/v4-chain/protocol/lib" "github.com/dydxprotocol/v4-chain/protocol/lib/ante" testmsgs "github.com/dydxprotocol/v4-chain/protocol/testutil/msgs" - listingtypes "github.com/dydxprotocol/v4-chain/protocol/x/listing/types" vaulttypes "github.com/dydxprotocol/v4-chain/protocol/x/vault/types" "github.com/stretchr/testify/require" @@ -77,8 +76,7 @@ func TestIsDydxMsg_Invalid(t *testing.T) { // nolint:staticcheck "/dydxprotocol.vault.MsgSetVaultQuotingParams": &vaulttypes.MsgSetVaultQuotingParams{}, // nolint:staticcheck - "/dydxprotocol.vault.MsgUpdateParams": &vaulttypes.MsgUpdateParams{}, - "/dydxprotocol.listing.MsgUpgradeIsolatedPerpetualToCross": &listingtypes.MsgUpgradeIsolatedPerpetualToCross{}, + "/dydxprotocol.vault.MsgUpdateParams": &vaulttypes.MsgUpdateParams{}, }, ) allMsgsMinusDydx := lib.MergeAllMapsMustHaveDistinctKeys(appmsgs.AllowMsgs, appmsgs.DisallowMsgs) diff --git a/protocol/lib/ante/unsupported_msgs.go b/protocol/lib/ante/unsupported_msgs.go index ea49127c85..8dd69cdf6d 100644 --- a/protocol/lib/ante/unsupported_msgs.go +++ b/protocol/lib/ante/unsupported_msgs.go @@ -5,7 +5,6 @@ import ( gov "github.com/cosmos/cosmos-sdk/x/gov/types/v1" govbeta "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1" icacontrollertypes "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/controller/types" - listingtypes "github.com/dydxprotocol/v4-chain/protocol/x/listing/types" vaulttypes "github.com/dydxprotocol/v4-chain/protocol/x/vault/types" ) @@ -26,9 +25,7 @@ func IsUnsupportedMsg(msg sdk.Msg) bool { // nolint:staticcheck *vaulttypes.MsgSetVaultQuotingParams, // nolint:staticcheck - *vaulttypes.MsgUpdateParams, - // WIP - *listingtypes.MsgUpgradeIsolatedPerpetualToCross: + *vaulttypes.MsgUpdateParams: return true } return false From e84a34b1b98d9bb799525e1b313945511567b48d Mon Sep 17 00:00:00 2001 From: Harry Wray Date: Tue, 19 Nov 2024 17:13:04 -0500 Subject: [PATCH 25/29] Update --- .../msg_server_upgrade_isolated_perpetual_to_cross_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/protocol/x/listing/keeper/msg_server_upgrade_isolated_perpetual_to_cross_test.go b/protocol/x/listing/keeper/msg_server_upgrade_isolated_perpetual_to_cross_test.go index ca8e9759b0..6e843ce2f4 100644 --- a/protocol/x/listing/keeper/msg_server_upgrade_isolated_perpetual_to_cross_test.go +++ b/protocol/x/listing/keeper/msg_server_upgrade_isolated_perpetual_to_cross_test.go @@ -31,14 +31,14 @@ func TestMsgUpgradeIsolatedPerpetualToCross_ValidateBasic(t *testing.T) { }, expectedErr: "Authority is invalid", }, - "Failure: Invaid authority": { + "Failure: Invalid authority": { msg: types.MsgUpgradeIsolatedPerpetualToCross{ Authority: "invalid", PerpetualId: 1, }, expectedErr: "Authority is invalid", }, - "Failure: Invaid perpetual ID": { + "Failure: Invalid perpetual ID": { msg: types.MsgUpgradeIsolatedPerpetualToCross{ Authority: validAuthority, PerpetualId: 0, From 12e279d64b76635179d4d65b1cee2b51a528b6b3 Mon Sep 17 00:00:00 2001 From: Harry Wray Date: Tue, 19 Nov 2024 17:14:08 -0500 Subject: [PATCH 26/29] Update --- .../x/listing/types/msg_upgrade_isolated_perpetual_to_cross.go | 3 --- 1 file changed, 3 deletions(-) diff --git a/protocol/x/listing/types/msg_upgrade_isolated_perpetual_to_cross.go b/protocol/x/listing/types/msg_upgrade_isolated_perpetual_to_cross.go index 79d56f2d93..19ddcfae1f 100644 --- a/protocol/x/listing/types/msg_upgrade_isolated_perpetual_to_cross.go +++ b/protocol/x/listing/types/msg_upgrade_isolated_perpetual_to_cross.go @@ -26,8 +26,5 @@ func (msg *MsgUpgradeIsolatedPerpetualToCross) ValidateBasic() error { ), ) } - if msg.PerpetualId == 0 { - return ErrInvalidPerpetualId - } return nil } From 334af8fb8349a870e640eb79b8f66ed1c8e17e77 Mon Sep 17 00:00:00 2001 From: Harry Wray Date: Wed, 20 Nov 2024 14:48:21 -0500 Subject: [PATCH 27/29] Update tests --- protocol/testutil/keeper/listing.go | 21 +- protocol/x/listing/keeper/listing_test.go | 7 +- ...pgrade_isolated_perpetual_to_cross_test.go | 236 ++++++++++++++++-- ...msg_upgrade_isolated_perpetual_to_cross.go | 30 --- protocol/x/subaccounts/keeper/transfer.go | 9 +- 5 files changed, 239 insertions(+), 64 deletions(-) delete mode 100644 protocol/x/listing/types/msg_upgrade_isolated_perpetual_to_cross.go diff --git a/protocol/testutil/keeper/listing.go b/protocol/testutil/keeper/listing.go index 17af514ab1..1448645130 100644 --- a/protocol/testutil/keeper/listing.go +++ b/protocol/testutil/keeper/listing.go @@ -11,6 +11,7 @@ import ( "github.com/dydxprotocol/v4-chain/protocol/lib" "github.com/dydxprotocol/v4-chain/protocol/mocks" "github.com/dydxprotocol/v4-chain/protocol/testutil/constants" + assetskeeper "github.com/dydxprotocol/v4-chain/protocol/x/assets/keeper" clobkeeper "github.com/dydxprotocol/v4-chain/protocol/x/clob/keeper" perpetualskeeper "github.com/dydxprotocol/v4-chain/protocol/x/perpetuals/keeper" priceskeeper "github.com/dydxprotocol/v4-chain/protocol/x/prices/keeper" @@ -38,6 +39,9 @@ func ListingKeepers( perpetualsKeeper *perpetualskeeper.Keeper, clobKeeper *clobkeeper.Keeper, marketMapKeeper *marketmapkeeper.Keeper, + assetsKeeper *assetskeeper.Keeper, + bankKeeper_out *bankkeeper.BaseKeeper, + subaccountsKeeper *subaccountskeeper.Keeper, ) { ctx = initKeepers( t, func( @@ -64,13 +68,13 @@ func ListingKeepers( db, cdc, ) - bankKeeper, _ = createBankKeeper(stateStore, db, cdc, accountsKeeper) + bankKeeper_out, _ = createBankKeeper(stateStore, db, cdc, accountsKeeper) stakingKeeper, _ := createStakingKeeper( stateStore, db, cdc, accountsKeeper, - bankKeeper, + bankKeeper_out, ) statsKeeper, _ := createStatsKeeper( stateStore, @@ -114,7 +118,7 @@ func ListingKeepers( epochsKeeper, transientStoreKey, ) - assetsKeeper, _ := createAssetsKeeper( + assetsKeeper, _ = createAssetsKeeper( stateStore, db, cdc, @@ -127,19 +131,19 @@ func ListingKeepers( rewardsKeeper, _ := createRewardsKeeper( stateStore, assetsKeeper, - bankKeeper, + bankKeeper_out, feeTiersKeeper, pricesKeeper, indexerEventManager, db, cdc, ) - subaccountsKeeper, _ := createSubaccountsKeeper( + subaccountsKeeper, _ = createSubaccountsKeeper( stateStore, db, cdc, assetsKeeper, - bankKeeper, + bankKeeper_out, perpetualsKeeper, blockTimeKeeper, transientStoreKey, @@ -152,7 +156,7 @@ func ListingKeepers( memClob, assetsKeeper, blockTimeKeeper, - bankKeeper, + bankKeeper_out, feeTiersKeeper, perpetualsKeeper, pricesKeeper, @@ -182,7 +186,8 @@ func ListingKeepers( }, ) - return ctx, keeper, storeKey, mockTimeProvider, pricesKeeper, perpetualsKeeper, clobKeeper, marketMapKeeper + return ctx, keeper, storeKey, mockTimeProvider, pricesKeeper, perpetualsKeeper, + clobKeeper, marketMapKeeper, assetsKeeper, bankKeeper_out, subaccountsKeeper } func createListingKeeper( diff --git a/protocol/x/listing/keeper/listing_test.go b/protocol/x/listing/keeper/listing_test.go index 18c9a8778f..5f75bfb5c0 100644 --- a/protocol/x/listing/keeper/listing_test.go +++ b/protocol/x/listing/keeper/listing_test.go @@ -62,7 +62,7 @@ func TestCreateMarket(t *testing.T) { t.Run( name, func(t *testing.T) { mockIndexerEventManager := &mocks.IndexerEventManager{} - ctx, keeper, _, _, pricesKeeper, _, _, marketMapKeeper := keepertest.ListingKeepers( + ctx, keeper, _, _, pricesKeeper, _, _, marketMapKeeper, _, _, _ := keepertest.ListingKeepers( t, &mocks.BankKeeper{}, mockIndexerEventManager, @@ -131,7 +131,7 @@ func TestCreatePerpetual(t *testing.T) { t.Run( name, func(t *testing.T) { mockIndexerEventManager := &mocks.IndexerEventManager{} - ctx, keeper, _, _, pricesKeeper, perpetualsKeeper, _, marketMapKeeper := keepertest.ListingKeepers( + ctx, keeper, _, _, pricesKeeper, perpetualsKeeper, _, marketMapKeeper, _, _, _ := keepertest.ListingKeepers( t, &mocks.BankKeeper{}, mockIndexerEventManager, @@ -217,7 +217,8 @@ func TestCreateClobPair(t *testing.T) { t.Run( name, func(t *testing.T) { mockIndexerEventManager := &mocks.IndexerEventManager{} - ctx, keeper, _, _, pricesKeeper, perpetualsKeeper, clobKeeper, marketMapKeeper := keepertest.ListingKeepers( + ctx, keeper, _, _, pricesKeeper, perpetualsKeeper, clobKeeper, marketMapKeeper, + _, _, _ := keepertest.ListingKeepers( t, &mocks.BankKeeper{}, mockIndexerEventManager, diff --git a/protocol/x/listing/keeper/msg_server_upgrade_isolated_perpetual_to_cross_test.go b/protocol/x/listing/keeper/msg_server_upgrade_isolated_perpetual_to_cross_test.go index 6e843ce2f4..2113303bfa 100644 --- a/protocol/x/listing/keeper/msg_server_upgrade_isolated_perpetual_to_cross_test.go +++ b/protocol/x/listing/keeper/msg_server_upgrade_isolated_perpetual_to_cross_test.go @@ -1,60 +1,254 @@ package keeper_test import ( + "math/big" "testing" + sdkmath "cosmossdk.io/math" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/dydxprotocol/v4-chain/protocol/lib" + "github.com/dydxprotocol/v4-chain/protocol/mocks" + testapp "github.com/dydxprotocol/v4-chain/protocol/testutil/app" + bank_testutil "github.com/dydxprotocol/v4-chain/protocol/testutil/bank" "github.com/dydxprotocol/v4-chain/protocol/testutil/constants" + keepertest "github.com/dydxprotocol/v4-chain/protocol/testutil/keeper" + asstypes "github.com/dydxprotocol/v4-chain/protocol/x/assets/types" + "github.com/dydxprotocol/v4-chain/protocol/x/listing/keeper" + listingkeeper "github.com/dydxprotocol/v4-chain/protocol/x/listing/keeper" types "github.com/dydxprotocol/v4-chain/protocol/x/listing/types" + perpetualtypes "github.com/dydxprotocol/v4-chain/protocol/x/perpetuals/types" + satypes "github.com/dydxprotocol/v4-chain/protocol/x/subaccounts/types" "github.com/stretchr/testify/require" ) var ( // validAuthority is a valid bech32 address. - validAuthority = constants.AliceAccAddress.String() + validAuthority = lib.GovModuleAddress.String() ) -func TestMsgUpgradeIsolatedPerpetualToCross_ValidateBasic(t *testing.T) { +func TestMsgUpgradeIsolatedPerpetualToCross(t *testing.T) { tests := map[string]struct { - msg types.MsgUpgradeIsolatedPerpetualToCross + msg *types.MsgUpgradeIsolatedPerpetualToCross + expectedErr string + }{} + + for name, tc := range tests { + t.Run(name, func(t *testing.T) { + tApp := testapp.NewTestAppBuilder(t).Build() + ctx := tApp.InitChain() + k := tApp.App.ListingKeeper + ms := keeper.NewMsgServerImpl(k) + _, err := ms.UpgradeIsolatedPerpetualToCross(ctx, tc.msg) + if tc.expectedErr == "" { + require.NoError(t, err) + } else { + require.ErrorContains(t, err, tc.expectedErr) + } + }) + } +} + +func TestUpgradeIsolatedPerpetualToCross(t *testing.T) { + tests := map[string]struct { + msg *types.MsgUpgradeIsolatedPerpetualToCross + isolatedInsuranceFundBalance *big.Int + isolatedCollateralPoolBalance *big.Int + crossInsuranceFundBalance *big.Int + crossCollateralPoolBalance *big.Int + expectedErr string }{ "Success": { - msg: types.MsgUpgradeIsolatedPerpetualToCross{ + msg: &types.MsgUpgradeIsolatedPerpetualToCross{ + Authority: validAuthority, + PerpetualId: 3, // isolated + }, + isolatedInsuranceFundBalance: big.NewInt(1), + isolatedCollateralPoolBalance: big.NewInt(1), + crossInsuranceFundBalance: big.NewInt(1), + crossCollateralPoolBalance: big.NewInt(1), + expectedErr: "", + }, + "Success - empty isolated insurance fund": { + msg: &types.MsgUpgradeIsolatedPerpetualToCross{ + Authority: validAuthority, + PerpetualId: 3, // isolated + }, + isolatedInsuranceFundBalance: big.NewInt(0), + isolatedCollateralPoolBalance: big.NewInt(1), + crossInsuranceFundBalance: big.NewInt(1), + crossCollateralPoolBalance: big.NewInt(1), + expectedErr: "", + }, + "Success - empty isolated collateral fund": { + msg: &types.MsgUpgradeIsolatedPerpetualToCross{ Authority: validAuthority, - PerpetualId: 1, + PerpetualId: 3, // isolated }, + isolatedInsuranceFundBalance: big.NewInt(1), + isolatedCollateralPoolBalance: big.NewInt(0), + crossInsuranceFundBalance: big.NewInt(1), + crossCollateralPoolBalance: big.NewInt(1), + expectedErr: "", + }, + "Success - empty isolated insurance fund + empty isolated collateral fund": { + msg: &types.MsgUpgradeIsolatedPerpetualToCross{ + Authority: validAuthority, + PerpetualId: 3, // isolated + }, + isolatedInsuranceFundBalance: big.NewInt(0), + isolatedCollateralPoolBalance: big.NewInt(0), + crossInsuranceFundBalance: big.NewInt(1), + crossCollateralPoolBalance: big.NewInt(1), + expectedErr: "", }, "Failure: Empty authority": { - msg: types.MsgUpgradeIsolatedPerpetualToCross{ + msg: &types.MsgUpgradeIsolatedPerpetualToCross{ Authority: "", - PerpetualId: 1, + PerpetualId: 3, // isolated }, - expectedErr: "Authority is invalid", + isolatedInsuranceFundBalance: big.NewInt(1), + isolatedCollateralPoolBalance: big.NewInt(1), + crossInsuranceFundBalance: big.NewInt(1), + crossCollateralPoolBalance: big.NewInt(1), + expectedErr: "invalid authority", }, "Failure: Invalid authority": { - msg: types.MsgUpgradeIsolatedPerpetualToCross{ + msg: &types.MsgUpgradeIsolatedPerpetualToCross{ Authority: "invalid", - PerpetualId: 1, + PerpetualId: 3, // isolated }, - expectedErr: "Authority is invalid", + isolatedInsuranceFundBalance: big.NewInt(1), + isolatedCollateralPoolBalance: big.NewInt(1), + crossInsuranceFundBalance: big.NewInt(1), + crossCollateralPoolBalance: big.NewInt(1), + expectedErr: "invalid authority", }, "Failure: Invalid perpetual ID": { - msg: types.MsgUpgradeIsolatedPerpetualToCross{ + msg: &types.MsgUpgradeIsolatedPerpetualToCross{ + Authority: validAuthority, + PerpetualId: 99999999, // invalid + }, + expectedErr: "Perpetual does not exist", + }, + "Failure - perpetual already has cross market type": { + msg: &types.MsgUpgradeIsolatedPerpetualToCross{ Authority: validAuthority, - PerpetualId: 0, + PerpetualId: 1, // cross }, - expectedErr: "Invalid perpetual ID", + isolatedInsuranceFundBalance: big.NewInt(1), + isolatedCollateralPoolBalance: big.NewInt(1), + crossInsuranceFundBalance: big.NewInt(1), + crossCollateralPoolBalance: big.NewInt(1), + expectedErr: "perpetual 1 is not an isolated perpetual and cannot be upgraded to cross", }, } for name, tc := range tests { - t.Run(name, func(t *testing.T) { - err := tc.msg.ValidateBasic() - if tc.expectedErr == "" { + t.Run( + name, func(t *testing.T) { + mockIndexerEventManager := &mocks.IndexerEventManager{} + + ctx, keeper, _, _, pricesKeeper, perpetualsKeeper, _, _, assetsKeeper, + bankKeeper, subaccountsKeeper := keepertest.ListingKeepers( + t, + &mocks.BankKeeper{}, + mockIndexerEventManager, + ) + + // Create the default markets. + keepertest.CreateTestMarkets(t, ctx, pricesKeeper) + + // Create liquidity tiers. + keepertest.CreateTestLiquidityTiers(t, ctx, perpetualsKeeper) + + // Create USDC asset. + err := keepertest.CreateUsdcAsset(ctx, assetsKeeper) require.NoError(t, err) - } else { - require.ErrorContains(t, err, tc.expectedErr) - } - }) + + // Create test perpetuals. + keepertest.CreateTestPerpetuals(t, ctx, perpetualsKeeper) + + var isolatedInsuranceFundAddr, crossInsuranceFundAddr, isolatedCollateralPoolAddr, crossCollateralPoolAddr sdk.AccAddress + if tc.isolatedInsuranceFundBalance != nil { + // Get addresses for isolated/cross insurance funds and collateral pools. + isolatedInsuranceFundAddr, err = perpetualsKeeper.GetInsuranceFundModuleAddress(ctx, tc.msg.PerpetualId) + require.NoError(t, err) + + isolatedCollateralPoolAddr, err = subaccountsKeeper.GetCollateralPoolFromPerpetualId(ctx, tc.msg.PerpetualId) + require.NoError(t, err) + + crossInsuranceFundAddr = perpetualtypes.InsuranceFundModuleAddress + + crossCollateralPoolAddr = satypes.ModuleAddress + + // Fund the isolated insurance account, cross insurance account, + // isolated collateral pool, and cross collateral pool. + fundingData := [][]interface{}{ + {isolatedInsuranceFundAddr, tc.isolatedInsuranceFundBalance}, + {crossInsuranceFundAddr, tc.crossInsuranceFundBalance}, + {isolatedCollateralPoolAddr, tc.isolatedCollateralPoolBalance}, + {crossCollateralPoolAddr, tc.crossCollateralPoolBalance}, + } + + for _, data := range fundingData { + addr := data[0].(sdk.AccAddress) + amount := data[1].(*big.Int) + + if amount.Cmp(big.NewInt(0)) != 0 { + err = bank_testutil.FundAccount( + ctx, + addr, + sdk.Coins{ + sdk.NewCoin(constants.Usdc.Denom, sdkmath.NewIntFromBigInt(amount)), + }, + *bankKeeper, + ) + require.NoError(t, err) + } + } + } + + // Upgrade perpetual from isolated to cross. + ms := listingkeeper.NewMsgServerImpl(*keeper) + _, err = ms.UpgradeIsolatedPerpetualToCross(ctx, tc.msg) + if tc.expectedErr != "" { + require.ErrorContains(t, err, tc.expectedErr) + return + } + require.NoError(t, err) + + // Check perpetual market type has been upgraded to cross. + perpetual, err := perpetualsKeeper.GetPerpetual(ctx, tc.msg.PerpetualId) + require.NoError(t, err) + require.Equal( + t, + perpetualtypes.PerpetualMarketType_PERPETUAL_MARKET_TYPE_CROSS, + perpetual.Params.MarketType, + ) + + // Check expected balance for isolated/cross insurance funds and collateral pools. + expectedBalances := [][]interface{}{ + {isolatedInsuranceFundAddr, big.NewInt(0)}, + {crossInsuranceFundAddr, big.NewInt(0).Add(tc.isolatedInsuranceFundBalance, tc.crossInsuranceFundBalance)}, + {isolatedCollateralPoolAddr, big.NewInt(0)}, + {crossCollateralPoolAddr, big.NewInt(0).Add(tc.isolatedCollateralPoolBalance, tc.crossCollateralPoolBalance)}, + } + + for _, data := range expectedBalances { + addr := data[0].(sdk.AccAddress) + amount := data[1].(*big.Int) + + require.Equal( + t, + sdk.NewCoin( + asstypes.AssetUsdc.Denom, + sdkmath.NewIntFromBigInt(amount), + ), + bankKeeper.GetBalance(ctx, addr, asstypes.AssetUsdc.Denom), + ) + } + }, + ) } } diff --git a/protocol/x/listing/types/msg_upgrade_isolated_perpetual_to_cross.go b/protocol/x/listing/types/msg_upgrade_isolated_perpetual_to_cross.go deleted file mode 100644 index 19ddcfae1f..0000000000 --- a/protocol/x/listing/types/msg_upgrade_isolated_perpetual_to_cross.go +++ /dev/null @@ -1,30 +0,0 @@ -package types - -import ( - fmt "fmt" - - errorsmod "cosmossdk.io/errors" - - sdk "github.com/cosmos/cosmos-sdk/types" -) - -var _ sdk.Msg = &MsgUpgradeIsolatedPerpetualToCross{} - -func (msg *MsgUpgradeIsolatedPerpetualToCross) GetSigners() []sdk.AccAddress { - addr, _ := sdk.AccAddressFromBech32(msg.Authority) - return []sdk.AccAddress{addr} -} - -func (msg *MsgUpgradeIsolatedPerpetualToCross) ValidateBasic() error { - if _, err := sdk.AccAddressFromBech32(msg.Authority); err != nil { - return errorsmod.Wrap( - ErrInvalidAuthority, - fmt.Sprintf( - "authority '%s' must be a valid bech32 address, but got error '%v'", - msg.Authority, - err.Error(), - ), - ) - } - return nil -} diff --git a/protocol/x/subaccounts/keeper/transfer.go b/protocol/x/subaccounts/keeper/transfer.go index f4c53fede5..5271d06454 100644 --- a/protocol/x/subaccounts/keeper/transfer.go +++ b/protocol/x/subaccounts/keeper/transfer.go @@ -1,6 +1,7 @@ package keeper import ( + "fmt" "math/big" errorsmod "cosmossdk.io/errors" @@ -521,14 +522,18 @@ func (k Keeper) TransferIsolatedInsuranceFundToCross(ctx sdk.Context, perpetualI return nil } + _, exists := k.assetsKeeper.GetAsset(ctx, assettypes.AssetUsdc.Id) + if !exists { + return fmt.Errorf("USDC asset not found in state") + } + _, coinToTransfer, err := k.assetsKeeper.ConvertAssetToCoin( ctx, assettypes.AssetUsdc.Id, isolatedInsuranceFundBalance, ) if err != nil { - // Panic if USDC does not exist. - panic(err) + return err } isolatedInsuranceFundAddr, err := k.perpetualsKeeper.GetInsuranceFundModuleAddress(ctx, perpetualId) From 2e4e342429154d59e1061c9257ab1a1f70890b96 Mon Sep 17 00:00:00 2001 From: Harry Wray Date: Wed, 20 Nov 2024 14:57:38 -0500 Subject: [PATCH 28/29] Update --- ...pgrade_isolated_perpetual_to_cross_test.go | 28 ++----------------- 1 file changed, 2 insertions(+), 26 deletions(-) diff --git a/protocol/x/listing/keeper/msg_server_upgrade_isolated_perpetual_to_cross_test.go b/protocol/x/listing/keeper/msg_server_upgrade_isolated_perpetual_to_cross_test.go index 2113303bfa..1ee4846391 100644 --- a/protocol/x/listing/keeper/msg_server_upgrade_isolated_perpetual_to_cross_test.go +++ b/protocol/x/listing/keeper/msg_server_upgrade_isolated_perpetual_to_cross_test.go @@ -8,12 +8,10 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/dydxprotocol/v4-chain/protocol/lib" "github.com/dydxprotocol/v4-chain/protocol/mocks" - testapp "github.com/dydxprotocol/v4-chain/protocol/testutil/app" bank_testutil "github.com/dydxprotocol/v4-chain/protocol/testutil/bank" "github.com/dydxprotocol/v4-chain/protocol/testutil/constants" keepertest "github.com/dydxprotocol/v4-chain/protocol/testutil/keeper" asstypes "github.com/dydxprotocol/v4-chain/protocol/x/assets/types" - "github.com/dydxprotocol/v4-chain/protocol/x/listing/keeper" listingkeeper "github.com/dydxprotocol/v4-chain/protocol/x/listing/keeper" types "github.com/dydxprotocol/v4-chain/protocol/x/listing/types" perpetualtypes "github.com/dydxprotocol/v4-chain/protocol/x/perpetuals/types" @@ -22,33 +20,10 @@ import ( ) var ( - // validAuthority is a valid bech32 address. validAuthority = lib.GovModuleAddress.String() ) func TestMsgUpgradeIsolatedPerpetualToCross(t *testing.T) { - tests := map[string]struct { - msg *types.MsgUpgradeIsolatedPerpetualToCross - expectedErr string - }{} - - for name, tc := range tests { - t.Run(name, func(t *testing.T) { - tApp := testapp.NewTestAppBuilder(t).Build() - ctx := tApp.InitChain() - k := tApp.App.ListingKeeper - ms := keeper.NewMsgServerImpl(k) - _, err := ms.UpgradeIsolatedPerpetualToCross(ctx, tc.msg) - if tc.expectedErr == "" { - require.NoError(t, err) - } else { - require.ErrorContains(t, err, tc.expectedErr) - } - }) - } -} - -func TestUpgradeIsolatedPerpetualToCross(t *testing.T) { tests := map[string]struct { msg *types.MsgUpgradeIsolatedPerpetualToCross isolatedInsuranceFundBalance *big.Int @@ -169,7 +144,8 @@ func TestUpgradeIsolatedPerpetualToCross(t *testing.T) { // Create test perpetuals. keepertest.CreateTestPerpetuals(t, ctx, perpetualsKeeper) - var isolatedInsuranceFundAddr, crossInsuranceFundAddr, isolatedCollateralPoolAddr, crossCollateralPoolAddr sdk.AccAddress + var isolatedInsuranceFundAddr, crossInsuranceFundAddr, isolatedCollateralPoolAddr, + crossCollateralPoolAddr sdk.AccAddress if tc.isolatedInsuranceFundBalance != nil { // Get addresses for isolated/cross insurance funds and collateral pools. isolatedInsuranceFundAddr, err = perpetualsKeeper.GetInsuranceFundModuleAddress(ctx, tc.msg.PerpetualId) From b74b8eb49d37a52eeee32d1b8fac2e1c9349e998 Mon Sep 17 00:00:00 2001 From: Harry Wray Date: Thu, 21 Nov 2024 17:13:14 -0500 Subject: [PATCH 29/29] remove errors --- protocol/x/listing/types/errors.go | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/protocol/x/listing/types/errors.go b/protocol/x/listing/types/errors.go index 0633784e88..8213fdd738 100644 --- a/protocol/x/listing/types/errors.go +++ b/protocol/x/listing/types/errors.go @@ -39,16 +39,4 @@ var ( 6, "invalid market map ticker metadata", ) - - ErrInvalidAuthority = errorsmod.Register( - ModuleName, - 7, - "Authority is invalid", - ) - - ErrInvalidPerpetualId = errorsmod.Register( - ModuleName, - 8, - "Invalid perpetual ID", - ) )