diff --git a/docs/static/openapi.yml b/docs/static/openapi.yml index d3d7eec74..323c94293 100644 --- a/docs/static/openapi.yml +++ b/docs/static/openapi.yml @@ -39454,53 +39454,6 @@ paths: type: boolean tags: - Query - /elys-network/elys/incentive/apr/{withdraw_type}/{denom}: - get: - summary: Calculate APR - operationId: ElysIncentiveApr - responses: - '200': - description: A successful response. - schema: - type: object - properties: - apr: - type: string - default: - description: An unexpected error response. - schema: - type: object - properties: - code: - type: integer - format: int32 - message: - type: string - details: - type: array - items: - type: object - properties: - '@type': - type: string - additionalProperties: {} - parameters: - - name: withdraw_type - in: path - required: true - type: string - enum: - - ALL_PROGRAM - - USDC_PROGRAM - - ELYS_PROGRAM - - EDEN_PROGRAM - - EDENB_PROGRAM - - name: denom - in: path - required: true - type: string - tags: - - Query /elys-network/elys/incentive/community_pool: get: summary: Queries a list of CommunityPool items. @@ -39578,9 +39531,9 @@ paths: total_blocks_per_year: type: string title: distribution duration - block number per year - epoch_num_blocks: + allocation_epoch_in_blocks: type: string - title: we set block count in 24 hrs + title: we set block numbers in 24 hrs max_eden_per_allocation: type: string title: >- @@ -39610,9 +39563,9 @@ paths: total_blocks_per_year: type: string title: distribution duration - block number per year - epoch_num_blocks: + allocation_epoch_in_blocks: type: string - title: we set block count in 24 hrs + title: we set block numbers in 24 hrs max_eden_per_allocation: type: string title: >- @@ -83984,9 +83937,9 @@ definitions: total_blocks_per_year: type: string title: distribution duration - block number per year - epoch_num_blocks: + allocation_epoch_in_blocks: type: string - title: we set block count in 24 hrs + title: we set block numbers in 24 hrs max_eden_per_allocation: type: string title: maximum eden allocation per day that won't exceed 30% apr @@ -84031,9 +83984,9 @@ definitions: total_blocks_per_year: type: string title: distribution duration - block number per year - epoch_num_blocks: + allocation_epoch_in_blocks: type: string - title: we set block count in 24 hrs + title: we set block numbers in 24 hrs max_eden_per_allocation: type: string title: maximum eden allocation per day that won't exceed 30% apr @@ -84061,9 +84014,9 @@ definitions: total_blocks_per_year: type: string title: distribution duration - block number per year - epoch_num_blocks: + allocation_epoch_in_blocks: type: string - title: we set block count in 24 hrs + title: we set block numbers in 24 hrs max_eden_per_allocation: type: string title: maximum eden allocation per day that won't exceed 30% apr @@ -84200,11 +84153,6 @@ definitions: format: uint64 multiplier: type: string - elys.incentive.QueryAprResponse: - type: object - properties: - apr: - type: string elys.incentive.QueryCommunityPoolResponse: type: object properties: @@ -84244,9 +84192,9 @@ definitions: total_blocks_per_year: type: string title: distribution duration - block number per year - epoch_num_blocks: + allocation_epoch_in_blocks: type: string - title: we set block count in 24 hrs + title: we set block numbers in 24 hrs max_eden_per_allocation: type: string title: maximum eden allocation per day that won't exceed 30% apr @@ -84274,9 +84222,9 @@ definitions: total_blocks_per_year: type: string title: distribution duration - block number per year - epoch_num_blocks: + allocation_epoch_in_blocks: type: string - title: we set block count in 24 hrs + title: we set block numbers in 24 hrs max_eden_per_allocation: type: string title: maximum eden allocation per day that won't exceed 30% apr diff --git a/proto/elys/incentive/incentive.proto b/proto/elys/incentive/incentive.proto index faf76b795..cbe6dfe79 100644 --- a/proto/elys/incentive/incentive.proto +++ b/proto/elys/incentive/incentive.proto @@ -16,8 +16,8 @@ message IncentiveInfo { // distribution duration - block number per year string total_blocks_per_year = 3 [ (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int", (gogoproto.nullable) = false]; - // we set block count in 24 hrs - string epoch_num_blocks = 4 + // we set block numbers in 24 hrs + string allocation_epoch_in_blocks = 4 [ (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int", (gogoproto.nullable) = false]; // maximum eden allocation per day that won't exceed 30% apr string max_eden_per_allocation = 5 diff --git a/x/incentive/keeper/abci.go b/x/incentive/keeper/abci.go index b3bd745d3..22aa2bc8e 100644 --- a/x/incentive/keeper/abci.go +++ b/x/incentive/keeper/abci.go @@ -105,14 +105,14 @@ func (k Keeper) ProcessUpdateIncentiveParams(ctx sdk.Context) bool { // ------------- LP Incentive parameter ------------- // ptypes.DaysPerYear is guaranteed to be positive as it is defined as a constant - EpochNumBlocks := totalBlocksPerYear.Quo(sdk.NewInt(ptypes.DaysPerYear)) + allocationEpochInblocks := totalBlocksPerYear.Quo(sdk.NewInt(ptypes.DaysPerYear)) totalDistributionEpochPerYear := totalBlocksPerYear.Quo(sdk.NewInt(params.DistributionEpochForLpsInBlocks)) // If totalDistributionEpochPerYear is zero, we skip this inflation to avoid division by zero if totalBlocksPerYear == sdk.ZeroInt() { continue } currentEpochInBlocks := sdk.NewInt(ctx.BlockHeight() - int64(inflation.StartBlockHeight)).Mul(totalDistributionEpochPerYear).Quo(totalBlocksPerYear) - maxEdenPerAllocation := sdk.NewInt(int64(inflation.Inflation.LmRewards)).Mul(EpochNumBlocks).Quo(totalBlocksPerYear) + maxEdenPerAllocation := sdk.NewInt(int64(inflation.Inflation.LmRewards)).Mul(allocationEpochInblocks).Quo(totalBlocksPerYear) incentiveInfo := types.IncentiveInfo{ // reward amount in eden for 1 year EdenAmountPerYear: sdk.NewInt(int64(inflation.Inflation.LmRewards)), @@ -121,7 +121,7 @@ func (k Keeper) ProcessUpdateIncentiveParams(ctx sdk.Context) bool { // distribution duration - block number per year TotalBlocksPerYear: totalBlocksPerYear, // we set block numbers in 24 hrs - EpochNumBlocks: EpochNumBlocks, + AllocationEpochInBlocks: allocationEpochInblocks, // maximum eden allocation per day that won't exceed 30% apr MaxEdenPerAllocation: maxEdenPerAllocation, // number of block intervals that distribute rewards. @@ -144,7 +144,7 @@ func (k Keeper) ProcessUpdateIncentiveParams(ctx sdk.Context) bool { params.LpIncentives[0].EdenAmountPerYear = incentiveInfo.EdenAmountPerYear params.LpIncentives[0].DistributionStartBlock = incentiveInfo.DistributionStartBlock params.LpIncentives[0].TotalBlocksPerYear = incentiveInfo.TotalBlocksPerYear - params.LpIncentives[0].EpochNumBlocks = incentiveInfo.EpochNumBlocks + params.LpIncentives[0].AllocationEpochInBlocks = incentiveInfo.AllocationEpochInBlocks params.LpIncentives[0].DistributionEpochInBlocks = incentiveInfo.DistributionEpochInBlocks params.LpIncentives[0].EdenBoostApr = incentiveInfo.EdenBoostApr } @@ -152,7 +152,7 @@ func (k Keeper) ProcessUpdateIncentiveParams(ctx sdk.Context) bool { // ------------- Stakers parameter ------------- totalDistributionEpochPerYear = totalBlocksPerYear.Quo(sdk.NewInt(params.DistributionEpochForStakersInBlocks)) currentEpochInBlocks = sdk.NewInt(ctx.BlockHeight() - int64(inflation.StartBlockHeight)).Mul(totalDistributionEpochPerYear).Quo(totalBlocksPerYear) - maxEdenPerAllocation = sdk.NewInt(int64(inflation.Inflation.IcsStakingRewards)).Mul(EpochNumBlocks).Quo(totalBlocksPerYear) + maxEdenPerAllocation = sdk.NewInt(int64(inflation.Inflation.IcsStakingRewards)).Mul(allocationEpochInblocks).Quo(totalBlocksPerYear) incentiveInfo = types.IncentiveInfo{ // reward amount in eden for 1 year EdenAmountPerYear: sdk.NewInt(int64(inflation.Inflation.IcsStakingRewards)), @@ -161,7 +161,7 @@ func (k Keeper) ProcessUpdateIncentiveParams(ctx sdk.Context) bool { // distribution duration - block number per year TotalBlocksPerYear: totalBlocksPerYear, // we set block numbers in 24 hrs - EpochNumBlocks: EpochNumBlocks, + AllocationEpochInBlocks: allocationEpochInblocks, // maximum eden allocation per day that won't exceed 30% apr MaxEdenPerAllocation: maxEdenPerAllocation, // number of block intervals that distribute rewards. @@ -184,7 +184,7 @@ func (k Keeper) ProcessUpdateIncentiveParams(ctx sdk.Context) bool { params.StakeIncentives[0].EdenAmountPerYear = incentiveInfo.EdenAmountPerYear params.StakeIncentives[0].DistributionStartBlock = incentiveInfo.DistributionStartBlock params.StakeIncentives[0].TotalBlocksPerYear = incentiveInfo.TotalBlocksPerYear - params.StakeIncentives[0].EpochNumBlocks = incentiveInfo.EpochNumBlocks + params.StakeIncentives[0].AllocationEpochInBlocks = incentiveInfo.AllocationEpochInBlocks params.StakeIncentives[0].DistributionEpochInBlocks = incentiveInfo.DistributionEpochInBlocks params.StakeIncentives[0].EdenBoostApr = incentiveInfo.EdenBoostApr } diff --git a/x/incentive/keeper/apr.go b/x/incentive/keeper/apr.go index f68423a5f..c4e586c29 100644 --- a/x/incentive/keeper/apr.go +++ b/x/incentive/keeper/apr.go @@ -48,16 +48,16 @@ func (k Keeper) CalculateApr(ctx sdk.Context, query *types.QueryAprRequest) (sdk // Calculate stable stake pool share. poolShare := k.CalculatePoolShareForStableStakeLPs(ctx, totalProxyTVL, baseCurrency) - // Eden amount for LP in 24hrs = EpochNumBlocks is the number of block for 24 hrs - epochEdenAmount := lpIncentive.EdenAmountPerYear.Mul(lpIncentive.EpochNumBlocks).Quo(lpIncentive.TotalBlocksPerYear) + // Eden amount for LP in 24hrs = AllocationEpochInBlocks is the number of block for 24 hrs + edenAmountPerDay := lpIncentive.EdenAmountPerYear.Mul(lpIncentive.AllocationEpochInBlocks).Quo(lpIncentive.TotalBlocksPerYear) - epochLpsMaxEdenAmount := params.MaxEdenRewardAprLps.Mul(totalProxyTVL).MulInt(lpIncentive.EpochNumBlocks).QuoInt(lpIncentive.TotalBlocksPerYear) + maxEdenAmountPerLps := params.MaxEdenRewardAprLps.Mul(totalProxyTVL).MulInt(lpIncentive.AllocationEpochInBlocks).QuoInt(lpIncentive.TotalBlocksPerYear) // Use min amount (eden allocation from tokenomics and max apr based eden amount) - epochEdenAmount = sdk.MinInt(epochEdenAmount, epochLpsMaxEdenAmount.TruncateInt()) + edenAmountPerDay = sdk.MinInt(edenAmountPerDay, maxEdenAmountPerLps.TruncateInt()) // Eden amount for stable stake LP in 24hrs - epochStableStakeEdenAmount := sdk.NewDecFromInt(epochEdenAmount).Mul(poolShare) + edenAmountPerStableStakePerDay := sdk.NewDecFromInt(edenAmountPerDay).Mul(poolShare) // Calc Eden price in usdc // We put Elys as denom as Eden won't be avaialble in amm pool and has the same value as Elys @@ -66,7 +66,7 @@ func (k Keeper) CalculateApr(ctx sdk.Context, query *types.QueryAprRequest) (sdk // Eden Apr for usdc earn program = {(Eden allocated for stable stake pool per day*365*price{eden/usdc}/(total usdc deposit)}*100 // we divide 100000 as we have use 100000elys as input in the price estimation - apr := epochStableStakeEdenAmount. + apr := edenAmountPerStableStakePerDay. MulInt(sdk.NewInt(ptypes.DaysPerYear)). MulInt(edenPrice). MulInt(sdk.NewInt(100)). @@ -86,22 +86,22 @@ func (k Keeper) CalculateApr(ctx sdk.Context, query *types.QueryAprRequest) (sdk } // Calculate - epochStakersEdenAmount := stkIncentive.EdenAmountPerYear. - Mul(stkIncentive.EpochNumBlocks). + edenAmountPerEpochStakersPerDay := stkIncentive.EdenAmountPerYear. + Mul(stkIncentive.AllocationEpochInBlocks). Quo(stkIncentive.TotalBlocksPerYear) // Maximum eden based per distribution epoch on maximum APR - 30% by default // Allocated for staking per day = (0.3/365)* ( total elys staked + total Eden committed + total Eden boost committed) - epochStakersMaxEdenAmount := params.MaxEdenRewardAprStakers. + maxEdenAmountPerStakers := params.MaxEdenRewardAprStakers. MulInt(totalStakedSnapshot). - MulInt(stkIncentive.EpochNumBlocks). + MulInt(stkIncentive.AllocationEpochInBlocks). QuoInt(stkIncentive.TotalBlocksPerYear) // Use min amount (eden allocation from tokenomics and max apr based eden amount) - epochStakersEdenAmount = sdk.MinInt(epochStakersEdenAmount, epochStakersMaxEdenAmount.TruncateInt()) + edenAmountPerEpochStakersPerDay = sdk.MinInt(edenAmountPerEpochStakersPerDay, maxEdenAmountPerStakers.TruncateInt()) // For Eden reward Apr for elys staking = {(amount of Eden allocated for staking per day)*365/( total elys staked + total Eden committed + total Eden boost committed)}*100 - apr := epochStakersEdenAmount. + apr := edenAmountPerEpochStakersPerDay. Mul(sdk.NewInt(ptypes.DaysPerYear)). Mul(sdk.NewInt(100)). Quo(totalStakedSnapshot) @@ -116,8 +116,8 @@ func (k Keeper) CalculateApr(ctx sdk.Context, query *types.QueryAprRequest) (sdk } else { // Elys staking, Eden committed, EdenB committed. params := k.GetParams(ctx) - amount := params.DexRewardsStakers.Amount - if amount.IsZero() { + amt := params.DexRewardsStakers.Amount + if amt.IsZero() { return sdk.ZeroInt(), nil } @@ -126,6 +126,10 @@ func (k Keeper) CalculateApr(ctx sdk.Context, query *types.QueryAprRequest) (sdk return sdk.ZeroInt(), nil } + // DexReward amount per day = amount distributed / duration(in seconds) * total seconds per day. + // AllocationEpochInBlocks is the number of the block per day + amtDexRewardPerDay := amt.MulInt(stkIncentive.AllocationEpochInBlocks).QuoInt(params.DexRewardsStakers.NumBlocks) + // Calc Eden price in usdc // We put Elys as denom as Eden won't be avaialble in amm pool and has the same value as Elys edenPrice := k.EstimatePrice(ctx, sdk.NewCoin(ptypes.Elys, sdk.NewInt(1000000)), baseCurrency) @@ -142,13 +146,9 @@ func (k Keeper) CalculateApr(ctx sdk.Context, query *types.QueryAprRequest) (sdk return sdk.ZeroInt(), nil } - // DexReward amount per day = amount distributed / duration(in seconds) * total seconds per day. - // EpochNumBlocks is the number of the block per day - dailyDexRewardAmount := amount.MulInt(stkIncentive.EpochNumBlocks).QuoInt(params.DexRewardsStakers.NumBlocks) - // Usdc apr for elys staking = (24 hour dex rewards in USDC generated for stakers) * 365*100/ {price ( elys/usdc)*( sum of (elys staked, Eden committed, Eden boost committed))} // we multiply 10 as we have use 10elys as input in the price estimation - apr := dailyDexRewardAmount. + apr := amtDexRewardPerDay. MulInt(sdk.NewInt(ptypes.DaysPerYear)). MulInt(sdk.NewInt(100)). MulInt(sdk.NewInt(1000000)). diff --git a/x/incentive/keeper/keeper.go b/x/incentive/keeper/keeper.go index 8b4726722..fc23241f6 100644 --- a/x/incentive/keeper/keeper.go +++ b/x/incentive/keeper/keeper.go @@ -131,23 +131,23 @@ func (k Keeper) UpdateStakersRewardsUnclaimed(ctx sdk.Context, stakeIncentive ty // Calculate eden amount per epoch params := k.GetParams(ctx) - // Ensure stakeIncentive.TotalBlocksPerYear or stakeIncentive.EpochNumBlocks are not zero to avoid division by zero - if stakeIncentive.TotalBlocksPerYear.IsZero() || stakeIncentive.EpochNumBlocks.IsZero() { + // Ensure stakeIncentive.TotalBlocksPerYear or stakeIncentive.AllocationEpochInBlocks are not zero to avoid division by zero + if stakeIncentive.TotalBlocksPerYear.IsZero() || stakeIncentive.AllocationEpochInBlocks.IsZero() { return errorsmod.Wrap(types.ErrNoInflationaryParams, "invalid inflationary params") } // Calculate - epochStakersEdenAmount := stakeIncentive.EdenAmountPerYear.Mul(stakeIncentive.EpochNumBlocks).Quo(stakeIncentive.TotalBlocksPerYear) + edenAmountPerEpochStakersPerDay := stakeIncentive.EdenAmountPerYear.Mul(stakeIncentive.AllocationEpochInBlocks).Quo(stakeIncentive.TotalBlocksPerYear) // Maximum eden based per distribution epoch on maximum APR - 30% by default // Allocated for staking per day = (0.3/365)* ( total elys staked + total Eden committed + total Eden boost committed) - epochStakersMaxEdenAmount := params.MaxEdenRewardAprStakers.MulInt(k.tci.TotalElysBonded.Add(k.tci.TotalEdenEdenBoostCommitted)).MulInt(stakeIncentive.EpochNumBlocks).QuoInt(stakeIncentive.TotalBlocksPerYear) + maxEdenAmountPerStakersPerDay := params.MaxEdenRewardAprStakers.MulInt(k.tci.TotalElysBonded.Add(k.tci.TotalEdenEdenBoostCommitted)).MulInt(stakeIncentive.AllocationEpochInBlocks).QuoInt(stakeIncentive.TotalBlocksPerYear) // Use min amount (eden allocation from tokenomics and max apr based eden amount) - epochStakersEdenAmount = sdk.MinInt(epochStakersEdenAmount, epochStakersMaxEdenAmount.TruncateInt()) + edenAmountPerEpochStakersPerDay = sdk.MinInt(edenAmountPerEpochStakersPerDay, maxEdenAmountPerStakersPerDay.TruncateInt()) // Calculate eden amount per distribution epoch - edenAmountPerEpochStakersPerDistribution := epochStakersEdenAmount.Mul(stakeIncentive.DistributionEpochInBlocks).Quo(stakeIncentive.EpochNumBlocks) + edenAmountPerEpochStakersPerDistribution := edenAmountPerEpochStakersPerDay.Mul(stakeIncentive.DistributionEpochInBlocks).Quo(stakeIncentive.AllocationEpochInBlocks) // Track the DEX rewards distribution for stakers // Add dexRevenue amount that was tracked by Lp tracker @@ -352,26 +352,26 @@ func (k Keeper) UpdateLPRewardsUnclaimed(ctx sdk.Context, lpIncentive types.Ince // Proxy TVL = 20*0.3+30*0.5+40*1.0 totalProxyTVL := k.CalculateProxyTVL(ctx, baseCurrency) - // Ensure lpIncentive.TotalBlocksPerYear or lpIncentive.EpochNumBlocks are not zero to avoid division by zero - if lpIncentive.TotalBlocksPerYear.IsZero() || lpIncentive.EpochNumBlocks.IsZero() { + // Ensure lpIncentive.TotalBlocksPerYear or lpIncentive.AllocationEpochInBlocks are not zero to avoid division by zero + if lpIncentive.TotalBlocksPerYear.IsZero() || lpIncentive.AllocationEpochInBlocks.IsZero() { return errorsmod.Wrap(types.ErrNoInflationaryParams, "invalid inflationary params") } // Calculate eden amount per epoch - epochLpsEdenAmount := lpIncentive.EdenAmountPerYear.Mul(lpIncentive.EpochNumBlocks).Quo(lpIncentive.TotalBlocksPerYear) + edenAmountPerEpochLPsPerDay := lpIncentive.EdenAmountPerYear.Mul(lpIncentive.AllocationEpochInBlocks).Quo(lpIncentive.TotalBlocksPerYear) // Track the DEX rewards distribution for stakers params := k.GetParams(ctx) // Maximum eden based per distribution epoch on maximum APR - 30% by default // Allocated for staking per day = (0.3/365)* (total weighted proxy TVL) - epochLpsMaxEdenAmount := params.MaxEdenRewardAprLps.Mul(totalProxyTVL).MulInt(lpIncentive.EpochNumBlocks).QuoInt(lpIncentive.TotalBlocksPerYear) + maxEdenAmountPerLpsPerDay := params.MaxEdenRewardAprLps.Mul(totalProxyTVL).MulInt(lpIncentive.AllocationEpochInBlocks).QuoInt(lpIncentive.TotalBlocksPerYear) // Use min amount (eden allocation from tokenomics and max apr based eden amount) - epochLpsEdenAmount = sdk.MinInt(epochLpsEdenAmount, epochLpsMaxEdenAmount.TruncateInt()) + edenAmountPerEpochLPsPerDay = sdk.MinInt(edenAmountPerEpochLPsPerDay, maxEdenAmountPerLpsPerDay.TruncateInt()) // Calculate Eden amount per distribution epoch - edenAmountPerEpochLPsPerDistribution := epochLpsEdenAmount.Mul(lpIncentive.DistributionEpochInBlocks).Quo(lpIncentive.EpochNumBlocks) + edenAmountPerEpochLPsPerDistribution := edenAmountPerEpochLPsPerDay.Mul(lpIncentive.DistributionEpochInBlocks).Quo(lpIncentive.AllocationEpochInBlocks) // Add dexRevenue amount that was tracked by Lp tracker dexRevenueLPsAmtPerDistribution = dexRevenueLPsAmtPerDistribution.Add(params.DexRewardsLps.AmountCollectedByOtherTracker) @@ -597,20 +597,12 @@ func (k Keeper) UpdateAmmPoolAPR(ctx sdk.Context, lpIncentive types.IncentiveInf } // Dex reward Apr per pool = total accumulated usdc rewards for 7 day * 52/ tvl of pool - weeklyDexRewardsTotal := poolInfo.DexRewardAmountGiven. - MulInt(lpIncentive.EpochNumBlocks). - MulInt(sdk.NewInt(ptypes.DaysPerWeek)). - QuoInt(poolInfo.NumBlocks) - poolInfo.DexApr = weeklyDexRewardsTotal. - MulInt(sdk.NewInt(ptypes.WeeksPerYear)). - Quo(tvl) + totalLMDexRewardsAllocatedPerWeek := poolInfo.DexRewardAmountGiven.MulInt(lpIncentive.AllocationEpochInBlocks).MulInt(sdk.NewInt(ptypes.DaysPerWeek)).QuoInt(poolInfo.NumBlocks) + poolInfo.DexApr = totalLMDexRewardsAllocatedPerWeek.MulInt(sdk.NewInt(ptypes.WeeksPerYear)).Quo(tvl) // Eden reward Apr per pool = (total LM Eden reward allocated per day*((tvl of pool * multiplier)/total proxy TVL) ) * 365 / TVL of pool - dailyEdenRewardsTotal := poolInfo.EdenRewardAmountGiven.Mul(lpIncentive.EpochNumBlocks).Quo(poolInfo.NumBlocks) - poolInfo.EdenApr = sdk.NewDecFromInt(dailyEdenRewardsTotal). - Mul(poolShare). - MulInt(sdk.NewInt(ptypes.DaysPerYear)). - Quo(tvl) + totalLMEdenRewardsAllocatedPerDay := poolInfo.EdenRewardAmountGiven.Mul(lpIncentive.AllocationEpochInBlocks).Quo(poolInfo.NumBlocks) + poolInfo.EdenApr = sdk.NewDecFromInt(totalLMEdenRewardsAllocatedPerDay).Mul(poolShare).MulInt(sdk.NewInt(ptypes.DaysPerYear)).Quo(tvl) // Update Pool Info k.SetPoolInfo(ctx, poolId, poolInfo) diff --git a/x/incentive/keeper/keeper_apr_per_pool_test.go b/x/incentive/keeper/keeper_apr_per_pool_test.go index 3a1911c8f..7be11891e 100644 --- a/x/incentive/keeper/keeper_apr_per_pool_test.go +++ b/x/incentive/keeper/keeper_apr_per_pool_test.go @@ -79,7 +79,7 @@ func TestAPRCalculationPerPool(t *testing.T) { // distribution duration - block number per year TotalBlocksPerYear: sdk.NewInt(10000), // we set block numbers in 24 hrs - EpochNumBlocks: sdk.NewInt(100), + AllocationEpochInBlocks: sdk.NewInt(100), // maximum eden allocation per day that won't exceed 30% apr MaxEdenPerAllocation: sdk.NewInt(100), // number of block intervals that distribute rewards. @@ -109,7 +109,7 @@ func TestAPRCalculationPerPool(t *testing.T) { require.NoError(t, err) // 1 week later. - ctx = ctx.WithBlockHeight(lpIncentive.EpochNumBlocks.Mul(sdk.NewInt(ptypes.DaysPerWeek)).Int64()) + ctx = ctx.WithBlockHeight(lpIncentive.AllocationEpochInBlocks.Mul(sdk.NewInt(ptypes.DaysPerWeek)).Int64()) poolInfo.NumBlocks = sdk.NewInt(ctx.BlockHeight()) ik.SetPoolInfo(ctx, poolId, poolInfo) diff --git a/x/incentive/types/incentive.pb.go b/x/incentive/types/incentive.pb.go index 7b991fbb8..94416994c 100644 --- a/x/incentive/types/incentive.pb.go +++ b/x/incentive/types/incentive.pb.go @@ -33,8 +33,8 @@ type IncentiveInfo struct { DistributionStartBlock github_com_cosmos_cosmos_sdk_types.Int `protobuf:"bytes,2,opt,name=distribution_start_block,json=distributionStartBlock,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Int" json:"distribution_start_block"` // distribution duration - block number per year TotalBlocksPerYear github_com_cosmos_cosmos_sdk_types.Int `protobuf:"bytes,3,opt,name=total_blocks_per_year,json=totalBlocksPerYear,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Int" json:"total_blocks_per_year"` - // we set block count in 24 hrs - EpochNumBlocks github_com_cosmos_cosmos_sdk_types.Int `protobuf:"bytes,4,opt,name=epoch_num_blocks,json=epochNumBlocks,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Int" json:"epoch_num_blocks"` + // we set block numbers in 24 hrs + AllocationEpochInBlocks github_com_cosmos_cosmos_sdk_types.Int `protobuf:"bytes,4,opt,name=allocation_epoch_in_blocks,json=allocationEpochInBlocks,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Int" json:"allocation_epoch_in_blocks"` // maximum eden allocation per day that won't exceed 30% apr MaxEdenPerAllocation github_com_cosmos_cosmos_sdk_types.Int `protobuf:"bytes,5,opt,name=max_eden_per_allocation,json=maxEdenPerAllocation,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Int" json:"max_eden_per_allocation"` // number of block intervals that distribute rewards. @@ -85,34 +85,34 @@ func init() { func init() { proto.RegisterFile("elys/incentive/incentive.proto", fileDescriptor_ed0e67c7f36f3313) } var fileDescriptor_ed0e67c7f36f3313 = []byte{ - // 431 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0xd3, 0x4f, 0x8e, 0xd3, 0x30, - 0x14, 0x06, 0xf0, 0x86, 0x3f, 0x05, 0x2c, 0xa8, 0x20, 0x2a, 0x10, 0x46, 0x28, 0x45, 0x2c, 0x10, - 0x9b, 0x49, 0x16, 0x9c, 0xa0, 0x15, 0x23, 0xd1, 0x0d, 0x1a, 0x0d, 0x2c, 0x80, 0x8d, 0xe5, 0xa4, - 0x6f, 0x52, 0xab, 0xb1, 0x5f, 0x64, 0xbf, 0x40, 0x7b, 0x0b, 0x0e, 0xc2, 0x41, 0x66, 0x39, 0x4b, - 0xc4, 0x62, 0x84, 0xda, 0x8b, 0x20, 0x3b, 0xed, 0x34, 0x15, 0xab, 0xc9, 0x2a, 0x76, 0x6c, 0xfd, - 0xbe, 0x7c, 0xb1, 0xc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5a, 0x6d, 0x63, 0xa2, 0x3b, 0x9d, - 0xf4, 0x81, 0x77, 0x3e, 0xd6, 0xaa, 0x09, 0x08, 0x81, 0x3d, 0x57, 0x62, 0xc9, 0xfd, 0x59, 0xb8, - 0x0f, 0x17, 0x65, 0x89, 0xb9, 0x70, 0x0d, 0xa3, 0xbb, 0x9d, 0x02, 0x86, 0x4a, 0x2c, 0x4f, 0x66, - 0xa0, 0x4f, 0xc1, 0x8c, 0xaf, 0xad, 0x10, 0xd9, 0xcb, 0x83, 0xd3, 0x68, 0xda, 0x48, 0xbd, 0x2b, - 0xd3, 0xef, 0x94, 0xf5, 0xa2, 0x6d, 0x9e, 0x38, 0x72, 0xaa, 0xf7, 0xbd, 0xf2, 0xda, 0x18, 0xd0, - 0xf4, 0x5f, 0xd6, 0xbd, 0x6e, 0xbd, 0xb6, 0xdc, 0x61, 0xcc, 0x67, 0x36, 0xf0, 0xbf, 0x2e, 0x43, - 0xb4, 0xc4, 0x45, 0x65, 0xa2, 0xfb, 0x37, 0xd6, 0xdf, 0x43, 0x7e, 0xf6, 0xd0, 0x29, 0x13, 0x87, - 0x8c, 0x2b, 0x33, 0xf9, 0x70, 0xb1, 0x8e, 0x83, 0xcb, 0x75, 0x1c, 0xfc, 0x5d, 0xc7, 0xc1, 0xcf, - 0x4d, 0xdc, 0xbb, 0xdc, 0xc4, 0xbd, 0xdf, 0x9b, 0xb8, 0xf7, 0x2d, 0x69, 0x79, 0xee, 0x6a, 0x1e, - 0x6b, 0xa0, 0x1f, 0x68, 0x16, 0x7e, 0x92, 0x2e, 0x5b, 0x37, 0xd9, 0xdb, 0x59, 0xdf, 0xdf, 0xbf, - 0x77, 0xff, 0x02, 0x00, 0x00, 0xff, 0xff, 0xe7, 0x58, 0xbd, 0xc7, 0xe8, 0x03, 0x00, 0x00, + // 426 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0xd3, 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0x83, 0x9f, 0xbb, 0x78, 0x70, 0xb1, 0x8b, + 0x07, 0xbf, 0x77, 0xf1, 0xe0, 0x5b, 0xd2, 0xf1, 0xdc, 0xb4, 0x1e, 0x69, 0xa0, 0x1f, 0x68, 0x56, + 0x7e, 0x93, 0xae, 0x3b, 0xc3, 0xed, 0xed, 0x6c, 0xe8, 0x47, 0xf2, 0xc3, 0xbf, 0x00, 0x00, 0x00, + 0xff, 0xff, 0x62, 0xa6, 0xae, 0x62, 0xfb, 0x03, 0x00, 0x00, } func (m *IncentiveInfo) Marshal() (dAtA []byte, err error) { @@ -176,9 +176,9 @@ func (m *IncentiveInfo) MarshalToSizedBuffer(dAtA []byte) (int, error) { i-- dAtA[i] = 0x2a { - size := m.EpochNumBlocks.Size() + size := m.AllocationEpochInBlocks.Size() i -= size - if _, err := m.EpochNumBlocks.MarshalTo(dAtA[i:]); err != nil { + if _, err := m.AllocationEpochInBlocks.MarshalTo(dAtA[i:]); err != nil { return 0, err } i = encodeVarintIncentive(dAtA, i, uint64(size)) @@ -241,7 +241,7 @@ func (m *IncentiveInfo) Size() (n int) { n += 1 + l + sovIncentive(uint64(l)) l = m.TotalBlocksPerYear.Size() n += 1 + l + sovIncentive(uint64(l)) - l = m.EpochNumBlocks.Size() + l = m.AllocationEpochInBlocks.Size() n += 1 + l + sovIncentive(uint64(l)) l = m.MaxEdenPerAllocation.Size() n += 1 + l + sovIncentive(uint64(l)) @@ -393,7 +393,7 @@ func (m *IncentiveInfo) Unmarshal(dAtA []byte) error { iNdEx = postIndex case 4: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field EpochNumBlocks", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field AllocationEpochInBlocks", wireType) } var stringLen uint64 for shift := uint(0); ; shift += 7 { @@ -421,7 +421,7 @@ func (m *IncentiveInfo) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - if err := m.EpochNumBlocks.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + if err := m.AllocationEpochInBlocks.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { return err } iNdEx = postIndex diff --git a/x/incentive/types/params.go b/x/incentive/types/params.go index f769e508e..49c178815 100644 --- a/x/incentive/types/params.go +++ b/x/incentive/types/params.go @@ -279,7 +279,7 @@ func validateLPIncentives(i interface{}) error { return fmt.Errorf("invalid total blocks per year: %v", vv) } - if vv.EpochNumBlocks.LT(sdk.NewInt(0)) { + if vv.AllocationEpochInBlocks.LT(sdk.NewInt(0)) { return fmt.Errorf("invalid allocation epoch in blocks: %v", vv) } @@ -321,7 +321,7 @@ func validateStakeIncentives(i interface{}) error { return fmt.Errorf("invalid total blocks per year: %v", vv) } - if vv.EpochNumBlocks.LT(sdk.NewInt(0)) { + if vv.AllocationEpochInBlocks.LT(sdk.NewInt(0)) { return fmt.Errorf("invalid allocation epoch in blocks: %v", vv) } diff --git a/x/incentive/types/params_test.go b/x/incentive/types/params_test.go index 553ea5a54..e32133d2c 100644 --- a/x/incentive/types/params_test.go +++ b/x/incentive/types/params_test.go @@ -30,7 +30,7 @@ func Test_validateParams(t *testing.T) { // distribution duration - block number per year TotalBlocksPerYear: sdk.NewInt(10512000), // we set block numbers in 24 hrs - EpochNumBlocks: sdk.NewInt(28800), + AllocationEpochInBlocks: sdk.NewInt(28800), // maximum eden allocation per day that won't exceed 30% apr MaxEdenPerAllocation: sdk.NewInt(27397238400), // number of block intervals that distribute rewards. diff --git a/x/incentive/types/query.pb.gw.go b/x/incentive/types/query.pb.gw.go index b5a443e54..1c5937357 100644 --- a/x/incentive/types/query.pb.gw.go +++ b/x/incentive/types/query.pb.gw.go @@ -21,6 +21,7 @@ import ( "google.golang.org/grpc" "google.golang.org/grpc/codes" "google.golang.org/grpc/grpclog" + "google.golang.org/grpc/metadata" "google.golang.org/grpc/status" ) @@ -31,6 +32,7 @@ var _ status.Status var _ = runtime.String var _ = utilities.NewDoubleArray var _ = descriptor.ForMessage +var _ = metadata.Join func request_Query_Params_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { var protoReq QueryParamsRequest @@ -153,12 +155,14 @@ func local_request_Query_Apr_0(ctx context.Context, marshaler runtime.Marshaler, // RegisterQueryHandlerServer registers the http handlers for service Query to "mux". // UnaryRPC :call QueryServer directly. // StreamingRPC :currently unsupported pending https://github.com/grpc/grpc-go/issues/906. -// Note that using this registration option will cause many gRPC library features (such as grpc.SendHeader, etc) to stop working. Consider using RegisterQueryHandlerFromEndpoint instead. +// Note that using this registration option will cause many gRPC library features to stop working. Consider using RegisterQueryHandlerFromEndpoint instead. func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, server QueryServer) error { mux.Handle("GET", pattern_Query_Params_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { ctx, cancel := context.WithCancel(req.Context()) defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) if err != nil { @@ -166,6 +170,7 @@ func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, serv return } resp, md, err := local_request_Query_Params_0(rctx, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) ctx = runtime.NewServerMetadataContext(ctx, md) if err != nil { runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) @@ -179,6 +184,8 @@ func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, serv mux.Handle("GET", pattern_Query_CommunityPool_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { ctx, cancel := context.WithCancel(req.Context()) defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) if err != nil { @@ -186,6 +193,7 @@ func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, serv return } resp, md, err := local_request_Query_CommunityPool_0(rctx, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) ctx = runtime.NewServerMetadataContext(ctx, md) if err != nil { runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) @@ -199,6 +207,8 @@ func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, serv mux.Handle("GET", pattern_Query_Apr_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { ctx, cancel := context.WithCancel(req.Context()) defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) if err != nil { @@ -206,6 +216,7 @@ func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, serv return } resp, md, err := local_request_Query_Apr_0(rctx, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) ctx = runtime.NewServerMetadataContext(ctx, md) if err != nil { runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) diff --git a/x/parameter/types/keys.go b/x/parameter/types/keys.go index 63a5e6c40..77e3b500e 100644 --- a/x/parameter/types/keys.go +++ b/x/parameter/types/keys.go @@ -41,6 +41,9 @@ const ( // 31540000s per year SecondsPerYear = 31540000 + // One day seconds + SecondsPerDay = 86400 + // Days per year DaysPerYear = 365