@switch-win/sdk 1.2.0 → 1.2.2
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 +81 -80
- package/ROBINHOOD.md +630 -518
- package/package.json +1 -1
- package/src/index.ts +26 -26
- package/src/limit-orders.ts +60 -30
- package/src/networks/index.ts +20 -20
- package/src/networks/robinhood.ts +327 -306
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -109,29 +109,29 @@ export {
|
|
|
109
109
|
fetchLimitOrderStats,
|
|
110
110
|
} from "./limit-orders.js";
|
|
111
111
|
|
|
112
|
-
export type {
|
|
113
|
-
BuildLimitOrderOptions,
|
|
114
|
-
ListLimitOrdersOptions,
|
|
115
|
-
} from "./limit-orders.js";
|
|
116
|
-
|
|
117
|
-
// Network-specific swap configuration
|
|
118
|
-
export {
|
|
119
|
-
ROBINHOOD_NETWORK,
|
|
120
|
-
ROBINHOOD_CHAIN,
|
|
121
|
-
ROBINHOOD_NATIVE_ETH,
|
|
122
|
-
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";
|
|
112
|
+
export type {
|
|
113
|
+
BuildLimitOrderOptions,
|
|
114
|
+
ListLimitOrdersOptions,
|
|
115
|
+
} from "./limit-orders.js";
|
|
116
|
+
|
|
117
|
+
// Network-specific swap configuration
|
|
118
|
+
export {
|
|
119
|
+
ROBINHOOD_NETWORK,
|
|
120
|
+
ROBINHOOD_CHAIN,
|
|
121
|
+
ROBINHOOD_NATIVE_ETH,
|
|
122
|
+
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";
|
package/src/limit-orders.ts
CHANGED
|
@@ -107,7 +107,8 @@ export interface BuildLimitOrderOptions {
|
|
|
107
107
|
* one tax. Avoids the double sell-tax of maker → LO → pool.)
|
|
108
108
|
* - **Tax output token** → set `feeOnOutput: false` (default)
|
|
109
109
|
* (Output goes directly to recipient in one transfer.)
|
|
110
|
-
* - **Both tokens tax** →
|
|
110
|
+
* - **Both tokens tax** → use `feeOnOutput: false`; execution is restricted
|
|
111
|
+
* to tax-compatible Uniswap V2 routing.
|
|
111
112
|
*
|
|
112
113
|
* **Bottom line:** Use `feeOnOutput: false` (default) unless the input
|
|
113
114
|
* token is a tax token. This gives operators maximum flexibility and
|
|
@@ -181,13 +182,16 @@ export function buildLimitOrder(options: BuildLimitOrderOptions): LimitOrderPara
|
|
|
181
182
|
* const signature = await signer._signTypedData(domain, types, order);
|
|
182
183
|
* ```
|
|
183
184
|
*/
|
|
184
|
-
export function getEIP712SigningParams(
|
|
185
|
+
export function getEIP712SigningParams(
|
|
186
|
+
limitOrderContract?: string,
|
|
187
|
+
chainId: number = 369,
|
|
188
|
+
) {
|
|
185
189
|
if (limitOrderContract) {
|
|
186
190
|
return {
|
|
187
191
|
domain: {
|
|
188
192
|
name: "SwitchLimitOrder" as const,
|
|
189
193
|
version: "2" as const,
|
|
190
|
-
chainId
|
|
194
|
+
chainId,
|
|
191
195
|
verifyingContract: limitOrderContract,
|
|
192
196
|
},
|
|
193
197
|
types: LIMIT_ORDER_EIP712_TYPES,
|
|
@@ -225,8 +229,8 @@ export function getApprovalTarget(limitOrderContract?: string): string {
|
|
|
225
229
|
*
|
|
226
230
|
* @returns The SwitchRouter contract address
|
|
227
231
|
*/
|
|
228
|
-
export function getRouterApprovalTarget(): string {
|
|
229
|
-
return SWITCH_ROUTER;
|
|
232
|
+
export function getRouterApprovalTarget(routerContract?: string): string {
|
|
233
|
+
return routerContract || SWITCH_ROUTER;
|
|
230
234
|
}
|
|
231
235
|
|
|
232
236
|
/**
|
|
@@ -235,8 +239,11 @@ export function getRouterApprovalTarget(): string {
|
|
|
235
239
|
* Returns `true` only if `tokenOut` is WPLS (the output will be unwrapped
|
|
236
240
|
* to native PLS by the contract).
|
|
237
241
|
*/
|
|
238
|
-
export function shouldUnwrapOutput(
|
|
239
|
-
|
|
242
|
+
export function shouldUnwrapOutput(
|
|
243
|
+
tokenOut: string,
|
|
244
|
+
wrappedNativeToken: string = WPLS,
|
|
245
|
+
): boolean {
|
|
246
|
+
return tokenOut.toLowerCase() === wrappedNativeToken.toLowerCase();
|
|
240
247
|
}
|
|
241
248
|
|
|
242
249
|
// ═══════════════════════════════════════════════════════════════════════════════
|
|
@@ -251,9 +258,20 @@ export function shouldUnwrapOutput(tokenOut: string): boolean {
|
|
|
251
258
|
*
|
|
252
259
|
* @returns The SwitchPLSFlow contract address
|
|
253
260
|
*/
|
|
254
|
-
export function getPLSFlowAddress(): string {
|
|
255
|
-
return SWITCH_PLS_FLOW;
|
|
256
|
-
}
|
|
261
|
+
export function getPLSFlowAddress(nativeFlowContract?: string): string {
|
|
262
|
+
return nativeFlowContract || SWITCH_PLS_FLOW;
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
export interface LimitOrderNetworkOptions {
|
|
266
|
+
network?: "pulsechain" | "robinhood";
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
function endpointForNetwork(endpoint: string, network?: string): string {
|
|
270
|
+
if (!network) return endpoint;
|
|
271
|
+
const url = new URL(endpoint);
|
|
272
|
+
url.searchParams.set("network", network);
|
|
273
|
+
return url.toString();
|
|
274
|
+
}
|
|
257
275
|
|
|
258
276
|
/**
|
|
259
277
|
* Check if the input token is native PLS (should use PLSFlow instead of EIP-712).
|
|
@@ -312,10 +330,11 @@ export function isNativePLS(tokenIn: string): boolean {
|
|
|
312
330
|
* }
|
|
313
331
|
* ```
|
|
314
332
|
*/
|
|
315
|
-
export async function submitLimitOrder(
|
|
316
|
-
signedOrder: SignedLimitOrder,
|
|
317
|
-
|
|
318
|
-
|
|
333
|
+
export async function submitLimitOrder(
|
|
334
|
+
signedOrder: SignedLimitOrder,
|
|
335
|
+
options: LimitOrderNetworkOptions = {},
|
|
336
|
+
): Promise<CreateLimitOrderResponse | ErrorResponse> {
|
|
337
|
+
const res = await fetch(endpointForNetwork(LIMIT_ORDERS_ENDPOINT, options.network), {
|
|
319
338
|
method: "POST",
|
|
320
339
|
headers: { "Content-Type": "application/json" },
|
|
321
340
|
body: JSON.stringify(signedOrder),
|
|
@@ -336,11 +355,12 @@ export async function submitLimitOrder(
|
|
|
336
355
|
* @param nonce - Nonce of the order to cancel
|
|
337
356
|
* @returns Success confirmation or error
|
|
338
357
|
*/
|
|
339
|
-
export async function cancelLimitOrder(
|
|
340
|
-
maker: string,
|
|
341
|
-
nonce: number,
|
|
342
|
-
|
|
343
|
-
|
|
358
|
+
export async function cancelLimitOrder(
|
|
359
|
+
maker: string,
|
|
360
|
+
nonce: number,
|
|
361
|
+
options: LimitOrderNetworkOptions = {},
|
|
362
|
+
): Promise<CancelLimitOrderResponse | ErrorResponse> {
|
|
363
|
+
const res = await fetch(endpointForNetwork(LIMIT_ORDERS_ENDPOINT, options.network), {
|
|
344
364
|
method: "DELETE",
|
|
345
365
|
headers: { "Content-Type": "application/json" },
|
|
346
366
|
body: JSON.stringify({ maker, nonce }),
|
|
@@ -350,7 +370,9 @@ export async function cancelLimitOrder(
|
|
|
350
370
|
}
|
|
351
371
|
|
|
352
372
|
/** Filter options for listing limit orders */
|
|
353
|
-
export interface ListLimitOrdersOptions {
|
|
373
|
+
export interface ListLimitOrdersOptions {
|
|
374
|
+
/** Backend network process to query. */
|
|
375
|
+
network?: "pulsechain" | "robinhood";
|
|
354
376
|
/** Filter by order status. Default: `"ACTIVE"` */
|
|
355
377
|
status?: LimitOrderStatus;
|
|
356
378
|
/** Filter by maker address */
|
|
@@ -415,7 +437,8 @@ export async function fetchLimitOrders(
|
|
|
415
437
|
if (options.tokenOut) params.set("tokenOut", options.tokenOut);
|
|
416
438
|
if (options.pair) params.set("pair", options.pair);
|
|
417
439
|
if (options.limit != null) params.set("limit", String(options.limit));
|
|
418
|
-
if (options.offset != null) params.set("offset", String(options.offset));
|
|
440
|
+
if (options.offset != null) params.set("offset", String(options.offset));
|
|
441
|
+
if (options.network) params.set("network", options.network);
|
|
419
442
|
|
|
420
443
|
const url = params.toString()
|
|
421
444
|
? `${LIMIT_ORDERS_ENDPOINT}?${params}`
|
|
@@ -432,11 +455,14 @@ export async function fetchLimitOrders(
|
|
|
432
455
|
* @param nonce - Order nonce
|
|
433
456
|
* @returns The order record, or an error if not found
|
|
434
457
|
*/
|
|
435
|
-
export async function fetchLimitOrder(
|
|
436
|
-
maker: string,
|
|
437
|
-
nonce: number,
|
|
438
|
-
|
|
439
|
-
|
|
458
|
+
export async function fetchLimitOrder(
|
|
459
|
+
maker: string,
|
|
460
|
+
nonce: number,
|
|
461
|
+
options: LimitOrderNetworkOptions = {},
|
|
462
|
+
): Promise<LimitOrderRecord | ErrorResponse> {
|
|
463
|
+
const res = await fetch(
|
|
464
|
+
endpointForNetwork(`${LIMIT_ORDERS_ENDPOINT}/${maker}/${nonce}`, options.network),
|
|
465
|
+
);
|
|
440
466
|
return res.json() as Promise<LimitOrderRecord | ErrorResponse>;
|
|
441
467
|
}
|
|
442
468
|
|
|
@@ -445,8 +471,10 @@ export async function fetchLimitOrder(
|
|
|
445
471
|
*
|
|
446
472
|
* Useful for displaying which token pairs have open limit orders.
|
|
447
473
|
*/
|
|
448
|
-
export async function fetchLimitOrderPairs(
|
|
449
|
-
|
|
474
|
+
export async function fetchLimitOrderPairs(
|
|
475
|
+
options: LimitOrderNetworkOptions = {},
|
|
476
|
+
): Promise<LimitOrderPair[]> {
|
|
477
|
+
const res = await fetch(endpointForNetwork(LIMIT_ORDER_PAIRS_ENDPOINT, options.network));
|
|
450
478
|
return res.json() as Promise<LimitOrderPair[]>;
|
|
451
479
|
}
|
|
452
480
|
|
|
@@ -455,7 +483,9 @@ export async function fetchLimitOrderPairs(): Promise<LimitOrderPair[]> {
|
|
|
455
483
|
*
|
|
456
484
|
* Returns counts of active, filled, cancelled, and expired orders.
|
|
457
485
|
*/
|
|
458
|
-
export async function fetchLimitOrderStats(
|
|
459
|
-
|
|
486
|
+
export async function fetchLimitOrderStats(
|
|
487
|
+
options: LimitOrderNetworkOptions = {},
|
|
488
|
+
): Promise<LimitOrderStats> {
|
|
489
|
+
const res = await fetch(endpointForNetwork(LIMIT_ORDER_STATS_ENDPOINT, options.network));
|
|
460
490
|
return res.json() as Promise<LimitOrderStats>;
|
|
461
491
|
}
|
package/src/networks/index.ts
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
export {
|
|
2
|
-
ROBINHOOD_NETWORK,
|
|
3
|
-
ROBINHOOD_CHAIN,
|
|
4
|
-
ROBINHOOD_NATIVE_ETH,
|
|
5
|
-
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";
|
|
1
|
+
export {
|
|
2
|
+
ROBINHOOD_NETWORK,
|
|
3
|
+
ROBINHOOD_CHAIN,
|
|
4
|
+
ROBINHOOD_NATIVE_ETH,
|
|
5
|
+
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";
|