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 VeloraSwapResult

Bases: object

Result of a Velora swap execution.

Contains transaction hash and amounts from the executed swap.

__init__(tx_hash, buy_token, sell_token, amount_sold, amount_bought)
Parameters
Return type

None

get_amount_bought_decimal()

Get amount bought in human-readable decimals.

Return type

decimal.Decimal

get_amount_sold_decimal()

Get amount sold in human-readable decimals.

Return type

decimal.Decimal

class VeloraSwapTransaction

Bases: object

Velora swap transaction data.

Contains all information needed to execute a swap on Augustus Swapper.

__init__(buy_token, sell_token, amount_in, min_amount_out, to, calldata, value, price_route)
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
Returns

Swap transaction data ready for execution

Raises

VeloraAPIError – If the API returns an error

Return type

eth_defi.velora.swap.VeloraSwapTransaction