v1

client

class algofi.v1.client.AlgofiMainnetClient(algod_client=None, indexer_client=None, user_address=None)

Bases: Client

class algofi.v1.client.AlgofiTestnetClient(algod_client=None, indexer_client=None, user_address=None)

Bases: Client

class algofi.v1.client.Client(algod_client: AlgodClient, indexer_client: IndexerClient, historical_indexer_client: IndexerClient, user_address, chain)

Bases: object

get_active_asset_ids()

Returns the active asset ids.

Returns:

list of active asset ids

Return type:

list

get_active_assets()

Returns a dictionary of the asset objects for each active market

Returns:

dictionary of asset objects

get_active_bank_asset_ids()

Returns the active bank asset ids.

Returns:

list of active bank asset ids

Return type:

list

get_active_market_addresses()

Returns the list of the active market addresses

Returns:

list of active market_addresses

Return type:

list

get_active_market_app_ids()

Returns the list of the active market app ids

Returns:

list of active market_app_ids

Return type:

list

get_active_markets()

Returns dictionary of active markets by symbol

Returns:

markets dictionary

Return type:

dict

get_active_oracle_app_ids()

Returns the list of active oracle app ids

Returns:

list of active oracle app ids

Return type:

list

get_active_ordered_symbols()

Returns the list of symbols of the active assets

Returns:

list of symbols for active assets

Return type:

list

get_asset(symbol)

Returns the asset object for the requested symbol.

Parameters:

symbol (string) – symbol of the asset

Returns:

Asset object

Return type:

Asset

get_default_params()

Initializes the transactions parameters for the client.

get_manager()

Returns the manager object

Returns:

manager

Return type:

Manager

get_market(symbol)

Returns the market object for the given symbol

Parameters:

symbol (string) – market symbol

Returns:

market

Return type:

Market

get_max_atomic_opt_in_market_app_ids()

Returns the max opt in market application ids.

Returns:

list of max opt in market application ids

Return type:

list

get_prices(update=True)
Returns a dictionary of dollarized float prices of the active assets pulled from their oracles.

If update is False returns the latest updated dollarized float prices

Parameters:

update (bool, optional) – fetch updated prices if True

Returns:

dictionary of int prices

Return type:

dict

get_raw_prices(update=True)
Returns a dictionary of raw oracle prices of the active assets pulled from their oracles.

If update is False returns the latest updated raw prices

Parameters:

update (bool, optional) – fetch updated prices if True

Returns:

dictionary of int prices

Return type:

dict

get_staking_contract(name)

Returns the manager object

Parameters:

name (string) – staking contract name

Returns:

staking contract

Return type:

StakingContract

get_staking_contracts()

Returns the manager object

Returns:

staking contracts dictionary

Return type:

dict

get_storage_accounts(staking_contract_name=None, verbose=False)

Returns a list of storage accounts for the given manager app id

Returns:

list of storage accounts

Return type:

list

get_storage_state(storage_address=None, block=None, include_manager=True)

Returns a dictionary with the lending market state for a given storage address

Parameters:

storage_address (string) – address to get info for. If None will use address supplied when creating client

Returns:

state

Return type:

dict

get_user_balance(asset_id=1, 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_id (int, optional) – id of the asset, default to None (algo)

Returns:

amount of asset

Return type:

int

get_user_balances(address=None, block=None)

Returns a dictionary of user balances by asset id

Parameters:

address (string) – address to get info for

Returns:

amount of asset

Return type:

int

get_user_info(address=None, block=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_user_staking_contract_state(staking_contract_name, address=None)

Returns a dictionary with the staking contract state for the named staking contract and selected address

Parameters:
  • staking_contract_name (string) – name of staking contract to query

  • address (string) – address to get info for. If None will use address supplied when creating client

Returns:

state

Return type:

dict

get_user_state(address=None, block=None)

Returns a dictionary with the lending market state for a given address (must be opted in)

Parameters:

address (string) – address to get info for. If None will use address supplied when creating client

Returns:

state

Return type:

dict

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_id, 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_id (int) – id of the asset

Returns:

boolean if user is opted into an asset

Return type:

boolean

prepare_add_collateral_transactions(symbol, amount, address=None)

Returns an add_collateral transaction group

Parameters:
  • symbol (string) – symbol to add collateral with

  • amount (int) – amount of collateral to add

  • address (string) – defaults to client user address. address to send add_collateral transaction group from

Returns:

add_collateral transaction group

Return type:

TransactionGroup

prepare_borrow_transactions(symbol, amount, address=None)

Returns a borrow transaction group

Parameters:
  • symbol (string) – symbol to borrow

  • amount (int) – amount to borrow

  • address (string) – defaults to client user address. address to send borrow transaction group from

Returns:

borrow transaction group

Return type:

TransactionGroup

prepare_burn_transactions(symbol, amount, address=None)

Returns a burn transaction group

Parameters:
  • symbol (string) – symbol to burn

  • amount (int) – amount of bAsset to burn

  • address (string) – defaults to client user address. address to send burn transaction group from

Returns:

burn transaction group

Return type:

TransactionGroup

prepare_claim_rewards_transactions(address=None)

Returns a claim_rewards transaction group

Parameters:

address (string) – defaults to client user address. address to send claim_rewards from

Returns:

claim_rewards transaction group

Return type:

TransactionGroup

prepare_claim_staking_rewards_transactions(staking_contract_name, address=None)

Returns a staking contract claim rewards transaction group

Parameters:
  • staking_contract_name (string) – name of staking contract to unstake on

  • address (string) – defaults to client user address. address to send claim rewards transaction group from

Returns:

unstake transaction group

Return type:

TransactionGroup

prepare_liquidate_transactions(target_storage_address, borrow_symbol, amount, collateral_symbol, address=None)

Returns a liquidate transaction group NOTE: seizing vALGO collateral returns ALGOs not bAssets. all other markets return bAssets.

Parameters:
  • target_storage_address (string) – storage address to liquidate

  • borrow_symbol (string) – symbol to repay

  • amount (int) – amount to repay

  • collateral_symbol (string) – symbol to sieze collateral from

  • address (string) – defaults to client user address. address to send liquidate transaction group from

Returns:

liquidate transaction group

Return type:

TransactionGroup

prepare_mint_to_collateral_transactions(symbol, amount, address=None)

Returns a mint_to_collateral transaction group

Parameters:
  • symbol (string) – symbol to mint to collateral

  • amount (int) – amount to mint to collateral

  • address (string) – defaults to client user address. address to send mint_to_collateral transaction group from

Returns:

mint_to_collateral transaction group

Return type:

TransactionGroup

prepare_mint_transactions(symbol, amount, address=None)

Returns a mint transaction group

Parameters:
  • symbol (string) – symbol to mint

  • amount (int) – amount of mint

  • address (string) – defaults to client user address. address to send mint transaction group from

Returns:

mint transaction group

Return type:

TransactionGroup

prepare_optin_transactions(storage_address, address=None)

Returns an opt in transaction group

Parameters:
  • storage_address – storage address to fund and rekey

  • address (string) – defaults to client user address. address to send add_collateral transaction group from

Returns:

opt in transaction group

Return type:

TransactionGroup

prepare_remove_algos_from_vault_transactions(amount, address=None)

Returns a staking contract claim rewards transaction group

Parameters:
  • amount (int) – amount of algos in base units

  • address (string) – defaults to client user address. address to send remove algos from vault group transaction from.

Returns:

remove algos from vault transaction group

Return type:

TransactionGroup

prepare_remove_collateral_transactions(symbol, amount, address=None)

Returns a remove_collateral transaction group

Parameters:
  • symbol (string) – symbol to remove collateral from

  • amount (int) – amount of collateral to remove

  • address (string) – defaults to client user address. address to send remove_collateral transaction group from

Returns:

remove_collateral transaction group

Return type:

TransactionGroup

prepare_remove_collateral_underlying_transactions(symbol, amount, address=None)

Returns a remove_collateral_underlying transaction group

Parameters:
  • symbol (string) – symbol to remove collateral from

  • amount (int) – amount of collateral to remove

  • address (string) – defaults to client user address. address to send remove_collateral_underlying transaction group from

Returns:

remove_collateral_underlying transaction group

Return type:

TransactionGroup

prepare_repay_borrow_transactions(symbol, amount, address=None)

Returns a repay_borrow transaction group

Parameters:
  • symbol (string) – symbol to repay

  • amount (int) – amount of repay

  • address (string) – defaults to client user address. address to send repay_borrow transaction group from

Returns:

repay_borrow transaction group

Return type:

TransactionGroup

prepare_send_governance_commitment_transactions(governance_address, commitment_amount, address=None, beneficiary=None, check_vault_balance=True)

Returns a send governance commitment group transaction. A zero-value PaymentTxn with formatted notes field. Format for notes field can be found within Algorand Foundation Governance Spec at <https://github.com/algorandfoundation/governance/blob/main/af-gov1-spec.md>

Parameters:
  • governance_address (string) – governance address to send commitment txn to. Get governance address from <https://governance.algorand.foundation/api/periods> within the relevant period “sign_up_address”

  • commitment_amount (int) – amount of ALGOs (in microalgos) to commit to governance

  • address (string, optional) – defaults to client user address. address to send send governance commitment transaction group from. This is the primary account address for Algofi, not the vault account address from which the commitment inner transaction will originate.

  • beneficiary (string, optional) – specify a beneficiary of the governance rewards. governance rewards will be sent from the Algorand Foundation to this address at the end of governance if the vault account is eligible for rewards.

  • check_vault_balance (boolean, default True) – checks the ALGO balance of the Vault. raises exception if commitment amount > the ALGO balance of the Vault account.

Returns:

send governance commitment transaction group

Return type:

TransactionGroup

prepare_send_governance_vote_transactions(governance_address, note, address=None)

Returns a send governance vote group transaction. A zero-value PaymentTxn with formatted notes field. Format for voting notes field can be found within Algorand Foundation Governance Spec at <https://github.com/algorandfoundation/governance/blob/main/af-gov1-spec.md>

Parameters:
  • governance_address (string) – governance address to send vote txn to. Get governance address from <https://governance.algorand.foundation/api/periods> within the relevant period “sign_up_address”.

  • note (bytes) – notes field for voting in governance. see spec for voting notes field at <https://github.com/algorandfoundation/governance/blob/main/af-gov1-spec.md>.

  • address (string, optional) – defaults to client user address. address to send send governance vote transaction group from. this is the primary account address for Algofi, not the vault account address from which the vote inner transaction will originate.

Returns:

send governance vote transaction group

Return type:

TransactionGroup

prepare_send_keyreg_offline_transactions(address=None)

Returns a send keyreg offline group transaction

Parameters:

address (string) – defaults to client user address. address to send send keyreg offline group transaction from.

Returns:

send keyreg offline group transaction

Return type:

TransactionGroup

prepare_send_keyreg_online_transactions(vote_pk, selection_pk, state_proof_pk, vote_first, vote_last, vote_key_dilution, address=None)

Returns a send keyreg online group transaction

Parameters:
  • vote_pk (bytes) – vote key for consensus (generated on participation node)

  • selection_pk (bytes) – selection key for consensus (generated on participation node)

  • state_proof_pk (bytes) – state proof key for consensus (generated on participation node)

  • vote_first (int) – first round at which account votes

  • vote_last (int) – last round at which account votes

  • vote_key_dilution (int) – key dilution

  • address (string) – defaults to client user address. address to send send keyreg online group transaction from.

Returns:

send keyreg group transaction

Return type:

TransactionGroup

prepare_stake_transactions(staking_contract_name, amount, address=None)

Returns a staking contract stake transaction group

Parameters:
  • staking_contract_name (string) – name of staking contract to stake on

  • amount (int) – amount of stake

  • address (string) – defaults to client user address. address to send stake transaction group from

Returns:

stake transaction group

Return type:

TransactionGroup

prepare_staking_contract_optin_transactions(staking_contract_name, storage_address, address=None)

Returns a staking contract optin transaction group

Parameters:
  • staking_contract_name (string) – name of staking contract to opt in to

  • storage_address – storage address to fund and rekey

  • address (string) – defaults to client user address. address to create optin transaction group for

Returns:

staking contract opt in transaction group

Return type:

TransactionGroup

prepare_supply_algos_to_vault_transactions(amount, address=None)

Returns supply algos to vault group transaction

Parameters:
  • amount (int) – amount of algos in base units

  • address (string) – defaults to client user address. address to send supply algos to vault group transaction from.

Returns:

supply algos to vault transaction group

Return type:

TransactionGroup

prepare_sync_vault_transactions(address=None)

Returns a sync vault transactions group

Parameters:

address (string) – defaults to client user address. address to send sync vault group transaction from.

Returns:

sync vault group transaction

Return type:

TransactionGroup

prepare_unstake_transactions(staking_contract_name, amount, address=None)

Returns a staking contract unstake transaction group

Parameters:
  • staking_contract_name (string) – name of staking contract to unstake on

  • amount (int) – amount of unstake

  • address (string) – defaults to client user address. address to send unstake transaction group from

Returns:

unstake transaction group

Return type:

TransactionGroup

submit(transaction_group, wait=False)

Submits group transaction to network + waits for completion if specified. Fails if transaction fails or wait operation times out.

Parameters:
  • transaction_group (list) – a list of signed transactions

  • wait (boolean, optional) – boolean whether to wait for transaction to be completed, defaults to False

Returns:

dict of the transaction id {“txid”: txid}

Return type:

dict

manager

class algofi.v1.manager.Manager(indexer_client: IndexerClient, historical_indexer_client: IndexerClient, manager_app_id)

Bases: object

get_manager_address()

Return manager address

Returns:

manager address

Return type:

string

get_manager_app_id()

Return manager app id

Returns:

manager app id

Return type:

int

get_rewards_program()

Return a list of current rewards program

Returns:

rewards program

Return type:

RewardsProgram

get_storage_address(address, block=None)

Returns the storage address for the client user at a given block

Parameters:
  • address (string) – address to get info for

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

Returns:

storage account address for user

Return type:

string

get_storage_state(storage_address, block=None)

Returns the market local state for storage address.

Parameters:
  • storage_address (string) – storage_address to get info for

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

Returns:

market local state for address

Return type:

dict

get_storage_unrealized_rewards(storage_address, markets)

Returns projected unrealized rewards for a storage address

Parameters:
  • storage_address (string) – account storage address of user to get unrealized rewards for

  • markets (list) – list of markets to get unrealized rewards for

Returns:

tuple of primary and secondary unrealized rewards

Return type:

(int, int)

get_supported_market_count(block=None)

Return the supported market count

Parameters:

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

Returns:

supported market count

Return type:

int

get_user_address(storage_address)

Returns the storage address for the client user

Parameters:

address (string) – address to get info for

Returns:

storage account address for user

Return type:

string

get_user_state(address, block=None)

Returns the market local state for address.

Parameters:
  • address (string) – address to get info for

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

Returns:

market local state for address

Return type:

dict

get_user_unrealized_rewards(address, markets)

Returns projected unrealized rewards for a user address

Parameters:
  • address (string) – account address of user to get unrealized rewards for

  • markets (list) – list of markets to get unrealized rewards for

Returns:

tuple of primary and secondary unrealized rewards

Return type:

(int, int)

update_global_state(block=None)

Method to fetch most recent manager global state.

Parameters:

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

market

class algofi.v1.market.Market(indexer_client: IndexerClient, historical_indexer_client: IndexerClient, market_app_id)

Bases: object

get_active_collateral(block=None)

Returns active_collateral for this market

Parameters:

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

Returns:

active_collateral

Return type:

int

get_asset()

Returns asset object for this market

Returns:

asset

Return type:

Asset

get_bank_circulation(block=None)

Returns bank_circulation for this market

Parameters:

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

Returns:

bank_circulation

Return type:

int

get_bank_to_underlying_exchange(block=None)

Returns bank_to_underlying_exchange for this market

Parameters:

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

Returns:

bank_to_underlying_exchange

Return type:

int

get_collateral_factor(block=None)

Returns collateral_factor for this market

Parameters:

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

Returns:

collateral_factor

Return type:

int

get_liquidation_incentive(block=None)

Returns liquidation_incentive for this market

Parameters:

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

Returns:

liquidation_incentive

Return type:

int

get_market_address()

Returns the address for this market

Returns:

market address

Return type:

string

get_market_app_id()

Returns the app id for this market

Returns:

market app id

Return type:

int

get_market_counter()

Returns the market counter for this market

Returns:

market counter

Return type:

int

get_outstanding_borrow_shares(block=None)

Returns outstanding_borrow_shares for this market

Parameters:

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

Returns:

outstanding_borrow_shares

Return type:

int

get_storage_state(storage_address, block=None)

Returns the market local state for address.

Parameters:
  • storage_address (string) – storage_address to get info for

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

Returns:

market local state for address

Return type:

dict

get_total_borrow_interest_rate(block=None)

Returns total_borrow_interest_rate for this market

Parameters:

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

Returns:

total_borrow_interest_rate

Return type:

int

get_underlying_borrowed(block=None)

Returns underlying_borrowed for this market

Parameters:

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

Returns:

underlying_borrowed

Return type:

int

get_underlying_cash(block=None)

Returns underlying_cash for this market

Parameters:

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

Returns:

underlying_cash

Return type:

int

get_underlying_reserves(block=None)

Returns underlying_reserves for this market

Parameters:

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

Returns:

underlying_reserves

Return type:

int

get_underlying_supplied(block=None)

Returns underlying supplied = underlying_cash + underlying_borrowed - underlying_reserves for this market. The mainnet STBL market was seeded with 1tn STBL, so this must be subtracted from the calculation.

Parameters:

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

Returns:

underlying supplied

Return type:

int

update_global_state(block=None)

Method to fetch most recent market global state.

Parameters:

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

staking_contract

class algofi.v1.staking_contract.StakingContract(indexer_client: IndexerClient, historical_indexer_client: IndexerClient, staking_contract_info)

Bases: object

get_asset()

Returns asset object for this market

Returns:

asset

Return type:

Asset

get_manager()

Return staking contract manager

Returns:

manager

Return type:

Manager

get_manager_address()

Return manager address

Returns:

manager address

Return type:

string

get_manager_app_id()

Return manager app id

Returns:

manager app id

Return type:

int

get_market()

Return staking contract market

Returns:

market

Return type:

Market

get_market_address()

Returns the market address

Returns:

market address

Return type:

string

get_market_app_id()

Returns the market app id

Returns:

market app id

Return type:

int

get_oracle_app_id()

Returns the oracle app id

Returns:

oracle app id

Return type:

int

get_rewards_program()

Return a list of current rewards program

Returns:

rewards program

Return type:

RewardsProgram

get_staked()

Return staked amount

Returns:

staked

Return type:

int

get_storage_address(address)

Returns the staking contract storage address for the given address or None if it does not exist.

Parameters:

address (string) – address to get info for

Returns:

storage account address for user

Return type:

string

get_storage_state(storage_address)

Returns the staking contract local state for storage_address.

Parameters:

storage_address (string) – storage address to get info for

Returns:

staking contract local state for address

Return type:

dict

get_user_state(address)

Returns the staking contract local state for address.

Parameters:

address (string) – address to get info for

Returns:

staking contract local state for address

Return type:

dict

update_global_state(block=None)

Method to fetch most recent staking contract global state

Parameters:

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

asset

class algofi.v1.asset.Asset(indexer_client: IndexerClient, historical_indexer_client: IndexerClient, underlying_asset_id, bank_asset_id, oracle_app_id=None, oracle_price_field=None, oracle_price_scale_factor=None)

Bases: object

get_bank_asset_id()

Returns bank asset id

Returns:

bank asset id

Return type:

int

get_bank_asset_info()

Returns bank asset info

Returns:

bank asset info

Return type:

dict

get_decimal_amount(amount)

Returns an decimal representation of asset amount devided by asset’s decimals :param amount: amount of asset :type amount: float :return: int amount of asset divided by decimals :rtype: int

get_oracle_app_id()

Returns oracle app id

Returns:

oracle app id

Return type:

int

get_oracle_price_field()

Returns oracle price field

Returns:

oracle price field

Return type:

string

get_oracle_price_scale_factor()

Returns oracle price scale factor

Returns:

oracle price scale factor

Return type:

int

get_price(block=None, update=True)
Returns the current oracle price if update.

Else returns the latest updated price

Parameters:
  • block (int, optional) – block at which to get historical data

  • update (bool, optional) – fetch updated prices if True

Returns:

oracle price

Return type:

int

get_raw_price(block=None, update=True)
Returns the current raw oracle price if update.

Else returns the latest updated raw price

Parameters:
  • block (int, optional) – block at which to get historical data

  • update (bool, optional) – fetch updated prices if True

Returns:

oracle price

Return type:

int

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

get_underlying_asset_id()

Returns underying asset id

Returns:

underlying asset id

Return type:

int

get_underlying_asset_info()

Returns underying asset info

Returns:

underlying asset info

Return type:

dict

get_underlying_decimals()

Returns decimals of asset

Returns:

decimals

Return type:

int

to_usd(amount, block=None, update=True)

Return the usd value of the underlying amount (base units)

Parameters:
  • amount (int) – integer amount of base underlying units

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

Returns:

usd value

Return type:

float

rewards_program

class algofi.v1.rewards_program.RewardsProgram(indexer_client: IndexerClient, historical_indexer_client: IndexerClient, manager_state)

Bases: object

get_latest_rewards_time()

Return latest rewards time

Returns:

latest rewards time

Return type:

int

get_rewards_amount()

Return rewards amount

Returns:

rewards amount

Return type:

int

get_rewards_asset_id()

Return rewards asset id

Returns:

rewards asset id

Return type:

int

get_rewards_asset_ids()

Return a list of current rewards assets

Returns:

rewards asset list

Return type:

list

get_rewards_per_second()

Return rewards per second

Returns:

rewards per second

Return type:

int

get_rewards_program_number()

Return rewards program number

Returns:

rewards program number

Return type:

int

get_rewards_secondary_asset_id()

Return rewards secondary asset id

Returns:

rewards secondary asset id

Return type:

int

get_rewards_secondary_ratio()

Return rewards secondary ratio

Returns:

rewards secondary ratio

Return type:

int

get_storage_unrealized_rewards(storage_address, manager, markets)

Return the projected claimable rewards for a given storage_address. Ordering of markets must be as seen in contracts.json.

Parameters:
  • storage_address (string) –

  • manager (Manager) – a Manager object representing the manger application

  • markets (list) – list of markets to get unrealized rewards for

Returns:

tuple of primary and secondary unrealized rewards

Return type:

(int, int)