erc_4626.vault_protocol.lagoon.velora
Documentation for eth_defi.erc_4626.vault_protocol.lagoon.velora Python module.
Velora (ParaSwap) swap support for Lagoon vaults.
Velora is a DEX aggregator that executes swaps atomically, unlike CowSwap which uses an offchain order book and presigning.
Flow:
Fetch quote from Velora API (GET /prices)
Build swap transaction from Velora API (POST /transactions/:network)
Approve TokenTransferProxy via vault’s performCall()
Execute swap via swapAndValidateVelora() on TradingStrategyModuleV0
See Velora developer documentation for more details.
Functions
|
High-level function: fetch quote, build tx, approve, and execute swap. |
|
Approve Velora TokenTransferProxy to spend tokens on behalf of the vault. |
|
Build swapAndValidateVelora() call on TradingStrategyModuleV0. |
|
Execute a Velora swap through the vault. |
- approve_and_execute_velora_swap(asset_manager_wallet, vault, buy_token, sell_token, amount_in, broadcast_callback=<function _default_broadcast_callback>, slippage_bps=250, api_timeout=datetime.timedelta(seconds=30))
High-level function: fetch quote, build tx, approve, and execute swap.
This is the main entry point for executing Velora swaps through a Lagoon vault.
Example:
from decimal import Decimal from eth_defi.erc_4626.vault_protocol.lagoon.velora import approve_and_execute_velora_swap from eth_defi.token import fetch_erc20_details weth = fetch_erc20_details(web3, "0x82aF49447D8a07e3bd95BD0d56f35241523fBab1") usdc = fetch_erc20_details(web3, "0xaf88d065e77c8cC2239327C5EDb3A432268e5831") result = approve_and_execute_velora_swap( asset_manager_wallet=hot_wallet, vault=lagoon_vault, buy_token=usdc, sell_token=weth, amount_in=Decimal("0.1"), slippage_bps=100, # 1% slippage ) print(f"Swapped {result.get_amount_sold_decimal()} WETH for {result.get_amount_bought_decimal()} USDC")
- Parameters
asset_manager_wallet (eth_defi.hotwallet.HotWallet) – Hot wallet of the asset manager
vault (eth_defi.erc_4626.vault_protocol.lagoon.vault.LagoonVault) – Lagoon vault instance
buy_token (eth_defi.token.TokenDetails) – Token to receive
sell_token (eth_defi.token.TokenDetails) – Token to sell
amount_in (decimal.Decimal) – Amount of sell_token to swap (human-readable decimals)
broadcast_callback (Callable[[web3.main.Web3, Any, web3.contract.contract.ContractFunction], hexbytes.main.HexBytes]) – Callback to broadcast transactions
slippage_bps (int) – Allowed slippage in basis points (e.g., 250 = 2.5%)
api_timeout (datetime.timedelta) – API request timeout
- Returns
VeloraSwapResult with transaction hash and amounts
- Raises
VeloraAPIError – If the Velora API returns an error
- Return type
- approve_velora(vault, token, amount)
Approve Velora TokenTransferProxy to spend tokens on behalf of the vault.
Warning
Approve TokenTransferProxy, NOT Augustus Swapper. Funds may be lost if approved to Augustus directly.
- Parameters
vault (eth_defi.erc_4626.vault_protocol.lagoon.vault.LagoonVault) – Lagoon vault instance
token (eth_defi.token.TokenDetails) – Token to approve
amount (decimal.Decimal) – Amount to approve (human-readable decimals)
- Returns
Contract function to execute via performCall
- Return type
web3.contract.contract.ContractFunction
- build_velora_swap(vault, buy_token, sell_token, amount_in, min_amount_out, augustus_calldata)
Build swapAndValidateVelora() call on TradingStrategyModuleV0.
- Parameters
vault (eth_defi.erc_4626.vault_protocol.lagoon.vault.LagoonVault) – Lagoon vault instance
buy_token (eth_defi.token.TokenDetails) – Token to receive
sell_token (eth_defi.token.TokenDetails) – Token to sell
amount_in (decimal.Decimal) – Amount of sell_token to swap (human-readable decimals)
min_amount_out (decimal.Decimal) – Minimum amount of buy_token to receive (human-readable decimals)
augustus_calldata (hexbytes.main.HexBytes) – Raw calldata from Velora API to execute on Augustus Swapper
- Returns
Contract function to execute
- Return type
web3.contract.contract.ContractFunction
- execute_velora_swap(asset_manager, vault, buy_token, sell_token, amount_in, min_amount_out, augustus_calldata, broadcast_callback=<function _default_broadcast_callback>)
Execute a Velora swap through the vault.
This builds and broadcasts the swapAndValidateVelora() transaction and extracts the result from the VeloraSwapExecuted event.
- Parameters
asset_manager (Union[eth_defi.hotwallet.HotWallet, eth_typing.evm.HexAddress]) – Hot wallet or address of the asset manager
vault (eth_defi.erc_4626.vault_protocol.lagoon.vault.LagoonVault) – Lagoon vault instance
buy_token (eth_defi.token.TokenDetails) – Token to receive
sell_token (eth_defi.token.TokenDetails) – Token to sell
amount_in (decimal.Decimal) – Amount of sell_token to swap (human-readable decimals)
min_amount_out (decimal.Decimal) – Minimum amount of buy_token to receive (human-readable decimals)
augustus_calldata (hexbytes.main.HexBytes) – Raw calldata from Velora API to execute on Augustus Swapper
broadcast_callback (Callable[[web3.main.Web3, Any, web3.contract.contract.ContractFunction], hexbytes.main.HexBytes]) – Callback to broadcast the transaction
- Returns
VeloraSwapResult with transaction hash and amounts
- Return type