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

Merged
merged 74 commits into from
Jan 2, 2025
Merged

Add LBPool #1001

merged 74 commits into from
Jan 2, 2025

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
Copy link
Contributor

@elshan-eth elshan-eth left a comment

Choose a reason for hiding this comment

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

Looks good! I have a couple of minor comments

pkg/pool-weighted/contracts/lbp/LBPool.sol Outdated Show resolved Hide resolved
pkg/pool-weighted/contracts/lbp/LBPool.sol Outdated Show resolved Hide resolved
pkg/pool-weighted/contracts/lbp/LBPool.sol Outdated Show resolved Hide resolved
pkg/pool-weighted/test/LBPool.test.ts Outdated Show resolved Hide resolved
Copy link
Contributor

@jubeira jubeira left a comment

Choose a reason for hiding this comment

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

Just a few minor comments, but otherwise looks great and makes a lot of sense.

Thanks @gerrrg ! And happy holidays btw :)
I'll take it from here.

// could spoof the address of the owner, allowing anyone to call permissioned functions.

// solhint-disable-next-line var-name-mixedcase
address private immutable _TRUSTED_ROUTER;
Copy link
Contributor

Choose a reason for hiding this comment

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

I see no reason in principle for this to change, but it does pose a maintainability question in case we ever migrate routers and the SDK / frontend need to adapt.

If we expect the lifecycle of these pools to be rather bounded I guess this is fine, as it's the simplest / cheapest approach.

Copy link
Contributor

Choose a reason for hiding this comment

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

Also let's add a getter here.

Copy link
Collaborator

@EndymionJkb EndymionJkb Dec 31, 2024

Choose a reason for hiding this comment

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

The other reason is Daniel said we did want to support at least two from launch: basic and batch. If we have the registry (see PR #1296), we could use that. It would be equivalent to gerrg's original "provider" idea, and the maintenance would be done in the registry, so we wouldn't need to worry about it here. (And then we don't need a getter.)

Copy link
Collaborator

Choose a reason for hiding this comment

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

It would look like:

IBalancerContractRegistry private immutable _contractRegistry;

constructor(
    NewPoolParams memory params,
    IVault vault,
    address owner,
    bool swapEnabledOnStart,
    IBalancerContractRegistry contractRegistry
) WeightedPool(params, vault) Ownable(owner) {
    _contractRegistry = contractRegistry;
}

onBefore hooks:
{
    if (_contractRegistry.isActiveBalancerContract(ContractType.ROUTER, router) == false) {
        revert RouterNotTrusted();
    }

    return IRouterCommon(router).getSender() == owner();
}

Copy link
Contributor

Choose a reason for hiding this comment

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

The other reason is Daniel said we did want to support at least two from launch: basic and batch. If we have the registry (see PR #1296), we could use that. It would be equivalent to gerrg's original "provider" idea, and the maintenance would be done in the registry, so we wouldn't need to worry about it here. (And then we don't need a getter.)

Sounds like an overkill really.
The trusted router is only used to add liquidity, and block non-owners from adding liquidity. You can still use any router to swap.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Right... so really the only benefit would be not having to redeploy if we update the basic router (which should be rare compared to adding a new router or updating something more relay-like such as the CLR router)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@jubeira good point that the router only affects liquidity provision. Definitely makes it less of an issue, though I do still think it would be best to allow any "approved" router

For more context, the singular trusted router setup that is in the contract was 100% meant to be a placeholder until there was a router provider/contact registry. Simplifying it to be a single router made it possible for me to get unblocked in the meantime

Copy link
Contributor

Choose a reason for hiding this comment

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

thanks, I'll double check.
I think this is a good starting point anyways.

pkg/pool-weighted/contracts/lbp/LBPool.sol Outdated Show resolved Hide resolved
pkg/pool-weighted/contracts/lbp/LBPool.sol Show resolved Hide resolved
pkg/pool-weighted/contracts/lbp/LBPoolFactory.sol Outdated Show resolved Hide resolved
pkg/pool-weighted/contracts/lbp/LBPoolFactory.sol Outdated Show resolved Hide resolved
*
* @param router The address (usually a router contract) that initiated the add liquidity operation
*/
function onBeforeAddLiquidity(
Copy link
Contributor

Choose a reason for hiding this comment

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

What about initialize?

Copy link
Contributor

Choose a reason for hiding this comment

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

Well initialize doesn't have the router argument, so we can't do the same approach.

But we can create and initialize in the same tx. I'll add a method in the factory.

pkg/pool-weighted/test/foundry/LBPool.t.sol Outdated Show resolved Hide resolved
pkg/pool-weighted/test/foundry/LBPool.t.sol Outdated Show resolved Hide resolved
pkg/pool-weighted/test/foundry/LBPool.t.sol Outdated Show resolved Hide resolved
pkg/vault/test/foundry/utils/BasePoolTest.sol Show resolved Hide resolved
Copy link
Collaborator

@EndymionJkb EndymionJkb left a comment

Choose a reason for hiding this comment

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

Agree with the suggestions; ideally would review and merge the registry, then update this one to use it as a source of trusted routers (or we can add a follow-on PR).

@jubeira jubeira requested a review from EndymionJkb January 2, 2025 16:44
Copy link
Collaborator

@EndymionJkb EndymionJkb left a comment

Choose a reason for hiding this comment

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

Looks better now; seems the initialization method is still pending? I suppose we could do both: keep the factory method, and also add the onBeforeInitialize hook and check _trustedRouter.getSender() in it.

pkg/pool-weighted/contracts/lbp/LBPool.sol Outdated Show resolved Hide resolved
pkg/pool-weighted/contracts/lbp/LBPool.sol Outdated Show resolved Hide resolved
pkg/pool-weighted/contracts/lbp/LBPool.sol Show resolved Hide resolved
pkg/pool-weighted/contracts/lbp/LBPool.sol Outdated Show resolved Hide resolved
@jubeira jubeira requested a review from EndymionJkb January 2, 2025 19:28
Copy link
Collaborator

@EndymionJkb EndymionJkb left a comment

Choose a reason for hiding this comment

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

Looks good! I'm sure we'll continue to iterate on this in follow-ons, but I think it's a fine starting point.

@jubeira jubeira merged commit b1293dc into main Jan 2, 2025
13 checks passed
@jubeira jubeira deleted the add-lbpool branch January 2, 2025 22:50
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.

4 participants