🤽Lending Pools

This package contains read and write methods for all August Digital lending pools, as featured on the Kelp DAO restaking app.

Introduction

The LendingPool contract is a timelock-enabled ERC4626-compliant token vault designed to increase the utilisation of a liquid restaking token (LRT) through lending and borrowing activities. Users with LRT can become lenders by depositing their tokens in to the pool. The pool operator then lends the collected tokens or funds to borrowers through loan contracts. Lenders can withdraw from the scheme at any time, and the pool operator reserves the right to call the loans whenever necessary to ensure the required funds are available for returning to the lenders.

Using the SDK

You can use either the methods individually or by using the initialized AugustPools class. If you're using methods directly, you will be required to pass a the RPC URL so we recommend using a the class instead.

In these documentation examples, we will present the methods as if they're being used as a member of the exported AugustPools class (i.e. AugustPools.<METHOD_NAME>).

Installation

Install the package in your project directory with:

npm install @augustdigital/pools

Available Methods

Fetching Pool Data

Get All Lending Pools

Returns an array of of all August Digital lending pools including all relevant on-chain details about the pool.

async getPools()
[
    {
        address: IAddress;
        name: string;
        asset: IAddress;
        apy?: INormalizedNumber;
        collateral?: IAddress[];
        loansOperator: IAddress;
        globalLoansAmount: INormalizedNumber;
        symbol: string;
        totalAssets: INormalizedNumber;
        totalSupply: INormalizedNumber;
        totalBorrowed?: INormalizedNumber;
        decimals: number;
        loans?: IPoolLoan[];
        getTotalLoansDeployed: INormalizedNumber;
        underlying: {
            address: IAddress;
            symbol: string;
            decimals: number;
        }
    }
    ...
]

Get Lending Pool

Returns a single August Digital lending pool including all the on-chain details about the pool.

// @param pool - vault contract address
async getPool(pool: IAddress)
[
    {
        address: IAddress;
        name: string;
        asset: IAddress;
        apy?: INormalizedNumber;
        collateral?: IAddress[];
        loansOperator: IAddress;
        globalLoansAmount: INormalizedNumber;
        symbol: string;
        totalAssets: INormalizedNumber;
        totalSupply: INormalizedNumber;
        totalBorrowed?: INormalizedNumber;
        decimals: number;
        loans?: IPoolLoan[];
        getTotalLoansDeployed: INormalizedNumber;
        underlying: {
            address: IAddress;
            symbol: string;
            decimals: number;
        }
    }
    ...
] 

Get Available Redemptions

Returns a list of all available redemptions including the required parameters for a Pool.claim contract write method.

// @param pool - vault contract address
// @param address (optional) - user wallet address
async getAvailableRedemptions(pool: IAddress, address?: IAddress)
[
    {
        receiver: IAddress;
        day: INormalizedNumber;
        month: INormalizedNumber;
        year: INormalizedNumber;
        amount: INormalizedNumber;
        date: Date;
    },
    ...
]

Get Positions Across All Pools

Returns a list of all staked positions for a given wallet address across all Lending Pools for the given network in a way where the object contains all required parameters to pass to Pool.claim.

// @param address wallet address to query positions for
// @param pools (optional) - array of pool data objects
async getAllPositions(address: IAddress, pools?: IPoolWithUnderlying[])
[
    {
        ...pool: IPoolWithUnderlying;
        token: string;                                    // token symbol
        position: string;                                 // pool name
        status: "REDEEM" | "STAKED" | "PENDING";      
        availableRedemptions: IPoolAvailableRedemptions[],
        redeemable: INormalizedNumber;
        walletBalance: string;
      }
      ...
]

Get Pool APR

Returns a pool's current or historical APR which is based on a weighted average of all deployed and active loans.

// @param pool - vault contract address
// @param input params (optional) - object that if passed returns a historical list of objects
async getPoolApr(
    pool: IAddress,
    {
      start: Date
      order?: 'asc' | 'desc'          // default: desc --> descending
      interval?:                      // default: days --> day interval
        | 'years'
        | 'quarters'
        | 'months'
        | 'weeks'
        | 'days'
        | 'hours'
        | 'minutes'
    }
)
{
    timestamp: number;             // unix timestamp
    value: INormalized;            // APR amount at that unix time
} | {                              // OR historical will be an array
    timestamp: number;             
    value: INormalized; 
}[]

Get Pool TVL

Returns a pool's current or historical TVL which is simply the total deposits subtracted by total withdraws.

// @param pool - vault contract address
// @param input params (optional) - object that if passed returns a historical list of objects
async getPoolTvl(
    pool: IAddress,
    {
      start: Date
      order?: 'asc' | 'desc'          // default: desc --> descending
      interval?:                      // default: days --> day interval
        | 'years'
        | 'quarters'
        | 'months'
        | 'weeks'
        | 'days'
        | 'hours'
        | 'minutes'
    }
)
{
    timestamp: number;             // unix timestamp
    value: INormalizedNumber;      // TVL amount at that unix time
} | {                              // OR historical will be an array
    timestamp: number;             
    value: INormalizedNumber; 
}[]

Interacting with a Pool

Allowance

Returns the user wallet allowance for the inputted lending pool.

// @param pool - vault contract address
// @param signer - ethers Signer object built from user wallet
async allowance(pool: IAddress, signer: ISigner)
{
    normalized: string;
    raw: bigint;
}

Approve

Wrapper for the lending pool's ERC20.approve method.

// @param pool - vault contract address
// @param signer - ethers Signer object built from user wallet
// @param input params - object with amount to approve in any number type
async approve(pool: IAddress, signer: Signer, { amount: string | number | bigint })
TransactionHash: string

Deposit

Wrapper for the lending pool's ERC4626.deposit method.

// @param pool - vault contract address
// @param signer - ethers Signer object built from user wallet
// @param input params - object with amount to approve in any number type
async deposit(pool: IAddress, signer: Signer, { amount: string | number | bigint })
TransactionHash: string

Request Withdrawal

Wrapper for the lending pool's Pool.requestRedeem method.

// @param pool - vault contract address
// @param signer - ethers Signer object built from user wallet
async requestWithdrawal(pool: IAddress, signer: Signer)
TransactionHash: string

Withdraw

Wrapper for the lending pool's Pool.claim method.

async withdraw(
    pool: IAddress,
    signer: Signer,
    inputParams: {
      amount: string | bigint | number;
      day: string;
      month: string;
      year: string;
      receiverIndex: string;
    }
)
TransactionHash: string

Last updated