Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Query osmo equivilent is staked via superfluid #1632

Merged
merged 16 commits into from
Jun 6, 2022
2 changes: 2 additions & 0 deletions docs/core/proto-docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -3247,6 +3247,7 @@ and OSMO tokens for superfluid staking
| `delegator_address` | [string](#string) | | |
| `validator_address` | [string](#string) | | |
| `delegation_amount` | [cosmos.base.v1beta1.Coin](#cosmos.base.v1beta1.Coin) | | |
| `equivilent_staked_amount` | [cosmos.base.v1beta1.Coin](#cosmos.base.v1beta1.Coin) | | |



Expand Down Expand Up @@ -3691,6 +3692,7 @@ assets
| ----- | ---- | ----- | ----------- |
| `superfluid_delegation_records` | [SuperfluidDelegationRecord](#osmosis.superfluid.SuperfluidDelegationRecord) | repeated | |
| `total_delegated_coins` | [cosmos.base.v1beta1.Coin](#cosmos.base.v1beta1.Coin) | repeated | |
| `total_equivilent_staked_amount` | [cosmos.base.v1beta1.Coin](#cosmos.base.v1beta1.Coin) | | |
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this needs to be regenerated due to the typo




Expand Down
4 changes: 4 additions & 0 deletions proto/osmosis/superfluid/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,10 @@ message SuperfluidDelegationsByDelegatorResponse {
(gogoproto.nullable) = false,
(gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins"
];
cosmos.base.v1beta1.Coin total_equivilent_staked_amount = 3 [
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
cosmos.base.v1beta1.Coin total_equivilent_staked_amount = 3 [
cosmos.base.v1beta1.Coin total_equivalent_staked_amount = 3 [

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thank u xD i changed that

(gogoproto.nullable) = false,
(gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coin"
];
}

message SuperfluidUndelegationsByDelegatorRequest {
Expand Down
2 changes: 2 additions & 0 deletions proto/osmosis/superfluid/superfluid.proto
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ message SuperfluidDelegationRecord {
(gogoproto.nullable) = false,
(gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coin"
];
cosmos.base.v1beta1.Coin equivilent_staked_amount = 4
[ (gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coin" ];
}

message LockIdIntermediaryAccountConnection {
Expand Down
17 changes: 14 additions & 3 deletions x/superfluid/keeper/grpc_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import (
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"

appparams "github.com/osmosis-labs/osmosis/v7/app/params"

lockuptypes "github.com/osmosis-labs/osmosis/v7/x/lockup/types"
"github.com/osmosis-labs/osmosis/v7/x/superfluid/types"
)
Expand Down Expand Up @@ -195,6 +197,7 @@ func (q Querier) SuperfluidDelegationsByDelegator(goCtx context.Context, req *ty
res := types.SuperfluidDelegationsByDelegatorResponse{
SuperfluidDelegationRecords: []types.SuperfluidDelegationRecord{},
TotalDelegatedCoins: sdk.NewCoins(),
TotalEquivilentStakedAmount: sdk.NewCoin(appparams.BaseCoinUnit, sdk.ZeroInt()),
}

syntheticLocks := q.Keeper.lk.GetAllSyntheticLockupsByAddr(ctx, delAddr)
Expand All @@ -213,17 +216,25 @@ func (q Querier) SuperfluidDelegationsByDelegator(goCtx context.Context, req *ty
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.
equivilentAmount := q.Keeper.GetSuperfluidOSMOTokens(ctx, baseDenom, lockedCoins.Amount)
coin := sdk.NewCoin(appparams.BaseCoinUnit, equivilentAmount)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
equivilentAmount := q.Keeper.GetSuperfluidOSMOTokens(ctx, baseDenom, lockedCoins.Amount)
coin := sdk.NewCoin(appparams.BaseCoinUnit, equivilentAmount)
equivalentAmount := q.Keeper.GetSuperfluidOSMOTokens(ctx, baseDenom, lockedCoins.Amount)
coin := sdk.NewCoin(appparams.BaseCoinUnit, equivalentAmount)

minor nit


if err != nil {
return nil, err
}
res.SuperfluidDelegationRecords = append(res.SuperfluidDelegationRecords,
types.SuperfluidDelegationRecord{
DelegatorAddress: req.DelegatorAddress,
ValidatorAddress: valAddr,
DelegationAmount: lockedCoins,
DelegatorAddress: req.DelegatorAddress,
ValidatorAddress: valAddr,
DelegationAmount: lockedCoins,
EquivilentStakedAmount: &coin,
},
)
res.TotalDelegatedCoins = res.TotalDelegatedCoins.Add(lockedCoins)
res.TotalEquivilentStakedAmount = res.TotalEquivilentStakedAmount.Add(coin)
}

return &res, nil
Expand Down
10 changes: 10 additions & 0 deletions x/superfluid/keeper/grpc_query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,22 @@ func (suite *KeeperTestSuite) TestGRPCQuerySuperfluidDelegations() {
res, err := suite.queryClient.SuperfluidDelegationsByDelegator(sdk.WrapSDKContext(suite.Ctx), &types.SuperfluidDelegationsByDelegatorRequest{
DelegatorAddress: delegator.String(),
})

multiplier0 := suite.querier.Keeper.GetOsmoEquivalentMultiplier(suite.Ctx, denoms[0])
multiplier1 := suite.querier.Keeper.GetOsmoEquivalentMultiplier(suite.Ctx, denoms[1])
minRiskFactor := suite.querier.Keeper.GetParams(suite.Ctx).MinimumRiskFactor

expectAmount0 := multiplier0.Mul(sdk.NewDec(1000000)).Sub(multiplier0.Mul(sdk.NewDec(1000000)).Mul(minRiskFactor))
expectAmount1 := multiplier1.Mul(sdk.NewDec(1000000)).Sub(multiplier1.Mul(sdk.NewDec(1000000)).Mul(minRiskFactor))

suite.Require().NoError(err)
suite.Require().Len(res.SuperfluidDelegationRecords, 2)
suite.Require().True(res.TotalDelegatedCoins.IsEqual(sdk.NewCoins(
sdk.NewInt64Coin(denoms[0], 1000000),
sdk.NewInt64Coin(denoms[1], 1000000),
)))
suite.Require().True(res.SuperfluidDelegationRecords[0].EquivilentStakedAmount.IsEqual(sdk.NewCoin("uosmo", expectAmount0.RoundInt())))
suite.Require().True(res.SuperfluidDelegationRecords[1].EquivilentStakedAmount.IsEqual(sdk.NewCoin("uosmo", expectAmount1.RoundInt())))
}

// for each validator denom pair, make sure they have 1 delegations
Expand Down
Loading