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

[TRA-461] define MsgWithdrawFromVault proto #1815

Merged
merged 14 commits into from
Jul 1, 2024
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { Params, ParamsSDKType } from "./params";
import { VaultId, VaultIdSDKType, NumShares, NumSharesSDKType } from "./vault";
import { OwnerShare, OwnerShareSDKType } from "./query";
import { VaultId, VaultIdSDKType, NumShares, NumSharesSDKType, OwnerShare, OwnerShareSDKType } from "./vault";
import * as _m0 from "protobufjs/minimal";
import { DeepPartial } from "../../helpers";
/** GenesisState defines `x/vault`'s genesis state. */
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { VaultType, VaultTypeSDKType, VaultId, VaultIdSDKType, NumShares, NumSharesSDKType } from "./vault";
import { VaultType, VaultTypeSDKType, VaultId, VaultIdSDKType, OwnerShare, OwnerShareSDKType } from "./vault";
import { PageRequest, PageRequestSDKType, PageResponse, PageResponseSDKType } from "../../cosmos/base/query/v1beta1/pagination";
import { Params, ParamsSDKType } from "./params";
import { SubaccountId, SubaccountIdSDKType } from "../subaccounts/subaccount";
Expand Down Expand Up @@ -86,18 +86,6 @@ export interface QueryOwnerSharesRequestSDKType {
number: number;
pagination?: PageRequestSDKType;
}
/** OwnerShare is a type for owner shares in a vault. */

export interface OwnerShare {
owner: string;
shares?: NumShares;
}
/** OwnerShare is a type for owner shares in a vault. */

export interface OwnerShareSDKType {
owner: string;
shares?: NumSharesSDKType;
}
/** QueryOwnerSharesResponse is a response type for the OwnerShares RPC method. */

export interface QueryOwnerSharesResponse {
Expand Down Expand Up @@ -495,61 +483,6 @@ export const QueryOwnerSharesRequest = {

};

function createBaseOwnerShare(): OwnerShare {
return {
owner: "",
shares: undefined
};
}

export const OwnerShare = {
encode(message: OwnerShare, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer {
if (message.owner !== "") {
writer.uint32(10).string(message.owner);
}

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

return writer;
},

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

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

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

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

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

return message;
},

fromPartial(object: DeepPartial<OwnerShare>): OwnerShare {
const message = createBaseOwnerShare();
message.owner = object.owner ?? "";
message.shares = object.shares !== undefined && object.shares !== null ? NumShares.fromPartial(object.shares) : undefined;
return message;
}

};

function createBaseQueryOwnerSharesResponse(): QueryOwnerSharesResponse {
return {
ownerShares: [],
Expand Down
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 { MsgDepositToVault, MsgDepositToVaultResponse, MsgUpdateParams, MsgUpdateParamsResponse } from "./tx";
import { MsgDepositToVault, MsgDepositToVaultResponse, MsgWithdrawFromVault, MsgWithdrawFromVaultResponse, MsgUpdateParams, MsgUpdateParamsResponse } from "./tx";
/** Msg defines the Msg service. */

export interface Msg {
/** DepositToVault deposits funds into a vault. */
depositToVault(request: MsgDepositToVault): Promise<MsgDepositToVaultResponse>;
/** WithdrawFromVault attempts to withdraw funds from a vault. */

withdrawFromVault(request: MsgWithdrawFromVault): Promise<MsgWithdrawFromVaultResponse>;
/** UpdateParams updates the Params in state. */

updateParams(request: MsgUpdateParams): Promise<MsgUpdateParamsResponse>;
Expand All @@ -16,6 +19,7 @@ export class MsgClientImpl implements Msg {
constructor(rpc: Rpc) {
this.rpc = rpc;
this.depositToVault = this.depositToVault.bind(this);
this.withdrawFromVault = this.withdrawFromVault.bind(this);
this.updateParams = this.updateParams.bind(this);
}

Expand All @@ -25,6 +29,12 @@ export class MsgClientImpl implements Msg {
return promise.then(data => MsgDepositToVaultResponse.decode(new _m0.Reader(data)));
}

withdrawFromVault(request: MsgWithdrawFromVault): Promise<MsgWithdrawFromVaultResponse> {
const data = MsgWithdrawFromVault.encode(request).finish();
const promise = this.rpc.request("dydxprotocol.vault.Msg", "WithdrawFromVault", data);
return promise.then(data => MsgWithdrawFromVaultResponse.decode(new _m0.Reader(data)));
}

updateParams(request: MsgUpdateParams): Promise<MsgUpdateParamsResponse> {
const data = MsgUpdateParams.encode(request).finish();
const promise = this.rpc.request("dydxprotocol.vault.Msg", "UpdateParams", data);
Expand Down
222 changes: 219 additions & 3 deletions indexer/packages/v4-protos/src/codegen/dydxprotocol/vault/tx.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import { VaultId, VaultIdSDKType } from "./vault";
import { VaultId, VaultIdSDKType, NumShares, NumSharesSDKType } from "./vault";
import { SubaccountId, SubaccountIdSDKType } from "../subaccounts/subaccount";
import { Params, ParamsSDKType } from "./params";
import * as _m0 from "protobufjs/minimal";
import { DeepPartial } from "../../helpers";
/** MsgDepositToVault is the Msg/DepositToVault request type. */
/**
* MsgDepositToVault deposits the specified asset from the subaccount to the
* vault.
*/

export interface MsgDepositToVault {
/** The vault to deposit into. */
Expand All @@ -15,7 +18,10 @@ export interface MsgDepositToVault {

quoteQuantums: Uint8Array;
}
/** MsgDepositToVault is the Msg/DepositToVault request type. */
/**
* MsgDepositToVault deposits the specified asset from the subaccount to the
* vault.
*/

export interface MsgDepositToVaultSDKType {
/** The vault to deposit into. */
Expand All @@ -33,6 +39,86 @@ export interface MsgDepositToVaultResponse {}
/** MsgDepositToVaultResponse is the Msg/DepositToVault response type. */

export interface MsgDepositToVaultResponseSDKType {}
/**
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replace empty interface with type alias.

The MsgDepositToVaultResponseSDKType interface is empty and should be replaced with a type alias to avoid linting errors.

- export interface MsgDepositToVaultResponseSDKType {}
+ export type MsgDepositToVaultResponseSDKType = {};
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
export interface MsgDepositToVaultResponseSDKType {}
export type MsgDepositToVaultResponseSDKType = {};
Tools
Biome

[error] 41-41: An empty interface is equivalent to {}.

Safe fix: Use a type alias instead.

(lint/suspicious/noEmptyInterface)

* MsgWithdrawFromVault attempts to withdraw the specified target amount of
* asset from the vault to the subaccount.
*/

export interface MsgWithdrawFromVault {
/** The vault to withdraw from. */
vaultId?: VaultId;
/**
* The subaccount to withdraw to.
* The subaccount must own shares in the vault.
*/

subaccountId?: SubaccountId;
/**
* The amount of quote quantums to withdraw.
* The amount should account for slippage, so that the final amount withdrawn
* to the user matches the amount specified.
* If the amount specified exceeds the max amount that can be withdrawn (=
* user equity - slippage), only the max amount is withdrawn. For example:
* * user equity = $1020
* * target amount = $1000
* * slippage = $50
* then, the amount withdrawn is $970 (= 1020 - (1000 + 50 - 1020))
*/

quoteQuantums: Uint8Array;
}
/**
* MsgWithdrawFromVault attempts to withdraw the specified target amount of
* asset from the vault to the subaccount.
*/

export interface MsgWithdrawFromVaultSDKType {
/** The vault to withdraw from. */
vault_id?: VaultIdSDKType;
/**
* The subaccount to withdraw to.
* The subaccount must own shares in the vault.
*/

subaccount_id?: SubaccountIdSDKType;
/**
* The amount of quote quantums to withdraw.
* The amount should account for slippage, so that the final amount withdrawn
* to the user matches the amount specified.
* If the amount specified exceeds the max amount that can be withdrawn (=
* user equity - slippage), only the max amount is withdrawn. For example:
* * user equity = $1020
* * target amount = $1000
* * slippage = $50
* then, the amount withdrawn is $970 (= 1020 - (1000 + 50 - 1020))
*/

quote_quantums: Uint8Array;
}
/** MsgWithdrawFromVaultResponse is the Msg/WithdrawFromVault response type. */

export interface MsgWithdrawFromVaultResponse {
/** Number of shares that have been redeemed as part of the withdrawal. */
redeemedShares?: NumShares;
/** Number of shares remaining after the withdrawal. */

remainingShares?: NumShares;
/** Number of shares for the vault after the withdrawal. */

totalShares?: NumShares;
}
/** MsgWithdrawFromVaultResponse is the Msg/WithdrawFromVault response type. */

export interface MsgWithdrawFromVaultResponseSDKType {
/** Number of shares that have been redeemed as part of the withdrawal. */
redeemed_shares?: NumSharesSDKType;
/** Number of shares remaining after the withdrawal. */

remaining_shares?: NumSharesSDKType;
/** Number of shares for the vault after the withdrawal. */

total_shares?: NumSharesSDKType;
}
/** MsgUpdateParams is the Msg/UpdateParams request type. */

export interface MsgUpdateParams {
Expand Down Expand Up @@ -155,6 +241,136 @@ export const MsgDepositToVaultResponse = {

};

function createBaseMsgWithdrawFromVault(): MsgWithdrawFromVault {
return {
vaultId: undefined,
subaccountId: undefined,
quoteQuantums: new Uint8Array()
};
}

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

if (message.subaccountId !== undefined) {
SubaccountId.encode(message.subaccountId, 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): MsgWithdrawFromVault {
const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input);
let end = length === undefined ? reader.len : reader.pos + length;
const message = createBaseMsgWithdrawFromVault();

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

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

case 2:
message.subaccountId = SubaccountId.decode(reader, reader.uint32());
break;

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

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

return message;
},

fromPartial(object: DeepPartial<MsgWithdrawFromVault>): MsgWithdrawFromVault {
const message = createBaseMsgWithdrawFromVault();
message.vaultId = object.vaultId !== undefined && object.vaultId !== null ? VaultId.fromPartial(object.vaultId) : undefined;
message.subaccountId = object.subaccountId !== undefined && object.subaccountId !== null ? SubaccountId.fromPartial(object.subaccountId) : undefined;
message.quoteQuantums = object.quoteQuantums ?? new Uint8Array();
return message;
}

};

function createBaseMsgWithdrawFromVaultResponse(): MsgWithdrawFromVaultResponse {
return {
redeemedShares: undefined,
remainingShares: undefined,
totalShares: undefined
};
}

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

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

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

return writer;
},

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

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

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

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

case 3:
message.totalShares = NumShares.decode(reader, reader.uint32());
break;

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

return message;
},

fromPartial(object: DeepPartial<MsgWithdrawFromVaultResponse>): MsgWithdrawFromVaultResponse {
const message = createBaseMsgWithdrawFromVaultResponse();
message.redeemedShares = object.redeemedShares !== undefined && object.redeemedShares !== null ? NumShares.fromPartial(object.redeemedShares) : undefined;
message.remainingShares = object.remainingShares !== undefined && object.remainingShares !== null ? NumShares.fromPartial(object.remainingShares) : undefined;
message.totalShares = object.totalShares !== undefined && object.totalShares !== null ? NumShares.fromPartial(object.totalShares) : undefined;
return message;
}

};

function createBaseMsgUpdateParams(): MsgUpdateParams {
return {
authority: "",
Expand Down
Loading
Loading