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 7742aeb..13a2ec9 100644 --- a/docs/docs/03-sdk/04-methods-reference/transfer/transferWithHook.md +++ b/docs/docs/03-sdk/04-methods-reference/transfer/transferWithHook.md @@ -94,6 +94,7 @@ sprinter.transferWithHook(settings, { baseUrl: "https://custom.api.url" }).then( ## Parameters - `settings`: _(Required)_ An object containing the following fields: + - `account`: The user’s address. - `destinationChain`: The ID of the destination chain. - `token`: The symbol of the token to be transferred (e.g., `USDC`, `ETH`). @@ -112,6 +113,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 ef93250..e259303 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 @@ -38,6 +38,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/react/.prettierrc b/packages/react/.prettierrc new file mode 100644 index 0000000..60998ab --- /dev/null +++ b/packages/react/.prettierrc @@ -0,0 +1,6 @@ +{ + "useTabs": false, + "singleQuote": false, + "trailingComma": "all", + "printWidth": 80 +} diff --git a/packages/sdk/.prettierrc b/packages/sdk/.prettierrc new file mode 100644 index 0000000..99c88b4 --- /dev/null +++ b/packages/sdk/.prettierrc @@ -0,0 +1,6 @@ +{ + "useTabs": false, + "singleQuote": false, + "trailingComma": "all", + "printWidth": 80 +} diff --git a/packages/sdk/src/api.ts b/packages/sdk/src/api.ts index fb0b94a..ad4ab41 100644 --- a/packages/sdk/src/api.ts +++ b/packages/sdk/src/api.ts @@ -185,6 +185,7 @@ export async function getContractCallSolution( recipient, threshold, whitelistedSourceChains, + enableSwaps, }: SingleHopContractSolutionOptions, { baseUrl, signal }: FetchOptions = {}, ): Promise { @@ -203,6 +204,7 @@ export async function getContractCallSolution( recipient, threshold, whitelistedSourceChains, + enableSwaps, }), }).then( (response) => diff --git a/packages/sdk/src/internal/validators.ts b/packages/sdk/src/internal/validators.ts index 24de300..cf11ec2 100644 --- a/packages/sdk/src/internal/validators.ts +++ b/packages/sdk/src/internal/validators.ts @@ -2,6 +2,7 @@ import { array, assign, bigint, + boolean, define, number, object, @@ -40,6 +41,7 @@ const BridgeCoreSchema = object({ const BridgeCoreWithRecipientSchema = assign( BridgeCoreSchema, object({ + enableSwaps: optional(boolean()), recipient: optional(hexString()), }), ); diff --git a/packages/sdk/src/sprinter.ts b/packages/sdk/src/sprinter.ts index 5223f38..fedb7e4 100644 --- a/packages/sdk/src/sprinter.ts +++ b/packages/sdk/src/sprinter.ts @@ -355,6 +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): 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. * @@ -372,6 +373,7 @@ export class Sprinter { * token: "USDC", * amount: "100000000", * recipient: "0xRecipientAddress", // Optional recipient of leftover tokens + * enableSwaps: true, // Enabling swaps on the source chain * }; * * sprinter.transfer(settings).then(solution => { @@ -387,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, @@ -422,6 +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): 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. * @@ -444,6 +448,7 @@ export class Sprinter { * gasLimit: 21000, * }, * recipient: "0xRecipientAddress", // for sending leftover tokens + * enableSwaps: true, // Enabling swaps on the source chain * }; * * sprinter.transferWithHook(settings).then(solution => { @@ -459,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..a44e149 100644 --- a/packages/sdk/src/types.ts +++ b/packages/sdk/src/types.ts @@ -59,6 +59,7 @@ export interface ContractCallSolutionOptions { export interface SingleHopContractSolutionOptions extends SolutionOptions { recipient?: Address; contractCall?: ContractCallSolutionOptions; + enableSwaps?: boolean; } export interface ContractSolutionOptions extends SolutionOptions {