algofi

utils

class algofi.utils.TransactionGroup(transactions)

Bases: object

sign_with_private_key(address, private_key)

Signs the transactions with specified private key and saves to class state

Parameters:
  • address (string) – account address of the user

  • private_key (string) – private key of user

sign_with_private_keys(private_keys)

Signs the transactions with specified list of private keys and saves to class state

Parameters:

private_key (string) – private key of user

submit(algod, wait=False)

Submits the signed transactions to network using the algod client

Parameters:
  • algod (AlgodClient) – algod client

  • wait (boolean, optional) – wait for txn to complete, defaults to False

Returns:

dict of transaction id

Return type:

dict

class algofi.utils.Transactions(value)

Bases: Enum

An enumeration.

ADD_COLLATERAL = 3
BORROW = 7
BURN = 5
CLAIM_REWARDS = 10
LIQUIDATE = 9
MINT = 1
MINT_TO_COLLATERAL = 2
REMOVE_ALGOS_FROM_VAULT = 12
REMOVE_COLLATERAL = 4
REMOVE_COLLATERAL_UNDERLYING = 6
REPAY_BORROW = 8
SEND_GOVERNANCE_TXN = 14
SEND_KEYREG_OFFLINE_TXN = 16
SEND_KEYREG_ONLINE_TXN = 15
SUPPLY_ALGOS_TO_VAULT = 11
SYNC_VAULT = 13
algofi.utils.encode_value(value, type)
algofi.utils.encode_varint(number)
algofi.utils.format_state(state)

Returns state dict formatted to human-readable strings

Parameters:

state (dict) – dict of state returned by read_local_state or read_global_state

Returns:

dict of state with keys + values formatted from bytes to utf-8 strings

Return type:

dict

algofi.utils.get_accounts_opted_into_app(indexer, app_id)

Submits the signed transactions to network using the algod client :param indexer: indexer client :type indexer: IndexerClient :param app_id: application id :type app_id: int :return: list of accounts opted into app :rtype: list

algofi.utils.get_global_state_field(indexer_client, app_id, field_name, block=None)

Returns field of global state for application with the given app_id

Parameters:
  • indexer_client (IndexerClient) – indexer client

  • app_id (int) – id of the application

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

Returns:

value of global state variable for app

Return type:

dict

algofi.utils.get_init_round(chain)

Returns init round of algofi protocol for a specified chain. Pulled from hardcoded values in contracts.json.

Parameters:

chain (string e.g. 'testnet') – network to query data for

Returns:

init round of algofi protocol on specified chain

Return type:

string

algofi.utils.get_manager_app_id(chain)

Returns app id of manager for the specified chain. Pulled from hardcoded values in contracts.json.

Parameters:

chain (string e.g. 'testnet') – network to query data for

Returns:

manager app id

Return type:

int

algofi.utils.get_market_app_id(chain, symbol)

Returns market app id of symbol for the specified chain. Pulled from hardcoded values in contracts.json.

Parameters:
  • chain (string e.g. 'testnet') – network to query data for

  • symbol (string e.g. 'ALGO') – symbol to get market data for

Returns:

market app id

Return type:

int

algofi.utils.get_new_account()

Returns a tuple with a new key, address and passphrase.

Returns:

tuple of key, address, passphrase for a new algorand account

Return type:

tuple

algofi.utils.get_ordered_symbols(chain, max=False, max_atomic_opt_in=False)

Returns list of supported symbols for the specified chain. Pulled from hardcoded values in contracts.json.

Parameters:
  • chain (string e.g. 'testnet') – network to query data for

  • max (boolean) – max assets?

Returns:

list of supported symbols for algofi’s protocol on chain

Return type:

list

algofi.utils.get_program(definition, variables=None)

Return a byte array to be used in LogicSig.

algofi.utils.get_staking_contracts(chain)

Returns list of supported staking contracts for the specified chain. Pulled from hardcoded values in contracts.json.

Parameters:

chain (string e.g. 'testnet') – network to query data for

Returns:

list of supported staking contracts

Return type:

list

algofi.utils.get_state_bytes(state, key)
algofi.utils.get_state_int(state, key)
algofi.utils.int_to_bytes(num)
algofi.utils.prepare_payment_transaction(sender, suggested_params, receiver, amount, rekey_to=None)

Returns a TransactionGroup object representing a payment group transaction for a given sender, receiver, amount and ability to rekey.

Parameters:
  • sender (string) – account address for the sender

  • suggested_params (algosdk.transaction.SuggestedParams object) – suggested transaction params

  • receiver (string) – account address for the receiver

  • amount (string) – amount of algos to send

  • amount – address to rekey sender to after payment

Returns:

TransactionGroup object representing a payment group transaction

Return type:

TransactionGroup

algofi.utils.read_global_state(indexer_client, app_id, block=None)

Returns dict of global state for application with the given app_id

Parameters:
  • indexer_client (IndexerClient) – indexer client

  • app_id (int) – id of the application

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

Returns:

dict of global state for application with id app_id

Return type:

dict

algofi.utils.read_local_state(indexer_client, address, app_id, block=None)

Returns dict of local state for address for application with id app_id

Parameters:
  • indexer_client (IndexerClient) – indexer client

  • address (string) – address of account for which to get state

  • app_id (int) – id of the application

  • block (int, optional) – block at which to get the historical local state

Returns:

dict of local state of address for application with id app_id

Return type:

dict

algofi.utils.sign_and_submit_transactions(client, transactions, signed_transactions, sender, sender_sk)
algofi.utils.wait_for_confirmation(client, txid)

Waits for a transaction with id txid to complete. Returns dict with transaction information after completion.

Parameters:
  • client (AlgodClient) – algod client

  • txid (string) – id of the sent transaction

Returns:

dict of transaction information

Return type:

dict