mirror of
https://github.com/0glabs/0g-chain.git
synced 2024-11-10 18:15:19 +00:00
ae181604ff
* Add basic earn types and interfaces * Add VaultStrategy type * Update params with allowedVaults, deposit/withdraw msgs * Fill in Deposit method, add keeper methods * Add testutil, params, codec * Add withdraw * emit vault events * Implement vault viewer methods * Update doc comments, strategies * Add earn cli query/tx commands * Add successfull balance withdraw tests * Add ukava vault to dev genesis * Add vault keeper method doc comments * Update stablecoin strategy to only accept usdx * Vault state tests * VaultTotalSupplied tests * msg server test
70 lines
1.6 KiB
Go
70 lines
1.6 KiB
Go
package keeper
|
|
|
|
import (
|
|
"context"
|
|
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
|
|
"github.com/kava-labs/kava/x/earn/types"
|
|
)
|
|
|
|
type msgServer struct {
|
|
keeper Keeper
|
|
}
|
|
|
|
// NewMsgServerImpl returns an implementation of the earn MsgServer interface
|
|
// for the provided Keeper.
|
|
func NewMsgServerImpl(keeper Keeper) types.MsgServer {
|
|
return &msgServer{keeper: keeper}
|
|
}
|
|
|
|
var _ types.MsgServer = msgServer{}
|
|
|
|
// Deposit handles MsgDeposit messages
|
|
func (m msgServer) Deposit(goCtx context.Context, msg *types.MsgDeposit) (*types.MsgDepositResponse, error) {
|
|
ctx := sdk.UnwrapSDKContext(goCtx)
|
|
|
|
depositor, err := sdk.AccAddressFromBech32(msg.Depositor)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
if err := m.keeper.Deposit(ctx, depositor, msg.Amount); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
ctx.EventManager().EmitEvent(
|
|
sdk.NewEvent(
|
|
sdk.EventTypeMessage,
|
|
sdk.NewAttribute(sdk.AttributeKeyModule, types.ModuleName),
|
|
sdk.NewAttribute(sdk.AttributeKeySender, depositor.String()),
|
|
),
|
|
)
|
|
|
|
return &types.MsgDepositResponse{}, nil
|
|
}
|
|
|
|
// Withdraw handles MsgWithdraw messages
|
|
func (m msgServer) Withdraw(goCtx context.Context, msg *types.MsgWithdraw) (*types.MsgWithdrawResponse, error) {
|
|
ctx := sdk.UnwrapSDKContext(goCtx)
|
|
|
|
from, err := sdk.AccAddressFromBech32(msg.From)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
if err := m.keeper.Withdraw(ctx, from, msg.Amount); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
ctx.EventManager().EmitEvent(
|
|
sdk.NewEvent(
|
|
sdk.EventTypeMessage,
|
|
sdk.NewAttribute(sdk.AttributeKeyModule, types.ModuleName),
|
|
sdk.NewAttribute(sdk.AttributeKeySender, from.String()),
|
|
),
|
|
)
|
|
|
|
return &types.MsgWithdrawResponse{}, nil
|
|
}
|