velora.swap
Documentation for eth_defi.velora.swap Python module.
Velora (ParaSwap) swap transaction building.
See Velora API documentation for more details.
Functions
|
Build a Velora swap transaction from a quote. |
Classes
Result of a Velora swap execution. |
|
Velora swap transaction data. |
- class VeloraSwapTransaction
Bases:
objectVelora swap transaction data.
Contains all information needed to execute a swap on Augustus Swapper.
- buy_token: eth_defi.token.TokenDetails
Token we are going to receive (token out)
- sell_token: eth_defi.token.TokenDetails
Token we are losing (token in)
- amount_in: decimal.Decimal
Amount of sell_token to spend (human-readable decimals)
- min_amount_out: decimal.Decimal
Minimum amount of buy_token to receive (human-readable decimals)
- to: eth_typing.evm.HexAddress
Augustus Swapper contract address
- calldata: hexbytes.main.HexBytes
Raw calldata to execute on Augustus Swapper
- __init__(buy_token, sell_token, amount_in, min_amount_out, to, calldata, value, price_route)
- Parameters
buy_token (eth_defi.token.TokenDetails) –
sell_token (eth_defi.token.TokenDetails) –
amount_in (decimal.Decimal) –
min_amount_out (decimal.Decimal) –
to (eth_typing.evm.HexAddress) –
calldata (hexbytes.main.HexBytes) –
value (int) –
price_route (dict) –
- Return type
None
- class VeloraSwapResult
Bases:
objectResult of a Velora swap execution.
Contains transaction hash and amounts from the executed swap.
- tx_hash: hexbytes.main.HexBytes
Transaction hash
- buy_token: eth_defi.token.TokenDetails
Token we received
- sell_token: eth_defi.token.TokenDetails
Token we sold
- get_amount_sold_decimal()
Get amount sold in human-readable decimals.
- Return type
- get_amount_bought_decimal()
Get amount bought in human-readable decimals.
- Return type
- __init__(tx_hash, buy_token, sell_token, amount_sold, amount_bought)
- Parameters
tx_hash (hexbytes.main.HexBytes) –
buy_token (eth_defi.token.TokenDetails) –
sell_token (eth_defi.token.TokenDetails) –
amount_sold (int) –
amount_bought (int) –
- Return type
None
- fetch_velora_swap_transaction(quote, user_address, slippage_bps=250, api_timeout=datetime.timedelta(seconds=30), partner=None, deadline=None)
Build a Velora swap transaction from a quote.
This calls the Velora /transactions endpoint to build the actual swap transaction calldata that can be executed on Augustus Swapper.
Example:
from eth_defi.velora.quote import fetch_velora_quote from eth_defi.velora.swap import fetch_velora_swap_transaction # First get a quote quote = fetch_velora_quote( from_=vault_address, buy_token=usdc, sell_token=weth, amount_in=Decimal("0.1"), ) # Then build the swap transaction swap_tx = fetch_velora_swap_transaction( quote=quote, user_address=vault_address, slippage_bps=100, # 1% slippage ) # Execute on Augustus Swapper # tx = web3.eth.send_transaction({ # "to": swap_tx.to, # "data": swap_tx.calldata, # "value": swap_tx.value, # })
- Parameters
quote (eth_defi.velora.quote.VeloraQuote) – Quote from fetch_velora_quote()
user_address (Union[eth_typing.evm.HexAddress, str]) – Address that will execute the swap (the Safe address for vault integration)
slippage_bps (int) – Allowed slippage in basis points (e.g., 250 = 2.5%)
api_timeout (datetime.timedelta) – API request timeout
partner (str | None) – Partner name for analytics tracking
deadline (int | None) – UNIX timestamp after which the transaction is invalid
- Returns
Swap transaction data ready for execution
- Raises
VeloraAPIError – If the API returns an error
- Return type