@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.
Files changed (73) hide show
  1. package/CHANGELOG.md +34 -0
  2. package/GASLESS.md +434 -0
  3. package/LIMIT-ORDERS.md +213 -205
  4. package/README.md +134 -105
  5. package/ROBINHOOD.md +201 -198
  6. package/abi/GaslessSwitchV2ABI.json +1095 -0
  7. package/dist/constants.d.ts +276 -0
  8. package/dist/constants.d.ts.map +1 -0
  9. package/dist/constants.js +403 -0
  10. package/dist/constants.js.map +1 -0
  11. package/dist/gasless-client.d.ts +82 -0
  12. package/dist/gasless-client.d.ts.map +1 -0
  13. package/dist/gasless-client.js +467 -0
  14. package/dist/gasless-client.js.map +1 -0
  15. package/dist/gasless-index.d.ts +5 -0
  16. package/dist/gasless-index.d.ts.map +1 -0
  17. package/dist/gasless-index.js +5 -0
  18. package/dist/gasless-index.js.map +1 -0
  19. package/dist/gasless-operators.d.ts +32 -0
  20. package/dist/gasless-operators.d.ts.map +1 -0
  21. package/dist/gasless-operators.js +132 -0
  22. package/dist/gasless-operators.js.map +1 -0
  23. package/dist/gasless-store.d.ts +18 -0
  24. package/dist/gasless-store.d.ts.map +1 -0
  25. package/dist/gasless-store.js +83 -0
  26. package/dist/gasless-store.js.map +1 -0
  27. package/dist/gasless-types.d.ts +222 -0
  28. package/dist/gasless-types.d.ts.map +1 -0
  29. package/dist/gasless-types.js +2 -0
  30. package/dist/gasless-types.js.map +1 -0
  31. package/dist/gasless.d.ts +135 -0
  32. package/dist/gasless.d.ts.map +1 -0
  33. package/dist/gasless.js +513 -0
  34. package/dist/gasless.js.map +1 -0
  35. package/dist/index.d.ts +29 -0
  36. package/dist/index.d.ts.map +1 -0
  37. package/dist/index.js +30 -0
  38. package/dist/index.js.map +1 -0
  39. package/dist/limit-orders.d.ts +440 -0
  40. package/dist/limit-orders.d.ts.map +1 -0
  41. package/dist/limit-orders.js +387 -0
  42. package/dist/limit-orders.js.map +1 -0
  43. package/dist/networks/index.d.ts +3 -0
  44. package/dist/networks/index.d.ts.map +1 -0
  45. package/dist/networks/index.js +2 -0
  46. package/dist/networks/index.js.map +1 -0
  47. package/dist/networks/robinhood.d.ts +536 -0
  48. package/dist/networks/robinhood.d.ts.map +1 -0
  49. package/dist/networks/robinhood.js +489 -0
  50. package/dist/networks/robinhood.js.map +1 -0
  51. package/dist/types.d.ts +436 -0
  52. package/dist/types.d.ts.map +1 -0
  53. package/dist/types.js +19 -0
  54. package/dist/types.js.map +1 -0
  55. package/examples/gasless-nextjs-proxy.ts +87 -0
  56. package/examples/gasless-operator.ts +76 -0
  57. package/examples/gasless-swap.ts +173 -0
  58. package/examples/limit-order-ethers.ts +195 -0
  59. package/examples/nextjs-proxy.ts +82 -0
  60. package/examples/react-hooks.tsx +396 -0
  61. package/examples/swap-ethers.ts +209 -0
  62. package/examples/swap-web3py.py +267 -0
  63. package/package.json +53 -12
  64. package/src/constants.ts +184 -182
  65. package/src/gasless-client.ts +824 -0
  66. package/src/gasless-index.ts +4 -0
  67. package/src/gasless-operators.ts +227 -0
  68. package/src/gasless-store.ts +137 -0
  69. package/src/gasless-types.ts +262 -0
  70. package/src/gasless.ts +756 -0
  71. package/src/index.ts +69 -63
  72. package/src/limit-orders.ts +206 -195
  73. package/src/types.ts +80 -55
@@ -0,0 +1,467 @@
1
+ import { Contract, Interface, MaxUint256, verifyTypedData, } from "ethers";
2
+ import { API_BASE, ERC20_ABI, NATIVE_PLS } from "./constants.js";
3
+ import { GASLESS_DEPLOYMENTS, GASLESS_SWITCH_ABI, GaslessError, assessGaslessQuote, buildGaslessOrder, gaslessAddress, gaslessCeil, gaslessUint, getGaslessSigningParams, normalizeGaslessTrade, readGaslessChainState, sameAddress, selectGaslessFeeOnOutput, validateGaslessConfig, validateGaslessTaxInfo, } from "./gasless.js";
4
+ function endpoint(url, query) {
5
+ const suffix = new URLSearchParams(query).toString();
6
+ return `${url}${url.includes("?") ? "&" : "?"}${suffix}`;
7
+ }
8
+ /** Abort bounded reads; a timed-out POST must instead retain its uncertain order lock. */
9
+ export async function withGaslessDeadline(work, timeoutMs, signal) {
10
+ signal?.throwIfAborted();
11
+ let timer;
12
+ let onAbort;
13
+ const timeout = new Promise((_, reject) => {
14
+ timer = setTimeout(() => reject(new GaslessError("REQUEST_TIMEOUT", "Gasless request timed out.", true)), timeoutMs);
15
+ onAbort = () => reject(signal?.reason ?? new GaslessError("ABORTED", "Request cancelled."));
16
+ signal?.addEventListener("abort", onAbort, { once: true });
17
+ });
18
+ try {
19
+ return await Promise.race([work(), timeout]);
20
+ }
21
+ finally {
22
+ clearTimeout(timer);
23
+ signal?.removeEventListener("abort", onAbort);
24
+ }
25
+ }
26
+ /** Complete field comparison prevents a duplicate-nonce response matching a different order. */
27
+ export function gaslessRecordMatches(pending, record) {
28
+ const o = pending.order;
29
+ return (sameAddress(record.limitOrderContract, pending.contract) &&
30
+ ["maker", "tokenIn", "tokenOut", "recipient", "partnerAddress"].every((key) => sameAddress(record[key], o[key])) &&
31
+ record.nonce === o.nonce &&
32
+ record.deadline === o.deadline &&
33
+ record.amountIn === o.amountIn &&
34
+ record.minAmountOut === o.minAmountOut &&
35
+ record.feeOnOutput === o.feeOnOutput &&
36
+ record.unwrapOutput === o.unwrapOutput);
37
+ }
38
+ export class GaslessSubmissionError extends GaslessError {
39
+ pending;
40
+ constructor(message, pending) {
41
+ super("SUBMISSION_UNCERTAIN", message, true);
42
+ this.pending = pending;
43
+ this.name = "GaslessSubmissionError";
44
+ }
45
+ }
46
+ /** Gasless settlements charge a fixed 0.1% protocol fee, plus an operator payout
47
+ * capped at 0.05% of the after-fee base including gas. Integrators cannot override
48
+ * the protocol fee; offer regular swaps only if this fee policy is unsuitable.
49
+ * No background quote polling. Each method is explicit; status checks never request a quote. */
50
+ export class GaslessSwapClient {
51
+ deployment;
52
+ provider;
53
+ fetcher;
54
+ quoteUrl;
55
+ ordersUrl;
56
+ taxUrl;
57
+ constructor(options) {
58
+ const deployment = {
59
+ ...(options.deployment ?? GASLESS_DEPLOYMENTS[options.network]),
60
+ };
61
+ if (deployment.network !== options.network ||
62
+ deployment.chainId !== GASLESS_DEPLOYMENTS[options.network].chainId)
63
+ throw new GaslessError("WRONG_CHAIN", "Deployment and requested network differ.");
64
+ this.deployment = Object.freeze({
65
+ ...deployment,
66
+ contract: gaslessAddress(deployment.contract),
67
+ router: gaslessAddress(deployment.router),
68
+ wrappedNative: gaslessAddress(deployment.wrappedNative),
69
+ });
70
+ this.provider = options.provider;
71
+ this.fetcher = options.fetch ?? globalThis.fetch;
72
+ const base = (options.apiBaseUrl ?? API_BASE).replace(/\/$/, "");
73
+ this.quoteUrl = options.quoteEndpoint ?? `${base}/swap/quote`;
74
+ this.ordersUrl = options.ordersEndpoint ?? `${base}/limit-orders`;
75
+ this.taxUrl = options.taxEndpoint ?? `${base}/swap/checkTax`;
76
+ }
77
+ async request(url, init = {}, signal, timeoutMs = 15_000) {
78
+ const timeout = AbortSignal.timeout(timeoutMs);
79
+ const combined = signal ? AbortSignal.any([signal, timeout]) : timeout;
80
+ const response = await this.fetcher(url, {
81
+ ...init,
82
+ cache: "no-store",
83
+ signal: combined,
84
+ });
85
+ const body = await response.json().catch(() => null);
86
+ const error = body && typeof body === "object" && "error" in body
87
+ ? String(body.error)
88
+ : undefined;
89
+ if (!response.ok || error || !body)
90
+ throw new GaslessError("API_ERROR", error ?? `Switch API returned HTTP ${response.status}.`, response.status >= 500 || response.status === 429);
91
+ return body;
92
+ }
93
+ async getConfig(signal) {
94
+ const config = await this.request(endpoint(`${this.ordersUrl}/config`, {
95
+ network: this.deployment.network,
96
+ }), {}, signal);
97
+ validateGaslessConfig(config, this.deployment);
98
+ return config;
99
+ }
100
+ async tax(token, maker, signal) {
101
+ if (sameAddress(token, NATIVE_PLS) ||
102
+ sameAddress(token, this.deployment.wrappedNative))
103
+ return { isTaxToken: false, sellTaxBps: 0, buyTaxBps: 0 };
104
+ const tax = await this.request(endpoint(this.taxUrl, {
105
+ network: this.deployment.network,
106
+ token,
107
+ sender: maker,
108
+ }), {}, signal);
109
+ validateGaslessTaxInfo(tax);
110
+ return tax;
111
+ }
112
+ async checkQuoteBlock(quote, signal) {
113
+ if (!Number.isSafeInteger(quote.quoteBlockNumber) ||
114
+ quote.quoteBlockNumber <= 0)
115
+ throw new GaslessError("INVALID_PREVIEW", "Missing quote block.");
116
+ const block = await withGaslessDeadline(() => this.provider.getBlock(quote.quoteBlockNumber), 10_000, signal);
117
+ const now = Date.now() / 1000;
118
+ if (!block || now - block.timestamp > 90 || block.timestamp > now + 15)
119
+ throw new GaslessError("STALE_QUOTE", "The quote uses an old or unavailable chain snapshot.", true);
120
+ }
121
+ /** Connected-wallet quote. Missing gas simulation or unknown taxes never enable gasless. */
122
+ async quote(tradeInput, signal) {
123
+ const trade = normalizeGaslessTrade(tradeInput);
124
+ if (sameAddress(trade.tokenIn, NATIVE_PLS))
125
+ return {
126
+ eligible: false,
127
+ code: "NATIVE_INPUT_REQUIRES_WRAP",
128
+ reason: "Wrap native currency first (wrapping requires gas), or use Regular.",
129
+ retryable: false,
130
+ };
131
+ try {
132
+ const [network, , inputTax, outputTax] = await Promise.all([
133
+ withGaslessDeadline(() => this.provider.getNetwork(), 10_000, signal),
134
+ this.getConfig(signal),
135
+ this.tax(trade.tokenIn, trade.maker, signal),
136
+ this.tax(trade.tokenOut, trade.maker, signal),
137
+ ]);
138
+ if (network.chainId !== BigInt(this.deployment.chainId))
139
+ throw new GaslessError("WRONG_CHAIN", "RPC is on another network.");
140
+ const feeOnOutput = selectGaslessFeeOnOutput(this.deployment.network, trade.tokenIn, trade.tokenOut, inputTax, outputTax);
141
+ const quote = await this.request(endpoint(this.quoteUrl, {
142
+ network: this.deployment.network,
143
+ from: trade.tokenIn,
144
+ to: trade.tokenOut,
145
+ amount: trade.amountIn,
146
+ sender: trade.maker,
147
+ receiver: trade.recipient,
148
+ partnerAddress: trade.partnerAddress,
149
+ slippage: String(trade.slippageBps),
150
+ fee: "10",
151
+ feeOnOutput: String(feeOnOutput),
152
+ gasless: "true",
153
+ // Do not send fee=15: the preview reserves the capped payout itself.
154
+ // Do not restrict adapters: public operators need the same route universe.
155
+ }), {}, signal, 45_000);
156
+ if (quote.feeOnOutput !== feeOnOutput)
157
+ throw new GaslessError("INVALID_PREVIEW", "API changed the requested fee side.");
158
+ // Read gas again after routing: a long quote must not retain an old gas price.
159
+ const [current] = await Promise.all([
160
+ withGaslessDeadline(() => readGaslessChainState(this.provider, this.deployment), 15_000, signal),
161
+ this.checkQuoteBlock(quote, signal),
162
+ ]);
163
+ return assessGaslessQuote(quote, trade, this.deployment, current);
164
+ }
165
+ catch (error) {
166
+ if (signal?.aborted)
167
+ throw signal.reason;
168
+ const code = error instanceof GaslessError &&
169
+ ["CONFIGURATION_CHANGED", "TAX_CHECK_UNAVAILABLE"].includes(error.code)
170
+ ? error.code
171
+ : "QUOTE_UNAVAILABLE";
172
+ return {
173
+ eligible: false,
174
+ code,
175
+ reason: error instanceof Error
176
+ ? error.message
177
+ : "Gasless execution is unavailable. Use Regular.",
178
+ retryable: error instanceof GaslessError ? error.retryable : true,
179
+ };
180
+ }
181
+ }
182
+ /** A signing click can await a refresh and continue to the wallet in the same call. */
183
+ async prepare(trade, displayed, signal) {
184
+ const checkedAt = displayed?.quote?.gaslessExecution?.status === "ready"
185
+ ? displayed.quote.gaslessExecution.checkedAt
186
+ : 0;
187
+ if (displayed &&
188
+ Date.now() >= checkedAt &&
189
+ Date.now() - checkedAt <= 30_000) {
190
+ await this.getConfig(signal);
191
+ const [state] = await Promise.all([
192
+ withGaslessDeadline(() => readGaslessChainState(this.provider, this.deployment), 15_000, signal),
193
+ this.checkQuoteBlock(displayed.quote, signal),
194
+ ]);
195
+ const checked = assessGaslessQuote(displayed.quote, trade, this.deployment, state);
196
+ if (checked.eligible)
197
+ return checked.prepared;
198
+ }
199
+ const refreshed = await this.quote(trade, signal);
200
+ if (!refreshed.eligible)
201
+ throw new GaslessError(refreshed.code, refreshed.reason, refreshed.retryable);
202
+ return refreshed.prepared;
203
+ }
204
+ async checkSigner(signer, maker) {
205
+ if (!signer.provider ||
206
+ !sameAddress(await signer.getAddress(), maker) ||
207
+ (await signer.provider.getNetwork()).chainId !==
208
+ BigInt(this.deployment.chainId))
209
+ throw new GaslessError("WALLET_CHANGED", "Wallet account or network changed. Review the swap.");
210
+ }
211
+ async checkFunds(maker, tokenIn, amountIn, signal) {
212
+ const token = new Contract(gaslessAddress(tokenIn), ERC20_ABI, this.provider);
213
+ const [balance, allowance] = await withGaslessDeadline(() => Promise.all([
214
+ token.balanceOf(gaslessAddress(maker)),
215
+ token.allowance(maker, this.deployment.contract),
216
+ ]), 15_000, signal);
217
+ return {
218
+ balance: balance.toString(),
219
+ allowance: allowance.toString(),
220
+ hasBalance: balance >= gaslessUint(amountIn),
221
+ approved: allowance >= gaslessUint(amountIn),
222
+ spender: this.deployment.contract,
223
+ };
224
+ }
225
+ /** Build approval with a fresh API-compatible gas boost. User still sends/confirms it. */
226
+ async approvalRequest(tradeInput, signer, options = {}) {
227
+ const trade = normalizeGaslessTrade(tradeInput);
228
+ if (sameAddress(trade.tokenIn, NATIVE_PLS))
229
+ throw new GaslessError("NATIVE_INPUT_REQUIRES_WRAP", "Native input must be wrapped before approval.");
230
+ await this.checkSigner(signer, trade.maker);
231
+ await this.getConfig(options.signal);
232
+ const state = await withGaslessDeadline(() => readGaslessChainState(this.provider, this.deployment), 15_000, options.signal);
233
+ const boosted = gaslessCeil(gaslessUint(state.rawGasPriceWei) * 13000n, 10000n);
234
+ const quoted = options.quoteGasPriceWei
235
+ ? gaslessUint(options.quoteGasPriceWei)
236
+ : boosted;
237
+ const amount = options.resetToZero
238
+ ? 0n
239
+ : options.unlimited === false
240
+ ? gaslessUint(trade.amountIn)
241
+ : MaxUint256;
242
+ const request = {
243
+ chainId: this.deployment.chainId,
244
+ from: trade.maker,
245
+ to: trade.tokenIn,
246
+ value: 0n,
247
+ data: new Interface(ERC20_ABI).encodeFunctionData("approve", [
248
+ this.deployment.contract,
249
+ amount,
250
+ ]),
251
+ gasPrice: boosted > quoted ? boosted : quoted,
252
+ };
253
+ request.gasLimit = gaslessCeil((await withGaslessDeadline(() => this.provider.estimateGas(request), 15_000, options.signal)) * 13000n, 10000n);
254
+ return request;
255
+ }
256
+ async approve(trade, signer, options = {}) {
257
+ const request = await this.approvalRequest(trade, signer, options);
258
+ options.signal?.throwIfAborted();
259
+ await this.checkSigner(signer, trade.maker);
260
+ return signer.sendTransaction(request);
261
+ }
262
+ /** Off-chain signatures are not indexed until POST succeeds. */
263
+ async signAndSubmit(input) {
264
+ if (await input.store.load())
265
+ throw new GaslessError("ORDER_PENDING", "An existing gasless order can still execute. Reconcile it before another swap.");
266
+ await this.checkSigner(input.signer, input.trade.maker);
267
+ let prepared = await this.prepare(input.trade, input.displayed, input.signal);
268
+ let order;
269
+ for (let attempt = 0; attempt < 2; attempt++) {
270
+ const funds = await this.checkFunds(prepared.trade.maker, prepared.trade.tokenIn, prepared.trade.amountIn, input.signal);
271
+ if (!funds.hasBalance)
272
+ throw new GaslessError("INSUFFICIENT_BALANCE", "The input token balance is insufficient.");
273
+ if (!funds.approved)
274
+ throw new GaslessError("APPROVAL_REQUIRED", "Approve GaslessSwitch first. Approval requires native gas.");
275
+ try {
276
+ order = buildGaslessOrder(prepared);
277
+ break;
278
+ }
279
+ catch (error) {
280
+ if (!(error instanceof GaslessError) ||
281
+ error.code !== "STALE_QUOTE" ||
282
+ attempt === 1)
283
+ throw error;
284
+ prepared = await this.prepare(input.trade, undefined, input.signal);
285
+ }
286
+ }
287
+ if (!order)
288
+ throw new GaslessError("STALE_QUOTE", "Refresh the gasless quote.", true);
289
+ Object.freeze(order);
290
+ const contract = new Contract(this.deployment.contract, GASLESS_SWITCH_ABI, this.provider);
291
+ if (await withGaslessDeadline(() => contract.isNonceUsed(order.maker, order.nonce), 10_000, input.signal))
292
+ throw new GaslessError("NONCE_USED", "Generated nonce is already used; request another preparation.", true);
293
+ await input.onPrepared?.(prepared);
294
+ input.signal?.throwIfAborted();
295
+ await this.checkSigner(input.signer, order.maker);
296
+ const checked = assessGaslessQuote(prepared.quote, input.trade, this.deployment, prepared.chainState);
297
+ if (!checked.eligible)
298
+ throw new GaslessError(checked.code, checked.reason, checked.retryable);
299
+ let pending = {
300
+ network: this.deployment.network,
301
+ chainId: this.deployment.chainId,
302
+ contract: this.deployment.contract,
303
+ order,
304
+ state: "signing",
305
+ };
306
+ await input.store.reserve(pending);
307
+ let signature;
308
+ try {
309
+ input.onPending?.(pending);
310
+ const { domain, types } = getGaslessSigningParams(this.deployment);
311
+ signature = await input.signer.signTypedData(domain, types, order);
312
+ // Persist the signed payload before the request; never replace its nonce on retry.
313
+ pending = { ...pending, signature, state: "submitting" };
314
+ await input.store.update(pending);
315
+ if (!sameAddress(verifyTypedData(domain, types, order, signature), order.maker))
316
+ throw new GaslessError("INVALID_SIGNATURE", "Signature does not match the maker. Hosted submission currently requires an EOA signature.");
317
+ await this.checkSigner(input.signer, order.maker);
318
+ input.signal?.throwIfAborted();
319
+ await this.getConfig(input.signal);
320
+ if (JSON.stringify(normalizeGaslessTrade(input.trade)) !==
321
+ JSON.stringify(prepared.trade))
322
+ throw new GaslessError("TRADE_CHANGED", "Trade changed after signing. Keep the signed order locked until expiry.");
323
+ await this.checkSigner(input.signer, order.maker);
324
+ if (order.deadline <= Math.floor(Date.now() / 1000) + 30)
325
+ throw new GaslessError("ORDER_EXPIRING", "Order is too close to expiry to submit. Keep its lock until chain expiry.");
326
+ const record = await this.submitExact(pending, input.signal);
327
+ pending = { ...pending, state: "submitted" };
328
+ await input.store.update(pending);
329
+ input.onPending?.(pending);
330
+ return record;
331
+ }
332
+ catch (error) {
333
+ if (!signature)
334
+ await input.store.release(pending);
335
+ else {
336
+ pending = { ...pending, signature, state: "uncertain" };
337
+ await input.store.update(pending);
338
+ input.onPending?.(pending);
339
+ throw new GaslessSubmissionError(error instanceof Error
340
+ ? error.message
341
+ : "Submission is uncertain. Check this exact order before retrying.", pending);
342
+ }
343
+ throw error;
344
+ }
345
+ }
346
+ async submitExact(pending, signal) {
347
+ if (!pending.signature ||
348
+ pending.network !== this.deployment.network ||
349
+ pending.chainId !== this.deployment.chainId ||
350
+ !sameAddress(pending.contract, this.deployment.contract))
351
+ throw new GaslessError("INVALID_SUBMISSION", "Signed order does not target this gasless deployment.");
352
+ const payload = {
353
+ ...pending.order,
354
+ signature: pending.signature,
355
+ limitOrderContract: pending.contract,
356
+ };
357
+ try {
358
+ const result = await this.request(endpoint(this.ordersUrl, { network: pending.network }), {
359
+ method: "POST",
360
+ headers: { "Content-Type": "application/json" },
361
+ body: JSON.stringify(payload),
362
+ }, signal, 20_000);
363
+ if (result.success !== true ||
364
+ !result.order ||
365
+ !gaslessRecordMatches(pending, result.order))
366
+ throw new GaslessError("INVALID_RESPONSE", "API did not confirm this exact gasless order.");
367
+ return result.order;
368
+ }
369
+ catch (error) {
370
+ if (!signal?.aborted) {
371
+ // Hosted duplicates return an error, not an idempotent success response.
372
+ const existing = await this.getOrder(pending, signal).catch(() => null);
373
+ if (existing && gaslessRecordMatches(pending, existing))
374
+ return existing;
375
+ }
376
+ throw error;
377
+ }
378
+ }
379
+ /** Resend only the original signed payload after reconciling a transport/duplicate error. */
380
+ async retrySubmission(store, signal) {
381
+ const pending = await store.load();
382
+ if (!pending?.signature)
383
+ throw new GaslessError("NO_SIGNED_ORDER", "There is no saved signed order to retry.");
384
+ const existing = await this.getOrder(pending, signal);
385
+ if (existing) {
386
+ await store.update({ ...pending, state: "submitted" });
387
+ return existing;
388
+ }
389
+ await this.getConfig(signal);
390
+ if (pending.order.deadline <= Math.floor(Date.now() / 1000) + 30)
391
+ throw new GaslessError("ORDER_EXPIRING", "Wait for chain expiry instead of resubmitting an expiring order.");
392
+ const record = await this.submitExact(pending, signal);
393
+ await store.update({ ...pending, state: "submitted" });
394
+ return record;
395
+ }
396
+ async getOrder(pending, signal) {
397
+ if (pending.network !== this.deployment.network ||
398
+ pending.chainId !== this.deployment.chainId)
399
+ throw new GaslessError("WRONG_CHAIN", "Pending order belongs to another network.");
400
+ try {
401
+ const record = await this.request(endpoint(`${this.ordersUrl}/${gaslessAddress(pending.order.maker)}/${pending.order.nonce}`, { network: pending.network }), {}, signal, 10_000);
402
+ if (!gaslessRecordMatches(pending, record))
403
+ throw new GaslessError("ORDER_IDENTITY_MISMATCH", "The API record does not match the saved signed order.");
404
+ return record;
405
+ }
406
+ catch (error) {
407
+ if (error instanceof GaslessError &&
408
+ error.code === "API_ERROR" &&
409
+ error.message === "Order not found")
410
+ return null;
411
+ throw error;
412
+ }
413
+ }
414
+ /** Poll at most once per 5 seconds. An API outage alone cannot release the pending lock. */
415
+ async reconcile(store, signal) {
416
+ const pending = await store.load();
417
+ if (!pending)
418
+ return null;
419
+ let record = null;
420
+ let readError;
421
+ try {
422
+ record = await this.getOrder(pending, signal);
423
+ }
424
+ catch (error) {
425
+ if (signal?.aborted ||
426
+ (error instanceof GaslessError &&
427
+ ["ORDER_IDENTITY_MISMATCH", "WRONG_CHAIN"].includes(error.code)))
428
+ throw error;
429
+ readError = error;
430
+ }
431
+ if (record?.status === "FILLED") {
432
+ await store.release(pending);
433
+ return {
434
+ status: "filled",
435
+ pending,
436
+ record,
437
+ settlementTxUrl: typeof record.filledTxHash === "string" &&
438
+ /^0x[\da-f]{64}$/i.test(record.filledTxHash)
439
+ ? `${this.deployment.explorer}/tx/${record.filledTxHash}`
440
+ : undefined,
441
+ };
442
+ }
443
+ if (record?.status === "CANCELLED") {
444
+ await store.release(pending);
445
+ return { status: "cancelled", pending, record };
446
+ }
447
+ // API EXPIRED or the local clock alone cannot unlock a still-executable signature.
448
+ const [network, block] = await withGaslessDeadline(() => Promise.all([
449
+ this.provider.getNetwork(),
450
+ this.provider.getBlock("latest"),
451
+ ]), 10_000, signal);
452
+ if (network.chainId !== BigInt(pending.chainId))
453
+ throw new GaslessError("WRONG_CHAIN", "RPC is on another network.");
454
+ if (block && block.timestamp > pending.order.deadline) {
455
+ await store.release(pending);
456
+ return {
457
+ status: "closed",
458
+ pending,
459
+ reason: "The chain has passed the signed deadline. Check order history for the final settlement result.",
460
+ };
461
+ }
462
+ if (readError)
463
+ throw readError;
464
+ return { status: "pending", pending };
465
+ }
466
+ }
467
+ //# sourceMappingURL=gasless-client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"gasless-client.js","sourceRoot":"","sources":["../src/gasless-client.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EACR,SAAS,EACT,UAAU,EACV,eAAe,GAKhB,MAAM,QAAQ,CAAC;AAChB,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAGjE,OAAO,EACL,mBAAmB,EACnB,kBAAkB,EAClB,YAAY,EACZ,kBAAkB,EAClB,iBAAiB,EACjB,cAAc,EACd,WAAW,EACX,WAAW,EACX,uBAAuB,EACvB,qBAAqB,EACrB,qBAAqB,EACrB,WAAW,EACX,wBAAwB,EACxB,qBAAqB,EACrB,sBAAsB,GACvB,MAAM,cAAc,CAAC;AA6BtB,SAAS,QAAQ,CAAC,GAAW,EAAE,KAA6B;IAC1D,MAAM,MAAM,GAAG,IAAI,eAAe,CAAC,KAAK,CAAC,CAAC,QAAQ,EAAE,CAAC;IACrD,OAAO,GAAG,GAAG,GAAG,GAAG,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,GAAG,MAAM,EAAE,CAAC;AAC3D,CAAC;AAED,0FAA0F;AAC1F,MAAM,CAAC,KAAK,UAAU,mBAAmB,CACvC,IAAsB,EACtB,SAAiB,EACjB,MAAoB;IAEpB,MAAM,EAAE,cAAc,EAAE,CAAC;IACzB,IAAI,KAAoC,CAAC;IACzC,IAAI,OAAmB,CAAC;IACxB,MAAM,OAAO,GAAG,IAAI,OAAO,CAAQ,CAAC,CAAC,EAAE,MAAM,EAAE,EA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O,CAAC;YAC7C,MAAM,IAAI,YAAY,CAAC,aAAa,EAAE,4BAA4B,CAAC,CAAC;QACtE,IAAI,KAAK,IAAI,KAAK,CAAC,SAAS,GAAG,OAAO,CAAC,KAAK,CAAC,QAAQ,EAAE,CAAC;YACtD,MAAM,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;YAC7B,OAAO;gBACL,MAAM,EAAE,QAAQ;gBAChB,OAAO;gBACP,MAAM,EACJ,gGAAgG;aACnG,CAAC;QACJ,CAAC;QACD,IAAI,SAAS;YAAE,MAAM,SAAS,CAAC;QAC/B,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,OAAO,EAAE,CAAC;IACxC,CAAC;CACF"}
@@ -0,0 +1,5 @@
1
+ export * from "./gasless.js";
2
+ export * from "./gasless-client.js";
3
+ export * from "./gasless-store.js";
4
+ export * from "./gasless-operators.js";
5
+ //# sourceMappingURL=gasless-index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"gasless-index.d.ts","sourceRoot":"","sources":["../src/gasless-index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,qBAAqB,CAAC;AACpC,cAAc,oBAAoB,CAAC;AACnC,cAAc,wBAAwB,CAAC"}
@@ -0,0 +1,5 @@
1
+ export * from "./gasless.js";
2
+ export * from "./gasless-client.js";
3
+ export * from "./gasless-store.js";
4
+ export * from "./gasless-operators.js";
5
+ //# sourceMappingURL=gasless-index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"gasless-index.js","sourceRoot":"","sources":["../src/gasless-index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,qBAAqB,CAAC;AACpC,cAAc,oBAAoB,CAAC;AACnC,cAAc,wBAAwB,CAAC"}
@@ -0,0 +1,32 @@
1
+ import { type Provider } from "ethers";
2
+ import type { LimitOrderConfigResponse, LimitOrderRecord } from "./types.js";
3
+ import type { GaslessDeployment, GaslessOrder, GaslessRoute } from "./gasless-types.js";
4
+ /** Never infer gasless from a symbol, short deadline, orderType label, or legacy array. */
5
+ export declare function classifySwitchOrder(order: Pick<LimitOrderRecord, "limitOrderContract">, config: LimitOrderConfigResponse, deployment: GaslessDeployment): "gasless" | "limit-order" | "unsupported";
6
+ export declare function selectGaslessPriorityOrders(orders: readonly LimitOrderRecord[], config: LimitOrderConfigResponse, deployment: GaslessDeployment, chainTimestamp: number): LimitOrderRecord[];
7
+ /** Gasless V2 fixes the excess side from the maker's signed fee mode. */
8
+ export declare function gaslessExcessOnInput(feeOnOutput: boolean): boolean;
9
+ /** Nominal cap before payout transfer tax. Gas is part of this payout, never an add-on. */
10
+ export declare function cappedGaslessPayout(availableSurplus: bigint, afterFeeBase: bigint): bigint;
11
+ /** Use measured after-tax payout valued via an executable payout-token/native route. */
12
+ export declare function assessGaslessOperatorProfit(payoutNative: bigint, gasLimit: bigint, gasPrice: bigint, minimumNetNative?: bigint): {
13
+ eligible: boolean;
14
+ gasBudgetNative: bigint;
15
+ netNative: bigint;
16
+ };
17
+ export declare function assertGaslessOperator(provider: Provider, deployment: GaslessDeployment, operator: string): Promise<void>;
18
+ /** Encode already-built execution routes. This does NOT quote, simulate, or establish profitability. */
19
+ export declare function encodeGaslessFill(input: {
20
+ deployment: GaslessDeployment;
21
+ order: GaslessOrder;
22
+ signature: string;
23
+ routes: readonly GaslessRoute[];
24
+ /** Actual maker -> settlement balance delta, required for an input-fee fill. */
25
+ receivedInput?: string;
26
+ chainTimestamp: number;
27
+ }): {
28
+ to: string;
29
+ data: string;
30
+ value: string;
31
+ };
32
+ //# sourceMappingURL=gasless-operators.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"gasless-operators.d.ts","sourceRoot":"","sources":["../src/gasless-operators.ts"],"names":[],"mappings":"AAAA,OAAO,EAAwC,KAAK,QAAQ,EAAE,MAAM,QAAQ,CAAC;AAC7E,OAAO,KAAK,EAAE,wBAAwB,EAAE,gBAAgB,EAAE,MAAM,YAAY,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