thirdweb 5.110.6 → 5.111.0-nightly-8ef418c543b89679286a200175a35c41e98240e2-20251101000402

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 (45) 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/exports/react.js +2 -4
  4. package/dist/cjs/exports/react.js.map +1 -1
  5. package/dist/cjs/react/core/hooks/transaction/useSendTransaction.js +5 -6
  6. package/dist/cjs/react/core/hooks/transaction/useSendTransaction.js.map +1 -1
  7. package/dist/cjs/version.js +1 -1
  8. package/dist/cjs/version.js.map +1 -1
  9. package/dist/esm/bridge/index.js +0 -1
  10. package/dist/esm/bridge/index.js.map +1 -1
  11. package/dist/esm/exports/react.js +0 -1
  12. package/dist/esm/exports/react.js.map +1 -1
  13. package/dist/esm/react/core/hooks/transaction/useSendTransaction.js +5 -6
  14. package/dist/esm/react/core/hooks/transaction/useSendTransaction.js.map +1 -1
  15. package/dist/esm/version.js +1 -1
  16. package/dist/esm/version.js.map +1 -1
  17. package/dist/scripts/bridge-widget.js +70 -70
  18. package/dist/types/bridge/index.d.ts +0 -1
  19. package/dist/types/bridge/index.d.ts.map +1 -1
  20. package/dist/types/exports/react.d.ts +0 -1
  21. package/dist/types/exports/react.d.ts.map +1 -1
  22. package/dist/types/react/core/hooks/transaction/useSendTransaction.d.ts.map +1 -1
  23. package/dist/types/version.d.ts +1 -1
  24. package/dist/types/version.d.ts.map +1 -1
  25. package/package.json +1 -1
  26. package/src/bridge/index.ts +0 -1
  27. package/src/exports/react.ts +0 -4
  28. package/src/react/core/hooks/transaction/useSendTransaction.ts +5 -8
  29. package/src/version.ts +1 -1
  30. package/dist/cjs/bridge/Routes.js +0 -166
  31. package/dist/cjs/bridge/Routes.js.map +0 -1
  32. package/dist/cjs/react/core/hooks/useBridgeRoutes.js +0 -61
  33. package/dist/cjs/react/core/hooks/useBridgeRoutes.js.map +0 -1
  34. package/dist/esm/bridge/Routes.js +0 -163
  35. package/dist/esm/bridge/Routes.js.map +0 -1
  36. package/dist/esm/react/core/hooks/useBridgeRoutes.js +0 -58
  37. package/dist/esm/react/core/hooks/useBridgeRoutes.js.map +0 -1
  38. package/dist/types/bridge/Routes.d.ts +0 -166
  39. package/dist/types/bridge/Routes.d.ts.map +0 -1
  40. package/dist/types/react/core/hooks/useBridgeRoutes.d.ts +0 -29
  41. package/dist/types/react/core/hooks/useBridgeRoutes.d.ts.map +0 -1
  42. package/src/bridge/Routes.test.ts +0 -161
  43. package/src/bridge/Routes.ts +0 -228
  44. package/src/react/core/hooks/useBridgeRoutes.test.ts +0 -137
  45. package/src/react/core/hooks/useBridgeRoutes.ts +0 -75
@@ -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
- });
@@ -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
- }