diff --git a/indexer/packages/v4-protos/src/codegen/dydxprotocol/stats/stats.ts b/indexer/packages/v4-protos/src/codegen/dydxprotocol/stats/stats.ts index e8fd1d0a48..63e5a2d4f6 100644 --- a/indexer/packages/v4-protos/src/codegen/dydxprotocol/stats/stats.ts +++ b/indexer/packages/v4-protos/src/codegen/dydxprotocol/stats/stats.ts @@ -153,11 +153,11 @@ export interface UserStatsSDKType { affiliate_30d_referred_volume_quote_quantums: Long; } -/** CachedStakeAmount stores the last calculated total staked amount for address */ +/** CachedStakedBaseTokens stores the last calculated total staked base tokens */ -export interface CachedStakeAmount { - /** Last calculated total staked amount by the delegator (in coin amount). */ - stakedAmount: Uint8Array; +export interface CachedStakedBaseTokens { + /** Last calculated total staked base tokens by the delegator. */ + stakedBaseTokens: Uint8Array; /** * Block time at which the calculation is cached (in Unix Epoch seconds) * Rounded down to nearest second. @@ -165,11 +165,11 @@ export interface CachedStakeAmount { cachedAt: Long; } -/** CachedStakeAmount stores the last calculated total staked amount for address */ +/** CachedStakedBaseTokens stores the last calculated total staked base tokens */ -export interface CachedStakeAmountSDKType { - /** Last calculated total staked amount by the delegator (in coin amount). */ - staked_amount: Uint8Array; +export interface CachedStakedBaseTokensSDKType { + /** Last calculated total staked base tokens by the delegator. */ + staked_base_tokens: Uint8Array; /** * Block time at which the calculation is cached (in Unix Epoch seconds) * Rounded down to nearest second. @@ -573,17 +573,17 @@ export const UserStats = { }; -function createBaseCachedStakeAmount(): CachedStakeAmount { +function createBaseCachedStakedBaseTokens(): CachedStakedBaseTokens { return { - stakedAmount: new Uint8Array(), + stakedBaseTokens: new Uint8Array(), cachedAt: Long.ZERO }; } -export const CachedStakeAmount = { - encode(message: CachedStakeAmount, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { - if (message.stakedAmount.length !== 0) { - writer.uint32(10).bytes(message.stakedAmount); +export const CachedStakedBaseTokens = { + encode(message: CachedStakedBaseTokens, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { + if (message.stakedBaseTokens.length !== 0) { + writer.uint32(10).bytes(message.stakedBaseTokens); } if (!message.cachedAt.isZero()) { @@ -593,17 +593,17 @@ export const CachedStakeAmount = { return writer; }, - decode(input: _m0.Reader | Uint8Array, length?: number): CachedStakeAmount { + decode(input: _m0.Reader | Uint8Array, length?: number): CachedStakedBaseTokens { const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input); let end = length === undefined ? reader.len : reader.pos + length; - const message = createBaseCachedStakeAmount(); + const message = createBaseCachedStakedBaseTokens(); while (reader.pos < end) { const tag = reader.uint32(); switch (tag >>> 3) { case 1: - message.stakedAmount = reader.bytes(); + message.stakedBaseTokens = reader.bytes(); break; case 2: @@ -619,9 +619,9 @@ export const CachedStakeAmount = { return message; }, - fromPartial(object: DeepPartial): CachedStakeAmount { - const message = createBaseCachedStakeAmount(); - message.stakedAmount = object.stakedAmount ?? new Uint8Array(); + fromPartial(object: DeepPartial): CachedStakedBaseTokens { + const message = createBaseCachedStakedBaseTokens(); + message.stakedBaseTokens = object.stakedBaseTokens ?? new Uint8Array(); message.cachedAt = object.cachedAt !== undefined && object.cachedAt !== null ? Long.fromValue(object.cachedAt) : Long.ZERO; return message; } diff --git a/proto/dydxprotocol/stats/stats.proto b/proto/dydxprotocol/stats/stats.proto index 49752315bd..ca1841ac9f 100644 --- a/proto/dydxprotocol/stats/stats.proto +++ b/proto/dydxprotocol/stats/stats.proto @@ -75,10 +75,10 @@ message UserStats { uint64 affiliate_30d_referred_volume_quote_quantums = 4; } -// CachedStakeAmount stores the last calculated total staked amount for address -message CachedStakeAmount { - // Last calculated total staked amount by the delegator (in coin amount). - bytes staked_amount = 1 [ +// CachedStakedBaseTokens stores the last calculated total staked base tokens +message CachedStakedBaseTokens { + // Last calculated total staked base tokens by the delegator. + bytes staked_base_tokens = 1 [ (gogoproto.customtype) = "github.com/dydxprotocol/v4-chain/protocol/dtypes.SerializableInt", (gogoproto.nullable) = false diff --git a/protocol/lib/metrics/metric_keys.go b/protocol/lib/metrics/metric_keys.go index d2208b7a6a..5c49c1cf6d 100644 --- a/protocol/lib/metrics/metric_keys.go +++ b/protocol/lib/metrics/metric_keys.go @@ -27,8 +27,8 @@ const ( ClobRateLimitPlaceOrderCount = "clob_rate_limit_place_order_count" ClobRateLimitCancelOrderCount = "clob_rate_limit_cancel_order_count" ClobRateLimitBatchCancelCount = "clob_rate_limit_batch_cancel_count" - StatsGetStakedAmountCacheHit = "stats_get_staked_amount_cache_hit" - StatsGetStakedAmountCacheMiss = "stats_get_staked_amount_cache_miss" + StatsGetStakedBaseTokensCacheHit = "stats_get_staked_base_tokens_cache_hit" + StatsGetStakedBaseTokensCacheMiss = "stats_get_staked_base_tokens_cache_miss" // Gauges InsuranceFundBalance = "insurance_fund_balance" @@ -38,8 +38,8 @@ const ( ClobSubaccountsRequiringDeleveragingCount = "clob_subaccounts_requiring_deleveraging_count" SendingProcessDepositToSubaccount = "sending_process_deposit_to_subaccount" RateLimitInsufficientWithdrawalAmount = "rate_limit_insufficient_withdrawal_amount" - StatsGetStakedAmountLatencyCacheHit = "stats_get_staked_amount_latency_cache_hit" - StatsGetStakedAmountLatencyCacheMiss = "stats_get_staked_amount_latency_cache_miss" + StatsGetStakedBaseTokensLatencyCacheHit = "stats_get_staked_base_tokens_latency_cache_hit" + StatsGetStakedBaseTokensLatencyCacheMiss = "stats_get_staked_base_tokens_latency_cache_miss" // Samples ClobDeleverageSubaccountTotalQuoteQuantumsDistribution = "clob_deleverage_subaccount_total_quote_quantums_distribution" diff --git a/protocol/x/affiliates/keeper/grpc_query.go b/protocol/x/affiliates/keeper/grpc_query.go index 584a282fb5..287e4d6ba0 100644 --- a/protocol/x/affiliates/keeper/grpc_query.go +++ b/protocol/x/affiliates/keeper/grpc_query.go @@ -40,7 +40,7 @@ func (k Keeper) AffiliateInfo(c context.Context, userStats := k.statsKeeper.GetUserStats(ctx, addr.String()) referredVolume := userStats.Affiliate_30DReferredVolumeQuoteQuantums - stakedAmount := k.statsKeeper.GetStakedAmount(ctx, req.GetAddress()) + stakedAmount := k.statsKeeper.GetStakedBaseTokens(ctx, req.GetAddress()) return &types.AffiliateInfoResponse{ IsWhitelisted: isWhitelisted, diff --git a/protocol/x/affiliates/keeper/keeper_test.go b/protocol/x/affiliates/keeper/keeper_test.go index f2eb51cc6e..017c2dd930 100644 --- a/protocol/x/affiliates/keeper/keeper_test.go +++ b/protocol/x/affiliates/keeper/keeper_test.go @@ -220,7 +220,7 @@ func TestGetTakerFeeShareViaStakedAmount(t *testing.T) { require.Equal(t, types.DefaultAffiliateTiers.Tiers[0].TakerFeeSharePpm, feeSharePpm) ctx = ctx.WithBlockTime(ctx.BlockTime().Add( - time.Duration(statstypes.StakedAmountCacheDurationSeconds+1) * time.Second, + time.Duration(statstypes.StakedBaseTokensCacheDurationSeconds+1) * time.Second, )) // Add more staked amount to upgrade tier err = stakingKeeper.SetDelegation(ctx, diff --git a/protocol/x/affiliates/types/expected_keepers.go b/protocol/x/affiliates/types/expected_keepers.go index 0c6800a75c..bc7ccf321b 100644 --- a/protocol/x/affiliates/types/expected_keepers.go +++ b/protocol/x/affiliates/types/expected_keepers.go @@ -8,7 +8,7 @@ import ( ) type StatsKeeper interface { - GetStakedAmount(ctx sdk.Context, delegatorAddr string) *big.Int + GetStakedBaseTokens(ctx sdk.Context, delegatorAddr string) *big.Int GetBlockStats(ctx sdk.Context) *stattypes.BlockStats GetUserStats(ctx sdk.Context, address string) *stattypes.UserStats SetUserStats(ctx sdk.Context, address string, userStats *stattypes.UserStats) diff --git a/protocol/x/feetiers/keeper/grpc_query.go b/protocol/x/feetiers/keeper/grpc_query.go index 54bae2980d..0b5b74d8a8 100644 --- a/protocol/x/feetiers/keeper/grpc_query.go +++ b/protocol/x/feetiers/keeper/grpc_query.go @@ -152,7 +152,7 @@ func (k Keeper) UserStakingTier( _, userFeeTier := k.getUserFeeTier(ctx, req.Address, affiliateParameters.RefereeMinimumFeeTierIdx) // Get user's staking info - stakedAmount := k.statsKeeper.GetStakedAmount(ctx, req.Address) + stakedAmount := k.statsKeeper.GetStakedBaseTokens(ctx, req.Address) discountPpm := k.GetStakingDiscountPpm(ctx, userFeeTier.Name, stakedAmount) return &types.QueryUserStakingTierResponse{ diff --git a/protocol/x/feetiers/keeper/grpc_query_test.go b/protocol/x/feetiers/keeper/grpc_query_test.go index d168245033..93bdb84857 100644 --- a/protocol/x/feetiers/keeper/grpc_query_test.go +++ b/protocol/x/feetiers/keeper/grpc_query_test.go @@ -540,9 +540,9 @@ func TestUserStakingTier(t *testing.T) { if tc.userBondedTokens != nil { bondedAmount = tc.userBondedTokens } - statsKeeper.UnsafeSetCachedStakedAmount(ctx, tc.req.Address, &stattypes.CachedStakeAmount{ - StakedAmount: dtypes.NewIntFromBigInt(bondedAmount), - CachedAt: ctx.BlockTime().Unix(), + statsKeeper.UnsafeSetCachedStakedBaseTokens(ctx, tc.req.Address, &stattypes.CachedStakedBaseTokens{ + StakedBaseTokens: dtypes.NewIntFromBigInt(bondedAmount), + CachedAt: ctx.BlockTime().Unix(), }) } diff --git a/protocol/x/feetiers/keeper/keeper.go b/protocol/x/feetiers/keeper/keeper.go index f218132aad..96a0a6b772 100644 --- a/protocol/x/feetiers/keeper/keeper.go +++ b/protocol/x/feetiers/keeper/keeper.go @@ -159,7 +159,7 @@ func (k Keeper) GetPerpetualFeePpm( "error", err, ) } else { - stakedAmount := k.statsKeeper.GetStakedAmount(ctx, address) + stakedAmount := k.statsKeeper.GetStakedBaseTokens(ctx, address) stakingDiscountPpm := k.GetStakingDiscountPpm(ctx, userTier.Name, stakedAmount) if stakingDiscountPpm > 0 { // Final fee diff --git a/protocol/x/feetiers/keeper/keeper_test.go b/protocol/x/feetiers/keeper/keeper_test.go index c905a08068..b200023b22 100644 --- a/protocol/x/feetiers/keeper/keeper_test.go +++ b/protocol/x/feetiers/keeper/keeper_test.go @@ -504,9 +504,9 @@ func TestGetPerpetualFeePpm(t *testing.T) { // Set up user bonded tokens if tc.userBondedTokens != nil { - statsKeeper.UnsafeSetCachedStakedAmount(ctx, tc.user, &stattypes.CachedStakeAmount{ - StakedAmount: dtypes.NewIntFromBigInt(tc.userBondedTokens), - CachedAt: ctx.BlockTime().Unix(), + statsKeeper.UnsafeSetCachedStakedBaseTokens(ctx, tc.user, &stattypes.CachedStakedBaseTokens{ + StakedBaseTokens: dtypes.NewIntFromBigInt(tc.userBondedTokens), + CachedAt: ctx.BlockTime().Unix(), }) } diff --git a/protocol/x/feetiers/types/expected_keepers.go b/protocol/x/feetiers/types/expected_keepers.go index eb8e54eb16..f8a5f40805 100644 --- a/protocol/x/feetiers/types/expected_keepers.go +++ b/protocol/x/feetiers/types/expected_keepers.go @@ -13,7 +13,7 @@ import ( type StatsKeeper interface { GetUserStats(ctx sdk.Context, address string) *statstypes.UserStats GetGlobalStats(ctx sdk.Context) *statstypes.GlobalStats - GetStakedAmount(ctx sdk.Context, delegatorAddr string) *big.Int + GetStakedBaseTokens(ctx sdk.Context, delegatorAddr string) *big.Int } // VaultKeeper defines the expected vault keeper. diff --git a/protocol/x/stats/keeper/keeper.go b/protocol/x/stats/keeper/keeper.go index 472d6e525b..a99efb8411 100644 --- a/protocol/x/stats/keeper/keeper.go +++ b/protocol/x/stats/keeper/keeper.go @@ -294,49 +294,49 @@ func (k Keeper) ExpireOldStats(ctx sdk.Context) { k.SetStatsMetadata(ctx, metadata) } -// GetStakedAmount returns the total staked amount for a delegator address. +// GetStakedBaseTokens returns the total staked base tokens for a delegator address. // It maintains a cache to optimize performance. The function first checks // if there's a cached value that hasn't expired. If found, it returns the // cached amount. Otherwise, it calculates the staked amount by querying -// the staking keeper, caches the result, and returns the calculated amount -func (k Keeper) GetStakedAmount(ctx sdk.Context, +// the staking keeper, caches the result, and returns the calculated amount. +func (k Keeper) GetStakedBaseTokens(ctx sdk.Context, delegatorAddr string) *big.Int { startTime := time.Now() - stakedAmount := big.NewInt(0) + stakedBaseTokens := big.NewInt(0) store := prefix.NewStore(ctx.KVStore(k.storeKey), []byte(types.CachedStakeAmountKeyPrefix)) bytes := store.Get([]byte(delegatorAddr)) // return cached value if it's not expired if bytes != nil { - var cachedStakedAmount types.CachedStakeAmount - k.cdc.MustUnmarshal(bytes, &cachedStakedAmount) + var cachedStakedBaseTokens types.CachedStakedBaseTokens + k.cdc.MustUnmarshal(bytes, &cachedStakedBaseTokens) // sanity checks - if cachedStakedAmount.CachedAt < 0 { - panic("cachedStakedAmount.CachedAt is negative") + if cachedStakedBaseTokens.CachedAt < 0 { + panic("cachedStakedBaseTokens.CachedAt is negative") } if ctx.BlockTime().Unix() < 0 { panic("Invariant violation: ctx.BlockTime().Unix() is negative") } - if cachedStakedAmount.CachedAt < 0 { - panic("Invariant violation: cachedStakedAmount.CachedAt is negative") + if cachedStakedBaseTokens.CachedAt < 0 { + panic("Invariant violation: cachedStakedBaseTokens.CachedAt is negative") } - if cachedStakedAmount.CachedAt > ctx.BlockTime().Unix() { - panic("Invariant violation: cachedStakedAmount.CachedAt is greater than blocktime") + if cachedStakedBaseTokens.CachedAt > ctx.BlockTime().Unix() { + panic("Invariant violation: cachedStakedBaseTokens.CachedAt is greater than blocktime") } - if ctx.BlockTime().Unix()-cachedStakedAmount.CachedAt <= types.StakedAmountCacheDurationSeconds { - stakedAmount.Set(cachedStakedAmount.StakedAmount.BigInt()) - metrics.IncrCounterWithLabels(metrics.StatsGetStakedAmountCacheHit, 1) + if ctx.BlockTime().Unix()-cachedStakedBaseTokens.CachedAt <= types.StakedBaseTokensCacheDurationSeconds { + stakedBaseTokens.Set(cachedStakedBaseTokens.StakedBaseTokens.BigInt()) + metrics.IncrCounterWithLabels(metrics.StatsGetStakedBaseTokensCacheHit, 1) telemetry.MeasureSince( startTime, types.ModuleName, - metrics.StatsGetStakedAmountLatencyCacheHit, + metrics.StatsGetStakedBaseTokensLatencyCacheHit, metrics.Latency, ) - return stakedAmount + return stakedBaseTokens } } - metrics.IncrCounterWithLabels(metrics.StatsGetStakedAmountCacheMiss, 1) + metrics.IncrCounterWithLabels(metrics.StatsGetStakedBaseTokensCacheMiss, 1) // calculate staked amount delegator, err := sdk.AccAddressFromBech32(delegatorAddr) @@ -350,26 +350,41 @@ func (k Keeper) GetStakedAmount(ctx sdk.Context, } for _, delegation := range delegations { - stakedAmount.Add(stakedAmount, delegation.GetShares().RoundInt().BigInt()) + // Get the validator to convert shares to tokens + valAddr, err := sdk.ValAddressFromBech32(delegation.GetValidatorAddr()) + if err != nil { + // If invalid validator address, skip this delegation + continue + } + + validator, err := k.stakingKeeper.GetValidator(ctx, valAddr) + if err != nil { + // If validator not found, skip this delegation + continue + } + + // Convert shares to tokens using validator exchange rate + tokens := validator.TokensFromShares(delegation.GetShares()) + stakedBaseTokens.Add(stakedBaseTokens, tokens.RoundInt().BigInt()) } // update cache - cachedStakedAmount := types.CachedStakeAmount{ - StakedAmount: dtypes.NewIntFromBigInt(stakedAmount), - CachedAt: ctx.BlockTime().Unix(), + cachedStakedBaseTokens := types.CachedStakedBaseTokens{ + StakedBaseTokens: dtypes.NewIntFromBigInt(stakedBaseTokens), + CachedAt: ctx.BlockTime().Unix(), } - store.Set([]byte(delegatorAddr), k.cdc.MustMarshal(&cachedStakedAmount)) + store.Set([]byte(delegatorAddr), k.cdc.MustMarshal(&cachedStakedBaseTokens)) telemetry.MeasureSince( startTime, types.ModuleName, - metrics.StatsGetStakedAmountLatencyCacheMiss, + metrics.StatsGetStakedBaseTokensLatencyCacheMiss, metrics.Latency, ) - return stakedAmount + return stakedBaseTokens } -func (k Keeper) UnsafeSetCachedStakedAmount(ctx sdk.Context, delegatorAddr string, - cachedStakedAmount *types.CachedStakeAmount) { +func (k Keeper) UnsafeSetCachedStakedBaseTokens(ctx sdk.Context, delegatorAddr string, + cachedStakedBaseTokens *types.CachedStakedBaseTokens) { store := prefix.NewStore(ctx.KVStore(k.storeKey), []byte(types.CachedStakeAmountKeyPrefix)) - store.Set([]byte(delegatorAddr), k.cdc.MustMarshal(cachedStakedAmount)) + store.Set([]byte(delegatorAddr), k.cdc.MustMarshal(cachedStakedBaseTokens)) } diff --git a/protocol/x/stats/keeper/keeper_test.go b/protocol/x/stats/keeper/keeper_test.go index e0690a49e1..3b8b55af94 100644 --- a/protocol/x/stats/keeper/keeper_test.go +++ b/protocol/x/stats/keeper/keeper_test.go @@ -297,22 +297,36 @@ func TestExpireOldStats(t *testing.T) { require.NotNil(t, k.GetEpochStatsOrNil(ctx, uint32(12))) } -func TestGetStakedAmount(t *testing.T) { +func TestGetStakedBaseTokens(t *testing.T) { testCases := []struct { - name string - wholeCoinsToStake uint32 + name string + userShares uint32 + validatorTotalTokens uint32 + validatorTotalShares uint32 }{ { - name: "100 whole coins staked", - wholeCoinsToStake: 100, + name: "1 share = 1 base token", + userShares: 100, + validatorTotalTokens: 1000, + validatorTotalShares: 1000, }, { - name: "100,000 whole coins staked", - wholeCoinsToStake: 100_000, + name: "1 share = 1.5 base tokens", + userShares: 100, + validatorTotalTokens: 1500, + validatorTotalShares: 1000, }, { - name: "0 coins staked", - wholeCoinsToStake: 0, + name: "1 share = 2 base tokens", + userShares: 100, + validatorTotalTokens: 2000, + validatorTotalShares: 1000, + }, + { + name: "1 share = 0.5 base tokens", + userShares: 100, + validatorTotalTokens: 500, + validatorTotalShares: 1000, }, } @@ -322,24 +336,43 @@ func TestGetStakedAmount(t *testing.T) { ctx := tApp.InitChain() statsKeeper := tApp.App.StatsKeeper stakingKeeper := tApp.App.StakingKeeper + expMultiplier, _ := lib.BigPow10(-lib.BaseDenomExponent) - coinsToStakeQuantums := new(big.Int).Mul( - lib.BigU(tc.wholeCoinsToStake), - expMultiplier, + + // Set validator's tokens and shares + validator, err := stakingKeeper.GetValidator(ctx, constants.AliceValAddress) + require.NoError(t, err) + + validator.Tokens = math.NewIntFromBigInt( + new(big.Int).Mul(lib.BigU(tc.validatorTotalTokens), expMultiplier), ) + validator.DelegatorShares = math.LegacyNewDecFromBigInt( + new(big.Int).Mul(lib.BigU(tc.validatorTotalShares), expMultiplier), + ) + err = stakingKeeper.SetValidator(ctx, validator) + require.NoError(t, err) + + // Create user delegation + userSharesBigInt := new(big.Int).Mul(lib.BigU(tc.userShares), expMultiplier) delegation := stakingtypes.NewDelegation( - constants.AliceAccAddress.String(), constants.AliceValAddress.String(), - math.LegacyNewDecFromBigInt(coinsToStakeQuantums)) - err := stakingKeeper.SetDelegation(ctx, delegation) + constants.AliceAccAddress.String(), + constants.AliceValAddress.String(), + math.LegacyNewDecFromBigInt(userSharesBigInt), + ) + err = stakingKeeper.SetDelegation(ctx, delegation) require.NoError(t, err) - receivedCoins := statsKeeper.GetStakedAmount(ctx, constants.AliceAccAddress.String()) - require.Equal(t, coinsToStakeQuantums, receivedCoins) + // User should have `userShares * (validator tokens / validator shares)` number of base tokens + expectedTokens := new(big.Int).Mul(userSharesBigInt, lib.BigU(tc.validatorTotalTokens)) + expectedTokens.Div(expectedTokens, lib.BigU(tc.validatorTotalShares)) + + actualTokens := statsKeeper.GetStakedBaseTokens(ctx, constants.AliceAccAddress.String()) + require.Equal(t, expectedTokens, actualTokens) }) } } -func TestGetStakedAmount_Cache_Hit(t *testing.T) { +func TestGetStakedBaseTokens_Cache_Hit(t *testing.T) { tApp := testapp.NewTestAppBuilder(t).Build() ctx := tApp.InitChain() statsKeeper := tApp.App.StatsKeeper @@ -348,16 +381,16 @@ func TestGetStakedAmount_Cache_Hit(t *testing.T) { lib.BigI(100), expMultiplier, ) - statsKeeper.UnsafeSetCachedStakedAmount(ctx, constants.AliceAccAddress.String(), &types.CachedStakeAmount{ - StakedAmount: dtypes.NewIntFromBigInt(coinsToStakeQuantums), - CachedAt: ctx.BlockTime().Unix(), + statsKeeper.UnsafeSetCachedStakedBaseTokens(ctx, constants.AliceAccAddress.String(), &types.CachedStakedBaseTokens{ + StakedBaseTokens: dtypes.NewIntFromBigInt(coinsToStakeQuantums), + CachedAt: ctx.BlockTime().Unix(), }) - receivedCoins := statsKeeper.GetStakedAmount(ctx, constants.AliceAccAddress.String()) + receivedCoins := statsKeeper.GetStakedBaseTokens(ctx, constants.AliceAccAddress.String()) require.Equal(t, coinsToStakeQuantums, receivedCoins) } -func TestGetStakedAmount_Cache_Miss(t *testing.T) { +func TestGetStakedBaseTokens_Cache_Miss(t *testing.T) { tApp := testapp.NewTestAppBuilder(t).Build() ctx := tApp.InitChain() statsKeeper := tApp.App.StatsKeeper @@ -376,9 +409,9 @@ func TestGetStakedAmount_Cache_Miss(t *testing.T) { ) // set expired delegation - statsKeeper.UnsafeSetCachedStakedAmount(ctx, constants.AliceAccAddress.String(), &types.CachedStakeAmount{ - StakedAmount: dtypes.NewIntFromBigInt(expiredCoinsToStakeQuantums), - CachedAt: ctx.BlockTime().Unix(), + statsKeeper.UnsafeSetCachedStakedBaseTokens(ctx, constants.AliceAccAddress.String(), &types.CachedStakedBaseTokens{ + StakedBaseTokens: dtypes.NewIntFromBigInt(expiredCoinsToStakeQuantums), + CachedAt: ctx.BlockTime().Unix(), }) ctx = ctx.WithBlockTime(ctx.BlockTime().Add(time.Duration(epochstypes.StatsEpochDuration+1) * time.Second)) @@ -389,6 +422,6 @@ func TestGetStakedAmount_Cache_Miss(t *testing.T) { err := stakingKeeper.SetDelegation(ctx, delegation) require.NoError(t, err) - receivedCoins := statsKeeper.GetStakedAmount(ctx, constants.AliceAccAddress.String()) + receivedCoins := statsKeeper.GetStakedBaseTokens(ctx, constants.AliceAccAddress.String()) require.Equal(t, latestCoinsToStakeQuantums, receivedCoins) } diff --git a/protocol/x/stats/types/constants.go b/protocol/x/stats/types/constants.go index f5a8b8ad86..2d2aa33bb9 100644 --- a/protocol/x/stats/types/constants.go +++ b/protocol/x/stats/types/constants.go @@ -1,4 +1,4 @@ package types -// Staked amount cache duration set to 15 minutes -const StakedAmountCacheDurationSeconds int64 = 900 +// Staked base tokens cache duration set to 15 minutes +const StakedBaseTokensCacheDurationSeconds int64 = 900 diff --git a/protocol/x/stats/types/expected_keepers.go b/protocol/x/stats/types/expected_keepers.go index a33ee70d27..7cdcd0a5f8 100644 --- a/protocol/x/stats/types/expected_keepers.go +++ b/protocol/x/stats/types/expected_keepers.go @@ -16,4 +16,5 @@ type EpochsKeeper interface { type StakingKeeper interface { GetDelegatorDelegations(ctx context.Context, delegator sdk.AccAddress, maxRetrieve uint16) ([]stakingtypes.Delegation, error) + GetValidator(ctx context.Context, addr sdk.ValAddress) (stakingtypes.Validator, error) } diff --git a/protocol/x/stats/types/stats.pb.go b/protocol/x/stats/types/stats.pb.go index 6198e03f19..f9fa866ae3 100644 --- a/protocol/x/stats/types/stats.pb.go +++ b/protocol/x/stats/types/stats.pb.go @@ -425,27 +425,27 @@ func (m *UserStats) GetAffiliate_30DReferredVolumeQuoteQuantums() uint64 { return 0 } -// CachedStakeAmount stores the last calculated total staked amount for address -type CachedStakeAmount struct { - // Last calculated total staked amount by the delegator (in coin amount). - StakedAmount github_com_dydxprotocol_v4_chain_protocol_dtypes.SerializableInt `protobuf:"bytes,1,opt,name=staked_amount,json=stakedAmount,proto3,customtype=github.com/dydxprotocol/v4-chain/protocol/dtypes.SerializableInt" json:"staked_amount"` +// CachedStakedBaseTokens stores the last calculated total staked base tokens +type CachedStakedBaseTokens struct { + // Last calculated total staked base tokens by the delegator. + StakedBaseTokens github_com_dydxprotocol_v4_chain_protocol_dtypes.SerializableInt `protobuf:"bytes,1,opt,name=staked_base_tokens,json=stakedBaseTokens,proto3,customtype=github.com/dydxprotocol/v4-chain/protocol/dtypes.SerializableInt" json:"staked_base_tokens"` // Block time at which the calculation is cached (in Unix Epoch seconds) // Rounded down to nearest second. CachedAt int64 `protobuf:"varint,2,opt,name=cached_at,json=cachedAt,proto3" json:"cached_at,omitempty"` } -func (m *CachedStakeAmount) Reset() { *m = CachedStakeAmount{} } -func (m *CachedStakeAmount) String() string { return proto.CompactTextString(m) } -func (*CachedStakeAmount) ProtoMessage() {} -func (*CachedStakeAmount) Descriptor() ([]byte, []int) { +func (m *CachedStakedBaseTokens) Reset() { *m = CachedStakedBaseTokens{} } +func (m *CachedStakedBaseTokens) String() string { return proto.CompactTextString(m) } +func (*CachedStakedBaseTokens) ProtoMessage() {} +func (*CachedStakedBaseTokens) Descriptor() ([]byte, []int) { return fileDescriptor_07475747e6dcccdc, []int{5} } -func (m *CachedStakeAmount) XXX_Unmarshal(b []byte) error { +func (m *CachedStakedBaseTokens) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) } -func (m *CachedStakeAmount) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { +func (m *CachedStakedBaseTokens) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { if deterministic { - return xxx_messageInfo_CachedStakeAmount.Marshal(b, m, deterministic) + return xxx_messageInfo_CachedStakedBaseTokens.Marshal(b, m, deterministic) } else { b = b[:cap(b)] n, err := m.MarshalToSizedBuffer(b) @@ -455,19 +455,19 @@ func (m *CachedStakeAmount) XXX_Marshal(b []byte, deterministic bool) ([]byte, e return b[:n], nil } } -func (m *CachedStakeAmount) XXX_Merge(src proto.Message) { - xxx_messageInfo_CachedStakeAmount.Merge(m, src) +func (m *CachedStakedBaseTokens) XXX_Merge(src proto.Message) { + xxx_messageInfo_CachedStakedBaseTokens.Merge(m, src) } -func (m *CachedStakeAmount) XXX_Size() int { +func (m *CachedStakedBaseTokens) XXX_Size() int { return m.Size() } -func (m *CachedStakeAmount) XXX_DiscardUnknown() { - xxx_messageInfo_CachedStakeAmount.DiscardUnknown(m) +func (m *CachedStakedBaseTokens) XXX_DiscardUnknown() { + xxx_messageInfo_CachedStakedBaseTokens.DiscardUnknown(m) } -var xxx_messageInfo_CachedStakeAmount proto.InternalMessageInfo +var xxx_messageInfo_CachedStakedBaseTokens proto.InternalMessageInfo -func (m *CachedStakeAmount) GetCachedAt() int64 { +func (m *CachedStakedBaseTokens) GetCachedAt() int64 { if m != nil { return m.CachedAt } @@ -482,54 +482,55 @@ func init() { proto.RegisterType((*EpochStats_UserWithStats)(nil), "dydxprotocol.stats.EpochStats.UserWithStats") proto.RegisterType((*GlobalStats)(nil), "dydxprotocol.stats.GlobalStats") proto.RegisterType((*UserStats)(nil), "dydxprotocol.stats.UserStats") - proto.RegisterType((*CachedStakeAmount)(nil), "dydxprotocol.stats.CachedStakeAmount") + proto.RegisterType((*CachedStakedBaseTokens)(nil), "dydxprotocol.stats.CachedStakedBaseTokens") } func init() { proto.RegisterFile("dydxprotocol/stats/stats.proto", fileDescriptor_07475747e6dcccdc) } var fileDescriptor_07475747e6dcccdc = []byte{ - // 651 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x54, 0xc1, 0x4f, 0x13, 0x4f, - 0x14, 0xee, 0x96, 0xf2, 0x0b, 0x0c, 0xb4, 0xbf, 0xb8, 0xe1, 0xd0, 0xd4, 0xd0, 0x36, 0x55, 0x42, - 0x0f, 0xb8, 0x25, 0xd4, 0x60, 0xbc, 0x49, 0x0d, 0xa0, 0x26, 0x9a, 0xb0, 0x20, 0x1a, 0x13, 0xb3, - 0x99, 0xee, 0xbc, 0x6e, 0x27, 0xcc, 0xee, 0x94, 0xdd, 0x59, 0x02, 0xfe, 0x15, 0xdc, 0x3c, 0xfa, - 0xef, 0x70, 0xe4, 0x68, 0x3c, 0xa0, 0xc2, 0xff, 0xe0, 0xd9, 0xcc, 0x1b, 0x76, 0x4b, 0x81, 0x83, - 0x97, 0x66, 0xde, 0x37, 0xdf, 0xf7, 0xbd, 0xd7, 0x6f, 0x5e, 0x96, 0xd4, 0xd9, 0x09, 0x3b, 0x1e, - 0xc5, 0x52, 0x49, 0x5f, 0x8a, 0x4e, 0xa2, 0xa8, 0x4a, 0xcc, 0xaf, 0x83, 0xa0, 0x6d, 0xdf, 0xbc, - 0x77, 0xf0, 0xa6, 0xb6, 0x10, 0xc8, 0x40, 0x22, 0xd6, 0xd1, 0x27, 0xc3, 0xac, 0x35, 0x02, 0x29, - 0x03, 0x01, 0x1d, 0xac, 0xfa, 0xe9, 0xa0, 0xa3, 0x78, 0x08, 0x89, 0xa2, 0xe1, 0xc8, 0x10, 0x5a, - 0xbf, 0x2d, 0x42, 0x7a, 0x42, 0xfa, 0x07, 0xbb, 0xda, 0xc5, 0x7e, 0x4e, 0xa6, 0x07, 0x5c, 0x88, - 0xa4, 0x6a, 0x35, 0xa7, 0xda, 0x73, 0x6b, 0x8f, 0x9c, 0xbb, 0x9d, 0x9c, 0x31, 0xdd, 0xd9, 0xe2, - 0x42, 0xb8, 0x46, 0x51, 0xfb, 0x6a, 0x91, 0x92, 0xae, 0xed, 0x05, 0x32, 0xad, 0xe8, 0x01, 0xc4, - 0x55, 0xab, 0x69, 0xb5, 0x67, 0x5d, 0x53, 0x68, 0x34, 0x44, 0xb4, 0x68, 0x50, 0x2c, 0xec, 0x1a, - 0x99, 0x89, 0xa4, 0xe2, 0x32, 0xa2, 0xa2, 0x3a, 0xd5, 0xb4, 0xda, 0x25, 0x37, 0xaf, 0xed, 0x6d, - 0xd2, 0xa4, 0x83, 0x01, 0x17, 0x9c, 0x2a, 0xf0, 0x06, 0x00, 0x5e, 0x00, 0x11, 0xc4, 0x54, 0x01, - 0xf3, 0x0e, 0x53, 0x1a, 0xa9, 0x34, 0x4c, 0xaa, 0x25, 0xd4, 0x2c, 0xe6, 0xbc, 0x2d, 0x80, 0xed, - 0x8c, 0xb5, 0x73, 0x4d, 0x6a, 0xad, 0x93, 0x32, 0x8e, 0xfb, 0x16, 0x14, 0x65, 0x54, 0x51, 0x7b, - 0x89, 0x54, 0x54, 0x4c, 0xb9, 0xe0, 0x51, 0xe0, 0xc1, 0x48, 0xfa, 0x43, 0x1c, 0xb5, 0xec, 0x96, - 0x33, 0x74, 0x53, 0x83, 0xad, 0x3f, 0x16, 0x21, 0x78, 0x32, 0xd9, 0xbc, 0x21, 0x15, 0x24, 0x7b, - 0x10, 0x31, 0x4f, 0xe7, 0x88, 0xaa, 0xb9, 0xb5, 0x9a, 0x63, 0x42, 0x76, 0xb2, 0x90, 0x9d, 0xbd, - 0x2c, 0xe4, 0xde, 0xcc, 0xd9, 0x45, 0xa3, 0x70, 0x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, 0xa4, 0xfe, - 0x10, 0xd8, 0xae, 0xfe, 0xdb, 0x1b, 0xa1, 0x4c, 0x23, 0x65, 0x87, 0xa4, 0x9c, 0xe8, 0x92, 0x79, - 0x14, 0x01, 0x4c, 0x66, 0xbe, 0xf7, 0x4a, 0x6f, 0xcb, 0x8f, 0x8b, 0xc6, 0x8b, 0x80, 0xab, 0x61, - 0xda, 0x77, 0x7c, 0x19, 0x76, 0x26, 0x3e, 0x05, 0x47, 0x4f, 0x9f, 0xf8, 0x43, 0xca, 0xa3, 0x4e, - 0x8e, 0x30, 0x75, 0x32, 0x82, 0xc4, 0xd9, 0x85, 0x98, 0x53, 0xc1, 0xbf, 0xd0, 0xbe, 0x80, 0xd7, - 0x91, 0x72, 0xe7, 0x8d, 0xfd, 0x75, 0xbb, 0x87, 0x64, 0xd6, 0xc7, 0x19, 0x3c, 0xaa, 0x30, 0xdd, - 0x29, 0x77, 0xc6, 0x00, 0x1b, 0xaa, 0xb7, 0x73, 0x76, 0x59, 0xb7, 0xce, 0x2f, 0xeb, 0xd6, 0xaf, - 0xcb, 0xba, 0x75, 0x7a, 0x55, 0x2f, 0x9c, 0x5f, 0xd5, 0x0b, 0xdf, 0xaf, 0xea, 0x85, 0x4f, 0xcf, - 0xfe, 0x7d, 0x8c, 0xe3, 0xeb, 0xaf, 0x14, 0x4e, 0xd3, 0xff, 0x0f, 0xf1, 0xee, 0xdf, 0x00, 0x00, - 0x00, 0xff, 0xff, 0x5e, 0x82, 0xca, 0x98, 0xc8, 0x04, 0x00, 0x00, + // 659 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x94, 0xcf, 0x4e, 0xdb, 0x4a, + 0x14, 0xc6, 0xe3, 0x10, 0xae, 0x60, 0x20, 0xb9, 0x57, 0x23, 0x74, 0x15, 0xe5, 0x8a, 0x24, 0xca, + 0x2d, 0x22, 0x0b, 0xea, 0x20, 0x52, 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xff, 0xc4, 0xb7, 0xfb, 0xfe, + 0x47, 0xe6, 0x5d, 0x9c, 0x88, 0x71, 0x8d, 0x5e, 0xcf, 0x38, 0x73, 0x06, 0x3c, 0xd3, 0xbd, 0xdd, + 0xb3, 0xcb, 0xba, 0x75, 0x7e, 0x59, 0xb7, 0x7e, 0x5c, 0xd6, 0xad, 0xd3, 0xab, 0x7a, 0xe1, 0xfc, + 0xaa, 0x5e, 0xf8, 0x7a, 0x55, 0x2f, 0x7c, 0x78, 0xfc, 0xe7, 0xa3, 0x1c, 0x5f, 0x7f, 0xb3, 0x70, + 0xa2, 0xfe, 0x5f, 0xc8, 0xbb, 0xbf, 0x03, 0x00, 0x00, 0xff, 0xff, 0x78, 0xda, 0x4e, 0x4b, 0xd6, + 0x04, 0x00, 0x00, } func (m *BlockStats) Marshal() (dAtA []byte, err error) { @@ -802,7 +803,7 @@ func (m *UserStats) MarshalToSizedBuffer(dAtA []byte) (int, error) { return len(dAtA) - i, nil } -func (m *CachedStakeAmount) Marshal() (dAtA []byte, err error) { +func (m *CachedStakedBaseTokens) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) n, err := m.MarshalToSizedBuffer(dAtA[:size]) @@ -812,12 +813,12 @@ func (m *CachedStakeAmount) Marshal() (dAtA []byte, err error) { return dAtA[:n], nil } -func (m *CachedStakeAmount) MarshalTo(dAtA []byte) (int, error) { +func (m *CachedStakedBaseTokens) MarshalTo(dAtA []byte) (int, error) { size := m.Size() return m.MarshalToSizedBuffer(dAtA[:size]) } -func (m *CachedStakeAmount) MarshalToSizedBuffer(dAtA []byte) (int, error) { +func (m *CachedStakedBaseTokens) MarshalToSizedBuffer(dAtA []byte) (int, error) { i := len(dAtA) _ = i var l int @@ -828,9 +829,9 @@ func (m *CachedStakeAmount) MarshalToSizedBuffer(dAtA []byte) (int, error) { dAtA[i] = 0x10 } { - size := m.StakedAmount.Size() + size := m.StakedBaseTokens.Size() i -= size - if _, err := m.StakedAmount.MarshalTo(dAtA[i:]); err != nil { + if _, err := m.StakedBaseTokens.MarshalTo(dAtA[i:]); err != nil { return 0, err } i = encodeVarintStats(dAtA, i, uint64(size)) @@ -968,13 +969,13 @@ func (m *UserStats) Size() (n int) { return n } -func (m *CachedStakeAmount) Size() (n int) { +func (m *CachedStakedBaseTokens) Size() (n int) { if m == nil { return 0 } var l int _ = l - l = m.StakedAmount.Size() + l = m.StakedBaseTokens.Size() n += 1 + l + sovStats(uint64(l)) if m.CachedAt != 0 { n += 1 + sovStats(uint64(m.CachedAt)) @@ -1723,7 +1724,7 @@ func (m *UserStats) Unmarshal(dAtA []byte) error { } return nil } -func (m *CachedStakeAmount) Unmarshal(dAtA []byte) error { +func (m *CachedStakedBaseTokens) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 for iNdEx < l { @@ -1746,15 +1747,15 @@ func (m *CachedStakeAmount) Unmarshal(dAtA []byte) error { fieldNum := int32(wire >> 3) wireType := int(wire & 0x7) if wireType == 4 { - return fmt.Errorf("proto: CachedStakeAmount: wiretype end group for non-group") + return fmt.Errorf("proto: CachedStakedBaseTokens: wiretype end group for non-group") } if fieldNum <= 0 { - return fmt.Errorf("proto: CachedStakeAmount: illegal tag %d (wire type %d)", fieldNum, wire) + return fmt.Errorf("proto: CachedStakedBaseTokens: illegal tag %d (wire type %d)", fieldNum, wire) } switch fieldNum { case 1: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field StakedAmount", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field StakedBaseTokens", wireType) } var byteLen int for shift := uint(0); ; shift += 7 { @@ -1781,7 +1782,7 @@ func (m *CachedStakeAmount) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - if err := m.StakedAmount.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + if err := m.StakedBaseTokens.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { return err } iNdEx = postIndex