thirdweb 5.96.8 → 5.97.0

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 (166) hide show
  1. package/dist/cjs/bridge/Buy.js +55 -3
  2. package/dist/cjs/bridge/Buy.js.map +1 -1
  3. package/dist/cjs/bridge/Chains.js +65 -0
  4. package/dist/cjs/bridge/Chains.js.map +1 -0
  5. package/dist/cjs/bridge/Routes.js +20 -1
  6. package/dist/cjs/bridge/Routes.js.map +1 -1
  7. package/dist/cjs/bridge/Sell.js +55 -3
  8. package/dist/cjs/bridge/Sell.js.map +1 -1
  9. package/dist/cjs/bridge/index.js +3 -1
  10. package/dist/cjs/bridge/index.js.map +1 -1
  11. package/dist/cjs/bridge/types/Chain.js +3 -0
  12. package/dist/cjs/bridge/types/Chain.js.map +1 -0
  13. package/dist/cjs/pay/buyWithCrypto/getHistory.js +1 -0
  14. package/dist/cjs/pay/buyWithCrypto/getHistory.js.map +1 -1
  15. package/dist/cjs/pay/buyWithCrypto/getQuote.js +1 -0
  16. package/dist/cjs/pay/buyWithCrypto/getQuote.js.map +1 -1
  17. package/dist/cjs/pay/buyWithCrypto/getStatus.js +1 -0
  18. package/dist/cjs/pay/buyWithCrypto/getStatus.js.map +1 -1
  19. package/dist/cjs/pay/buyWithCrypto/getTransfer.js +1 -0
  20. package/dist/cjs/pay/buyWithCrypto/getTransfer.js.map +1 -1
  21. package/dist/cjs/pay/buyWithFiat/getHistory.js +1 -0
  22. package/dist/cjs/pay/buyWithFiat/getHistory.js.map +1 -1
  23. package/dist/cjs/pay/buyWithFiat/getPostOnRampQuote.js +1 -0
  24. package/dist/cjs/pay/buyWithFiat/getPostOnRampQuote.js.map +1 -1
  25. package/dist/cjs/pay/buyWithFiat/getQuote.js.map +1 -1
  26. package/dist/cjs/pay/buyWithFiat/getStatus.js +1 -0
  27. package/dist/cjs/pay/buyWithFiat/getStatus.js.map +1 -1
  28. package/dist/cjs/pay/buyWithFiat/isSwapRequiredPostOnramp.js +1 -0
  29. package/dist/cjs/pay/buyWithFiat/isSwapRequiredPostOnramp.js.map +1 -1
  30. package/dist/cjs/react/core/hooks/pay/useBuyWithCryptoHistory.js +1 -0
  31. package/dist/cjs/react/core/hooks/pay/useBuyWithCryptoHistory.js.map +1 -1
  32. package/dist/cjs/react/core/hooks/pay/useBuyWithCryptoQuote.js +1 -0
  33. package/dist/cjs/react/core/hooks/pay/useBuyWithCryptoQuote.js.map +1 -1
  34. package/dist/cjs/react/core/hooks/pay/useBuyWithCryptoStatus.js +1 -0
  35. package/dist/cjs/react/core/hooks/pay/useBuyWithCryptoStatus.js.map +1 -1
  36. package/dist/cjs/react/core/hooks/pay/useBuyWithFiatHistory.js +1 -0
  37. package/dist/cjs/react/core/hooks/pay/useBuyWithFiatHistory.js.map +1 -1
  38. package/dist/cjs/react/core/hooks/pay/useBuyWithFiatQuote.js +1 -0
  39. package/dist/cjs/react/core/hooks/pay/useBuyWithFiatQuote.js.map +1 -1
  40. package/dist/cjs/react/core/hooks/pay/useBuyWithFiatStatus.js +1 -0
  41. package/dist/cjs/react/core/hooks/pay/useBuyWithFiatStatus.js.map +1 -1
  42. package/dist/cjs/version.js +1 -1
  43. package/dist/cjs/wallets/connection/autoConnect.js.map +1 -1
  44. package/dist/cjs/wallets/connection/autoConnectCore.js +18 -2
  45. package/dist/cjs/wallets/connection/autoConnectCore.js.map +1 -1
  46. package/dist/esm/bridge/Buy.js +55 -3
  47. package/dist/esm/bridge/Buy.js.map +1 -1
  48. package/dist/esm/bridge/Chains.js +62 -0
  49. package/dist/esm/bridge/Chains.js.map +1 -0
  50. package/dist/esm/bridge/Routes.js +20 -1
  51. package/dist/esm/bridge/Routes.js.map +1 -1
  52. package/dist/esm/bridge/Sell.js +55 -3
  53. package/dist/esm/bridge/Sell.js.map +1 -1
  54. package/dist/esm/bridge/index.js +1 -0
  55. package/dist/esm/bridge/index.js.map +1 -1
  56. package/dist/esm/bridge/types/Chain.js +2 -0
  57. package/dist/esm/bridge/types/Chain.js.map +1 -0
  58. package/dist/esm/pay/buyWithCrypto/getHistory.js +1 -0
  59. package/dist/esm/pay/buyWithCrypto/getHistory.js.map +1 -1
  60. package/dist/esm/pay/buyWithCrypto/getQuote.js +1 -0
  61. package/dist/esm/pay/buyWithCrypto/getQuote.js.map +1 -1
  62. package/dist/esm/pay/buyWithCrypto/getStatus.js +1 -0
  63. package/dist/esm/pay/buyWithCrypto/getStatus.js.map +1 -1
  64. package/dist/esm/pay/buyWithCrypto/getTransfer.js +1 -0
  65. package/dist/esm/pay/buyWithCrypto/getTransfer.js.map +1 -1
  66. package/dist/esm/pay/buyWithFiat/getHistory.js +1 -0
  67. package/dist/esm/pay/buyWithFiat/getHistory.js.map +1 -1
  68. package/dist/esm/pay/buyWithFiat/getPostOnRampQuote.js +1 -0
  69. package/dist/esm/pay/buyWithFiat/getPostOnRampQuote.js.map +1 -1
  70. package/dist/esm/pay/buyWithFiat/getQuote.js.map +1 -1
  71. package/dist/esm/pay/buyWithFiat/getStatus.js +1 -0
  72. package/dist/esm/pay/buyWithFiat/getStatus.js.map +1 -1
  73. package/dist/esm/pay/buyWithFiat/isSwapRequiredPostOnramp.js +1 -0
  74. package/dist/esm/pay/buyWithFiat/isSwapRequiredPostOnramp.js.map +1 -1
  75. package/dist/esm/react/core/hooks/pay/useBuyWithCryptoHistory.js +1 -0
  76. package/dist/esm/react/core/hooks/pay/useBuyWithCryptoHistory.js.map +1 -1
  77. package/dist/esm/react/core/hooks/pay/useBuyWithCryptoQuote.js +1 -0
  78. package/dist/esm/react/core/hooks/pay/useBuyWithCryptoQuote.js.map +1 -1
  79. package/dist/esm/react/core/hooks/pay/useBuyWithCryptoStatus.js +1 -0
  80. package/dist/esm/react/core/hooks/pay/useBuyWithCryptoStatus.js.map +1 -1
  81. package/dist/esm/react/core/hooks/pay/useBuyWithFiatHistory.js +1 -0
  82. package/dist/esm/react/core/hooks/pay/useBuyWithFiatHistory.js.map +1 -1
  83. package/dist/esm/react/core/hooks/pay/useBuyWithFiatQuote.js +1 -0
  84. package/dist/esm/react/core/hooks/pay/useBuyWithFiatQuote.js.map +1 -1
  85. package/dist/esm/react/core/hooks/pay/useBuyWithFiatStatus.js +1 -0
  86. package/dist/esm/react/core/hooks/pay/useBuyWithFiatStatus.js.map +1 -1
  87. package/dist/esm/version.js +1 -1
  88. package/dist/esm/wallets/connection/autoConnect.js.map +1 -1
  89. package/dist/esm/wallets/connection/autoConnectCore.js +17 -1
  90. package/dist/esm/wallets/connection/autoConnectCore.js.map +1 -1
  91. package/dist/types/bridge/Buy.d.ts +49 -0
  92. package/dist/types/bridge/Buy.d.ts.map +1 -1
  93. package/dist/types/bridge/Chains.d.ts +57 -0
  94. package/dist/types/bridge/Chains.d.ts.map +1 -0
  95. package/dist/types/bridge/Routes.d.ts +17 -0
  96. package/dist/types/bridge/Routes.d.ts.map +1 -1
  97. package/dist/types/bridge/Sell.d.ts +49 -0
  98. package/dist/types/bridge/Sell.d.ts.map +1 -1
  99. package/dist/types/bridge/index.d.ts +2 -0
  100. package/dist/types/bridge/index.d.ts.map +1 -1
  101. package/dist/types/bridge/types/Chain.d.ts +36 -0
  102. package/dist/types/bridge/types/Chain.d.ts.map +1 -0
  103. package/dist/types/pay/buyWithCrypto/getHistory.d.ts +1 -0
  104. package/dist/types/pay/buyWithCrypto/getHistory.d.ts.map +1 -1
  105. package/dist/types/pay/buyWithCrypto/getQuote.d.ts +1 -0
  106. package/dist/types/pay/buyWithCrypto/getQuote.d.ts.map +1 -1
  107. package/dist/types/pay/buyWithCrypto/getStatus.d.ts +1 -0
  108. package/dist/types/pay/buyWithCrypto/getStatus.d.ts.map +1 -1
  109. package/dist/types/pay/buyWithCrypto/getTransfer.d.ts +1 -0
  110. package/dist/types/pay/buyWithCrypto/getTransfer.d.ts.map +1 -1
  111. package/dist/types/pay/buyWithFiat/getHistory.d.ts +2 -0
  112. package/dist/types/pay/buyWithFiat/getHistory.d.ts.map +1 -1
  113. package/dist/types/pay/buyWithFiat/getPostOnRampQuote.d.ts +1 -0
  114. package/dist/types/pay/buyWithFiat/getPostOnRampQuote.d.ts.map +1 -1
  115. package/dist/types/pay/buyWithFiat/getQuote.d.ts +2 -0
  116. package/dist/types/pay/buyWithFiat/getQuote.d.ts.map +1 -1
  117. package/dist/types/pay/buyWithFiat/getStatus.d.ts +2 -0
  118. package/dist/types/pay/buyWithFiat/getStatus.d.ts.map +1 -1
  119. package/dist/types/pay/buyWithFiat/isSwapRequiredPostOnramp.d.ts +1 -0
  120. package/dist/types/pay/buyWithFiat/isSwapRequiredPostOnramp.d.ts.map +1 -1
  121. package/dist/types/react/core/hooks/pay/useBuyWithCryptoHistory.d.ts +1 -0
  122. package/dist/types/react/core/hooks/pay/useBuyWithCryptoHistory.d.ts.map +1 -1
  123. package/dist/types/react/core/hooks/pay/useBuyWithCryptoQuote.d.ts +1 -0
  124. package/dist/types/react/core/hooks/pay/useBuyWithCryptoQuote.d.ts.map +1 -1
  125. package/dist/types/react/core/hooks/pay/useBuyWithCryptoStatus.d.ts +1 -0
  126. package/dist/types/react/core/hooks/pay/useBuyWithCryptoStatus.d.ts.map +1 -1
  127. package/dist/types/react/core/hooks/pay/useBuyWithFiatHistory.d.ts +1 -0
  128. package/dist/types/react/core/hooks/pay/useBuyWithFiatHistory.d.ts.map +1 -1
  129. package/dist/types/react/core/hooks/pay/useBuyWithFiatQuote.d.ts +1 -0
  130. package/dist/types/react/core/hooks/pay/useBuyWithFiatQuote.d.ts.map +1 -1
  131. package/dist/types/react/core/hooks/pay/useBuyWithFiatStatus.d.ts +1 -0
  132. package/dist/types/react/core/hooks/pay/useBuyWithFiatStatus.d.ts.map +1 -1
  133. package/dist/types/version.d.ts +1 -1
  134. package/dist/types/wallets/connection/autoConnect.d.ts +6 -0
  135. package/dist/types/wallets/connection/autoConnect.d.ts.map +1 -1
  136. package/dist/types/wallets/connection/autoConnectCore.d.ts +13 -5
  137. package/dist/types/wallets/connection/autoConnectCore.d.ts.map +1 -1
  138. package/package.json +1 -1
  139. package/src/bridge/Buy.test.ts +36 -0
  140. package/src/bridge/Buy.ts +57 -1
  141. package/src/bridge/Chains.test.ts +28 -0
  142. package/src/bridge/Chains.ts +75 -0
  143. package/src/bridge/Routes.ts +21 -0
  144. package/src/bridge/Sell.test.ts +36 -0
  145. package/src/bridge/Sell.ts +57 -1
  146. package/src/bridge/index.ts +2 -0
  147. package/src/bridge/types/Chain.ts +40 -0
  148. package/src/pay/buyWithCrypto/getHistory.ts +1 -0
  149. package/src/pay/buyWithCrypto/getQuote.ts +1 -0
  150. package/src/pay/buyWithCrypto/getStatus.ts +1 -0
  151. package/src/pay/buyWithCrypto/getTransfer.ts +1 -0
  152. package/src/pay/buyWithFiat/getHistory.ts +2 -0
  153. package/src/pay/buyWithFiat/getPostOnRampQuote.ts +1 -0
  154. package/src/pay/buyWithFiat/getQuote.ts +2 -0
  155. package/src/pay/buyWithFiat/getStatus.ts +2 -0
  156. package/src/pay/buyWithFiat/isSwapRequiredPostOnramp.ts +1 -0
  157. package/src/react/core/hooks/pay/useBuyWithCryptoHistory.ts +1 -0
  158. package/src/react/core/hooks/pay/useBuyWithCryptoQuote.ts +1 -0
  159. package/src/react/core/hooks/pay/useBuyWithCryptoStatus.ts +1 -0
  160. package/src/react/core/hooks/pay/useBuyWithFiatHistory.ts +1 -0
  161. package/src/react/core/hooks/pay/useBuyWithFiatQuote.ts +1 -0
  162. package/src/react/core/hooks/pay/useBuyWithFiatStatus.ts +1 -0
  163. package/src/version.ts +1 -1
  164. package/src/wallets/connection/autoConnect.ts +6 -0
  165. package/src/wallets/connection/autoConnectCore.test.ts +13 -0
  166. package/src/wallets/connection/autoConnectCore.ts +40 -13
@@ -0,0 +1,28 @@
1
+ import { describe, expect, it } from "vitest";
2
+ import { TEST_CLIENT } from "~test/test-clients.js";
3
+ import { chains } from "./Chains.js";
4
+
5
+ describe("chains", () => {
6
+ it("should fetch chains", async () => {
7
+ // Setup
8
+ const client = TEST_CLIENT;
9
+
10
+ // Test
11
+ const result = await chains({ client });
12
+
13
+ // Verify
14
+ expect(result).toBeInstanceOf(Array);
15
+
16
+ // Basic structure validation
17
+ if (result.length > 0) {
18
+ const chain = result[0];
19
+ expect(chain).toHaveProperty("chainId");
20
+ expect(chain).toHaveProperty("name");
21
+ expect(chain).toHaveProperty("icon");
22
+ expect(chain).toHaveProperty("nativeCurrency");
23
+ expect(chain?.nativeCurrency).toHaveProperty("name");
24
+ expect(chain?.nativeCurrency).toHaveProperty("symbol");
25
+ expect(chain?.nativeCurrency).toHaveProperty("decimals");
26
+ }
27
+ });
28
+ });
@@ -0,0 +1,75 @@
1
+ import type { ThirdwebClient } from "../client/client.js";
2
+ import { getClientFetch } from "../utils/fetch.js";
3
+ import { UNIVERSAL_BRIDGE_URL } from "./constants.js";
4
+ import type { Chain } from "./types/Chain.js";
5
+
6
+ /**
7
+ * Retrieves supported Universal Bridge chains.
8
+ *
9
+ * @example
10
+ * ```typescript
11
+ * import { Bridge } from "thirdweb";
12
+ *
13
+ * const chains = await Bridge.chains({
14
+ * client: thirdwebClient,
15
+ * });
16
+ * ```
17
+ *
18
+ * Returned chains might look something like:
19
+ * ```typescript
20
+ * [
21
+ * {
22
+ * chainId: 1,
23
+ * name: "Ethereum",
24
+ * icon: "https://assets.thirdweb.com/chains/1.png",
25
+ * nativeCurrency: {
26
+ * name: "Ether",
27
+ * symbol: "ETH",
28
+ * decimals: 18
29
+ * }
30
+ * },
31
+ * {
32
+ * chainId: 137,
33
+ * name: "Polygon",
34
+ * icon: "https://assets.thirdweb.com/chains/137.png",
35
+ * nativeCurrency: {
36
+ * name: "MATIC",
37
+ * symbol: "MATIC",
38
+ * decimals: 18
39
+ * }
40
+ * }
41
+ * ]
42
+ * ```
43
+ *
44
+ * @param options - The options for fetching chains.
45
+ * @param options.client - Your thirdweb client.
46
+ *
47
+ * @returns A promise that resolves to an array of chains.
48
+ *
49
+ * @throws Will throw an error if there is an issue fetching the chains.
50
+ * @bridge
51
+ * @beta
52
+ */
53
+ export async function chains(options: chains.Options): Promise<chains.Result> {
54
+ const { client } = options;
55
+
56
+ const clientFetch = getClientFetch(client);
57
+ const url = new URL(`${UNIVERSAL_BRIDGE_URL}/chains`);
58
+
59
+ const response = await clientFetch(url.toString());
60
+ if (!response.ok) {
61
+ const errorJson = await response.json();
62
+ throw new Error(`${errorJson.code} | ${errorJson.message}`);
63
+ }
64
+
65
+ const { data }: { data: Chain[] } = await response.json();
66
+ return data;
67
+ }
68
+
69
+ export declare namespace chains {
70
+ type Options = {
71
+ client: ThirdwebClient;
72
+ };
73
+
74
+ type Result = Chain[];
75
+ }
@@ -86,6 +86,21 @@ import type { Route } from "./types/Route.js";
86
86
  * });
87
87
  * ```
88
88
  *
89
+ * You can sort the returned routes by `popularity`:
90
+ * ```ts
91
+ * import { Bridge } from "thirdweb";
92
+ *
93
+ * // Get the 10 most popular routes starting from mainnet ETH
94
+ * const routes = await Bridge.routes({
95
+ * originChainId: 1,
96
+ * originTokenAddress: "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE",
97
+ * limit: 10,
98
+ * offset: 0,
99
+ * sortBy: "popularity",
100
+ * client: thirdwebClient,
101
+ * });
102
+ * ```
103
+ *
89
104
  * @param options - The options for the quote.
90
105
  * @param options.client - Your thirdweb client.
91
106
  * @param options.originChainId - Filter by a specific origin chain ID.
@@ -94,6 +109,7 @@ import type { Route } from "./types/Route.js";
94
109
  * @param options.destinationTokenAddress - Filter by a specific destination token address.
95
110
  * @param options.transactionHash - Filter by a specific transaction hash.
96
111
  * @param options.maxSteps - Limit the number of steps returned.
112
+ * @param options.sortBy - Sort the routes by various categories.
97
113
  * @param options.limit - Limit the number of routes returned.
98
114
  * @param options.offset - Offset the number of routes returned.
99
115
  *
@@ -111,6 +127,7 @@ export async function routes(options: routes.Options): Promise<routes.Result> {
111
127
  destinationChainId,
112
128
  destinationTokenAddress,
113
129
  maxSteps,
130
+ sortBy,
114
131
  limit,
115
132
  offset,
116
133
  } = options;
@@ -138,6 +155,9 @@ export async function routes(options: routes.Options): Promise<routes.Result> {
138
155
  if (offset) {
139
156
  url.searchParams.set("offset", offset.toString());
140
157
  }
158
+ if (sortBy) {
159
+ url.searchParams.set("sortBy", sortBy);
160
+ }
141
161
 
142
162
  const response = await clientFetch(url.toString());
143
163
  if (!response.ok) {
@@ -157,6 +177,7 @@ export declare namespace routes {
157
177
  destinationChainId?: number;
158
178
  destinationTokenAddress?: ox__Address.Address;
159
179
  transactionHash?: ox__Hex.Hex;
180
+ sortBy?: "popularity";
160
181
  maxSteps?: number;
161
182
  limit?: number;
162
183
  offset?: number;
@@ -32,6 +32,23 @@ describe.runIf(process.env.TW_SECRET_KEY)("Bridge.Sell.quote", () => {
32
32
  }),
33
33
  ).rejects.toThrowError();
34
34
  });
35
+
36
+ it("should limit quotes to routes with a certain number of steps", async () => {
37
+ const quote = await Sell.quote({
38
+ originChainId: 1,
39
+ originTokenAddress: "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE",
40
+ destinationChainId: 10,
41
+ destinationTokenAddress: "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE",
42
+ amount: toWei("0.01"),
43
+ maxSteps: 2,
44
+ client: TEST_CLIENT,
45
+ });
46
+
47
+ expect(quote).toBeDefined();
48
+ expect(quote.originAmount).toEqual(toWei("0.01"));
49
+ expect(quote.intent).toBeDefined();
50
+ expect(quote.steps.length).toBeLessThanOrEqual(2);
51
+ });
35
52
  });
36
53
 
37
54
  describe.runIf(process.env.TW_SECRET_KEY)("Bridge.Sell.prepare", () => {
@@ -69,4 +86,23 @@ describe.runIf(process.env.TW_SECRET_KEY)("Bridge.Sell.prepare", () => {
69
86
  }),
70
87
  ).rejects.toThrowError();
71
88
  });
89
+
90
+ it("should limit quotes to routes with a certain number of steps", async () => {
91
+ const quote = await Sell.prepare({
92
+ originChainId: 1,
93
+ originTokenAddress: "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE",
94
+ destinationChainId: 10,
95
+ destinationTokenAddress: "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE",
96
+ amount: toWei("0.01"),
97
+ maxSteps: 2,
98
+ sender: "0x2a4f24F935Eb178e3e7BA9B53A5Ee6d8407C0709",
99
+ receiver: "0x2a4f24F935Eb178e3e7BA9B53A5Ee6d8407C0709",
100
+ client: TEST_CLIENT,
101
+ });
102
+
103
+ expect(quote).toBeDefined();
104
+ expect(quote.originAmount).toEqual(toWei("0.01"));
105
+ expect(quote.steps.length).toBeLessThanOrEqual(2);
106
+ expect(quote.intent).toBeDefined();
107
+ });
72
108
  });
@@ -2,6 +2,7 @@ import type { Address as ox__Address } from "ox";
2
2
  import { defineChain } from "../chains/utils.js";
3
3
  import type { ThirdwebClient } from "../client/client.js";
4
4
  import { getClientFetch } from "../utils/fetch.js";
5
+ import { stringify } from "../utils/json.js";
5
6
  import { UNIVERSAL_BRIDGE_URL } from "./constants.js";
6
7
  import type { PreparedQuote, Quote } from "./types/Quote.js";
7
8
 
@@ -70,12 +71,27 @@ import type { PreparedQuote, Quote } from "./types/Quote.js";
70
71
  *
71
72
  * You can access this functions input and output types with `Sell.quote.Options` and `Sell.quote.Result`, respectively.
72
73
  *
74
+ * To limit quotes to routes that have a certain number of steps involved, use the `maxSteps` option.
75
+ *
76
+ * ```ts
77
+ * const quote = await Bridge.Sell.quote({
78
+ * originChainId: 1,
79
+ * originTokenAddress: NATIVE_TOKEN_ADDRESS,
80
+ * destinationChainId: 10,
81
+ * destinationTokenAddress: NATIVE_TOKEN_ADDRESS,
82
+ * amount: toWei("0.01"),
83
+ * maxSteps: 2, // Will only return a quote for routes with 2 or fewer steps
84
+ * client: thirdwebClient,
85
+ * });
86
+ * ```
87
+ *
73
88
  * @param options - The options for the quote.
74
89
  * @param options.originChainId - The chain ID of the origin token.
75
90
  * @param options.originTokenAddress - The address of the origin token.
76
91
  * @param options.destinationChainId - The chain ID of the destination token.
77
92
  * @param options.destinationTokenAddress - The address of the destination token.
78
93
  * @param options.amount - The amount of the origin token to sell.
94
+ * @param [options.maxSteps] - Limit the number of total steps in the route.
79
95
  * @param options.client - Your thirdweb client.
80
96
  *
81
97
  * @returns A promise that resolves to a non-finalized quote for the requested sell.
@@ -92,6 +108,7 @@ export async function quote(options: quote.Options): Promise<quote.Result> {
92
108
  destinationTokenAddress,
93
109
  amount,
94
110
  client,
111
+ maxSteps,
95
112
  } = options;
96
113
 
97
114
  const clientFetch = getClientFetch(client);
@@ -101,6 +118,9 @@ export async function quote(options: quote.Options): Promise<quote.Result> {
101
118
  url.searchParams.set("destinationChainId", destinationChainId.toString());
102
119
  url.searchParams.set("destinationTokenAddress", destinationTokenAddress);
103
120
  url.searchParams.set("sellAmountWei", amount.toString());
121
+ if (typeof maxSteps !== "undefined") {
122
+ url.searchParams.set("maxSteps", maxSteps.toString());
123
+ }
104
124
 
105
125
  const response = await clientFetch(url.toString());
106
126
  if (!response.ok) {
@@ -136,6 +156,7 @@ export declare namespace quote {
136
156
  destinationTokenAddress: ox__Address.Address;
137
157
  amount: bigint;
138
158
  client: ThirdwebClient;
159
+ maxSteps?: number;
139
160
  };
140
161
 
141
162
  type Result = Quote & {
@@ -238,6 +259,37 @@ export declare namespace quote {
238
259
  *
239
260
  * You can access this functions input and output types with `Sell.prepare.Options` and `Sell.prepare.Result`, respectively.
240
261
  *
262
+ * You can include arbitrary data to be included on any webhooks and status responses with the `purchaseData` option.
263
+ *
264
+ * ```ts
265
+ * const quote = await Bridge.Sell.prepare({
266
+ * originChainId: 1,
267
+ * originTokenAddress: NATIVE_TOKEN_ADDRESS,
268
+ * destinationChainId: 10,
269
+ * destinationTokenAddress: NATIVE_TOKEN_ADDRESS,
270
+ * amount: toWei("0.01"),
271
+ * purchaseData: {
272
+ * size: "large",
273
+ * shippingAddress: "123 Main St, New York, NY 10001",
274
+ * },
275
+ * client: thirdwebClient,
276
+ * });
277
+ * ```
278
+ *
279
+ * To limit quotes to routes that have a certain number of steps involved, use the `maxSteps` option.
280
+ *
281
+ * ```ts
282
+ * const quote = await Bridge.Sell.prepare({
283
+ * originChainId: 1,
284
+ * originTokenAddress: NATIVE_TOKEN_ADDRESS,
285
+ * destinationChainId: 10,
286
+ * destinationTokenAddress: NATIVE_TOKEN_ADDRESS,
287
+ * amount: toWei("0.01"),
288
+ * maxSteps: 2, // Will only return a quote for routes with 2 or fewer steps
289
+ * client: thirdwebClient,
290
+ * });
291
+ * ```
292
+ *
241
293
  * @param options - The options for the quote.
242
294
  * @param options.originChainId - The chain ID of the origin token.
243
295
  * @param options.originTokenAddress - The address of the origin token.
@@ -247,6 +299,7 @@ export declare namespace quote {
247
299
  * @param options.sender - The address of the sender.
248
300
  * @param options.receiver - The address of the recipient.
249
301
  * @param options.purchaseData - Arbitrary data to be passed to the purchase function and included with any webhooks or status calls.
302
+ * @param [options.maxSteps] - Limit the number of total steps in the route.
250
303
  * @param options.client - Your thirdweb client.
251
304
  *
252
305
  * @returns A promise that resolves to a finalized quote and transactions for the requested sell.
@@ -268,6 +321,7 @@ export async function prepare(
268
321
  receiver,
269
322
  client,
270
323
  purchaseData,
324
+ maxSteps,
271
325
  } = options;
272
326
 
273
327
  const clientFetch = getClientFetch(client);
@@ -278,7 +332,7 @@ export async function prepare(
278
332
  headers: {
279
333
  "Content-Type": "application/json",
280
334
  },
281
- body: JSON.stringify({
335
+ body: stringify({
282
336
  sellAmountWei: amount.toString(),
283
337
  originChainId: originChainId.toString(),
284
338
  originTokenAddress,
@@ -287,6 +341,7 @@ export async function prepare(
287
341
  sender,
288
342
  receiver,
289
343
  purchaseData,
344
+ maxSteps,
290
345
  }),
291
346
  });
292
347
  if (!response.ok) {
@@ -335,6 +390,7 @@ export declare namespace prepare {
335
390
  receiver: ox__Address.Address;
336
391
  client: ThirdwebClient;
337
392
  purchaseData?: unknown;
393
+ maxSteps?: number;
338
394
  };
339
395
 
340
396
  type Result = PreparedQuote & {
@@ -2,7 +2,9 @@ export * as Buy from "./Buy.js";
2
2
  export * as Sell from "./Sell.js";
3
3
  export { status } from "./Status.js";
4
4
  export { routes } from "./Routes.js";
5
+ export { chains } from "./Chains.js";
5
6
 
6
7
  export type { Status } from "./types/Status.js";
7
8
  export type { Route } from "./types/Route.js";
8
9
  export type { Quote, PreparedQuote } from "./types/Quote.js";
10
+ export type { Chain } from "./types/Chain.js";
@@ -0,0 +1,40 @@
1
+ /**
2
+ * Represents a blockchain chain in the Universal Bridge.
3
+ * @public
4
+ */
5
+ export interface Chain {
6
+ /**
7
+ * The chain ID of the chain.
8
+ */
9
+ chainId: number;
10
+
11
+ /**
12
+ * The name of the chain.
13
+ */
14
+ name: string;
15
+
16
+ /**
17
+ * The URL of the chain's icon.
18
+ */
19
+ icon: string;
20
+
21
+ /**
22
+ * Information about the native currency of the chain.
23
+ */
24
+ nativeCurrency: {
25
+ /**
26
+ * The name of the native currency.
27
+ */
28
+ name: string;
29
+
30
+ /**
31
+ * The symbol of the native currency.
32
+ */
33
+ symbol: string;
34
+
35
+ /**
36
+ * The number of decimals used by the native currency.
37
+ */
38
+ decimals: number;
39
+ };
40
+ }
@@ -61,6 +61,7 @@ export type BuyWithCryptoHistoryData = {
61
61
  * const status = await getBuyWithCryptoHistory(params)
62
62
  * ```
63
63
  * @returns Object of type [`BuyWithCryptoHistoryData`](https://portal.thirdweb.com/references/typescript/v5/BuyWithCryptoHistoryData)
64
+ * @deprecated
64
65
  * @buyCrypto
65
66
  */
66
67
  export async function getBuyWithCryptoHistory(
@@ -208,6 +208,7 @@ export type BuyWithCryptoQuote = {
208
208
  * maxSlippageBPS: 50, // optional: max 0.5% slippage
209
209
  * });
210
210
  * ```
211
+ * @deprecated
211
212
  * @buyCrypto
212
213
  */
213
214
  export async function getBuyWithCryptoQuote(
@@ -123,6 +123,7 @@ export type ValidBuyWithCryptoStatus = Exclude<
123
123
  * }});
124
124
  * ```
125
125
  * @returns Object of type [`BuyWithCryptoStatus`](https://portal.thirdweb.com/references/typescript/v5/BuyWithCryptoStatus)
126
+ * @deprecated
126
127
  * @buyCrypto
127
128
  */
128
129
  export async function getBuyWithCryptoStatus(
@@ -119,6 +119,7 @@ export type BuyWithCryptoTransfer = {
119
119
  * }
120
120
  * });
121
121
  * ```
122
+ * @deprecated
122
123
  * @buyCrypto
123
124
  */
124
125
  export async function getBuyWithCryptoTransfer(
@@ -5,6 +5,7 @@ import type { BuyWithFiatStatus } from "./getStatus.js";
5
5
 
6
6
  /**
7
7
  * The parameters for [`getBuyWithFiatHistory`](https://portal.thirdweb.com/references/typescript/v5/getBuyWithFiatHistory) function
8
+ * @deprecated
8
9
  * @buyCrypto
9
10
  */
10
11
  export type BuyWithFiatHistoryParams = {
@@ -60,6 +61,7 @@ export type BuyWithFiatHistoryData = {
60
61
  * })
61
62
  * ```
62
63
  * @returns Object of type [`BuyWithFiatHistoryData`](https://portal.thirdweb.com/references/typescript/v5/BuyWithFiatHistoryData)
64
+ * @deprecated
63
65
  * @buyCrypto
64
66
  */
65
67
  export async function getBuyWithFiatHistory(
@@ -55,6 +55,7 @@ export type GetPostOnRampQuoteParams = {
55
55
  * });
56
56
  * }
57
57
  * ```
58
+ * @deprecated
58
59
  * @buyCrypto
59
60
  */
60
61
  export async function getPostOnRampQuote({
@@ -6,6 +6,7 @@ import type { FiatProvider, PayTokenInfo } from "../utils/commonTypes.js";
6
6
  import { getPayBuyWithFiatQuoteEndpoint } from "../utils/definitions.js";
7
7
  /**
8
8
  * Parameters for [`getBuyWithFiatQuote`](https://portal.thirdweb.com/references/typescript/v5/getBuyWithFiatQuote) function
9
+ * @deprecated
9
10
  * @buyCrypto
10
11
  */
11
12
  export type GetBuyWithFiatQuoteParams = {
@@ -102,6 +103,7 @@ export type GetBuyWithFiatQuoteParams = {
102
103
  * - The on-ramp and destination token information.
103
104
  * - Processing fees
104
105
  *
106
+ * @deprecated
105
107
  * @buyCrypto
106
108
  */
107
109
  export type BuyWithFiatQuote = {
@@ -8,6 +8,7 @@ import { getPayBuyWithFiatStatusEndpoint } from "../utils/definitions.js";
8
8
 
9
9
  /**
10
10
  * Parameters for the [`getBuyWithFiatStatus`](https://portal.thirdweb.com/references/typescript/v5/getBuyWithFiatStatus) function
11
+ * @deprecated
11
12
  * @buyCrypto
12
13
  */
13
14
  export type GetBuyWithFiatStatusParams = {
@@ -172,6 +173,7 @@ export type BuyWithFiatStatus =
172
173
  * // when the fiatStatus.status is "ON_RAMP_TRANSFER_COMPLETED" - the process is complete
173
174
  * // when the fiatStatus.status is "CRYPTO_SWAP_REQUIRED" - start the swap process
174
175
  * ```
176
+ * @deprecated
175
177
  * @buyCrypto
176
178
  */
177
179
  export async function getBuyWithFiatStatus(
@@ -12,6 +12,7 @@ import type { BuyWithFiatQuote } from "./getQuote.js";
12
12
  *
13
13
  * @param buyWithFiatQuote - The quote of type [`BuyWithFiatQuote`](https://portal.thirdweb.com/references/typescript/v5/BuyWithFiatQuote) returned
14
14
  * by the [`getBuyWithFiatQuote`](https://portal.thirdweb.com/references/typescript/v5/getBuyWithFiatQuote) function.
15
+ * @deprecated
15
16
  * @buyCrypto
16
17
  */
17
18
  export function isSwapRequiredPostOnramp(
@@ -34,6 +34,7 @@ export type BuyWithCryptoHistoryQueryOptions = Omit<
34
34
  * return <div> ... </div>
35
35
  * }
36
36
  * ```
37
+ * @deprecated
37
38
  * @buyCrypto
38
39
  */
39
40
  export function useBuyWithCryptoHistory(
@@ -71,6 +71,7 @@ export type BuyWithCryptoQuoteQueryOptions = Omit<
71
71
  * return <button onClick={handleBuyWithCrypto}>Swap</button>
72
72
  * }
73
73
  * ```
74
+ * @deprecated
74
75
  * @buyCrypto
75
76
  */
76
77
  export function useBuyWithCryptoQuote(
@@ -52,6 +52,7 @@ import {
52
52
  * return <button onClick={handleBuyWithCrypto}>Swap</button>
53
53
  * }
54
54
  * ```
55
+ * @deprecated
55
56
  * @buyCrypto
56
57
  */
57
58
  export function useBuyWithCryptoStatus(params?: BuyWithCryptoTransaction) {
@@ -34,6 +34,7 @@ export type BuyWithFiatHistoryQueryOptions = Omit<
34
34
  * return <div> ... </div>
35
35
  * }
36
36
  * ```
37
+ * @deprecated
37
38
  * @buyCrypto
38
39
  */
39
40
  export function useBuyWithFiatHistory(
@@ -60,6 +60,7 @@ export type BuyWithFiatQuoteQueryOptions = Omit<
60
60
  * );
61
61
  * }
62
62
  * ```
63
+ * @deprecated
63
64
  * @buyCrypto
64
65
  */
65
66
  export function useBuyWithFiatQuote(
@@ -32,6 +32,7 @@ import type { WithPickedOnceQueryOptions } from "../types.js";
32
32
  * return <div>...</div>;
33
33
  * }
34
34
  * ```
35
+ * @deprecated
35
36
  * @buyCrypto
36
37
  */
37
38
  export function useBuyWithFiatStatus(
package/src/version.ts CHANGED
@@ -1 +1 @@
1
- export const version = "5.96.8";
1
+ export const version = "5.97.0";
@@ -32,6 +32,12 @@ import type { AutoConnectProps } from "./types.js";
32
32
  export async function autoConnect(
33
33
  props: AutoConnectProps & {
34
34
  wallets?: Wallet[];
35
+ /**
36
+ * If true, the auto connect will be forced even if autoConnect has already been attempted successfully earlier.
37
+ *
38
+ * @default `false`
39
+ */
40
+ force?: boolean;
35
41
  },
36
42
  ): Promise<boolean> {
37
43
  const wallets = props.wallets || getDefaultWallets(props);
@@ -35,6 +35,7 @@ describe("useAutoConnectCore", () => {
35
35
 
36
36
  expect(
37
37
  await autoConnectCore({
38
+ force: true,
38
39
  storage: mockStorage,
39
40
  props: {
40
41
  wallets: [wallet],
@@ -68,6 +69,7 @@ describe("useAutoConnectCore", () => {
68
69
 
69
70
  expect(
70
71
  await autoConnectCore({
72
+ force: true,
71
73
  storage: mockStorage,
72
74
  props: {
73
75
  wallets: [wallet],
@@ -111,6 +113,7 @@ describe("useAutoConnectCore", () => {
111
113
  });
112
114
 
113
115
  await autoConnectCore({
116
+ force: true,
114
117
  storage: mockStorage,
115
118
  props: {
116
119
  wallets: [wallet],
@@ -155,6 +158,7 @@ describe("useAutoConnectCore", () => {
155
158
  });
156
159
 
157
160
  await autoConnectCore({
161
+ force: true,
158
162
  storage: mockStorage,
159
163
  props: {
160
164
  wallets: [wallet],
@@ -191,6 +195,7 @@ describe("useAutoConnectCore", () => {
191
195
  const warnSpy = vi.spyOn(console, "warn").mockImplementation(() => {});
192
196
 
193
197
  await autoConnectCore({
198
+ force: true,
194
199
  storage: mockStorage,
195
200
  props: {
196
201
  wallets: [wallet1],
@@ -235,6 +240,7 @@ describe("useAutoConnectCore", () => {
235
240
  const addConnectedWalletSpy = vi.spyOn(manager, "addConnectedWallet");
236
241
 
237
242
  await autoConnectCore({
243
+ force: true,
238
244
  storage: mockStorage,
239
245
  props: {
240
246
  wallets: [wallet1, wallet2],
@@ -264,6 +270,7 @@ describe("useAutoConnectCore", () => {
264
270
  JSON.stringify([wallet.id]),
265
271
  );
266
272
  await autoConnectCore({
273
+ force: true,
267
274
  storage: mockStorage,
268
275
  props: {
269
276
  wallets: [wallet],
@@ -276,6 +283,7 @@ describe("useAutoConnectCore", () => {
276
283
 
277
284
  expect(mockOnConnect).toHaveBeenCalledWith(wallet);
278
285
  });
286
+
279
287
  it("should continue even if onConnect callback throws", async () => {
280
288
  const mockOnConnect = vi.fn();
281
289
  mockOnConnect.mockImplementation(() => {
@@ -296,6 +304,7 @@ describe("useAutoConnectCore", () => {
296
304
  JSON.stringify([wallet.id]),
297
305
  );
298
306
  await autoConnectCore({
307
+ force: true,
299
308
  storage: mockStorage,
300
309
  props: {
301
310
  wallets: [wallet],
@@ -308,6 +317,7 @@ describe("useAutoConnectCore", () => {
308
317
 
309
318
  expect(mockOnConnect).toHaveBeenCalledWith(wallet);
310
319
  });
320
+
311
321
  it("should call setLastAuthProvider if authProvider is present", async () => {
312
322
  const wallet = createWalletAdapter({
313
323
  adaptedAccount: TEST_ACCOUNT_A,
@@ -328,6 +338,7 @@ describe("useAutoConnectCore", () => {
328
338
  JSON.stringify([wallet.id]),
329
339
  );
330
340
  await autoConnectCore({
341
+ force: true,
331
342
  storage: mockStorage,
332
343
  props: {
333
344
  wallets: [wallet],
@@ -340,6 +351,7 @@ describe("useAutoConnectCore", () => {
340
351
 
341
352
  expect(mockSetLastAuthProvider).toHaveBeenCalledWith("email", mockStorage);
342
353
  });
354
+
343
355
  it("should set connection status to disconnect if no connectedWallet is returned", async () => {
344
356
  const wallet = createWalletAdapter({
345
357
  adaptedAccount: TEST_ACCOUNT_A,
@@ -360,6 +372,7 @@ describe("useAutoConnectCore", () => {
360
372
  .mockResolvedValueOnce(null as unknown as Wallet);
361
373
 
362
374
  await autoConnectCore({
375
+ force: true,
363
376
  storage: mockStorage,
364
377
  props: {
365
378
  wallets: [wallet],