Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add megavault withdrawal msg #2288

Merged
merged 6 commits into from
Sep 19, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import { Rpc } from "../../helpers";
import * as _m0 from "protobufjs/minimal";
import { MsgDepositToMegavault, MsgDepositToMegavaultResponse, MsgUpdateDefaultQuotingParams, MsgUpdateDefaultQuotingParamsResponse, MsgUpdateOperatorParams, MsgUpdateOperatorParamsResponse, MsgSetVaultParams, MsgSetVaultParamsResponse, MsgUnlockShares, MsgUnlockSharesResponse, MsgAllocateToVault, MsgAllocateToVaultResponse, MsgRetrieveFromVault, MsgRetrieveFromVaultResponse } from "./tx";
import { MsgDepositToMegavault, MsgDepositToMegavaultResponse, MsgWithdrawFromMegavault, MsgWithdrawFromMegavaultResponse, MsgUpdateDefaultQuotingParams, MsgUpdateDefaultQuotingParamsResponse, MsgUpdateOperatorParams, MsgUpdateOperatorParamsResponse, MsgSetVaultParams, MsgSetVaultParamsResponse, MsgUnlockShares, MsgUnlockSharesResponse, MsgAllocateToVault, MsgAllocateToVaultResponse, MsgRetrieveFromVault, MsgRetrieveFromVaultResponse } from "./tx";
/** Msg defines the Msg service. */

export interface Msg {
/** DepositToMegavault deposits funds into megavault. */
depositToMegavault(request: MsgDepositToMegavault): Promise<MsgDepositToMegavaultResponse>;
/** WithdrawFromMegavault withdraws shares from megavault. */

withdrawFromMegavault(request: MsgWithdrawFromMegavault): Promise<MsgWithdrawFromMegavaultResponse>;
/** UpdateDefaultQuotingParams updates the default quoting params in state. */

updateDefaultQuotingParams(request: MsgUpdateDefaultQuotingParams): Promise<MsgUpdateDefaultQuotingParamsResponse>;
Expand Down Expand Up @@ -34,6 +37,7 @@ export class MsgClientImpl implements Msg {
constructor(rpc: Rpc) {
this.rpc = rpc;
this.depositToMegavault = this.depositToMegavault.bind(this);
this.withdrawFromMegavault = this.withdrawFromMegavault.bind(this);
this.updateDefaultQuotingParams = this.updateDefaultQuotingParams.bind(this);
this.updateOperatorParams = this.updateOperatorParams.bind(this);
this.setVaultParams = this.setVaultParams.bind(this);
Expand All @@ -48,6 +52,12 @@ export class MsgClientImpl implements Msg {
return promise.then(data => MsgDepositToMegavaultResponse.decode(new _m0.Reader(data)));
}

withdrawFromMegavault(request: MsgWithdrawFromMegavault): Promise<MsgWithdrawFromMegavaultResponse> {
const data = MsgWithdrawFromMegavault.encode(request).finish();
const promise = this.rpc.request("dydxprotocol.vault.Msg", "WithdrawFromMegavault", data);
return promise.then(data => MsgWithdrawFromMegavaultResponse.decode(new _m0.Reader(data)));
}

updateDefaultQuotingParams(request: MsgUpdateDefaultQuotingParams): Promise<MsgUpdateDefaultQuotingParamsResponse> {
const data = MsgUpdateDefaultQuotingParams.encode(request).finish();
const promise = this.rpc.request("dydxprotocol.vault.Msg", "UpdateDefaultQuotingParams", data);
Expand Down
166 changes: 165 additions & 1 deletion indexer/packages/v4-protos/src/codegen/dydxprotocol/vault/tx.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { SubaccountId, SubaccountIdSDKType } from "../subaccounts/subaccount";
import { NumShares, NumSharesSDKType } from "./share";
import { QuotingParams, QuotingParamsSDKType, OperatorParams, OperatorParamsSDKType, VaultParams, VaultParamsSDKType, Params, ParamsSDKType } from "./params";
import { VaultId, VaultIdSDKType } from "./vault";
import { NumShares, NumSharesSDKType } from "./share";
import * as _m0 from "protobufjs/minimal";
import { DeepPartial } from "../../helpers";
/**
Expand Down Expand Up @@ -40,6 +40,60 @@ export interface MsgDepositToMegavaultResponseSDKType {
/** The number of shares minted from the deposit. */
minted_shares?: NumSharesSDKType;
}
/**
* MsgWithdrawFromMegavault withdraws the specified shares from megavault to
* a subaccount.
*/

export interface MsgWithdrawFromMegavault {
/** The subaccount to withdraw to. */
subaccountId?: SubaccountId;
/** Number of shares to withdraw. */

shares?: NumShares;
/**
* The minimum number of quote quantums above shares should redeem, i.e.
* transaction fails if above shares redeem less than min_quote_quantums.
*/

minQuoteQuantums: Uint8Array;
}
/**
* MsgWithdrawFromMegavault withdraws the specified shares from megavault to
* a subaccount.
*/

export interface MsgWithdrawFromMegavaultSDKType {
/** The subaccount to withdraw to. */
subaccount_id?: SubaccountIdSDKType;
/** Number of shares to withdraw. */

shares?: NumSharesSDKType;
/**
* The minimum number of quote quantums above shares should redeem, i.e.
* transaction fails if above shares redeem less than min_quote_quantums.
*/

min_quote_quantums: Uint8Array;
}
/**
* MsgWithdrawFromMegavaultResponse is the Msg/WithdrawFromMegavault response
* type.
*/

export interface MsgWithdrawFromMegavaultResponse {
/** The number of quote quantums redeemed from the withdrawal. */
quoteQuantums: Uint8Array;
}
/**
* MsgWithdrawFromMegavaultResponse is the Msg/WithdrawFromMegavault response
* type.
*/

export interface MsgWithdrawFromMegavaultResponseSDKType {
/** The number of quote quantums redeemed from the withdrawal. */
quote_quantums: Uint8Array;
}
/**
* MsgUpdateDefaultQuotingParams is the Msg/UpdateDefaultQuotingParams request
* type.
Expand Down Expand Up @@ -335,6 +389,116 @@ export const MsgDepositToMegavaultResponse = {

};

function createBaseMsgWithdrawFromMegavault(): MsgWithdrawFromMegavault {
return {
subaccountId: undefined,
shares: undefined,
minQuoteQuantums: new Uint8Array()
};
}

export const MsgWithdrawFromMegavault = {
encode(message: MsgWithdrawFromMegavault, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer {
if (message.subaccountId !== undefined) {
SubaccountId.encode(message.subaccountId, writer.uint32(10).fork()).ldelim();
}

if (message.shares !== undefined) {
NumShares.encode(message.shares, writer.uint32(18).fork()).ldelim();
}

if (message.minQuoteQuantums.length !== 0) {
writer.uint32(26).bytes(message.minQuoteQuantums);
}

return writer;
},

decode(input: _m0.Reader | Uint8Array, length?: number): MsgWithdrawFromMegavault {
const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input);
let end = length === undefined ? reader.len : reader.pos + length;
const message = createBaseMsgWithdrawFromMegavault();

while (reader.pos < end) {
const tag = reader.uint32();

switch (tag >>> 3) {
case 1:
message.subaccountId = SubaccountId.decode(reader, reader.uint32());
break;

case 2:
message.shares = NumShares.decode(reader, reader.uint32());
break;

case 3:
message.minQuoteQuantums = reader.bytes();
break;

default:
reader.skipType(tag & 7);
break;
}
}

return message;
},

fromPartial(object: DeepPartial<MsgWithdrawFromMegavault>): MsgWithdrawFromMegavault {
const message = createBaseMsgWithdrawFromMegavault();
message.subaccountId = object.subaccountId !== undefined && object.subaccountId !== null ? SubaccountId.fromPartial(object.subaccountId) : undefined;
message.shares = object.shares !== undefined && object.shares !== null ? NumShares.fromPartial(object.shares) : undefined;
message.minQuoteQuantums = object.minQuoteQuantums ?? new Uint8Array();
return message;
}

};

function createBaseMsgWithdrawFromMegavaultResponse(): MsgWithdrawFromMegavaultResponse {
return {
quoteQuantums: new Uint8Array()
};
}

export const MsgWithdrawFromMegavaultResponse = {
encode(message: MsgWithdrawFromMegavaultResponse, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer {
if (message.quoteQuantums.length !== 0) {
writer.uint32(10).bytes(message.quoteQuantums);
}

return writer;
},

decode(input: _m0.Reader | Uint8Array, length?: number): MsgWithdrawFromMegavaultResponse {
const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input);
let end = length === undefined ? reader.len : reader.pos + length;
const message = createBaseMsgWithdrawFromMegavaultResponse();

while (reader.pos < end) {
const tag = reader.uint32();

switch (tag >>> 3) {
case 1:
message.quoteQuantums = reader.bytes();
break;

default:
reader.skipType(tag & 7);
break;
}
}

return message;
},

fromPartial(object: DeepPartial<MsgWithdrawFromMegavaultResponse>): MsgWithdrawFromMegavaultResponse {
const message = createBaseMsgWithdrawFromMegavaultResponse();
message.quoteQuantums = object.quoteQuantums ?? new Uint8Array();
return message;
}

};

function createBaseMsgUpdateDefaultQuotingParams(): MsgUpdateDefaultQuotingParams {
return {
authority: "",
Expand Down
38 changes: 38 additions & 0 deletions proto/dydxprotocol/vault/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ service Msg {
rpc DepositToMegavault(MsgDepositToMegavault)
returns (MsgDepositToMegavaultResponse);

// WithdrawFromMegavault withdraws shares from megavault.
rpc WithdrawFromMegavault(MsgWithdrawFromMegavault)
returns (MsgWithdrawFromMegavaultResponse);

// UpdateDefaultQuotingParams updates the default quoting params in state.
rpc UpdateDefaultQuotingParams(MsgUpdateDefaultQuotingParams)
returns (MsgUpdateDefaultQuotingParamsResponse);
Expand Down Expand Up @@ -65,6 +69,40 @@ message MsgDepositToMegavaultResponse {
NumShares minted_shares = 1 [ (gogoproto.nullable) = false ];
}

// MsgWithdrawFromMegavault withdraws the specified shares from megavault to
// a subaccount.
message MsgWithdrawFromMegavault {
// This annotation enforces that the tx signer is the owner specified in
// `subaccount_id`.
option (cosmos.msg.v1.signer) = "subaccount_id";

// The subaccount to withdraw to.
dydxprotocol.subaccounts.SubaccountId subaccount_id = 1
[ (gogoproto.nullable) = false ];

// Number of shares to withdraw.
NumShares shares = 2 [ (gogoproto.nullable) = false ];

// The minimum number of quote quantums above shares should redeem, i.e.
// transaction fails if above shares redeem less than min_quote_quantums.
bytes min_quote_quantums = 3 [
(gogoproto.customtype) =
"github.com/dydxprotocol/v4-chain/protocol/dtypes.SerializableInt",
(gogoproto.nullable) = false
];
}

// MsgWithdrawFromMegavaultResponse is the Msg/WithdrawFromMegavault response
// type.
message MsgWithdrawFromMegavaultResponse {
// The number of quote quantums redeemed from the withdrawal.
bytes quote_quantums = 1 [
(gogoproto.customtype) =
"github.com/dydxprotocol/v4-chain/protocol/dtypes.SerializableInt",
(gogoproto.nullable) = false
];
}

// MsgUpdateDefaultQuotingParams is the Msg/UpdateDefaultQuotingParams request
// type.
message MsgUpdateDefaultQuotingParams {
Expand Down
3 changes: 3 additions & 0 deletions protocol/app/module/interface_registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@ func NewInterfaceRegistry(addrPrefix string, valAddrPrefix string) (types.Interf
"dydxprotocol.vault.MsgDepositToMegavault": getLegacyMsgSignerFn(
[]string{"subaccount_id", "owner"},
),
"dydxprotocol.vault.MsgWithdrawFromMegavault": getLegacyMsgSignerFn(
[]string{"subaccount_id", "owner"},
),
"dydxprotocol.listing.MsgCreateMarketPermissionless": getLegacyMsgSignerFn(
[]string{"subaccount_id", "owner"},
),
Expand Down
2 changes: 2 additions & 0 deletions protocol/app/msgs/all_msgs.go
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,8 @@ var (
"/dydxprotocol.vault.MsgUpdateOperatorParams": {},
"/dydxprotocol.vault.MsgUpdateOperatorParamsResponse": {},
"/dydxprotocol.vault.MsgUpdateParams": {},
"/dydxprotocol.vault.MsgWithdrawFromMegavault": {},
"/dydxprotocol.vault.MsgWithdrawFromMegavaultResponse": {},

// vest
"/dydxprotocol.vest.MsgSetVestEntry": {},
Expand Down
18 changes: 10 additions & 8 deletions protocol/app/msgs/normal_msgs.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,14 +246,16 @@ var (
"/dydxprotocol.sending.MsgWithdrawFromSubaccountResponse": nil,

// vault
"/dydxprotocol.vault.MsgAllocateToVault": &vault.MsgAllocateToVault{},
"/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,
"/dydxprotocol.vault.MsgAllocateToVault": &vault.MsgAllocateToVault{},
"/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,
"/dydxprotocol.vault.MsgWithdrawFromMegavault": &vault.MsgWithdrawFromMegavault{},
"/dydxprotocol.vault.MsgWithdrawFromMegavaultResponse": nil,
}

NormalMsgsSlinky = map[string]sdk.Msg{
Expand Down
2 changes: 2 additions & 0 deletions protocol/app/msgs/normal_msgs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,8 @@ func TestNormalMsgs_Key(t *testing.T) {
"/dydxprotocol.vault.MsgRetrieveFromVaultResponse",
"/dydxprotocol.vault.MsgSetVaultParams",
"/dydxprotocol.vault.MsgSetVaultParamsResponse",
"/dydxprotocol.vault.MsgWithdrawFromMegavault",
"/dydxprotocol.vault.MsgWithdrawFromMegavaultResponse",

// ibc application module: ICA
"/ibc.applications.interchain_accounts.v1.InterchainAccount",
Expand Down
1 change: 1 addition & 0 deletions protocol/testutil/encoding/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ func GetTestEncodingCfg() testutil.TestEncodingConfig {

// Vault.
&vaulttypes.MsgDepositToMegavault{},
&vaulttypes.MsgWithdrawFromMegavault{},
}

for _, msg := range msgInterfacesToRegister {
Expand Down
8 changes: 8 additions & 0 deletions protocol/x/vault/keeper/deposit.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,14 @@ func (k Keeper) DepositToMegavault(
return nil, err
}

ctx.EventManager().EmitEvent(
types.NewDepositToMegavaultEvent(
fromSubaccount.Owner,
quoteQuantums.Uint64(),
mintedShares.Uint64(),
),
)

return mintedShares, nil
}

Expand Down
5 changes: 4 additions & 1 deletion protocol/x/vault/keeper/msg_server_allocate_to_vault.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ func (k msgServer) AllocateToVault(
return nil, types.ErrClobPairNotFound
}

// If vault params doesn't exist, initialize params with `STAND_BY` status.
// If vault doesn't exist:
// 1. initialize params with `STAND_BY` status.
// 2. add vault to address store.
_, exists = k.Keeper.GetVaultParams(ctx, msg.VaultId)
if !exists {
err := k.Keeper.SetVaultParams(
Expand All @@ -47,6 +49,7 @@ func (k msgServer) AllocateToVault(
if err != nil {
return nil, err
}
k.Keeper.AddVaultToAddressStore(ctx, msg.VaultId)
}

// Transfer from main vault to the specified vault.
Expand Down
Loading
Loading