Skip to content

Commit e526f75

Browse files
committed
[SDK] Feature: Update sdk bridge functions with new schema (#6830)
<!-- ## title your PR with this format: "[SDK/Dashboard/Portal] Feature/Fix: Concise title for the changes" If you did not copy the branch name from Linear, paste the issue tag here (format is TEAM-0000): ## Notes for the reviewer Anything important to call out? Be sure to also clarify these in your comments. ## How to test Unit tests, playground, etc. --> <!-- start pr-codex --> --- ## PR-Codex overview This PR enhances the SDK Bridge functionality by standardizing parameter naming, introducing a `purchaseData` field, and improving quote structures with a `steps` array. It also updates API interactions to use JSON bodies for complex data. ### Detailed summary - Standardized parameter naming: `buyAmountWei` and `sellAmountWei` changed to `amount`. - Added optional `purchaseData` parameter to Buy and Sell functions. - Introduced `steps` array in quotes for detailed transaction information. - Enhanced status responses to include `purchaseData`. - Updated API interactions to use JSON body instead of query parameters for prepare functions. > ✨ Ask PR-Codex anything about this PR by commenting with `/codex {your question}` <!-- end pr-codex -->
1 parent f912e42 commit e526f75

File tree

10 files changed

+462
-137
lines changed

10 files changed

+462
-137
lines changed

.changeset/fluffy-pigs-drive.md

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
---
2+
"thirdweb": minor
3+
---
4+
5+
Enhanced SDK Bridge functionality with the following key updates:
6+
7+
1. **Breaking Change:** Standardized parameter naming in bridge functions:
8+
- Changed `buyAmountWei` to `amount` in Buy functions
9+
- Changed `sellAmountWei` to `amount` in Sell functions
10+
11+
Example:
12+
```ts
13+
// Before
14+
const buyQuote = await buy.quote({
15+
originChainId: 1,
16+
originTokenAddress: NATIVE_TOKEN_ADDRESS,
17+
destinationChainId: 10,
18+
destinationTokenAddress: NATIVE_TOKEN_ADDRESS,
19+
buyAmountWei: toWei("0.01"),
20+
client: thirdwebClient,
21+
});
22+
23+
// After
24+
const buyQuote = await buy.quote({
25+
originChainId: 1,
26+
originTokenAddress: NATIVE_TOKEN_ADDRESS,
27+
destinationChainId: 10,
28+
destinationTokenAddress: NATIVE_TOKEN_ADDRESS,
29+
amount: toWei("0.01"),
30+
client: thirdwebClient,
31+
});
32+
```
33+
34+
2. **Enhanced Quote Structure:** Added `steps` array to buy/sell quote responses with detailed token information:
35+
```ts
36+
// Steps contains detailed information about each step in a cross-chain transaction
37+
steps: [
38+
{
39+
originToken: {
40+
chainId: 1,
41+
address: "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE",
42+
symbol: "ETH",
43+
name: "Ethereum",
44+
decimals: 18,
45+
priceUsd: 2000,
46+
iconUri: "https://..."
47+
},
48+
destinationToken: {
49+
chainId: 10,
50+
address: "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE",
51+
symbol: "ETH",
52+
name: "Ethereum",
53+
decimals: 18,
54+
priceUsd: 2000,
55+
iconUri: "https://..."
56+
},
57+
originAmount: 1000000000000000000n,
58+
destinationAmount: 9980000000000000000n,
59+
estimatedExecutionTimeMs: 1000,
60+
transactions: [/* transactions for this step */]
61+
}
62+
]
63+
```
64+
65+
3. **Added Purchase Data Support:** Added optional `purchaseData` parameter to Buy and Sell functions:
66+
```ts
67+
// Example with purchaseData
68+
const quote = await buy.prepare({
69+
originChainId: 1,
70+
originTokenAddress: NATIVE_TOKEN_ADDRESS,
71+
destinationChainId: 10,
72+
destinationTokenAddress: NATIVE_TOKEN_ADDRESS,
73+
amount: toWei("0.01"),
74+
sender: "0x2a4f24F935Eb178e3e7BA9B53A5Ee6d8407C0709",
75+
receiver: "0x2a4f24F935Eb178e3e7BA9B53A5Ee6d8407C0709",
76+
purchaseData: {
77+
foo: "bar",
78+
},
79+
client: thirdwebClient,
80+
});
81+
```
82+
83+
4. **Enhanced Status Responses:** Status responses now include the `purchaseData` field that was provided during the initial transaction:
84+
```ts
85+
// Status response includes purchaseData
86+
{
87+
status: "COMPLETED",
88+
// ...other status fields
89+
purchaseData: {
90+
foo: "bar"
91+
}
92+
}
93+
```
94+
95+
5. **Updated API Interactions:** Changed from query parameters to JSON body for prepare functions to accommodate complex data.

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

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,14 @@ describe.runIf(process.env.TW_SECRET_KEY)("Bridge.Buy.quote", () => {
1010
originTokenAddress: "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE",
1111
destinationChainId: 10,
1212
destinationTokenAddress: "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE",
13-
buyAmountWei: toWei("0.01"),
13+
amount: toWei("0.01"),
1414
client: TEST_CLIENT,
1515
});
1616

1717
expect(quote).toBeDefined();
1818
expect(quote.destinationAmount).toEqual(toWei("0.01"));
1919
expect(quote.intent).toBeDefined();
20+
expect(quote.steps.length).toBeGreaterThan(0);
2021
});
2122

2223
it("should surface any errors", async () => {
@@ -26,7 +27,7 @@ describe.runIf(process.env.TW_SECRET_KEY)("Bridge.Buy.quote", () => {
2627
originTokenAddress: "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE",
2728
destinationChainId: 444,
2829
destinationTokenAddress: "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE",
29-
buyAmountWei: toWei("1000000000"),
30+
amount: toWei("1000000000"),
3031
client: TEST_CLIENT,
3132
}),
3233
).rejects.toThrowError();
@@ -40,16 +41,20 @@ describe.runIf(process.env.TW_SECRET_KEY)("Bridge.Buy.prepare", () => {
4041
originTokenAddress: "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE",
4142
destinationChainId: 10,
4243
destinationTokenAddress: "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE",
43-
buyAmountWei: toWei("0.01"),
44+
amount: toWei("0.01"),
4445
sender: "0x2a4f24F935Eb178e3e7BA9B53A5Ee6d8407C0709",
4546
receiver: "0x2a4f24F935Eb178e3e7BA9B53A5Ee6d8407C0709",
4647
client: TEST_CLIENT,
48+
purchaseData: {
49+
foo: "bar",
50+
},
4751
});
4852

4953
expect(quote).toBeDefined();
5054
expect(quote.destinationAmount).toEqual(toWei("0.01"));
51-
expect(quote.transactions).toBeDefined();
52-
expect(quote.transactions.length).toBeGreaterThan(0);
55+
for (const step of quote.steps) {
56+
expect(step.transactions.length).toBeGreaterThan(0);
57+
}
5358
expect(quote.intent).toBeDefined();
5459
});
5560

@@ -60,7 +65,7 @@ describe.runIf(process.env.TW_SECRET_KEY)("Bridge.Buy.prepare", () => {
6065
originTokenAddress: "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE",
6166
destinationChainId: 444,
6267
destinationTokenAddress: "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE",
63-
buyAmountWei: toWei("1000000000"),
68+
amount: toWei("1000000000"),
6469
sender: "0x2a4f24F935Eb178e3e7BA9B53A5Ee6d8407C0709",
6570
receiver: "0x2a4f24F935Eb178e3e7BA9B53A5Ee6d8407C0709",
6671
client: TEST_CLIENT,

0 commit comments

Comments
 (0)