-
Notifications
You must be signed in to change notification settings - Fork 589
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
test/feat: incentive accumulator truncation #7395
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ package concentrated_liquidity_test | |
|
||
import ( | ||
"errors" | ||
"fmt" | ||
"time" | ||
|
||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
|
@@ -11,6 +12,7 @@ import ( | |
"github.com/osmosis-labs/osmosis/osmomath" | ||
"github.com/osmosis-labs/osmosis/osmoutils/accum" | ||
cl "github.com/osmosis-labs/osmosis/v22/x/concentrated-liquidity" | ||
"github.com/osmosis-labs/osmosis/v22/x/concentrated-liquidity/math" | ||
"github.com/osmosis-labs/osmosis/v22/x/concentrated-liquidity/model" | ||
"github.com/osmosis-labs/osmosis/v22/x/concentrated-liquidity/types" | ||
"github.com/osmosis-labs/osmosis/v22/x/gamm/pool-models/balancer" | ||
|
@@ -3548,3 +3550,90 @@ func (s *KeeperTestSuite) TestGetIncentiveRecordSerialized() { | |
}) | ||
} | ||
} | ||
|
||
// This PR shows that there is a chance of incentives being truncated due to large liquidity value. | ||
// We observed this in pool 1423 where both tokens have 18 decimal precision. | ||
// | ||
// It has been determined that no funds are at risk. The incentives are eventually distributed if either: | ||
// a) Long time without an update to the pool state occurs (at least 51 minute with the current configuration) | ||
// b) current tick liquidity becomes smaller | ||
func (s *KeeperTestSuite) TestIncentiveTruncation() { | ||
s.SetupTest() | ||
|
||
// Create a pool | ||
pool := s.PrepareConcentratedPool() | ||
|
||
// osmosisd q concentratedliquidity incentive-records 1423 --node https://osmosis-rpc.polkachu.com:443 | ||
// incentive_records: | ||
// - incentive_id: "5833" | ||
// incentive_record_body: | ||
// emission_rate: "9645.061724537037037037" | ||
// remaining_coin: | ||
// amount: "518549443.513510006462246574" | ||
// denom: ibc/A8CA5EE328FA10C9519DF6057DA1F69682D28F7D0F5CCC7ECB72E3DCA2D157A4 | ||
// start_time: "2024-01-31T17:16:11.187417702Z" | ||
// min_uptime: 0.000000001s | ||
// pool_id: "1423" | ||
// pagination: | ||
// next_key: null | ||
// total: "0" | ||
// 24 * 60 * 60 * 9645.061724537037037037 | ||
// 833333333.0 -<------ Initial incentives in recorrd | ||
incentiveCoin := sdk.NewCoin("ibc/A8CA5EE328FA10C9519DF6057DA1F69682D28F7D0F5CCC7ECB72E3DCA2D157A4", sdk.NewInt(833333333)) | ||
|
||
// Create a pool state simulating pool 1423. The only difference is that we force the pool state given 1 position as | ||
// opposed to many. | ||
// osmosisd q poolmanager pool 1423 --height 13559864 --node https://osmosis-rpc.polkachu.com:443 | ||
desiredLiquidity := osmomath.MustNewBigDecFromStr("28968940108516957474488782.253893404842148631") | ||
desiredCurrentTick := int64(596) | ||
desiredCurrentSqrtPrice, err := math.TickToSqrtPrice(desiredCurrentTick) | ||
s.Require().NoError(err) | ||
|
||
amount0 := math.CalcAmount0Delta(desiredLiquidity, desiredCurrentSqrtPrice, types.MaxSqrtPriceBigDec, true).Dec().TruncateInt() | ||
amount1 := math.CalcAmount1Delta(desiredLiquidity, types.MinSqrtPriceBigDec, desiredCurrentSqrtPrice, true).Dec().TruncateInt() | ||
|
||
lpCoins := sdk.NewCoins(sdk.NewCoin(ETH, amount0), sdk.NewCoin(USDC, amount1)) | ||
s.FundAcc(s.TestAccs[0], lpCoins) | ||
|
||
// LP | ||
positionData, err := s.App.ConcentratedLiquidityKeeper.CreatePosition(s.Ctx, pool.GetId(), s.TestAccs[0], lpCoins, osmomath.ZeroInt(), osmomath.ZeroInt(), types.MinInitializedTick, types.MaxTick) | ||
s.Require().NoError(err) | ||
|
||
fmt.Println("initial liquidity", positionData.Liquidity) | ||
|
||
// Fund the account with the incentive coin | ||
s.FundAcc(s.TestAccs[0], sdk.NewCoins(incentiveCoin)) | ||
|
||
// Set incentives for pool to ensure accumulators work correctly | ||
_, err = s.App.ConcentratedLiquidityKeeper.CreateIncentive(s.Ctx, pool.GetId(), s.TestAccs[0], incentiveCoin, osmomath.MustNewDecFromStr("9645.061724537037037037"), s.Ctx.BlockTime(), time.Nanosecond) | ||
s.Require().NoError(err) | ||
|
||
// Reset events | ||
s.Ctx = s.Ctx.WithEventManager(sdk.NewEventManager()) | ||
|
||
// The check below shows that the incentive is not claimed due to truncation | ||
s.Ctx = s.Ctx.WithBlockTime(s.Ctx.BlockTime().Add(time.Minute * 50)) | ||
incentives, _, err := s.App.ConcentratedLiquidityKeeper.CollectIncentives(s.Ctx, s.TestAccs[0], positionData.ID) | ||
s.Require().NoError(err) | ||
s.Require().True(incentives.IsZero()) | ||
|
||
// Truncation happens | ||
events := s.Ctx.EventManager().Events() | ||
s.Require().Equal(1, len(events)) | ||
s.Require().Equal(types.IncentiveTruncationPlaceholderName, events[0].Type) | ||
|
||
// Reset events | ||
s.Ctx = s.Ctx.WithEventManager(sdk.NewEventManager()) | ||
|
||
s.Ctx = s.Ctx.WithBlockTime(s.Ctx.BlockTime().Add(time.Minute * 51)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn't we only need to add 1 minute here? Since we already went ahead 50 minutes above? |
||
incentives, _, err = s.App.ConcentratedLiquidityKeeper.CollectIncentives(s.Ctx, s.TestAccs[0], positionData.ID) | ||
s.Require().NoError(err) | ||
s.Require().False(incentives.IsZero()) | ||
|
||
// Truncation event does not occur | ||
events = s.Ctx.EventManager().Events() | ||
s.Require().NotEqual(0, len(events)) | ||
for _, event := range events { | ||
s.Require().NotEqual(types.IncentiveTruncationPlaceholderName, event.Type) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -48,4 +48,6 @@ const ( | |
AttributeKeySpreadRewardGrowthOppositeDirectionOfLastTraversal = "spread_reward_growth" | ||
AttributeKeyUptimeGrowthOppositeDirectionOfLastTraversal = "uptime_growth" | ||
AttributeNewOwner = "new_owner" | ||
|
||
IncentiveTruncationPlaceholderName = "concentrated_liquidity_incentive_truncation" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we remove placeholder name? |
||
) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should create an alert for these and a Grafana dashboard cc: @niccoloraspa @alessandrolomanto