@switch-win/sdk 1.2.9 → 1.3.1
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/CHANGELOG.md +34 -0
- package/GASLESS.md +434 -0
- package/LIMIT-ORDERS.md +213 -205
- package/README.md +134 -105
- package/ROBINHOOD.md +201 -198
- package/abi/GaslessSwitchV2ABI.json +1095 -0
- package/dist/constants.d.ts +276 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +403 -0
- package/dist/constants.js.map +1 -0
- package/dist/gasless-client.d.ts +82 -0
- package/dist/gasless-client.d.ts.map +1 -0
- package/dist/gasless-client.js +467 -0
- package/dist/gasless-client.js.map +1 -0
- package/dist/gasless-index.d.ts +5 -0
- package/dist/gasless-index.d.ts.map +1 -0
- package/dist/gasless-index.js +5 -0
- package/dist/gasless-index.js.map +1 -0
- package/dist/gasless-operators.d.ts +32 -0
- package/dist/gasless-operators.d.ts.map +1 -0
- package/dist/gasless-operators.js +132 -0
- package/dist/gasless-operators.js.map +1 -0
- package/dist/gasless-store.d.ts +18 -0
- package/dist/gasless-store.d.ts.map +1 -0
- package/dist/gasless-store.js +83 -0
- package/dist/gasless-store.js.map +1 -0
- package/dist/gasless-types.d.ts +222 -0
- package/dist/gasless-types.d.ts.map +1 -0
- package/dist/gasless-types.js +2 -0
- package/dist/gasless-types.js.map +1 -0
- package/dist/gasless.d.ts +135 -0
- package/dist/gasless.d.ts.map +1 -0
- package/dist/gasless.js +513 -0
- package/dist/gasless.js.map +1 -0
- package/dist/index.d.ts +29 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +30 -0
- package/dist/index.js.map +1 -0
- package/dist/limit-orders.d.ts +440 -0
- package/dist/limit-orders.d.ts.map +1 -0
- package/dist/limit-orders.js +387 -0
- package/dist/limit-orders.js.map +1 -0
- package/dist/networks/index.d.ts +3 -0
- package/dist/networks/index.d.ts.map +1 -0
- package/dist/networks/index.js +2 -0
- package/dist/networks/index.js.map +1 -0
- package/dist/networks/robinhood.d.ts +536 -0
- package/dist/networks/robinhood.d.ts.map +1 -0
- package/dist/networks/robinhood.js +489 -0
- package/dist/networks/robinhood.js.map +1 -0
- package/dist/types.d.ts +436 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +19 -0
- package/dist/types.js.map +1 -0
- package/examples/gasless-nextjs-proxy.ts +87 -0
- package/examples/gasless-operator.ts +76 -0
- package/examples/gasless-swap.ts +173 -0
- package/examples/limit-order-ethers.ts +195 -0
- package/examples/nextjs-proxy.ts +82 -0
- package/examples/react-hooks.tsx +396 -0
- package/examples/swap-ethers.ts +209 -0
- package/examples/swap-web3py.py +267 -0
- package/package.json +53 -12
- package/src/constants.ts +184 -182
- package/src/gasless-client.ts +824 -0
- package/src/gasless-index.ts +4 -0
- package/src/gasless-operators.ts +227 -0
- package/src/gasless-store.ts +137 -0
- package/src/gasless-types.ts +262 -0
- package/src/gasless.ts +756 -0
- package/src/index.ts +69 -63
- package/src/limit-orders.ts +206 -195
- package/src/types.ts +80 -55
|
@@ -0,0 +1,440 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Switch Limit Orders (V2) — Helper Functions
|
|
3
|
+
*
|
|
4
|
+
* Provides a complete toolkit for creating, signing, submitting, querying,
|
|
5
|
+
* and cancelling EIP-712 signed limit orders on PulseChain and Robinhood
|
|
6
|
+
* Chain.
|
|
7
|
+
*
|
|
8
|
+
* ## How it works
|
|
9
|
+
*
|
|
10
|
+
* 1. **Build** order parameters with `buildLimitOrder()`
|
|
11
|
+
* 2. **Sign** via EIP-712 with your wallet (ethers.js `signTypedData`)
|
|
12
|
+
* 3. **Submit** the signed order to the Switch backend with `submitLimitOrder()`
|
|
13
|
+
* 4. The Switch filler bot monitors active orders and fills them when profitable
|
|
14
|
+
* 5. **Cancel** an order on-chain via `invalidateNonce()`; the backend indexer
|
|
15
|
+
* observes the cancellation event
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```ts
|
|
19
|
+
* import { buildLimitOrder, submitLimitOrder, fetchLimitOrders } from "@switch-win/sdk/limit-orders";
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
import type { LimitOrderParams, SignedLimitOrder, CreateLimitOrderResponse, CancelLimitOrderResponse, ListLimitOrdersResponse, LimitOrderRecord, LimitOrderPair, LimitOrderStats, LimitOrderConfigResponse, LimitOrderStatus, ErrorResponse } from "./types.js";
|
|
23
|
+
export { LIMIT_ORDER_EIP712_DOMAIN, LIMIT_ORDER_EIP712_TYPES } from "./constants.js";
|
|
24
|
+
/** Options for building a limit order */
|
|
25
|
+
export interface BuildLimitOrderOptions {
|
|
26
|
+
/** Maker (signer) address */
|
|
27
|
+
maker: string;
|
|
28
|
+
/** Input token address (token being sold) */
|
|
29
|
+
tokenIn: string;
|
|
30
|
+
/** Output token address (token being bought) */
|
|
31
|
+
tokenOut: string;
|
|
32
|
+
/** Amount of tokenIn to sell (wei string) */
|
|
33
|
+
amountIn: string;
|
|
34
|
+
/** Minimum amount of tokenOut to accept (wei string) */
|
|
35
|
+
minAmountOut: string;
|
|
36
|
+
/**
|
|
37
|
+
* Order expiry as a Unix timestamp. Defaults to `0` (no expiry).
|
|
38
|
+
* Tip: use `Math.floor(Date.now() / 1000) + 86400` for 24-hour expiry.
|
|
39
|
+
*/
|
|
40
|
+
deadline?: number;
|
|
41
|
+
/**
|
|
42
|
+
* Unique nonce. Defaults to `Date.now()` (milliseconds) which is
|
|
43
|
+
* practically unique for a single maker. You can also use a random integer.
|
|
44
|
+
*/
|
|
45
|
+
nonce?: number;
|
|
46
|
+
/**
|
|
47
|
+
* Fee mode — `true` to take fee from output, `false` from input. Default `false`.
|
|
48
|
+
*
|
|
49
|
+
* This choice is **permanent once signed** and has two major effects:
|
|
50
|
+
*
|
|
51
|
+
* ### 1. Determines the approval target
|
|
52
|
+
*
|
|
53
|
+
* | `feeOnOutput` | Maker must approve | Helper |
|
|
54
|
+
* |---|---|---|
|
|
55
|
+
* | `false` (default) | **SwitchLimitOrder** | `getApprovalTarget()` |
|
|
56
|
+
* | `true` | **SwitchRouter** | `getRouterApprovalTarget()` |
|
|
57
|
+
*
|
|
58
|
+
* ### 2. Constrains how operators (fillers) can take profit
|
|
59
|
+
*
|
|
60
|
+
* When `feeOnOutput=false`, the LO contract holds all input tokens
|
|
61
|
+
* after pulling them from the maker. Operators can freely choose to
|
|
62
|
+
* take their profit from either the input side or the output side.
|
|
63
|
+
*
|
|
64
|
+
* When `feeOnOutput=true`, the Router pulls tokens directly from the
|
|
65
|
+
* maker. If an operator also wants to take excess *input* tokens,
|
|
66
|
+
* the LO contract would need a **second** approval (from the maker
|
|
67
|
+
* to the LO contract) — which the maker typically hasn't granted.
|
|
68
|
+
* This means operators are effectively limited to taking profit
|
|
69
|
+
* from the output side only. The order is still fully fillable,
|
|
70
|
+
* but operators have less flexibility. In low-liquidity or
|
|
71
|
+
* tight-margin situations, this could reduce the chance of a fill.
|
|
72
|
+
*
|
|
73
|
+
* ### 3. Tax (fee-on-transfer) token guidelines
|
|
74
|
+
*
|
|
75
|
+
* - **Tax input token** → set `feeOnOutput: true`
|
|
76
|
+
* (Router sends tokens directly from maker to pool — one transfer,
|
|
77
|
+
* one tax. Avoids the double sell-tax of maker → LO → pool.)
|
|
78
|
+
* - **Tax output token** → set `feeOnOutput: false` (default)
|
|
79
|
+
* (Output goes directly to recipient in one transfer.)
|
|
80
|
+
* - **Both tokens tax** → use `feeOnOutput: false`; execution is restricted
|
|
81
|
+
* to tax-compatible Uniswap V2 routing.
|
|
82
|
+
*
|
|
83
|
+
* **Bottom line:** Use `feeOnOutput: false` (default) unless the input
|
|
84
|
+
* token is a tax token. This gives operators maximum flexibility and
|
|
85
|
+
* the best chance of your order being filled.
|
|
86
|
+
*/
|
|
87
|
+
feeOnOutput?: boolean;
|
|
88
|
+
/**
|
|
89
|
+
* Recipient address for the output tokens. Defaults to the maker address.
|
|
90
|
+
* Set to a different address to send output to another wallet.
|
|
91
|
+
*/
|
|
92
|
+
recipient?: string;
|
|
93
|
+
/**
|
|
94
|
+
* If `true` and tokenOut is WPLS, the contract unwraps to native PLS
|
|
95
|
+
* before sending to the recipient. Default `false`.
|
|
96
|
+
*/
|
|
97
|
+
unwrapOutput?: boolean;
|
|
98
|
+
/**
|
|
99
|
+
* Partner address to receive 50% of protocol fees.
|
|
100
|
+
* Defaults to the zero address (no partner).
|
|
101
|
+
*/
|
|
102
|
+
partnerAddress?: string;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Build a `LimitOrderParams` object ready for EIP-712 signing.
|
|
106
|
+
*
|
|
107
|
+
* @param options - Order parameters
|
|
108
|
+
* @returns A fully-populated `LimitOrderParams` object
|
|
109
|
+
*
|
|
110
|
+
* @example
|
|
111
|
+
* ```ts
|
|
112
|
+
* const order = buildLimitOrder({
|
|
113
|
+
* maker: "0xYourAddress",
|
|
114
|
+
* tokenIn: WPLS,
|
|
115
|
+
* tokenOut: "0xPLSXAddress",
|
|
116
|
+
* amountIn: ethers.parseUnits("1000", 18).toString(),
|
|
117
|
+
* minAmountOut: ethers.parseUnits("500000", 18).toString(),
|
|
118
|
+
* });
|
|
119
|
+
* ```
|
|
120
|
+
*/
|
|
121
|
+
export declare function buildLimitOrder(options: BuildLimitOrderOptions): LimitOrderParams;
|
|
122
|
+
/**
|
|
123
|
+
* Get the EIP-712 domain and types needed for signing a limit order.
|
|
124
|
+
*
|
|
125
|
+
* Pass the returned values directly to your wallet's `signTypedData` method.
|
|
126
|
+
*
|
|
127
|
+
* @example
|
|
128
|
+
* ```ts
|
|
129
|
+
* // ethers.js v6
|
|
130
|
+
* const { domain, types } = getEIP712SigningParams();
|
|
131
|
+
* const signature = await signer.signTypedData(domain, types, order);
|
|
132
|
+
*
|
|
133
|
+
* // ethers.js v5
|
|
134
|
+
* const signature = await signer._signTypedData(domain, types, order);
|
|
135
|
+
* ```
|
|
136
|
+
*/
|
|
137
|
+
export declare function getEIP712SigningParams(limitOrderContract?: string, chainId?: number): {
|
|
138
|
+
readonly domain: {
|
|
139
|
+
readonly name: "SwitchLimitOrder";
|
|
140
|
+
readonly version: "2";
|
|
141
|
+
readonly chainId: number;
|
|
142
|
+
readonly verifyingContract: string;
|
|
143
|
+
};
|
|
144
|
+
readonly types: {
|
|
145
|
+
readonly LimitOrder: readonly [{
|
|
146
|
+
readonly name: "maker";
|
|
147
|
+
readonly type: "address";
|
|
148
|
+
}, {
|
|
149
|
+
readonly name: "tokenIn";
|
|
150
|
+
readonly type: "address";
|
|
151
|
+
}, {
|
|
152
|
+
readonly name: "tokenOut";
|
|
153
|
+
readonly type: "address";
|
|
154
|
+
}, {
|
|
155
|
+
readonly name: "amountIn";
|
|
156
|
+
readonly type: "uint256";
|
|
157
|
+
}, {
|
|
158
|
+
readonly name: "minAmountOut";
|
|
159
|
+
readonly type: "uint256";
|
|
160
|
+
}, {
|
|
161
|
+
readonly name: "deadline";
|
|
162
|
+
readonly type: "uint256";
|
|
163
|
+
}, {
|
|
164
|
+
readonly name: "nonce";
|
|
165
|
+
readonly type: "uint256";
|
|
166
|
+
}, {
|
|
167
|
+
readonly name: "feeOnOutput";
|
|
168
|
+
readonly type: "bool";
|
|
169
|
+
}, {
|
|
170
|
+
readonly name: "recipient";
|
|
171
|
+
readonly type: "address";
|
|
172
|
+
}, {
|
|
173
|
+
readonly name: "unwrapOutput";
|
|
174
|
+
readonly type: "bool";
|
|
175
|
+
}, {
|
|
176
|
+
readonly name: "partnerAddress";
|
|
177
|
+
readonly type: "address";
|
|
178
|
+
}];
|
|
179
|
+
};
|
|
180
|
+
};
|
|
181
|
+
/**
|
|
182
|
+
* Get the approval target for `feeOnOutput: false` orders (the default).
|
|
183
|
+
*
|
|
184
|
+
* When `feeOnOutput` is `false`, the **SwitchLimitOrder** contract pulls
|
|
185
|
+
* tokens from the maker via `safeTransferFrom`, then forwards them to the
|
|
186
|
+
* router internally. The maker must `approve(SWITCH_LIMIT_ORDER, amountIn)`.
|
|
187
|
+
*
|
|
188
|
+
* For `feeOnOutput: true` orders, use {@link getRouterApprovalTarget} instead.
|
|
189
|
+
*
|
|
190
|
+
* @returns The SwitchLimitOrder contract address
|
|
191
|
+
*/
|
|
192
|
+
export declare function getApprovalTarget(limitOrderContract?: string): string;
|
|
193
|
+
/**
|
|
194
|
+
* Get the approval target for `feeOnOutput: true` orders.
|
|
195
|
+
*
|
|
196
|
+
* When `feeOnOutput` is `true`, the **SwitchRouter** pulls tokens directly
|
|
197
|
+
* from the maker via `goSwitchFrom` (one transfer, one tax — ideal for tax
|
|
198
|
+
* input tokens). The maker must `approve(SWITCH_ROUTER, amountIn)`.
|
|
199
|
+
*
|
|
200
|
+
* For `feeOnOutput: false` orders (default), use {@link getApprovalTarget} instead.
|
|
201
|
+
*
|
|
202
|
+
* @returns The SwitchRouter contract address
|
|
203
|
+
*/
|
|
204
|
+
export declare function getRouterApprovalTarget(routerContract?: string): string;
|
|
205
|
+
/**
|
|
206
|
+
* Determine whether `unwrapOutput` should be set for a given output token.
|
|
207
|
+
*
|
|
208
|
+
* Returns `true` only if `tokenOut` is WPLS (the output will be unwrapped
|
|
209
|
+
* to native PLS by the contract).
|
|
210
|
+
*/
|
|
211
|
+
export declare function shouldUnwrapOutput(tokenOut: string, wrappedNativeToken?: string): boolean;
|
|
212
|
+
/**
|
|
213
|
+
* Get the SwitchPLSFlow contract address.
|
|
214
|
+
*
|
|
215
|
+
* Use this contract to create native PLS limit orders (sell PLS for any token)
|
|
216
|
+
* in a single transaction — no EIP-712 signing required.
|
|
217
|
+
*
|
|
218
|
+
* @returns The SwitchPLSFlow contract address
|
|
219
|
+
*/
|
|
220
|
+
export declare function getPLSFlowAddress(nativeFlowContract?: string): string;
|
|
221
|
+
/** Networks supported by the shared Switch limit-order API. */
|
|
222
|
+
export type LimitOrderNetwork = "pulsechain" | "robinhood";
|
|
223
|
+
/** Complete deployment metadata needed to create or fill limit orders. */
|
|
224
|
+
export interface LimitOrderNetworkConfig {
|
|
225
|
+
network: LimitOrderNetwork;
|
|
226
|
+
chainId: number;
|
|
227
|
+
chainName: string;
|
|
228
|
+
nativeSymbol: "PLS" | "ETH";
|
|
229
|
+
nativeSentinel: string;
|
|
230
|
+
wrappedNativeToken: string;
|
|
231
|
+
routerContract: string;
|
|
232
|
+
limitOrderContract: string;
|
|
233
|
+
nativeFlowContract: string;
|
|
234
|
+
}
|
|
235
|
+
/** Static defaults. Prefer {@link fetchLimitOrderConfig} at application startup. */
|
|
236
|
+
export declare const LIMIT_ORDER_NETWORK_CONFIGS: Readonly<Record<LimitOrderNetwork, LimitOrderNetworkConfig>>;
|
|
237
|
+
/** Return the static deployment defaults for a supported limit-order network. */
|
|
238
|
+
export declare function getLimitOrderNetworkConfig(network?: LimitOrderNetwork): LimitOrderNetworkConfig;
|
|
239
|
+
/** Build the correct EIP-712 signing domain for a supported network. */
|
|
240
|
+
export declare function getNetworkEIP712SigningParams(network: LimitOrderNetwork, limitOrderContract?: string): {
|
|
241
|
+
readonly domain: {
|
|
242
|
+
readonly name: "SwitchLimitOrder";
|
|
243
|
+
readonly version: "2";
|
|
244
|
+
readonly chainId: number;
|
|
245
|
+
readonly verifyingContract: string;
|
|
246
|
+
};
|
|
247
|
+
readonly types: {
|
|
248
|
+
readonly LimitOrder: readonly [{
|
|
249
|
+
readonly name: "maker";
|
|
250
|
+
readonly type: "address";
|
|
251
|
+
}, {
|
|
252
|
+
readonly name: "tokenIn";
|
|
253
|
+
readonly type: "address";
|
|
254
|
+
}, {
|
|
255
|
+
readonly name: "tokenOut";
|
|
256
|
+
readonly type: "address";
|
|
257
|
+
}, {
|
|
258
|
+
readonly name: "amountIn";
|
|
259
|
+
readonly type: "uint256";
|
|
260
|
+
}, {
|
|
261
|
+
readonly name: "minAmountOut";
|
|
262
|
+
readonly type: "uint256";
|
|
263
|
+
}, {
|
|
264
|
+
readonly name: "deadline";
|
|
265
|
+
readonly type: "uint256";
|
|
266
|
+
}, {
|
|
267
|
+
readonly name: "nonce";
|
|
268
|
+
readonly type: "uint256";
|
|
269
|
+
}, {
|
|
270
|
+
readonly name: "feeOnOutput";
|
|
271
|
+
readonly type: "bool";
|
|
272
|
+
}, {
|
|
273
|
+
readonly name: "recipient";
|
|
274
|
+
readonly type: "address";
|
|
275
|
+
}, {
|
|
276
|
+
readonly name: "unwrapOutput";
|
|
277
|
+
readonly type: "bool";
|
|
278
|
+
}, {
|
|
279
|
+
readonly name: "partnerAddress";
|
|
280
|
+
readonly type: "address";
|
|
281
|
+
}];
|
|
282
|
+
};
|
|
283
|
+
};
|
|
284
|
+
/** Resolve the maker's ERC-20 approval target for the selected fee mode. */
|
|
285
|
+
export declare function getLimitOrderApprovalTarget(network: LimitOrderNetwork, feeOnOutput: boolean, overrides?: {
|
|
286
|
+
limitOrderContract?: string;
|
|
287
|
+
routerContract?: string;
|
|
288
|
+
}): string;
|
|
289
|
+
export interface LimitOrderNetworkOptions {
|
|
290
|
+
network?: LimitOrderNetwork;
|
|
291
|
+
}
|
|
292
|
+
/**
|
|
293
|
+
* Check if the input token is native PLS (should use PLSFlow instead of EIP-712).
|
|
294
|
+
*
|
|
295
|
+
* When the user wants to sell native PLS (not WPLS), they should use the
|
|
296
|
+
* PLSFlow contract instead of the standard EIP-712 signing flow.
|
|
297
|
+
*
|
|
298
|
+
* @param tokenIn - The input token address
|
|
299
|
+
* @returns `true` if tokenIn is the native PLS sentinel address
|
|
300
|
+
*/
|
|
301
|
+
export declare function isNativePLS(tokenIn: string): boolean;
|
|
302
|
+
/** Network-neutral native-currency sentinel check (PLS or ETH). */
|
|
303
|
+
export declare function isNativeCurrency(tokenIn: string): boolean;
|
|
304
|
+
/** Return the native-order flow contract for PulseChain or Robinhood Chain. */
|
|
305
|
+
export declare function getNativeFlowAddress(network: LimitOrderNetwork, nativeFlowContract?: string): string;
|
|
306
|
+
/**
|
|
307
|
+
* Submit a signed limit order to the Switch backend.
|
|
308
|
+
*
|
|
309
|
+
* The backend verifies the EIP-712 signature and stores the order. No gas
|
|
310
|
+
* is required — this is an off-chain operation.
|
|
311
|
+
*
|
|
312
|
+
* **⚠️ CRITICAL:** For standard ERC-20 orders, the EIP-712 signature is
|
|
313
|
+
* purely off-chain — nothing is recorded on-chain until the bot fills it.
|
|
314
|
+
* If this POST fails or never fires (e.g. user closes their browser after
|
|
315
|
+
* signing), the **order is permanently lost**. Your integration should:
|
|
316
|
+
*
|
|
317
|
+
* 1. Call `submitLimitOrder()` **immediately** after the user signs.
|
|
318
|
+
* 2. **Await** the response and verify `success: true` before showing
|
|
319
|
+
* the order as "created" in your UI.
|
|
320
|
+
* 3. If the POST fails, first query the same maker + nonce and verify its
|
|
321
|
+
* contract and every signed field. The backend rejects duplicate nonces;
|
|
322
|
+
* it does not return an idempotent success. Retry only the identical payload,
|
|
323
|
+
* preserving its nonce and signature while the order is still live.
|
|
324
|
+
* 4. Do **not** navigate away or close the signing flow until the
|
|
325
|
+
* backend confirms the order.
|
|
326
|
+
*
|
|
327
|
+
* Native PLS/ETH flow orders are an exception — they are recorded
|
|
328
|
+
* on-chain first, so the backend can discover them via event indexing
|
|
329
|
+
* even if the POST never arrives.
|
|
330
|
+
*
|
|
331
|
+
* @param signedOrder - Order parameters + EIP-712 signature
|
|
332
|
+
* @returns The created order record, or an error
|
|
333
|
+
*
|
|
334
|
+
* @example
|
|
335
|
+
* ```ts
|
|
336
|
+
* const order = buildLimitOrder({ ... });
|
|
337
|
+
* const signature = await signer.signTypedData(domain, types, order);
|
|
338
|
+
* const result = await submitLimitOrder({ ...order, signature });
|
|
339
|
+
*
|
|
340
|
+
* if ("error" in result) {
|
|
341
|
+
* console.error(result.error);
|
|
342
|
+
* } else {
|
|
343
|
+
* console.log("Order created:", result.order.id);
|
|
344
|
+
* }
|
|
345
|
+
* ```
|
|
346
|
+
*/
|
|
347
|
+
export declare function submitLimitOrder(signedOrder: SignedLimitOrder, options?: LimitOrderNetworkOptions): Promise<CreateLimitOrderResponse | ErrorResponse>;
|
|
348
|
+
/**
|
|
349
|
+
* Legacy helper for backend deployments that implemented REST cancellation.
|
|
350
|
+
*
|
|
351
|
+
* The current hosted Switch API intentionally has no DELETE endpoint.
|
|
352
|
+
* Cancellation must be performed on-chain with `invalidateNonce(nonce)` on
|
|
353
|
+
* the contract stored in the order's `limitOrderContract` field. The indexer
|
|
354
|
+
* then updates the order status from the emitted event.
|
|
355
|
+
*
|
|
356
|
+
* @param maker - Maker address
|
|
357
|
+
* @param nonce - Nonce of the order to cancel
|
|
358
|
+
* @returns Success confirmation or error on compatible legacy backends
|
|
359
|
+
* @deprecated Do not use with the hosted Switch API; cancel on-chain instead.
|
|
360
|
+
*/
|
|
361
|
+
export declare function cancelLimitOrder(maker: string, nonce: number, options?: LimitOrderNetworkOptions): Promise<CancelLimitOrderResponse | ErrorResponse>;
|
|
362
|
+
/** Filter options for listing limit orders */
|
|
363
|
+
export interface ListLimitOrdersOptions {
|
|
364
|
+
/** Backend network process to query. */
|
|
365
|
+
network?: LimitOrderNetwork;
|
|
366
|
+
/** Filter by order status. Default: `"ACTIVE"` */
|
|
367
|
+
status?: LimitOrderStatus;
|
|
368
|
+
/** Filter by maker address */
|
|
369
|
+
maker?: string;
|
|
370
|
+
/**
|
|
371
|
+
* Filter by owner address. Matches orders where the address is either
|
|
372
|
+
* the `maker` or `recipient` field. Useful for native-PLS (PLSFlow) orders
|
|
373
|
+
* where the maker is the PLSFlow contract but the user is the recipient.
|
|
374
|
+
*/
|
|
375
|
+
owner?: string;
|
|
376
|
+
/** Filter by partner address */
|
|
377
|
+
partnerAddress?: string;
|
|
378
|
+
/** Filter by input token address */
|
|
379
|
+
tokenIn?: string;
|
|
380
|
+
/** Filter by output token address */
|
|
381
|
+
tokenOut?: string;
|
|
382
|
+
/** Filter by pair key (`tokenIn:tokenOut`, lowercased) */
|
|
383
|
+
pair?: string;
|
|
384
|
+
/** Page size (1–500). Default: `100` */
|
|
385
|
+
limit?: number;
|
|
386
|
+
/** Page offset. Default: `0` */
|
|
387
|
+
offset?: number;
|
|
388
|
+
}
|
|
389
|
+
/**
|
|
390
|
+
* Fetch limit orders from the Switch backend with optional filters.
|
|
391
|
+
*
|
|
392
|
+
* @param options - Query filters (all optional)
|
|
393
|
+
* @returns Paginated list of orders
|
|
394
|
+
*
|
|
395
|
+
* @example
|
|
396
|
+
* ```ts
|
|
397
|
+
* // All active orders for a specific maker
|
|
398
|
+
* const { orders, total } = await fetchLimitOrders({
|
|
399
|
+
* maker: "0xYourAddress",
|
|
400
|
+
* status: "ACTIVE",
|
|
401
|
+
* });
|
|
402
|
+
*
|
|
403
|
+
* // All filled orders for a token pair
|
|
404
|
+
* const filled = await fetchLimitOrders({
|
|
405
|
+
* tokenIn: WPLS,
|
|
406
|
+
* tokenOut: "0xPLSXAddress",
|
|
407
|
+
* status: "FILLED",
|
|
408
|
+
* });
|
|
409
|
+
*
|
|
410
|
+
* // Orders attributed to a specific partner
|
|
411
|
+
* const partnerOrders = await fetchLimitOrders({
|
|
412
|
+
* partnerAddress: "0xPartnerAddress",
|
|
413
|
+
* status: "ACTIVE",
|
|
414
|
+
* });
|
|
415
|
+
* ```
|
|
416
|
+
*/
|
|
417
|
+
export declare function fetchLimitOrders(options?: ListLimitOrdersOptions): Promise<ListLimitOrdersResponse>;
|
|
418
|
+
/**
|
|
419
|
+
* Fetch a single limit order by maker address and nonce.
|
|
420
|
+
*
|
|
421
|
+
* @param maker - Maker address
|
|
422
|
+
* @param nonce - Order nonce
|
|
423
|
+
* @returns The order record, or an error if not found
|
|
424
|
+
*/
|
|
425
|
+
export declare function fetchLimitOrder(maker: string, nonce: number, options?: LimitOrderNetworkOptions): Promise<LimitOrderRecord | ErrorResponse>;
|
|
426
|
+
/**
|
|
427
|
+
* Fetch active trading pairs with order counts.
|
|
428
|
+
*
|
|
429
|
+
* Useful for displaying which token pairs have open limit orders.
|
|
430
|
+
*/
|
|
431
|
+
export declare function fetchLimitOrderPairs(options?: LimitOrderNetworkOptions): Promise<LimitOrderPair[]>;
|
|
432
|
+
/** Fetch the active deployment and EIP-712 domain for a network. */
|
|
433
|
+
export declare function fetchLimitOrderConfig(options?: LimitOrderNetworkOptions): Promise<LimitOrderConfigResponse>;
|
|
434
|
+
/**
|
|
435
|
+
* Fetch summary statistics for all limit orders.
|
|
436
|
+
*
|
|
437
|
+
* Returns counts of active, filled, cancelled, and expired orders.
|
|
438
|
+
*/
|
|
439
|
+
export declare function fetchLimitOrderStats(options?: LimitOrderNetworkOptions): Promise<LimitOrderStats>;
|
|
440
|
+
//# sourceMappingURL=limit-orders.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"limit-orders.d.ts","sourceRoot":"","sources":["../src/limit-orders.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,KAAK,EACV,gBAAgB,EAChB,gBAAgB,EAChB,wBAAwB,EACxB,wBAAwB,EACxB,uBAAuB,EACvB,gBAAgB,EAChB,cAAc,EACd,eAAe,EACf,wBAAwB,EACxB,gBAAgB,EAChB,aAAa,EACd,MAAM,YAAY,CAAC;AA6BpB,OAAO,EAAE,yBAAyB,EAAE,wBAAwB,EAAE,MAAM,gBAAgB,CAAC;AAMrF,yCAAyC;AACzC,MAAM,WAAW,sBAAsB;IACrC,6BAA6B;IAC7B,KAAK,EAAE,MAAM,CAAC;IACd,6CAA6C;IAC7C,OAAO,EAAE,MAAM,CAAC;IAChB,gDAAgD;IAChD,QAAQ,EAAE,MAAM,CAAC;IACjB,6CAA6C;IAC7C,QAAQ,EAAE,MAAM,CAAC;IACjB,wDAAwD;IACxD,YAAY,EAAE,MAAM,CAAC;IACrB;;;OAGG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB;;;OAGG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IACf;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAwCG;IACH,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB;;;OAGG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;;OAGG;IACH,YAAY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