From 035ed1d871cf2cee064bde37bebf8487a3619197 Mon Sep 17 00:00:00 2001 From: Thibaut Sardan Date: Mon, 9 Dec 2024 15:24:55 +0100 Subject: [PATCH] default to false and add docs --- .../04-methods-reference/transfer/transferWithHook.md | 2 ++ .../04-methods-reference/transfer/transfer_method.md | 1 + packages/sdk/src/api.ts | 4 ++++ packages/sdk/src/sprinter.ts | 10 ++++++---- packages/sdk/src/types.ts | 1 + 5 files changed, 14 insertions(+), 4 deletions(-) diff --git a/docs/docs/03-sdk/04-methods-reference/transfer/transferWithHook.md b/docs/docs/03-sdk/04-methods-reference/transfer/transferWithHook.md index 24e0e02..e4321ea 100644 --- a/docs/docs/03-sdk/04-methods-reference/transfer/transferWithHook.md +++ b/docs/docs/03-sdk/04-methods-reference/transfer/transferWithHook.md @@ -109,6 +109,8 @@ sprinter.transferWithHook(settings, { baseUrl: 'https://custom.api.url' }).then( - `recipient?`: *(Optional)* The address of the recipient of any leftover tokens. - `sourceChains?`: *(Optional)* An array of source chain IDs to be considered for the transfer. If omitted, Sprinter will use all available chains for the solution. - `threshold?`: *(Optional)* The minimum amount of tokens required to trigger the transfer solution. If not met, the transfer solution will not proceed. + - `enableSwaps`: *(Optional)* Defaults to `false`. Whether to enable token swaps on the source chain. + - `fetchOptions?`: *(Optional)* An object containing `baseUrl` to override the default API endpoint for this request. import HowToCallData from "../_how-to-calldata.md" diff --git a/docs/docs/03-sdk/04-methods-reference/transfer/transfer_method.md b/docs/docs/03-sdk/04-methods-reference/transfer/transfer_method.md index 3bc1224..4d84fee 100644 --- a/docs/docs/03-sdk/04-methods-reference/transfer/transfer_method.md +++ b/docs/docs/03-sdk/04-methods-reference/transfer/transfer_method.md @@ -37,6 +37,7 @@ sprinter.transfer(settings).then(solution => { - `recipient?`: *(Optional)* The address of the recipient of any leftover tokens. - `sourceChains?`: *(Optional)* An array of source chain IDs to be considered for the transfer. If omitted, Sprinter will use all available chains for the solution. To limit the solution to a specific chain, provide an array containing only that chain's ID. - `threshold?`: *(Optional)* The minimum amount of tokens required to trigger the transfer solution. If not met, the transfer solution will not proceed. + - `enableSwaps`: *(Optional)* Defaults to `false`. Whether to enable token swaps on the source chain. - `fetchOptions?`: *(Optional)* An object containing `baseUrl` to override the default API endpoint for this request. diff --git a/packages/sdk/src/api.ts b/packages/sdk/src/api.ts index fb0b94a..4731e1c 100644 --- a/packages/sdk/src/api.ts +++ b/packages/sdk/src/api.ts @@ -148,6 +148,7 @@ export async function getContractSolution( contractCall, threshold, whitelistedSourceChains, + enableSwaps, }: ContractSolutionOptions, { baseUrl, signal }: FetchOptions = {}, ): Promise { @@ -165,6 +166,7 @@ export async function getContractSolution( type: "fungible", threshold, whitelistedSourceChains, + enableSwaps }), }).then( (response) => @@ -185,6 +187,7 @@ export async function getContractCallSolution( recipient, threshold, whitelistedSourceChains, + enableSwaps, }: SingleHopContractSolutionOptions, { baseUrl, signal }: FetchOptions = {}, ): Promise { @@ -203,6 +206,7 @@ export async function getContractCallSolution( recipient, threshold, whitelistedSourceChains, + enableSwaps, }), }).then( (response) => diff --git a/packages/sdk/src/sprinter.ts b/packages/sdk/src/sprinter.ts index b1dc04e..fedb7e4 100644 --- a/packages/sdk/src/sprinter.ts +++ b/packages/sdk/src/sprinter.ts @@ -355,7 +355,7 @@ export class Sprinter { * - `recipient` (optional): The address of the recipient of any leftover tokens. * - `threshold` (optional): The minimum amount threshold required for the transfer. * - `sourceChains` (optional): An array of whitelisted source chain IDs for the transfer. - * - `enableSwaps` {boolean} (optional): Whether to enable token swaps on the source chain. + * - `enableSwaps` {boolean} (optional): Defaults to `false`. Whether to enable token swaps on the source chain. * * @param {FetchOptions} [options] - Optional configuration for the fetch request, such as custom headers or query parameters. * @@ -389,10 +389,11 @@ export class Sprinter { ): Promise { assert(settings, SingleHopSchema); - const { sourceChains, amount, ...data } = settings; + const { sourceChains, amount, enableSwaps = false, ...data } = settings; return await getContractCallSolution( { ...data, + enableSwaps, amount: BigInt(amount), whitelistedSourceChains: sourceChains, } as SolutionOptions, @@ -424,7 +425,7 @@ export class Sprinter { * - `recipient` {string} (optional): The address of the recipient of any leftover tokens. * - `sourceChains` {Array} (optional): An array of source chain IDs to be considered for the transfer. * - `threshold` {number} (optional): The minimum amount threshold required for the transfer. - * - `enableSwaps` {boolean} (optional): Whether to enable token swaps on the source chain. + * - `enableSwaps` {boolean} (optional): Defaults to `false`. Whether to enable token swaps on the source chain. * * @param {FetchOptions} [options] - Optional configuration for the fetch request, such as custom headers or query parameters. * @@ -463,10 +464,11 @@ export class Sprinter { ): Promise { assert(settings, SingleHopWithContractSchema); - const { sourceChains, amount, ...data } = settings; + const { sourceChains, amount, enableSwaps = false, ...data } = settings; return await getContractCallSolution( { ...data, + enableSwaps, amount: BigInt(amount), whitelistedSourceChains: sourceChains, } as SolutionOptions, diff --git a/packages/sdk/src/types.ts b/packages/sdk/src/types.ts index f408d17..50e68e6 100644 --- a/packages/sdk/src/types.ts +++ b/packages/sdk/src/types.ts @@ -45,6 +45,7 @@ export interface SolutionOptions { amount: NumberLike; threshold?: number; whitelistedSourceChains?: ChainID[]; + enableSwaps?: boolean; } export interface ContractCallSolutionOptions {