client

This module exposes PactClient class which is an entry points for interacting with the SDK.

Typical usage example:

import algosdk
from algosdk.v2client.algod import AlgodClient

import pactsdk

algod = AlgodClient("<token>", "<url>")
pact = pactsdk.PactClient(algod)

algo = pact.fetch_asset(0)
other_coin = pact.fetch_asset(12345678)

pools = pact.fetch_pools_by_assets(algo, other_coin)
class pactsdk.client.PactClient(algod, network='mainnet', **kwargs)

Bases: object

An entry point for interacting with the SDK.

Exposes convenience methods for fetching assets and pools.

__init__(algod, network='mainnet', **kwargs)

Constructor for the PactClient class.

Parameters
  • algod (AlgodClient) – Algorand client to work with.

  • network (Literal[‘mainnet’, ‘testnet’, ‘dev’]) – The Algorand network to use the client with. The configuration values depend on the chosen network.

  • kwargs – Use it to overwrite configuration parameters.

algod: algosdk.v2client.algod.AlgodClient

Algorand client to work with.

config: pactsdk.config.Config

Client configuration with global contracts ids etc.

farming: pactsdk.farming.farming_client.PactFarmingClient
fetch_asset(asset_index)

A convenient method for fetching ASAs (Algorand Standard Asset).

This will return an Asset class with the relevant data about the asset if the asset index is valid. Note that an index of zero (0) will return the Algo asset.

Parameters

asset_index (int) – The id of the asset.

Raises

algosdk.error.AlgodHTTPError – If the asset does not exist.

Return type

Asset

Returns

Asset instance for the given index.

list_pools(params=None)

Returns a list of pools according to the pool options passed in. Uses Pact API for fetching the data.

This method is deprecated but is kept for backward compatibility. Pact is in the process of changing the way the pools are created. In the future, all pools will be created using a pool factory contract which allows for an on-chain discoverability of pools.

Parameters

params (Optional[ListPoolsParams]) – API call parameters.

Return type

ApiListPoolsResponse

Returns

Paginated list of pools.

fetch_pools_by_assets(primary_asset, secondary_asset)

Returns a list of liquidity pools on Pact that are across the primary and secondary assets.

First, it uses Pact API retrieve app ids matching the provided assets and then uses algod client to fetch contracts data from the blockchain.

Parameters
  • primary_asset (Union[Asset, int]) – Primary asset or the asset id for the pool to find.

  • secondary_asset (Union[Asset, int]) – Secondary asset or the asset id for the pool to find.

Return type

list[Pool]

Returns

List of pools for the two assets, the list may be empty.

fetch_pool_by_id(app_id)

Fetches the pool by the application id. It uses algod client to fetch the data directly from the blockchain.

Parameters

app_id (int) – The application id of pool to return.

Raises

algosdk.error.AlgodHTTPError – If the pool does not exist.

Return type

Pool

Returns

The pool for the application id.

fetch_folks_lending_pool(app_id)

Fetches Folks Finance lending pool that can be used in FolksLendingPoolAdapter which allows higher APR than a normal pool. See pactsdk.folks_lending_pool for details.

Parameters

app_id (int) – The application id of the Folks Finance pool. You can find the ids here - https://docs.folks.finance/developer/contracts

Return type

FolksLendingPool

Returns

The Folks Finance lending pool for the given application id.

get_folks_lending_pool_adapter(pact_pool, primary_lending_pool, secondary_lending_pool)

Creates the adapter object that allows composing Folks Finance lending pools with Pact pool, resulting in a higher APR. See pactsdk.folks_lending_pool for details.

Parameters
  • pact_pool (Pool) – The Pact pool between two fAssets tokens.

  • primary_lending_pool (FolksLendingPool) – The Folks Finance pool for the primary fAsset.

  • secondary_lending_pool (FolksLendingPool) – The Folks Finance pool for the secondary fAsset.

Return type

FolksLendingPoolAdapter

Returns

The adapter object.

get_constant_product_pool_factory()

Gets the constant product pool factory according to the client’s configuration.

Return type

ConstantProductFactory

get_nft_constant_product_pool_factory()

Gets the NFT constant product pool factory according to the client’s configuration.

Return type

ConstantProductFactory