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

Feature/osmosis cl #1527

Merged
merged 5 commits into from
Apr 30, 2024
Merged

Feature/osmosis cl #1527

merged 5 commits into from
Apr 30, 2024

Conversation

joe-bowman
Copy link
Contributor

1. Summary

Fixes #1151

Update's osmosis-types dependency (can import properly when we are on SDK 47!)

Add CL Pool Submodule for participation rewards

* update osmosis-types to v22; add concentrated-liquidity and poolmanager
* update osmosis-types usages for v22 types
* ensure pool and math dirs are included; update codecs for inclusion
Copy link

vercel bot commented Apr 30, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
quicksilver ✅ Ready (Inspect) Visit Preview 💬 Add feedback Apr 30, 2024 2:35pm

Copy link
Contributor

coderabbitai bot commented Apr 30, 2024

Walkthrough

This comprehensive update introduces a variety of new functionalities and improvements across the Osmosis protocol, particularly enhancing the concentrated liquidity and pool management systems. Key additions include new message types for liquidity positions, pool creation, and incentives, alongside updates to error handling and parameter management. This aligns with the protocol's ongoing efforts to refine its DeFi capabilities and user experience.

Changes

File Path Change Summary
proto/.../accum.proto, proto/.../concentratedliquidity/... Introduced new messages for accumulator states, concentrated liquidity pools, positions, and governance.
proto/.../gamm/..., proto/.../lockup/..., proto/.../poolmanager/... Added and updated messages for GAMM operations, lockup functionalities, and pool management.
third-party-chains/osmosis-types/... Extensive updates to support concentrated liquidity, including new interfaces, error handling, and mathematical functions for liquidity management.

Assessment against linked issues

Objective Addressed Explanation
Bump osmosis-types to v22 (#1151)

Poem

🐇💻 In the land of code and flow,
Where the bits like rivers go,
Osmosis grows, with liquid dreams,
Pools and locks and data streams.
🌊🔐 Each update a step, it seems,
In pursuit of decentralized schemes.
🌟🚀 To the moon, our codebase gleams!


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

ProtocolDataTypeCrescentParams ProtocolDataType = 13
ProtocolDataTypeCrescentReserveAddressBalance ProtocolDataType = 14
ProtocolDataTypeCrescentPoolCoinSupply ProtocolDataType = 15
ProtocolDataTypeCrescentParams ProtocolDataType = 13 // Deprecated: Do not use.
Copy link
Contributor

Choose a reason for hiding this comment

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

can we remove?

@@ -35,17 +35,18 @@ const (
ProtocolDataTypeOsmosisParams ProtocolDataType = 2
ProtocolDataTypeLiquidToken ProtocolDataType = 3
ProtocolDataTypeOsmosisPool ProtocolDataType = 4
ProtocolDataTypeCrescentPool ProtocolDataType = 5
ProtocolDataTypeSifchainPool ProtocolDataType = 6
ProtocolDataTypeCrescentPool ProtocolDataType = 5 // Deprecated: Do not use.
Copy link
Contributor

Choose a reason for hiding this comment

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

can we remove?

@faddat
Copy link
Contributor

faddat commented Apr 30, 2024

review:

I skipped the imported code, and reviewed all of the code added. I wondered if we could remove code referencing sif and cresent.

Copy link

codecov bot commented Apr 30, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 62.45%. Comparing base (7f095c3) to head (8b398bb).
Report is 2 commits behind head on main.

❗ Current head 8b398bb differs from pull request most recent head 164ad3a. Consider uploading reports for the commit 164ad3a to get more accurate results

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #1527      +/-   ##
==========================================
- Coverage   62.97%   62.45%   -0.53%     
==========================================
  Files         192      194       +2     
  Lines       13495    13609     +114     
==========================================
+ Hits         8499     8500       +1     
- Misses       4181     4294     +113     
  Partials      815      815              
Flag Coverage Δ
unittests 62.45% <ø> (-0.53%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Coverage Δ
x/claimsmanager/types/codec.go 35.29% <ø> (-7.57%) ⬇️
x/participationrewards/keeper/callbacks.go 48.33% <ø> (-5.16%) ⬇️
x/participationrewards/keeper/distribution.go 69.16% <ø> (ø)
x/participationrewards/keeper/submodule_osmosis.go 63.23% <ø> (ø)
...participationrewards/keeper/submodule_osmosiscl.go 0.00% <ø> (ø)
x/participationrewards/types/codec.go 42.10% <ø> (+5.74%) ⬆️
x/participationrewards/types/submodule_osmosis.go 44.06% <ø> (ø)
...participationrewards/types/submodule_osmosis_cl.go 0.00% <ø> (ø)

@faddat
Copy link
Contributor

faddat commented Apr 30, 2024

Talked to @joe-bowman -- the deprecated fields are still there so we don't mess up numbering.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 42

Out of diff range and nitpick comments (6)
third-party-chains/osmosis-types/gamm/codec.go (1)

46-53: Clarify the usage of ModuleCdc and ensure it is only used where appropriate, as per the comments.

Consider adding more detailed documentation on when it is appropriate to use ModuleCdc and when it should be avoided.

proto/osmosis/accum/v1beta1/accum.proto (1)

34-50: The description in the comments for accum_value_per_share is detailed and informative. However, ensure that the complexity of the explanation does not hinder understanding for new developers.

Consider simplifying the comment or adding a reference to further documentation for clarity.

third-party-chains/osmosis-types/concentrated-liquidity/constants.go (1)

9-72: The constants defined in this file, such as MinInitializedTick, MaxSpotPrice, and AuthorizedTickSpacing, are crucial for the operation of concentrated liquidity pools. Ensure that these constants are consistent with the rest of the protocol and are documented clearly to avoid confusion.

Consider adding more detailed comments to explain the purpose and usage of each constant, especially those that are critical to the protocol's operation.

third-party-chains/osmosis-types/concentrated-liquidity/events.go (1)

3-57: The event type constants defined in this file, such as TypeEvtCreatePosition and TypeEvtCollectIncentives, are used to track and manage events within the concentrated liquidity functionality. Ensure that these constants are used consistently across the protocol and are documented clearly.

Consider adding more detailed comments to explain the purpose and usage of each event type, especially those that are critical to the protocol's operation.

third-party-chains/osmosis-types/concentrated-liquidity/math/precompute.go (1)

39-39: TODO comment detected. Ensure that this is tracked or resolved if necessary.

third-party-chains/osmosis-types/concentrated-liquidity/model/pool.go (1)

123-124: Clarify the TODO comment regarding backward compatibility.

The TODO comment in the SpotPrice method mentions maintaining backward compatibility but lacks clarity on the specific changes needed or the timeline. It would be beneficial to expand this comment to provide more context or link to relevant issues/documentation.

Comment on lines +24 to +932

func (e SqrtRootCalculationError) Error() string {
return fmt.Sprintf("issue calculating square root of price limit %s", e.SqrtPriceLimit)
}

type TickToSqrtPriceConversionError struct {
NextTick int64
}

func (e TickToSqrtPriceConversionError) Error() string {
return fmt.Sprintf("could not convert next tick to nextSqrtPrice (%v)", e.NextTick)
}

type SwapNoProgressError struct {
PoolId uint64
UserProvidedCoin sdk.Coin
}

func (e SwapNoProgressError) Error() string {
return fmt.Sprintf("ran out of iterations during swap. Possibly entered an infinite loop. Pool id (%d), user provided coin (%s)", e.PoolId, e.UserProvidedCoin)
}

type SwapNoProgressWithConsumptionError struct {
ComputedSqrtPrice osmomath.BigDec
AmountIn osmomath.Dec
AmountOut osmomath.Dec
}

func (e SwapNoProgressWithConsumptionError) Error() string {
return fmt.Sprintf("did not advance sqrt price after swap step %s, with amounts in (%s), out (%s)", e.ComputedSqrtPrice, e.AmountIn, e.AmountOut)
}

type SqrtPriceToTickError struct {
OutOfBounds bool
}

func (e SqrtPriceToTickError) Error() string {
return fmt.Sprintf("sqrt price to tick could not find a satisfying tick index. Hit bounds: %v", e.OutOfBounds)
}

type OverChargeSwapOutGivenInError struct {
AmountSpecifiedRemaining osmomath.Dec
}

func (e OverChargeSwapOutGivenInError) Error() string {
return fmt.Sprintf("over charge problem swap out given in by (%s)", e.AmountSpecifiedRemaining)
}

type ComputedSqrtPriceInequalityError struct {
IsZeroForOne bool
NextInitializedTickSqrtPrice osmomath.BigDec
ComputedSqrtPrice osmomath.BigDec
}

func (e ComputedSqrtPriceInequalityError) Error() string {
return fmt.Sprintf("edge case has occurred when swapping at tick boundaries, with izZeroForOne (%t), NextInitializedTickSqrtPrice (%s), computedSqrtPrice (%s). Please try again with a different swap amount", e.IsZeroForOne, e.NextInitializedTickSqrtPrice, e.ComputedSqrtPrice)
}

type NumberOfTicksExceedsMaxError struct {
NumberOfTicks uint64
MaxNumberOfTicks uint64
}

func (e NumberOfTicksExceedsMaxError) Error() string {
return fmt.Sprintf("number of ticks exceeds max ticks. Provided number of ticks (%d), max ticks (%d)", e.NumberOfTicks, e.MaxNumberOfTicks)
}

type DuplicatePositionIdsError struct {
PositionIds []uint64
}

func (e DuplicatePositionIdsError) Error() string {
return fmt.Sprintf("duplicate position ids found (%v)", e.PositionIds)
}

type LastPositionTransferError struct {
PositionId uint64
PoolId uint64
}

func (e LastPositionTransferError) Error() string {
return fmt.Sprintf("cannot transfer position %d because it is the last position in pool %d", e.PositionId, e.PoolId)
}

type ContractHookOutOfGasError struct {
GasLimit uint64
}

func (e ContractHookOutOfGasError) Error() string {
return fmt.Sprintf("A single contract call cannot exceed %d gas in a CL hook call.", e.GasLimit)
}

type InvalidActionPrefixError struct {
ActionPrefix string
ValidActions []string
}

func (e InvalidActionPrefixError) Error() string {
return fmt.Sprintf("invalid action prefix (%s). Valid actions: %s", e.ActionPrefix, e.ValidActions)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Ensure minimal changes to vendored files to maintain alignment with the original source.

This file is part of a vendored directory, and as per previous discussions, changes to these files should be minimal to keep them as close to the original as possible. If you need assistance in aligning the changes with the original source, please let me know.

Comment on lines +28 to +56
// NewConcentratedLiquidityPool creates a new ConcentratedLiquidity pool with the specified parameters.
// The two provided denoms are ordered so that denom0 is lexicographically smaller than denom1.
func NewConcentratedLiquidityPool(poolId uint64, denom0, denom1 string, tickSpacing uint64, spreadFactor osmomath.Dec) (Pool, error) {
// Ensure that the two denoms are different
if denom0 == denom1 {
return Pool{}, types.MatchingDenomError{Denom: denom0}
}

// Spread factor must be [0,1)
if spreadFactor.IsNegative() || spreadFactor.GTE(one) {
return Pool{}, types.InvalidSpreadFactorError{ActualSpreadFactor: spreadFactor}
}

// Create a new pool struct with the specified parameters
pool := Pool{
Address: poolmanagertypes.NewPoolAddress(poolId).String(),
IncentivesAddress: osmoutils.NewModuleAddressWithPrefix(types.ModuleName, incentivesAddressPrefix, sdk.Uint64ToBigEndian(poolId)).String(),
SpreadRewardsAddress: osmoutils.NewModuleAddressWithPrefix(types.ModuleName, spreadRewardsAddressPrefix, sdk.Uint64ToBigEndian(poolId)).String(),
Id: poolId,
CurrentSqrtPrice: osmomath.ZeroBigDec(),
CurrentTick: 0,
CurrentTickLiquidity: osmomath.ZeroDec(),
Token0: denom0,
Token1: denom1,
TickSpacing: tickSpacing,
ExponentAtPriceOne: types.ExponentAtPriceOne,
SpreadFactor: spreadFactor,
}
return pool, nil
Copy link
Contributor

Choose a reason for hiding this comment

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

Ensure the new NewConcentratedLiquidityPool function adheres to minimal modification principles for vendored files.

This function introduces significant new logic for creating a concentrated liquidity pool. Given that this file is from a vendored directory, which should ideally remain close to the original to ease updates and maintain compatibility, please confirm if these changes are essential and if they have been or will be contributed back to the source repository.

Comment on lines +59 to +66
// GetAddress returns the address of the concentrated liquidity pool
func (p Pool) GetAddress() sdk.AccAddress {
addr, err := addressutils.AccAddressFromBech32(p.Address, "")
if err != nil {
panic(fmt.Sprintf("could not bech32 decode address of pool with id: %d", p.GetId()))
}
return addr
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Review the use of panic for error handling in GetAddress.

Using panic for error handling in production code, especially in a blockchain context where stability is crucial, is risky. It can lead to abrupt termination of the application. Consider returning the error to the caller and handling it gracefully.

Comment on lines +68 to +74
// GetIncentivesAddress returns the address storing incentives of the concentrated liquidity pool.
func (p Pool) GetIncentivesAddress() sdk.AccAddress {
addr, err := addressutils.AccAddressFromBech32(p.IncentivesAddress, "")
if err != nil {
panic(fmt.Sprintf("could not bech32 decode incentive address of pool with id: %d", p.GetId()))
}
return addr
Copy link
Contributor

Choose a reason for hiding this comment

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

Review the use of panic for error handling in GetIncentivesAddress.

Similar to the previous comment, the use of panic here can lead to instability. It's generally better practice in Go to handle errors gracefully by returning them to the caller, unless a panic is absolutely necessary.

Comment on lines +77 to +80
func (p Pool) GetSpreadRewardsAddress() sdk.AccAddress {
addr, err := addressutils.AccAddressFromBech32(p.SpreadRewardsAddress, "")
if err != nil {
panic(fmt.Sprintf("could not bech32 decode spread factor address of pool with id: %d", p.GetId()))
Copy link
Contributor

Choose a reason for hiding this comment

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

Review the use of panic for error handling in GetSpreadRewardsAddress.

The use of panic for handling decoding errors is not recommended. Consider modifying the method to return an error and handle it appropriately in the calling code.

* `accum/pos/{accumName}||{positionName}`

We really should be prefix separating this state into its own sub-area (or potentially even a different store entirely -- I think its worth doing this prelaunch)

Copy link
Contributor

Choose a reason for hiding this comment

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

Correct the spelling mistake in "AccumName".

- accumName and positionName's are confined to one of the following two:
+ AccumName and PositionName's are confined to one of the following two:

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change


We really should be prefix separating this state into its own sub-area (or potentially even a different store entirely -- I think its worth doing this prelaunch)

accumName and positionName's are confined to one of the following two:
Copy link
Contributor

Choose a reason for hiding this comment

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

Correct the spelling mistake in "AccumName".

- - Spread rewards     - accumName = `0x0B/` || `str encode pool ID`
+ - Spread rewards     - AccumName = `0x0B/` || `string encode pool ID`

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
accumName and positionName's are confined to one of the following two:
accumName and positionName's are confined to one of the following two:

accumName and positionName's are confined to one of the following two:
- Spread rewards
- accumName = `0x0B/` || `str encode pool ID`
- positionName = `0x0A/` || `str encode position ID`
Copy link
Contributor

Choose a reason for hiding this comment

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

Correct the spelling mistake in "PositionName".

- - positionName = `0x0A/` || `str encode position ID`
+ - PositionName = `0x0A/` || `string encode position ID`

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
- positionName = `0x0A/` || `str encode position ID`
- PositionName = `0x0A/` || `string encode position ID`

- accumName = `0x0B/` || `str encode pool ID`
- positionName = `0x0A/` || `str encode position ID`
- incentive rewards
- accumName = `0x0C/` || `str encode pool ID` || `/` || `str encode uptime index ID`
Copy link
Contributor

Choose a reason for hiding this comment

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

Correct the spelling mistake in "AccumName".

- - accumName = `0x0C/` || `str encode pool ID` || `/` || `str encode uptime index ID`
+ - AccumName = `0x0C/` || `string encode pool ID` || `/` || `string encode uptime index ID`

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
- accumName = `0x0C/` || `str encode pool ID` || `/` || `str encode uptime index ID`
- AccumName = `0x0C/` || `string encode pool ID` || `/` || `string encode uptime index ID`

- positionName = `0x0A/` || `str encode position ID`
- incentive rewards
- accumName = `0x0C/` || `str encode pool ID` || `/` || `str encode uptime index ID`
- positionName = `0x08` || `var-length, base10 string encoding of position ID`
Copy link
Contributor

Choose a reason for hiding this comment

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

Correct the spelling mistake in "PositionName".

- - positionName = `0x08` || `var-length, base10 string encoding of position ID`
+ - PositionName = `0x08` || `var-length, base10 string encoding of position ID`

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
- positionName = `0x08` || `var-length, base10 string encoding of position ID`
- PositionName = `0x08` || `var-length, base10 string encoding of position ID`

@faddat faddat merged commit 9daeb7b into main Apr 30, 2024
22 of 23 checks passed
@joe-bowman joe-bowman deleted the feature/osmosis-cl branch May 8, 2024 13:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bump osmosis-types to v22
2 participants