Skip to content

[SDK] Feature: Update sdk bridge functions with new schema #6830

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
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
95 changes: 95 additions & 0 deletions .changeset/fluffy-pigs-drive.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
---
"thirdweb": minor
---

Enhanced SDK Bridge functionality with the following key updates:

1. **Breaking Change:** Standardized parameter naming in bridge functions:
- Changed `buyAmountWei` to `amount` in Buy functions
- Changed `sellAmountWei` to `amount` in Sell functions

Example:
```ts
// Before
const buyQuote = await buy.quote({
originChainId: 1,
originTokenAddress: NATIVE_TOKEN_ADDRESS,
destinationChainId: 10,
destinationTokenAddress: NATIVE_TOKEN_ADDRESS,
buyAmountWei: toWei("0.01"),
client: thirdwebClient,
});

// After
const buyQuote = await buy.quote({
originChainId: 1,
originTokenAddress: NATIVE_TOKEN_ADDRESS,
destinationChainId: 10,
destinationTokenAddress: NATIVE_TOKEN_ADDRESS,
amount: toWei("0.01"),
client: thirdwebClient,
});
```

2. **Enhanced Quote Structure:** Added `steps` array to buy/sell quote responses with detailed token information:
```ts
// Steps contains detailed information about each step in a cross-chain transaction
steps: [
{
originToken: {
chainId: 1,
address: "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE",
symbol: "ETH",
name: "Ethereum",
decimals: 18,
priceUsd: 2000,
iconUri: "https://..."
},
destinationToken: {
chainId: 10,
address: "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE",
symbol: "ETH",
name: "Ethereum",
decimals: 18,
priceUsd: 2000,
iconUri: "https://..."
},
originAmount: 1000000000000000000n,
destinationAmount: 9980000000000000000n,
estimatedExecutionTimeMs: 1000,
transactions: [/* transactions for this step */]
}
]
```

3. **Added Purchase Data Support:** Added optional `purchaseData` parameter to Buy and Sell functions:
```ts
// Example with purchaseData
const quote = await buy.prepare({
originChainId: 1,
originTokenAddress: NATIVE_TOKEN_ADDRESS,
destinationChainId: 10,
destinationTokenAddress: NATIVE_TOKEN_ADDRESS,
amount: toWei("0.01"),
sender: "0x2a4f24F935Eb178e3e7BA9B53A5Ee6d8407C0709",
receiver: "0x2a4f24F935Eb178e3e7BA9B53A5Ee6d8407C0709",
purchaseData: {
foo: "bar",
},
client: thirdwebClient,
});
```

4. **Enhanced Status Responses:** Status responses now include the `purchaseData` field that was provided during the initial transaction:
```ts
// Status response includes purchaseData
{
status: "COMPLETED",
// ...other status fields
purchaseData: {
foo: "bar"
}
}
```

5. **Updated API Interactions:** Changed from query parameters to JSON body for prepare functions to accommodate complex data.
17 changes: 11 additions & 6 deletions packages/thirdweb/src/bridge/Buy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,14 @@ describe.runIf(process.env.TW_SECRET_KEY)("Bridge.Buy.quote", () => {
originTokenAddress: "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE",
destinationChainId: 10,
destinationTokenAddress: "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE",
buyAmountWei: toWei("0.01"),
amount: toWei("0.01"),
client: TEST_CLIENT,
});

expect(quote).toBeDefined();
expect(quote.destinationAmount).toEqual(toWei("0.01"));
expect(quote.intent).toBeDefined();
expect(quote.steps.length).toBeGreaterThan(0);
});

it("should surface any errors", async () => {
Expand All @@ -26,7 +27,7 @@ describe.runIf(process.env.TW_SECRET_KEY)("Bridge.Buy.quote", () => {
originTokenAddress: "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE",
destinationChainId: 444,
destinationTokenAddress: "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE",
buyAmountWei: toWei("1000000000"),
amount: toWei("1000000000"),
client: TEST_CLIENT,
}),
).rejects.toThrowError();
Expand All @@ -40,16 +41,20 @@ describe.runIf(process.env.TW_SECRET_KEY)("Bridge.Buy.prepare", () => {
originTokenAddress: "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE",
destinationChainId: 10,
destinationTokenAddress: "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE",
buyAmountWei: toWei("0.01"),
amount: toWei("0.01"),
sender: "0x2a4f24F935Eb178e3e7BA9B53A5Ee6d8407C0709",
receiver: "0x2a4f24F935Eb178e3e7BA9B53A5Ee6d8407C0709",
client: TEST_CLIENT,
purchaseData: {
foo: "bar",
},
});

expect(quote).toBeDefined();
expect(quote.destinationAmount).toEqual(toWei("0.01"));
expect(quote.transactions).toBeDefined();
expect(quote.transactions.length).toBeGreaterThan(0);
for (const step of quote.steps) {
expect(step.transactions.length).toBeGreaterThan(0);
}
expect(quote.intent).toBeDefined();
});

Expand All @@ -60,7 +65,7 @@ describe.runIf(process.env.TW_SECRET_KEY)("Bridge.Buy.prepare", () => {
originTokenAddress: "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE",
destinationChainId: 444,
destinationTokenAddress: "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE",
buyAmountWei: toWei("1000000000"),
amount: toWei("1000000000"),
sender: "0x2a4f24F935Eb178e3e7BA9B53A5Ee6d8407C0709",
receiver: "0x2a4f24F935Eb178e3e7BA9B53A5Ee6d8407C0709",
client: TEST_CLIENT,
Expand Down
Loading
Loading