velora.swap

Documentation for eth_defi.velora.swap Python module.

Velora (ParaSwap) swap transaction building.

See Velora API documentation for more details.

Functions

fetch_velora_swap_transaction(quote, ...[, ...])

Build a Velora swap transaction from a quote.

Classes

VeloraSwapResult

Result of a Velora swap execution.

VeloraSwapTransaction

Velora swap transaction data.

class VeloraSwapTransaction

Bases: object

Velora 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

value: int

ETH value to send (usually 0 for ERC-20 swaps)

price_route: dict

Original price route from quote (for reference)

__init__(buy_token, sell_token, amount_in, min_amount_out, to, calldata, value, price_route)
Parameters
Return type

None

class VeloraSwapResult

Bases: object

Result 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

amount_sold: int

Amount of sell_token spent (raw units)

amount_bought: int

Amount of buy_token received (raw units)

get_amount_sold_decimal()

Get amount sold in human-readable decimals.

Return type

decimal.Decimal

get_amount_bought_decimal()

Get amount bought in human-readable decimals.

Return type

decimal.Decimal

__init__(tx_hash, buy_token, sell_token, amount_sold, amount_bought)
Parameters
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

eth_defi.velora.swap.VeloraSwapTransaction