@anywalletkit/protocol-swap2-omniston 0.2.8 → 0.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.
@@ -1,4 +1,4 @@
1
- import { OmnistonProviderOptions } from './provider.cjs';
1
+ export { D as DEFAULT_OMNISTON_TON_CODE_HASHES, w as DEFAULT_OMNISTON_TON_PROXY_TON_MASTERS, x as DEFAULT_OMNISTON_TON_SWAP_INTERFACES, M as MAX_OMNISTON_EXCLUSIVITY_SECONDS, y as OmnistonTonDeliveryInput, z as OmnistonTonDeliveryLocatorOptions, B as OmnistonTonValidationOptions, F as TonEscrowBuildExpectation, G as TonOutputPositionInput, I as createOmnistonTonDeliveryLocator, J as createOmnistonTonValidators } from './provider-BBG2zhpu.cjs';
2
2
  import '@anywalletkit/protocol-swap2-core/types';
3
3
 
4
4
  /** How far back (blocks) a factory event is searched, per chain — shared with the EVM input validator. */
@@ -86,97 +86,6 @@ declare function createOmnistonEvmInputValidator(options?: {
86
86
  onRefusal?: OmnistonValidatorRefusal;
87
87
  }): (input: EvmInputValidationInput) => Promise<boolean>;
88
88
 
89
- /** Audited from the active mainnet Escrow builder on 2026-08-13. These are
90
- * immutable TVM code cells, not resolver-controlled addresses. A contract
91
- * upgrade must deliberately update these hashes after reviewing its schema.
92
- *
93
- * `authorityKeys` is the optional 256-bit public key in the escrow config: the
94
- * escrow code checks `CHKSIGNU` against it for its signature-gated operations
95
- * (disassembly of code 9e77cb9e…, 2026-10-11). It has been the same key since
96
- * the August audit, so it stays pinned. */
97
- declare const DEFAULT_OMNISTON_TON_CODE_HASHES: {
98
- readonly escrow: readonly ["9e77cb9e8fd7406d4e85e5f57378eb51e51b862424cf988306c783d50ade697a"];
99
- readonly execution: readonly ["f6edbc76e6fbcd6bac573cb942401a3d9198ee9605f9403b0f5c8081259210e5"];
100
- readonly authorityKeys: readonly ["ed210da12aa96ea42de4f2f61dc172bbaa3da86051a1b2a6f342f69a777d2770"];
101
- /** EVM→TON output position: the contract the factory deploys for the
102
- * resolver's jetton lock (observed on every resolver-created position,
103
- * 2026-10-15/16), and the escrow code cell it carries in its state. */
104
- readonly position: readonly ["e4d5115a321ade7b827e38fb522c20d2f2cd46e4c6b0b5f7dd8b6b096792d77b"];
105
- readonly outputEscrow: readonly ["d30423575384773abaad8d3c6f763898afa3d57a5693005904b7c61e95cee630"];
106
- };
107
- /** Upper bound on the exclusivity window the escrow config may carry. It is
108
- * how long the trader's input stays locked when no resolver reserves the
109
- * position (SDK: "at the end of this period trader's position becomes
110
- * available for manual withdrawal"); the live value is 300 s. */
111
- declare const MAX_OMNISTON_EXCLUSIVITY_SECONDS = 3600;
112
- type PayloadInput = Omit<Parameters<NonNullable<OmnistonProviderOptions["validateTonEscrowPayload"]>>[0], "exclusivityTimeout"> & {
113
- exclusivityTimeout?: number;
114
- };
115
- /** Code interfaces (tonapi's by-code-hash labels) a same-chain swap message
116
- * may pay into. The resolver picks the pool/vault per route, so the check is
117
- * "a STON.fi or DeDust contract by code", not a fixed address list — seen
118
- * live: native GRAM → DeDust CPMM v2 pool, jettons → STON.fi router v2. */
119
- declare const DEFAULT_OMNISTON_TON_SWAP_INTERFACES: readonly ["stonfi_router", "stonfi_router_v2", "stonfi_pool", "stonfi_pool_v2", "dedust_vault", "dedust_v2_cpmm", "dedust_pool"];
120
- /** Proxy-TON (pTON) jetton masters STON.fi routes native TON through. A
121
- * native-input swap pays the ROUTER'S pTON wallet — a plain `jetton_wallet`
122
- * to tonapi, no DEX code interface — so such a target is accepted only when
123
- * its jetton master is pTON AND its owner carries a DEX router interface.
124
- * Seen live 2026-09-05: GRAM → USDT on StonFiV2 targeted the router's pTON
125
- * v2 wallet and the code-interface check alone refused it. */
126
- declare const DEFAULT_OMNISTON_TON_PROXY_TON_MASTERS: readonly ["EQCM3B12QK1e4yZSf8GtBRT0aLMNyEsBc_DhVfRRtOEffLez", "EQBnGWMCf3-FZZq1W4IWcWiGAc3PHuZ0_H-7sad2oY00o83S"];
127
- interface OmnistonTonValidationOptions {
128
- fetch?: typeof fetch;
129
- /** Diagnostics hook: every refusal of validateTonOutputPosition names its check (never a secret). */
130
- onRefusal?: (reason: string, details?: Record<string, unknown>) => void;
131
- tonApiUrl?: string;
132
- tonApiKey?: string;
133
- /** Code interfaces accepted as swap targets (default: the STON.fi / DeDust set above). */
134
- swapTargetInterfaces?: readonly string[];
135
- /** Proxy-TON masters whose router-owned wallets may receive native input (default: pTON v1/v2). */
136
- proxyTonMasters?: readonly string[];
137
- escrowCodeHashes?: readonly string[];
138
- executionCodeHashes?: readonly string[];
139
- /** Pinned escrow authority public keys (hex, 32 bytes). */
140
- authorityKeys?: readonly string[];
141
- /** EVM→TON output position code hashes (default: the observed factory position). */
142
- positionCodeHashes?: readonly string[];
143
- /** Escrow code cells an output position may carry (default: the observed one). */
144
- outputEscrowCodeHashes?: readonly string[];
145
- now?: () => number;
146
- }
147
- type TonOutputPositionInput = Parameters<NonNullable<OmnistonProviderOptions["validateTonOutputPosition"]>>[0];
148
- declare function createOmnistonTonValidators(options?: OmnistonTonValidationOptions): Pick<OmnistonProviderOptions, "validateTonJettonWallet" | "validateTonSwapTarget" | "validateTonOutputPosition" | "validateTonSwapLeg"> & {
149
- validateTonEscrowPayload: (input: PayloadInput) => boolean | Promise<boolean>;
150
- };
151
- interface OmnistonTonDeliveryLocatorOptions {
152
- fetch?: typeof fetch;
153
- tonApiUrl?: string;
154
- tonApiKey?: string;
155
- /** Recipient events scanned per call (newest first; the delivery is recent by construction). */
156
- limit?: number;
157
- }
158
- interface OmnistonTonDeliveryInput {
159
- /** The output position that paid out; when absent any sender of a matching transfer counts (backfills). */
160
- positionAddress?: string;
161
- recipientAddress: string;
162
- jettonMasterAddress: string;
163
- minUnits: string;
164
- /** Unix seconds; events before it are not this delivery (backfills). With it set, the EARLIEST match wins — the one closest to the order, not a later swap's payout. */
165
- afterTimestamp?: number;
166
- /** Unix seconds; events after it are not this delivery (backfills: the row's completion time plus slack). */
167
- beforeTimestamp?: number;
168
- }
169
- /**
170
- * Finds an Omniston TON delivery: the jetton transfer from the output position
171
- * to the recipient of at least `minUnits`, in the recipient's tonapi events.
172
- * Returns tonapi's `event_id` — the hash `@anywalletkit/wallet-ton`'s history
173
- * source gives the same event as a row, so a wallet can pair the TON receive
174
- * with the swap. Feeds `omnistonProvider({locateTonDelivery})`; a server may
175
- * also call it with no position to backfill rows completed before the locator
176
- * existed. Never throws: null when nothing matched or tonapi did not answer.
177
- */
178
- declare function createOmnistonTonDeliveryLocator(options?: OmnistonTonDeliveryLocatorOptions): (input: OmnistonTonDeliveryInput) => Promise<string | null>;
179
-
180
89
  /**
181
90
  * Settlement contracts this deployment trusts for Omniston, per CAIP-2 chain.
182
91
  * Audited public addresses — no secret — so both the server wiring and the
@@ -196,4 +105,4 @@ declare const AUDITED_OMNISTON_SETTLEMENT_CONTRACTS: Record<string, string[]>;
196
105
  */
197
106
  declare const AUDITED_OMNISTON_EVM_ORDER_PROTOCOLS: Record<string, string[]>;
198
107
 
199
- export { AUDITED_OMNISTON_EVM_ORDER_PROTOCOLS, AUDITED_OMNISTON_SETTLEMENT_CONTRACTS, DEFAULT_OMNISTON_TON_CODE_HASHES, DEFAULT_OMNISTON_TON_PROXY_TON_MASTERS, DEFAULT_OMNISTON_TON_SWAP_INTERFACES, type EvmInputValidationInput, type EvmOutputValidationInput, MAX_OMNISTON_EXCLUSIVITY_SECONDS, OMNISTON_EVM_LOOKBACK_BLOCKS, OMNISTON_EVM_MIN_CONFIRMATIONS, type OmnistonEvmOutputRefusal, type OmnistonRpcRequest, type OmnistonRpcUrls, type OmnistonTonDeliveryInput, type OmnistonTonDeliveryLocatorOptions, type OmnistonTonValidationOptions, type OmnistonValidatorRefusal, SRC_ESCROW_CREATED_TOPIC, type TonOutputPositionInput, createOmnistonEvmDeliveryLocator, createOmnistonEvmInputValidator, createOmnistonEvmOutputValidator, createOmnistonTonDeliveryLocator, createOmnistonTonValidators, omnistonEvmRpcRequest };
108
+ export { AUDITED_OMNISTON_EVM_ORDER_PROTOCOLS, AUDITED_OMNISTON_SETTLEMENT_CONTRACTS, type EvmInputValidationInput, type EvmOutputValidationInput, OMNISTON_EVM_LOOKBACK_BLOCKS, OMNISTON_EVM_MIN_CONFIRMATIONS, type OmnistonEvmOutputRefusal, type OmnistonRpcRequest, type OmnistonRpcUrls, type OmnistonValidatorRefusal, SRC_ESCROW_CREATED_TOPIC, createOmnistonEvmDeliveryLocator, createOmnistonEvmInputValidator, createOmnistonEvmOutputValidator, omnistonEvmRpcRequest };
@@ -1,4 +1,4 @@
1
- import { OmnistonProviderOptions } from './provider.js';
1
+ export { D as DEFAULT_OMNISTON_TON_CODE_HASHES, w as DEFAULT_OMNISTON_TON_PROXY_TON_MASTERS, x as DEFAULT_OMNISTON_TON_SWAP_INTERFACES, M as MAX_OMNISTON_EXCLUSIVITY_SECONDS, y as OmnistonTonDeliveryInput, z as OmnistonTonDeliveryLocatorOptions, B as OmnistonTonValidationOptions, F as TonEscrowBuildExpectation, G as TonOutputPositionInput, I as createOmnistonTonDeliveryLocator, J as createOmnistonTonValidators } from './provider-BBG2zhpu.js';
2
2
  import '@anywalletkit/protocol-swap2-core/types';
3
3
 
4
4
  /** How far back (blocks) a factory event is searched, per chain — shared with the EVM input validator. */
@@ -86,97 +86,6 @@ declare function createOmnistonEvmInputValidator(options?: {
86
86
  onRefusal?: OmnistonValidatorRefusal;
87
87
  }): (input: EvmInputValidationInput) => Promise<boolean>;
88
88
 
89
- /** Audited from the active mainnet Escrow builder on 2026-08-13. These are
90
- * immutable TVM code cells, not resolver-controlled addresses. A contract
91
- * upgrade must deliberately update these hashes after reviewing its schema.
92
- *
93
- * `authorityKeys` is the optional 256-bit public key in the escrow config: the
94
- * escrow code checks `CHKSIGNU` against it for its signature-gated operations
95
- * (disassembly of code 9e77cb9e…, 2026-10-11). It has been the same key since
96
- * the August audit, so it stays pinned. */
97
- declare const DEFAULT_OMNISTON_TON_CODE_HASHES: {
98
- readonly escrow: readonly ["9e77cb9e8fd7406d4e85e5f57378eb51e51b862424cf988306c783d50ade697a"];
99
- readonly execution: readonly ["f6edbc76e6fbcd6bac573cb942401a3d9198ee9605f9403b0f5c8081259210e5"];
100
- readonly authorityKeys: readonly ["ed210da12aa96ea42de4f2f61dc172bbaa3da86051a1b2a6f342f69a777d2770"];
101
- /** EVM→TON output position: the contract the factory deploys for the
102
- * resolver's jetton lock (observed on every resolver-created position,
103
- * 2026-10-15/16), and the escrow code cell it carries in its state. */
104
- readonly position: readonly ["e4d5115a321ade7b827e38fb522c20d2f2cd46e4c6b0b5f7dd8b6b096792d77b"];
105
- readonly outputEscrow: readonly ["d30423575384773abaad8d3c6f763898afa3d57a5693005904b7c61e95cee630"];
106
- };
107
- /** Upper bound on the exclusivity window the escrow config may carry. It is
108
- * how long the trader's input stays locked when no resolver reserves the
109
- * position (SDK: "at the end of this period trader's position becomes
110
- * available for manual withdrawal"); the live value is 300 s. */
111
- declare const MAX_OMNISTON_EXCLUSIVITY_SECONDS = 3600;
112
- type PayloadInput = Omit<Parameters<NonNullable<OmnistonProviderOptions["validateTonEscrowPayload"]>>[0], "exclusivityTimeout"> & {
113
- exclusivityTimeout?: number;
114
- };
115
- /** Code interfaces (tonapi's by-code-hash labels) a same-chain swap message
116
- * may pay into. The resolver picks the pool/vault per route, so the check is
117
- * "a STON.fi or DeDust contract by code", not a fixed address list — seen
118
- * live: native GRAM → DeDust CPMM v2 pool, jettons → STON.fi router v2. */
119
- declare const DEFAULT_OMNISTON_TON_SWAP_INTERFACES: readonly ["stonfi_router", "stonfi_router_v2", "stonfi_pool", "stonfi_pool_v2", "dedust_vault", "dedust_v2_cpmm", "dedust_pool"];
120
- /** Proxy-TON (pTON) jetton masters STON.fi routes native TON through. A
121
- * native-input swap pays the ROUTER'S pTON wallet — a plain `jetton_wallet`
122
- * to tonapi, no DEX code interface — so such a target is accepted only when
123
- * its jetton master is pTON AND its owner carries a DEX router interface.
124
- * Seen live 2026-09-05: GRAM → USDT on StonFiV2 targeted the router's pTON
125
- * v2 wallet and the code-interface check alone refused it. */
126
- declare const DEFAULT_OMNISTON_TON_PROXY_TON_MASTERS: readonly ["EQCM3B12QK1e4yZSf8GtBRT0aLMNyEsBc_DhVfRRtOEffLez", "EQBnGWMCf3-FZZq1W4IWcWiGAc3PHuZ0_H-7sad2oY00o83S"];
127
- interface OmnistonTonValidationOptions {
128
- fetch?: typeof fetch;
129
- /** Diagnostics hook: every refusal of validateTonOutputPosition names its check (never a secret). */
130
- onRefusal?: (reason: string, details?: Record<string, unknown>) => void;
131
- tonApiUrl?: string;
132
- tonApiKey?: string;
133
- /** Code interfaces accepted as swap targets (default: the STON.fi / DeDust set above). */
134
- swapTargetInterfaces?: readonly string[];
135
- /** Proxy-TON masters whose router-owned wallets may receive native input (default: pTON v1/v2). */
136
- proxyTonMasters?: readonly string[];
137
- escrowCodeHashes?: readonly string[];
138
- executionCodeHashes?: readonly string[];
139
- /** Pinned escrow authority public keys (hex, 32 bytes). */
140
- authorityKeys?: readonly string[];
141
- /** EVM→TON output position code hashes (default: the observed factory position). */
142
- positionCodeHashes?: readonly string[];
143
- /** Escrow code cells an output position may carry (default: the observed one). */
144
- outputEscrowCodeHashes?: readonly string[];
145
- now?: () => number;
146
- }
147
- type TonOutputPositionInput = Parameters<NonNullable<OmnistonProviderOptions["validateTonOutputPosition"]>>[0];
148
- declare function createOmnistonTonValidators(options?: OmnistonTonValidationOptions): Pick<OmnistonProviderOptions, "validateTonJettonWallet" | "validateTonSwapTarget" | "validateTonOutputPosition" | "validateTonSwapLeg"> & {
149
- validateTonEscrowPayload: (input: PayloadInput) => boolean | Promise<boolean>;
150
- };
151
- interface OmnistonTonDeliveryLocatorOptions {
152
- fetch?: typeof fetch;
153
- tonApiUrl?: string;
154
- tonApiKey?: string;
155
- /** Recipient events scanned per call (newest first; the delivery is recent by construction). */
156
- limit?: number;
157
- }
158
- interface OmnistonTonDeliveryInput {
159
- /** The output position that paid out; when absent any sender of a matching transfer counts (backfills). */
160
- positionAddress?: string;
161
- recipientAddress: string;
162
- jettonMasterAddress: string;
163
- minUnits: string;
164
- /** Unix seconds; events before it are not this delivery (backfills). With it set, the EARLIEST match wins — the one closest to the order, not a later swap's payout. */
165
- afterTimestamp?: number;
166
- /** Unix seconds; events after it are not this delivery (backfills: the row's completion time plus slack). */
167
- beforeTimestamp?: number;
168
- }
169
- /**
170
- * Finds an Omniston TON delivery: the jetton transfer from the output position
171
- * to the recipient of at least `minUnits`, in the recipient's tonapi events.
172
- * Returns tonapi's `event_id` — the hash `@anywalletkit/wallet-ton`'s history
173
- * source gives the same event as a row, so a wallet can pair the TON receive
174
- * with the swap. Feeds `omnistonProvider({locateTonDelivery})`; a server may
175
- * also call it with no position to backfill rows completed before the locator
176
- * existed. Never throws: null when nothing matched or tonapi did not answer.
177
- */
178
- declare function createOmnistonTonDeliveryLocator(options?: OmnistonTonDeliveryLocatorOptions): (input: OmnistonTonDeliveryInput) => Promise<string | null>;
179
-
180
89
  /**
181
90
  * Settlement contracts this deployment trusts for Omniston, per CAIP-2 chain.
182
91
  * Audited public addresses — no secret — so both the server wiring and the
@@ -196,4 +105,4 @@ declare const AUDITED_OMNISTON_SETTLEMENT_CONTRACTS: Record<string, string[]>;
196
105
  */
197
106
  declare const AUDITED_OMNISTON_EVM_ORDER_PROTOCOLS: Record<string, string[]>;
198
107
 
199
- export { AUDITED_OMNISTON_EVM_ORDER_PROTOCOLS, AUDITED_OMNISTON_SETTLEMENT_CONTRACTS, DEFAULT_OMNISTON_TON_CODE_HASHES, DEFAULT_OMNISTON_TON_PROXY_TON_MASTERS, DEFAULT_OMNISTON_TON_SWAP_INTERFACES, type EvmInputValidationInput, type EvmOutputValidationInput, MAX_OMNISTON_EXCLUSIVITY_SECONDS, OMNISTON_EVM_LOOKBACK_BLOCKS, OMNISTON_EVM_MIN_CONFIRMATIONS, type OmnistonEvmOutputRefusal, type OmnistonRpcRequest, type OmnistonRpcUrls, type OmnistonTonDeliveryInput, type OmnistonTonDeliveryLocatorOptions, type OmnistonTonValidationOptions, type OmnistonValidatorRefusal, SRC_ESCROW_CREATED_TOPIC, type TonOutputPositionInput, createOmnistonEvmDeliveryLocator, createOmnistonEvmInputValidator, createOmnistonEvmOutputValidator, createOmnistonTonDeliveryLocator, createOmnistonTonValidators, omnistonEvmRpcRequest };
108
+ export { AUDITED_OMNISTON_EVM_ORDER_PROTOCOLS, AUDITED_OMNISTON_SETTLEMENT_CONTRACTS, type EvmInputValidationInput, type EvmOutputValidationInput, OMNISTON_EVM_LOOKBACK_BLOCKS, OMNISTON_EVM_MIN_CONFIRMATIONS, type OmnistonEvmOutputRefusal, type OmnistonRpcRequest, type OmnistonRpcUrls, type OmnistonValidatorRefusal, SRC_ESCROW_CREATED_TOPIC, createOmnistonEvmDeliveryLocator, createOmnistonEvmInputValidator, createOmnistonEvmOutputValidator, omnistonEvmRpcRequest };
@@ -507,6 +507,40 @@ function createOmnistonEvmInputValidator(options = {}) {
507
507
  import { Buffer } from "buffer";
508
508
  import { Address, Cell } from "@ton/core";
509
509
  import { bigintToNumber as bigintToNumber2 } from "@anywalletkit/core";
510
+
511
+ // src/validators/settlement.ts
512
+ var AUDITED_OMNISTON_SETTLEMENT_CONTRACTS = {
513
+ "ton:-239": ["EQAbWJ3Y1HgIIvcMq1prG1anlDC0T3cZlAU7luPT6LmTpmrZ"],
514
+ "eip155:1": ["0xafCF681272AF10959736f45616eeCBC22D7095E2"],
515
+ "eip155:56": ["0xafCF681272AF10959736f45616eeCBC22D7095E2"],
516
+ "eip155:137": ["0x41A392062A4307a6961d48e30FF20bF6823715B8"],
517
+ "eip155:4663": ["0xafCF681272AF10959736f45616eeCBC22D7095E2"],
518
+ "eip155:8453": ["0xACa3E2F9b61a44892926bC6c3e104192E7D1c3cd"],
519
+ "eip155:42161": ["0xafCF681272AF10959736f45616eeCBC22D7095E2"],
520
+ "eip155:43114": ["0xafCF681272AF10959736f45616eeCBC22D7095E2"],
521
+ // 2026-10-20: one factory address on X Layer, HyperEVM and Plasma. Runtime
522
+ // bytecode equals Ethereum's 0xafCF… byte for byte except the immutable slots
523
+ // (escrow implementations, its order protocol, domain hash); it references
524
+ // the order protocol trusted below on the same chain.
525
+ "eip155:196": ["0xd602079AFa5c38F550510a2a988CbFa698Fa0189"],
526
+ "eip155:999": ["0xd602079AFa5c38F550510a2a988CbFa698Fa0189"],
527
+ "eip155:9745": ["0xd602079AFa5c38F550510a2a988CbFa698Fa0189"]
528
+ };
529
+ var AUDITED_OMNISTON_EVM_ORDER_PROTOCOLS = {
530
+ "eip155:1": ["0xb5810aCfD45D85Eaa938bF90a5857295513DA7E9"],
531
+ "eip155:56": ["0xb5810aCfD45D85Eaa938bF90a5857295513DA7E9"],
532
+ "eip155:137": ["0xafCF681272AF10959736f45616eeCBC22D7095E2"],
533
+ "eip155:8453": ["0xe7405fAcDEDB2512e91F2886BDff13231343aF5E"],
534
+ "eip155:42161": ["0xb5810aCfD45D85Eaa938bF90a5857295513DA7E9"],
535
+ "eip155:43114": ["0xb5810aCfD45D85Eaa938bF90a5857295513DA7E9"],
536
+ // 2026-10-20: bytecode equals Ethereum's 0xb581… except immutables (wrapped
537
+ // native, own address, chain id 196 / 9745 / 999 at the chain-id slot).
538
+ "eip155:196": ["0xb5810aCfD45D85Eaa938bF90a5857295513DA7E9"],
539
+ "eip155:9745": ["0xb5810aCfD45D85Eaa938bF90a5857295513DA7E9"],
540
+ "eip155:999": ["0xD84778bbeEC5D2a8d17c6424249C438EC0b1ABE3"]
541
+ };
542
+
543
+ // src/validators/ton.ts
510
544
  var JETTON_TRANSFER_OP = 260734629;
511
545
  var ESCROW_CREATE_OP = 3232100569;
512
546
  var ESCROW_CONFIG_OP = 4073126499;
@@ -683,6 +717,11 @@ function exactCellEnd(slice) {
683
717
  return slice.remainingBits === 0 && slice.remainingRefs === 0;
684
718
  }
685
719
  function destinationChainId(chain) {
720
+ const caip2 = /^eip155:([0-9]{1,10})$/.exec(chain);
721
+ if (caip2) {
722
+ const id = BigInt(caip2[1]);
723
+ return [1n, 56n, 137n, 4663n, 8453n, 42161n, 43114n, 196n, 999n, 9745n].includes(id) ? id : null;
724
+ }
686
725
  const ids = {
687
726
  ethereum: 1n,
688
727
  bnb: 56n,
@@ -697,6 +736,65 @@ function destinationChainId(chain) {
697
736
  };
698
737
  return ids[chain] ?? null;
699
738
  }
739
+ function readTonEscrowBody(payloadBocHex) {
740
+ const outer = oneRoot(payloadBocHex, "payload").beginParse();
741
+ if (outer.loadUint(32) !== JETTON_TRANSFER_OP) throw new Error("not a jetton transfer");
742
+ outer.loadUintBig(64);
743
+ const amount = outer.loadCoins();
744
+ const protocol = outer.loadAddressAny();
745
+ if (!(protocol instanceof Address)) throw new Error("no protocol address");
746
+ outer.loadAddressAny();
747
+ if (outer.loadMaybeRef() !== null) throw new Error("custom payload");
748
+ outer.loadCoins();
749
+ if (!outer.loadBit() || outer.remainingRefs !== 1) throw new Error("no forward payload");
750
+ const forward = outer.loadRef();
751
+ const root = forward.beginParse();
752
+ if (root.loadUint(32) !== ESCROW_CREATE_OP) throw new Error("not an escrow create");
753
+ const quoteId = Buffer.from(root.loadBuffer(32)).toString("hex");
754
+ root.loadBit();
755
+ root.loadAddressAny();
756
+ root.loadCoins();
757
+ root.loadBit();
758
+ if (root.remainingRefs !== 4) throw new Error("escrow refs");
759
+ const config = root.loadRef().beginParse();
760
+ if (config.loadUint(32) !== ESCROW_CONFIG_OP) throw new Error("escrow config");
761
+ const resolver = config.loadAddressAny();
762
+ if (!(resolver instanceof Address)) throw new Error("no resolver");
763
+ if (config.loadBit()) config.loadBuffer(32);
764
+ const exclusivity = config.loadUintBig(64);
765
+ config.loadUintBig(64);
766
+ if (config.remainingRefs !== 2) throw new Error("escrow config refs");
767
+ const state = config.loadRef();
768
+ if (!config.loadBit()) throw new Error("no destination");
769
+ const destination = config.loadRef().beginParse();
770
+ if (state.refs.length !== 2) throw new Error("escrow state");
771
+ const execution = state.refs[1].beginParse();
772
+ execution.loadUint(32);
773
+ const secretHash = new Uint8Array(execution.loadBuffer(32));
774
+ execution.loadAddressAny();
775
+ for (let i = 0; i < 4; i++) execution.loadUintBig(64);
776
+ const ownerData = execution.loadRef().beginParse();
777
+ ownerData.loadAddressAny();
778
+ ownerData.loadBit();
779
+ const deposit = ownerData.loadCoins();
780
+ destination.loadUintBig(64);
781
+ destination.loadBuffer(20);
782
+ destination.loadBuffer(20);
783
+ const resolverSends = destination.loadCoins();
784
+ if (exclusivity > BigInt(MAX_OMNISTON_EXCLUSIVITY_SECONDS)) throw new Error("exclusivity");
785
+ return {
786
+ amount,
787
+ protocolAddress: protocol.toString(),
788
+ forwardPayloadBocHex: Buffer.from(forward.toBoc()).toString("hex"),
789
+ quoteId,
790
+ initialResolverAddress: resolver.toString(),
791
+ exclusivityTimeout: Number(exclusivity.toString()),
792
+ // bounded above
793
+ secretHash,
794
+ depositUnits: deposit.toString(),
795
+ resolverSendsUnits: resolverSends.toString()
796
+ };
797
+ }
700
798
  function validatePayload(input, trusted) {
701
799
  const exclusivityTimeout = input.exclusivityTimeout;
702
800
  if (typeof exclusivityTimeout !== "number" || !Number.isSafeInteger(exclusivityTimeout) || exclusivityTimeout < 1 || exclusivityTimeout > MAX_OMNISTON_EXCLUSIVITY_SECONDS) return false;
@@ -814,6 +912,7 @@ function createOmnistonTonValidators(options = {}) {
814
912
  position: new Set((options.positionCodeHashes ?? DEFAULT_OMNISTON_TON_CODE_HASHES.position).map((value) => value.toLowerCase())),
815
913
  outputEscrow: new Set((options.outputEscrowCodeHashes ?? DEFAULT_OMNISTON_TON_CODE_HASHES.outputEscrow).map((value) => value.toLowerCase()))
816
914
  };
915
+ const trustedProtocols = new Set((options.trustedProtocolAddresses ?? AUDITED_OMNISTON_SETTLEMENT_CONTRACTS["ton:-239"] ?? []).map((value) => Address.parse(value).toRawString()));
817
916
  const jettonWalletOf = async (ownerAddress, jettonMasterAddress) => {
818
917
  const response = await get(`/v2/accounts/${encodeURIComponent(ownerAddress)}/jettons/${encodeURIComponent(jettonMasterAddress)}`);
819
918
  if (!response.ok) return null;
@@ -845,6 +944,51 @@ function createOmnistonTonValidators(options = {}) {
845
944
  return false;
846
945
  }
847
946
  },
947
+ /**
948
+ * The app's own check of a TON → EVM escrow build behind `remoteProvider` (through `omnistonVerifyBuild`): the
949
+ * structural check `validateTonEscrowPayload` runs on the server, with every field that decides where the
950
+ * trader's money goes taken from the app — the jetton amount, the owner the excess and refunds go to, the
951
+ * destination chain, address and token, a delivery of at least `minResolverSendsUnits`, and a protocol contract
952
+ * from `trustedProtocolAddresses`. The fields the server and the resolver choose (quote id, resolver, hashlock,
953
+ * exclusivity, deposit) are read from the body and held to the same pins and bounds: audited escrow and
954
+ * execution code, authority key, one execution, the reviewed timelocks, no Dutch auction. A reason, or `null`.
955
+ */
956
+ verifyTonEscrowBuild(input) {
957
+ let body;
958
+ try {
959
+ body = readTonEscrowBody(input.payloadBocHex);
960
+ } catch {
961
+ return "the escrow body is not an Omniston escrow transfer";
962
+ }
963
+ if (!trustedProtocols.has(Address.parse(body.protocolAddress).toRawString())) return `the escrow transfer pays ${body.protocolAddress}, not an Omniston protocol contract this app trusts`;
964
+ if (!/^\d{1,40}$/.test(input.inputUnits) || body.amount !== BigInt(input.inputUnits)) return `the escrow transfer moves ${body.amount}, not the ${input.inputUnits} this swap sells`;
965
+ if (!/^\d{1,80}$/.test(input.minResolverSendsUnits) || BigInt(body.resolverSendsUnits) < BigInt(input.minResolverSendsUnits)) {
966
+ return `the resolver is bound to deliver ${body.resolverSendsUnits}, under the quote's minimum ${input.minResolverSendsUnits}`;
967
+ }
968
+ let ok = false;
969
+ try {
970
+ ok = validatePayload({
971
+ payloadBocHex: input.payloadBocHex,
972
+ forwardPayloadBocHex: body.forwardPayloadBocHex,
973
+ quoteId: body.quoteId,
974
+ inputUnits: input.inputUnits,
975
+ resolverSendsUnits: body.resolverSendsUnits,
976
+ srcHtlcSecurityDepositUnits: body.depositUnits,
977
+ protocolAddress: body.protocolAddress,
978
+ ownerAddress: input.ownerAddress,
979
+ destinationChain: input.destinationChain,
980
+ destinationAddress: input.destinationAddress,
981
+ outputTokenAddress: input.outputTokenAddress,
982
+ initialResolverAddress: body.initialResolverAddress,
983
+ secretHashes: [body.secretHash],
984
+ hashingFunction: "HASHING_FUNCTION_KECCAK256",
985
+ exclusivityTimeout: body.exclusivityTimeout
986
+ }, trusted);
987
+ } catch {
988
+ ok = false;
989
+ }
990
+ return ok ? null : "the escrow body is not this swap's (owner, destination chain, address or token) or not the audited escrow (code, authority, timelocks)";
991
+ },
848
992
  /**
849
993
  * EVM→TON: the position the tracking feed named must be (1) an active
850
994
  * contract with the pinned position code, (2) carrying state that binds
@@ -1015,38 +1159,6 @@ function createOmnistonTonDeliveryLocator(options = {}) {
1015
1159
  }
1016
1160
  };
1017
1161
  }
1018
-
1019
- // src/validators/settlement.ts
1020
- var AUDITED_OMNISTON_SETTLEMENT_CONTRACTS = {
1021
- "ton:-239": ["EQAbWJ3Y1HgIIvcMq1prG1anlDC0T3cZlAU7luPT6LmTpmrZ"],
1022
- "eip155:1": ["0xafCF681272AF10959736f45616eeCBC22D7095E2"],
1023
- "eip155:56": ["0xafCF681272AF10959736f45616eeCBC22D7095E2"],
1024
- "eip155:137": ["0x41A392062A4307a6961d48e30FF20bF6823715B8"],
1025
- "eip155:4663": ["0xafCF681272AF10959736f45616eeCBC22D7095E2"],
1026
- "eip155:8453": ["0xACa3E2F9b61a44892926bC6c3e104192E7D1c3cd"],
1027
- "eip155:42161": ["0xafCF681272AF10959736f45616eeCBC22D7095E2"],
1028
- "eip155:43114": ["0xafCF681272AF10959736f45616eeCBC22D7095E2"],
1029
- // 2026-10-20: one factory address on X Layer, HyperEVM and Plasma. Runtime
1030
- // bytecode equals Ethereum's 0xafCF… byte for byte except the immutable slots
1031
- // (escrow implementations, its order protocol, domain hash); it references
1032
- // the order protocol trusted below on the same chain.
1033
- "eip155:196": ["0xd602079AFa5c38F550510a2a988CbFa698Fa0189"],
1034
- "eip155:999": ["0xd602079AFa5c38F550510a2a988CbFa698Fa0189"],
1035
- "eip155:9745": ["0xd602079AFa5c38F550510a2a988CbFa698Fa0189"]
1036
- };
1037
- var AUDITED_OMNISTON_EVM_ORDER_PROTOCOLS = {
1038
- "eip155:1": ["0xb5810aCfD45D85Eaa938bF90a5857295513DA7E9"],
1039
- "eip155:56": ["0xb5810aCfD45D85Eaa938bF90a5857295513DA7E9"],
1040
- "eip155:137": ["0xafCF681272AF10959736f45616eeCBC22D7095E2"],
1041
- "eip155:8453": ["0xe7405fAcDEDB2512e91F2886BDff13231343aF5E"],
1042
- "eip155:42161": ["0xb5810aCfD45D85Eaa938bF90a5857295513DA7E9"],
1043
- "eip155:43114": ["0xb5810aCfD45D85Eaa938bF90a5857295513DA7E9"],
1044
- // 2026-10-20: bytecode equals Ethereum's 0xb581… except immutables (wrapped
1045
- // native, own address, chain id 196 / 9745 / 999 at the chain-id slot).
1046
- "eip155:196": ["0xb5810aCfD45D85Eaa938bF90a5857295513DA7E9"],
1047
- "eip155:9745": ["0xb5810aCfD45D85Eaa938bF90a5857295513DA7E9"],
1048
- "eip155:999": ["0xD84778bbeEC5D2a8d17c6424249C438EC0b1ABE3"]
1049
- };
1050
1162
  export {
1051
1163
  AUDITED_OMNISTON_EVM_ORDER_PROTOCOLS,
1052
1164
  AUDITED_OMNISTON_SETTLEMENT_CONTRACTS,