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,163 +0,0 @@
1
- import { getThirdwebBaseUrl } from "../utils/domains.js";
2
- import { getClientFetch } from "../utils/fetch.js";
3
- import { ApiError } from "./types/Errors.js";
4
- /**
5
- * Retrieves supported Bridge routes based on the provided filters.
6
- *
7
- * When multiple filters are specified, a route must satisfy all filters to be included (it acts as an AND operator).
8
- *
9
- * @example
10
- * ```typescript
11
- * import { Bridge } from "thirdweb";
12
- *
13
- * const routes = await Bridge.routes({
14
- * client: thirdwebClient,
15
- * });
16
- * ```
17
- *
18
- * Returned routes might look something like:
19
- * ```typescript
20
- * [
21
- * {
22
- * destinationToken: {
23
- * address: "0x12c88a3C30A7AaBC1dd7f2c08a97145F5DCcD830",
24
- * chainId: 1,
25
- * decimals: 18,
26
- * iconUri: "https://assets.coingecko.com/coins/images/37207/standard/G.jpg",
27
- * name: "G7",
28
- * symbol: "G7",
29
- * },
30
- * originToken: {
31
- * address: "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE",
32
- * chainId: 480,
33
- * decimals: 18,
34
- * iconUri: "https://assets.relay.link/icons/1/light.png",
35
- * name: "Ether",
36
- * symbol: "ETH",
37
- * }
38
- * },
39
- * {
40
- * destinationToken: {
41
- * address: "0x4d224452801ACEd8B2F0aebE155379bb5D594381",
42
- * chainId: 1,
43
- * decimals: 18,
44
- * iconUri: "https://coin-images.coingecko.com/coins/images/24383/large/apecoin.jpg?1696523566",
45
- * name: "ApeCoin",
46
- * symbol: "APE",
47
- * },
48
- * originToken: {
49
- * address: "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE",
50
- * chainId: 480,
51
- * decimals: 18,
52
- * iconUri: "https://assets.relay.link/icons/1/light.png",
53
- * name: "Ether",
54
- * symbol: "ETH",
55
- * }
56
- * }
57
- * ]
58
- * ```
59
- *
60
- * You can filter for specific chains or tokens:
61
- * ```typescript
62
- * import { Bridge } from "thirdweb";
63
- *
64
- * // Get all routes starting from mainnet ETH
65
- * const routes = await Bridge.routes({
66
- * originChainId: 1,
67
- * originTokenAddress: "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE",
68
- * client: thirdwebClient,
69
- * });
70
- * ```
71
- *
72
- * The returned routes will be limited based on the API. You can paginate through the results using the `limit` and `offset` parameters:
73
- * ```typescript
74
- * import { Bridge } from "thirdweb";
75
- *
76
- * // Get the first 10 routes starting from mainnet ETH
77
- * const routes = await Bridge.routes({
78
- * originChainId: 1,
79
- * originTokenAddress: "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE",
80
- * limit: 10,
81
- * offset: 0,
82
- * client: thirdwebClient,
83
- * });
84
- * ```
85
- *
86
- * You can sort the returned routes by `popularity`:
87
- * ```ts
88
- * import { Bridge } from "thirdweb";
89
- *
90
- * // Get the 10 most popular routes starting from mainnet ETH
91
- * const routes = await Bridge.routes({
92
- * originChainId: 1,
93
- * originTokenAddress: "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE",
94
- * limit: 10,
95
- * offset: 0,
96
- * sortBy: "popularity",
97
- * client: thirdwebClient,
98
- * });
99
- * ```
100
- *
101
- * @param options - The options for the quote.
102
- * @param options.client - Your thirdweb client.
103
- * @param options.originChainId - Filter by a specific origin chain ID.
104
- * @param options.originTokenAddress - Filter by a specific origin token address.
105
- * @param options.destinationChainId - Filter by a specific destination chain ID.
106
- * @param options.destinationTokenAddress - Filter by a specific destination token address.
107
- * @param options.transactionHash - Filter by a specific transaction hash.
108
- * @param options.maxSteps - Limit the number of steps returned.
109
- * @param options.sortBy - Sort the routes by various categories.
110
- * @param options.limit - Limit the number of routes returned.
111
- * @param options.offset - Offset the number of routes returned.
112
- *
113
- * @returns A promise that resolves to an array of routes.
114
- *
115
- * @throws Will throw an error if there is an issue fetching the routes.
116
- * @bridge
117
- * @beta
118
- */
119
- export async function routes(options) {
120
- const { client, originChainId, originTokenAddress, destinationChainId, destinationTokenAddress, maxSteps, sortBy, limit, offset, includePrices, } = options;
121
- const clientFetch = getClientFetch(client);
122
- const url = new URL(`${getThirdwebBaseUrl("bridge")}/v1/routes`);
123
- if (originChainId) {
124
- url.searchParams.set("originChainId", originChainId.toString());
125
- }
126
- if (originTokenAddress) {
127
- url.searchParams.set("originTokenAddress", originTokenAddress);
128
- }
129
- if (destinationChainId) {
130
- url.searchParams.set("destinationChainId", destinationChainId.toString());
131
- }
132
- if (destinationTokenAddress) {
133
- url.searchParams.set("destinationTokenAddress", destinationTokenAddress);
134
- }
135
- if (maxSteps) {
136
- url.searchParams.set("maxSteps", maxSteps.toString());
137
- }
138
- if (limit) {
139
- url.searchParams.set("limit", limit.toString());
140
- }
141
- if (offset) {
142
- url.searchParams.set("offset", offset.toString());
143
- }
144
- if (sortBy) {
145
- url.searchParams.set("sortBy", sortBy);
146
- }
147
- if (includePrices) {
148
- url.searchParams.set("includePrices", includePrices.toString());
149
- }
150
- const response = await clientFetch(url.toString());
151
- if (!response.ok) {
152
- const errorJson = await response.json();
153
- throw new ApiError({
154
- code: errorJson.code || "UNKNOWN_ERROR",
155
- correlationId: errorJson.correlationId || undefined,
156
- message: errorJson.message || response.statusText,
157
- statusCode: response.status,
158
- });
159
- }
160
- const { data } = await response.json();
161
- return data;
162
- }
163
- //# sourceMappingURL=Routes.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"Routes.js","sourceRoot":"","sources":["../../../src/bridge/Routes.ts"],"names":[],"mappings":"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"}
@@ -1,58 +0,0 @@
1
- import { useQuery } from "@tanstack/react-query";
2
- import { routes } from "../../../bridge/Routes.js";
3
- import { ApiError } from "../../../bridge/types/Errors.js";
4
- import { mapBridgeError } from "../errors/mapBridgeError.js";
5
- /**
6
- * Hook that fetches available bridge routes with caching and retry logic
7
- *
8
- * @param params - Parameters for fetching routes including client and filter options
9
- * @returns React Query result with routes data, loading state, and error handling
10
- *
11
- * @example
12
- * ```tsx
13
- * const { data: routes, isLoading, error } = useBridgeRoutes({
14
- * client: thirdwebClient,
15
- * originChainId: 1,
16
- * destinationChainId: 137,
17
- * originTokenAddress: "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE"
18
- * });
19
- * ```
20
- */
21
- export function useBridgeRoutes(params) {
22
- const { enabled = true, ...routeParams } = params;
23
- return useQuery({
24
- enabled: enabled && !!routeParams.client,
25
- gcTime: 10 * 60 * 1000,
26
- queryFn: () => routes(routeParams),
27
- queryKey: [
28
- "bridge-routes",
29
- {
30
- destinationChainId: routeParams.destinationChainId,
31
- destinationTokenAddress: routeParams.destinationTokenAddress,
32
- limit: routeParams.limit,
33
- maxSteps: routeParams.maxSteps,
34
- offset: routeParams.offset,
35
- originChainId: routeParams.originChainId,
36
- originTokenAddress: routeParams.originTokenAddress,
37
- sortBy: routeParams.sortBy,
38
- },
39
- ], // 5 minutes - routes are relatively stable
40
- retry: (failureCount, error) => {
41
- // Handle both ApiError and generic Error instances
42
- if (error instanceof ApiError) {
43
- const bridgeError = mapBridgeError(error);
44
- // Don't retry on client-side errors (4xx)
45
- if (bridgeError.statusCode &&
46
- bridgeError.statusCode >= 400 &&
47
- bridgeError.statusCode < 500) {
48
- return false;
49
- }
50
- }
51
- // Retry up to 3 times for server errors or network issues
52
- return failureCount < 3;
53
- }, // 10 minutes garbage collection
54
- retryDelay: (attemptIndex) => Math.min(1000 * 2 ** attemptIndex, 30000),
55
- staleTime: 5 * 60 * 1000, // Exponential backoff, max 30s
56
- });
57
- }
58
- //# sourceMappingURL=useBridgeRoutes.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"useBridgeRoutes.js","sourceRoot":"","sources":["../../../../../src/react/core/hooks/useBridgeRoutes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAEjD,OAAO,EAAE,MAAM,EAAE,MAAM,2BAA2B,CAAC;AACnD,OAAO,EAAE,QAAQ,EAAE,MAAM,iCAAiC,CAAC;AAC3D,OAAO,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAa7D;;;;;;;;;;;;;;;GAeG;AACH,MAAM,UAAU,eAAe,CAAC,MAA6B;IAC3D,MAAM,EAAE,OAAO,GAAG,IAAI,EAAE,GAAG,WAAW,EAAE,GAAG,MAAM,CAAC;IAElD,OAAO,QAAQ,CAAC;QACd,OAAO,EAAE,OAAO,IAAI,CAAC,CAAC,WAAW,CAAC,MAAM;QACxC,MAAM,EAAE,EAAE,GAAG,EAAE,GAAG,IAAI;QACtB,OAAO,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,WAAW,CAAC;QAClC,QAAQ,EAAE;YACR,eAAe;YACf;gBACE,kBAAkB,EAAE,WAAW,CAAC,kBAAkB;gBAClD,uBAAuB,EAAE,WAAW,CAAC,uBAAuB;gBAC5D,KAAK,EAAE,WAAW,CAAC,KAAK;gBACxB,QAAQ,EAAE,WAAW,CAAC,QAAQ;gBAC9B,MAAM,EAAE,WAAW,CAAC,MAAM;gBAC1B,aAAa,EAAE,WAAW,CAAC,aAAa;gBACxC,kBAAkB,EAAE,WAAW,CAAC,kBAAkB;gBAClD,MAAM,EAAE,WAAW,CAAC,MAAM;aAC3B;SACF,EAAE,2CAA2C;QAC9C,KAAK,EAAE,CAAC,YAAY,EAAE,KAAK,EAAE,EAAE;YAC7B,mDAAmD;YACnD,IAAI,KAAK,YAAY,QAAQ,EAAE,CAAC;gBAC9B,MAAM,WAAW,GAAG,cAAc,CAAC,KAAK,CAAC,CAAC;gBAE1C,0CAA0C;gBAC1C,IACE,WAAW,CAAC,UAAU;oBACtB,WAAW,CAAC,UAAU,IAAI,GAAG;oBAC7B,WAAW,CAAC,UAAU,GAAG,GAAG,EAC5B,CAAC;oBACD,OAAO,KAAK,CAAC;gBACf,CAAC;YACH,CAAC;YAED,0DAA0D;YAC1D,OAAO,YAAY,GAAG,CAAC,CAAC;QAC1B,CAAC,EAAE,gCAAgC;QACnC,UAAU,EAAE,CAAC,YAAY,EAAE,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,GAAG,CAAC,IAAI,YAAY,EAAE,KAAK,CAAC;QACvE,SAAS,EAAE,CAAC,GAAG,EAAE,GAAG,IAAI,EAAE,+BAA+B;KAC1D,CAAC,CAAC;AACL,CAAC"}
@@ -1,166 +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 type { Route } from "./types/Route.js";
4
- /**
5
- * Retrieves supported Bridge routes based on the provided filters.
6
- *
7
- * When multiple filters are specified, a route must satisfy all filters to be included (it acts as an AND operator).
8
- *
9
- * @example
10
- * ```typescript
11
- * import { Bridge } from "thirdweb";
12
- *
13
- * const routes = await Bridge.routes({
14
- * client: thirdwebClient,
15
- * });
16
- * ```
17
- *
18
- * Returned routes might look something like:
19
- * ```typescript
20
- * [
21
- * {
22
- * destinationToken: {
23
- * address: "0x12c88a3C30A7AaBC1dd7f2c08a97145F5DCcD830",
24
- * chainId: 1,
25
- * decimals: 18,
26
- * iconUri: "https://assets.coingecko.com/coins/images/37207/standard/G.jpg",
27
- * name: "G7",
28
- * symbol: "G7",
29
- * },
30
- * originToken: {
31
- * address: "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE",
32
- * chainId: 480,
33
- * decimals: 18,
34
- * iconUri: "https://assets.relay.link/icons/1/light.png",
35
- * name: "Ether",
36
- * symbol: "ETH",
37
- * }
38
- * },
39
- * {
40
- * destinationToken: {
41
- * address: "0x4d224452801ACEd8B2F0aebE155379bb5D594381",
42
- * chainId: 1,
43
- * decimals: 18,
44
- * iconUri: "https://coin-images.coingecko.com/coins/images/24383/large/apecoin.jpg?1696523566",
45
- * name: "ApeCoin",
46
- * symbol: "APE",
47
- * },
48
- * originToken: {
49
- * address: "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE",
50
- * chainId: 480,
51
- * decimals: 18,
52
- * iconUri: "https://assets.relay.link/icons/1/light.png",
53
- * name: "Ether",
54
- * symbol: "ETH",
55
- * }
56
- * }
57
- * ]
58
- * ```
59
- *
60
- * You can filter for specific chains or tokens:
61
- * ```typescript
62
- * import { Bridge } from "thirdweb";
63
- *
64
- * // Get all routes starting from mainnet ETH
65
- * const routes = await Bridge.routes({
66
- * originChainId: 1,
67
- * originTokenAddress: "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE",
68
- * client: thirdwebClient,
69
- * });
70
- * ```
71
- *
72
- * The returned routes will be limited based on the API. You can paginate through the results using the `limit` and `offset` parameters:
73
- * ```typescript
74
- * import { Bridge } from "thirdweb";
75
- *
76
- * // Get the first 10 routes starting from mainnet ETH
77
- * const routes = await Bridge.routes({
78
- * originChainId: 1,
79
- * originTokenAddress: "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE",
80
- * limit: 10,
81
- * offset: 0,
82
- * client: thirdwebClient,
83
- * });
84
- * ```
85
- *
86
- * You can sort the returned routes by `popularity`:
87
- * ```ts
88
- * import { Bridge } from "thirdweb";
89
- *
90
- * // Get the 10 most popular routes starting from mainnet ETH
91
- * const routes = await Bridge.routes({
92
- * originChainId: 1,
93
- * originTokenAddress: "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE",
94
- * limit: 10,
95
- * offset: 0,
96
- * sortBy: "popularity",
97
- * client: thirdwebClient,
98
- * });
99
- * ```
100
- *
101
- * @param options - The options for the quote.
102
- * @param options.client - Your thirdweb client.
103
- * @param options.originChainId - Filter by a specific origin chain ID.
104
- * @param options.originTokenAddress - Filter by a specific origin token address.
105
- * @param options.destinationChainId - Filter by a specific destination chain ID.
106
- * @param options.destinationTokenAddress - Filter by a specific destination token address.
107
- * @param options.transactionHash - Filter by a specific transaction hash.
108
- * @param options.maxSteps - Limit the number of steps returned.
109
- * @param options.sortBy - Sort the routes by various categories.
110
- * @param options.limit - Limit the number of routes returned.
111
- * @param options.offset - Offset the number of routes returned.
112
- *
113
- * @returns A promise that resolves to an array of routes.
114
- *
115
- * @throws Will throw an error if there is an issue fetching the routes.
116
- * @bridge
117
- * @beta
118
- */
119
- export declare function routes(options: routes.Options): Promise<routes.Result>;
120
- /**
121
- * Namespace containing types for the routes function.
122
- * @namespace routes
123
- * @bridge
124
- */
125
- export declare namespace routes {
126
- /**
127
- * Options for fetching available bridge routes.
128
- * @interface Options
129
- * @bridge
130
- */
131
- type Options = {
132
- /** Your thirdweb client */
133
- client: ThirdwebClient;
134
- /** The origin chain ID to filter routes by */
135
- originChainId?: number;
136
- /** The origin token address to filter routes by */
137
- originTokenAddress?: ox__Address.Address;
138
- /** The destination chain ID to filter routes by */
139
- destinationChainId?: number;
140
- /** The destination token address to filter routes by */
141
- destinationTokenAddress?: ox__Address.Address;
142
- /** Transaction hash to filter routes by */
143
- transactionHash?: ox__Hex.Hex;
144
- /**
145
- * Sort routes by popularity
146
- * @deprecated
147
- */
148
- sortBy?: "popularity";
149
- /** Maximum number of steps in the route */
150
- maxSteps?: number;
151
- /** Whether to include price information in the response */
152
- includePrices?: boolean;
153
- /** Number of results to return (pagination) */
154
- limit?: number;
155
- /** Number of results to skip (pagination) */
156
- offset?: number;
157
- };
158
- /**
159
- * Result returned from fetching bridge routes.
160
- * Contains an array of available routes.
161
- * @interface Result
162
- * @bridge
163
- */
164
- type Result = Route[];
165
- }
166
- //# sourceMappingURL=Routes.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"Routes.d.ts","sourceRoot":"","sources":["../../../src/bridge/Routes.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,IAAI,WAAW,EAAE,GAAG,IAAI,OAAO,EAAE,MAAM,IAAI,CAAC;AACjE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAI1D,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AAE9C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkHG;AACH,wBAAsB,MAAM,CAAC,OAAO,EAAE,MAAM,CAAC,OAAO,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,CAyD5E;AAED;;;;GAIG;AACH,MAAM,CAAC,OAAO,WAAW,MAAM,CAAC;IAC9B;;;;OAIG;IACH,KAAK,OAAO,GAAG;QACb,2BAA2B;QAC3B,MAAM,EAAE,cAAc,CAAC;QACvB,8CAA8C;QAC9C,aAAa,CAAC,EAAE,MAAM,CAAC;QACvB,mDAAmD;QACnD,kBAAkB,CAAC,EAAE,WAAW,CAAC,OAAO,CAAC;QACzC,mDAAmD;QACnD,kBAAkB,CAAC,EAAE,MAAM,CAAC;QAC5B,wDAAwD;QACxD,uBAAuB,CAAC,EAAE,WAAW,CAAC,OAAO,CAAC;QAC9C,2CAA2C;QAC3C,eAAe,CAAC,EAAE,OAAO,CAAC,GAAG,CAAC;QAC9B;;;WAGG;QACH,MAAM,CAAC,EAAE,YAAY,CAAC;QACtB,2CAA2C;QAC3C,QAAQ,CAAC,EAAE,MAAM,CAAC;QAClB,2DAA2D;QAC3D,aAAa,CAAC,EAAE,OAAO,CAAC;QACxB,+CAA+C;QAC/C,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,6CAA6C;QAC7C,MAAM,CAAC,EAAE,MAAM,CAAC;KACjB,CAAC;IAEF;;;;;OAKG;IACH,KAAK,MAAM,GAAG,KAAK,EAAE,CAAC;CACvB"}
@@ -1,29 +0,0 @@
1
- import type { routes as RoutesTypes } from "../../../bridge/Routes.js";
2
- /**
3
- * Parameters for the useBridgeRoutes hook
4
- */
5
- export type UseBridgeRoutesParams = RoutesTypes.Options & {
6
- /**
7
- * Whether to enable the query. Useful for conditional fetching.
8
- * @default true
9
- */
10
- enabled?: boolean;
11
- };
12
- /**
13
- * Hook that fetches available bridge routes with caching and retry logic
14
- *
15
- * @param params - Parameters for fetching routes including client and filter options
16
- * @returns React Query result with routes data, loading state, and error handling
17
- *
18
- * @example
19
- * ```tsx
20
- * const { data: routes, isLoading, error } = useBridgeRoutes({
21
- * client: thirdwebClient,
22
- * originChainId: 1,
23
- * destinationChainId: 137,
24
- * originTokenAddress: "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE"
25
- * });
26
- * ```
27
- */
28
- export declare function useBridgeRoutes(params: UseBridgeRoutesParams): import("@tanstack/react-query").UseQueryResult<RoutesTypes.Result, Error>;
29
- //# sourceMappingURL=useBridgeRoutes.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"useBridgeRoutes.d.ts","sourceRoot":"","sources":["../../../../../src/react/core/hooks/useBridgeRoutes.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,IAAI,WAAW,EAAE,MAAM,2BAA2B,CAAC;AAKvE;;GAEG;AACH,MAAM,MAAM,qBAAqB,GAAG,WAAW,CAAC,OAAO,GAAG;IACxD;;;OAGG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB,CAAC;AAEF;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE,qBAAqB,6EAyC5D"}
@@ -1,161 +0,0 @@
1
- import { http, passthrough } from "msw";
2
- import { setupServer } from "msw/node";
3
- import { afterAll, afterEach, beforeAll, describe, expect, it } from "vitest";
4
- import { TEST_CLIENT } from "~test/test-clients.js";
5
- import { routes } from "./Routes.js";
6
-
7
- const server = setupServer(
8
- http.get("https://bridge.thirdweb.com/v1/routes", () => {
9
- passthrough();
10
- }),
11
- );
12
-
13
- describe.runIf(process.env.TW_SECRET_KEY)("Bridge.routes", () => {
14
- beforeAll(() => server.listen());
15
- afterEach(() => server.resetHandlers());
16
- afterAll(() => server.close());
17
-
18
- it("should get a valid list of routes", async () => {
19
- const allRoutes = await routes({
20
- client: TEST_CLIENT,
21
- });
22
-
23
- expect(allRoutes).toBeDefined();
24
- expect(Array.isArray(allRoutes)).toBe(true);
25
- });
26
-
27
- it("should filter routes by origin chain", async () => {
28
- const filteredRoutes = await routes({
29
- client: TEST_CLIENT,
30
- originChainId: 1,
31
- });
32
-
33
- expect(filteredRoutes).toBeDefined();
34
- expect(Array.isArray(filteredRoutes)).toBe(true);
35
- expect(
36
- filteredRoutes.every((route) => route.originToken.chainId === 1),
37
- ).toBe(true);
38
- });
39
-
40
- it("should filter routes by destination chain", async () => {
41
- const filteredRoutes = await routes({
42
- client: TEST_CLIENT,
43
- destinationChainId: 1,
44
- });
45
-
46
- expect(filteredRoutes).toBeDefined();
47
- expect(Array.isArray(filteredRoutes)).toBe(true);
48
- expect(
49
- filteredRoutes.every((route) => route.destinationToken.chainId === 1),
50
- ).toBe(true);
51
- });
52
-
53
- it("should filter routes by origin token", async () => {
54
- const filteredRoutes = await routes({
55
- client: TEST_CLIENT,
56
- originTokenAddress: "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE",
57
- });
58
-
59
- expect(filteredRoutes).toBeDefined();
60
- expect(Array.isArray(filteredRoutes)).toBe(true);
61
- expect(
62
- filteredRoutes.every(
63
- (route) =>
64
- route.originToken.address ===
65
- "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE",
66
- ),
67
- ).toBe(true);
68
- });
69
-
70
- it("should filter routes by destination token", async () => {
71
- const filteredRoutes = await routes({
72
- client: TEST_CLIENT,
73
- destinationTokenAddress: "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE",
74
- });
75
-
76
- expect(filteredRoutes).toBeDefined();
77
- expect(Array.isArray(filteredRoutes)).toBe(true);
78
- expect(
79
- filteredRoutes.every(
80
- (route) =>
81
- route.destinationToken.address ===
82
- "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE",
83
- ),
84
- ).toBe(true);
85
- });
86
-
87
- it("should combine filters", async () => {
88
- const filteredRoutes = await routes({
89
- client: TEST_CLIENT,
90
- destinationChainId: 10,
91
- destinationTokenAddress: "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE",
92
- originChainId: 1,
93
- originTokenAddress: "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE",
94
- });
95
-
96
- expect(filteredRoutes).toBeDefined();
97
- expect(Array.isArray(filteredRoutes)).toBe(true);
98
- expect(filteredRoutes.length).toBeGreaterThan(0);
99
- expect(
100
- filteredRoutes.every(
101
- (route) =>
102
- route.originToken.chainId === 1 &&
103
- route.destinationToken.chainId === 10 &&
104
- route.originToken.address ===
105
- "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE" &&
106
- route.destinationToken.address ===
107
- "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE",
108
- ),
109
- ).toBe(true);
110
- });
111
-
112
- it("should respect limit and offset", async () => {
113
- const page1Routes = await routes({
114
- client: TEST_CLIENT,
115
- limit: 1,
116
- offset: 1,
117
- });
118
-
119
- expect(page1Routes).toBeDefined();
120
- expect(Array.isArray(page1Routes)).toBe(true);
121
- expect(page1Routes.length).toBe(1);
122
-
123
- const page2Routes = await routes({
124
- client: TEST_CLIENT,
125
- limit: 1,
126
- offset: 2,
127
- });
128
-
129
- expect(page2Routes).toBeDefined();
130
- expect(Array.isArray(page2Routes)).toBe(true);
131
- expect(page2Routes.length).toBe(1);
132
-
133
- expect(JSON.stringify(page1Routes)).not.toEqual(
134
- JSON.stringify(page2Routes),
135
- );
136
- });
137
-
138
- it("should surface any errors", async () => {
139
- server.use(
140
- http.get("https://bridge.thirdweb.com/v1/routes", () => {
141
- return Response.json(
142
- {
143
- code: "InvalidRoutesRequest",
144
- message: "The provided request is invalid.",
145
- },
146
- { status: 400 },
147
- );
148
- }),
149
- );
150
-
151
- await expect(
152
- routes({
153
- client: TEST_CLIENT,
154
- limit: 1000,
155
- offset: 1000,
156
- }),
157
- ).rejects.toThrowErrorMatchingInlineSnapshot(
158
- "[Error: The provided request is invalid.]",
159
- );
160
- });
161
- });