forked from alexgo-io/alex-sdk
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(README): Function especification moved into `documentation.m…
…d` file
- Loading branch information
david weil
committed
Jun 28, 2024
1 parent
953afaa
commit aacc31e
Showing
2 changed files
with
127 additions
and
103 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
# API documentation | ||
|
||
## Supported Currencies | ||
|
||
The SDK supports the following currencies: | ||
|
||
```typescript | ||
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: | ||
|
||
```typescript | ||
export declare class AlexSDK { | ||
getFeeRate(from: Currency, to: Currency): Promise<bigint>; | ||
getRouter(from: Currency, to: Currency): Promise<Currency[]>; | ||
getAmountTo(from: Currency, fromAmount: bigint, to: Currency): Promise<bigint>; | ||
runSwap(stxAddress: string, currencyX: Currency, | ||
currencyY: Currency, fromAmount: bigint, | ||
minDy: bigint, router: Currency[]): Promise<TxToBroadCast>; | ||
getLatestPrices(): Promise<Partial<{ [currency in Currency]: number }>>; | ||
getBalances(stxAddress: string): Promise<Partial<{ [currency in Currency]: bigint }>>; | ||
fetchSwappableCurrency(): Promise<TokenInfo[]>; | ||
} | ||
``` | ||
|
||
### getFee | ||
Rate | ||
Get the swap fee (liquidity provider fee) between two currencies. | ||
|
||
```typescript | ||
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`. | ||
|
||
### getRouter | ||
|
||
Get the router path for swapping between two currencies. | ||
|
||
```typescript | ||
async function getRouter(from: Currency, to: Currency): Promise<Currency[]>; | ||
``` | ||
|
||
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. | ||
|
||
```typescript | ||
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`. | ||
|
||
|
||
### runSwap | ||
|
||
Perform a swap between two currencies using the specified route and amount. | ||
|
||
```typescript | ||
function runSwap(stxAddress: string, currencyX: Currency, currencyY: Currency, | ||
fromAmount: bigint, minDy: bigint, router: 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`. | ||
|
||
### 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. | ||
|
||
```typescript | ||
async function getLatestPrices(): Promise<Partial<{ [currency in Currency]: number }>>; | ||
``` | ||
Possible exceptions: `Failed to fetch token mappings`. | ||
|
||
### 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. | ||
|
||
```typescript | ||
async function getBalances(stxAddress: string): Promise<Partial<{ [currency in Currency]: bigint }>>; | ||
``` | ||
|
||
Possible exceptions: `Failed to fetch token mappings`. | ||
|
||
|
||
### fetchSwappableCurrency | ||
|
||
This function returns an array of `TokenInfo` objects, each containing detailed information about a supported swappable currency. | ||
|
||
```typescript | ||
function fetchSwappableCurrency(): Promise<TokenInfo[]>; | ||
``` | ||
|
||
Possible exceptions: `Failed to fetch token mappings`. | ||
|