Skip to content

Commit 1b00833

Browse files
committed
Merge branch 'greg/tool-4506-update-routes-endpoint' of https://github.com/thirdweb-dev/js into greg/tool-4506-update-routes-endpoint
2 parents abd77ec + 727d0e9 commit 1b00833

File tree

14 files changed

+234
-65
lines changed

14 files changed

+234
-65
lines changed

packages/thirdweb/src/bridge/Buy.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import type { Address as ox__Address } from "ox";
22
import { defineChain } from "../chains/utils.js";
33
import type { ThirdwebClient } from "../client/client.js";
4+
import { getThirdwebBaseUrl } from "../utils/domains.js";
45
import { getClientFetch } from "../utils/fetch.js";
56
import { stringify } from "../utils/json.js";
6-
import { UNIVERSAL_BRIDGE_URL } from "./constants.js";
77
import type { PreparedQuote, Quote } from "./types/Quote.js";
88

99
/**
@@ -113,7 +113,7 @@ export async function quote(options: quote.Options): Promise<quote.Result> {
113113
"buyAmountWei" in options ? options.buyAmountWei : options.amount;
114114

115115
const clientFetch = getClientFetch(client);
116-
const url = new URL(`${UNIVERSAL_BRIDGE_URL}/buy/quote`);
116+
const url = new URL(`${getThirdwebBaseUrl("bridge")}/v1/buy/quote`);
117117
url.searchParams.set("originChainId", originChainId.toString());
118118
url.searchParams.set("originTokenAddress", originTokenAddress);
119119
url.searchParams.set("destinationChainId", destinationChainId.toString());
@@ -335,7 +335,7 @@ export async function prepare(
335335
} = options;
336336

337337
const clientFetch = getClientFetch(client);
338-
const url = new URL(`${UNIVERSAL_BRIDGE_URL}/buy/prepare`);
338+
const url = new URL(`${getThirdwebBaseUrl("bridge")}/v1/buy/prepare`);
339339

340340
const response = await clientFetch(url.toString(), {
341341
method: "POST",

packages/thirdweb/src/bridge/Chains.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { ThirdwebClient } from "../client/client.js";
2+
import { getThirdwebBaseUrl } from "../utils/domains.js";
23
import { getClientFetch } from "../utils/fetch.js";
3-
import { UNIVERSAL_BRIDGE_URL } from "./constants.js";
44
import type { Chain } from "./types/Chain.js";
55

66
/**
@@ -54,7 +54,7 @@ export async function chains(options: chains.Options): Promise<chains.Result> {
5454
const { client } = options;
5555

5656
const clientFetch = getClientFetch(client);
57-
const url = new URL(`${UNIVERSAL_BRIDGE_URL}/chains`);
57+
const url = new URL(`${getThirdwebBaseUrl("bridge")}/v1/chains`);
5858

5959
const response = await clientFetch(url.toString());
6060
if (!response.ok) {

packages/thirdweb/src/bridge/Routes.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { Address as ox__Address, Hex as ox__Hex } from "ox";
22
import type { ThirdwebClient } from "../client/client.js";
3+
import { getThirdwebBaseUrl } from "../utils/domains.js";
34
import { getClientFetch } from "../utils/fetch.js";
4-
import { UNIVERSAL_BRIDGE_URL } from "./constants.js";
55
import type { Route } from "./types/Route.js";
66

77
/**
@@ -133,7 +133,7 @@ export async function routes(options: routes.Options): Promise<routes.Result> {
133133
} = options;
134134

135135
const clientFetch = getClientFetch(client);
136-
const url = new URL(`${UNIVERSAL_BRIDGE_URL}/routes`);
136+
const url = new URL(`${getThirdwebBaseUrl("bridge")}/v1/routes`);
137137
if (originChainId) {
138138
url.searchParams.set("originChainId", originChainId.toString());
139139
}

packages/thirdweb/src/bridge/Sell.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import type { Address as ox__Address } from "ox";
22
import { defineChain } from "../chains/utils.js";
33
import type { ThirdwebClient } from "../client/client.js";
4+
import { getThirdwebBaseUrl } from "../utils/domains.js";
45
import { getClientFetch } from "../utils/fetch.js";
56
import { stringify } from "../utils/json.js";
6-
import { UNIVERSAL_BRIDGE_URL } from "./constants.js";
77
import type { PreparedQuote, Quote } from "./types/Quote.js";
88

99
/**
@@ -112,7 +112,7 @@ export async function quote(options: quote.Options): Promise<quote.Result> {
112112
} = options;
113113

114114
const clientFetch = getClientFetch(client);
115-
const url = new URL(`${UNIVERSAL_BRIDGE_URL}/sell/quote`);
115+
const url = new URL(`${getThirdwebBaseUrl("bridge")}/v1/sell/quote`);
116116
url.searchParams.set("originChainId", originChainId.toString());
117117
url.searchParams.set("originTokenAddress", originTokenAddress);
118118
url.searchParams.set("destinationChainId", destinationChainId.toString());
@@ -326,7 +326,7 @@ export async function prepare(
326326
} = options;
327327

328328
const clientFetch = getClientFetch(client);
329-
const url = new URL(`${UNIVERSAL_BRIDGE_URL}/sell/prepare`);
329+
const url = new URL(`${getThirdwebBaseUrl("bridge")}/v1/sell/prepare`);
330330

331331
const response = await clientFetch(url.toString(), {
332332
method: "POST",

packages/thirdweb/src/bridge/Status.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import type { Hex as ox__Hex } from "ox";
22
import type { Chain } from "../chains/types.js";
33
import type { ThirdwebClient } from "../client/client.js";
4+
import { getThirdwebBaseUrl } from "../utils/domains.js";
45
import { getClientFetch } from "../utils/fetch.js";
5-
import { UNIVERSAL_BRIDGE_URL } from "./constants.js";
66
import type { Status } from "./types/Status.js";
77

88
/**
@@ -108,7 +108,7 @@ export async function status(options: status.Options): Promise<status.Result> {
108108
const chainId = "chainId" in options ? options.chainId : options.chain.id;
109109

110110
const clientFetch = getClientFetch(client);
111-
const url = new URL(`${UNIVERSAL_BRIDGE_URL}/status`);
111+
const url = new URL(`${getThirdwebBaseUrl("bridge")}/v1/status`);
112112
url.searchParams.set("transactionHash", transactionHash);
113113
url.searchParams.set("chainId", chainId.toString());
114114

packages/thirdweb/src/bridge/Transfer.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import type { Address as ox__Address } from "ox";
22
import { defineChain } from "../chains/utils.js";
33
import type { ThirdwebClient } from "../client/client.js";
4+
import { getThirdwebBaseUrl } from "../utils/domains.js";
45
import { getClientFetch } from "../utils/fetch.js";
56
import { stringify } from "../utils/json.js";
6-
import { UNIVERSAL_BRIDGE_URL } from "./constants.js";
77
import type { PreparedQuote } from "./types/Quote.js";
88

99
/**
@@ -192,7 +192,7 @@ export async function prepare(
192192
} = options;
193193

194194
const clientFetch = getClientFetch(client);
195-
const url = new URL(`${UNIVERSAL_BRIDGE_URL}/transfer/prepare`);
195+
const url = new URL(`${getThirdwebBaseUrl("bridge")}/v1/transfer/prepare`);
196196

197197
const response = await clientFetch(url.toString(), {
198198
method: "POST",

packages/thirdweb/src/bridge/constants.ts

Lines changed: 0 additions & 10 deletions
This file was deleted.

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

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { Value } from "ox";
2+
import * as ox__AbiFunction from "ox/AbiFunction";
23
import * as Bridge from "../../bridge/index.js";
34
import { getCachedChain } from "../../chains/utils.js";
45
import type { ThirdwebClient } from "../../client/client.js";
@@ -260,14 +261,22 @@ export async function getBuyWithCryptoQuote(
260261
);
261262
}
262263

263-
const approvalData: QuoteApprovalInfo | undefined = approvalTx
264-
? {
265-
chainId: firstStep.originToken.chainId,
266-
tokenAddress: firstStep.originToken.address,
267-
spenderAddress: approvalTx.to,
268-
amountWei: quote.originAmount.toString(),
269-
}
270-
: undefined;
264+
let approvalData: QuoteApprovalInfo | undefined;
265+
if (approvalTx) {
266+
const abiFunction = ox__AbiFunction.from([
267+
"function approve(address spender, uint256 amount)",
268+
]);
269+
const [spender, amount] = ox__AbiFunction.decodeData(
270+
abiFunction,
271+
approvalTx.data,
272+
);
273+
approvalData = {
274+
chainId: firstStep.originToken.chainId,
275+
tokenAddress: firstStep.originToken.address,
276+
spenderAddress: spender,
277+
amountWei: amount.toString(),
278+
};
279+
}
271280

272281
const swapRoute: BuyWithCryptoQuote = {
273282
transactionRequest: {
@@ -341,7 +350,7 @@ export async function getBuyWithCryptoQuote(
341350
slippageBPS: 0,
342351
feesUSDCents: 0,
343352
gasCostUSDCents: 0,
344-
durationSeconds: 0,
353+
durationSeconds: firstStep.estimatedExecutionTimeMs / 1000,
345354
},
346355

347356
maxSlippageBPS: 0,

0 commit comments

Comments
 (0)