diff --git a/indexer/packages/v4-protos/src/codegen/dydxprotocol/vault/tx.rpc.msg.ts b/indexer/packages/v4-protos/src/codegen/dydxprotocol/vault/tx.rpc.msg.ts index a2eeb00760..28b5f9ee7e 100644 --- a/indexer/packages/v4-protos/src/codegen/dydxprotocol/vault/tx.rpc.msg.ts +++ b/indexer/packages/v4-protos/src/codegen/dydxprotocol/vault/tx.rpc.msg.ts @@ -1,6 +1,6 @@ import { Rpc } from "../../helpers"; import * as _m0 from "protobufjs/minimal"; -import { MsgDepositToMegavault, MsgDepositToMegavaultResponse, MsgUpdateDefaultQuotingParams, MsgUpdateDefaultQuotingParamsResponse, MsgUpdateOperatorParams, MsgUpdateOperatorParamsResponse, MsgSetVaultParams, MsgSetVaultParamsResponse, MsgUnlockShares, MsgUnlockSharesResponse, MsgAllocateToVault, MsgAllocateToVaultResponse } from "./tx"; +import { MsgDepositToMegavault, MsgDepositToMegavaultResponse, MsgUpdateDefaultQuotingParams, MsgUpdateDefaultQuotingParamsResponse, MsgUpdateOperatorParams, MsgUpdateOperatorParamsResponse, MsgSetVaultParams, MsgSetVaultParamsResponse, MsgUnlockShares, MsgUnlockSharesResponse, MsgAllocateToVault, MsgAllocateToVaultResponse, MsgRetrieveFromVault, MsgRetrieveFromVaultResponse } from "./tx"; /** Msg defines the Msg service. */ export interface Msg { @@ -24,6 +24,9 @@ export interface Msg { /** AllocateToVault allocates funds from main vault to a vault. */ allocateToVault(request: MsgAllocateToVault): Promise; + /** RetrieveFromVault retrieves funds from a vault to main vault. */ + + retrieveFromVault(request: MsgRetrieveFromVault): Promise; } export class MsgClientImpl implements Msg { private readonly rpc: Rpc; @@ -36,6 +39,7 @@ export class MsgClientImpl implements Msg { this.setVaultParams = this.setVaultParams.bind(this); this.unlockShares = this.unlockShares.bind(this); this.allocateToVault = this.allocateToVault.bind(this); + this.retrieveFromVault = this.retrieveFromVault.bind(this); } depositToMegavault(request: MsgDepositToMegavault): Promise { @@ -74,4 +78,10 @@ export class MsgClientImpl implements Msg { return promise.then(data => MsgAllocateToVaultResponse.decode(new _m0.Reader(data))); } + retrieveFromVault(request: MsgRetrieveFromVault): Promise { + const data = MsgRetrieveFromVault.encode(request).finish(); + const promise = this.rpc.request("dydxprotocol.vault.Msg", "RetrieveFromVault", data); + return promise.then(data => MsgRetrieveFromVaultResponse.decode(new _m0.Reader(data))); + } + } \ No newline at end of file diff --git a/indexer/packages/v4-protos/src/codegen/dydxprotocol/vault/tx.ts b/indexer/packages/v4-protos/src/codegen/dydxprotocol/vault/tx.ts index 4f749db8a7..720d8c3806 100644 --- a/indexer/packages/v4-protos/src/codegen/dydxprotocol/vault/tx.ts +++ b/indexer/packages/v4-protos/src/codegen/dydxprotocol/vault/tx.ts @@ -206,6 +206,34 @@ export interface MsgAllocateToVaultResponse {} /** MsgAllocateToVaultResponse is the Msg/AllocateToVault response type. */ export interface MsgAllocateToVaultResponseSDKType {} +/** MsgRetrieveFromVault is the Msg/RetrieveFromVault request type. */ + +export interface MsgRetrieveFromVault { + authority: string; + /** The vault to retrieve from. */ + + vaultId?: VaultId; + /** Number of quote quantums to retrieve. */ + + quoteQuantums: Uint8Array; +} +/** MsgRetrieveFromVault is the Msg/RetrieveFromVault request type. */ + +export interface MsgRetrieveFromVaultSDKType { + authority: string; + /** The vault to retrieve from. */ + + vault_id?: VaultIdSDKType; + /** Number of quote quantums to retrieve. */ + + quote_quantums: Uint8Array; +} +/** MsgRetrieveFromVaultResponse is the Msg/RetrieveFromVault response type. */ + +export interface MsgRetrieveFromVaultResponse {} +/** MsgRetrieveFromVaultResponse is the Msg/RetrieveFromVault response type. */ + +export interface MsgRetrieveFromVaultResponseSDKType {} function createBaseMsgDepositToMegavault(): MsgDepositToMegavault { return { @@ -836,4 +864,103 @@ export const MsgAllocateToVaultResponse = { return message; } +}; + +function createBaseMsgRetrieveFromVault(): MsgRetrieveFromVault { + return { + authority: "", + vaultId: undefined, + quoteQuantums: new Uint8Array() + }; +} + +export const MsgRetrieveFromVault = { + encode(message: MsgRetrieveFromVault, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { + if (message.authority !== "") { + writer.uint32(10).string(message.authority); + } + + if (message.vaultId !== undefined) { + VaultId.encode(message.vaultId, writer.uint32(18).fork()).ldelim(); + } + + if (message.quoteQuantums.length !== 0) { + writer.uint32(26).bytes(message.quoteQuantums); + } + + return writer; + }, + + decode(input: _m0.Reader | Uint8Array, length?: number): MsgRetrieveFromVault { + const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input); + let end = length === undefined ? reader.len : reader.pos + length; + const message = createBaseMsgRetrieveFromVault(); + + while (reader.pos < end) { + const tag = reader.uint32(); + + switch (tag >>> 3) { + case 1: + message.authority = reader.string(); + break; + + case 2: + message.vaultId = VaultId.decode(reader, reader.uint32()); + break; + + case 3: + message.quoteQuantums = reader.bytes(); + break; + + default: + reader.skipType(tag & 7); + break; + } + } + + return message; + }, + + fromPartial(object: DeepPartial): MsgRetrieveFromVault { + const message = createBaseMsgRetrieveFromVault(); + message.authority = object.authority ?? ""; + message.vaultId = object.vaultId !== undefined && object.vaultId !== null ? VaultId.fromPartial(object.vaultId) : undefined; + message.quoteQuantums = object.quoteQuantums ?? new Uint8Array(); + return message; + } + +}; + +function createBaseMsgRetrieveFromVaultResponse(): MsgRetrieveFromVaultResponse { + return {}; +} + +export const MsgRetrieveFromVaultResponse = { + encode(_: MsgRetrieveFromVaultResponse, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { + return writer; + }, + + decode(input: _m0.Reader | Uint8Array, length?: number): MsgRetrieveFromVaultResponse { + const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input); + let end = length === undefined ? reader.len : reader.pos + length; + const message = createBaseMsgRetrieveFromVaultResponse(); + + while (reader.pos < end) { + const tag = reader.uint32(); + + switch (tag >>> 3) { + default: + reader.skipType(tag & 7); + break; + } + } + + return message; + }, + + fromPartial(_: DeepPartial): MsgRetrieveFromVaultResponse { + const message = createBaseMsgRetrieveFromVaultResponse(); + return message; + } + }; \ No newline at end of file diff --git a/proto/dydxprotocol/vault/tx.proto b/proto/dydxprotocol/vault/tx.proto index 0ad8faa073..b094dae2d2 100644 --- a/proto/dydxprotocol/vault/tx.proto +++ b/proto/dydxprotocol/vault/tx.proto @@ -34,6 +34,10 @@ service Msg { // AllocateToVault allocates funds from main vault to a vault. rpc AllocateToVault(MsgAllocateToVault) returns (MsgAllocateToVaultResponse); + + // RetrieveFromVault retrieves funds from a vault to main vault. + rpc RetrieveFromVault(MsgRetrieveFromVault) + returns (MsgRetrieveFromVaultResponse); } // MsgDepositToMegavault deposits the specified asset from the subaccount to @@ -152,3 +156,23 @@ message MsgAllocateToVault { // MsgAllocateToVaultResponse is the Msg/AllocateToVault response type. message MsgAllocateToVaultResponse {} + +// MsgRetrieveFromVault is the Msg/RetrieveFromVault request type. +message MsgRetrieveFromVault { + // The address that has the authority to retrieve from a vault. + option (cosmos.msg.v1.signer) = "authority"; + string authority = 1 [ (cosmos_proto.scalar) = "cosmos.AddressString" ]; + + // The vault to retrieve from. + VaultId vault_id = 2 [ (gogoproto.nullable) = false ]; + + // Number of quote quantums to retrieve. + bytes quote_quantums = 3 [ + (gogoproto.customtype) = + "github.com/dydxprotocol/v4-chain/protocol/dtypes.SerializableInt", + (gogoproto.nullable) = false + ]; +} + +// MsgRetrieveFromVaultResponse is the Msg/RetrieveFromVault response type. +message MsgRetrieveFromVaultResponse {} diff --git a/protocol/app/msgs/all_msgs.go b/protocol/app/msgs/all_msgs.go index 0743ada948..2be1990bb9 100644 --- a/protocol/app/msgs/all_msgs.go +++ b/protocol/app/msgs/all_msgs.go @@ -253,6 +253,8 @@ var ( "/dydxprotocol.vault.MsgAllocateToVaultResponse": {}, "/dydxprotocol.vault.MsgDepositToMegavault": {}, "/dydxprotocol.vault.MsgDepositToMegavaultResponse": {}, + "/dydxprotocol.vault.MsgRetrieveFromVault": {}, + "/dydxprotocol.vault.MsgRetrieveFromVaultResponse": {}, "/dydxprotocol.vault.MsgSetVaultParams": {}, "/dydxprotocol.vault.MsgSetVaultParamsResponse": {}, "/dydxprotocol.vault.MsgUnlockShares": {}, diff --git a/protocol/app/msgs/normal_msgs.go b/protocol/app/msgs/normal_msgs.go index 5032a41961..daa82e9257 100644 --- a/protocol/app/msgs/normal_msgs.go +++ b/protocol/app/msgs/normal_msgs.go @@ -250,6 +250,8 @@ var ( "/dydxprotocol.vault.MsgAllocateToVaultResponse": nil, "/dydxprotocol.vault.MsgDepositToMegavault": &vault.MsgDepositToMegavault{}, "/dydxprotocol.vault.MsgDepositToMegavaultResponse": nil, + "/dydxprotocol.vault.MsgRetrieveFromVault": &vault.MsgRetrieveFromVault{}, + "/dydxprotocol.vault.MsgRetrieveFromVaultResponse": nil, "/dydxprotocol.vault.MsgSetVaultParams": &vault.MsgSetVaultParams{}, "/dydxprotocol.vault.MsgSetVaultParamsResponse": nil, } diff --git a/protocol/app/msgs/normal_msgs_test.go b/protocol/app/msgs/normal_msgs_test.go index f6bbdc6837..6cf4df6160 100644 --- a/protocol/app/msgs/normal_msgs_test.go +++ b/protocol/app/msgs/normal_msgs_test.go @@ -151,6 +151,8 @@ func TestNormalMsgs_Key(t *testing.T) { "/dydxprotocol.vault.MsgAllocateToVaultResponse", "/dydxprotocol.vault.MsgDepositToMegavault", "/dydxprotocol.vault.MsgDepositToMegavaultResponse", + "/dydxprotocol.vault.MsgRetrieveFromVault", + "/dydxprotocol.vault.MsgRetrieveFromVaultResponse", "/dydxprotocol.vault.MsgSetVaultParams", "/dydxprotocol.vault.MsgSetVaultParamsResponse", diff --git a/protocol/x/vault/client/cli/tx.go b/protocol/x/vault/client/cli/tx.go index 392f8347f2..573ef5034c 100644 --- a/protocol/x/vault/client/cli/tx.go +++ b/protocol/x/vault/client/cli/tx.go @@ -29,6 +29,7 @@ func GetTxCmd() *cobra.Command { cmd.AddCommand(CmdDepositToMegavault()) cmd.AddCommand(CmdSetVaultParams()) cmd.AddCommand(CmdAllocateToVault()) + cmd.AddCommand(CmdRetrieveFromVault()) return cmd } @@ -192,3 +193,53 @@ func CmdAllocateToVault() *cobra.Command { return cmd } + +func CmdRetrieveFromVault() *cobra.Command { + cmd := &cobra.Command{ + Use: "retrieve-from-vault [authority] [vault_type] [vault_number] [quote_quantums]", + Short: "Broadcast message RetrieveFromVault", + Args: cobra.ExactArgs(4), + RunE: func(cmd *cobra.Command, args []string) (err error) { + // Parse vault type. + vaultType, err := GetVaultTypeFromString(args[1]) + if err != nil { + return err + } + + // Parse vault number. + vaultNumber, err := strconv.ParseUint(args[2], 10, 32) + if err != nil { + return err + } + + // Parse quantums. + quantums, err := cast.ToUint64E(args[3]) + if err != nil { + return err + } + + clientCtx, err := client.GetClientTxContext(cmd) + if err != nil { + return err + } + + // Create MsgRetrieveFromVault. + msg := &types.MsgRetrieveFromVault{ + Authority: args[0], + VaultId: types.VaultId{ + Type: vaultType, + Number: uint32(vaultNumber), + }, + QuoteQuantums: dtypes.NewIntFromUint64(quantums), + } + + // Broadcast or generate the transaction. + return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg) + }, + } + + // Add the necessary flags. + flags.AddTxFlagsToCmd(cmd) + + return cmd +} diff --git a/protocol/x/vault/keeper/msg_server_retrieve_from_vault.go b/protocol/x/vault/keeper/msg_server_retrieve_from_vault.go new file mode 100644 index 0000000000..d4586eda70 --- /dev/null +++ b/protocol/x/vault/keeper/msg_server_retrieve_from_vault.go @@ -0,0 +1,47 @@ +package keeper + +import ( + "context" + + errorsmod "cosmossdk.io/errors" + + "github.com/dydxprotocol/v4-chain/protocol/lib" + assetstypes "github.com/dydxprotocol/v4-chain/protocol/x/assets/types" + "github.com/dydxprotocol/v4-chain/protocol/x/vault/types" +) + +// RetrieveFromVault retrieves funds from a vault to main vault. +func (k msgServer) RetrieveFromVault( + goCtx context.Context, + msg *types.MsgRetrieveFromVault, +) (*types.MsgRetrieveFromVaultResponse, error) { + ctx := lib.UnwrapSDKContext(goCtx, types.ModuleName) + operator := k.GetOperatorParams(ctx).Operator + + // Check if authority is valid (must be a module authority or operator). + if !k.HasAuthority(msg.Authority) && msg.Authority != operator { + return nil, errorsmod.Wrapf( + types.ErrInvalidAuthority, + "invalid authority %s", + msg.Authority, + ) + } + + // Check if vault exists. + if _, exists := k.Keeper.GetVaultParams(ctx, msg.VaultId); !exists { + return nil, types.ErrVaultParamsNotFound + } + + // Transfer from specified vault to main vault. + if err := k.Keeper.subaccountsKeeper.TransferFundsFromSubaccountToSubaccount( + ctx, + *msg.VaultId.ToSubaccountId(), + types.MegavaultMainSubaccount, + assetstypes.AssetUsdc.Id, + msg.QuoteQuantums.BigInt(), + ); err != nil { + return nil, err + } + + return &types.MsgRetrieveFromVaultResponse{}, nil +} diff --git a/protocol/x/vault/keeper/msg_server_retrieve_from_vault_test.go b/protocol/x/vault/keeper/msg_server_retrieve_from_vault_test.go new file mode 100644 index 0000000000..a5082e55f6 --- /dev/null +++ b/protocol/x/vault/keeper/msg_server_retrieve_from_vault_test.go @@ -0,0 +1,253 @@ +package keeper_test + +import ( + "testing" + + "github.com/cometbft/cometbft/types" + "github.com/stretchr/testify/require" + + "github.com/dydxprotocol/v4-chain/protocol/dtypes" + "github.com/dydxprotocol/v4-chain/protocol/lib" + testapp "github.com/dydxprotocol/v4-chain/protocol/testutil/app" + "github.com/dydxprotocol/v4-chain/protocol/testutil/constants" + assetstypes "github.com/dydxprotocol/v4-chain/protocol/x/assets/types" + satypes "github.com/dydxprotocol/v4-chain/protocol/x/subaccounts/types" + "github.com/dydxprotocol/v4-chain/protocol/x/vault/keeper" + vaulttypes "github.com/dydxprotocol/v4-chain/protocol/x/vault/types" +) + +func TestMsgRetrieveFromVault(t *testing.T) { + tests := map[string]struct { + // Operator. + operator string + // Number of quote quantums main vault has. + mainVaultQuantums uint64 + // Number of quote quantums sub vault has. + subVaultQuantums uint64 + // Number of base quantums of sub vault's position. + subVaultPositionBaseQuantums int64 + // Existing vault params, if any. + vaultParams *vaulttypes.VaultParams + // Msg. + msg *vaulttypes.MsgRetrieveFromVault + // Expected error. + expectedErr string + }{ + "Success - Gov Authority, Retrieve 50 From Vault Clob 0": { + operator: constants.AliceAccAddress.String(), + mainVaultQuantums: 100, + subVaultQuantums: 200, + vaultParams: &vaulttypes.VaultParams{ + Status: vaulttypes.VaultStatus_VAULT_STATUS_QUOTING, + }, + msg: &vaulttypes.MsgRetrieveFromVault{ + Authority: lib.GovModuleAddress.String(), + VaultId: constants.Vault_Clob0, + QuoteQuantums: dtypes.NewInt(50), + }, + }, + "Success - Operator Authority, Retrieve all from Vault Clob 1": { + operator: constants.AliceAccAddress.String(), + mainVaultQuantums: 0, + subVaultQuantums: 3_500_000, + vaultParams: &vaulttypes.VaultParams{ + Status: vaulttypes.VaultStatus_VAULT_STATUS_CLOSE_ONLY, + }, + msg: &vaulttypes.MsgRetrieveFromVault{ + Authority: constants.AliceAccAddress.String(), + VaultId: constants.Vault_Clob1, + QuoteQuantums: dtypes.NewInt(3_500_000), + }, + }, + "Failure - Insufficient quantums to retrieve from Vault Clob 0 with no open position": { + operator: constants.AliceAccAddress.String(), + mainVaultQuantums: 0, + subVaultQuantums: 26, + vaultParams: &vaulttypes.VaultParams{ + Status: vaulttypes.VaultStatus_VAULT_STATUS_QUOTING, + }, + msg: &vaulttypes.MsgRetrieveFromVault{ + Authority: constants.AliceAccAddress.String(), + VaultId: constants.Vault_Clob0, + QuoteQuantums: dtypes.NewInt(27), + }, + expectedErr: "failed to apply subaccount updates", + }, + "Success - Retrieval from vault with open position exactly meets initial margin requirement": { + operator: constants.AliceAccAddress.String(), + mainVaultQuantums: 0, + subVaultQuantums: 3_500_000, + subVaultPositionBaseQuantums: -1_000_000, + // open_notional = -1_000_000 * 10^-9 * 1_500 * 10^6 = = -1_500_000 + // equity = 3_500_000 - 1_500_000 = 2_000_000 + // initial_margin_requirement = position_size * imf + // = |-1_500_000| * 0.05 = 75_000 + vaultParams: &vaulttypes.VaultParams{ + Status: vaulttypes.VaultStatus_VAULT_STATUS_QUOTING, + }, + msg: &vaulttypes.MsgRetrieveFromVault{ + Authority: constants.AliceAccAddress.String(), + VaultId: constants.Vault_Clob1, + QuoteQuantums: dtypes.NewInt(1_925_000), + }, + }, + "Failure - Retrieval from vault with open position would result in undercollateralization": { + operator: constants.AliceAccAddress.String(), + mainVaultQuantums: 0, + subVaultQuantums: 3_500_000, + subVaultPositionBaseQuantums: -1_000_000, + // open_notional = -1_000_000 * 10^-9 * 1_500 * 10^6 = = -1_500_000 + // equity = 3_500_000 - 1_500_000 = 2_000_000 + // initial_margin_requirement = position_size * imf + // = |-1_500_000| * 0.05 = 75_000 + vaultParams: &vaulttypes.VaultParams{ + Status: vaulttypes.VaultStatus_VAULT_STATUS_QUOTING, + }, + msg: &vaulttypes.MsgRetrieveFromVault{ + Authority: constants.AliceAccAddress.String(), + VaultId: constants.Vault_Clob1, + QuoteQuantums: dtypes.NewInt(1_925_001), + }, + expectedErr: satypes.NewlyUndercollateralized.String(), + }, + "Failure - Retrieve from non-existent vault": { + operator: constants.AliceAccAddress.String(), + mainVaultQuantums: 0, + subVaultQuantums: 15, + msg: &vaulttypes.MsgRetrieveFromVault{ + Authority: constants.AliceAccAddress.String(), + VaultId: constants.Vault_Clob0, + QuoteQuantums: dtypes.NewInt(10), + }, + expectedErr: vaulttypes.ErrVaultParamsNotFound.Error(), + }, + "Failure - Invalid Authority": { + operator: constants.BobAccAddress.String(), + mainVaultQuantums: 100, + subVaultQuantums: 15, + msg: &vaulttypes.MsgRetrieveFromVault{ + Authority: constants.AliceAccAddress.String(), + VaultId: constants.Vault_Clob1, + QuoteQuantums: dtypes.NewInt(10), + }, + expectedErr: vaulttypes.ErrInvalidAuthority.Error(), + }, + "Failure - Empty Authority": { + operator: constants.BobAccAddress.String(), + mainVaultQuantums: 100, + subVaultQuantums: 15, + msg: &vaulttypes.MsgRetrieveFromVault{ + Authority: "", + VaultId: constants.Vault_Clob1, + QuoteQuantums: dtypes.NewInt(10), + }, + expectedErr: vaulttypes.ErrInvalidAuthority.Error(), + }, + } + + for name, tc := range tests { + t.Run(name, func(t *testing.T) { + tApp := testapp.NewTestAppBuilder(t).WithGenesisDocFn(func() (genesis types.GenesisDoc) { + genesis = testapp.DefaultGenesis() + // Set megavault operator. + testapp.UpdateGenesisDocWithAppStateForModule( + &genesis, + func(genesisState *vaulttypes.GenesisState) { + genesisState.OperatorParams = vaulttypes.OperatorParams{ + Operator: tc.operator, + } + if tc.vaultParams != nil { + genesisState.Vaults = []vaulttypes.Vault{ + { + VaultId: tc.msg.VaultId, + VaultParams: *tc.vaultParams, + }, + } + } + }, + ) + // Set balances of main vault and sub vault. + testapp.UpdateGenesisDocWithAppStateForModule( + &genesis, + func(genesisState *satypes.GenesisState) { + genesisState.Subaccounts = []satypes.Subaccount{ + { + Id: &vaulttypes.MegavaultMainSubaccount, + AssetPositions: []*satypes.AssetPosition{ + { + AssetId: assetstypes.AssetUsdc.Id, + Quantums: dtypes.NewIntFromUint64(tc.mainVaultQuantums), + }, + }, + }, + { + Id: tc.msg.VaultId.ToSubaccountId(), + AssetPositions: []*satypes.AssetPosition{ + { + AssetId: assetstypes.AssetUsdc.Id, + Quantums: dtypes.NewIntFromUint64(tc.subVaultQuantums), + }, + }, + PerpetualPositions: []*satypes.PerpetualPosition{ + { + PerpetualId: tc.msg.VaultId.Number, + Quantums: dtypes.NewInt(tc.subVaultPositionBaseQuantums), + }, + }, + }, + } + }, + ) + return genesis + }).Build() + ctx := tApp.InitChain() + k := tApp.App.VaultKeeper + ms := keeper.NewMsgServerImpl(k) + + // Retrieve from vault. + _, err := ms.RetrieveFromVault(ctx, tc.msg) + + // Check expectations. + mainVault := tApp.App.SubaccountsKeeper.GetSubaccount(ctx, vaulttypes.MegavaultMainSubaccount) + subVault := tApp.App.SubaccountsKeeper.GetSubaccount(ctx, *tc.msg.VaultId.ToSubaccountId()) + + require.Len(t, mainVault.AssetPositions, 1) + if tc.expectedErr != "" { + require.ErrorContains(t, err, tc.expectedErr) + + // Verify that main vault and sub vault balances are unchanged. + require.Len(t, subVault.AssetPositions, 1) + require.Equal( + t, + tc.mainVaultQuantums, + mainVault.AssetPositions[0].Quantums.BigInt().Uint64(), + ) + require.Equal( + t, + tc.subVaultQuantums, + subVault.AssetPositions[0].Quantums.BigInt().Uint64(), + ) + } else { + require.NoError(t, err) + + // Verify that main vault and sub vault balances are updated. + expectedSubVaultQuantums := tc.subVaultQuantums - tc.msg.QuoteQuantums.BigInt().Uint64() + if expectedSubVaultQuantums == 0 { + require.Len(t, subVault.AssetPositions, 0) + } else { + require.Len(t, subVault.AssetPositions, 1) + require.Equal( + t, + expectedSubVaultQuantums, + subVault.AssetPositions[0].Quantums.BigInt().Uint64(), + ) + } + require.Equal( + t, + tc.mainVaultQuantums+tc.msg.QuoteQuantums.BigInt().Uint64(), + mainVault.AssetPositions[0].Quantums.BigInt().Uint64(), + ) + } + }) + } +} diff --git a/protocol/x/vault/types/tx.pb.go b/protocol/x/vault/types/tx.pb.go index f89fb01e87..0324697e91 100644 --- a/protocol/x/vault/types/tx.pb.go +++ b/protocol/x/vault/types/tx.pb.go @@ -661,6 +661,99 @@ func (m *MsgAllocateToVaultResponse) XXX_DiscardUnknown() { var xxx_messageInfo_MsgAllocateToVaultResponse proto.InternalMessageInfo +// MsgRetrieveFromVault is the Msg/RetrieveFromVault request type. +type MsgRetrieveFromVault struct { + Authority string `protobuf:"bytes,1,opt,name=authority,proto3" json:"authority,omitempty"` + // The vault to retrieve from. + VaultId VaultId `protobuf:"bytes,2,opt,name=vault_id,json=vaultId,proto3" json:"vault_id"` + // Number of quote quantums to retrieve. + QuoteQuantums github_com_dydxprotocol_v4_chain_protocol_dtypes.SerializableInt `protobuf:"bytes,3,opt,name=quote_quantums,json=quoteQuantums,proto3,customtype=github.com/dydxprotocol/v4-chain/protocol/dtypes.SerializableInt" json:"quote_quantums"` +} + +func (m *MsgRetrieveFromVault) Reset() { *m = MsgRetrieveFromVault{} } +func (m *MsgRetrieveFromVault) String() string { return proto.CompactTextString(m) } +func (*MsgRetrieveFromVault) ProtoMessage() {} +func (*MsgRetrieveFromVault) Descriptor() ([]byte, []int) { + return fileDescriptor_ced574c6017ce006, []int{13} +} +func (m *MsgRetrieveFromVault) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgRetrieveFromVault) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgRetrieveFromVault.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 *MsgRetrieveFromVault) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgRetrieveFromVault.Merge(m, src) +} +func (m *MsgRetrieveFromVault) XXX_Size() int { + return m.Size() +} +func (m *MsgRetrieveFromVault) XXX_DiscardUnknown() { + xxx_messageInfo_MsgRetrieveFromVault.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgRetrieveFromVault proto.InternalMessageInfo + +func (m *MsgRetrieveFromVault) GetAuthority() string { + if m != nil { + return m.Authority + } + return "" +} + +func (m *MsgRetrieveFromVault) GetVaultId() VaultId { + if m != nil { + return m.VaultId + } + return VaultId{} +} + +// MsgRetrieveFromVaultResponse is the Msg/RetrieveFromVault response type. +type MsgRetrieveFromVaultResponse struct { +} + +func (m *MsgRetrieveFromVaultResponse) Reset() { *m = MsgRetrieveFromVaultResponse{} } +func (m *MsgRetrieveFromVaultResponse) String() string { return proto.CompactTextString(m) } +func (*MsgRetrieveFromVaultResponse) ProtoMessage() {} +func (*MsgRetrieveFromVaultResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_ced574c6017ce006, []int{14} +} +func (m *MsgRetrieveFromVaultResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgRetrieveFromVaultResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgRetrieveFromVaultResponse.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 *MsgRetrieveFromVaultResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgRetrieveFromVaultResponse.Merge(m, src) +} +func (m *MsgRetrieveFromVaultResponse) XXX_Size() int { + return m.Size() +} +func (m *MsgRetrieveFromVaultResponse) XXX_DiscardUnknown() { + xxx_messageInfo_MsgRetrieveFromVaultResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgRetrieveFromVaultResponse proto.InternalMessageInfo + func init() { proto.RegisterType((*MsgDepositToMegavault)(nil), "dydxprotocol.vault.MsgDepositToMegavault") proto.RegisterType((*MsgDepositToMegavaultResponse)(nil), "dydxprotocol.vault.MsgDepositToMegavaultResponse") @@ -675,65 +768,70 @@ func init() { proto.RegisterType((*MsgUpdateOperatorParamsResponse)(nil), "dydxprotocol.vault.MsgUpdateOperatorParamsResponse") proto.RegisterType((*MsgAllocateToVault)(nil), "dydxprotocol.vault.MsgAllocateToVault") proto.RegisterType((*MsgAllocateToVaultResponse)(nil), "dydxprotocol.vault.MsgAllocateToVaultResponse") + proto.RegisterType((*MsgRetrieveFromVault)(nil), "dydxprotocol.vault.MsgRetrieveFromVault") + proto.RegisterType((*MsgRetrieveFromVaultResponse)(nil), "dydxprotocol.vault.MsgRetrieveFromVaultResponse") } func init() { proto.RegisterFile("dydxprotocol/vault/tx.proto", fileDescriptor_ced574c6017ce006) } var fileDescriptor_ced574c6017ce006 = []byte{ - // 834 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xc4, 0x56, 0x4f, 0x4f, 0x13, 0x4d, - 0x18, 0xef, 0xc2, 0xfb, 0xf2, 0xbe, 0x0c, 0x6d, 0xd1, 0x4d, 0x95, 0xb2, 0x48, 0x0b, 0x25, 0x20, - 0x48, 0xd8, 0x06, 0x30, 0xfe, 0x21, 0x1e, 0xa0, 0xe1, 0x00, 0xd1, 0xaa,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0xe6, 0x0c, 0xd6, 0x86, 0xaa, 0x9a, 0x88, - 0x90, 0x3c, 0x35, 0x75, 0x43, 0xcb, 0xb5, 0xa0, 0xe2, 0x53, 0x70, 0x59, 0xe5, 0xf5, 0x0a, 0xfb, - 0xbc, 0x60, 0x81, 0x8f, 0x09, 0x73, 0x74, 0x64, 0x65, 0x3a, 0x88, 0xac, 0xa7, 0xb5, 0x43, 0x38, - 0xa6, 0x06, 0xd0, 0x5a, 0x8b, 0xda, 0xbe, 0xb5, 0xda, 0xa5, 0xae, 0x82, 0xd9, 0x9e, 0x3a, 0x9a, - 0xde, 0xa5, 0x1a, 0x02, 0xb8, 0x98, 0x25, 0x5a, 0x1e, 0xd1, 0xc7, 0x36, 0xe8, 0x9c, 0x2a, 0xef, - 0x80, 0xff, 0x19, 0x73, 0x7b, 0xee, 0xb8, 0xae, 0x89, 0x20, 0x5d, 0xac, 0xd5, 0xb6, 0xea, 0x28, - 0xfa, 0xaf, 0xc6, 0x5f, 0xc5, 0x2d, 0x10, 0xe6, 0xd9, 0x8e, 0x33, 0x83, 0xac, 0x42, 0xb2, 0x6b, - 0x05, 0x8f, 0x2f, 0x23, 0xb5, 0x56, 0xa8, 0xc3, 0x8e, 0x09, 0x30, 0xde, 0x21, 0xd2, 0xb5, 0xe0, - 0x15, 0x18, 0xb5, 0xbd, 0x32, 0xca, 0x58, 0x79, 0xce, 0xe7, 0xe0, 0xcc, 0xfa, 0x67, 0x40, 0x04, - 0xbf, 0x30, 0x90, 0x59, 0x80, 0x1c, 0xc1, 0x4c, 0x18, 0xce, 0x85, 0x59, 0xd0, 0xc9, 0xea, 0x20, - 0xa7, 0x81, 0x31, 0x5f, 0x7f, 0x77, 0xb2, 0xef, 0x81, 0x51, 0x8b, 0xc5, 0xcf, 0x34, 0xdb, 0xd1, - 0x66, 0xae, 0x33, 0xdd, 0xef, 0x05, 0xae, 0x94, 0x4d, 0xc5, 0x39, 0x77, 0xfa, 0x16, 0x18, 0xf2, - 0xcc, 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xee, 0x0f, 0xd7, 0x6c, 0x95, 0xd9, 0x39, 0x3c, - 0x49, 0x08, 0x47, 0x27, 0x09, 0xe1, 0xc7, 0x49, 0x42, 0x78, 0xd7, 0x48, 0x84, 0x8e, 0x1a, 0x89, - 0xd0, 0xb7, 0x46, 0x22, 0xf4, 0xe4, 0x66, 0xff, 0x07, 0xaa, 0xde, 0xfc, 0xe5, 0x6a, 0x9f, 0xab, - 0xe2, 0x10, 0x8b, 0xaf, 0xfe, 0x0e, 0x00, 0x00, 0xff, 0xff, 0x36, 0x56, 0xc3, 0xbf, 0xdc, 0x0a, - 0x00, 0x00, + // 881 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe4, 0x57, 0xcf, 0x4f, 0x1b, 0x47, + 0x14, 0xf6, 0x42, 0x45, 0xcb, 0x60, 0x9b, 0xb2, 0x72, 0x8b, 0x59, 0x60, 0x0d, 0x46, 0x50, 0x28, + 0x62, 0x5d, 0xa0, 0xea, 0x0f, 0xd4, 0x03, 0x58, 0xa8, 0x02, 0xb5, 0x6e, 0x8b, 0x4d, 0x7b, 0xa8, + 0x54, 0xb9, 0xeb, 0xdd, 0x61, 0xbd, 0xaa, 0x77, 0xc7, 0xec, 0xcc, 0xba, 0xa6, 0x87, 0x1e, 0x72, + 0x4c, 0x14, 0x29, 0x97, 0xfc, 0x05, 0x91, 0x72, 0xce, 0x21, 0x7f, 0x43, 0xc4, 0x11, 0xe5, 0x14, + 0xe5, 0x80, 0x22, 0x7c, 0x88, 0xf2, 0x5f, 0x44, 0x3b, 0xb3, 0x5e, 0x7b, 0x7f, 0x59, 0x06, 0x14, + 0xe5, 0x90, 0x0b, 0xec, 0xbe, 0xf9, 0xde, 0x7b, 0xdf, 0xf7, 0xed, 0x9b, 0x19, 0x19, 0xcc, 0xaa, + 0x67, 0x6a, 0xbb, 0x69, 0x21, 0x82, 0x14, 0xd4, 0x28, 0xb4, 0x64, 0xbb, 0x41, 0x0a, 0xa4, 0x2d, + 0xd1, 0x08, 0xcf, 0xf7, 0x2f, 0x4a, 0x74, 0x51, 0x98, 0x51, 0x10, 0x36, 0x10, 0xae, 0xd2, 0x70, + 0x81, 0xbd, 0x30, 0xb8, 0x30, 0xcd, 0xde, 0x0a, 0x06, 0xd6, 0x0a, 0xad, 0x4d, 0xe7, 0x9f, 0xbb, + 0xb0, 0xe6, 0x6b, 0x82, 0xed, 0x9a, 0xac, 0x28, 0xc8, 0x36, 0x09, 0xee, 0x7b, 0x76, 0xa1, 0xb9, + 0x08, 0x3e, 0x4d, 0xd9, 0x92, 0x8d, 0x6e, 0x13, 0x31, 0x02, 0x80, 0xeb, 0xb2, 0x05, 0x07, 0xac, + 0xd3, 0xbf, 0xee, 0x7a, 0x46, 0x43, 0x1a, 0x62, 0xe4, 0x9d, 0x27, 0x16, 0xcd, 0xbf, 0xe1, 0xc0, + 0x67, 0x25, 0xac, 0xed, 0xc3, 0x26, 0xc2, 0x3a, 0x39, 0x46, 0x25, 0xa8, 0xc9, 0x34, 0x8b, 0xff, + 0x09, 0xa4, 0x7a, 0x24, 0xab, 0xba, 0x9a, 0xe5, 0x16, 0xb8, 0xd5, 0x89, 0xad, 0x15, 0xc9, 0xe7, + 0x4d, 0x9f, 0x26, 0xa9, 0xe2, 0x3d, 0x1f, 0xaa, 0xe5, 0x24, 0xee, 0x7b, 0xe3, 0x11, 0x48, 0x9f, + 0xda, 0x88, 0xc0, 0xea, 0xa9, 0x2d, 0x9b, 0xc4, 0x36, 0x70, 0x76, 0x64, 0x81, 0x5b, 0x4d, 0x16, + 0x0f, 0xce, 0x2f, 0x73, 0x89, 0x97, 0x97, 0xb9, 0x5d, 0x4d, 0x27, 0x75, 0xbb, 0x26, 0x29, 0xc8, + 0x28, 0xf8, 0x75, 0x7c, 0xbd, 0xa1, 0xd4, 0x65, 0xdd, 0x2c, 0x78, 0x11, 0x95, 0x9c, 0x35, 0x21, + 0x96, 0x2a, 0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db, 0xe1, 0xf7, 0x70, 0xbb, 0xfb, 0xd3, 0xc2, 0xd9, 0xca, 0xb5, + 0x31, 0x1a, 0xdf, 0x7e, 0x1b, 0x00, 0x00, 0xff, 0xff, 0xf1, 0xc9, 0xfd, 0x40, 0x7d, 0x0c, 0x00, + 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -761,6 +859,8 @@ type MsgClient interface { UnlockShares(ctx context.Context, in *MsgUnlockShares, opts ...grpc.CallOption) (*MsgUnlockSharesResponse, error) // AllocateToVault allocates funds from main vault to a vault. AllocateToVault(ctx context.Context, in *MsgAllocateToVault, opts ...grpc.CallOption) (*MsgAllocateToVaultResponse, error) + // RetrieveFromVault retrieves funds from a vault to main vault. + RetrieveFromVault(ctx context.Context, in *MsgRetrieveFromVault, opts ...grpc.CallOption) (*MsgRetrieveFromVaultResponse, error) } type msgClient struct { @@ -825,6 +925,15 @@ func (c *msgClient) AllocateToVault(ctx context.Context, in *MsgAllocateToVault, return out, nil } +func (c *msgClient) RetrieveFromVault(ctx context.Context, in *MsgRetrieveFromVault, opts ...grpc.CallOption) (*MsgRetrieveFromVaultResponse, error) { + out := new(MsgRetrieveFromVaultResponse) + err := c.cc.Invoke(ctx, "/dydxprotocol.vault.Msg/RetrieveFromVault", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + // MsgServer is the server API for Msg service. type MsgServer interface { // DepositToMegavault deposits funds into megavault. @@ -840,6 +949,8 @@ type MsgServer interface { UnlockShares(context.Context, *MsgUnlockShares) (*MsgUnlockSharesResponse, error) // AllocateToVault allocates funds from main vault to a vault. AllocateToVault(context.Context, *MsgAllocateToVault) (*MsgAllocateToVaultResponse, error) + // RetrieveFromVault retrieves funds from a vault to main vault. + RetrieveFromVault(context.Context, *MsgRetrieveFromVault) (*MsgRetrieveFromVaultResponse, error) } // UnimplementedMsgServer can be embedded to have forward compatible implementations. @@ -864,6 +975,9 @@ func (*UnimplementedMsgServer) UnlockShares(ctx context.Context, req *MsgUnlockS func (*UnimplementedMsgServer) AllocateToVault(ctx context.Context, req *MsgAllocateToVault) (*MsgAllocateToVaultResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method AllocateToVault not implemented") } +func (*UnimplementedMsgServer) RetrieveFromVault(ctx context.Context, req *MsgRetrieveFromVault) (*MsgRetrieveFromVaultResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method RetrieveFromVault not implemented") +} func RegisterMsgServer(s grpc1.Server, srv MsgServer) { s.RegisterService(&_Msg_serviceDesc, srv) @@ -977,6 +1091,24 @@ func _Msg_AllocateToVault_Handler(srv interface{}, ctx context.Context, dec func return interceptor(ctx, in, info, handler) } +func _Msg_RetrieveFromVault_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(MsgRetrieveFromVault) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(MsgServer).RetrieveFromVault(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/dydxprotocol.vault.Msg/RetrieveFromVault", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(MsgServer).RetrieveFromVault(ctx, req.(*MsgRetrieveFromVault)) + } + return interceptor(ctx, in, info, handler) +} + var _Msg_serviceDesc = grpc.ServiceDesc{ ServiceName: "dydxprotocol.vault.Msg", HandlerType: (*MsgServer)(nil), @@ -1005,6 +1137,10 @@ var _Msg_serviceDesc = grpc.ServiceDesc{ MethodName: "AllocateToVault", Handler: _Msg_AllocateToVault_Handler, }, + { + MethodName: "RetrieveFromVault", + Handler: _Msg_RetrieveFromVault_Handler, + }, }, Streams: []grpc.StreamDesc{}, Metadata: "dydxprotocol/vault/tx.proto", @@ -1470,6 +1606,79 @@ func (m *MsgAllocateToVaultResponse) MarshalToSizedBuffer(dAtA []byte) (int, err return len(dAtA) - i, nil } +func (m *MsgRetrieveFromVault) 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 *MsgRetrieveFromVault) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgRetrieveFromVault) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + { + size := m.QuoteQuantums.Size() + i -= size + if _, err := m.QuoteQuantums.MarshalTo(dAtA[i:]); err != nil { + return 0, err + } + i = encodeVarintTx(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x1a + { + size, err := m.VaultId.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintTx(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + 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 *MsgRetrieveFromVaultResponse) 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 *MsgRetrieveFromVaultResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgRetrieveFromVaultResponse) 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 @@ -1650,6 +1859,32 @@ func (m *MsgAllocateToVaultResponse) Size() (n int) { return n } +func (m *MsgRetrieveFromVault) 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)) + } + l = m.VaultId.Size() + n += 1 + l + sovTx(uint64(l)) + l = m.QuoteQuantums.Size() + n += 1 + l + sovTx(uint64(l)) + return n +} + +func (m *MsgRetrieveFromVaultResponse) 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 } @@ -2896,6 +3131,204 @@ func (m *MsgAllocateToVaultResponse) Unmarshal(dAtA []byte) error { } return nil } +func (m *MsgRetrieveFromVault) 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: MsgRetrieveFromVault: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgRetrieveFromVault: 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 != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field VaultId", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.VaultId.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field QuoteQuantums", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.QuoteQuantums.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + 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 *MsgRetrieveFromVaultResponse) 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: MsgRetrieveFromVaultResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgRetrieveFromVaultResponse: 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