@alphafi/alphalend-sdk - v1.1.5
    Preparing search index...

    Class AlphalendClient

    AlphaLend Client

    The main entry point for interacting with the AlphaLend protocol:

    • Provides methods for all protocol actions (supply, borrow, withdraw, repay, claimRewards, liquidate)
    • Handles connection to the Sui blockchain and Pyth oracle
    • Manages transaction building for protocol interactions
    • Exposes query methods for protocol state, markets, and user positions
    • Initializes and coordinates price feed updates
    Index

    Constructors

    • Creates a new AlphaLend client instance

      Parameters

      • network: string

        Network to connect to ("mainnet", "testnet", or "devnet")

      • client: SuiClient

        SuiClient instance for blockchain interaction

      Returns AlphalendClient

    Properties

    client: SuiClient
    constants: Constants
    lendingProtocol: LendingProtocol
    network: string
    pythClient: SuiPythClient
    pythConnection: SuiPriceServiceConnection

    Methods

    • Borrows tokens from the AlphaLend protocol

      Parameters

      • params: BorrowParams

        Borrow parameters

        Parameters for borrowing assets from a lending market Used with the borrow method

        • address: string

          Address of the user borrowing tokens

        • amount: bigint

          Amount to borrow in base units (in mists)

        • coinType: string

          Borrow coin type (e.g., "0x2::sui::SUI")

        • marketId: string

          Market ID to borrow from

        • positionCapId: string

          Object ID of the position capability object

        • priceUpdateCoinTypes: string[]

          Coin types of the coins whose price needs to be updated (Will have to pass all market coin types that user has supplied or borrowed in and current market coin type in which user is borrowing)

      Returns Promise<Transaction>

      Transaction object ready for signing and execution

    • Claims rewards from the AlphaLend protocol

      Parameters

      • params: ClaimRewardsParams

        ClaimRewards parameters

        Parameters for claiming rewards accrued from lending or borrowing Used with the claimRewards method

        • address: string

          Address of the user supplying collateral

        • OptionalclaimAll?: boolean

          Whether to claim and deposit all rewards (except alpha)

          Use claimAndDepositAll instead.

        • OptionalclaimAlpha?: boolean

          Whether to claim and deposit alpha rewards

          Use claimAndDepositAlpha instead.

        • OptionalclaimAndDepositAll?: boolean

          Whether to deposit all rewards (except alpha)

        • OptionalclaimAndDepositAlpha?: boolean

          Whether to deposit alpha rewards

        • positionCapId: string

          Object ID of the position capability object

      Returns Promise<Transaction>

      Transaction object ready for signing and execution

      Use claimAndDepositAlpha instead

      Use claimAndDepositAll instead

    • Creates a new position in the protocol

      Parameters

      • tx: Transaction

      Returns TransactionResult

      Transaction object for creating a new position

    • Gets all markets data from the protocol

      Returns Promise<undefined | MarketData[]>

      Promise resolving to an array of Market objects

    • Gets all markets data from the protocol with cached markets chain data

      Parameters

      • markets: Market[]

      Returns Promise<undefined | MarketData[]>

      Promise resolving to an array of MarketData objects

    • Gets a coin object suitable for a transaction

      Parameters

      • tx: Transaction

        Transaction to which the coin will be added

      • type: string

        Fully qualified coin type to get

      • address: string

        Address of the user that owns the coin

      Returns Promise<undefined | string | TransactionObjectArgument>

      Transaction argument representing the coin or undefined if not found

    • Gets all markets chain data to cache

      Returns Promise<undefined | Market[]>

      Promise resolving to an array of Market objects

    • Gets user portfolio data

      Parameters

      • userAddress: string

        The user's address for which to fetch portfolio data

      Returns Promise<undefined | UserPortfolio[]>

      Promise resolving to an array of UserPortfolio objects or undefined if not found

    • Gets user portfolio data for a specific position

      Parameters

      • positionId: string

        The position ID to get portfolio data for

      Returns Promise<undefined | UserPortfolio>

      Promise resolving to a UserPortfolio object or undefined if not found

    • Gets portfolio data from position id with cached markets data

      Parameters

      • positionId: string

        The position id for which to fetch portfolio data

      • markets: Market[]

        The cached markets data to use for the portfolio

      Returns Promise<undefined | UserPortfolio>

      Promise resolving to a UserPortfolio object or undefined if not found

    • Gets user portfolio data with cached markets data

      Parameters

      • userAddress: string

        The user's address for which to fetch portfolio data

      • markets: Market[]

        The cached markets data to use for the portfolio

      Returns Promise<undefined | UserPortfolio[]>

      Promise resolving to an array of UserPortfolio objects or undefined if not found

    • Liquidates an unhealthy position

      Parameters

      • params: LiquidateParams

        Liquidate parameters - liquidatePositionId, borrowMarketId, withdrawMarketId, repayAmount, borrowCoinType, withdrawCoinType, coinObjectId, priceUpdateCoinTypes

      Returns Promise<(undefined | TransactionObjectArgument)[]>

      Transaction object ready for signing and execution

    • Repays borrowed tokens to the AlphaLend protocol

      Parameters

      • params: RepayParams

        Repay parameters

        Parameters for repaying borrowed assets to a lending market Used with the repay method

        • address: string

          Address of the user repaying the debt

        • amount: bigint

          Amount to repay in base units (in mists)

        • coinType: string

          Repay coin type (e.g., "0x2::sui::SUI")

        • marketId: string

          Market ID where the debt exists

        • positionCapId: string

          Object ID of the position capability object

      Returns Promise<undefined | Transaction>

      Transaction object ready for signing and execution

    • Supplies token collateral to the AlphaLend protocol

      Parameters

      • params: SupplyParams

        Supply parameters

        Parameters for supplying assets as collateral to a lending market Used with the supply method

        • address: string

          Address of the user supplying collateral

        • amount: bigint

          Amount to supply as collateral in base units (in mists)

        • coinType: string

          Supply coin type (e.g., "0x2::sui::SUI")

        • marketId: string

          Market ID where collateral is being added

        • OptionalpositionCapId?: string

          Object ID of the position capability object

      Returns Promise<undefined | Transaction>

      Transaction object ready for signing and execution

    • Parameters

      • tx: Transaction
      • coinTypes: string[]

      Returns Promise<void>

    • Updates price information for assets from Pyth oracle

      This method:

      1. Gathers price feed IDs for the specified coins
      2. Fetches the latest price data from Pyth oracle
      3. Adds price update instructions to the transaction
      4. Updates the protocol with new price information

      Parameters

      • tx: Transaction

        Transaction object to add price update calls to

      • coinTypes: string[]

        Array of fully qualified coin types (e.g., "0x2::sui::SUI")

      Returns Promise<void>

      Transaction object with price update calls

    • Withdraws token collateral from the AlphaLend protocol

      Parameters

      • params: WithdrawParams

        Withdraw parameters

        Parameters for withdrawing collateral from a lending market Used with the withdraw method

        • address: string

          Address of the user withdrawing collateral

        • amount: bigint

          Amount to withdraw (in mists, use MAX_U64 constant to withdraw all)

        • coinType: string

          Withdraw coin type (e.g., "0x2::sui::SUI")

        • marketId: string

          Market ID from which to withdraw

        • positionCapId: string

          Object ID of the position capability object

        • priceUpdateCoinTypes: string[]

          Coin types of the coins whose price needs to be updated (Will have to pass all market coin types that user has supplied or borrowed in and current market coin type in which user is withdrawing)

      Returns Promise<Transaction>

      Transaction object ready for signing and execution