Skip to content

Commit

Permalink
[Tier]: Add total vested in query and portfolio (#666)
Browse files Browse the repository at this point in the history
* add get vesting

* del

* query
  • Loading branch information
amityadav0 authored Jul 29, 2024
1 parent 9fa47da commit df360ed
Show file tree
Hide file tree
Showing 5 changed files with 136 additions and 79 deletions.
1 change: 1 addition & 0 deletions proto/elys/tier/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -187,5 +187,6 @@ message QueryStakedResponse {
string commitments = 1 [(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec", (gogoproto.nullable) = false];
string delegations = 2 [(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec", (gogoproto.nullable) = false];
string unbondings = 3 [(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec", (gogoproto.nullable) = false];
string totalVested = 4 [(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec", (gogoproto.nullable) = false];
}

14 changes: 10 additions & 4 deletions x/tier/keeper/portfolio.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/query"
ammtypes "github.com/elys-network/elys/x/amm/types"
commitmenttypes "github.com/elys-network/elys/x/commitment/types"
estakingtypes "github.com/elys-network/elys/x/estaking/types"
mastercheftypes "github.com/elys-network/elys/x/masterchef/types"

Expand Down Expand Up @@ -46,8 +47,8 @@ func (k Keeper) RetrieveAllPortfolio(ctx sdk.Context, user string) {
totalValue = totalValue.Add(staked)

// Staked assets
commit, delegations, unbondings := k.RetrieveStaked(ctx, sender)
totalValue = totalValue.Add(commit).Add(delegations).Add(unbondings)
commit, delegations, unbondings, totalVesting := k.RetrieveStaked(ctx, sender)
totalValue = totalValue.Add(commit).Add(delegations).Add(unbondings).Add(totalVesting)

// LeverageLp
lev := k.RetrieveLeverageLpTotal(ctx, sender)
Expand Down Expand Up @@ -82,9 +83,14 @@ func (k Keeper) RetrievePoolTotal(ctx sdk.Context, user sdk.AccAddress) sdk.Dec
return totalValue
}

func (k Keeper) RetrieveStaked(ctx sdk.Context, user sdk.AccAddress) (sdk.Dec, sdk.Dec, sdk.Dec) {
func (k Keeper) RetrieveStaked(ctx sdk.Context, user sdk.AccAddress) (sdk.Dec, sdk.Dec, sdk.Dec, sdk.Dec) {
totalCommit := sdk.NewDec(0)
commitments := k.commitement.GetCommitments(ctx, user.String())
totalVested := sdk.NewDec(0)
vestingResp, vestErr := k.commitement.CommitmentVestingInfo(ctx, &commitmenttypes.QueryCommitmentVestingInfoRequest{Address: user.String()})
if vestErr == nil {
totalVested = vestingResp.Total.ToLegacyDec()
}
for _, commitment := range commitments.CommittedTokens {
if !strings.HasPrefix(commitment.Denom, "amm/pool") {
if strings.HasPrefix(commitment.Denom, "stablestake") {
Expand Down Expand Up @@ -137,7 +143,7 @@ func (k Keeper) RetrieveStaked(ctx sdk.Context, user sdk.AccAddress) (sdk.Dec, s
}
}
}
return totalCommit, totalDelegations, totalUnbondings
return totalCommit, totalDelegations, totalUnbondings, totalVested
}

func (k Keeper) RetrieveRewardsTotal(ctx sdk.Context, user sdk.AccAddress) sdk.Dec {
Expand Down
3 changes: 2 additions & 1 deletion x/tier/keeper/query_staked.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,12 @@ func (k Keeper) Staked(goCtx context.Context, req *types.QueryStakedRequest) (*t
sender := sdk.MustAccAddressFromBech32(req.User)
ctx := sdk.UnwrapSDKContext(goCtx)

com, del, unbon := k.RetrieveStaked(ctx, sender)
com, del, unbon, totalVested := k.RetrieveStaked(ctx, sender)

return &types.QueryStakedResponse{
Commitments: com,
Delegations: del,
Unbondings: unbon,
TotalVested: totalVested,
}, nil
}
1 change: 1 addition & 0 deletions x/tier/types/expected_keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ type OracleKeeper interface {

type CommitmentKeeper interface {
GetCommitments(ctx sdk.Context, creator string) commitmenttypes.Commitments
CommitmentVestingInfo(goCtx context.Context, req *commitmenttypes.QueryCommitmentVestingInfoRequest) (*commitmenttypes.QueryCommitmentVestingInfoResponse, error)
}

type PerpetualKeeper interface {
Expand Down
Loading

0 comments on commit df360ed

Please sign in to comment.