Skip to content

Commit 6dd2b09

Browse files
authored
[SDK] Feature: Adds sortBy to Bridge.routes (#6955)
1 parent 736c3f8 commit 6dd2b09

File tree

4 files changed

+43
-0
lines changed

4 files changed

+43
-0
lines changed

.changeset/ninety-snails-smash.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
---
2+
"thirdweb": patch
3+
---
4+
5+
Added the `sortBy` option to Bridge.routes
6+
7+
```ts
8+
import { Bridge } from "thirdweb";
9+
10+
const routes = await Bridge.routes({
11+
originChainId: 1,
12+
originTokenAddress: "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE",
13+
limit: 10,
14+
offset: 0,
15+
sortBy: "popularity",
16+
client: thirdwebClient,
17+
});
18+
```

packages/thirdweb/src/bridge/Buy.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ import type { PreparedQuote, Quote } from "./types/Quote.js";
9191
* @param options.destinationChainId - The chain ID of the destination token.
9292
* @param options.destinationTokenAddress - The address of the destination token.
9393
* @param options.amount - The amount of the destination token to receive.
94+
* @param [options.maxSteps] - Limit the number of total steps in the route.
9495
* @param options.client - Your thirdweb client.
9596
*
9697
* @returns A promise that resolves to a non-finalized quote for the requested buy.
@@ -307,6 +308,7 @@ export declare namespace quote {
307308
* @param options.sender - The address of the sender.
308309
* @param options.receiver - The address of the recipient.
309310
* @param options.purchaseData - Arbitrary data to be passed to the purchase function and included with any webhooks or status calls.
311+
* @param [options.maxSteps] - Limit the number of total steps in the route.
310312
* @param options.client - Your thirdweb client.
311313
*
312314
* @returns A promise that resolves to a finalized quote and transactions for the requested buy.

packages/thirdweb/src/bridge/Routes.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,21 @@ import type { Route } from "./types/Route.js";
8686
* });
8787
* ```
8888
*
89+
* You can sort the returned routes by `popularity`:
90+
* ```ts
91+
* import { Bridge } from "thirdweb";
92+
*
93+
* // Get the 10 most popular routes starting from mainnet ETH
94+
* const routes = await Bridge.routes({
95+
* originChainId: 1,
96+
* originTokenAddress: "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE",
97+
* limit: 10,
98+
* offset: 0,
99+
* sortBy: "popularity",
100+
* client: thirdwebClient,
101+
* });
102+
* ```
103+
*
89104
* @param options - The options for the quote.
90105
* @param options.client - Your thirdweb client.
91106
* @param options.originChainId - Filter by a specific origin chain ID.
@@ -94,6 +109,7 @@ import type { Route } from "./types/Route.js";
94109
* @param options.destinationTokenAddress - Filter by a specific destination token address.
95110
* @param options.transactionHash - Filter by a specific transaction hash.
96111
* @param options.maxSteps - Limit the number of steps returned.
112+
* @param options.sortBy - Sort the routes by various categories.
97113
* @param options.limit - Limit the number of routes returned.
98114
* @param options.offset - Offset the number of routes returned.
99115
*
@@ -111,6 +127,7 @@ export async function routes(options: routes.Options): Promise<routes.Result> {
111127
destinationChainId,
112128
destinationTokenAddress,
113129
maxSteps,
130+
sortBy,
114131
limit,
115132
offset,
116133
} = options;
@@ -138,6 +155,9 @@ export async function routes(options: routes.Options): Promise<routes.Result> {
138155
if (offset) {
139156
url.searchParams.set("offset", offset.toString());
140157
}
158+
if (sortBy) {
159+
url.searchParams.set("sortBy", sortBy);
160+
}
141161

142162
const response = await clientFetch(url.toString());
143163
if (!response.ok) {
@@ -157,6 +177,7 @@ export declare namespace routes {
157177
destinationChainId?: number;
158178
destinationTokenAddress?: ox__Address.Address;
159179
transactionHash?: ox__Hex.Hex;
180+
sortBy?: "popularity";
160181
maxSteps?: number;
161182
limit?: number;
162183
offset?: number;

packages/thirdweb/src/bridge/Sell.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ import type { PreparedQuote, Quote } from "./types/Quote.js";
9191
* @param options.destinationChainId - The chain ID of the destination token.
9292
* @param options.destinationTokenAddress - The address of the destination token.
9393
* @param options.amount - The amount of the origin token to sell.
94+
* @param [options.maxSteps] - Limit the number of total steps in the route.
9495
* @param options.client - Your thirdweb client.
9596
*
9697
* @returns A promise that resolves to a non-finalized quote for the requested sell.
@@ -298,6 +299,7 @@ export declare namespace quote {
298299
* @param options.sender - The address of the sender.
299300
* @param options.receiver - The address of the recipient.
300301
* @param options.purchaseData - Arbitrary data to be passed to the purchase function and included with any webhooks or status calls.
302+
* @param [options.maxSteps] - Limit the number of total steps in the route.
301303
* @param options.client - Your thirdweb client.
302304
*
303305
* @returns A promise that resolves to a finalized quote and transactions for the requested sell.

0 commit comments

Comments
 (0)