-
Notifications
You must be signed in to change notification settings - Fork 44
/
query_vesting_info.go
64 lines (54 loc) · 2.06 KB
/
query_vesting_info.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
53
54
55
56
57
58
59
60
61
62
63
64
package wasm
import (
"encoding/json"
"fmt"
errorsmod "cosmossdk.io/errors"
sdk "github.com/cosmos/cosmos-sdk/types"
assetprofiletypes "github.com/elys-network/elys/x/assetprofile/types"
commitmenttypes "github.com/elys-network/elys/x/commitment/types"
ptypes "github.com/elys-network/elys/x/parameter/types"
)
func (oq *Querier) queryVestingInfo(ctx sdk.Context, query *commitmenttypes.QueryVestingInfoRequest) ([]byte, error) {
addr := query.Address
commitment := oq.keeper.GetCommitments(ctx, addr)
vestingTokens := commitment.GetVestingTokens()
baseCurrency, found := oq.assetKeeper.GetUsdcDenom(ctx)
if !found {
return nil, errorsmod.Wrapf(assetprofiletypes.ErrAssetProfileNotFound, "asset %s not found", ptypes.BaseCurrency)
}
edenDenomPrice := oq.ammKeeper.GetEdenDenomPrice(ctx, baseCurrency)
totalVesting := sdk.ZeroInt()
vestingDetails := make([]commitmenttypes.VestingDetail, 0)
for i, vesting := range vestingTokens {
vestingDetail := commitmenttypes.VestingDetail{
Id: fmt.Sprintf("%d", i),
TotalVesting: commitmenttypes.BalanceAvailable{
Amount: vesting.TotalAmount,
UsdAmount: edenDenomPrice.MulInt(vesting.TotalAmount),
},
Claimed: commitmenttypes.BalanceAvailable{
Amount: vesting.ClaimedAmount,
UsdAmount: edenDenomPrice.MulInt(vesting.ClaimedAmount),
},
VestedSoFar: commitmenttypes.BalanceAvailable{
Amount: vesting.VestedSoFar(ctx),
UsdAmount: edenDenomPrice.MulInt(vesting.VestedSoFar(ctx)),
},
RemainingBlocks: vesting.NumBlocks - (ctx.BlockHeight() - vesting.StartBlock),
}
vestingDetails = append(vestingDetails, vestingDetail)
totalVesting = totalVesting.Add(vesting.TotalAmount.Sub(vesting.ClaimedAmount))
}
res := commitmenttypes.QueryVestingInfoResponse{
Vesting: commitmenttypes.BalanceAvailable{
Amount: totalVesting,
UsdAmount: edenDenomPrice.MulInt(totalVesting),
},
VestingDetails: vestingDetails,
}
responseBytes, err := json.Marshal(res)
if err != nil {
return nil, errorsmod.Wrap(err, "failed to get reward balance response")
}
return responseBytes, nil
}