pool_calculator
- class pactsdk.pool_calculator.SwapCalculator(*args, **kwargs)
Bases:
Protocol
- pool: pactsdk.pool.Pool
- get_price(liq_a, liq_b)
Calculates the price of assets. Accepts and returns decimal values.
- Parameters
liq_a (
float
) – Primary liquidity if calculating price for primary asset, secondary otherwise.liq_b (
float
) – Secondary liquidity if calculating price for primary asset, primary otherwise.
- Return type
float
- Returns
The price of one asset in relation to the other.
- get_swap_gross_amount_received(liq_a, liq_b, amount_deposited)
Converts amountDeposited to amountReceived. Ignores fee calculations.
- Parameters
liq_a (
int
) – Primary liquidity if swapping primary asset, secondary otherwise.liq_b (
int
) – Secondary liquidity if swapping primary asset, primary otherwise.amount_deposited (
int
) – Amount of the asset deposited in the contract.
- Return type
int
- Returns
Amount of asset received from the contract after swap.
- get_swap_amount_deposited(liq_a, liq_b, amount_received)
Converts amountReceived to amountDeposited. Ignores fee calculations.
- Parameters
liq_a (
int
) – Primary liquidity if swapping primary asset, secondary otherwise.liq_b (
int
) – Secondary liquidity if swapping primary asset, primary otherwise.amount_received (
int
) – Amount of asset the user want to receive from the swap.
- Return type
int
- Returns
Amount of the asset the user has to deposit in the contract.
- get_minted_liquidity_tokens(added_liq_a, added_liq_b)
Returns amount of liquidity tokens that are going to be minted when adding liquidity.
- Parameters
added_liq_a (
int
) – Amount of primary asset to add to the pool.added_liq_b (
int
) – Amount of secondary asset to add to the pool.
- Return type
int
- Returns
Amount of liquidity tokens that will be minted and given to user.
- class pactsdk.pool_calculator.PoolCalculator(pool)
Bases:
object
Contains functions for calculation statistics and other numerical data about the pool.
The pool calculator uses internal data from the pool to calculate values like the Prices, Net Amounts and values for the swap. Uses different formulas based on pool type.
- property primary_asset_amount: int
- Return type
int
- property secondary_asset_amount: int
- Return type
int
- property primary_asset_amount_decimal: float
- Return type
float
- property secondary_asset_amount_decimal: float
- Return type
float
- property is_empty: bool
Checks if the pool is currently empty.
A pool is empty if either the primary or secondary asset is zero.
- Return type
bool
- Returns
True if the pool is empty, False otherwise.
- property primary_asset_price: float
Returns: Amount of secondary assets for a single primary asset.
- Return type
float
- property secondary_asset_price: float
Returns: Amount of primary assets for a single secondary asset.
- Return type
float
- amount_deposited_to_net_amount_received(asset, amount_deposited)
Converts amount deposited in the contract to amount received from the contract. Includes fee calculations.
- Parameters
asset (
Asset
) – Asset to deposit in the contract.amount_deposited (
int
) – Amount to deposit in the contract.
- Return type
int
- Returns
The amount to receive from the contract.
- net_amount_received_to_amount_deposited(asset, net_amount_received)
Converts amount received from the contract to amount deposited in the contract.
- Parameters
asset (
Asset
) – Asset to deposit in the contract.amount_deposited – Amount to receive from the contract.
- Return type
int
- Returns
The amount to deposit in the contract.
- get_fee_from_gross_amount(gross_amount)
Calculates the fee from the gross amount based on pool’s fee_bps.
- Parameters
gross_amount (
int
) – The amount to receive from the contract not yet lessened by the fee.- Return type
int
- Returns
The calculated fee.
- get_fee_from_net_amount(net_amount)
Calculates the fee from the net amount based on pool’s fee_bps. This is used in the swap for exact calculations.
- Parameters
net_amount (
int
) – The amount to receive from the contract already lessened by the fee.- Return type
int
- Returns
The calculated fee.
- get_liquidities(asset)
Returns the array of liquidities from the pool, sorting them by setting provided asset as primary.
- Parameters
asset (
Asset
) – The asset that is supposed to be the primary one.- Return type
tuple
[int
,int
]- Returns
Total liquidities of assets.
- get_minimum_amount_received(asset, amount, slippage_pct)
Based on the deposited amount and a slippage, calculate the minimum amount the user will receive from the contract.
- Parameters
asset (
Asset
) – The asset to deposit in the contract.amount_deposited – The amount to deposit in the contract.
slippage_pct (
float
) – Slippage in percents.
- Return type
int
- Returns
The minimum amount to receive from the contract.
- get_fee(asset, amount_deposited)
Calculates the exchange fee based on deposited amount.
- Parameters
asset (
Asset
) – The asset to deposit in the contract.amount_deposited (
int
) – The amount to deposit in the contract.
- Return type
int
- Returns
The calculated fee.
- get_asset_price_after_liq_change(asset, primary_liq_change, secondary_liq_change)
Simulates new asset price after changing the pool’s liquidity.
- Parameters
asset (
Asset
) – The asset for which to calculate the price for.primary_liq_change (
int
) – The change of primary liquidity on the pool.secondary_liq_change (
int
) – The change of secondary liquidity on the pool.
- Return type
float
- Returns
New asset price.
- get_price_impact_pct(asset, primary_liq_change, secondary_liq_change)
Calculates the price impact of changing the liquidity in a certain way.
- Parameters
asset (
Asset
) – The asset for which to calculate the price impact for.primary_liq_change (
int
) – The change of primary liquidity on the pool.secondary_liq_change (
int
) – The change of secondary liquidity on the pool.
- Return type
float
- Returns
The asset price impact.
- get_swap_price(asset_deposited, amount_deposited)
Calculates the price for which the asset in going to be swapped.
- Parameters
asset_deposited (
Asset
) – The asset deposited in the contract.amount_deposited (
int
) – The amount deposited in the contract.
- Return type
float
- Returns
The price of deposited asset in relation to received asset.