approve_and_execute_velora_swap
Documentation for eth_defi.erc_4626.vault_protocol.lagoon.velora.approve_and_execute_velora_swap function.
- 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