From 38e997e8c60c0e0ce97f4cef9b7279c5435c57b9 Mon Sep 17 00:00:00 2001 From: ignaciopenia <108410122+ignaciopenia@users.noreply.github.com> Date: Tue, 23 Jul 2024 04:33:07 -0300 Subject: [PATCH] Docs/refactor readme (#14) * docs: update docs with new functions * docs: add types to documentation.md --- README.md | 11 ++++++++++- documentation.md | 40 +++++++++++++++++++++++++++++++++++++++- 2 files changed, 49 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 2553fba..936dc0d 100644 --- a/README.md +++ b/README.md @@ -80,7 +80,16 @@ const alex = new AlexSDK(); // Fetch information about all swappable currencies const swappableCurrencies = await alex.fetchSwappableCurrency(); - console.log('Swappable currencies:', swappableCurrencies); + console.log('Swappable currencies:', swappableCurrencies); + + // Get all possible routes for swapping currencies + const allRoutes = await alex.getAllPossibleRoutes(Currency.STX, Currency.ALEX); + console.log('All possible routes:', allRoutes); + + // Get way points + const someRoute: AMMRoute = [x1, x2]; + const wayPoints = await sdk.getWayPoints(someRoute); + console.log('Way points for the route:', wayPoints); })(); ``` diff --git a/documentation.md b/documentation.md index 2183b5c..b0b0d87 100644 --- a/documentation.md +++ b/documentation.md @@ -31,6 +31,16 @@ function fetchSwappableCurrency(): Promise; Possible exceptions: `Failed to fetch token mappings`. +### getAllPossibleRoutes + +This function returns all possible routes for swapping between two specified currencies. It returns an array of AMMRoute, representing possible swap routes. + +```typescript +async function getAllPossibleRoutes(from: Currency, to: Currency): Promise; +``` + +Possible exceptions: `Failed to fetch token mappings`, `Can't find route`. + ### getAmountTo Get the amount of destination currency that will be received when swapping from one currency to another. @@ -81,13 +91,41 @@ async function getRoute(from: Currency, to: Currency): Promise; Possible exceptions: `Failed to fetch token mappings`, `Can't find route`. +### getWayPoints + +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. + +```typescript +async function getWayPoints(route: AMMRoute): Promise; +``` + +Possible exceptions: `Failed to fetch token mappings`. + ### runSwap Perform a swap between two currencies using the specified route and amount. ```typescript -function runSwap(stxAddress: string, currencyX: Currency, currencyY: Currency, +async function runSwap(stxAddress: string, currencyX: Currency, currencyY: Currency, fromAmount: bigint, minDy: bigint, customRoute: Currency[]): Promise; ``` Possible exceptions: `Failed to fetch token mappings`, `Can't find AMM route`, `Token mapping not found`, `Too many AMM pools in route`. + +## Types +```typescript +export type TokenInfo = { // TokenInfo represents the details of a token that can be used in the AlexSDK. + id: Currency; // The unique identifier of the currency. + name: string; // The display name of the token that ALEX maintains, usually the token symbol. + icon: string; // The URL to the icon image of the token, maintained by ALEX. + wrapToken: string; // The full asset id of the alex wrapped token in the format of "{deployer}.{contract}::{asset}". + wrapTokenDecimals: number; // The number of decimal places for the wrapped token. + underlyingToken: string; // The full asset id of the underlying token in the format of "{deployer}.{contract}::{asset}". + underlyingTokenDecimals: number; // The number of decimal places for the underlying token. + isRebaseToken: boolean; // A boolean flag indicating whether the token is a rebase token. + /** + * In a rebase token, getBalance is different from ft-balance + * Also postcondition would need to be adjusted since amount is different from ft-events + */ +}; +``` \ No newline at end of file