erc_4626.vault_protocol.lagoon.cowswap
Documentation for eth_defi.erc_4626.vault_protocol.lagoon.cowswap Python module.
Cow swap support for Lagoon vaults.
Cow Swap Pythonn SDK https://github.com/cowdao-grants/cow-py
See SwapCowSwap.sol and GuardV0Base.sol
Note
Because CowSwap does not offer any kind of testnet, end-to-end test or unit test support it is a bit hard to work with. You need to perform manual test to ensure the code is working.
See lagoon-cowswap-example.py script for a manual test example.
Notes
On Yearn and Cow integration, see https://medium.com/iearn/yearn-cow-swap-371b6d7cf3b3
Functions
|
Approve cowswap settlement contract to spend tokens on the behalf of Lagoon vault. |
|
Execute a presigned CowSwap order. |
|
Broadcast presigned transcation onchain and return order payload. |
|
Creates a sell order from the vault and executes it on CowSwap. |
|
Construct a pre-signed CowSwap order for the offchain order book to execute using TradingStrategyModuleV0. |
- BroadcastCallback
How we broadcast and confirm our presigned tx
def callback(web3, asset_manager: HexAddress | HotWallet, func: ContractFunction) -> tx hash:
alias of
Callable[[web3.main.Web3,Any,web3.contract.contract.ContractFunction],hexbytes.main.HexBytes]
- approve_cow_swap(vault, token, amount)
Approve cowswap settlement contract to spend tokens on the behalf of Lagoon vault.
- Parameters
vault (eth_defi.erc_4626.vault_protocol.lagoon.vault.LagoonVault) –
token (eth_defi.token.TokenDetails) –
amount (decimal.Decimal) –
- Return type
web3.contract.contract.ContractFunction
- presign_cowswap(vault, buy_token, sell_token, amount_in, min_amount_out, app_data=HexBytes('0x0000000000000000000000000000000000000000000000000000000000000000'))
Construct a pre-signed CowSwap order for the offchain order book to execute using TradingStrategyModuleV0.
- Parameters
app_data – From docs: If you do not care about appData, set this field to “{}” and make sure that the order you signed for this request had its appData field set to
0xb48d38f93eaa084033fc5970bf96e559c33c4cdc07d889ab00b4d63f9590739d.vault (eth_defi.erc_4626.vault_protocol.lagoon.vault.LagoonVault) –
buy_token (eth_defi.token.TokenDetails) –
sell_token (eth_defi.token.TokenDetails) –
amount_in (decimal.Decimal) –
min_amount_out (decimal.Decimal) –
- Return type
web3.contract.contract.ContractFunction
- presign_and_broadcast(asset_manager, vault, buy_token, sell_token, amount_in, min_amount_out, broadcast_callback=<function _default_broadcast_callback>)
Broadcast presigned transcation onchain and return order payload.
Create an order using onchain TradingStrategyModuleV0
Broadcast the onchain transaction
Extract the order data from the event log after the transaction is confirmed
Note
You need to approve the correct amount from the vault on CoW Swap settlemetn contract before executing this.
- Returns
Order data
- Parameters
asset_manager (Union[eth_defi.hotwallet.HotWallet, eth_typing.evm.HexAddress]) –
vault (eth_defi.erc_4626.vault_protocol.lagoon.vault.LagoonVault) –
buy_token (eth_defi.token.TokenDetails) –
sell_token (eth_defi.token.TokenDetails) –
amount_in (decimal.Decimal) –
min_amount_out (decimal.Decimal) –
broadcast_callback (Callable[[web3.main.Web3, Any, web3.contract.contract.ContractFunction], hexbytes.main.HexBytes]) –
- Return type
- execute_presigned_cowswap_order(chain_id, order, trade_timeout=datetime.timedelta(seconds=600), api_timeout=datetime.timedelta(seconds=60))
Execute a presigned CowSwap order.
Post the order to CowSwap API
Wait for the order to complete
- Returns
CowSwapResult with order UID and final status
- Parameters
chain_id (int) –
order (eth_defi.cow.order.GPv2OrderData) –
trade_timeout (datetime.timedelta) –
api_timeout (datetime.timedelta) –
- Return type
- presign_and_execute_cowswap(asset_manager_wallet, vault, buy_token, sell_token, amount_in, min_amount_out, broadcast_callback=<function _default_broadcast_callback>, api_timeout=datetime.timedelta(seconds=60), trade_timeout=datetime.timedelta(seconds=600))
Creates a sell order from the vault and executes it on CowSwap.
Blocks until the order is completed or failed or timed out.
- Raise
Various exceptions from broadcasting and order execution fails/timeouts..
- Parameters
asset_manager_wallet (eth_defi.hotwallet.HotWallet) –
vault (eth_defi.erc_4626.vault_protocol.lagoon.vault.LagoonVault) –
buy_token (eth_defi.token.TokenDetails) –
sell_token (eth_defi.token.TokenDetails) –
amount_in (decimal.Decimal) –
min_amount_out (decimal.Decimal) –
broadcast_callback (Callable[[web3.main.Web3, Any, web3.contract.contract.ContractFunction], hexbytes.main.HexBytes]) –
trade_timeout (datetime.timedelta) –
- Return type