thirdweb 5.110.5 → 5.111.0-nightly-8ef418c543b89679286a200175a35c41e98240e2-20251031000344

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (60) hide show
  1. package/dist/cjs/bridge/index.js +1 -3
  2. package/dist/cjs/bridge/index.js.map +1 -1
  3. package/dist/cjs/contract/deployment/zksync/implementations.js +4 -4
  4. package/dist/cjs/exports/contract.js.map +1 -1
  5. package/dist/cjs/exports/extensions/erc20.js +14 -5
  6. package/dist/cjs/exports/extensions/erc20.js.map +1 -1
  7. package/dist/cjs/exports/react.js +2 -4
  8. package/dist/cjs/exports/react.js.map +1 -1
  9. package/dist/cjs/react/core/hooks/transaction/useSendTransaction.js +5 -6
  10. package/dist/cjs/react/core/hooks/transaction/useSendTransaction.js.map +1 -1
  11. package/dist/cjs/version.js +1 -1
  12. package/dist/cjs/version.js.map +1 -1
  13. package/dist/esm/bridge/index.js +0 -1
  14. package/dist/esm/bridge/index.js.map +1 -1
  15. package/dist/esm/contract/deployment/zksync/implementations.js +4 -4
  16. package/dist/esm/exports/contract.js.map +1 -1
  17. package/dist/esm/exports/extensions/erc20.js +10 -4
  18. package/dist/esm/exports/extensions/erc20.js.map +1 -1
  19. package/dist/esm/exports/react.js +0 -1
  20. package/dist/esm/exports/react.js.map +1 -1
  21. package/dist/esm/react/core/hooks/transaction/useSendTransaction.js +5 -6
  22. package/dist/esm/react/core/hooks/transaction/useSendTransaction.js.map +1 -1
  23. package/dist/esm/version.js +1 -1
  24. package/dist/esm/version.js.map +1 -1
  25. package/dist/scripts/bridge-widget.js +112 -111
  26. package/dist/types/bridge/index.d.ts +0 -1
  27. package/dist/types/bridge/index.d.ts.map +1 -1
  28. package/dist/types/exports/contract.d.ts +1 -0
  29. package/dist/types/exports/contract.d.ts.map +1 -1
  30. package/dist/types/exports/extensions/erc20.d.ts +9 -3
  31. package/dist/types/exports/extensions/erc20.d.ts.map +1 -1
  32. package/dist/types/exports/react.d.ts +0 -1
  33. package/dist/types/exports/react.d.ts.map +1 -1
  34. package/dist/types/react/core/hooks/transaction/useSendTransaction.d.ts.map +1 -1
  35. package/dist/types/version.d.ts +1 -1
  36. package/dist/types/version.d.ts.map +1 -1
  37. package/package.json +4 -4
  38. package/src/bridge/index.ts +0 -1
  39. package/src/contract/deployment/zksync/implementations.ts +4 -4
  40. package/src/exports/contract.ts +2 -0
  41. package/src/exports/extensions/erc20.ts +10 -4
  42. package/src/exports/react.ts +0 -4
  43. package/src/react/core/hooks/transaction/useSendTransaction.ts +5 -8
  44. package/src/version.ts +1 -1
  45. package/dist/cjs/bridge/Routes.js +0 -166
  46. package/dist/cjs/bridge/Routes.js.map +0 -1
  47. package/dist/cjs/react/core/hooks/useBridgeRoutes.js +0 -61
  48. package/dist/cjs/react/core/hooks/useBridgeRoutes.js.map +0 -1
  49. package/dist/esm/bridge/Routes.js +0 -163
  50. package/dist/esm/bridge/Routes.js.map +0 -1
  51. package/dist/esm/react/core/hooks/useBridgeRoutes.js +0 -58
  52. package/dist/esm/react/core/hooks/useBridgeRoutes.js.map +0 -1
  53. package/dist/types/bridge/Routes.d.ts +0 -166
  54. package/dist/types/bridge/Routes.d.ts.map +0 -1
  55. package/dist/types/react/core/hooks/useBridgeRoutes.d.ts +0 -29
  56. package/dist/types/react/core/hooks/useBridgeRoutes.d.ts.map +0 -1
  57. package/src/bridge/Routes.test.ts +0 -161
  58. package/src/bridge/Routes.ts +0 -228
  59. package/src/react/core/hooks/useBridgeRoutes.test.ts +0 -137
  60. package/src/react/core/hooks/useBridgeRoutes.ts +0 -75
@@ -1,228 +0,0 @@
1
- import type { Address as ox__Address, Hex as ox__Hex } from "ox";
2
- import type { ThirdwebClient } from "../client/client.js";
3
- import { getThirdwebBaseUrl } from "../utils/domains.js";
4
- import { getClientFetch } from "../utils/fetch.js";
5
- import { ApiError } from "./types/Errors.js";
6
- import type { Route } from "./types/Route.js";
7
-
8
- /**
9
- * Retrieves supported Bridge routes based on the provided filters.
10
- *
11
- * When multiple filters are specified, a route must satisfy all filters to be included (it acts as an AND operator).
12
- *
13
- * @example
14
- * ```typescript
15
- * import { Bridge } from "thirdweb";
16
- *
17
- * const routes = await Bridge.routes({
18
- * client: thirdwebClient,
19
- * });
20
- * ```
21
- *
22
- * Returned routes might look something like:
23
- * ```typescript
24
- * [
25
- * {
26
- * destinationToken: {
27
- * address: "0x12c88a3C30A7AaBC1dd7f2c08a97145F5DCcD830",
28
- * chainId: 1,
29
- * decimals: 18,
30
- * iconUri: "https://assets.coingecko.com/coins/images/37207/standard/G.jpg",
31
- * name: "G7",
32
- * symbol: "G7",
33
- * },
34
- * originToken: {
35
- * address: "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE",
36
- * chainId: 480,
37
- * decimals: 18,
38
- * iconUri: "https://assets.relay.link/icons/1/light.png",
39
- * name: "Ether",
40
- * symbol: "ETH",
41
- * }
42
- * },
43
- * {
44
- * destinationToken: {
45
- * address: "0x4d224452801ACEd8B2F0aebE155379bb5D594381",
46
- * chainId: 1,
47
- * decimals: 18,
48
- * iconUri: "https://coin-images.coingecko.com/coins/images/24383/large/apecoin.jpg?1696523566",
49
- * name: "ApeCoin",
50
- * symbol: "APE",
51
- * },
52
- * originToken: {
53
- * address: "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE",
54
- * chainId: 480,
55
- * decimals: 18,
56
- * iconUri: "https://assets.relay.link/icons/1/light.png",
57
- * name: "Ether",
58
- * symbol: "ETH",
59
- * }
60
- * }
61
- * ]
62
- * ```
63
- *
64
- * You can filter for specific chains or tokens:
65
- * ```typescript
66
- * import { Bridge } from "thirdweb";
67
- *
68
- * // Get all routes starting from mainnet ETH
69
- * const routes = await Bridge.routes({
70
- * originChainId: 1,
71
- * originTokenAddress: "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE",
72
- * client: thirdwebClient,
73
- * });
74
- * ```
75
- *
76
- * The returned routes will be limited based on the API. You can paginate through the results using the `limit` and `offset` parameters:
77
- * ```typescript
78
- * import { Bridge } from "thirdweb";
79
- *
80
- * // Get the first 10 routes starting from mainnet ETH
81
- * const routes = await Bridge.routes({
82
- * originChainId: 1,
83
- * originTokenAddress: "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE",
84
- * limit: 10,
85
- * offset: 0,
86
- * client: thirdwebClient,
87
- * });
88
- * ```
89
- *
90
- * You can sort the returned routes by `popularity`:
91
- * ```ts
92
- * import { Bridge } from "thirdweb";
93
- *
94
- * // Get the 10 most popular routes starting from mainnet ETH
95
- * const routes = await Bridge.routes({
96
- * originChainId: 1,
97
- * originTokenAddress: "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE",
98
- * limit: 10,
99
- * offset: 0,
100
- * sortBy: "popularity",
101
- * client: thirdwebClient,
102
- * });
103
- * ```
104
- *
105
- * @param options - The options for the quote.
106
- * @param options.client - Your thirdweb client.
107
- * @param options.originChainId - Filter by a specific origin chain ID.
108
- * @param options.originTokenAddress - Filter by a specific origin token address.
109
- * @param options.destinationChainId - Filter by a specific destination chain ID.
110
- * @param options.destinationTokenAddress - Filter by a specific destination token address.
111
- * @param options.transactionHash - Filter by a specific transaction hash.
112
- * @param options.maxSteps - Limit the number of steps returned.
113
- * @param options.sortBy - Sort the routes by various categories.
114
- * @param options.limit - Limit the number of routes returned.
115
- * @param options.offset - Offset the number of routes returned.
116
- *
117
- * @returns A promise that resolves to an array of routes.
118
- *
119
- * @throws Will throw an error if there is an issue fetching the routes.
120
- * @bridge
121
- * @beta
122
- */
123
- export async function routes(options: routes.Options): Promise<routes.Result> {
124
- const {
125
- client,
126
- originChainId,
127
- originTokenAddress,
128
- destinationChainId,
129
- destinationTokenAddress,
130
- maxSteps,
131
- sortBy,
132
- limit,
133
- offset,
134
- includePrices,
135
- } = options;
136
-
137
- const clientFetch = getClientFetch(client);
138
- const url = new URL(`${getThirdwebBaseUrl("bridge")}/v1/routes`);
139
- if (originChainId) {
140
- url.searchParams.set("originChainId", originChainId.toString());
141
- }
142
- if (originTokenAddress) {
143
- url.searchParams.set("originTokenAddress", originTokenAddress);
144
- }
145
- if (destinationChainId) {
146
- url.searchParams.set("destinationChainId", destinationChainId.toString());
147
- }
148
- if (destinationTokenAddress) {
149
- url.searchParams.set("destinationTokenAddress", destinationTokenAddress);
150
- }
151
- if (maxSteps) {
152
- url.searchParams.set("maxSteps", maxSteps.toString());
153
- }
154
- if (limit) {
155
- url.searchParams.set("limit", limit.toString());
156
- }
157
- if (offset) {
158
- url.searchParams.set("offset", offset.toString());
159
- }
160
- if (sortBy) {
161
- url.searchParams.set("sortBy", sortBy);
162
- }
163
- if (includePrices) {
164
- url.searchParams.set("includePrices", includePrices.toString());
165
- }
166
-
167
- const response = await clientFetch(url.toString());
168
- if (!response.ok) {
169
- const errorJson = await response.json();
170
- throw new ApiError({
171
- code: errorJson.code || "UNKNOWN_ERROR",
172
- correlationId: errorJson.correlationId || undefined,
173
- message: errorJson.message || response.statusText,
174
- statusCode: response.status,
175
- });
176
- }
177
-
178
- const { data }: { data: Route[] } = await response.json();
179
- return data;
180
- }
181
-
182
- /**
183
- * Namespace containing types for the routes function.
184
- * @namespace routes
185
- * @bridge
186
- */
187
- export declare namespace routes {
188
- /**
189
- * Options for fetching available bridge routes.
190
- * @interface Options
191
- * @bridge
192
- */
193
- type Options = {
194
- /** Your thirdweb client */
195
- client: ThirdwebClient;
196
- /** The origin chain ID to filter routes by */
197
- originChainId?: number;
198
- /** The origin token address to filter routes by */
199
- originTokenAddress?: ox__Address.Address;
200
- /** The destination chain ID to filter routes by */
201
- destinationChainId?: number;
202
- /** The destination token address to filter routes by */
203
- destinationTokenAddress?: ox__Address.Address;
204
- /** Transaction hash to filter routes by */
205
- transactionHash?: ox__Hex.Hex;
206
- /**
207
- * Sort routes by popularity
208
- * @deprecated
209
- */
210
- sortBy?: "popularity";
211
- /** Maximum number of steps in the route */
212
- maxSteps?: number;
213
- /** Whether to include price information in the response */
214
- includePrices?: boolean;
215
- /** Number of results to return (pagination) */
216
- limit?: number;
217
- /** Number of results to skip (pagination) */
218
- offset?: number;
219
- };
220
-
221
- /**
222
- * Result returned from fetching bridge routes.
223
- * Contains an array of available routes.
224
- * @interface Result
225
- * @bridge
226
- */
227
- type Result = Route[];
228
- }
@@ -1,137 +0,0 @@
1
- import {
2
- beforeEach,
3
- describe,
4
- expect,
5
- it,
6
- type MockedFunction,
7
- vi,
8
- } from "vitest";
9
- import { routes } from "../../../bridge/Routes.js";
10
- import { ApiError } from "../../../bridge/types/Errors.js";
11
- import type { Route } from "../../../bridge/types/Route.js";
12
- import type { ThirdwebClient } from "../../../client/client.js";
13
- import type { UseBridgeRoutesParams } from "./useBridgeRoutes.js";
14
-
15
- // Mock the Bridge routes function
16
- vi.mock("../../../bridge/Routes.js", () => ({
17
- routes: vi.fn(),
18
- }));
19
-
20
- const mockRoutes = routes as MockedFunction<typeof routes>;
21
-
22
- // Mock client
23
- const mockClient = { clientId: "test" } as ThirdwebClient;
24
-
25
- // Mock route data
26
- const mockRouteData: Route[] = [
27
- {
28
- destinationToken: {
29
- address: "0x7ceB23fD6bC0adD59E62ac25578270cFf1b9f619",
30
- chainId: 137,
31
- decimals: 18,
32
- name: "Wrapped Ethereum",
33
- priceUsd: 2000.0,
34
- symbol: "WETH",
35
- },
36
- originToken: {
37
- address: "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE",
38
- chainId: 1,
39
- decimals: 18,
40
- name: "Ethereum",
41
- priceUsd: 2000.0,
42
- symbol: "ETH",
43
- },
44
- },
45
- ];
46
-
47
- describe("useBridgeRoutes", () => {
48
- beforeEach(() => {
49
- vi.clearAllMocks();
50
- });
51
-
52
- it("should export correct hook parameters type", () => {
53
- // Type-only test to verify UseBridgeRoutesParams interface
54
- const params: UseBridgeRoutesParams = {
55
- client: mockClient,
56
- destinationChainId: 137,
57
- enabled: true,
58
- originChainId: 1,
59
- };
60
-
61
- expect(params).toBeDefined();
62
- expect(params.client).toBe(mockClient);
63
- expect(params.originChainId).toBe(1);
64
- expect(params.destinationChainId).toBe(137);
65
- expect(params.enabled).toBe(true);
66
- });
67
-
68
- it("should handle different parameter combinations", () => {
69
- const fullParams: UseBridgeRoutesParams = {
70
- client: mockClient,
71
- destinationChainId: 137,
72
- destinationTokenAddress: "0x7ceB23fD6bC0adD59E62ac25578270cFf1b9f619",
73
- enabled: false,
74
- limit: 10,
75
- maxSteps: 3,
76
- offset: 0,
77
- originChainId: 1,
78
- originTokenAddress: "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE",
79
- sortBy: "popularity",
80
- };
81
-
82
- expect(fullParams).toBeDefined();
83
- expect(fullParams.sortBy).toBe("popularity");
84
- expect(fullParams.maxSteps).toBe(3);
85
- expect(fullParams.limit).toBe(10);
86
- expect(fullParams.offset).toBe(0);
87
- });
88
-
89
- it("should have optional enabled parameter defaulting to true", () => {
90
- const paramsWithoutEnabled: UseBridgeRoutesParams = {
91
- client: mockClient,
92
- destinationChainId: 137,
93
- originChainId: 1,
94
- };
95
-
96
- expect(paramsWithoutEnabled.enabled).toBeUndefined(); // Should be optional
97
- });
98
-
99
- it("should validate that Bridge.routes would be called with correct parameters", async () => {
100
- const testParams = {
101
- client: mockClient,
102
- destinationChainId: 137,
103
- originChainId: 1,
104
- originTokenAddress: "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE" as const,
105
- };
106
-
107
- // Mock the routes function to return our test data
108
- mockRoutes.mockResolvedValue(mockRouteData);
109
-
110
- // Directly call the routes function to verify it works with our parameters
111
- const result = await routes(testParams);
112
-
113
- expect(mockRoutes).toHaveBeenCalledWith(testParams);
114
- expect(result).toEqual(mockRouteData);
115
- });
116
-
117
- it("should handle API errors properly", async () => {
118
- const apiError = new ApiError({
119
- code: "INVALID_INPUT",
120
- message: "Invalid parameters",
121
- statusCode: 400,
122
- });
123
-
124
- mockRoutes.mockRejectedValue(apiError);
125
-
126
- try {
127
- await routes({
128
- client: mockClient,
129
- destinationChainId: 137,
130
- originChainId: 1,
131
- });
132
- } catch (error) {
133
- expect(error).toBe(apiError);
134
- expect(error).toBeInstanceOf(ApiError);
135
- }
136
- });
137
- });
@@ -1,75 +0,0 @@
1
- import { useQuery } from "@tanstack/react-query";
2
- import type { routes as RoutesTypes } from "../../../bridge/Routes.js";
3
- import { routes } from "../../../bridge/Routes.js";
4
- import { ApiError } from "../../../bridge/types/Errors.js";
5
- import { mapBridgeError } from "../errors/mapBridgeError.js";
6
-
7
- /**
8
- * Parameters for the useBridgeRoutes hook
9
- */
10
- export type UseBridgeRoutesParams = RoutesTypes.Options & {
11
- /**
12
- * Whether to enable the query. Useful for conditional fetching.
13
- * @default true
14
- */
15
- enabled?: boolean;
16
- };
17
-
18
- /**
19
- * Hook that fetches available bridge routes with caching and retry logic
20
- *
21
- * @param params - Parameters for fetching routes including client and filter options
22
- * @returns React Query result with routes data, loading state, and error handling
23
- *
24
- * @example
25
- * ```tsx
26
- * const { data: routes, isLoading, error } = useBridgeRoutes({
27
- * client: thirdwebClient,
28
- * originChainId: 1,
29
- * destinationChainId: 137,
30
- * originTokenAddress: "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE"
31
- * });
32
- * ```
33
- */
34
- export function useBridgeRoutes(params: UseBridgeRoutesParams) {
35
- const { enabled = true, ...routeParams } = params;
36
-
37
- return useQuery({
38
- enabled: enabled && !!routeParams.client,
39
- gcTime: 10 * 60 * 1000,
40
- queryFn: () => routes(routeParams),
41
- queryKey: [
42
- "bridge-routes",
43
- {
44
- destinationChainId: routeParams.destinationChainId,
45
- destinationTokenAddress: routeParams.destinationTokenAddress,
46
- limit: routeParams.limit,
47
- maxSteps: routeParams.maxSteps,
48
- offset: routeParams.offset,
49
- originChainId: routeParams.originChainId,
50
- originTokenAddress: routeParams.originTokenAddress,
51
- sortBy: routeParams.sortBy,
52
- },
53
- ], // 5 minutes - routes are relatively stable
54
- retry: (failureCount, error) => {
55
- // Handle both ApiError and generic Error instances
56
- if (error instanceof ApiError) {
57
- const bridgeError = mapBridgeError(error);
58
-
59
- // Don't retry on client-side errors (4xx)
60
- if (
61
- bridgeError.statusCode &&
62
- bridgeError.statusCode >= 400 &&
63
- bridgeError.statusCode < 500
64
- ) {
65
- return false;
66
- }
67
- }
68
-
69
- // Retry up to 3 times for server errors or network issues
70
- return failureCount < 3;
71
- }, // 10 minutes garbage collection
72
- retryDelay: (attemptIndex) => Math.min(1000 * 2 ** attemptIndex, 30000),
73
- staleTime: 5 * 60 * 1000, // Exponential backoff, max 30s
74
- });
75
- }