v0
approval_programs
asset
- class algofi_amm.v0.asset.Asset(amm_client, asset_id)
Bases:
object
- get_scaled_amount(amount)
Returns an integer representation of asset amount scaled by asset’s decimals :param amount: amount of asset :type amount: float :return: int amount of asset scaled by decimals :rtype: int
- refresh_price()
Returns the dollar price of the asset with a simple matching algorithm
balance_delta
- class algofi_amm.v0.balance_delta.BalanceDelta(pool, asset1_delta, asset2_delta, lp_delta, num_iter=0)
Bases:
object
client
- class algofi_amm.v0.client.AlgofiAMMClient(algod_client: AlgodClient, indexer_client: IndexerClient, historical_indexer_client: IndexerClient, user_address, network)
Bases:
object
- get_asset(asset_id)
Returns an
Asset
object representing the asset with given asset id- Parameters
asset_id (int) – asset id
- Returns
Asset
object representing the asset with given asset id- Return type
Asset
- get_pool(pool_type, asset1_id, asset2_id)
Returns a
Pool
object for given assets and pool_type- Parameters
pool_type (
PoolType
) – aPoolType
object for the type of pool (e.g. 30bp, 100bp fee)asset1_id (int) – asset 1 id
asset2_id (int) – asset 2 id
- Returns
a
Pool
object for given assets and pool_type- Return type
Pool
- get_user_balance(asset, address=None)
Returns a amount of asset in user’s balance with asset id asset_id
- Parameters
address (string) – address to get info for
asset (
Asset
) – asset object representing asa
- Returns
amount of asset
- Return type
int
- get_user_balances(address=None)
Returns a dictionary of user balances by asset id
- Parameters
address (string) – address to get info for
- Returns
dictionary of user balances by asset id
- Return type
dict
- get_user_info(address=None)
Returns a dictionary of information about the user
- Parameters
address (string) – address to get info for
- Returns
A dict of information of the user
- Return type
dict
- get_valid_pool_app_ids()
Returns a list of valid pool app ids.
- Returns
a
Pool
object for given assets and pool_type- Return type
Pool
- is_opted_into_app(app_id, address=None)
Returns a boolean if the user address is opted into an application with id app_id
- Parameters
address (string) – address to get info for
app_id (int) – id of the application
- Returns
boolean if user is opted into an application
- Return type
boolean
- is_opted_into_asset(asset, address=None)
Returns a boolean if the user address is opted into an asset with id asset_id
- Parameters
address (string) – address to get info for
asset (
Asset
) – asset object representing asa
- Returns
boolean if user is opted into an asset
- Return type
boolean
- class algofi_amm.v0.client.AlgofiAMMMainnetClient(algod_client=None, indexer_client=None, user_address=None)
Bases:
AlgofiAMMClient
- class algofi_amm.v0.client.AlgofiAMMTestnetClient(algod_client=None, indexer_client=None, user_address=None)
Bases:
AlgofiAMMClient
config
- class algofi_amm.v0.config.PoolStatus(value)
Bases:
Enum
Pool status enum
- ACTIVE = 1
- UNINITIALIZED = 0
- class algofi_amm.v0.config.PoolType(value)
Bases:
Enum
Pool type enum
- CONSTANT_PRODUCT_100BP_FEE = 4
- CONSTANT_PRODUCT_25BP_FEE = 1
- CONSTANT_PRODUCT_30BP_FEE = 2
- CONSTANT_PRODUCT_75BP_FEE = 3
- NANOSWAP = 5
- algofi_amm.v0.config.get_approval_program_by_pool_type(pool_type, network)
Gets the approval program for a given pool type
- algofi_amm.v0.config.get_clear_state_program()
Gets the clear state program
- Returns
clear state program bytecode as list of ints
- Return type
list
- algofi_amm.v0.config.get_manager_application_id(network, is_nanoswap)
Gets the manager application id for the given network
- Parameters
network (str) – network
Network
(“testnet” or “mainnet”)- Returns
manager application id for the given network
- Return type
int
- algofi_amm.v0.config.get_stbl_asset_id(network)
Gets asset id of STBL for a given network
- Parameters
network (str) – network
Network
(“testnet” or “mainnet”)- Returns
asset id of STBL for a given network
- Return type
int
- algofi_amm.v0.config.get_swap_fee(pool_type)
Gets the swap fee for a given pool type
- algofi_amm.v0.config.get_usdc_asset_id(network)
Gets asset id of USDC for a given network
- Parameters
network (str) – network
Network
(“testnet” or “mainnet”)- Returns
asset id of USDC for a given network
- Return type
int
- algofi_amm.v0.config.get_validator_index(network, pool_type)
Gets the validator index for a given pool type and network
logic_sig_generator
- algofi_amm.v0.logic_sig_generator.encode_varint(integer)
Returns bytecode representation of a TEAL Int from an integer
- Parameters
integer (int) – integer to encode
- Returns
list of ints representing bytecode representation of TEAL Int
- Return type
list
- algofi_amm.v0.logic_sig_generator.generate_logic_sig(asset1_id, asset2_id, manager_app_id, validator_index)
Returns a boolean if the user address is opted into an application with id app_id
- Parameters
asset1_id (int) – asset id of first asset in pool
asset1_id – asset id of second asset in pool
manager_app_id (int) – application id of manager
validator_index (int) – validator index for type of pool
- Returns
list of ints representing bytecode representation of logic sig
- Return type
list
pool
- class algofi_amm.v0.pool.Pool(algod_client, indexer_client, historical_indexer_client, network, 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 loanflash_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
orAssetTransferTxn
- 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
orAssetTransferTxn
. 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 swapswap_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
orAssetTransferTxn
. 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 swapswap_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
- refresh_metadata()
Refresh the metadata of the pool (e.g. if now initialized).
- refresh_state(block=None)
Refresh the global state of the pool
- Parameters
block (int, optional) – block at which to query historical state
- sign_txn_with_logic_sig(transaction)
Returns input transaction signed with logic sig of pool
- Parameters
transaction (
Transaction
) – aTransaction
to sign- Returns
transaction signed with logic sig of pool
- Return type
SignedTransaction