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

fix: migrate subset of spread reward accums #7876

Merged
merged 47 commits into from
Apr 26, 2024

Conversation

czarcas7ic
Copy link
Member

@czarcas7ic czarcas7ic commented Mar 27, 2024

Closes: #XXX

What is the purpose of the change

This feature is essentially identical to the work that was done on the incentive accumulators. There exists conditions in which dividing the spread factor by the liquidity amount results in truncation to zero, resulting in the proper amount of spread factor to be deposited into the spread factor module account, but not be distributed to LPs.

This will be fixed in two stages just like incentives:

  1. Migrate over only the most at risk pools of truncation, as well as any future pool created after upgrade to the new scaled accumulator logic
  2. Migrate over all remaining pools

Testing and Verifying

TBD

Summary by CodeRabbit

  • New Features

    • Introduced new functionality for migrating and scaling spread rewards and accumulators.
    • Added new test functions to validate the migration and scaling processes.
    • Enhanced swap functionality with updated scaling factors and telemetry emission adjustments.
  • Bug Fixes

    • Adjusted global spread reward growth calculations to include scaling factors, improving accuracy.
  • Documentation

    • Updated CHANGELOG.md with recent changes including migration processes and module enhancements.
  • Refactor

    • Renamed functions to better reflect their new functionality concerning incentives and spread factors.
    • Modified existing functions to include additional parameters for scaling, improving precision in calculations.
  • Tests

    • Expanded test coverage to include new scenarios for spread reward and accumulator migrations.
  • Chores

    • Updated imports and initialized new fields in various configurations to support the updated functionalities.

@czarcas7ic czarcas7ic added V:state/compatible/no_backport State machine compatible PR, depends on prior breaks V:state/breaking State machine breaking PR and removed V:state/compatible/no_backport State machine compatible PR, depends on prior breaks labels Mar 27, 2024
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: 1

Actionable comments outside the diff hunks (10)
CHANGELOG.md (10)

Line range hint 325-325: Ensure headings increment by one level at a time for proper document structure.

-## v6.4.0
+### v6.4.0

Line range hint 986-986: Ensure headings increment by one level at a time for proper document structure.

-## v6.3.1
+### v6.3.1

Line range hint 998-998: Ensure headings increment by one level at a time for proper document structure.

-## v6.3.0
+### v6.3.0

Line range hint 1007-1007: Ensure headings increment by one level at a time for proper document structure.

-## v6.2.0
+### v6.2.0

Line range hint 1012-1012: Ensure headings increment by one level at a time for proper document structure.

-## v6.1.0
+### v6.1.0

Line range hint 1064-1064: Ensure headings increment by one level at a time for proper document structure.

-## v6.0.0
+### v6.0.0

Line range hint 325-325: Remove trailing punctuation from heading for consistency.

-## [v6.0.0]
+## [v6.0.0]

Line range hint 588-588: Convert bare URLs to markdown links for better readability and navigation.

-https://github.com/osmosis-labs/osmosis/releases/tag/v6.0.0
+[v6.0.0](https://github.com/osmosis-labs/osmosis/releases/tag/v6.0.0)

Line range hint 646-646: Convert bare URLs to markdown links for better readability and navigation.

-https://github.com/osmosis-labs/osmosis/releases/tag/v6.0.0
+[v6.0.0](https://github.com/osmosis-labs/osmosis/releases/tag/v6.0.0)

Line range hint 1227-1227: Ensure all links are properly formatted and not empty.

-[]
+[Proper link text](link-url)

app/upgrades/v25/upgrades.go Outdated Show resolved Hide resolved
@czarcas7ic
Copy link
Member Author

Expanded a test e9e7c20

^ This would have caught the following bug 352c954

Thanks @PaddyMc for running in place testnet to highlight this

@czarcas7ic czarcas7ic closed this Apr 21, 2024
@czarcas7ic czarcas7ic reopened this Apr 21, 2024
Copy link
Contributor

@AlpinYukseloglu AlpinYukseloglu left a comment

Choose a reason for hiding this comment

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

LGTM! All my comments are non-blocking. Also noting that I didn't manually recompute/verify the swap test changes, but everything else looks good.

x/concentrated-liquidity/pool_test.go Outdated Show resolved Hide resolved
x/concentrated-liquidity/pool_test.go Outdated Show resolved Hide resolved
x/concentrated-liquidity/pool.go Outdated Show resolved Hide resolved
Comment on lines 360 to 361
// Truncated decimal, which is dust that is added back to the global accumulator
truncatedDec = scaledDec.Sub(scaledAmount.ToLegacyDec())
Copy link
Contributor

Choose a reason for hiding this comment

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

If removing this doesn't lead to significant amounts of fees becoming unclaimable I'd be in support of not doing it

Comment on lines +137 to 141
// Update global spread reward growth with the UNSCALED total
// We could scale this up, but we would need to scale it right back down at the end of the swap.
// The globalSpreadRewardGrowth is used to determine how much the user sends to the spread reward address,
// and is not persisted in the pool's tick accumulators.
ss.globalSpreadRewardGrowth = ss.globalSpreadRewardGrowth.Add(spreadRewardChargeTotal)
Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah this looks fine since globalSpreadRewardGrowth is initialized to zero and only used to settle balances post-swap. It does break the boundary of "only operate in scaled space for swaps" but if it's an important performance improvement I think it's okay to keep

I was going to suggest adding a comment on the field in swap strategy proto but I see you've done that already!

x/concentrated-liquidity/swaps.go Show resolved Hide resolved
x/concentrated-liquidity/swaps.go Show resolved Hide resolved
czarcas7ic and others added 5 commits April 22, 2024 23:18
Co-authored-by: Alpo <62043214+AlpinYukseloglu@users.noreply.github.com>
Co-authored-by: Alpo <62043214+AlpinYukseloglu@users.noreply.github.com>
Co-authored-by: Alpo <62043214+AlpinYukseloglu@users.noreply.github.com>
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: 1

Out of diff range and nitpick comments (1)
x/concentrated-liquidity/swaps_test.go (1)

737-770: Consider adding comments to explain the purpose of the test case.

Adding comments to the test cases can help other developers understand the purpose and expected behavior of each test, improving maintainability.

Comment on lines +3152 to +3153
// TODO: Dont hardcode one here
swapState.UpdateSpreadRewardGrowthGlobal(tc.spreadRewardChargeTotal, sdk.OneDec())
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove unnecessary TODO comment or address it if it's still relevant.

- // TODO: Dont hardcode one here
- // TODO: Dont hardcode one here

This TODO comment suggests a potential issue with hardcoding values. If this is still a concern, it should be addressed by parameterizing the value or explaining why it is hardcoded. If it's no longer relevant, the comment should be removed to avoid confusion.


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
// TODO: Dont hardcode one here
swapState.UpdateSpreadRewardGrowthGlobal(tc.spreadRewardChargeTotal, sdk.OneDec())
swapState.UpdateSpreadRewardGrowthGlobal(tc.spreadRewardChargeTotal, sdk.OneDec())

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: 1

Comment on lines +70 to +74
sortedPermAddrs := make([]string, 0, len(k.permAddrs))
for moduleName := range k.permAddrs {
sortedPermAddrs = append(sortedPermAddrs, moduleName)
}
sort.Strings(sortedPermAddrs)
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider caching sorted permission addresses to improve performance.

Sorting permAddrs every time forceTransfer is called could lead to performance issues, especially if the number of permissions is large. Consider caching the sorted list or ensuring that it remains sorted as permissions are added or removed.

@PaddyMc PaddyMc merged commit a156429 into main Apr 26, 2024
1 check passed
@PaddyMc PaddyMc deleted the adam/migrate-subset-of-spread-reward-accums branch April 26, 2024 20:44
@github-actions github-actions bot mentioned this pull request Aug 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants