Skip to content

Commit 5788cbd

Browse files
[SDK] Feature: Adds action field to Bridge transactions (#6613)
Signed-off-by: greg <[email protected]> Co-authored-by: graphite-app[bot] <96075541+graphite-app[bot]@users.noreply.github.com>
1 parent d9a39cd commit 5788cbd

File tree

6 files changed

+84
-23
lines changed

6 files changed

+84
-23
lines changed

.changeset/curvy-paths-burn.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"thirdweb": patch
3+
---
4+
5+
Adds transaction `action` fields to Bridge responses. This includes and necessary approval transactions.n

packages/thirdweb/src/bridge/Buy.ts

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type { Address as ox__Address } from "ox";
2+
import { defineChain } from "../chains/utils.js";
23
import type { ThirdwebClient } from "../client/client.js";
34
import { getClientFetch } from "../utils/fetch.js";
45
import { UNIVERSAL_BRIDGE_URL } from "./constants.js";
@@ -147,9 +148,18 @@ export declare namespace quote {
147148
* estimatedExecutionTimeMs: 1000
148149
* transactions: [
149150
* {
150-
* to: NATIVE_TOKEN_ADDRESS,
151+
* action: "approval",
152+
* id: "0x",
153+
* to: "0x...",
154+
* data: "0x...",
155+
* chainId: 10,
156+
* type: "eip1559"
157+
* },
158+
* {
159+
* action: "buy",
160+
* to: "0x...",
151161
* value: 10000026098875381n,
152-
* data: "0x",
162+
* data: "0x...",
153163
* chainId: 10,
154164
* type: "eip1559"
155165
* }
@@ -167,11 +177,11 @@ export declare namespace quote {
167177
*
168178
* ## Sending the transactions
169179
* 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:
170-
* - Approvals and other preparation transactions are not included in the transactions array.
180+
* - Approvals will have the `approval` action specified. You can perform approvals with `sendAndConfirmTransaction`, then proceed to the next transaction.
171181
* - 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.
172182
* - If an `expiration` timestamp is provided, all transactions must be executed before that time to guarantee successful execution at the specified price.
173183
*
174-
* 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.
184+
* 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.
175185
*
176186
* You can access this functions input and output types with `Buy.prepare.Options` and `Buy.prepare.Result`, respectively.
177187
*
@@ -231,6 +241,8 @@ export async function prepare(
231241
transactions: data.transactions.map((transaction) => ({
232242
...transaction,
233243
value: transaction.value ? BigInt(transaction.value) : undefined,
244+
client,
245+
chain: defineChain(transaction.chainId),
234246
})),
235247
expiration: data.expiration,
236248
intent: {

packages/thirdweb/src/bridge/Sell.ts

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type { Address as ox__Address } from "ox";
2+
import { defineChain } from "../chains/utils.js";
23
import type { ThirdwebClient } from "../client/client.js";
34
import { getClientFetch } from "../utils/fetch.js";
45
import { UNIVERSAL_BRIDGE_URL } from "./constants.js";
@@ -147,9 +148,19 @@ export declare namespace quote {
147148
* estimatedExecutionTimeMs: 1000
148149
* transactions: [
149150
* {
150-
* to: NATIVE_TOKEN_ADDRESS,
151+
* id: "0x...",
152+
* action: "approval",
153+
* to: "0x...",
154+
* data: "0x...",
155+
* chainId: 10,
156+
* type: "eip1559"
157+
* },
158+
* {
159+
* id: "0x...",
160+
* action: "sell",
161+
* to: "0x...",
151162
* value: 9980000000000000000n,
152-
* data: "0x",
163+
* data: "0x...",
153164
* chainId: 10,
154165
* type: "eip1559"
155166
* }
@@ -167,11 +178,11 @@ export declare namespace quote {
167178
*
168179
* ## Sending the transactions
169180
* 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:
170-
* - Approvals and other preparation transactions are not included in the transactions array.
181+
* - Approvals will have the `approval` action specified. You can perform approvals with `sendAndConfirmTransaction`, then proceed to the next transaction.
171182
* - 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.
172183
* - If an `expiration` timestamp is provided, all transactions must be executed before that time to guarantee successful execution at the specified price.
173184
*
174-
* 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.
185+
* 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.
175186
*
176187
* You can access this functions input and output types with `Sell.prepare.Options` and `Sell.prepare.Result`, respectively.
177188
*
@@ -231,6 +242,8 @@ export async function prepare(
231242
transactions: data.transactions.map((transaction) => ({
232243
...transaction,
233244
value: transaction.value ? BigInt(transaction.value) : undefined,
245+
client,
246+
chain: defineChain(transaction.chainId),
234247
})),
235248
expiration: data.expiration,
236249
intent: {

packages/thirdweb/src/bridge/Status.test.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { describe, expect, it } from "vitest";
22
import { TEST_CLIENT } from "~test/test-clients.js";
3+
import { defineChain } from "../chains/utils.js";
34
import { status } from "./Status.js";
45

56
describe.runIf(process.env.TW_SECRET_KEY)("Bridge.status", () => {
@@ -35,4 +36,16 @@ describe.runIf(process.env.TW_SECRET_KEY)("Bridge.status", () => {
3536
}
3637
`);
3738
});
39+
40+
it("should handle successfull status with chain", async () => {
41+
const result = await status({
42+
transactionHash:
43+
"0xe199ef82a0b6215221536e18ec512813c1aa10b4f5ed0d4dfdfcd703578da56d",
44+
chain: defineChain(8453),
45+
client: TEST_CLIENT,
46+
});
47+
48+
expect(result).toBeDefined();
49+
expect(result.status).toBe("COMPLETED");
50+
});
3851
});

packages/thirdweb/src/bridge/Status.ts

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type { Hex as ox__Hex } from "ox";
2+
import type { Chain } from "../chains/types.js";
23
import type { ThirdwebClient } from "../client/client.js";
34
import { getClientFetch } from "../utils/fetch.js";
45
import { UNIVERSAL_BRIDGE_URL } from "./constants.js";
@@ -100,7 +101,8 @@ import type { Status } from "./types/Status.js";
100101
* @beta
101102
*/
102103
export async function status(options: status.Options): Promise<status.Result> {
103-
const { transactionHash, chainId, client } = options;
104+
const { transactionHash, client } = options;
105+
const chainId = "chainId" in options ? options.chainId : options.chain.id;
104106

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

155157
export declare namespace status {
156-
type Options = {
157-
transactionHash: ox__Hex.Hex;
158-
chainId: number;
159-
client: ThirdwebClient;
160-
};
158+
type Options =
159+
| {
160+
transactionHash: ox__Hex.Hex;
161+
chainId: number;
162+
client: ThirdwebClient;
163+
}
164+
| {
165+
transactionHash: ox__Hex.Hex;
166+
chain: Chain;
167+
client: ThirdwebClient;
168+
};
161169

162170
type Result = Status;
163171
}

packages/thirdweb/src/bridge/types/Quote.ts

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
import type { TransactionEnvelopeEip1559 as ox__TransactionEnvelopeEip1559 } from "ox";
1+
import type { Hex as ox__Hex } from "ox";
2+
import type { Chain } from "../../chains/types.js";
3+
import type { ThirdwebClient } from "../../client/client.js";
24

35
export type Quote = {
46
/**
@@ -31,12 +33,20 @@ export type PreparedQuote = Quote & {
3133
/**
3234
* A series of [ox](https://oxlib.sh) EIP-1559 transactions that must be executed in sequential order to fulfill the complete route.
3335
*/
34-
transactions: Array<
35-
ox__TransactionEnvelopeEip1559.TransactionEnvelopeEip1559<
36-
false,
37-
bigint,
38-
number,
39-
"eip1559"
40-
>
41-
>;
36+
transactions: Array<{
37+
data: ox__Hex.Hex;
38+
to: ox__Hex.Hex;
39+
value?: bigint | undefined;
40+
chainId: number;
41+
/**
42+
* The action this transaction performs. This can be "approval", "transfer", "buy", or "sell".
43+
*/
44+
action: "approval" | "transfer" | "buy" | "sell";
45+
/**
46+
* The transaction ID, used for tracking purposes.
47+
*/
48+
id: ox__Hex.Hex;
49+
client: ThirdwebClient;
50+
chain: Chain;
51+
}>;
4252
};

0 commit comments

Comments
 (0)