@riftresearch/sdk 0.15.0 → 0.17.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +12 -1
- package/dist/index.d.ts +32 -1
- package/dist/index.js +25 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -64,8 +64,19 @@ const swap = await executeSwap({
|
|
|
64
64
|
console.log(`Order ID: ${swap.orderId}`)
|
|
65
65
|
|
|
66
66
|
// Check status
|
|
67
|
-
const status = await sdk.
|
|
67
|
+
const status = await sdk.getOrderStatus(swap.orderId)
|
|
68
68
|
console.log(`Status: ${status.status}`)
|
|
69
|
+
|
|
70
|
+
// List orders with filters and cursor pagination
|
|
71
|
+
const page = await sdk.getOrders({
|
|
72
|
+
sender: '0x1234...',
|
|
73
|
+
status: 'unfilled',
|
|
74
|
+
orderType: 'limit',
|
|
75
|
+
limit: 20,
|
|
76
|
+
})
|
|
77
|
+
|
|
78
|
+
console.log(`Fetched ${page.items.length} orders`)
|
|
79
|
+
console.log(`Next cursor: ${page.nextCursor}`)
|
|
69
80
|
```
|
|
70
81
|
|
|
71
82
|
## Limit Orders
|
package/dist/index.d.ts
CHANGED
|
@@ -184,6 +184,10 @@ interface AnalyticsOrderResponse {
|
|
|
184
184
|
lastSourceUpdateAt: string | null;
|
|
185
185
|
terminalAt: string | null;
|
|
186
186
|
}
|
|
187
|
+
interface AnalyticsOrdersResponse {
|
|
188
|
+
items: AnalyticsOrderResponse[];
|
|
189
|
+
nextCursor: string | null;
|
|
190
|
+
}
|
|
187
191
|
interface ErrorResponse {
|
|
188
192
|
error: string;
|
|
189
193
|
}
|
|
@@ -366,6 +370,8 @@ import { Chain as Chain3 } from "viem";
|
|
|
366
370
|
import { Account, PublicClient, Transport, WalletClient } from "viem";
|
|
367
371
|
import { Chain as Chain2 } from "viem/chains";
|
|
368
372
|
type RiftSwap = AnalyticsOrderResponse;
|
|
373
|
+
type RiftOrdersPage = AnalyticsOrdersResponse;
|
|
374
|
+
type OrderTypeFilter = "market" | "limit";
|
|
369
375
|
interface QuoteParameters {
|
|
370
376
|
/** The currency to swap from */
|
|
371
377
|
from: Currency;
|
|
@@ -434,6 +440,22 @@ interface SwapResult {
|
|
|
434
440
|
status: AnalyticsOrderStatus;
|
|
435
441
|
rift: RiftSwap;
|
|
436
442
|
}
|
|
443
|
+
interface GetOrdersOptions {
|
|
444
|
+
/** Filter by exact sender address */
|
|
445
|
+
sender?: string;
|
|
446
|
+
/** Filter by exact destination address */
|
|
447
|
+
destination?: string;
|
|
448
|
+
/** Filter by exact refund address */
|
|
449
|
+
refund?: string;
|
|
450
|
+
/** Filter by execution type */
|
|
451
|
+
orderType?: OrderTypeFilter;
|
|
452
|
+
/** Filter by coarse public order status */
|
|
453
|
+
status?: AnalyticsOrderStatus;
|
|
454
|
+
/** Page size. The API clamps this between 1 and 100, defaulting to 50. */
|
|
455
|
+
limit?: number;
|
|
456
|
+
/** Opaque cursor returned by a previous getOrders() response */
|
|
457
|
+
cursor?: string;
|
|
458
|
+
}
|
|
437
459
|
type CancelOrderResult = CancelOrderResponse;
|
|
438
460
|
/**
|
|
439
461
|
* Function type for sending Bitcoin.
|
|
@@ -585,8 +607,17 @@ declare class RiftSdk {
|
|
|
585
607
|
/**
|
|
586
608
|
* Get the current status of an order by its ID.
|
|
587
609
|
*/
|
|
610
|
+
getOrderStatus(orderId: string): Promise<AnalyticsOrderResponse>;
|
|
611
|
+
/**
|
|
612
|
+
* @deprecated Use getOrderStatus() instead.
|
|
613
|
+
*/
|
|
588
614
|
getSwapStatus(orderId: string): Promise<AnalyticsOrderResponse>;
|
|
589
615
|
/**
|
|
616
|
+
* List orders through the public `/orders` endpoint with the same filters
|
|
617
|
+
* exposed by the swap-router OpenAPI documentation.
|
|
618
|
+
*/
|
|
619
|
+
getOrders(options?: GetOrdersOptions): Promise<RiftOrdersPage>;
|
|
620
|
+
/**
|
|
590
621
|
* Cancel a supported limit order through the swap router.
|
|
591
622
|
*
|
|
592
623
|
* The SDK first requests the backend-specific typed-data payload from the
|
|
@@ -596,4 +627,4 @@ declare class RiftSdk {
|
|
|
596
627
|
cancelOrder<chain extends Chain3 | undefined = Chain3 | undefined>(options: CancelOrderOptions<chain>): Promise<CancelOrderResult>;
|
|
597
628
|
}
|
|
598
629
|
declare function createRiftSdk(options: RiftSdkOptions): RiftSdk;
|
|
599
|
-
export { getSupportedModes, detectRoute, createRiftSdk, createCurrency, TokenIdentifier, AnalyticsOrderStatus as SwapStatus, SwapRouterApiError, SwapRoute, SwapResult, SwapResponse, SupportedModes, SendBitcoinFn, RiftSwap, RiftSdkOptions, RiftSdk, QuoteResult, QuoteParameters, NativeToken, LimitPricing, GetQuoteResult, ExecutionStep, ExecutionAction, ExecuteSwapStepType, ExecuteSwapOptions, ExecuteSwapOnExecuteStepCallback, EvmChain, EvmCallStep, EvmCallKind, Erc20Token, Currency, Currencies, CreateLimitOrderOptions, Chain, CancelOrderResult, CancelOrderOptions, BtcTransferStep, BtcTransferKind, BitcoinChain };
|
|
630
|
+
export { getSupportedModes, detectRoute, createRiftSdk, createCurrency, TokenIdentifier, AnalyticsOrderStatus as SwapStatus, SwapRouterApiError, SwapRoute, SwapResult, SwapResponse, SupportedModes, SendBitcoinFn, RiftSwap, RiftSdkOptions, RiftSdk, RiftOrdersPage, QuoteResult, QuoteParameters, OrderTypeFilter, NativeToken, LimitPricing, GetQuoteResult, GetOrdersOptions, ExecutionStep, ExecutionAction, ExecuteSwapStepType, ExecuteSwapOptions, ExecuteSwapOnExecuteStepCallback, EvmChain, EvmCallStep, EvmCallKind, Erc20Token, Currency, Currencies, CreateLimitOrderOptions, Chain, CancelOrderResult, CancelOrderOptions, BtcTransferStep, BtcTransferKind, BitcoinChain };
|
package/dist/index.js
CHANGED
|
@@ -183,6 +183,20 @@ import {
|
|
|
183
183
|
} from "viem";
|
|
184
184
|
|
|
185
185
|
// src/client.ts
|
|
186
|
+
function buildQueryString(query) {
|
|
187
|
+
if (!query) {
|
|
188
|
+
return "";
|
|
189
|
+
}
|
|
190
|
+
const searchParams = new URLSearchParams;
|
|
191
|
+
for (const [key, value] of Object.entries(query)) {
|
|
192
|
+
if (value === undefined) {
|
|
193
|
+
continue;
|
|
194
|
+
}
|
|
195
|
+
searchParams.set(key, String(value));
|
|
196
|
+
}
|
|
197
|
+
const search = searchParams.toString();
|
|
198
|
+
return search.length > 0 ? `?${search}` : "";
|
|
199
|
+
}
|
|
186
200
|
async function request(baseUrl, path, init) {
|
|
187
201
|
try {
|
|
188
202
|
const response = await fetch(`${baseUrl}${path}`, init);
|
|
@@ -274,12 +288,16 @@ function createClient(baseUrl) {
|
|
|
274
288
|
const limit = {
|
|
275
289
|
post: (body) => postJson(normalizedBaseUrl, "/order/limit", body)
|
|
276
290
|
};
|
|
291
|
+
const orders = {
|
|
292
|
+
get: (query) => get(normalizedBaseUrl, `/orders${buildQueryString(query)}`)
|
|
293
|
+
};
|
|
277
294
|
return {
|
|
278
295
|
quote: {
|
|
279
296
|
post: (body) => postJson(normalizedBaseUrl, "/quote", body)
|
|
280
297
|
},
|
|
281
298
|
market,
|
|
282
299
|
limit,
|
|
300
|
+
orders,
|
|
283
301
|
swap
|
|
284
302
|
};
|
|
285
303
|
}
|
|
@@ -995,9 +1013,15 @@ class RiftSdk {
|
|
|
995
1013
|
}
|
|
996
1014
|
return context.sendBitcoin;
|
|
997
1015
|
}
|
|
998
|
-
async
|
|
1016
|
+
async getOrderStatus(orderId) {
|
|
999
1017
|
return this.unwrapEdenResult(await this.riftClient.swap({ orderId }).get());
|
|
1000
1018
|
}
|
|
1019
|
+
async getSwapStatus(orderId) {
|
|
1020
|
+
return this.getOrderStatus(orderId);
|
|
1021
|
+
}
|
|
1022
|
+
async getOrders(options) {
|
|
1023
|
+
return this.unwrapEdenResult(await this.riftClient.orders.get(options));
|
|
1024
|
+
}
|
|
1001
1025
|
async cancelOrder(options) {
|
|
1002
1026
|
const walletClient = options.walletClient;
|
|
1003
1027
|
const account = walletClient.account;
|