Skip to content

Commit

Permalink
Docs/refactor readme (#14)
Browse files Browse the repository at this point in the history
* docs: update docs with new functions

* docs: add types to documentation.md
  • Loading branch information
ignaciopenia authored Jul 23, 2024
1 parent 9c5de7d commit 38e997e
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 2 deletions.
11 changes: 10 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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);
})();
```

Expand Down
40 changes: 39 additions & 1 deletion documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,16 @@ function fetchSwappableCurrency(): Promise<TokenInfo[]>;

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<AMMRoute[]>;
```

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.
Expand Down Expand Up @@ -81,13 +91,41 @@ async function getRoute(from: Currency, to: Currency): Promise<Currency[]>;

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<TokenInfo[]>;
```

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<TxToBroadCast>;
```

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
*/
};
```

0 comments on commit 38e997e

Please sign in to comment.