@@ -17,7 +17,7 @@ import type { PreparedQuote, Quote } from "./types/Quote.js";
1717 * originTokenAddress: NATIVE_TOKEN_ADDRESS,
1818 * destinationChainId: 10,
1919 * destinationTokenAddress: NATIVE_TOKEN_ADDRESS,
20- * buyAmountWei : toWei("0.01"),
20+ * amount : toWei("0.01"),
2121 * client: thirdwebClient,
2222 * });
2323 * ```
@@ -30,12 +30,37 @@ import type { PreparedQuote, Quote } from "./types/Quote.js";
3030 * blockNumber: 22026509n,
3131 * timestamp: 1741730936680,
3232 * estimatedExecutionTimeMs: 1000
33+ * steps: [
34+ * {
35+ * originToken: {
36+ * chainId: 1,
37+ * address: "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE",
38+ * symbol: "ETH",
39+ * name: "Ethereum",
40+ * decimals: 18,
41+ * priceUsd: 0.0025,
42+ * iconUri: "https://..."
43+ * },
44+ * destinationToken: {
45+ * chainId: 10,
46+ * address: "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE",
47+ * symbol: "ETH",
48+ * name: "Ethereum",
49+ * decimals: 18,
50+ * priceUsd: 0.0025,
51+ * iconUri: "https://..."
52+ * },
53+ * originAmount: 10000026098875381n,
54+ * destinationAmount: 1000000000000000000n,
55+ * estimatedExecutionTimeMs: 1000
56+ * }
57+ * ],
3358 * intent: {
3459 * originChainId: 1,
3560 * originTokenAddress: NATIVE_TOKEN_ADDRESS,
3661 * destinationChainId: 10,
3762 * destinationTokenAddress: NATIVE_TOKEN_ADDRESS,
38- * buyAmountWei : 1000000000000000000n
63+ * amount : 1000000000000000000n
3964 * }
4065 * }
4166 * ```
@@ -50,7 +75,7 @@ import type { PreparedQuote, Quote } from "./types/Quote.js";
5075 * @param options.originTokenAddress - The address of the origin token.
5176 * @param options.destinationChainId - The chain ID of the destination token.
5277 * @param options.destinationTokenAddress - The address of the destination token.
53- * @param options.buyAmountWei - The amount of the origin token to buy .
78+ * @param options.amount - The amount of the destination token to receive .
5479 * @param options.client - Your thirdweb client.
5580 *
5681 * @returns A promise that resolves to a non-finalized quote for the requested buy.
@@ -65,17 +90,18 @@ export async function quote(options: quote.Options): Promise<quote.Result> {
6590 originTokenAddress,
6691 destinationChainId,
6792 destinationTokenAddress,
68- buyAmountWei,
6993 client,
7094 } = options ;
95+ const amount =
96+ "buyAmountWei" in options ? options . buyAmountWei : options . amount ;
7197
7298 const clientFetch = getClientFetch ( client ) ;
7399 const url = new URL ( `${ UNIVERSAL_BRIDGE_URL } /buy/quote` ) ;
74100 url . searchParams . set ( "originChainId" , originChainId . toString ( ) ) ;
75101 url . searchParams . set ( "originTokenAddress" , originTokenAddress ) ;
76102 url . searchParams . set ( "destinationChainId" , destinationChainId . toString ( ) ) ;
77103 url . searchParams . set ( "destinationTokenAddress" , destinationTokenAddress ) ;
78- url . searchParams . set ( "buyAmountWei" , buyAmountWei . toString ( ) ) ;
104+ url . searchParams . set ( "buyAmountWei" , amount . toString ( ) ) ;
79105
80106 const response = await clientFetch ( url . toString ( ) ) ;
81107 if ( ! response . ok ) {
@@ -92,12 +118,14 @@ export async function quote(options: quote.Options): Promise<quote.Result> {
92118 blockNumber : data . blockNumber ? BigInt ( data . blockNumber ) : undefined ,
93119 timestamp : data . timestamp ,
94120 estimatedExecutionTimeMs : data . estimatedExecutionTimeMs ,
121+ steps : data . steps ,
95122 intent : {
96123 originChainId,
97124 originTokenAddress,
98125 destinationChainId,
99126 destinationTokenAddress,
100- buyAmountWei,
127+ buyAmountWei : amount ,
128+ amount,
101129 } ,
102130 } ;
103131}
@@ -108,9 +136,15 @@ export declare namespace quote {
108136 originTokenAddress : ox__Address . Address ;
109137 destinationChainId : number ;
110138 destinationTokenAddress : ox__Address . Address ;
111- buyAmountWei : bigint ;
112139 client : ThirdwebClient ;
113- } ;
140+ } & (
141+ | {
142+ buyAmountWei : bigint ;
143+ }
144+ | {
145+ amount : bigint ;
146+ }
147+ ) ;
114148
115149 type Result = Quote & {
116150 intent : {
@@ -119,6 +153,7 @@ export declare namespace quote {
119153 destinationChainId : number ;
120154 destinationTokenAddress : ox__Address . Address ;
121155 buyAmountWei : bigint ;
156+ amount : bigint ;
122157 } ;
123158 } ;
124159}
@@ -135,7 +170,7 @@ export declare namespace quote {
135170 * originTokenAddress: NATIVE_TOKEN_ADDRESS,
136171 * destinationChainId: 10,
137172 * destinationTokenAddress: NATIVE_TOKEN_ADDRESS,
138- * buyAmountWei : toWei("0.01"),
173+ * amount : toWei("0.01"),
139174 * client: thirdwebClient,
140175 * });
141176 * ```
@@ -148,31 +183,56 @@ export declare namespace quote {
148183 * blockNumber: 22026509n,
149184 * timestamp: 1741730936680,
150185 * estimatedExecutionTimeMs: 1000
151- * transactions : [
186+ * steps : [
152187 * {
153- * action: "approval",
154- * id: "0x",
155- * to: "0x...",
156- * data: "0x...",
157- * chainId: 10,
158- * type: "eip1559"
159- * },
160- * {
161- * action: "buy",
162- * to: "0x...",
163- * value: 10000026098875381n,
164- * data: "0x...",
165- * chainId: 10,
166- * type: "eip1559"
188+ * originToken: {
189+ * chainId: 1,
190+ * address: "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE",
191+ * symbol: "ETH",
192+ * name: "Ethereum",
193+ * decimals: 18,
194+ * priceUsd: 2000,
195+ * iconUri: "https://..."
196+ * },
197+ * destinationToken: {
198+ * chainId: 10,
199+ * address: "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE",
200+ * symbol: "ETH",
201+ * name: "Ethereum",
202+ * decimals: 18,
203+ * priceUsd: 2000,
204+ * iconUri: "https://..."
205+ * },
206+ * originAmount: 10000026098875381n,
207+ * destinationAmount: 1000000000000000000n,
208+ * estimatedExecutionTimeMs: 1000
209+ * transactions: [
210+ * {
211+ * action: "approval",
212+ * id: "0x",
213+ * to: "0x...",
214+ * data: "0x...",
215+ * chainId: 10,
216+ * type: "eip1559"
217+ * },
218+ * {
219+ * action: "buy",
220+ * to: "0x...",
221+ * value: 10000026098875381n,
222+ * data: "0x...",
223+ * chainId: 10,
224+ * type: "eip1559"
225+ * }
226+ * ]
167227 * }
168228 * ],
169229 * expiration: 1741730936680,
170230 * intent: {
171231 * originChainId: 1,
172- * originTokenAddress: NATIVE_TOKEN_ADDRESS ,
232+ * originTokenAddress: "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE" ,
173233 * destinationChainId: 10,
174- * destinationTokenAddress: NATIVE_TOKEN_ADDRESS ,
175- * buyAmountWei : 1000000000000000000n
234+ * destinationTokenAddress: "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE" ,
235+ * amount : 1000000000000000000n
176236 * }
177237 * }
178238 * ```
@@ -192,12 +252,12 @@ export declare namespace quote {
192252 * @param options.originTokenAddress - The address of the origin token.
193253 * @param options.destinationChainId - The chain ID of the destination token.
194254 * @param options.destinationTokenAddress - The address of the destination token.
195- * @param options.buyAmountWei - The amount of the origin token to buy .
255+ * @param options.amount - The amount of the destination token to receive .
196256 * @param options.sender - The address of the sender.
197257 * @param options.receiver - The address of the recipient.
198258 * @param options.client - Your thirdweb client.
199259 *
200- * @returns A promise that resolves to a non- finalized quote for the requested buy.
260+ * @returns A promise that resolves to a finalized quote and transactions for the requested buy.
201261 *
202262 * @throws Will throw an error if there is an issue fetching the quote.
203263 * @bridge Buy
@@ -211,10 +271,10 @@ export async function prepare(
211271 originTokenAddress,
212272 destinationChainId,
213273 destinationTokenAddress,
214- buyAmountWei,
215274 sender,
216275 receiver,
217276 client,
277+ amount,
218278 } = options ;
219279
220280 const clientFetch = getClientFetch ( client ) ;
@@ -223,7 +283,7 @@ export async function prepare(
223283 url . searchParams . set ( "originTokenAddress" , originTokenAddress ) ;
224284 url . searchParams . set ( "destinationChainId" , destinationChainId . toString ( ) ) ;
225285 url . searchParams . set ( "destinationTokenAddress" , destinationTokenAddress ) ;
226- url . searchParams . set ( "buyAmountWei" , buyAmountWei . toString ( ) ) ;
286+ url . searchParams . set ( "buyAmountWei" , amount . toString ( ) ) ;
227287 url . searchParams . set ( "sender" , sender ) ;
228288 url . searchParams . set ( "receiver" , receiver ) ;
229289
@@ -242,19 +302,21 @@ export async function prepare(
242302 blockNumber : data . blockNumber ? BigInt ( data . blockNumber ) : undefined ,
243303 timestamp : data . timestamp ,
244304 estimatedExecutionTimeMs : data . estimatedExecutionTimeMs ,
245- transactions : data . transactions . map ( ( transaction ) => ( {
246- ...transaction ,
247- value : transaction . value ? BigInt ( transaction . value ) : undefined ,
248- client,
249- chain : defineChain ( transaction . chainId ) ,
305+ steps : data . steps . map ( ( step ) => ( {
306+ ...step ,
307+ transactions : step . transactions . map ( ( transaction ) => ( {
308+ ...transaction ,
309+ value : transaction . value ? BigInt ( transaction . value ) : undefined ,
310+ client,
311+ chain : defineChain ( transaction . chainId ) ,
312+ } ) ) ,
250313 } ) ) ,
251- expiration : data . expiration ,
252314 intent : {
253315 originChainId,
254316 originTokenAddress,
255317 destinationChainId,
256318 destinationTokenAddress,
257- buyAmountWei ,
319+ amount ,
258320 } ,
259321 } ;
260322}
@@ -265,9 +327,9 @@ export declare namespace prepare {
265327 originTokenAddress : ox__Address . Address ;
266328 destinationChainId : number ;
267329 destinationTokenAddress : ox__Address . Address ;
268- buyAmountWei : bigint ;
269330 sender : ox__Address . Address ;
270331 receiver : ox__Address . Address ;
332+ amount : bigint ;
271333 client : ThirdwebClient ;
272334 } ;
273335
@@ -277,7 +339,7 @@ export declare namespace prepare {
277339 originTokenAddress : ox__Address . Address ;
278340 destinationChainId : number ;
279341 destinationTokenAddress : ox__Address . Address ;
280- buyAmountWei : bigint ;
342+ amount : bigint ;
281343 } ;
282344 } ;
283345}
0 commit comments