|
| 1 | +--- |
| 2 | +sidebar_position: 1 |
| 3 | +--- |
| 4 | + |
| 5 | +# Deploying a CoW AMM Using Balancer |
| 6 | + |
| 7 | +In this short tutorial, we describe how you can create and deploy their own Balancer CoW AMM. |
| 8 | + |
| 9 | +**You may also deploy a CoW AMM through the Balancer UI using [this guide.](https://cow.finance/learn/how-to-create-a-lvr-protected-liquidity-pool-on-cowamm)** |
| 10 | + |
| 11 | +The proposed transactions and interactions can be executed through any smart contract or EOA transaction builder, Etherscan "Write Contract," from other UI mechanisms, or directly from the console. |
| 12 | + |
| 13 | +The current factory contract addresses are the following: |
| 14 | + |
| 15 | +- Ethereum Mainnet: [`0xf76c421bAb7df8548604E60deCCcE50477C10462`](https://etherscan.io/address/0xf76c421bAb7df8548604E60deCCcE50477C10462#code) |
| 16 | +- Gnosis Chain: [`0x703Bd8115E6F21a37BB5Df97f78614ca72Ad7624`](https://gnosisscan.io/address/0x703Bd8115E6F21a37BB5Df97f78614ca72Ad7624#code) |
| 17 | +- Arbitrum One: [`0xE0e2Ba143EE5268DA87D529949a2521115987302`](https://arbiscan.io/address/0xe0e2ba143ee5268da87d529949a2521115987302#code) |
| 18 | +- Base: [`0x03362f847B4fAbC12e1Ce98b6b59F94401E4588e`](https://basescan.org/address/0x03362f847b4fabc12e1ce98b6b59f94401e4588e#code) |
| 19 | +- Avalanche: N/A |
| 20 | +- Polygon: N/A |
| 21 | +- BNB: N/A |
| 22 | +- Linea: N/A |
| 23 | +- Plasma: N/A |
| 24 | +- Sepolia Testnet: [`0x1E3D76AC2BB67a2D7e8395d3A624b30AA9056DF9`](https://sepolia.etherscan.io/address/0x1E3D76AC2BB67a2D7e8395d3A624b30AA9056DF9#code) |
| 25 | + |
| 26 | +These contracts can be verified through [this](https://github.com/balancer/cow-amm) repository. |
| 27 | + |
| 28 | +1. In order to create a new pool, one first needs to call the `newBPool` function of the factory contract. An example transaction that creates a new pool can be found [here](https://etherscan.io/tx/0x7543a97853827e267ecd3c1309509ac7704e4f85a53fbfacd6060f461d85bad8#eventlog). The relevant `LOG_NEW_POOL` log also reveals the address of the newly created pool; in our example transaction, it is `0x81530e9B069c69F6671A0A9d7Ee337cafEF419F6`. |
| 29 | + |
| 30 | +:::note |
| 31 | + |
| 32 | +In case ABI of the factory contract is not fetched, the ABI from the Sepolia network can be used. |
| 33 | +::: |
| 34 | + |
| 35 | +1. The next step is to approve the tokens we want to add to the pool; this can be done by calling the `approve()` function on the contract of the relevant ERC-20 token that is being added to the pool, where the "spender" needs to be set to the newly created BPool address from (1). |
| 36 | + |
| 37 | +:::caution |
| 38 | + |
| 39 | +One needs to take the token's decimals into account in order to set the correct approval. |
| 40 | +::: |
| 41 | + |
| 42 | +1. The next step is to bind the approved tokens to the pool, by using the `bind()` function of the newly created pool contract. We need to do one bind per token that will be added to the pool. Note that the `denorm` parameter should always be set to 1000000000000000000 (i.e., 10^18). |
| 43 | + |
| 44 | +2. We can then set the swap fee; this is the fee trades will pay if they trade permissionlessly (i.e., outside of the batch), and this is done by calling the `setSwapFee()` function of the pool contract. The fee parameter needs to be specified in wei, hence, a 10% fee would be 100000000000000000 (i.e., 10^17) |
| 45 | + |
| 46 | +:::note |
| 47 | + |
| 48 | +In order to guarantee full LVR protection, the fee should be set to 100%. |
| 49 | +::: |
| 50 | + |
| 51 | +:::caution |
| 52 | + |
| 53 | +The fee parameter is an unsigned integer where 10^18 corresponds to 100% of fee. Note that 100% is actually not a valid value though, but one can set up to 99.99%. |
| 54 | +::: |
| 55 | + |
| 56 | +1. The final step is to finalize the pool by calling the `finalize()` function of the newly created pool contract. |
0 commit comments