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

Add LBPool #1001

Open
wants to merge 47 commits into
base: main
Choose a base branch
from
Open

Add LBPool #1001

wants to merge 47 commits into from

Conversation

gerrrg
Copy link
Collaborator

@gerrrg gerrrg commented Sep 22, 2024

Description

tl;dr: Create a weight shifting LBPool for V3.

Note

This PR replaces and obsoletes #971 by turning it into a PR from the add-lbpool branch from w/in this repo rather than my fork.

What

  • Port over the main functionality of LBPool from V2 to V3
  • Port over the gradual value change library
  • Create a WeightValidation library for improved portability (could use this in standard WP if desired)
  • Adhere to events for V2 LBP to improve the ease of integration/compatibility
  • Make the pool contract its own hook contract and do beforeJoin hook for onlyOwner LP
  • Store info for only a single weight for higher precision/lower gas since weights must sum to FP.ONE
  • Add relevant tests
  • Modify some inherited tests (BasePoolTest.sol) to be more generalizable/override-able

Why

Modernize a highly popular feature from v2

Type of change

  • Bug fix
  • New feature
  • Breaking change
  • Dependency changes
  • Code refactor / cleanup
  • Optimization: [ ] gas / [ ] bytecode
  • Documentation or wording changes
  • Other

Checklist:

  • The diff is legible and has no extraneous changes
  • Complex code has been commented, including external interfaces
  • [tbd] Tests have 100% code coverage
  • The base branch is either main, or there's a description of how to merge

Issue Resolution

n/a

gerrrg and others added 30 commits July 23, 2024 13:47
…x time to avoid time overflow attack; add misc events and errors; change paused vars to be swapEnabled; add setters and getters for swap enabled/swap fee/gradual update params; add 3 hooks for dynamic swap fee percentage, paused blocking swaps, and only owner can join; build out GradualValueChange library
…BP's add liquidity hook; change terminology back to what it originally was in the interface
…enable swap fee changes by the assigned admin rather than assuming that power has been delegated to governance
…R rather than the placeholder trusted router provider; leave references in comments for future addition
@gerrrg
Copy link
Collaborator Author

gerrrg commented Sep 22, 2024

Copying over summary comment from old PR

I've now incorporated all the changes that @EndymionJkb made in #974 and included them in this PR. I believe we can now close that one; I'll summarize the notes/comments from that review here for convenience to note anything known outstanding.

TODOs from PR #974

  • Consider moving LBPool to pkg/pool-weighted/lbp or similar
  • Consider checking for swapsEnabled in a minimally overridden onSwap rather than in an onBeforeSwap hook to reduce gas costs (using this hook results in a double storage read for balances)
  • Port over v2 LBP tests
  • Consider changing the fn name for updateWeightsGradually since it describes the action as "update" rather than "schedule".
    • pro: it's more clear 👓
    • con: it breaks previous version convention (do we care? 🤷)
  • Consider renaming NormalizedWeightInvariant in WeightedPool (inherited by LBPool) to be more descriptive

Other TODOs

  • LBPFactory test(s)
  • LBPool test coverage

Misc comments/down-the-line TODOs

  • Seedless version
  • {,I}TrustedRouterProvider.sol

@gerrrg
Copy link
Collaborator Author

gerrrg commented Sep 23, 2024

I'm not entirely sure why/how, but Vault Factory changes somehow got pulled into this branch. TODO: get rid of these/resolve the issue that brought them in

@gerrrg
Copy link
Collaborator Author

gerrrg commented Sep 24, 2024

@EndymionJkb I'm not sure if this is a bug in lcov, or if I'm actually doing something wrong here.

For LBPoolFactory.sol, lcov is claiming that the two SLOC in the constructor (setting _poolVersion and _TRUSTED_ROUTER) are not covered, which appears to be incorrect. The constructor has to be invoked in order for the rest of the tests to run, and other tests (like getPoolVersion and the LBP's trusted router test) would undoubtedly fail if these lines were not run.

Other than that, I think I'm at 100% coverage now -- just a bit puzzled by that result

@EndymionJkb
Copy link
Collaborator

@EndymionJkb I'm not sure if this is a bug in lcov, or if I'm actually doing something wrong here.
Other than that, I think I'm at 100% coverage now -- just a bit puzzled by that result

We're aware of issues with coverage. It behaves differently / has holes on both hardhat and forge. Modifiers aren't handled very well, for instance (though that's not what's going on here), which is why they can be run either independently or merged.

It's good to run coverage to make sure you aren't missing anything, but some anomalies are expected, so don't worry about it if it flags something you know actually does run.

Comment on lines +177 to +179
if (!_getPoolSwapEnabled()) {
revert SwapsDisabled();
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not just pause the pool instead?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Pausing would also prevent the owner from adding liquidity. Often these are deployed with swaps disabled, funded at a later point (to set initial prices), the update is scheduled, and then swaps are enabled to start the sale

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.

3 participants