@anywalletkit/protocol-swap2-omniston 0.5.3 → 0.5.5

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 (41) hide show
  1. package/README.md +72 -4
  2. package/dist/activity.cjs +4 -1
  3. package/dist/activity.cjs.map +1 -1
  4. package/dist/activity.d.cts +7 -1
  5. package/dist/activity.d.ts +7 -1
  6. package/dist/activity.js +1 -1
  7. package/dist/{chunk-AIWAM7BS.js → chunk-ENAEOF7N.js} +5 -2
  8. package/dist/chunk-ENAEOF7N.js.map +1 -0
  9. package/dist/{chunk-4JOTKQOT.js → chunk-FDSTD34Z.js} +10 -3
  10. package/dist/{chunk-4JOTKQOT.js.map → chunk-FDSTD34Z.js.map} +1 -1
  11. package/dist/chunk-IDRZHWWL.js +74 -0
  12. package/dist/chunk-IDRZHWWL.js.map +1 -0
  13. package/dist/{chunk-2E6CVWD6.js → chunk-IX4NF2J7.js} +2 -2
  14. package/dist/index.cjs +49 -2
  15. package/dist/index.cjs.map +1 -1
  16. package/dist/index.d.cts +1 -1
  17. package/dist/index.d.ts +1 -1
  18. package/dist/index.js +4 -4
  19. package/dist/protocol.cjs +11 -1
  20. package/dist/protocol.cjs.map +1 -1
  21. package/dist/protocol.d.cts +1 -1
  22. package/dist/protocol.d.ts +1 -1
  23. package/dist/protocol.js +4 -4
  24. package/dist/{provider-CcCZB-Cj.d.cts → provider-BQzNkVvW.d.cts} +18 -2
  25. package/dist/{provider-CcCZB-Cj.d.ts → provider-BQzNkVvW.d.ts} +18 -2
  26. package/dist/provider.cjs +49 -2
  27. package/dist/provider.cjs.map +1 -1
  28. package/dist/provider.d.cts +1 -1
  29. package/dist/provider.d.ts +1 -1
  30. package/dist/provider.js +3 -3
  31. package/dist/validators.cjs +125 -12
  32. package/dist/validators.cjs.map +1 -1
  33. package/dist/validators.d.cts +41 -4
  34. package/dist/validators.d.ts +41 -4
  35. package/dist/validators.js +88 -12
  36. package/dist/validators.js.map +1 -1
  37. package/package.json +6 -6
  38. package/dist/chunk-AIWAM7BS.js.map +0 -1
  39. package/dist/chunk-JWYDIW4V.js +0 -37
  40. package/dist/chunk-JWYDIW4V.js.map +0 -1
  41. /package/dist/{chunk-2E6CVWD6.js.map → chunk-IX4NF2J7.js.map} +0 -0
@@ -1,2 +1,2 @@
1
- export { A as AssetId, C as ChainAddress, E as EscrowMessage, H as HtlcSecretStore, O as ObservableLike, a as OmnistonClientLike, b as OmnistonProviderOptions, c as OmnistonQuote, d as OmnistonQuoteStore, e as OrderEvent, f as OrderExecution, g as OrderSettlement, h as OrderSnapshot, Q as QuoteRequest, R as RfqEvent, S as SwapSettlement, i as SwapTrackEvent, T as TON_SWAP_PROTOCOL_LAYOUTS, j as TonSwapCheckInput, k as TonSwapCheckResult, l as TonSwapLeg, m as TonSwapPayloadError, n as checkTonSwapPayload, o as encodeTypedMessage, p as inMemoryQuoteStore, q as inMemorySecretStore, r as omnistonPins, s as omnistonProvider, t as omnistonVerifyBuild, v as validateEvmToTonOrderExtension, u as validateEvmTypedOrder } from './provider-CcCZB-Cj.cjs';
1
+ export { A as AssetId, C as ChainAddress, E as EscrowMessage, H as HtlcSecretStore, O as ObservableLike, a as OmnistonClientLike, b as OmnistonProviderOptions, c as OmnistonQuote, d as OmnistonQuoteStore, e as OrderEvent, f as OrderExecution, g as OrderSettlement, h as OrderSnapshot, Q as QuoteRequest, R as RfqEvent, S as SwapSettlement, i as SwapTrackEvent, T as TON_SWAP_PROTOCOL_LAYOUTS, j as TonSwapCheckInput, k as TonSwapCheckResult, l as TonSwapLeg, m as TonSwapPayloadError, n as checkTonSwapPayload, o as encodeTypedMessage, p as inMemoryQuoteStore, q as inMemorySecretStore, r as omnistonPins, s as omnistonProvider, t as omnistonVerifyBuild, v as validateEvmToTonOrderExtension, u as validateEvmTypedOrder } from './provider-BQzNkVvW.cjs';
2
2
  import '@anywalletkit/protocol-swap2-core/types';
@@ -1,2 +1,2 @@
1
- export { A as AssetId, C as ChainAddress, E as EscrowMessage, H as HtlcSecretStore, O as ObservableLike, a as OmnistonClientLike, b as OmnistonProviderOptions, c as OmnistonQuote, d as OmnistonQuoteStore, e as OrderEvent, f as OrderExecution, g as OrderSettlement, h as OrderSnapshot, Q as QuoteRequest, R as RfqEvent, S as SwapSettlement, i as SwapTrackEvent, T as TON_SWAP_PROTOCOL_LAYOUTS, j as TonSwapCheckInput, k as TonSwapCheckResult, l as TonSwapLeg, m as TonSwapPayloadError, n as checkTonSwapPayload, o as encodeTypedMessage, p as inMemoryQuoteStore, q as inMemorySecretStore, r as omnistonPins, s as omnistonProvider, t as omnistonVerifyBuild, v as validateEvmToTonOrderExtension, u as validateEvmTypedOrder } from './provider-CcCZB-Cj.js';
1
+ export { A as AssetId, C as ChainAddress, E as EscrowMessage, H as HtlcSecretStore, O as ObservableLike, a as OmnistonClientLike, b as OmnistonProviderOptions, c as OmnistonQuote, d as OmnistonQuoteStore, e as OrderEvent, f as OrderExecution, g as OrderSettlement, h as OrderSnapshot, Q as QuoteRequest, R as RfqEvent, S as SwapSettlement, i as SwapTrackEvent, T as TON_SWAP_PROTOCOL_LAYOUTS, j as TonSwapCheckInput, k as TonSwapCheckResult, l as TonSwapLeg, m as TonSwapPayloadError, n as checkTonSwapPayload, o as encodeTypedMessage, p as inMemoryQuoteStore, q as inMemorySecretStore, r as omnistonPins, s as omnistonProvider, t as omnistonVerifyBuild, v as validateEvmToTonOrderExtension, u as validateEvmTypedOrder } from './provider-BQzNkVvW.js';
2
2
  import '@anywalletkit/protocol-swap2-core/types';
package/dist/provider.js CHANGED
@@ -10,10 +10,10 @@ import {
10
10
  omnistonVerifyBuild,
11
11
  validateEvmToTonOrderExtension,
12
12
  validateEvmTypedOrder
13
- } from "./chunk-4JOTKQOT.js";
13
+ } from "./chunk-FDSTD34Z.js";
14
14
  import "./chunk-QDXFC6BC.js";
15
- import "./chunk-AIWAM7BS.js";
16
- import "./chunk-JWYDIW4V.js";
15
+ import "./chunk-ENAEOF7N.js";
16
+ import "./chunk-IDRZHWWL.js";
17
17
  export {
18
18
  TON_SWAP_PROTOCOL_LAYOUTS,
19
19
  TonSwapPayloadError,
@@ -34,7 +34,10 @@ __export(validators_exports, {
34
34
  createOmnistonEvmOutputValidator: () => createOmnistonEvmOutputValidator,
35
35
  createOmnistonTonDeliveryLocator: () => createOmnistonTonDeliveryLocator,
36
36
  createOmnistonTonValidators: () => createOmnistonTonValidators,
37
- omnistonEvmRpcRequest: () => omnistonEvmRpcRequest
37
+ omnistonEvmRpcRequest: () => omnistonEvmRpcRequest,
38
+ omnistonQuorumValidator: () => omnistonQuorumValidator,
39
+ omnistonRpcOperator: () => omnistonRpcOperator,
40
+ omnistonRpcOperatorGroups: () => omnistonRpcOperatorGroups
38
41
  });
39
42
  module.exports = __toCommonJS(validators_exports);
40
43
 
@@ -179,6 +182,9 @@ function decodeFeeParameters(parameters) {
179
182
  async function omnistonEvmRpcRequest(chain, method, params, rpcUrls) {
180
183
  const urls = [...rpcUrls?.[chain] ?? [], ...DEFAULT_RPC_URLS[chain] ?? []].filter((url) => !!url);
181
184
  if (!urls.length) throw new Error(`omniston: no RPC configured for ${chain}`);
185
+ return await rpcOver(urls, chain, method, params);
186
+ }
187
+ async function rpcOver(urls, chain, method, params) {
182
188
  let lastError;
183
189
  for (const url of urls) {
184
190
  try {
@@ -198,6 +204,62 @@ async function omnistonEvmRpcRequest(chain, method, params, rpcUrls) {
198
204
  }
199
205
  throw lastError instanceof Error ? lastError : new Error(`omniston: RPC failed for ${chain}`);
200
206
  }
207
+ function omnistonRpcOperator(url) {
208
+ const host = new URL(url).hostname.toLowerCase().replace(/\.$/, "");
209
+ if (/^[\d.]+$/.test(host) || host.includes(":") || host.startsWith("[")) return host;
210
+ return host.split(".").slice(-2).join(".");
211
+ }
212
+ function omnistonRpcOperatorGroups(chain, rpcUrls, operatorOf = omnistonRpcOperator) {
213
+ const groups = [];
214
+ const seen = /* @__PURE__ */ new Set();
215
+ for (const url of [...rpcUrls?.[chain] ?? [], ...DEFAULT_RPC_URLS[chain] ?? []]) {
216
+ if (!url || seen.has(url)) continue;
217
+ seen.add(url);
218
+ let operator;
219
+ try {
220
+ operator = operatorOf(url);
221
+ } catch {
222
+ continue;
223
+ }
224
+ const group = groups.find((g) => g.operator === operator);
225
+ if (group) group.urls.push(url);
226
+ else groups.push({ operator, urls: [url] });
227
+ }
228
+ return groups;
229
+ }
230
+ function pinnedStateRequest(request) {
231
+ let pinned = null;
232
+ return async (chain, method, params) => {
233
+ if (method === "eth_blockNumber") {
234
+ const head = await request(chain, method, params);
235
+ const latest = BigInt(head);
236
+ const confirmations = OMNISTON_EVM_MIN_CONFIRMATIONS[chain] ?? 20n;
237
+ pinned = quantity(latest >= confirmations ? latest - confirmations : 0n);
238
+ return head;
239
+ }
240
+ if (pinned && (method === "eth_call" || method === "eth_getCode" || method === "eth_getBalance") && params.at(-1) === "latest") {
241
+ return await request(chain, method, [...params.slice(0, -1), pinned]);
242
+ }
243
+ return await request(chain, method, params);
244
+ };
245
+ }
246
+ function omnistonQuorumValidator(options, refuse, once) {
247
+ const quorum = options.quorum ?? 1;
248
+ if (!Number.isSafeInteger(quorum) || quorum < 1) throw new Error("omniston: quorum must be a positive integer");
249
+ if (quorum === 1) {
250
+ const request = options.request ?? ((chain, method, params) => omnistonEvmRpcRequest(chain, method, params, options.rpcUrls));
251
+ return (input) => once(request, input, refuse);
252
+ }
253
+ if (options.request) throw new Error("omniston: an RPC quorum needs rpcUrls (one request per operator), not a single request");
254
+ return async (input) => {
255
+ const groups = omnistonRpcOperatorGroups(input.chain, options.rpcUrls, options.operatorOf);
256
+ const operators = groups.map((g) => g.operator);
257
+ if (groups.length < quorum) return refuse("rpc-quorum-unavailable", { chain: input.chain, operators, quorum });
258
+ const results = await Promise.all(groups.map((g) => once(pinnedStateRequest((chain, method, params) => rpcOver(g.urls, chain, method, params)), input, (reason, details) => refuse(reason, { ...details, operator: g.operator })).catch(() => false)));
259
+ const agreed = operators.filter((_, i) => results[i]);
260
+ return agreed.length >= quorum || refuse("rpc-quorum-not-met", { chain: input.chain, agreed, operators, quorum });
261
+ };
262
+ }
201
263
  async function ethCall(request, chain, to, data) {
202
264
  return await request(chain, "eth_call", [{ to, data }, "latest"]);
203
265
  }
@@ -231,16 +293,15 @@ function locateImmutables(input, secretHash) {
231
293
  }
232
294
  }
233
295
  function createOmnistonEvmOutputValidator(options = {}) {
234
- const refuse = (reason, details) => {
296
+ const report = (reason, details) => {
235
297
  try {
236
298
  options.onRefusal?.(reason, details);
237
299
  } catch {
238
300
  }
239
301
  return false;
240
302
  };
241
- const request = options.request ?? ((chain, method, params) => omnistonEvmRpcRequest(chain, method, params, options.rpcUrls));
242
303
  const now = options.now ?? Date.now;
243
- return async (input) => {
304
+ return omnistonQuorumValidator(options, report, async (request, input, refuse) => {
244
305
  try {
245
306
  if (!OMNISTON_EVM_LOOKBACK_BLOCKS[input.chain] || input.executionIndex !== 0 || !(0, import_viem.isAddress)(input.positionAddress) || !(0, import_viem.isAddress)(input.factoryAddress) || !(0, import_viem.isAddress)(input.recipientAddress) || !(0, import_viem.isAddress)(input.outputTokenAddress) || !Number.isInteger(input.quoteTimestamp) || input.quoteTimestamp * 1e3 > now() + 12e4 || now() - input.quoteTimestamp * 1e3 > 6 * 60 * 60 * 1e3) return refuse("input-shape");
246
307
  const position = (0, import_viem.getAddress)(input.positionAddress);
@@ -337,7 +398,7 @@ function createOmnistonEvmOutputValidator(options = {}) {
337
398
  } catch (error) {
338
399
  return refuse("error", { message: error instanceof Error ? error.message : String(error) });
339
400
  }
340
- };
401
+ });
341
402
  }
342
403
  var TRANSFER_TOPIC = (0, import_viem.keccak256)((0, import_viem.stringToHex)("Transfer(address,address,uint256)"));
343
404
  var topicAddress = (address) => `0x${(0, import_viem.getAddress)(address).slice(2).toLowerCase().padStart(64, "0")}`;
@@ -440,16 +501,15 @@ async function ethCall2(request, chain, to, data) {
440
501
  return await request(chain, "eth_call", [{ to, data }, "latest"]);
441
502
  }
442
503
  function createOmnistonEvmInputValidator(options = {}) {
443
- const refuse = (reason, details) => {
504
+ const report = (reason, details) => {
444
505
  try {
445
506
  options.onRefusal?.(reason, details);
446
507
  } catch {
447
508
  }
448
509
  return false;
449
510
  };
450
- const request = options.request ?? ((chain, method, params) => omnistonEvmRpcRequest(chain, method, params, options.rpcUrls));
451
511
  const now = options.now ?? Date.now;
452
- return async (input) => {
512
+ return omnistonQuorumValidator(options, report, async (request, input, refuse) => {
453
513
  try {
454
514
  if (!OMNISTON_EVM_LOOKBACK_BLOCKS[input.chain] || !(0, import_viem2.isAddress)(input.positionAddress) || !(0, import_viem2.isAddress)(input.factoryAddress) || !(0, import_viem2.isAddress)(input.orderProtocolAddress) || !(0, import_viem2.isAddress)(input.ownerAddress) || !(0, import_viem2.isAddress)(input.resolverAddress) || !(0, import_viem2.isAddress)(input.inputTokenAddress) || !Number.isInteger(input.quoteTimestamp) || input.quoteTimestamp * 1e3 > now() + 12e4 || now() - input.quoteTimestamp * 1e3 > 6 * 60 * 60 * 1e3 || input.secretHash.length !== 32) return refuse("input-shape");
455
515
  const position = (0, import_viem2.getAddress)(input.positionAddress);
@@ -524,7 +584,7 @@ function createOmnistonEvmInputValidator(options = {}) {
524
584
  } catch (error) {
525
585
  return refuse("error", { message: error instanceof Error ? error.message : String(error) });
526
586
  }
527
- };
587
+ });
528
588
  }
529
589
 
530
590
  // src/validators/ton.ts
@@ -534,7 +594,44 @@ var import_core3 = require("@anywalletkit/core");
534
594
 
535
595
  // src/validators/settlement.ts
536
596
  var AUDITED_OMNISTON_SETTLEMENT_CONTRACTS = {
537
- "ton:-239": ["EQAbWJ3Y1HgIIvcMq1prG1anlDC0T3cZlAU7luPT6LmTpmrZ"],
597
+ // The TON Escrow Minter a new TON <-> EVM order may name. The provider
598
+ // compares TON addresses as these exact strings, so it is kept in the form
599
+ // Omniston's quotes use.
600
+ // - EQDybO88… (code 9737943f…, "rev2"): Omniston's TON <-> EVM quotes name it
601
+ // since 2026-11-10 ~19:00Z. Reviewed 2026-11-12, read-only:
602
+ // - Deploy tx fkabfHcN8DcrqQyazmlB+UprljBDeEkvFlgaVOi905g=
603
+ // (2026-11-10 18:47:06Z). Code and data still equal that StateInit:
604
+ // no upgrade since, none pending (no pendingCode, upgradeAfter 0).
605
+ // - Same admin (0:408fff62…) as rev1; it is also the admin_address of the
606
+ // STON.fi DEX v2 routers api.ston.fi lists. Deployed from the same
607
+ // wallet as rev1 (a weak signal on TON: anyone can send a StateInit).
608
+ // - The bytecode diff to rev1: escrow / execution code must be in an
609
+ // embedded whitelist (9e77…, f6ed…, d304…, pinned in ton.ts, plus 9fe4…
610
+ // for TON <-> TON, which the SDK does not pin), the escrow sub-VM must
611
+ // return one value, and a failed position deploy now credits the amount
612
+ // back to the same account contract instead of aborting (the only new
613
+ // path that moves value; no real message has used it). Fees, timelocks,
614
+ // payouts, admin and the 7-day upgrade delay are unchanged. Replayed
615
+ // through both codes, the real traffic of both minters (~42k
616
+ // transactions) and of ~1,070 of their positions gave the same outputs.
617
+ // - It deploys positions with code eb503578…, the only code in
618
+ // DEFAULT_OMNISTON_TON_CODE_HASHES.position. The address and that pin
619
+ // go together: without the pin every EVM -> TON order on this minter
620
+ // fills and then fails the disclosure check.
621
+ // - EQAbWJ3Y… (code f91c43d3…, "rev1", deployed 2026-06-09) is no longer
622
+ // trusted by default (2026-11-12). Omniston's quotes moved to rev2 on
623
+ // 2026-11-10 (rev1 still took a few orders on 2026-11-12), and rev1 lacks the escrow-code whitelist rev2 added: on
624
+ // rev1 only the SDK's own pins check the escrow and execution code an
625
+ // order carries. A quote that names rev1 is refused with its address
626
+ // in the reason, and so is building one cached under an older table; its positions (code e4d5115a…) fail
627
+ // position-code-hash. It stays in OMNISTON_ESCROWS (activity.ts), which
628
+ // recognizes history and grants no trust. Old orders need nothing from
629
+ // this table: trackIntent reads no trust table, and every disclosure
630
+ // check refuses a quote older than 6 h, so a rev1 order quoted before
631
+ // the switch cannot be closed by any version. Listing rev1 here or in
632
+ // trustedProtocolAddresses trusts it again for NEW orders; it does not
633
+ // help close an old one.
634
+ "ton:-239": ["EQDybO88l2lrrAmALRUqpmgEE_tuxk510F4Yd4xjbQZxC9IA"],
538
635
  "eip155:1": ["0xafCF681272AF10959736f45616eeCBC22D7095E2"],
539
636
  "eip155:56": ["0xafCF681272AF10959736f45616eeCBC22D7095E2"],
540
637
  "eip155:137": ["0x41A392062A4307a6961d48e30FF20bF6823715B8"],
@@ -576,8 +673,24 @@ var DEFAULT_OMNISTON_TON_CODE_HASHES = {
576
673
  authorityKeys: ["ed210da12aa96ea42de4f2f61dc172bbaa3da86051a1b2a6f342f69a777d2770"],
577
674
  /** EVM→TON output position: the contract the factory deploys for the
578
675
  * resolver's jetton lock (observed on every resolver-created position,
579
- * 2026-10-15/16), and the escrow code cell it carries in its state. */
580
- position: ["e4d5115a321ade7b827e38fb522c20d2f2cd46e4c6b0b5f7dd8b6b096792d77b"],
676
+ * 2026-10-15/16), and the escrow code cell it carries in its state.
677
+ * A position counts only when a trusted factory itself sent its deploy
678
+ * message, and a minter deploys only the position code stored in its own
679
+ * data, so this list follows the trusted minters in
680
+ * AUDITED_OMNISTON_SETTLEMENT_CONTRACTS["ton:-239"]:
681
+ * - eb503578…: positions of the rev2 Escrow Minter EQDybO88… (the position
682
+ * code stored in its data; reviewed 2026-11-12). The diff to rev1's
683
+ * e4d5115a… is 13 sub-VM calls in another mode (RUNVMX 20 -> 276) and 2
684
+ * escrow-code whitelist checks. The state layout is the same, and live
685
+ * and settled rev2 positions pass every check of
686
+ * validateTonOutputPosition.
687
+ * - e4d5115a… (positions of the rev1 minter EQAbWJ3Y…) left the default
688
+ * with rev1 on 2026-11-12. Only an EVM -> TON order quoted on rev1 less
689
+ * than 6 h before an app upgrades can still need it (positionCodeHashes
690
+ * with both codes, until those 6 h are over). That pin alone trusts no
691
+ * new order: a new quote must name a trusted minter, and a position
692
+ * counts only when the minter its quote named deployed it. */
693
+ position: ["eb503578b4d9cd791c9c0ecd0da6da4064aae2bcb19d3c924d4001c493386bc5"],
581
694
  outputEscrow: ["d30423575384773abaad8d3c6f763898afa3d57a5693005904b7c61e95cee630"]
582
695
  };
583
696
  var POSITION_DEPLOY_OP = "0xf240cd30";