2022-07-20 22:57:56 +00:00
|
|
|
package keeper
|
|
|
|
|
|
|
|
import (
|
2022-07-20 23:14:43 +00:00
|
|
|
"context"
|
|
|
|
|
|
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
|
|
|
2022-07-20 22:57:56 +00:00
|
|
|
"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{}
|
2022-07-20 23:14:43 +00:00
|
|
|
|
|
|
|
// 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
|
|
|
|
}
|
|
|
|
|
2022-09-12 16:43:59 +00:00
|
|
|
if err := m.keeper.Deposit(ctx, depositor, msg.Amount, msg.Strategy); err != nil {
|
2022-07-20 23:14:43 +00:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2022-09-29 17:01:06 +00:00
|
|
|
_, err = m.keeper.Withdraw(ctx, from, msg.Amount, msg.Strategy)
|
|
|
|
if err != nil {
|
2022-07-20 23:14:43 +00:00
|
|
|
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
|
|
|
|
}
|