From c25023f5c8cbd69ca7fd70413d70cb2b2f5ae849 Mon Sep 17 00:00:00 2001 From: = Date: Mon, 16 Dec 2024 15:37:54 +0100 Subject: [PATCH 1/5] Add information about integrating cow amms --- docs/cow-amm/tutorials/cow-amm-for-solvers.md | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/docs/cow-amm/tutorials/cow-amm-for-solvers.md b/docs/cow-amm/tutorials/cow-amm-for-solvers.md index 8262335e..9387480c 100644 --- a/docs/cow-amm/tutorials/cow-amm-for-solvers.md +++ b/docs/cow-amm/tutorials/cow-amm-for-solvers.md @@ -21,6 +21,19 @@ All addresses of Balancer CoW AMMs are sent as part of the auction instance as ` The AMM reserves are the balance of the two tokens traded by the AMM. +### Creating CoW AMM orders with the helper contract + +[The source code for the helper contract can be found here.](https://github.com/balancer/cow-amm/blob/main/src/contracts/BCoWHelper.sol) The `orderFromBuyAmount` and 'orderFromSellAmount' methods return the order, preInteractions, postInteractions, and signature. This can be used to generate the order with the CoW AMM and check the prices that the CoW AMM would provide for the order you would like to settle. + +Doing this will generate additional surplus in the solver competition. For example, if a solver would like to settle a user using outside liquidity that trades a pair for which there is a CoW AMM, then that solver can compare those prices with that of the CoW AMM. This (or part of this) interaction can then be replaced with the CoW AMM to generate additional surplus. This way the solver can integrate CoW AMMs by solving as if these CoW AMM's do not exist, and then check whether some of the outside interactions can be replaced by CoW AMMs (note: UPC and EBBO apply to CoW AMMs as well). + +Another way that a solver can use CoW AMM's is by using outside liquidity from the competition/auction to trade with the CoW AMM, thereby re-balancing the AMM and receiving an additional surplus for doing so if the prices of the CoW AMM is off relative to the outside world. + +The helper contracts are deployed here: +- [Mainnet](https://etherscan.io/address/0x03362f847b4fabc12e1ce98b6b59f94401e4588e#code) +- [Arbitrum](https://arbiscan.io/address/0xdb2aeab529c035469e190310def9957ef0398ba8#code) +- [Gnosis](https://gnosisscan.io/address/0xdb2aeab529c035469e190310def9957ef0398ba8#code) + ### Settling a custom order You need to choose a valid CoW Swap order with the following restrictions: From bf4db6a863333050f6a3283900a0b64a0a23416f Mon Sep 17 00:00:00 2001 From: = Date: Sun, 5 Jan 2025 10:18:53 +0100 Subject: [PATCH 2/5] Add CoW AMM factory contracts for Base and Arbitrum --- docs/cow-amm/tutorials/cow-amm-deployer.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/cow-amm/tutorials/cow-amm-deployer.md b/docs/cow-amm/tutorials/cow-amm-deployer.md index a89017c2..ceed4644 100644 --- a/docs/cow-amm/tutorials/cow-amm-deployer.md +++ b/docs/cow-amm/tutorials/cow-amm-deployer.md @@ -14,6 +14,8 @@ The proposed transactions and interactions can be executed through any smart con The current factory contract addresses are the following: - Ethereum Mainnet: [`0xf76c421bAb7df8548604E60deCCcE50477C10462`](https://etherscan.io/address/0xf76c421bAb7df8548604E60deCCcE50477C10462#code) - Gnosis Chain: [`0x703Bd8115E6F21a37BB5Df97f78614ca72Ad7624`](https://gnosisscan.io/address/0x703Bd8115E6F21a37BB5Df97f78614ca72Ad7624#code) +- Arbitrum One: [`0xE0e2Ba143EE5268DA87D529949a2521115987302`](https://arbiscan.io/address/0xe0e2ba143ee5268da87d529949a2521115987302#code) +- Base: [`0x03362f847B4fAbC12e1Ce98b6b59F94401E4588e`](https://basescan.org/address/0x03362f847b4fabc12e1ce98b6b59f94401e4588e#code) - Sepolia Testnet: [`0x1E3D76AC2BB67a2D7e8395d3A624b30AA9056DF9`](https://sepolia.etherscan.io/address/0x1E3D76AC2BB67a2D7e8395d3A624b30AA9056DF9#code) These contracts can be verified through [this](https://github.com/balancer/cow-amm) repository. From 6f11151dca2b3e3b6e97d775eeeade8c8702c034 Mon Sep 17 00:00:00 2001 From: = Date: Fri, 10 Jan 2025 16:41:02 +0100 Subject: [PATCH 3/5] Add Base helper contract --- docs/cow-amm/tutorials/cow-amm-for-solvers.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/cow-amm/tutorials/cow-amm-for-solvers.md b/docs/cow-amm/tutorials/cow-amm-for-solvers.md index 9387480c..2d927eb4 100644 --- a/docs/cow-amm/tutorials/cow-amm-for-solvers.md +++ b/docs/cow-amm/tutorials/cow-amm-for-solvers.md @@ -33,6 +33,7 @@ The helper contracts are deployed here: - [Mainnet](https://etherscan.io/address/0x03362f847b4fabc12e1ce98b6b59f94401e4588e#code) - [Arbitrum](https://arbiscan.io/address/0xdb2aeab529c035469e190310def9957ef0398ba8#code) - [Gnosis](https://gnosisscan.io/address/0xdb2aeab529c035469e190310def9957ef0398ba8#code) +- [Base](https://basescan.org/address/0x467665d4ae90e7a99c9c9af785791058426d6ea0#code) ### Settling a custom order From 1839f34b6ec30acfa7a908421c9988096d87263e Mon Sep 17 00:00:00 2001 From: = Date: Tue, 21 Jan 2025 09:31:01 +0100 Subject: [PATCH 4/5] Update CoW AMM documentation --- docs/cow-amm/tutorials/cow-amm-for-solvers.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/docs/cow-amm/tutorials/cow-amm-for-solvers.md b/docs/cow-amm/tutorials/cow-amm-for-solvers.md index 2d927eb4..997c01db 100644 --- a/docs/cow-amm/tutorials/cow-amm-for-solvers.md +++ b/docs/cow-amm/tutorials/cow-amm-for-solvers.md @@ -23,7 +23,11 @@ The AMM reserves are the balance of the two tokens traded by the AMM. ### Creating CoW AMM orders with the helper contract -[The source code for the helper contract can be found here.](https://github.com/balancer/cow-amm/blob/main/src/contracts/BCoWHelper.sol) The `orderFromBuyAmount` and 'orderFromSellAmount' methods return the order, preInteractions, postInteractions, and signature. This can be used to generate the order with the CoW AMM and check the prices that the CoW AMM would provide for the order you would like to settle. +[The source code for the helper contract can be found here.](https://github.com/balancer/cow-amm/blob/main/src/contracts/BCoWHelper.sol) The `orderFromBuyAmount` and 'orderFromSellAmount' methods return the order, preInteractions, postInteractions, and signature. This can be used to generate the order (JitOrder) with the CoW AMM and check the prices that the CoW AMM would provide for the order you would like to settle. + +Integrating CoW AMM orders requires adding a JitOrder with the CoW AMM. This order should be described from the CoW AMM pool's perspective. So if a user wants to sell token A to buy token B and you would like to settle (part of) this order with a CoW AMM, then you would need to add a JitOrder from the CoW AMM's perspective to match (part of) this order. In other words, you would be adding a JitOrder for the CoW AMM to sell token B to buy token A. You can do this by calling the `orderFromBuyAmount` because the user’s amount is exactly how much you would want the pool to receive, asking for the amount of tokens in exchange. + +One thing to keep in mind when using the helper contract to generate these JitOrders is that both the `orderFromSellAmount` and `orderFromBuyAmount` methods return an order where the `partiallyFillable` field is marked as true. However, since the driver does not support partially fillable JitOrders, it replaces the partiallyFillable field with false. This means that the `partiallyFillable` field must be set to false before passing the solution to the driver and the signature of both the JitOrder and the commit hash in the pre-interaction should be updated accordingly. Doing this will generate additional surplus in the solver competition. For example, if a solver would like to settle a user using outside liquidity that trades a pair for which there is a CoW AMM, then that solver can compare those prices with that of the CoW AMM. This (or part of this) interaction can then be replaced with the CoW AMM to generate additional surplus. This way the solver can integrate CoW AMMs by solving as if these CoW AMM's do not exist, and then check whether some of the outside interactions can be replaced by CoW AMMs (note: UPC and EBBO apply to CoW AMMs as well). From ebbc3de8a5ba6c1631edda34254b3642e204172b Mon Sep 17 00:00:00 2001 From: = Date: Tue, 21 Jan 2025 16:55:27 +0100 Subject: [PATCH 5/5] Apply PR feedback --- docs/cow-amm/tutorials/cow-amm-for-solvers.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/docs/cow-amm/tutorials/cow-amm-for-solvers.md b/docs/cow-amm/tutorials/cow-amm-for-solvers.md index 997c01db..ff7932f3 100644 --- a/docs/cow-amm/tutorials/cow-amm-for-solvers.md +++ b/docs/cow-amm/tutorials/cow-amm-for-solvers.md @@ -23,13 +23,15 @@ The AMM reserves are the balance of the two tokens traded by the AMM. ### Creating CoW AMM orders with the helper contract +Integrating CoW AMM orders requires adding a JitOrder with the CoW AMM. This order should be described from the CoW AMM pool's perspective. So if a user wants to sell token A to buy token B and you would like to settle (part of) this order with a CoW AMM, then you would need to add a JitOrder from the CoW AMM's perspective to match (part of) this order. In other words, you would be adding a JitOrder for the CoW AMM to sell token B to buy token A. You can do this by calling the `orderFromBuyAmount` because the user’s amount is exactly how much you would want the pool to receive, asking for the amount of tokens in exchange. + [The source code for the helper contract can be found here.](https://github.com/balancer/cow-amm/blob/main/src/contracts/BCoWHelper.sol) The `orderFromBuyAmount` and 'orderFromSellAmount' methods return the order, preInteractions, postInteractions, and signature. This can be used to generate the order (JitOrder) with the CoW AMM and check the prices that the CoW AMM would provide for the order you would like to settle. -Integrating CoW AMM orders requires adding a JitOrder with the CoW AMM. This order should be described from the CoW AMM pool's perspective. So if a user wants to sell token A to buy token B and you would like to settle (part of) this order with a CoW AMM, then you would need to add a JitOrder from the CoW AMM's perspective to match (part of) this order. In other words, you would be adding a JitOrder for the CoW AMM to sell token B to buy token A. You can do this by calling the `orderFromBuyAmount` because the user’s amount is exactly how much you would want the pool to receive, asking for the amount of tokens in exchange. +This order generated by the BCoWHelper contract will contain the limit prices for which the CoW AMM is willing to trade. Trading at exactly these limit prices will not generate surplus for the CoW AMM, any price improvement from these limit prices will be surplus captured by the CoW AMM. One thing to keep in mind when using the helper contract to generate these JitOrders is that both the `orderFromSellAmount` and `orderFromBuyAmount` methods return an order where the `partiallyFillable` field is marked as true. However, since the driver does not support partially fillable JitOrders, it replaces the partiallyFillable field with false. This means that the `partiallyFillable` field must be set to false before passing the solution to the driver and the signature of both the JitOrder and the commit hash in the pre-interaction should be updated accordingly. -Doing this will generate additional surplus in the solver competition. For example, if a solver would like to settle a user using outside liquidity that trades a pair for which there is a CoW AMM, then that solver can compare those prices with that of the CoW AMM. This (or part of this) interaction can then be replaced with the CoW AMM to generate additional surplus. This way the solver can integrate CoW AMMs by solving as if these CoW AMM's do not exist, and then check whether some of the outside interactions can be replaced by CoW AMMs (note: UPC and EBBO apply to CoW AMMs as well). +Doing this will generate additional surplus in the solver competition (assuming you trade at a better price than the provided limit price). For example, if a solver would like to settle a user using outside liquidity that trades a pair for which there is a CoW AMM, then that solver can compare those prices with that of the CoW AMM. This (or part of this) interaction can then be replaced with the CoW AMM to generate additional surplus. This way the solver can integrate CoW AMMs by solving as if these CoW AMM's do not exist, and then check whether some of the outside interactions can be replaced by CoW AMMs (note: UPC and EBBO apply to CoW AMMs as well). Another way that a solver can use CoW AMM's is by using outside liquidity from the competition/auction to trade with the CoW AMM, thereby re-balancing the AMM and receiving an additional surplus for doing so if the prices of the CoW AMM is off relative to the outside world.