-
Notifications
You must be signed in to change notification settings - Fork 592
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
Speedup CL spot price check and swap by removing an iterator #7258
Conversation
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.
LGTM!
Confirmed that this is valid per:
- pool creation with no positions:
osmosis/x/concentrated-liquidity/model/pool.go
Lines 46 to 47 in 74ea7f1
CurrentSqrtPrice: osmomath.ZeroBigDec(), CurrentTick: 0, - removal of last position:
osmosis/x/concentrated-liquidity/lp.go
Lines 615 to 616 in 74ea7f1
pool.SetCurrentSqrtPrice(osmomath.ZeroBigDec()) pool.SetCurrentTick(0)
// the current sqrt price being 0. | ||
// We also check that the current tick is 0, which is also guaranteed in this situation. | ||
// That derisks any edge-case where the sqrt price is 0 but the tick is not 0. | ||
func (k Keeper) PoolHasPosition(ctx sdk.Context, pool types.ConcentratedPoolExtension) bool { |
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.
Would it be appropriate to define this method on the pool itself?
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.
Great idea!
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.
Actually on further thought I'm not sure, this is a convention set by the keeper not the pool itself. (Adding a position doesn't go through a pool.AddPosition method)
Co-authored-by: Roman <roman@osmosis.team>
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.
ACK, merging due to 3 approvals
Speedup the CL check for if a pool is initialized.
Right now we do a very expensive iterator call. This technically saves gas for user swaps, but this is really small (at not all commensurate with the CPU costs it induces)
More pressingly, this is a notable delay to block processing time, due to occurrence in:
Notice that SpotPrice is 0 iff there is no position in the pool. You can convince yourself of this by looking at: