Skip to content

Commit bd21311

Browse files
authored
feat: add enableSwaps in transferWithHook and transfer (#97)
closes #94
1 parent c6188bb commit bd21311

File tree

8 files changed

+29
-2
lines changed

8 files changed

+29
-2
lines changed

docs/docs/03-sdk/04-methods-reference/transfer/transferWithHook.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ sprinter.transferWithHook(settings, { baseUrl: "https://custom.api.url" }).then(
9494
## Parameters
9595

9696
- `settings`: _(Required)_ An object containing the following fields:
97+
9798
- `account`: The user’s address.
9899
- `destinationChain`: The ID of the destination chain.
99100
- `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(
112113
- `recipient?`: _(Optional)_ The address of the recipient of any leftover tokens.
113114
- `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.
114115
- `threshold?`: _(Optional)_ The minimum amount of tokens required to trigger the transfer solution. If not met, the transfer solution will not proceed.
116+
- `enableSwaps`: _(Optional)_ Defaults to `false`. Whether to enable token swaps on the source chain.
117+
115118
- `fetchOptions?`: _(Optional)_ An object containing `baseUrl` to override the default API endpoint for this request.
116119

117120
import HowToCallData from "../\_how-to-calldata.md"

docs/docs/03-sdk/04-methods-reference/transfer/transfer_method.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ sprinter.transfer(settings).then((solution) => {
3838
- `recipient?`: _(Optional)_ The address of the recipient of any leftover tokens.
3939
- `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.
4040
- `threshold?`: _(Optional)_ The minimum amount of tokens required to trigger the transfer solution. If not met, the transfer solution will not proceed.
41+
- `enableSwaps`: _(Optional)_ Defaults to `false`. Whether to enable token swaps on the source chain.
4142

4243
- `fetchOptions?`: _(Optional)_ An object containing `baseUrl` to override the default API endpoint for this request.
4344

packages/react/.prettierrc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"useTabs": false,
3+
"singleQuote": false,
4+
"trailingComma": "all",
5+
"printWidth": 80
6+
}

packages/sdk/.prettierrc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"useTabs": false,
3+
"singleQuote": false,
4+
"trailingComma": "all",
5+
"printWidth": 80
6+
}

packages/sdk/src/api.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@ export async function getContractCallSolution(
185185
recipient,
186186
threshold,
187187
whitelistedSourceChains,
188+
enableSwaps,
188189
}: SingleHopContractSolutionOptions,
189190
{ baseUrl, signal }: FetchOptions = {},
190191
): Promise<SolutionResponse> {
@@ -203,6 +204,7 @@ export async function getContractCallSolution(
203204
recipient,
204205
threshold,
205206
whitelistedSourceChains,
207+
enableSwaps,
206208
}),
207209
}).then(
208210
(response) =>

packages/sdk/src/internal/validators.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import {
22
array,
33
assign,
44
bigint,
5+
boolean,
56
define,
67
number,
78
object,
@@ -40,6 +41,7 @@ const BridgeCoreSchema = object({
4041
const BridgeCoreWithRecipientSchema = assign(
4142
BridgeCoreSchema,
4243
object({
44+
enableSwaps: optional(boolean()),
4345
recipient: optional(hexString()),
4446
}),
4547
);

packages/sdk/src/sprinter.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,7 @@ export class Sprinter {
355355
* - `recipient` (optional): The address of the recipient of any leftover tokens.
356356
* - `threshold` (optional): The minimum amount threshold required for the transfer.
357357
* - `sourceChains` (optional): An array of whitelisted source chain IDs for the transfer.
358+
* - `enableSwaps` {boolean} (optional): Defaults to `false`. Whether to enable token swaps on the source chain.
358359
*
359360
* @param {FetchOptions} [options] - Optional configuration for the fetch request, such as custom headers or query parameters.
360361
*
@@ -372,6 +373,7 @@ export class Sprinter {
372373
* token: "USDC",
373374
* amount: "100000000",
374375
* recipient: "0xRecipientAddress", // Optional recipient of leftover tokens
376+
* enableSwaps: true, // Enabling swaps on the source chain
375377
* };
376378
*
377379
* sprinter.transfer(settings).then(solution => {
@@ -387,10 +389,11 @@ export class Sprinter {
387389
): Promise<SolutionResponse> {
388390
assert(settings, SingleHopSchema);
389391

390-
const { sourceChains, amount, ...data } = settings;
392+
const { sourceChains, amount, enableSwaps = false, ...data } = settings;
391393
return await getContractCallSolution(
392394
{
393395
...data,
396+
enableSwaps,
394397
amount: BigInt(amount),
395398
whitelistedSourceChains: sourceChains,
396399
} as SolutionOptions,
@@ -422,6 +425,7 @@ export class Sprinter {
422425
* - `recipient` {string} (optional): The address of the recipient of any leftover tokens.
423426
* - `sourceChains` {Array<number>} (optional): An array of source chain IDs to be considered for the transfer.
424427
* - `threshold` {number} (optional): The minimum amount threshold required for the transfer.
428+
* - `enableSwaps` {boolean} (optional): Defaults to `false`. Whether to enable token swaps on the source chain.
425429
*
426430
* @param {FetchOptions} [options] - Optional configuration for the fetch request, such as custom headers or query parameters.
427431
*
@@ -444,6 +448,7 @@ export class Sprinter {
444448
* gasLimit: 21000,
445449
* },
446450
* recipient: "0xRecipientAddress", // for sending leftover tokens
451+
* enableSwaps: true, // Enabling swaps on the source chain
447452
* };
448453
*
449454
* sprinter.transferWithHook(settings).then(solution => {
@@ -459,10 +464,11 @@ export class Sprinter {
459464
): Promise<SolutionResponse> {
460465
assert(settings, SingleHopWithContractSchema);
461466

462-
const { sourceChains, amount, ...data } = settings;
467+
const { sourceChains, amount, enableSwaps = false, ...data } = settings;
463468
return await getContractCallSolution(
464469
{
465470
...data,
471+
enableSwaps,
466472
amount: BigInt(amount),
467473
whitelistedSourceChains: sourceChains,
468474
} as SolutionOptions,

packages/sdk/src/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ export interface ContractCallSolutionOptions {
5959
export interface SingleHopContractSolutionOptions extends SolutionOptions {
6060
recipient?: Address;
6161
contractCall?: ContractCallSolutionOptions;
62+
enableSwaps?: boolean;
6263
}
6364

6465
export interface ContractSolutionOptions extends SolutionOptions {

0 commit comments

Comments
 (0)