-
Notifications
You must be signed in to change notification settings - Fork 115
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
allow operator and governance to retrieve from vaults (#2290)
- Loading branch information
Showing
10 changed files
with
1,006 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
Oops, something went wrong.