market

class algofipy.lending.v2.market.Market(lending_client, market_config)

Bases: object

b_asset_to_asset_amount(amount)

Converts b asset amount to underlying amount

Parameters:

amount (int) – b asset amount

Returns:

underlying asset amount

Return type:

int

borrow_shares_to_asset_amount(amount)

Converts borrow shares to underlying borrowed amount.

Parameters:

amount (int) – borrow shares amount

Returns:

underlying borrowed amount

Return type:

int

get_add_b_asset_collateral_txns(user, b_asset_amount, params=None)

Returns a TransactionGroup object representing an add collateral group transaction against the algofi protocol. Sender adds bank asset amount to collateral by sending them to the account address of the market application that generates the bank assets.

Parameters:
  • user (LendingUser) – account for the sender

  • b_asset_amount (int) – amount of bank asset to add to collateral

  • params – algod params

Returns:

TransactionGroup object representing an add collateral group transaction of size 2

Return type:

TransactionGroup

get_add_underlying_collateral_txns(user, underlying_amount, params=None)

Returns a TransactionGroup object representing an add collateral group transaction against the algofi protocol. Sender adds underlying asset amount to collateral by sending it to the account address of the market application that updates user active collateral.

Parameters:
  • user (LendingUser) – account for the sender

  • underlying_amount (int) – amount of underlying asset to add to collateral

  • params – algod params

Returns:

TransactionGroup object representing an add collateral group transaction of size 2

Return type:

TransactionGroup

get_aprs(total_supplied, total_borrowed)

Return the supply and borrow APR for the market.

Parameters:
  • total_supplied (int) – total amount underlying assets supplied

  • total_borrowed (int) – total amount underlying assets borrowed

Returns:

(supply_apr, borrow_apr)

Return type:

(float, float)

get_b_asset_opt_in_txn(user, params=None)

Returns a AssetTransferTxn object representing a transfer of zero units of the b asset.

Parameters:
  • user (LendingUser) – account for the sender

  • params – algod params

Returns:

AssetTransferTxn of underlying asset with 0 amount from user to self

Return type:

AssetTransferTxn

get_b_asset_to_underlying_exchange_rate(block=None)

Returns b_asset_to_underlying_exchange_rate for this market

Parameters:

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

Returns:

b_asset_to_underlying_exchange_rate

Return type:

int

get_borrow_txns(user, underlying_amount, params=None)

Returns a TransactionGroup object representing a borrow group transaction against the algofi protocol. Sender borrows underlying asset against their collateral in the protocol.

Parameters:
  • user (LendingUser) – account for the sender

  • underlying_amount (int) – amount to borrow

  • params – algod params

Returns:

TransactionGroup object representing a borrow group transaction of size (preamble_length + 1)

Return type:

TransactionGroup

get_burn_txns(user, b_asset_amount, params=None)

Returns a TransactionGroup object representing a burn group transaction against the algofi protocol. Sender reclaims underlying collateral asset by burning bank asset.

Parameters:
  • user (LendingUser) – account for the sender

  • b_asset_amount (int) – amount of underlying asset to remove

  • params – algod params

Returns:

TransactionGroup object representing a burn group transaction of size 2

Return type:

TransactionGroup

get_claim_rewards_txns(user, program_index, params=None)

Returns a TransactionGroup object representing a claim rewards group transaction against the algofi protocol. Sender claims accrued rewards from a specified rewards program.

Parameters:
  • user (LendingUser) – account for the sender

  • program_index (int) – specific program for which the rewards are being claimed

  • params – algod params

Returns:

TransactionGroup object representing a claim rewards group transaction of size 1

Return type:

TransactionGroup

get_liquidate_txns(user, target_user, repay_amount, seize_collateral_market, params=None)

Returns a TransactionGroup object representing a liquidate group transaction against the algofi protocol. Sender repays borrowed underlying asset + interest on behalf of the liquidatee and seizes their collateral in a specified market.

Parameters:
  • user (LendingUser) – account for the sender

  • target_user (LendingUser) – account for the liquidatee

  • repay_amount (int) – amount to repay

  • params – algod params

Param:

seize_collateral_market: market to seize collateral in

Returns:

TransactionGroup object representing a liquidate group transaction of size (preamble_length + 3)

Return type:

TransactionGroup

get_mint_txns(user, underlying_amount, params=None)

Returns a TransactionGroup object representing a mint bank asset group transaction against the algofi protocol. Sender mints bank asset by sending underlying asset to the account address of the market application which sends back the bank asset.

Parameters:
  • user (LendingUser) – account for the sender

  • underlying_amount (int) – amount of underlying asset to use in minting

  • params – algod params

Returns:

TransactionGroup object representing a mint group transaction of size 2

Return type:

TransactionGroup

get_remove_b_asset_collateral_txns(user, b_asset_amount, params=None)

Returns a TransactionGroup object representing a remove collateral group transaction against the algofi protocol. Sender reclaims collateral bank asset by reducing their active collateral.

Parameters:
  • user (LendingUser) – account for the sender

  • b_asset_amount (int) – amount of underlying asset to remove

  • params – algod params

Returns:

TransactionGroup object representing a remove collateral group transaction

Return type:

TransactionGroup

get_remove_underlying_collateral_txns(user, underlying_amount, params=None)

Returns a TransactionGroup object representing a remove collateral group transaction against the algofi protocol. Sender reclaims underlying collateral asset by reducing their active collateral.

Parameters:
  • user (LendingUser) – account for the sender

  • underlying_amount (int) – amount of underlying asset to remove

  • params – algod params

Returns:

TransactionGroup object representing a remove collateral group transaction of size (preamble_length + 1)

Return type:

TransactionGroup

get_repay_borrow_txns(user, underlying_amount, params=None)

Returns a TransactionGroup object representing a repay borrow group transaction against the algofi protocol. Sender repays borrowed underlying asset + interest to the protocol.

Parameters:
  • user (LendingUser) – account for the sender

  • underlying_amount (int) – amount to repay

  • params – algod params

Returns:

TransactionGroup object representing a repay group transaction of size 2

Return type:

TransactionGroup

get_underlying_asset_opt_in_txn(user, params=None)

Returns a AssetTransferTxn object representing a transfer of zero units of the market underlying asset.

Parameters:
  • user (LendingUser) – account for the sender

  • params – algod params

Returns:

AssetTransferTxn of underlying asset with 0 amount from user to self

Return type:

AssetTransferTxn

get_underlying_supplied()

Returns the total amount of underlying asset that has been supplied to the market, including the amount that has been borrowed

Returns:

Supplied amount in base unit terms

Return type:

int

load_state(block=None)

Loads market state from the blockchain

Parameters:

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

Return type:

None

local_min_balance = 471000
underlying_to_b_asset(amount)

Convert underlying asset amount to b asset amount.

Parameters:

amount (int) – underlying asset amount

Returns:

b asset amount

Return type:

int

underlying_to_usd(amount)

Converts underlying to usd

Parameters:

amount (int) – underlying asset amount

Returns:

dollarized amount

Return type:

int

class algofipy.lending.v2.market.RewardsProgramState(state, program_index)

Bases: object

rewards_asset_id_offset = 16
rewards_claimed_offset = 32
rewards_issued_offset = 24
rewards_per_second_offset = 8
rewards_program_number_offset = 0
rewards_state_length = 40