Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add enableSwaps in transferWithHook and transfer #97

Merged
merged 10 commits into from
Dec 11, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
6 changes: 6 additions & 0 deletions packages/react/.prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"useTabs": false,
"singleQuote": false,
"trailingComma": "all",
"printWidth": 80
}
6 changes: 6 additions & 0 deletions packages/sdk/.prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"useTabs": false,
"singleQuote": false,
"trailingComma": "all",
"printWidth": 80
}
4 changes: 4 additions & 0 deletions packages/sdk/src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ export async function getContractSolution(
contractCall,
threshold,
whitelistedSourceChains,
enableSwaps,
Tbaut marked this conversation as resolved.
Show resolved Hide resolved
}: ContractSolutionOptions,
{ baseUrl, signal }: FetchOptions = {},
): Promise<SolutionResponse> {
Expand All @@ -165,6 +166,7 @@ export async function getContractSolution(
type: "fungible",
threshold,
whitelistedSourceChains,
enableSwaps,
}),
}).then(
(response) =>
Expand All @@ -185,6 +187,7 @@ export async function getContractCallSolution(
recipient,
threshold,
whitelistedSourceChains,
enableSwaps,
}: SingleHopContractSolutionOptions,
{ baseUrl, signal }: FetchOptions = {},
): Promise<SolutionResponse> {
Expand All @@ -203,6 +206,7 @@ export async function getContractCallSolution(
recipient,
threshold,
whitelistedSourceChains,
enableSwaps,
}),
}).then(
(response) =>
Expand Down
2 changes: 2 additions & 0 deletions packages/sdk/src/internal/validators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {
array,
assign,
bigint,
boolean,
define,
number,
object,
Expand Down Expand Up @@ -35,6 +36,7 @@ const BridgeCoreSchema = object({
amount: numberLike,
threshold: optional(number()),
sourceChains: optional(array(number())),
enableSwaps: optional(boolean()),
Tbaut marked this conversation as resolved.
Show resolved Hide resolved
});

const BridgeCoreWithRecipientSchema = assign(
Expand Down
10 changes: 8 additions & 2 deletions packages/sdk/src/sprinter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand All @@ -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 => {
Expand All @@ -387,10 +389,11 @@ export class Sprinter {
): Promise<SolutionResponse> {
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,
Expand Down Expand Up @@ -422,6 +425,7 @@ export class Sprinter {
* - `recipient` {string} (optional): The address of the recipient of any leftover tokens.
* - `sourceChains` {Array<number>} (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.
*
Expand All @@ -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 => {
Expand All @@ -459,10 +464,11 @@ export class Sprinter {
): Promise<SolutionResponse> {
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,
Expand Down
1 change: 1 addition & 0 deletions packages/sdk/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export interface SolutionOptions {
amount: NumberLike;
threshold?: number;
whitelistedSourceChains?: ChainID[];
enableSwaps?: boolean;
}

export interface ContractCallSolutionOptions {
Expand Down
Loading