@switch-win/sdk 1.2.1 → 1.2.3
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/LIMIT-ORDERS.md +737 -0
- package/README.md +91 -83
- package/ROBINHOOD.md +676 -580
- package/package.json +3 -2
- package/src/index.ts +41 -29
- package/src/limit-orders.ts +193 -47
- package/src/networks/index.ts +19 -18
- package/src/networks/robinhood.ts +355 -292
- package/src/types.ts +33 -11
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@switch-win/sdk",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.3",
|
|
4
4
|
"description": "Official integration kit for the Switch DEX Aggregator on PulseChain and Robinhood Chain",
|
|
5
5
|
"author": "BuildTheTech",
|
|
6
6
|
"license": "MIT",
|
|
@@ -37,7 +37,8 @@
|
|
|
37
37
|
"src/",
|
|
38
38
|
"abi/",
|
|
39
39
|
"README.md",
|
|
40
|
-
"ROBINHOOD.md"
|
|
40
|
+
"ROBINHOOD.md",
|
|
41
|
+
"LIMIT-ORDERS.md"
|
|
41
42
|
],
|
|
42
43
|
"devDependencies": {
|
|
43
44
|
"typescript": "^5.9.3"
|
package/src/index.ts
CHANGED
|
@@ -45,8 +45,9 @@ export type {
|
|
|
45
45
|
CancelLimitOrderResponse,
|
|
46
46
|
ListLimitOrdersResponse,
|
|
47
47
|
LimitOrderPair,
|
|
48
|
-
LimitOrderStats,
|
|
49
|
-
|
|
48
|
+
LimitOrderStats,
|
|
49
|
+
LimitOrderConfigResponse,
|
|
50
|
+
LimitOrderMutationResponse,
|
|
50
51
|
} from "./types.js";
|
|
51
52
|
|
|
52
53
|
export { isErrorResponse } from "./types.js";
|
|
@@ -95,43 +96,54 @@ export {
|
|
|
95
96
|
// Limit Order helpers
|
|
96
97
|
export {
|
|
97
98
|
buildLimitOrder,
|
|
98
|
-
getEIP712SigningParams,
|
|
99
|
+
getEIP712SigningParams,
|
|
100
|
+
getNetworkEIP712SigningParams,
|
|
101
|
+
getLimitOrderNetworkConfig,
|
|
102
|
+
getLimitOrderApprovalTarget,
|
|
99
103
|
getApprovalTarget,
|
|
100
104
|
getRouterApprovalTarget,
|
|
101
105
|
shouldUnwrapOutput,
|
|
102
|
-
getPLSFlowAddress,
|
|
103
|
-
|
|
106
|
+
getPLSFlowAddress,
|
|
107
|
+
getNativeFlowAddress,
|
|
108
|
+
isNativePLS,
|
|
109
|
+
isNativeCurrency,
|
|
104
110
|
submitLimitOrder,
|
|
105
111
|
cancelLimitOrder,
|
|
106
112
|
fetchLimitOrders,
|
|
107
113
|
fetchLimitOrder,
|
|
108
|
-
fetchLimitOrderPairs,
|
|
109
|
-
|
|
110
|
-
|
|
114
|
+
fetchLimitOrderPairs,
|
|
115
|
+
fetchLimitOrderConfig,
|
|
116
|
+
fetchLimitOrderStats,
|
|
117
|
+
LIMIT_ORDER_NETWORK_CONFIGS,
|
|
118
|
+
} from "./limit-orders.js";
|
|
111
119
|
|
|
112
|
-
export type {
|
|
120
|
+
export type {
|
|
113
121
|
BuildLimitOrderOptions,
|
|
114
122
|
ListLimitOrdersOptions,
|
|
123
|
+
LimitOrderNetwork,
|
|
124
|
+
LimitOrderNetworkConfig,
|
|
125
|
+
LimitOrderNetworkOptions,
|
|
115
126
|
} from "./limit-orders.js";
|
|
116
|
-
|
|
117
|
-
// Network-specific swap configuration
|
|
118
|
-
export {
|
|
119
|
-
ROBINHOOD_NETWORK,
|
|
120
|
-
ROBINHOOD_CHAIN,
|
|
127
|
+
|
|
128
|
+
// Network-specific swap configuration
|
|
129
|
+
export {
|
|
130
|
+
ROBINHOOD_NETWORK,
|
|
131
|
+
ROBINHOOD_CHAIN,
|
|
121
132
|
ROBINHOOD_NATIVE_ETH,
|
|
133
|
+
ROBINHOOD_LIMIT_ORDER_EIP712_DOMAIN,
|
|
122
134
|
ROBINHOOD_SWITCH_CONTRACTS,
|
|
123
|
-
ROBINHOOD_UNISWAP_CONTRACTS,
|
|
124
|
-
ROBINHOOD_TOKENS,
|
|
125
|
-
ROBINHOOD_FRONTEND_TOKEN_LIST,
|
|
126
|
-
ROBINHOOD_FRONTEND_DEFAULT_TOKENS,
|
|
127
|
-
ROBINHOOD_TRUSTED_INTERMEDIATES,
|
|
128
|
-
ROBINHOOD_FEE_TOKEN_PRIORITY,
|
|
129
|
-
selectRobinhoodFeeOnOutput,
|
|
130
|
-
buildRobinhoodQuoteUrl,
|
|
131
|
-
} from "./networks/robinhood.js";
|
|
132
|
-
|
|
133
|
-
export type {
|
|
134
|
-
RobinhoodToken,
|
|
135
|
-
RobinhoodQuoteParams,
|
|
136
|
-
RobinhoodTaxInfo,
|
|
137
|
-
} from "./networks/robinhood.js";
|
|
135
|
+
ROBINHOOD_UNISWAP_CONTRACTS,
|
|
136
|
+
ROBINHOOD_TOKENS,
|
|
137
|
+
ROBINHOOD_FRONTEND_TOKEN_LIST,
|
|
138
|
+
ROBINHOOD_FRONTEND_DEFAULT_TOKENS,
|
|
139
|
+
ROBINHOOD_TRUSTED_INTERMEDIATES,
|
|
140
|
+
ROBINHOOD_FEE_TOKEN_PRIORITY,
|
|
141
|
+
selectRobinhoodFeeOnOutput,
|
|
142
|
+
buildRobinhoodQuoteUrl,
|
|
143
|
+
} from "./networks/robinhood.js";
|
|
144
|
+
|
|
145
|
+
export type {
|
|
146
|
+
RobinhoodToken,
|
|
147
|
+
RobinhoodQuoteParams,
|
|
148
|
+
RobinhoodTaxInfo,
|
|
149
|
+
} from "./networks/robinhood.js";
|
package/src/limit-orders.ts
CHANGED
|
@@ -2,7 +2,8 @@
|
|
|
2
2
|
* Switch Limit Orders (V2) — Helper Functions
|
|
3
3
|
*
|
|
4
4
|
* Provides a complete toolkit for creating, signing, submitting, querying,
|
|
5
|
-
* and cancelling EIP-712 signed limit orders on PulseChain
|
|
5
|
+
* and cancelling EIP-712 signed limit orders on PulseChain and Robinhood
|
|
6
|
+
* Chain.
|
|
6
7
|
*
|
|
7
8
|
* ## How it works
|
|
8
9
|
*
|
|
@@ -10,7 +11,8 @@
|
|
|
10
11
|
* 2. **Sign** via EIP-712 with your wallet (ethers.js `signTypedData`)
|
|
11
12
|
* 3. **Submit** the signed order to the Switch backend with `submitLimitOrder()`
|
|
12
13
|
* 4. The Switch filler bot monitors active orders and fills them when profitable
|
|
13
|
-
* 5. **Cancel** an order on-chain via `invalidateNonce()
|
|
14
|
+
* 5. **Cancel** an order on-chain via `invalidateNonce()`; the backend indexer
|
|
15
|
+
* observes the cancellation event
|
|
14
16
|
*
|
|
15
17
|
* @example
|
|
16
18
|
* ```ts
|
|
@@ -26,7 +28,8 @@ import type {
|
|
|
26
28
|
ListLimitOrdersResponse,
|
|
27
29
|
LimitOrderRecord,
|
|
28
30
|
LimitOrderPair,
|
|
29
|
-
LimitOrderStats,
|
|
31
|
+
LimitOrderStats,
|
|
32
|
+
LimitOrderConfigResponse,
|
|
30
33
|
LimitOrderStatus,
|
|
31
34
|
ErrorResponse,
|
|
32
35
|
} from "./types.js";
|
|
@@ -40,8 +43,15 @@ import {
|
|
|
40
43
|
SWITCH_LIMIT_ORDER,
|
|
41
44
|
SWITCH_ROUTER,
|
|
42
45
|
SWITCH_PLS_FLOW,
|
|
43
|
-
WPLS,
|
|
44
|
-
|
|
46
|
+
WPLS,
|
|
47
|
+
NATIVE_PLS,
|
|
48
|
+
} from "./constants.js";
|
|
49
|
+
import {
|
|
50
|
+
ROBINHOOD_CHAIN,
|
|
51
|
+
ROBINHOOD_NATIVE_ETH,
|
|
52
|
+
ROBINHOOD_SWITCH_CONTRACTS,
|
|
53
|
+
ROBINHOOD_TOKENS,
|
|
54
|
+
} from "./networks/robinhood.js";
|
|
45
55
|
|
|
46
56
|
// ── Re-export EIP-712 constants for convenience ─────────────────────────────
|
|
47
57
|
|
|
@@ -107,7 +117,8 @@ export interface BuildLimitOrderOptions {
|
|
|
107
117
|
* one tax. Avoids the double sell-tax of maker → LO → pool.)
|
|
108
118
|
* - **Tax output token** → set `feeOnOutput: false` (default)
|
|
109
119
|
* (Output goes directly to recipient in one transfer.)
|
|
110
|
-
* - **Both tokens tax** →
|
|
120
|
+
* - **Both tokens tax** → use `feeOnOutput: false`; execution is restricted
|
|
121
|
+
* to tax-compatible Uniswap V2 routing.
|
|
111
122
|
*
|
|
112
123
|
* **Bottom line:** Use `feeOnOutput: false` (default) unless the input
|
|
113
124
|
* token is a tax token. This gives operators maximum flexibility and
|
|
@@ -181,13 +192,16 @@ export function buildLimitOrder(options: BuildLimitOrderOptions): LimitOrderPara
|
|
|
181
192
|
* const signature = await signer._signTypedData(domain, types, order);
|
|
182
193
|
* ```
|
|
183
194
|
*/
|
|
184
|
-
export function getEIP712SigningParams(
|
|
195
|
+
export function getEIP712SigningParams(
|
|
196
|
+
limitOrderContract?: string,
|
|
197
|
+
chainId: number = 369,
|
|
198
|
+
) {
|
|
185
199
|
if (limitOrderContract) {
|
|
186
200
|
return {
|
|
187
201
|
domain: {
|
|
188
202
|
name: "SwitchLimitOrder" as const,
|
|
189
203
|
version: "2" as const,
|
|
190
|
-
chainId
|
|
204
|
+
chainId,
|
|
191
205
|
verifyingContract: limitOrderContract,
|
|
192
206
|
},
|
|
193
207
|
types: LIMIT_ORDER_EIP712_TYPES,
|
|
@@ -225,8 +239,8 @@ export function getApprovalTarget(limitOrderContract?: string): string {
|
|
|
225
239
|
*
|
|
226
240
|
* @returns The SwitchRouter contract address
|
|
227
241
|
*/
|
|
228
|
-
export function getRouterApprovalTarget(): string {
|
|
229
|
-
return SWITCH_ROUTER;
|
|
242
|
+
export function getRouterApprovalTarget(routerContract?: string): string {
|
|
243
|
+
return routerContract || SWITCH_ROUTER;
|
|
230
244
|
}
|
|
231
245
|
|
|
232
246
|
/**
|
|
@@ -235,12 +249,15 @@ export function getRouterApprovalTarget(): string {
|
|
|
235
249
|
* Returns `true` only if `tokenOut` is WPLS (the output will be unwrapped
|
|
236
250
|
* to native PLS by the contract).
|
|
237
251
|
*/
|
|
238
|
-
export function shouldUnwrapOutput(
|
|
239
|
-
|
|
252
|
+
export function shouldUnwrapOutput(
|
|
253
|
+
tokenOut: string,
|
|
254
|
+
wrappedNativeToken: string = WPLS,
|
|
255
|
+
): boolean {
|
|
256
|
+
return tokenOut.toLowerCase() === wrappedNativeToken.toLowerCase();
|
|
240
257
|
}
|
|
241
258
|
|
|
242
259
|
// ═══════════════════════════════════════════════════════════════════════════════
|
|
243
|
-
//
|
|
260
|
+
// Native-currency flow (SwitchPLSFlow ABI: PLS on PulseChain, ETH on Robinhood)
|
|
244
261
|
// ═══════════════════════════════════════════════════════════════════════════════
|
|
245
262
|
|
|
246
263
|
/**
|
|
@@ -251,9 +268,95 @@ export function shouldUnwrapOutput(tokenOut: string): boolean {
|
|
|
251
268
|
*
|
|
252
269
|
* @returns The SwitchPLSFlow contract address
|
|
253
270
|
*/
|
|
254
|
-
export function getPLSFlowAddress(): string {
|
|
255
|
-
return SWITCH_PLS_FLOW;
|
|
256
|
-
}
|
|
271
|
+
export function getPLSFlowAddress(nativeFlowContract?: string): string {
|
|
272
|
+
return nativeFlowContract || SWITCH_PLS_FLOW;
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
/** Networks supported by the shared Switch limit-order API. */
|
|
276
|
+
export type LimitOrderNetwork = "pulsechain" | "robinhood";
|
|
277
|
+
|
|
278
|
+
/** Complete deployment metadata needed to create or fill limit orders. */
|
|
279
|
+
export interface LimitOrderNetworkConfig {
|
|
280
|
+
network: LimitOrderNetwork;
|
|
281
|
+
chainId: number;
|
|
282
|
+
chainName: string;
|
|
283
|
+
nativeSymbol: "PLS" | "ETH";
|
|
284
|
+
nativeSentinel: string;
|
|
285
|
+
wrappedNativeToken: string;
|
|
286
|
+
routerContract: string;
|
|
287
|
+
limitOrderContract: string;
|
|
288
|
+
nativeFlowContract: string;
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
/** Static defaults. Prefer {@link fetchLimitOrderConfig} at application startup. */
|
|
292
|
+
export const LIMIT_ORDER_NETWORK_CONFIGS: Readonly<
|
|
293
|
+
Record<LimitOrderNetwork, LimitOrderNetworkConfig>
|
|
294
|
+
> = {
|
|
295
|
+
pulsechain: {
|
|
296
|
+
network: "pulsechain",
|
|
297
|
+
chainId: 369,
|
|
298
|
+
chainName: "PulseChain",
|
|
299
|
+
nativeSymbol: "PLS",
|
|
300
|
+
nativeSentinel: NATIVE_PLS,
|
|
301
|
+
wrappedNativeToken: WPLS,
|
|
302
|
+
routerContract: SWITCH_ROUTER,
|
|
303
|
+
limitOrderContract: SWITCH_LIMIT_ORDER,
|
|
304
|
+
nativeFlowContract: SWITCH_PLS_FLOW,
|
|
305
|
+
},
|
|
306
|
+
robinhood: {
|
|
307
|
+
network: "robinhood",
|
|
308
|
+
chainId: ROBINHOOD_CHAIN.id,
|
|
309
|
+
chainName: ROBINHOOD_CHAIN.name,
|
|
310
|
+
nativeSymbol: "ETH",
|
|
311
|
+
nativeSentinel: ROBINHOOD_NATIVE_ETH,
|
|
312
|
+
wrappedNativeToken: ROBINHOOD_TOKENS.WETH.address,
|
|
313
|
+
routerContract: ROBINHOOD_SWITCH_CONTRACTS.router,
|
|
314
|
+
limitOrderContract: ROBINHOOD_SWITCH_CONTRACTS.limitOrder,
|
|
315
|
+
nativeFlowContract: ROBINHOOD_SWITCH_CONTRACTS.nativeEthFlow,
|
|
316
|
+
},
|
|
317
|
+
} as const;
|
|
318
|
+
|
|
319
|
+
/** Return the static deployment defaults for a supported limit-order network. */
|
|
320
|
+
export function getLimitOrderNetworkConfig(
|
|
321
|
+
network: LimitOrderNetwork = "pulsechain",
|
|
322
|
+
): LimitOrderNetworkConfig {
|
|
323
|
+
return LIMIT_ORDER_NETWORK_CONFIGS[network];
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
/** Build the correct EIP-712 signing domain for a supported network. */
|
|
327
|
+
export function getNetworkEIP712SigningParams(
|
|
328
|
+
network: LimitOrderNetwork,
|
|
329
|
+
limitOrderContract?: string,
|
|
330
|
+
) {
|
|
331
|
+
const config = getLimitOrderNetworkConfig(network);
|
|
332
|
+
return getEIP712SigningParams(
|
|
333
|
+
limitOrderContract ?? config.limitOrderContract,
|
|
334
|
+
config.chainId,
|
|
335
|
+
);
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
/** Resolve the maker's ERC-20 approval target for the selected fee mode. */
|
|
339
|
+
export function getLimitOrderApprovalTarget(
|
|
340
|
+
network: LimitOrderNetwork,
|
|
341
|
+
feeOnOutput: boolean,
|
|
342
|
+
overrides: { limitOrderContract?: string; routerContract?: string } = {},
|
|
343
|
+
): string {
|
|
344
|
+
const config = getLimitOrderNetworkConfig(network);
|
|
345
|
+
return feeOnOutput
|
|
346
|
+
? getRouterApprovalTarget(overrides.routerContract ?? config.routerContract)
|
|
347
|
+
: getApprovalTarget(overrides.limitOrderContract ?? config.limitOrderContract);
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
export interface LimitOrderNetworkOptions {
|
|
351
|
+
network?: LimitOrderNetwork;
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
function endpointForNetwork(endpoint: string, network?: string): string {
|
|
355
|
+
if (!network) return endpoint;
|
|
356
|
+
const url = new URL(endpoint);
|
|
357
|
+
url.searchParams.set("network", network);
|
|
358
|
+
return url.toString();
|
|
359
|
+
}
|
|
257
360
|
|
|
258
361
|
/**
|
|
259
362
|
* Check if the input token is native PLS (should use PLSFlow instead of EIP-712).
|
|
@@ -264,10 +367,27 @@ export function getPLSFlowAddress(): string {
|
|
|
264
367
|
* @param tokenIn - The input token address
|
|
265
368
|
* @returns `true` if tokenIn is the native PLS sentinel address
|
|
266
369
|
*/
|
|
267
|
-
export function isNativePLS(tokenIn: string): boolean {
|
|
370
|
+
export function isNativePLS(tokenIn: string): boolean {
|
|
268
371
|
const NATIVE_SENTINEL = "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE";
|
|
269
372
|
return tokenIn.toLowerCase() === NATIVE_SENTINEL.toLowerCase();
|
|
270
|
-
}
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
/** Network-neutral native-currency sentinel check (PLS or ETH). */
|
|
376
|
+
export function isNativeCurrency(tokenIn: string): boolean {
|
|
377
|
+
const normalized = tokenIn.toLowerCase();
|
|
378
|
+
return (
|
|
379
|
+
normalized === NATIVE_PLS.toLowerCase() ||
|
|
380
|
+
normalized === ROBINHOOD_NATIVE_ETH.toLowerCase()
|
|
381
|
+
);
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
/** Return the native-order flow contract for PulseChain or Robinhood Chain. */
|
|
385
|
+
export function getNativeFlowAddress(
|
|
386
|
+
network: LimitOrderNetwork,
|
|
387
|
+
nativeFlowContract?: string,
|
|
388
|
+
): string {
|
|
389
|
+
return nativeFlowContract ?? getLimitOrderNetworkConfig(network).nativeFlowContract;
|
|
390
|
+
}
|
|
271
391
|
|
|
272
392
|
// ═══════════════════════════════════════════════════════════════════════════════
|
|
273
393
|
// API Helpers
|
|
@@ -292,7 +412,7 @@ export function isNativePLS(tokenIn: string): boolean {
|
|
|
292
412
|
* 4. Do **not** navigate away or close the signing flow until the
|
|
293
413
|
* backend confirms the order.
|
|
294
414
|
*
|
|
295
|
-
*
|
|
415
|
+
* Native PLS/ETH flow orders are an exception — they are recorded
|
|
296
416
|
* on-chain first, so the backend can discover them via event indexing
|
|
297
417
|
* even if the POST never arrives.
|
|
298
418
|
*
|
|
@@ -312,10 +432,11 @@ export function isNativePLS(tokenIn: string): boolean {
|
|
|
312
432
|
* }
|
|
313
433
|
* ```
|
|
314
434
|
*/
|
|
315
|
-
export async function submitLimitOrder(
|
|
316
|
-
signedOrder: SignedLimitOrder,
|
|
317
|
-
|
|
318
|
-
|
|
435
|
+
export async function submitLimitOrder(
|
|
436
|
+
signedOrder: SignedLimitOrder,
|
|
437
|
+
options: LimitOrderNetworkOptions = {},
|
|
438
|
+
): Promise<CreateLimitOrderResponse | ErrorResponse> {
|
|
439
|
+
const res = await fetch(endpointForNetwork(LIMIT_ORDERS_ENDPOINT, options.network), {
|
|
319
440
|
method: "POST",
|
|
320
441
|
headers: { "Content-Type": "application/json" },
|
|
321
442
|
body: JSON.stringify(signedOrder),
|
|
@@ -325,22 +446,24 @@ export async function submitLimitOrder(
|
|
|
325
446
|
}
|
|
326
447
|
|
|
327
448
|
/**
|
|
328
|
-
*
|
|
329
|
-
*
|
|
330
|
-
*
|
|
331
|
-
*
|
|
332
|
-
*
|
|
333
|
-
*
|
|
449
|
+
* Legacy helper for backend deployments that implemented REST cancellation.
|
|
450
|
+
*
|
|
451
|
+
* The current hosted Switch API intentionally has no DELETE endpoint.
|
|
452
|
+
* Cancellation must be performed on-chain with `invalidateNonce(nonce)` on
|
|
453
|
+
* the contract stored in the order's `limitOrderContract` field. The indexer
|
|
454
|
+
* then updates the order status from the emitted event.
|
|
334
455
|
*
|
|
335
456
|
* @param maker - Maker address
|
|
336
457
|
* @param nonce - Nonce of the order to cancel
|
|
337
|
-
* @returns Success confirmation or error
|
|
458
|
+
* @returns Success confirmation or error on compatible legacy backends
|
|
459
|
+
* @deprecated Do not use with the hosted Switch API; cancel on-chain instead.
|
|
338
460
|
*/
|
|
339
|
-
export async function cancelLimitOrder(
|
|
340
|
-
maker: string,
|
|
341
|
-
nonce: number,
|
|
342
|
-
|
|
343
|
-
|
|
461
|
+
export async function cancelLimitOrder(
|
|
462
|
+
maker: string,
|
|
463
|
+
nonce: number,
|
|
464
|
+
options: LimitOrderNetworkOptions = {},
|
|
465
|
+
): Promise<CancelLimitOrderResponse | ErrorResponse> {
|
|
466
|
+
const res = await fetch(endpointForNetwork(LIMIT_ORDERS_ENDPOINT, options.network), {
|
|
344
467
|
method: "DELETE",
|
|
345
468
|
headers: { "Content-Type": "application/json" },
|
|
346
469
|
body: JSON.stringify({ maker, nonce }),
|
|
@@ -350,7 +473,9 @@ export async function cancelLimitOrder(
|
|
|
350
473
|
}
|
|
351
474
|
|
|
352
475
|
/** Filter options for listing limit orders */
|
|
353
|
-
export interface ListLimitOrdersOptions {
|
|
476
|
+
export interface ListLimitOrdersOptions {
|
|
477
|
+
/** Backend network process to query. */
|
|
478
|
+
network?: LimitOrderNetwork;
|
|
354
479
|
/** Filter by order status. Default: `"ACTIVE"` */
|
|
355
480
|
status?: LimitOrderStatus;
|
|
356
481
|
/** Filter by maker address */
|
|
@@ -415,7 +540,8 @@ export async function fetchLimitOrders(
|
|
|
415
540
|
if (options.tokenOut) params.set("tokenOut", options.tokenOut);
|
|
416
541
|
if (options.pair) params.set("pair", options.pair);
|
|
417
542
|
if (options.limit != null) params.set("limit", String(options.limit));
|
|
418
|
-
if (options.offset != null) params.set("offset", String(options.offset));
|
|
543
|
+
if (options.offset != null) params.set("offset", String(options.offset));
|
|
544
|
+
if (options.network) params.set("network", options.network);
|
|
419
545
|
|
|
420
546
|
const url = params.toString()
|
|
421
547
|
? `${LIMIT_ORDERS_ENDPOINT}?${params}`
|
|
@@ -432,11 +558,14 @@ export async function fetchLimitOrders(
|
|
|
432
558
|
* @param nonce - Order nonce
|
|
433
559
|
* @returns The order record, or an error if not found
|
|
434
560
|
*/
|
|
435
|
-
export async function fetchLimitOrder(
|
|
436
|
-
maker: string,
|
|
437
|
-
nonce: number,
|
|
438
|
-
|
|
439
|
-
|
|
561
|
+
export async function fetchLimitOrder(
|
|
562
|
+
maker: string,
|
|
563
|
+
nonce: number,
|
|
564
|
+
options: LimitOrderNetworkOptions = {},
|
|
565
|
+
): Promise<LimitOrderRecord | ErrorResponse> {
|
|
566
|
+
const res = await fetch(
|
|
567
|
+
endpointForNetwork(`${LIMIT_ORDERS_ENDPOINT}/${maker}/${nonce}`, options.network),
|
|
568
|
+
);
|
|
440
569
|
return res.json() as Promise<LimitOrderRecord | ErrorResponse>;
|
|
441
570
|
}
|
|
442
571
|
|
|
@@ -445,17 +574,34 @@ export async function fetchLimitOrder(
|
|
|
445
574
|
*
|
|
446
575
|
* Useful for displaying which token pairs have open limit orders.
|
|
447
576
|
*/
|
|
448
|
-
export async function fetchLimitOrderPairs(
|
|
449
|
-
|
|
577
|
+
export async function fetchLimitOrderPairs(
|
|
578
|
+
options: LimitOrderNetworkOptions = {},
|
|
579
|
+
): Promise<LimitOrderPair[]> {
|
|
580
|
+
const res = await fetch(endpointForNetwork(LIMIT_ORDER_PAIRS_ENDPOINT, options.network));
|
|
450
581
|
return res.json() as Promise<LimitOrderPair[]>;
|
|
451
|
-
}
|
|
582
|
+
}
|
|
583
|
+
|
|
584
|
+
/** Fetch the active deployment and EIP-712 domain for a network. */
|
|
585
|
+
export async function fetchLimitOrderConfig(
|
|
586
|
+
options: LimitOrderNetworkOptions = {},
|
|
587
|
+
): Promise<LimitOrderConfigResponse> {
|
|
588
|
+
const res = await fetch(
|
|
589
|
+
endpointForNetwork(`${LIMIT_ORDERS_ENDPOINT}/config`, options.network),
|
|
590
|
+
);
|
|
591
|
+
if (!res.ok) {
|
|
592
|
+
throw new Error(`Failed to fetch limit-order config (${res.status})`);
|
|
593
|
+
}
|
|
594
|
+
return res.json() as Promise<LimitOrderConfigResponse>;
|
|
595
|
+
}
|
|
452
596
|
|
|
453
597
|
/**
|
|
454
598
|
* Fetch summary statistics for all limit orders.
|
|
455
599
|
*
|
|
456
600
|
* Returns counts of active, filled, cancelled, and expired orders.
|
|
457
601
|
*/
|
|
458
|
-
export async function fetchLimitOrderStats(
|
|
459
|
-
|
|
602
|
+
export async function fetchLimitOrderStats(
|
|
603
|
+
options: LimitOrderNetworkOptions = {},
|
|
604
|
+
): Promise<LimitOrderStats> {
|
|
605
|
+
const res = await fetch(endpointForNetwork(LIMIT_ORDER_STATS_ENDPOINT, options.network));
|
|
460
606
|
return res.json() as Promise<LimitOrderStats>;
|
|
461
607
|
}
|
package/src/networks/index.ts
CHANGED
|
@@ -1,20 +1,21 @@
|
|
|
1
|
-
export {
|
|
2
|
-
ROBINHOOD_NETWORK,
|
|
3
|
-
ROBINHOOD_CHAIN,
|
|
1
|
+
export {
|
|
2
|
+
ROBINHOOD_NETWORK,
|
|
3
|
+
ROBINHOOD_CHAIN,
|
|
4
4
|
ROBINHOOD_NATIVE_ETH,
|
|
5
|
+
ROBINHOOD_LIMIT_ORDER_EIP712_DOMAIN,
|
|
5
6
|
ROBINHOOD_SWITCH_CONTRACTS,
|
|
6
|
-
ROBINHOOD_UNISWAP_CONTRACTS,
|
|
7
|
-
ROBINHOOD_TOKENS,
|
|
8
|
-
ROBINHOOD_FRONTEND_TOKEN_LIST,
|
|
9
|
-
ROBINHOOD_FRONTEND_DEFAULT_TOKENS,
|
|
10
|
-
ROBINHOOD_TRUSTED_INTERMEDIATES,
|
|
11
|
-
ROBINHOOD_FEE_TOKEN_PRIORITY,
|
|
12
|
-
selectRobinhoodFeeOnOutput,
|
|
13
|
-
buildRobinhoodQuoteUrl,
|
|
14
|
-
} from "./robinhood.js";
|
|
15
|
-
|
|
16
|
-
export type {
|
|
17
|
-
RobinhoodToken,
|
|
18
|
-
RobinhoodQuoteParams,
|
|
19
|
-
RobinhoodTaxInfo,
|
|
20
|
-
} from "./robinhood.js";
|
|
7
|
+
ROBINHOOD_UNISWAP_CONTRACTS,
|
|
8
|
+
ROBINHOOD_TOKENS,
|
|
9
|
+
ROBINHOOD_FRONTEND_TOKEN_LIST,
|
|
10
|
+
ROBINHOOD_FRONTEND_DEFAULT_TOKENS,
|
|
11
|
+
ROBINHOOD_TRUSTED_INTERMEDIATES,
|
|
12
|
+
ROBINHOOD_FEE_TOKEN_PRIORITY,
|
|
13
|
+
selectRobinhoodFeeOnOutput,
|
|
14
|
+
buildRobinhoodQuoteUrl,
|
|
15
|
+
} from "./robinhood.js";
|
|
16
|
+
|
|
17
|
+
export type {
|
|
18
|
+
RobinhoodToken,
|
|
19
|
+
RobinhoodQuoteParams,
|
|
20
|
+
RobinhoodTaxInfo,
|
|
21
|
+
} from "./robinhood.js";
|