Skip to content

Commit efc4687

Browse files
gregfromstlclaude
andcommitted
[SDK] Feature: Switch buyWithCrypto to Universal Bridge service
- Changes the behavior of buyWithCrypto to use the Universal Bridge service instead of the legacy API - Updates getQuote and getTransfer implementation to use Bridge.Buy and Bridge.Sell - Adds a new Transfer module to the Bridge namespace for token transfers - Removes the legacy API endpoints from definitions.ts 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent ba52e68 commit efc4687

File tree

8 files changed

+339
-203
lines changed

8 files changed

+339
-203
lines changed

packages/thirdweb/src/bridge/Buy.ts

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ export async function quote(options: quote.Options): Promise<quote.Result> {
119119
url.searchParams.set("destinationChainId", destinationChainId.toString());
120120
url.searchParams.set("destinationTokenAddress", destinationTokenAddress);
121121
url.searchParams.set("buyAmountWei", amount.toString());
122+
url.searchParams.set("amount", amount.toString());
122123
if (maxSteps) {
123124
url.searchParams.set("maxSteps", maxSteps.toString());
124125
}
@@ -199,7 +200,7 @@ export declare namespace quote {
199200
* This will return a quote that might look like:
200201
* ```typescript
201202
* {
202-
* originAmount: 10000026098875381n,
203+
* originAmount: 2000030000n,
203204
* destinationAmount: 1000000000000000000n,
204205
* blockNumber: 22026509n,
205206
* timestamp: 1741730936680,
@@ -208,11 +209,11 @@ export declare namespace quote {
208209
* {
209210
* originToken: {
210211
* chainId: 1,
211-
* address: "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE",
212-
* symbol: "ETH",
213-
* name: "Ethereum",
214-
* decimals: 18,
215-
* priceUsd: 2000,
212+
* address: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
213+
* symbol: "USDC",
214+
* name: "USDC",
215+
* decimals: 6,
216+
* priceUsd: 1,
216217
* iconUri: "https://..."
217218
* },
218219
* destinationToken: {
@@ -224,7 +225,7 @@ export declare namespace quote {
224225
* priceUsd: 2000,
225226
* iconUri: "https://..."
226227
* },
227-
* originAmount: 10000026098875381n,
228+
* originAmount: 2000030000n,
228229
* destinationAmount: 1000000000000000000n,
229230
* estimatedExecutionTimeMs: 1000
230231
* transactions: [
@@ -250,7 +251,7 @@ export declare namespace quote {
250251
* expiration: 1741730936680,
251252
* intent: {
252253
* originChainId: 1,
253-
* originTokenAddress: "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE",
254+
* originTokenAddress: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
254255
* destinationChainId: 10,
255256
* destinationTokenAddress: "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE",
256257
* amount: 1000000000000000000n
@@ -342,7 +343,8 @@ export async function prepare(
342343
"Content-Type": "application/json",
343344
},
344345
body: stringify({
345-
buyAmountWei: amount.toString(),
346+
buyAmountWei: amount.toString(), // legacy
347+
amount: amount.toString(),
346348
originChainId: originChainId.toString(),
347349
originTokenAddress,
348350
destinationChainId: destinationChainId.toString(),
@@ -382,6 +384,8 @@ export async function prepare(
382384
destinationChainId,
383385
destinationTokenAddress,
384386
amount,
387+
sender,
388+
receiver,
385389
},
386390
};
387391
}
@@ -407,6 +411,8 @@ export declare namespace prepare {
407411
destinationChainId: number;
408412
destinationTokenAddress: ox__Address.Address;
409413
amount: bigint;
414+
sender: ox__Address.Address;
415+
receiver: ox__Address.Address;
410416
purchaseData?: unknown;
411417
};
412418
};

packages/thirdweb/src/bridge/Sell.ts

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ export async function quote(options: quote.Options): Promise<quote.Result> {
118118
url.searchParams.set("destinationChainId", destinationChainId.toString());
119119
url.searchParams.set("destinationTokenAddress", destinationTokenAddress);
120120
url.searchParams.set("sellAmountWei", amount.toString());
121+
url.searchParams.set("amount", amount.toString());
121122
if (typeof maxSteps !== "undefined") {
122123
url.searchParams.set("maxSteps", maxSteps.toString());
123124
}
@@ -190,7 +191,7 @@ export declare namespace quote {
190191
* This will return a quote that might look like:
191192
* ```typescript
192193
* {
193-
* originAmount: 1000000000000000000n,
194+
* originAmount: 2000000000n,
194195
* destinationAmount: 9980000000000000000n,
195196
* blockNumber: 22026509n,
196197
* timestamp: 1741730936680,
@@ -199,11 +200,11 @@ export declare namespace quote {
199200
* {
200201
* originToken: {
201202
* chainId: 1,
202-
* address: "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE",
203-
* symbol: "ETH",
204-
* name: "Ethereum",
205-
* decimals: 18,
206-
* priceUsd: 2000,
203+
* address: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
204+
* symbol: "USDC",
205+
* name: "USDC",
206+
* decimals: 6,
207+
* priceUsd: 1,
207208
* iconUri: "https://..."
208209
* },
209210
* destinationToken: {
@@ -215,7 +216,7 @@ export declare namespace quote {
215216
* priceUsd: 2000,
216217
* iconUri: "https://..."
217218
* },
218-
* originAmount: 1000000000000000000n,
219+
* originAmount: 2000000000n,
219220
* destinationAmount: 9980000000000000000n,
220221
* estimatedExecutionTimeMs: 1000
221222
* }
@@ -241,10 +242,10 @@ export declare namespace quote {
241242
* expiration: 1741730936680,
242243
* intent: {
243244
* originChainId: 1,
244-
* originTokenAddress: NATIVE_TOKEN_ADDRESS,
245+
* originTokenAddress: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
245246
* destinationChainId: 10,
246-
* destinationTokenAddress: NATIVE_TOKEN_ADDRESS,
247-
* amount: 1000000000000000000n
247+
* destinationTokenAddress: "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE",
248+
* amount: 2000000000n
248249
* }
249250
* }
250251
* ```
@@ -334,6 +335,7 @@ export async function prepare(
334335
},
335336
body: stringify({
336337
sellAmountWei: amount.toString(),
338+
amount: amount.toString(),
337339
originChainId: originChainId.toString(),
338340
originTokenAddress,
339341
destinationChainId: destinationChainId.toString(),
@@ -374,6 +376,8 @@ export async function prepare(
374376
destinationChainId,
375377
destinationTokenAddress,
376378
amount,
379+
sender,
380+
receiver,
377381
purchaseData,
378382
},
379383
};
@@ -400,6 +404,8 @@ export declare namespace prepare {
400404
destinationChainId: number;
401405
destinationTokenAddress: ox__Address.Address;
402406
amount: bigint;
407+
sender: ox__Address.Address;
408+
receiver: ox__Address.Address;
403409
purchaseData?: unknown;
404410
};
405411
};

packages/thirdweb/src/bridge/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
export * as Buy from "./Buy.js";
22
export * as Sell from "./Sell.js";
3+
export * as Transfer from "./Transfer.js";
34
export { status } from "./Status.js";
45
export { routes } from "./Routes.js";
56
export { chains } from "./Chains.js";

packages/thirdweb/src/pay/buyWithCrypto/commonTypes.ts

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,6 @@ export type QuoteTokenInfo = {
1010
symbol?: string;
1111
};
1212

13-
export type QuoteTransactionRequest = {
14-
data: string;
15-
to: string;
16-
value: string;
17-
from: string;
18-
chainId: number;
19-
gasPrice: string;
20-
gasLimit: string;
21-
};
22-
2313
export type QuoteApprovalInfo = {
2414
chainId: number;
2515
tokenAddress: string;

0 commit comments

Comments
 (0)