Skip to content

Commit

Permalink
Re-use code in superfluid TotalDelegationByDelegator (#1938)
Browse files Browse the repository at this point in the history
  • Loading branch information
ValarDragon authored Jul 3, 2022
1 parent b33920a commit 197a9b1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 41 deletions.
2 changes: 1 addition & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ linters:
# - gosec <- triggers too much for this round and should be re-enabled later
# - gosimple <- later
- govet
# - ifshort <- seems to be of questionable value
# - ifshort <- questionable value, unclear if globally helping readability.
- importas
- ineffassign
# - ireturn <- disabled because we want to return interfaces
Expand Down
49 changes: 9 additions & 40 deletions x/superfluid/keeper/grpc_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -439,48 +439,17 @@ func (q Querier) TotalDelegationByDelegator(goCtx context.Context, req *types.Qu
return nil, err
}

res := types.QueryTotalDelegationByDelegatorResponse{
SuperfluidDelegationRecords: []types.SuperfluidDelegationRecord{},
DelegationResponse: []stakingtypes.DelegationResponse{},
TotalDelegatedCoins: sdk.NewCoins(),
TotalEquivalentStakedAmount: sdk.NewCoin(appparams.BaseCoinUnit, sdk.ZeroInt()),
superfluidDelegationResp, err := q.SuperfluidDelegationsByDelegator(goCtx, &types.SuperfluidDelegationsByDelegatorRequest{
DelegatorAddress: req.DelegatorAddress})
if err != nil {
return nil, err
}

syntheticLocks := q.Keeper.lk.GetAllSyntheticLockupsByAddr(ctx, delAddr)

for _, syntheticLock := range syntheticLocks {
// don't include unbonding delegations
if strings.Contains(syntheticLock.SynthDenom, "superunbonding") {
continue
}

periodLock, err := q.Keeper.lk.GetLockByID(ctx, syntheticLock.UnderlyingLockId)
if err != nil {
return nil, err
}

baseDenom := periodLock.Coins.GetDenomByIndex(0)
lockedCoins := sdk.NewCoin(baseDenom, periodLock.GetCoins().AmountOf(baseDenom))
valAddr, err := ValidatorAddressFromSyntheticDenom(syntheticLock.SynthDenom)

// Find how many osmo tokens this delegation is worth at superfluids current risk adjustment
// and twap of the denom.
equivalentAmount := q.Keeper.GetSuperfluidOSMOTokens(ctx, baseDenom, lockedCoins.Amount)
coin := sdk.NewCoin(appparams.BaseCoinUnit, equivalentAmount)

if err != nil {
return nil, err
}
res.SuperfluidDelegationRecords = append(res.SuperfluidDelegationRecords,
types.SuperfluidDelegationRecord{
DelegatorAddress: req.DelegatorAddress,
ValidatorAddress: valAddr,
DelegationAmount: lockedCoins,
EquivalentStakedAmount: &coin,
},
)
res.TotalDelegatedCoins = res.TotalDelegatedCoins.Add(lockedCoins)
res.TotalEquivalentStakedAmount = res.TotalEquivalentStakedAmount.Add(coin)
res := types.QueryTotalDelegationByDelegatorResponse{
SuperfluidDelegationRecords: superfluidDelegationResp.SuperfluidDelegationRecords,
DelegationResponse: []stakingtypes.DelegationResponse{},
TotalDelegatedCoins: superfluidDelegationResp.TotalDelegatedCoins,
TotalEquivalentStakedAmount: superfluidDelegationResp.TotalEquivalentStakedAmount,
}

//this is for getting normal staking
Expand Down

0 comments on commit 197a9b1

Please sign in to comment.