Class AlexSDK

The AlexSDK class provides methods for interacting with a decentralized exchange (DEX) system, allowing users to fetch currency information, calculate routes for swaps, estimate fees and amounts, perform swaps, retrieve latest prices, and check balances.

Constructors

Methods

  • This function returns an array of TokenInfo objects, each containing detailed information about a supported swappable currency.

    Returns Promise<TokenInfo[]>

    • A promise that resolves to an array of TokenInfo objects representing the currencies available for swaps.
  • This function returns all possible routes for swapping between two specified currencies. It returns an array of AMMRoute, representing possible swap routes.

    Parameters

    Returns Promise<AMMRoute[]>

    • A promise that resolves to an array of AMMRoute objects, representing all possible swap routes between the two specified currencies.
  • Get the amount of destination currency that will be received when swapping from one currency to another.

    Parameters

    • from: Currency

      The currency to swap from.

    • fromAmount: bigint

      The amount of the source currency to swap.

    • to: Currency

      The currency to swap to.

    • OptionalcustomRoute: AMMRoute

      An optional custom route for the swap.

    Returns Promise<bigint>

    • A promise that resolves to a bigint representing the amount of the destination currency that will be received.
  • This function fetches the current balances of all supported tokens for a specified STX address. It returns an object where the keys are the currency identifiers (as defined in the Currency enum) and the values are the corresponding balances as bigint values.

    Parameters

    • stxAddress: string

      The Stacks (STX) address to retrieve the balances for.

    Returns Promise<Partial<{}>>

    • A promise that resolves to an object containing the balances of each currency for the given address.
  • Get the swap fee (liquidity provider fee) between two currencies.

    Parameters

    • from: Currency

      The currency to swap from.

    • to: Currency

      The currency to swap to.

    • OptionalcustomRoute: AMMRoute

      An optional custom route for the swap.

    Returns Promise<bigint>

    • A promise that resolves to a bigint representing the fee rate for the swap.
  • This function fetches the current price data for all supported tokens. It returns an object where the keys are the currency identifiers (as defined in the Currency enum) and the values are the corresponding prices in USD.

    Returns Promise<Partial<{}>>

    • A promise that resolves to an object containing the latest prices for each currency.
  • Get the router path for swapping between two currencies.

    Parameters

    Returns Promise<AMMRoute>

    • A promise that resolves to an AMMRoute object, representing the best route for the swap.
  • This function takes an AMMRoute and returns an array of TokenInfo objects representing the tokens involved in each step of the route, including the origin token.

    Parameters

    • route: AMMRoute

      The route to display.

    Returns Promise<TokenInfo[]>

    • A promise that resolves to an array of TokenInfo objects, representing the detailed information of the route.
  • Perform a swap between two currencies using the specified route and amount.

    Parameters

    • stxAddress: string

      The Stacks (STX) address to execute the swap from.

    • currencyX: Currency

      The currency to swap from.

    • currencyY: Currency

      The currency to swap to.

    • fromAmount: bigint

      The amount of the source currency to swap.

    • minDy: bigint

      The minimum amount of the destination currency to receive.

    • OptionalcustomRoute: AMMRoute

      An optional custom route for the swap.

    Returns Promise<TxToBroadCast>

    • A promise that resolves to a TxToBroadCast object, representing the transaction to be broadcasted.