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

Create CoW AMM Pool #1243

Open
joaobrunoah opened this issue Jan 20, 2025 · 0 comments · May be fixed by #1258
Open

Create CoW AMM Pool #1243

joaobrunoah opened this issue Jan 20, 2025 · 0 comments · May be fixed by #1258

Comments

@joaobrunoah
Copy link
Contributor

joaobrunoah commented Jan 20, 2025

Should create CoW Pool and Factory, as described below:

CoW AMM Pool

CoW AMM Pool inherits WeightedPool and BaseHooks. It accepts swaps and donations only from the Cow AMM Router contract, which is defined by the BalancerContractRegistry contract (type COW_ROUTER).

Contract Variables (all variables are internal)

  • address trustedRouter : A cache of the CoWRouter, informed by BalancerContractRegistry. When pool is created, it should store the Registry value of the router in the trustedRouter variable. It's updated by refreshTrustedRouter function.
  • address balancerContractRegistry : Refer's to the Balancer's Registry of trusted contracts. Must be immutable and set in the constructor.

Functions

refreshTrustedRouter

Updates trustedRouter with value from BalancerContractRegistry

  • Permissionless

getHookFlags

Enables onBeforeSwap and onBeforeAddLiquidity flags

  • Overrides BaseHooks
  • Logic
    • Creates empty HookFlags hookFlags
    • Sets hookFlags.shouldCallBeforeSwap = true
    • Sets hookFlags.shouldCallBeforeAddLiquidity = true
  • Return
    • hookFlags with filled flags

onBeforeSwap

Blocks swaps where routertrustedRouter

  • Overrides BaseHooks
  • Return poolSwapParams.router == trustedRouter

onBeforeAddLiquidity

Blocks Add Liquidity with kind “Donation” if the router is not the trustedRouter. Other types of add liquidity are allowed. Notice that unbalanced liquidity are disabled for this type of pool, so unbalanced add liquidity will revert in the Vault.

  • Overrides BaseHooks
  • Return kindAddLiquidityKind.DONATION or router == trustedRouter

CoW AMM Factory

CoW AMM Factory creates and registers CoW AMM pools . It inherits BasePoolFactory and Version .

Contract Variables

  • address balancerContractRegistry: address of Balancer's registry of trusted contracts. Must be immutable, and set in the constructor.
  • string poolVersion: Version of pools that will be deployed by this factory. Must be immutable, and set in the constructor.

Constructor

Copies the constructor of WeightedPoolFactory , and also sets the balancerContractRegistry address.

Functions

create

Creates and registers a CoW AMM Pool

  • arguments:
    • string name
    • string symbol
    • TokenConfig[] tokens
    • uint256[] memory normalizedWeights
    • PoolRoleAccounts roleAccounts
    • uint256 swapFeePercentage
    • bytes32 salt
  • Logic
    • if roleAccounts.poolCreator ≠ address(0)
      • revert with error StandardPoolWithCreator
    • Creates new LiquidityManagement liquidityManagement
    • liquidityManagement.enableDonation = true
    • liquidityManagement.disableUnbalancedLiquidity = true
    • Creates pool, using the arguments and the balancerContractRegistry address.
    • Register pool in the vault, setting the poolHooksContract as the pool address.
  • Side Note: The event PoolRegistered is emitted by the Vault and has all the information that CoW team needs, so we don't need to emit other events in the factory.
    • indexed pool and factory (CoW AMM Factory)
@joaobrunoah joaobrunoah linked a pull request Jan 23, 2025 that will close this issue
12 tasks
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 a pull request may close this issue.

1 participant