Files
alex-sdk/documentation.md
david weil de391d1ddd Tests/sdk features: coverage. Stage 1 (#9)
* tests: enhance tests for existing functions

* tests: add test cases for existing functions

* tests: add test cases for three new functions

* merge from alex changes

* fix: error with variable name

* fix: removed unused variable

* fix: testing of getRoute updated to its signature

---------

Co-authored-by: ignacio.pena@coinfabrik.com <ignacio.pena@coinfabrik.com>
Co-authored-by: simsbluebox <simsbluebox@gmail.com>
Co-authored-by: david weil <david.weil@endlesstruction.com.ar>
2024-07-11 17:56:32 +08:00

3.6 KiB

API documentation

Supported Currencies

The SDK supports the following currencies:

export enum Currency {
  ALEX = 'age000-governance-token',
  USDA = 'token-wusda',
  STX = 'token-wstx',
  BANANA = 'token-wban',
  XBTC = 'token-wbtc',
  DIKO = 'token-wdiko',
  SLIME = 'token-wslm',
  XUSD = 'token-wxusd',
  MIA = 'token-wmia',
  NYCC = 'token-wnycc',
  CORGI = 'token-wcorgi',
}

Functions

The AlexSDK class includes the following functions:

export declare class AlexSDK {
    fetchSwappableCurrency(): Promise<TokenInfo[]>;
    getAmountTo(from: Currency, fromAmount: bigint, to: Currency): Promise<bigint>;
    getBalances(stxAddress: string): Promise<Partial<{ [currency in Currency]: bigint }>>;
    getFeeRate(from: Currency, to: Currency): Promise<bigint>;
    getLatestPrices(): Promise<Partial<{ [currency in Currency]: number }>>;
    getRoute(from: Currency, to: Currency): Promise<Currency[]>;
    runSwap(stxAddress: string, currencyX: Currency, 
            currencyY: Currency, fromAmount: bigint, 
            minDy: bigint, customRoute: Currency[]): Promise<TxToBroadCast>;
}

fetchSwappableCurrency

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

function fetchSwappableCurrency(): Promise<TokenInfo[]>;

Possible exceptions: Failed to fetch token mappings.

getAmountTo

Get the amount of destination currency that will be received when swapping from one currency to another.

async function getAmountTo(from: Currency, fromAmount: bigint, to: Currency): Promise<bigint>;

Possible exceptions: Failed to fetch token mappings, No AMM pool found for the given route, Too many AMM pools in route, Error calling read-only function.

getBalances

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.

async function getBalances(stxAddress: string): Promise<Partial<{ [currency in Currency]: bigint }>>;

Possible exceptions: Failed to fetch token mappings.

getFeeRate

Get the swap fee (liquidity provider fee) between two currencies.

async function getFeeRate(from: Currency, to: Currency): Promise<bigint>;

Possible exceptions: Failed to fetch token mappings, No AMM pools in route, Too many AMM pools in route, Error calling read-only function.

getLatestPrices

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.

async function getLatestPrices(): Promise<Partial<{ [currency in Currency]: number }>>;

Possible exceptions: Failed to fetch token mappings.

getRoute

Get the router path for swapping between two currencies.

async function getRoute(from: Currency, to: Currency): Promise<Currency[]>;

Possible exceptions: Failed to fetch token mappings, Can't find route.

runSwap

Perform a swap between two currencies using the specified route and amount.

function runSwap(stxAddress: string, currencyX: Currency, currencyY: Currency, 
                  fromAmount: bigint, minDy: bigint, customRoute: Currency[]): Promise<TxToBroadCast>;

Possible exceptions: Failed to fetch token mappings, Can't find AMM route, Token mapping not found, Too many AMM pools in route.