Skip to content

Commit

Permalink
docs: update sdk readme and docs (#27)
Browse files Browse the repository at this point in the history
* fix: README sdk information

* fix: usage example in README

* docs: fix fetchSwapQuote and prepareSwapTransactions params

---------

Co-authored-by: Gabriele Di Remigio <[email protected]>
  • Loading branch information
stefanofa and gabrielediremigio authored Nov 24, 2023
1 parent 2728ec0 commit 74ff362
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 20 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ An open source interface for Folks Router build with [Astro](https://github.com/

The official JavaScript SDK for Folks Router DEXs aggregator.

_**NOTE:** More information on installation, use and examples will be available soon._
For installation instructions, usage guidelines, and examples, please visit this [link](https://github.com/Folks-Finance/folks-router/tree/main/packages/folks-router-js-sdk) to discover more about the SDK.
17 changes: 4 additions & 13 deletions apps/website/src/content/docs/docs/sdk/methods/fetch-swap-quote.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,11 @@ title: fetchSwapQuote
description: fetchSwapQuote function.
---

See the full code [here](https://github.com/Folks-Finance/folks-router/blob/js-sdk-readme/packages/folks-router-js-sdk/src/FolksRouterClient.ts#L24).
See the full code [here](https://github.com/Folks-Finance/folks-router/blob/main/packages/folks-router-js-sdk/src/FolksRouterClient.ts#L37).

```ts
fetchSwapQuote(
fromAssetId: number,
toAssetId: number,
amount: number | bigint,
swapMode: SwapMode,
params: SwapParams,
maxGroupSize?: number,
feeBps?: number | bigint,
referrer?: string,
Expand All @@ -33,14 +30,8 @@ interface SwapQuote {
### Parameters

```sh
# The assetId to swap from
fromAssetId: number
# The assetId to swap to
toAssetId: number
# The swap amount
amount: number | bigint
# The swap mode ("FIXED_INPUT" | "FIXED_OUTPUT")
swapMode: SwapMode
# The set of parameters used for executing the swap
params: SwapParams
# The maximum group size of the txn (min 3, max 16)
maxGroupSize?: number
# The fee percentage expressed as fixed percentage of input amount (4 d.p)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ title: prepareSwapTransactions
description: prepareSwapTransactions function.
---

See the full code [here](https://github.com/Folks-Finance/folks-router/blob/main/packages/folks-router-js-sdk/src/FolksRouterClient.ts#L57).
See the full code [here](https://github.com/Folks-Finance/folks-router/blob/main/packages/folks-router-js-sdk/src/FolksRouterClient.ts#L69).

```ts
prepareSwapTransactions(
params: SwapParams,
userAddress: string,
slippageBps: number | bigint,
swapQuote: SwapQuote,
Expand All @@ -24,6 +25,8 @@ type SwapTransactions = string[];
### Parameters

```sh
# The set of parameters used for executing the swap
params: SwapParams
# The address performing the transaction
userAddress: string
# The slippage percentage to perform the transaction
Expand Down
23 changes: 18 additions & 5 deletions packages/folks-router-js-sdk/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,25 +24,38 @@ Documentation for this SDK is available at [folksrouter.io](https://folksrouter.
## Usage

```ts
import { FolksRouterClient, Network, SwapMode } from "@folks-router/js-sdk";
import { FolksRouterClient, Network, SwapMode, SwapParams } from "@folks-router/js-sdk";
import { Algodv2, decodeUnsignedTransaction, generateAccount } from "algosdk";

const senderAccount = generateAccount();
const algodClient = new Algodv2("", "https://mainnet-api.algonode.cloud/", 443);
const folksRouterClient = new FolksRouterClient(Network.MAINNET);

async function main() {
// Construct Swap Params
const swapParams: SwapParams = {
fromAssetId: 0,
toAssetId: 31566704,
amount: BigInt(10e6),
swapMode: SwapMode.FIXED_INPUT,
};

// Fetch Swap Quote
const swapQuote = await folksRouterClient.fetchSwapQuote(0, 31566704, BigInt(10e6), SwapMode.FIXED_INPUT);
const swapQuote = await folksRouterClient.fetchSwapQuote(swapParams);

// Prepare Swap Transactions
const base64txns = await folksRouterClient.prepareSwapTransactions(senderAccount.addr, BigInt(10), swapQuote);
const unsignedTxns = base64txns.map((txn) => decodeUnsignedTransaction(Buffer.from(txn, "base64")));
const base64Txns = await folksRouterClient.prepareSwapTransactions(
swapParams,
senderAccount.addr,
BigInt(10),
swapQuote,
);
const unsignedTxns = base64Txns.map((txn) => decodeUnsignedTransaction(Buffer.from(txn, "base64")));
const signedTxns = unsignedTxns.map((txn) => txn.signTxn(senderAccount.sk));

// Submit Transaction
await algodClient.sendRawTransaction(signedTxns).do();
}

main();
main().catch(console.error);
```

0 comments on commit 74ff362

Please sign in to comment.