erc_4626.vault_protocol.lagoon.cowswap

Documentation for eth_defi.erc_4626.vault_protocol.lagoon.cowswap Python module.

Cow swap support for Lagoon vaults.

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

Functions

approve_cow_swap(vault, token, amount)

Approve cowswap settlement contract to spend tokens on the behalf of Lagoon vault.

execute_presigned_cowswap_order(chain_id, order)

Execute a presigned CowSwap order.

presign_and_broadcast(asset_manager, vault, ...)

Broadcast presigned transcation onchain and return order payload.

presign_and_execute_cowswap(...[, ...])

Creates a sell order from the vault and executes it on CowSwap.

presign_cowswap(vault, buy_token, ...[, ...])

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.

See https://github.com/cowprotocol/cow-sdk/blob/5dd3bf5659852590d5d46317bfc19c56e125ca59/packages/trading/src/tradingSdk.ts#L290

Parameters
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
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
Return type

eth_defi.cow.order.GPv2OrderData

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
Return type

eth_defi.cow.status.CowSwapResult

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
Return type

eth_defi.cow.status.CowSwapResult