swap
Set of utility classes for managing and performing swaps.
- class pactsdk.swap.SwapEffect(amount_received, amount_deposited, minimum_amount_received, fee, primary_asset_price_after_swap, secondary_asset_price_after_swap, primary_asset_price_change_pct, secondary_asset_price_change_pct, price, tx_fee, amplifier)
Bases:
object
Swap Effect are the basic details of the effect on the pool of performing the swap.
- amount_received: int
- amount_deposited: int
- minimum_amount_received: int
- fee: int
- primary_asset_price_after_swap: float
- secondary_asset_price_after_swap: float
- primary_asset_price_change_pct: float
- secondary_asset_price_change_pct: float
- price: float
- tx_fee: int
- amplifier: float
Stableswap only. Zero otherwise.
- class pactsdk.swap.Swap(pool, asset_deposited, amount, slippage_pct, swap_for_exact=False)
Bases:
object
Swap class represents a swap trade on a particular pool.
Typically, users don’t have to manually instantiate this class. Use
pactsdk.pool.Pool.prepare_swap()
instead.- pool: pactsdk.pool.Pool
The pool the swap is going to be performed in.
- asset_deposited: pactsdk.asset.Asset
The asset that will be swapped (deposited in the contract).
- asset_received: pactsdk.asset.Asset
The asset that will be received.
- amount: int
Either the amount to swap (deposit) or the amount to receive depending on the swap_for_exact parameter.
- slippage_pct: float
The maximum percentage of slippage allowed in performing the swap.
- swap_for_exact: bool = False
If true then amount is what you want to receive from the swap. Otherwise, it’s an amount that you want to swap (deposit). Note that the contracts do not support the “swap exact for” swap. It works by calculating the amount to deposit on the client side and doing a normal swap on the exchange.
- effect: pactsdk.swap.SwapEffect
The effect of the swap computed at the time of construction.
- prepare_tx_group(address)
Creates the transactions needed to perform the swap trade and returns them as a transaction group ready to be signed and committed.
- Parameters
address (
str
) – The account that will be performing the swap.- Return type
- Returns
A transaction group that when executed will perform the swap.