/
msg_server_claim_unlocked.go
52 lines (40 loc) · 1.72 KB
/
msg_server_claim_unlocked.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package keeper
import (
"context"
"cosmossdk.io/errors"
"github.com/KYVENetwork/chain/util"
"github.com/KYVENetwork/chain/x/team/types"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkErrors "github.com/cosmos/cosmos-sdk/types/errors"
)
func (k msgServer) ClaimUnlocked(goCtx context.Context, msg *types.MsgClaimUnlocked) (*types.MsgClaimUnlockedResponse, error) {
ctx := sdk.UnwrapSDKContext(goCtx)
if types.FOUNDATION_ADDRESS != msg.Authority && types.BCP_ADDRESS != msg.Authority {
return nil, errors.Wrapf(sdkErrors.ErrLogic, types.ErrInvalidAuthority.Error(), types.FOUNDATION_ADDRESS, types.BCP_ADDRESS, msg.Authority)
}
account, found := k.GetTeamVestingAccount(ctx, msg.Id)
if !found {
return nil, sdkErrors.ErrNotFound
}
// get current claimable amount
currentProgress := GetVestingStatus(account, uint64(ctx.BlockTime().Unix()))
// throw error if the requested claim amount is bigger than the available unlocked amount
if msg.Amount > currentProgress.CurrentClaimableAmount {
return nil, errors.Wrapf(sdkErrors.ErrLogic, types.ErrClaimAmountTooHigh.Error(), msg.Amount, currentProgress.CurrentClaimableAmount)
}
// Transfer claim amount from this module to recipient.
if err := util.TransferFromModuleToAddress(k.bankKeeper, ctx, types.ModuleName, msg.Recipient, msg.Amount); err != nil {
return nil, err
}
// update claimed amount of unlocked $KYVE
account.UnlockedClaimed += msg.Amount
account.LastClaimedTime = uint64(ctx.BlockTime().Unix())
k.SetTeamVestingAccount(ctx, account)
_ = ctx.EventManager().EmitTypedEvent(&types.EventClaimedUnlocked{
Authority: msg.Authority,
Id: account.Id,
Amount: msg.Amount,
Recipient: msg.Recipient,
})
return &types.MsgClaimUnlockedResponse{}, nil
}