pool

class algofipy.amm.v1.pool.Pool(amm_client, pool_type, asset1, asset2)

Bases: object

property amplification_factor
get_burn_quote(lp_amount)

Get burn quote for a given amount of lps to burn

Parameters:

lp_amount (int) – lp amount to burn

Returns:

burn quote for a given amount of lps to burn

Return type:

BalanceDelta

get_burn_txns(sender, burn_amount, params=None)

Get group transaction for burn with given burn amount. The LP token is transferred via AssetTransferTxn. Then, two burn calls are made, one for each asset.

Parameters:
  • sender (str) – sender

  • burn_amount (int) – lp asset amount to burn

Returns:

group transaction for burn with given burn amount

Return type:

TransactionGroup

get_create_pool_txn(sender, params=None)

Returns unsigned CreatePool transaction with given sender

Parameters:

sender (str) – sender

Returns:

unsigned CreatePool transaction with given sender

Return type:

ApplicationCreateTxn

get_empty_pool_quote(asset1_pooled_amount, asset2_pooled_amount)

Get pool quote for an empty pool

Parameters:
  • asset1_pooled_amount (int) – asset 1 pooled amount

  • asset2_pooled_amount (int) – asset 2 pooled amount

Returns:

pool quote for an empty pool

Return type:

BalanceDelta

get_flash_loan_txns(sender, flash_loan_asset, flash_loan_amount, group_transaction, params=None)

Get group transaction for swap exact for transaction

Parameters:
  • sender (str) – sender

  • flash_loan_asset (Asset) – asset to borrow in flash loan

  • flash_loan_amount (int) – asset amount to borrow

  • group_transaction (TransactionGroup) – a group transaction to “sandwich” between flash loan transaction

Returns:

group transaction for flash loan transaction composed with group transaction

Return type:

TransactionGroup

get_initialize_pool_txns(sender, pool_app_id, params=None)

Get group transaction for initializing the pool. First, the manager is funded (which funds the pool contract (for opting into assets, creating LP token) via an inner payment txn. Then, the logic sig is funded to opt into manager. After, the sender calls the initialize function on the pool. This transaction “registers” the pool with the manager so it is searchable via SDK.

Parameters:
  • sender (str) – sender

  • pool_app_id (int) – application id of the pool to initialize

Returns:

unsigned group transaction TransactionGroup with sender for initializing pool

Return type:

TransactionGroup

get_lp_token_opt_in_txn(sender, params=None)

Get lp token opt in transaction for the given sender

Parameters:

sender (str) – sender

Returns:

lp token opt in transaction for the given sender

Return type:

PaymentTxn or AssetTransferTxn

get_pool_price(asset_id)

Gets the price of the pool in terms of the asset with given asset_id :param asset_id: asset id of the asset to price :type asset_id: int :return: price of pool in terms of asset with given asset_id :rtype: float

get_pool_quote(asset_id, asset_amount)

Get full pool quote for a given asset id and amount

Parameters:
  • asset_id (int) – asset id of the asset to pool

  • asset_amount (int) – asset amount of the asset to pool

Returns:

pool quote for a non-empty pool

Return type:

BalanceDelta

get_pool_txns(sender, asset1_amount, asset2_amount, maximum_slippage, params=None, fee=3000)

Get group transaction for pooling with given asset amounts and maximum slippage. The two assets are sent via two PaymentTxn / AssetTransferTxn. Then, a pool call is made from which the LP tokens are issued via inner asset transfer txn. Lastly, two redeem residual calls are made to redeem residuals of assets 1 and 2 that are not used in the pooling operation. The ratio of the incoming asset amounts is compared to the ratio on the smart contract. If it differs (up or down) by more than the max_slippage percent, the transaction fails.

Parameters:
  • sender (str) – sender

  • asset1_amount (int) – asset amount for the first asset

  • asset2_amount (int) – asset amount for the second asset

  • maximum_slippage (int) – maximum slippage percent (scaled by 1000000) allowed

Returns:

group transaction for pooling with given asset amounts and maximum slippage

Return type:

TransactionGroup

get_swap_exact_for_quote(swap_in_asset_id, swap_in_amount)

Get swap exact for quote for a given asset id and swap amount

Parameters:
  • swap_in_asset_id (int) – id of incoming asset to swap

  • swap_in_amount (int) – amount of incoming asset to swap

Returns:

swap exact for quote for a given asset id and swap amount

Return type:

BalanceDelta

get_swap_exact_for_txns(sender, swap_in_asset, swap_in_amount, min_amount_to_receive, params=None, fee=2000)

Get group transaction for swap exact for transaction. An exact amount of the asset to be swapped is sent via a PaymentTxn or AssetTransferTxn. Then, a swap exact for call is made from which the output asset is sent via inner transaction. If the output asset amount exceeds the min_amount_to_receive, the transaction succeeds.

Parameters:
  • sender (str) – sender

  • swap_in_asset (Asset) – asset to swap

  • swap_in_amount (int) – asset amount of incoming asset

  • min_amount_to_receive (int) – minimum amount of outgoing asset to receive, assert failure if not

Returns:

group transaction for swap exact for transaction

Return type:

TransactionGroup

get_swap_for_exact_quote(swap_out_asset_id, swap_out_amount)

Get swap for exact quote for a given asset id and swap amount

Parameters:
  • swap_out_asset_id (int) – id of outgoing asset

  • swap_out_amount (int) – amount of outgoing asset

Returns:

swap for exact quote for a given outgoing asset id and amount

Return type:

BalanceDelta

get_swap_for_exact_txns(sender, swap_in_asset, swap_in_amount, amount_to_receive, params=None, fee=2000)

Get group transaction for swap for exact transaction. An amount of the asset to be swapped is sent via a PaymentTxn or AssetTransferTxn. Then, swap for exact call is made to swap for an exact amount of the output asset. If a sufficient amount of the incoming asset has been sent, the transaction succeeds. If it succeeds, a residual amount of the incoming asset is redeemed by the user in the next call.

Parameters:
  • sender (str) – sender

  • swap_in_asset (Asset) – asset to swap

  • swap_in_amount (int) – asset amount of incoming asset

  • amount_to_receive (int) – exact amount to receive of outgoing asset, assert fail if not possible

Returns:

group transaction for swap for exact transaction

Return type:

TransactionGroup

load_state(block=None)

Refresh the global state of the pool

Parameters:

block (int, optional) – block at which to query historical state

refresh_lp_token_price()

Refresh the dollar price of the LP token for this pool

refresh_metadata()

Refresh the metadata of the pool (e.g. if now initialized).

sign_txn_with_logic_sig(transaction)

Returns input transaction signed with logic sig of pool

Parameters:

transaction (Transaction) – a Transaction to sign

Returns:

transaction signed with logic sig of pool

Return type:

SignedTransaction