folks_lending_pool

This module allows for composing Pact swaps and adding/removing liquidity with Folks Finance lending pools, resulting in a higher APR for liquidity providers that accommodates both, the trading APR and the lending APR.

The user is not interacting with Folks Finance pools or Pact pools directly. Instead, the user is calling a global adapter contract that makes inner transactions to the other applications.

The Pact pool is between two fAssets e.g. fALGO and fUSDC but the user doesn’t have to be opted into those fAssets. The user interacts only with ALGO and USDC. Converting between the original assets and fAssets is hidden in the adapter contract.

To add liquidity:
  • The user deposits ALGO and USDC in the adapter contract.

  • The user calls “pre_add_liquidity” method on the adapter.

  • The adapter converts ALGO to fALGO and USDC to fUSDC in corresponding Folks Finance pools.

  • The user calls “add_liquidity” method on the adapter.

  • The adapter deposits fALGO and fUSDC in Pact pool and receives liquidity tokens in return.

  • The adapter transfers the liquidity tokens to the user.

To remove liquidity:
  • The user deposits liquidity tokens in the adapter contract.

  • The user calls “remove_liquidity” method on the adapter.

  • The adapter removes liquidity from the Pact pool and receives fALGO and fUSDC in return.

  • The user calls “post_remove_liquidity” method on the adapter.

  • The adapter converts fALGO to ALGO and fUSDC to USDC in corresponding Folks Finance pools.

  • The adapter transfers ALGO and USDC tokens to the user.

For swap:
  • The user deposits one of the assets in the adapter e.g. USDC.

  • The user calls “swap” method on the adapter.

  • The adapter converts USDC to fUSDC in a corresponding Folks Finance pool.

  • The adapter swaps fUSDC to fALGO in a Pact pool.

  • The adapter converts fALGO to ALGO in a corresponding Folks Finance pool.

  • The adapter transfers ALGO to the user.

class pactsdk.folks_lending_pool.FolksLendingPool(algod, app_id, manager_app_id, deposit_interest_rate, deposit_interest_index, updated_at, original_asset, f_asset, last_timestamp_override=None)

Bases: object

algod: algosdk.v2client.algod.AlgodClient
app_id: int
manager_app_id: int
deposit_interest_rate: int
deposit_interest_index: int
updated_at: datetime.datetime
original_asset: pactsdk.asset.Asset
f_asset: pactsdk.asset.Asset
escrow_address: str
last_timestamp_override: Optional[int] = None

The conversion calculations are dependant of precise timestamps. The Folks contract uses the last block timestamp for this value. The SDK, by default, uses current system time. This field allows to override the default behavior. This is needed in unit tests and normal users should leave this field as None.

convert_deposit(amount)

Calculates the amount fAsset received when depositing original asset.

Return type

int

convert_withdraw(amount, ceil=False)

Calculates the amount original asset received when depositing fAsset.

Return type

int

get_last_timestamp()
Return type

int

pactsdk.folks_lending_pool.fetch_folks_lending_pool(algod, app_id)

Fetches Folks lending pool application info from the algod, parses the global state and builds FolksLendingPool object.

Return type

FolksLendingPool

class pactsdk.folks_lending_pool.LendingLiquidityAddition(lending_pool_adapter, primary_asset_amount, secondary_asset_amount, slippage_pct)

Bases: object

A wrapper around LiquidityAddition object that converts assets to fAssets before creating LiquidityAddition object.

lending_pool_adapter: pactsdk.folks_lending_pool.FolksLendingPoolAdapter
primary_asset_amount: int

Amount of original primary asset deposited.

secondary_asset_amount: int

Amount of original secondary asset deposited.

slippage_pct: float

The maximum amount of slippage allowed in performing the add liquidity.

liquidity_addition: pactsdk.add_liquidity.LiquidityAddition

Information about actual add liquidity operation on the Pact pool.

class pactsdk.folks_lending_pool.LendingSwap(f_swap, asset_deposited, asset_received, amount_deposited, amount_received, minimum_amount_received, tx_fee)

Bases: object

A wrapper around Swap object that adds some lending specific information.

f_swap: pactsdk.swap.Swap

Information about the actual swap on the Pact pool.

asset_deposited: pactsdk.asset.Asset
asset_received: pactsdk.asset.Asset
amount_deposited: int

Amount of original asset deposited by the user.

amount_received: int

Amount of original asset received by the user.

minimum_amount_received: int

Minimal amount of original asset received by the user after the slippage.

tx_fee: int
class pactsdk.folks_lending_pool.FolksLendingPoolAdapter(algod, app_id, pact_pool, primary_lending_pool, secondary_lending_pool)

Bases: object

The representation of the adapter contract.

It allows adding/removing liquidity and making swaps using a combination Pact pool and Folks Finance lending pools.

This class tries to mimic the interface of a pactsdk.pool.Pool for making the above operations.

algod: algosdk.v2client.algod.AlgodClient
app_id: int
pact_pool: pactsdk.pool.Pool
primary_lending_pool: pactsdk.folks_lending_pool.FolksLendingPool
secondary_lending_pool: pactsdk.folks_lending_pool.FolksLendingPool
escrow_address: str
original_asset_to_f_asset(original_asset)
Return type

Asset

f_asset_to_original_asset(f_asset)
Return type

Asset

prepare_add_liquidity(primary_asset_amount, secondary_asset_amount, slippage_pct)
Return type

LendingLiquidityAddition

prepare_add_liquidity_tx_group(address, liquidity_addition)
Return type

TransactionGroup

build_add_liquidity_txs(address, liquidity_addition, suggested_params)
Return type

list[Transaction]

prepare_remove_liquidity_tx_group(address, amount)
Return type

TransactionGroup

build_remove_liquidity_txs(address, amount, suggested_params)
Return type

list[Transaction]

prepare_swap(asset, amount, slippage_pct, swap_for_exact=False)
Return type

LendingSwap

prepare_swap_tx_group(swap, address)
Return type

TransactionGroup

build_swap_txs(swap, address, suggested_params)
Return type

list[Transaction]

prepare_opt_in_to_asset_tx_group(address, asset_ids)
Return type

TransactionGroup

build_opt_in_to_asset_tx_group(address, asset_ids, suggested_params)