@anywalletkit/protocol-swap2-omniston 0.0.0-stage → 0.2.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 (48) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +94 -2
  3. package/dist/activity.cjs +79 -0
  4. package/dist/activity.cjs.map +1 -0
  5. package/dist/activity.d.cts +10 -0
  6. package/dist/activity.d.ts +10 -0
  7. package/dist/activity.js +13 -0
  8. package/dist/activity.js.map +1 -0
  9. package/dist/chunk-AIWAM7BS.js +59 -0
  10. package/dist/chunk-AIWAM7BS.js.map +1 -0
  11. package/dist/chunk-K2KBWGNL.js +27 -0
  12. package/dist/chunk-K2KBWGNL.js.map +1 -0
  13. package/dist/chunk-QDXFC6BC.js +30 -0
  14. package/dist/chunk-QDXFC6BC.js.map +1 -0
  15. package/dist/chunk-W3AXGSX3.js +2148 -0
  16. package/dist/chunk-W3AXGSX3.js.map +1 -0
  17. package/dist/config.cjs +50 -0
  18. package/dist/config.cjs.map +1 -0
  19. package/dist/config.d.cts +12 -0
  20. package/dist/config.d.ts +12 -0
  21. package/dist/config.js +7 -0
  22. package/dist/config.js.map +1 -0
  23. package/dist/index.cjs +2276 -0
  24. package/dist/index.cjs.map +1 -0
  25. package/dist/index.d.cts +8 -0
  26. package/dist/index.d.ts +8 -0
  27. package/dist/index.js +40 -0
  28. package/dist/index.js.map +1 -0
  29. package/dist/protocol.cjs +2262 -0
  30. package/dist/protocol.cjs.map +1 -0
  31. package/dist/protocol.d.cts +15 -0
  32. package/dist/protocol.d.ts +15 -0
  33. package/dist/protocol.js +10 -0
  34. package/dist/protocol.js.map +1 -0
  35. package/dist/provider.cjs +2251 -0
  36. package/dist/provider.cjs.map +1 -0
  37. package/dist/provider.d.cts +590 -0
  38. package/dist/provider.d.ts +590 -0
  39. package/dist/provider.js +23 -0
  40. package/dist/provider.js.map +1 -0
  41. package/dist/validators.cjs +1072 -0
  42. package/dist/validators.cjs.map +1 -0
  43. package/dist/validators.d.cts +199 -0
  44. package/dist/validators.d.ts +199 -0
  45. package/dist/validators.js +1065 -0
  46. package/dist/validators.js.map +1 -0
  47. package/module.json +17 -0
  48. package/package.json +88 -3
@@ -0,0 +1,199 @@
1
+ import { OmnistonProviderOptions } from './provider.js';
2
+ import '@anywalletkit/protocol-swap2-core/types';
3
+
4
+ /** How far back (blocks) a factory event is searched, per chain — shared with the EVM input validator. */
5
+ declare const OMNISTON_EVM_LOOKBACK_BLOCKS: Readonly<Record<string, bigint>>;
6
+ /** Confirmations before a factory event counts as final, per chain. */
7
+ declare const OMNISTON_EVM_MIN_CONFIRMATIONS: Readonly<Record<string, bigint>>;
8
+ type OmnistonRpcRequest = (chain: string, method: string, params: unknown[]) => Promise<unknown>;
9
+ /** CAIP-2 chain → JSON-RPC URLs, tried in order before the public fallbacks. */
10
+ type OmnistonRpcUrls = Readonly<Record<string, readonly string[]>>;
11
+ type RpcRequest = OmnistonRpcRequest;
12
+ interface EvmOutputValidationInput {
13
+ chain: string;
14
+ positionAddress: string;
15
+ factoryAddress: string;
16
+ quoteTimestamp: number;
17
+ executionIndex: number;
18
+ recipientAddress: string;
19
+ outputTokenAddress: string;
20
+ inputUnits: string;
21
+ outputUnits: string;
22
+ resolverSendsUnits: string;
23
+ srcHtlcSecurityDepositUnits: string;
24
+ dstSecurityDepositUnits: string;
25
+ protocolFeeUnits: string;
26
+ integratorFeeUnits: string;
27
+ integratorAddress?: string;
28
+ /** The quote's `settlementData.protocolFeeRecipientAddress` (destination
29
+ * chain): the only address the escrow may pay a non-zero protocol fee to. */
30
+ protocolFeeRecipientAddress?: string;
31
+ secretHash: Uint8Array;
32
+ }
33
+ /** Diagnostics hook: every refusal names its check and the numbers it compared (never a secret). */
34
+ type OmnistonEvmOutputRefusal = (reason: string, details?: Record<string, unknown>) => void;
35
+ /** JSON-RPC over the caller's endpoints (`rpcUrls`) with public failover (reads only). */
36
+ declare function omnistonEvmRpcRequest(chain: string, method: string, params: unknown[], rpcUrls?: OmnistonRpcUrls): Promise<unknown>;
37
+ declare function createOmnistonEvmOutputValidator(options?: {
38
+ request?: RpcRequest;
39
+ rpcUrls?: OmnistonRpcUrls;
40
+ now?: () => number;
41
+ onRefusal?: OmnistonEvmOutputRefusal;
42
+ }): (input: EvmOutputValidationInput) => Promise<boolean>;
43
+ /**
44
+ * Finds an Omniston EVM delivery: the ERC-20 `Transfer` from the destination
45
+ * escrow to the recipient of at least `minUnits`, within the chain's lookback
46
+ * window. Feeds `omnistonProvider({locateEvmDelivery})` so a completed order
47
+ * reports the transaction that actually paid the recipient.
48
+ */
49
+ declare function createOmnistonEvmDeliveryLocator(options?: {
50
+ request?: RpcRequest;
51
+ rpcUrls?: OmnistonRpcUrls;
52
+ }): (input: {
53
+ chain: string;
54
+ positionAddress: string;
55
+ recipientAddress: string;
56
+ tokenAddress: string;
57
+ minUnits: string;
58
+ }) => Promise<string | null>;
59
+
60
+ /** keccak256 of the event signature with the structs expanded (live Base 2026-10-16: 0x1140dcf8…). */
61
+ declare const SRC_ESCROW_CREATED_TOPIC: `0x${string}`;
62
+ interface EvmInputValidationInput {
63
+ chain: string;
64
+ positionAddress: string;
65
+ factoryAddress: string;
66
+ orderProtocolAddress: string;
67
+ ownerAddress: string;
68
+ resolverAddress: string;
69
+ inputTokenAddress: string;
70
+ inputUnits: string;
71
+ resolverSendsUnits: string;
72
+ srcHtlcSecurityDepositUnits: string;
73
+ quoteTimestamp: number;
74
+ secretHash: Uint8Array;
75
+ /** EVM destination only: the destination complement must name this chain, token and deposit. */
76
+ destinationChainId?: number;
77
+ destinationTokenAddress?: string;
78
+ dstSecurityDepositUnits?: string;
79
+ }
80
+ /** Diagnostics hook: every refusal names its check and the numbers it compared (never a secret). */
81
+ type OmnistonValidatorRefusal = (reason: string, details?: Record<string, unknown>) => void;
82
+ declare function createOmnistonEvmInputValidator(options?: {
83
+ request?: OmnistonRpcRequest;
84
+ rpcUrls?: OmnistonRpcUrls;
85
+ now?: () => number;
86
+ onRefusal?: OmnistonValidatorRefusal;
87
+ }): (input: EvmInputValidationInput) => Promise<boolean>;
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
+ /**
181
+ * Settlement contracts this deployment trusts for Omniston, per CAIP-2 chain.
182
+ * Audited public addresses — no secret — so both the server wiring and the
183
+ * browser-side provider import them from here.
184
+ * See how-to-project/OMNISTON-NETWORK-ONBOARDING.md before adding a network.
185
+ */
186
+ declare const AUDITED_OMNISTON_SETTLEMENT_CONTRACTS: Record<string, string[]>;
187
+ /**
188
+ * EVM order protocols (Omniston's fork of the 1inch Limit Order Protocol v4 —
189
+ * NOT the canonical 1inch deployment) an EVM→TON order is signed against. The
190
+ * wallet approves this contract for the input amount and signs an EIP-712
191
+ * order whose domain names it; on fill it moves the input into the escrow the
192
+ * factory above deploys. One address, different roles per chain (0xafCF… is
193
+ * the factory elsewhere and the order protocol on Polygon), so this table is
194
+ * separate from the factory table and CAIP-scoped. Runtime code hashes are in
195
+ * how-to-project/OMNISTON-NETWORK-ONBOARDING.md (snapshot 2026-10-16).
196
+ */
197
+ declare const AUDITED_OMNISTON_EVM_ORDER_PROTOCOLS: Record<string, string[]>;
198
+
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 };