-
Notifications
You must be signed in to change notification settings - Fork 115
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
allow operator and governance to retrieve from vaults #2290
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -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 {} | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use a type alias instead of an empty interface. The Consider using a type alias instead: -export interface MsgRetrieveFromVaultResponseSDKType {}
+export type MsgRetrieveFromVaultResponseSDKType = Record<string, never>; This provides a cleaner and more explicit way to represent an empty type. Committable suggestion
Suggested change
ToolsBiome
|
||||||
|
||||||
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>): 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>): MsgRetrieveFromVaultResponse { | ||||||
const message = createBaseMsgRetrieveFromVaultResponse(); | ||||||
return message; | ||||||
} | ||||||
|
||||||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use a type alias instead of an empty interface.
The
MsgRetrieveFromVaultResponse
interface is currently empty, which is equivalent to{}
. Using an empty interface is not recommended as it can lead to confusion and maintenance issues.Consider using a type alias instead:
This provides a cleaner and more explicit way to represent an empty type.
Committable suggestion
Tools
Biome