Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/curvy-paths-burn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"thirdweb": patch
---

Adds transaction `action` fields to Bridge responses. This includes and necessary approval transactions.n
20 changes: 16 additions & 4 deletions packages/thirdweb/src/bridge/Buy.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { Address as ox__Address } from "ox";
import { defineChain } from "../chains/utils.js";
import type { ThirdwebClient } from "../client/client.js";
import { getClientFetch } from "../utils/fetch.js";
import { UNIVERSAL_BRIDGE_URL } from "./constants.js";
Expand Down Expand Up @@ -147,9 +148,18 @@ export declare namespace quote {
* estimatedExecutionTimeMs: 1000
* transactions: [
* {
* to: NATIVE_TOKEN_ADDRESS,
* action: "approval",
* id: "0x",
* to: "0x...",
* data: "0x...",
* chainId: 10,
* type: "eip1559"
* },
* {
* action: "buy",
* to: "0x...",
* value: 10000026098875381n,
* data: "0x",
* data: "0x...",
* chainId: 10,
* type: "eip1559"
* }
Expand All @@ -167,11 +177,11 @@ export declare namespace quote {
*
* ## Sending the transactions
* The `transactions` array is a series of [ox](https://oxlib.sh) EIP-1559 transactions that must be executed one after the other in order to fulfill the complete route. There are a few things to keep in mind when executing these transactions:
* - Approvals and other preparation transactions are not included in the transactions array.
* - Approvals will have the `approval` action specified. You can perform approvals with `sendAndConfirmTransaction`, then proceed to the next transaction.
* - All transactions are assumed to be executed by the `sender` address, regardless of which chain they are on. The final transaction will use the `receiver` as the recipient address.
* - If an `expiration` timestamp is provided, all transactions must be executed before that time to guarantee successful execution at the specified price.
*
* NOTE: To get the status of each transaction, use `Bridge.status` rather than checking for transaction inclusion. This function will ensure full bridge completion on the destination chain.
* NOTE: To get the status of each non-approval transaction, use `Bridge.status` rather than checking for transaction inclusion. This function will ensure full bridge completion on the destination chain.
*
* You can access this functions input and output types with `Buy.prepare.Options` and `Buy.prepare.Result`, respectively.
*
Expand Down Expand Up @@ -231,6 +241,8 @@ export async function prepare(
transactions: data.transactions.map((transaction) => ({
...transaction,
value: transaction.value ? BigInt(transaction.value) : undefined,
client,
chain: defineChain(transaction.chainId),
})),
expiration: data.expiration,
intent: {
Expand Down
21 changes: 17 additions & 4 deletions packages/thirdweb/src/bridge/Sell.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { Address as ox__Address } from "ox";
import { defineChain } from "../chains/utils.js";
import type { ThirdwebClient } from "../client/client.js";
import { getClientFetch } from "../utils/fetch.js";
import { UNIVERSAL_BRIDGE_URL } from "./constants.js";
Expand Down Expand Up @@ -147,9 +148,19 @@ export declare namespace quote {
* estimatedExecutionTimeMs: 1000
* transactions: [
* {
* to: NATIVE_TOKEN_ADDRESS,
* id: "0x...",
* action: "approval",
* to: "0x...",
* data: "0x...",
* chainId: 10,
* type: "eip1559"
* },
* {
* id: "0x...",
* action: "sell",
* to: "0x...",
* value: 9980000000000000000n,
* data: "0x",
* data: "0x...",
* chainId: 10,
* type: "eip1559"
* }
Expand All @@ -167,11 +178,11 @@ export declare namespace quote {
*
* ## Sending the transactions
* The `transactions` array is a series of [ox](https://oxlib.sh) EIP-1559 transactions that must be executed one after the other in order to fulfill the complete route. There are a few things to keep in mind when executing these transactions:
* - Approvals and other preparation transactions are not included in the transactions array.
* - Approvals will have the `approval` action specified. You can perform approvals with `sendAndConfirmTransaction`, then proceed to the next transaction.
* - All transactions are assumed to be executed by the `sender` address, regardless of which chain they are on. The final transaction will use the `receiver` as the recipient address.
* - If an `expiration` timestamp is provided, all transactions must be executed before that time to guarantee successful execution at the specified price.
*
* NOTE: To get the status of each transaction, use `Bridge.status` rather than checking for transaction inclusion. This function will ensure full bridge completion on the destination chain.
* NOTE: To get the status of each non-approval transaction, use `Bridge.status` rather than checking for transaction inclusion. This function will ensure full bridge completion on the destination chain.
*
* You can access this functions input and output types with `Sell.prepare.Options` and `Sell.prepare.Result`, respectively.
*
Expand Down Expand Up @@ -231,6 +242,8 @@ export async function prepare(
transactions: data.transactions.map((transaction) => ({
...transaction,
value: transaction.value ? BigInt(transaction.value) : undefined,
client,
chain: defineChain(transaction.chainId),
})),
expiration: data.expiration,
intent: {
Expand Down
13 changes: 13 additions & 0 deletions packages/thirdweb/src/bridge/Status.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { describe, expect, it } from "vitest";
import { TEST_CLIENT } from "~test/test-clients.js";
import { defineChain } from "../chains/utils.js";
import { status } from "./Status.js";

describe.runIf(process.env.TW_SECRET_KEY)("Bridge.status", () => {
Expand Down Expand Up @@ -35,4 +36,16 @@ describe.runIf(process.env.TW_SECRET_KEY)("Bridge.status", () => {
}
`);
});

it("should handle successfull status with chain", async () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a typo in the test description - "successfull" should be "successful".

Suggested change
it("should handle successfull status with chain", async () => {
it("should handle successful status with chain", async () => {

Spotted by Diamond

Is this helpful? React 👍 or 👎 to let us know.

const result = await status({
transactionHash:
"0xe199ef82a0b6215221536e18ec512813c1aa10b4f5ed0d4dfdfcd703578da56d",
chain: defineChain(8453),
client: TEST_CLIENT,
});

expect(result).toBeDefined();
expect(result.status).toBe("COMPLETED");
});
});
20 changes: 14 additions & 6 deletions packages/thirdweb/src/bridge/Status.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { Hex as ox__Hex } from "ox";
import type { Chain } from "../chains/types.js";
import type { ThirdwebClient } from "../client/client.js";
import { getClientFetch } from "../utils/fetch.js";
import { UNIVERSAL_BRIDGE_URL } from "./constants.js";
Expand Down Expand Up @@ -100,7 +101,8 @@ import type { Status } from "./types/Status.js";
* @beta
*/
export async function status(options: status.Options): Promise<status.Result> {
const { transactionHash, chainId, client } = options;
const { transactionHash, client } = options;
const chainId = "chainId" in options ? options.chainId : options.chain.id;

const clientFetch = getClientFetch(client);
const url = new URL(`${UNIVERSAL_BRIDGE_URL}/status`);
Expand Down Expand Up @@ -153,11 +155,17 @@ export async function status(options: status.Options): Promise<status.Result> {
}

export declare namespace status {
type Options = {
transactionHash: ox__Hex.Hex;
chainId: number;
client: ThirdwebClient;
};
type Options =
| {
transactionHash: ox__Hex.Hex;
chainId: number;
client: ThirdwebClient;
}
| {
transactionHash: ox__Hex.Hex;
chain: Chain;
client: ThirdwebClient;
};

type Result = Status;
}
28 changes: 19 additions & 9 deletions packages/thirdweb/src/bridge/types/Quote.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import type { TransactionEnvelopeEip1559 as ox__TransactionEnvelopeEip1559 } from "ox";
import type { Hex as ox__Hex } from "ox";
import type { Chain } from "../../chains/types.js";
import type { ThirdwebClient } from "../../client/client.js";

export type Quote = {
/**
Expand Down Expand Up @@ -31,12 +33,20 @@ export type PreparedQuote = Quote & {
/**
* A series of [ox](https://oxlib.sh) EIP-1559 transactions that must be executed in sequential order to fulfill the complete route.
*/
transactions: Array<
ox__TransactionEnvelopeEip1559.TransactionEnvelopeEip1559<
false,
bigint,
number,
"eip1559"
>
>;
transactions: Array<{
data: ox__Hex.Hex;
to: ox__Hex.Hex;
value?: bigint | undefined;
chainId: number;
/**
* The action this transaction performs. This can be "approval", "transfer", "buy", or "sell".
*/
action: "approval" | "transfer" | "buy" | "sell";
/**
* The transaction ID, used for tracking purposes.
*/
id: ox__Hex.Hex;
client: ThirdwebClient;
chain: Chain;
}>;
};