@ocap/tx-pipeline 1.30.26 → 1.31.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 (149) hide show
  1. package/esm/appchain-sovereign-hub.d.mts +160 -0
  2. package/esm/appchain-sovereign-hub.mjs +348 -0
  3. package/esm/arcvault-external-adapter.d.mts +166 -0
  4. package/esm/arcvault-external-adapter.mjs +376 -0
  5. package/esm/encrypted-nft-envelope.d.mts +172 -0
  6. package/esm/encrypted-nft-envelope.mjs +458 -0
  7. package/esm/evm-simplified-bridge.d.mts +1370 -0
  8. package/esm/evm-simplified-bridge.mjs +3875 -0
  9. package/esm/give-to-mint-karma.d.mts +472 -0
  10. package/esm/give-to-mint-karma.mjs +1057 -0
  11. package/esm/helpers/replay-guard.d.mts +15 -0
  12. package/esm/helpers/replay-guard.mjs +23 -0
  13. package/esm/index.d.mts +10 -5
  14. package/esm/index.mjs +14 -10
  15. package/esm/legacy-protocol-sunset.d.mts +251 -0
  16. package/esm/legacy-protocol-sunset.mjs +1519 -0
  17. package/esm/library.d.mts +16 -0
  18. package/esm/library.mjs +17 -0
  19. package/esm/native-abt-exchange.d.mts +2055 -0
  20. package/esm/native-abt-exchange.mjs +7250 -0
  21. package/esm/ofac-screening.d.mts +17 -0
  22. package/esm/ofac-screening.mjs +39 -0
  23. package/esm/pipes/anti-land-attack.mjs +1 -1
  24. package/esm/pipes/decode-itx.mjs +46 -4
  25. package/esm/pipes/decode-tx.d.mts +2 -3
  26. package/esm/pipes/decode-tx.mjs +56 -115
  27. package/esm/pipes/extract-signer.mjs +2 -2
  28. package/esm/pipes/extract-state.mjs +14 -3
  29. package/esm/pipes/post-execution-invariant-gate.d.mts +61 -0
  30. package/esm/pipes/post-execution-invariant-gate.mjs +789 -0
  31. package/esm/pipes/pre-flight-waf.d.mts +73 -0
  32. package/esm/pipes/pre-flight-waf.mjs +756 -0
  33. package/esm/pipes/take-state-snapshot.mjs +3 -2
  34. package/esm/pipes/update-owner.mjs +39 -4
  35. package/esm/pipes/verify-account-migration.mjs +14 -4
  36. package/esm/pipes/verify-blocked.mjs +1 -1
  37. package/esm/pipes/verify-delegation.d.mts +22 -3
  38. package/esm/pipes/verify-delegation.mjs +259 -36
  39. package/esm/pipes/verify-list-size.mjs +1 -1
  40. package/esm/pipes/verify-multisig-v2.mjs +15 -7
  41. package/esm/pipes/verify-multisig.mjs +15 -7
  42. package/esm/pipes/verify-sender.mjs +1 -1
  43. package/esm/pipes/verify-signature.mjs +35 -6
  44. package/esm/pipes/verify-signer.mjs +2 -2
  45. package/esm/pipes/verify-state-diff.mjs +3 -3
  46. package/esm/pipes/verify-token-access.mjs +1 -1
  47. package/esm/pipes/verify-token-balance.mjs +13 -5
  48. package/esm/pipes/verify-transferrable.d.mts +8 -1
  49. package/esm/pipes/verify-transferrable.mjs +3 -3
  50. package/esm/pipes/verify-tx-input.mjs +2 -2
  51. package/esm/pipes/verify-tx-size.mjs +46 -2
  52. package/esm/pipes/verify-tx.mjs +5 -7
  53. package/esm/pipes/verify-updater.mjs +1 -1
  54. package/esm/social-economy-factories.d.mts +346 -0
  55. package/esm/social-economy-factories.mjs +845 -0
  56. package/esm/super-suites-foundation.d.mts +513 -0
  57. package/esm/super-suites-foundation.mjs +1241 -0
  58. package/esm/transaction-block.d.mts +471 -0
  59. package/esm/transaction-block.mjs +1906 -0
  60. package/esm/uniswap-erc7683-solver.d.mts +201 -0
  61. package/esm/uniswap-erc7683-solver.mjs +321 -0
  62. package/esm/uniswap-lp-copilot.d.mts +113 -0
  63. package/esm/uniswap-lp-copilot.mjs +320 -0
  64. package/esm/uniswap-router.d.mts +335 -0
  65. package/esm/uniswap-router.mjs +578 -0
  66. package/esm/uniswap-token-factory-graduation.d.mts +187 -0
  67. package/esm/uniswap-token-factory-graduation.mjs +426 -0
  68. package/esm/uniswap-v4-hook.d.mts +173 -0
  69. package/esm/uniswap-v4-hook.mjs +517 -0
  70. package/lib/appchain-sovereign-hub.cjs +352 -0
  71. package/lib/appchain-sovereign-hub.d.cts +160 -0
  72. package/lib/arcvault-external-adapter.cjs +383 -0
  73. package/lib/arcvault-external-adapter.d.cts +166 -0
  74. package/lib/encrypted-nft-envelope.cjs +477 -0
  75. package/lib/encrypted-nft-envelope.d.cts +172 -0
  76. package/lib/evm-simplified-bridge.cjs +3943 -0
  77. package/lib/evm-simplified-bridge.d.cts +1370 -0
  78. package/lib/give-to-mint-karma.cjs +1084 -0
  79. package/lib/give-to-mint-karma.d.cts +472 -0
  80. package/lib/helpers/replay-guard.cjs +27 -0
  81. package/lib/helpers/replay-guard.d.cts +15 -0
  82. package/lib/index.cjs +49 -16
  83. package/lib/index.d.cts +10 -5
  84. package/lib/legacy-protocol-sunset.cjs +1543 -0
  85. package/lib/legacy-protocol-sunset.d.cts +251 -0
  86. package/lib/library.cjs +303 -0
  87. package/lib/library.d.cts +16 -0
  88. package/lib/native-abt-exchange.cjs +7322 -0
  89. package/lib/native-abt-exchange.d.cts +2055 -0
  90. package/lib/ofac-screening.cjs +42 -0
  91. package/lib/ofac-screening.d.cts +17 -0
  92. package/lib/pipes/anti-land-attack.cjs +2 -2
  93. package/lib/pipes/decode-itx.cjs +46 -4
  94. package/lib/pipes/decode-itx.d.cts +1 -1
  95. package/lib/pipes/decode-tx.cjs +55 -116
  96. package/lib/pipes/decode-tx.d.cts +3 -4
  97. package/lib/pipes/extract-signer.cjs +2 -2
  98. package/lib/pipes/extract-state.cjs +14 -3
  99. package/lib/pipes/post-execution-invariant-gate.cjs +800 -0
  100. package/lib/pipes/post-execution-invariant-gate.d.cts +61 -0
  101. package/lib/pipes/pre-flight-waf.cjs +772 -0
  102. package/lib/pipes/pre-flight-waf.d.cts +73 -0
  103. package/lib/pipes/take-state-snapshot.cjs +3 -2
  104. package/lib/pipes/update-owner.cjs +40 -5
  105. package/lib/pipes/update-owner.d.cts +1 -1
  106. package/lib/pipes/verify-account-migration.cjs +14 -4
  107. package/lib/pipes/verify-blocked.cjs +1 -1
  108. package/lib/pipes/verify-delegation.cjs +259 -36
  109. package/lib/pipes/verify-delegation.d.cts +22 -3
  110. package/lib/pipes/verify-list-size.cjs +1 -1
  111. package/lib/pipes/verify-multisig-v2.cjs +15 -7
  112. package/lib/pipes/verify-multisig.cjs +15 -7
  113. package/lib/pipes/verify-sender.cjs +1 -1
  114. package/lib/pipes/verify-service-fee.d.cts +1 -1
  115. package/lib/pipes/verify-signature.cjs +35 -6
  116. package/lib/pipes/verify-signature.d.cts +1 -1
  117. package/lib/pipes/verify-signer.cjs +2 -2
  118. package/lib/pipes/verify-state-diff.cjs +4 -4
  119. package/lib/pipes/verify-token-access.cjs +2 -2
  120. package/lib/pipes/verify-token-balance.cjs +13 -5
  121. package/lib/pipes/verify-transferrable.cjs +3 -3
  122. package/lib/pipes/verify-transferrable.d.cts +8 -1
  123. package/lib/pipes/verify-tx-input.cjs +3 -3
  124. package/lib/pipes/verify-tx-size.cjs +46 -2
  125. package/lib/pipes/verify-tx-size.d.cts +1 -1
  126. package/lib/pipes/verify-tx.cjs +6 -8
  127. package/lib/pipes/verify-tx.d.cts +1 -1
  128. package/lib/pipes/verify-updater.cjs +1 -1
  129. package/lib/social-economy-factories.cjs +852 -0
  130. package/lib/social-economy-factories.d.cts +346 -0
  131. package/lib/super-suites-foundation.cjs +1257 -0
  132. package/lib/super-suites-foundation.d.cts +513 -0
  133. package/lib/transaction-block.cjs +1941 -0
  134. package/lib/transaction-block.d.cts +471 -0
  135. package/lib/uniswap-erc7683-solver.cjs +327 -0
  136. package/lib/uniswap-erc7683-solver.d.cts +201 -0
  137. package/lib/uniswap-lp-copilot.cjs +328 -0
  138. package/lib/uniswap-lp-copilot.d.cts +113 -0
  139. package/lib/uniswap-router.cjs +593 -0
  140. package/lib/uniswap-router.d.cts +335 -0
  141. package/lib/uniswap-token-factory-graduation.cjs +431 -0
  142. package/lib/uniswap-token-factory-graduation.d.cts +187 -0
  143. package/lib/uniswap-v4-hook.cjs +527 -0
  144. package/lib/uniswap-v4-hook.d.cts +173 -0
  145. package/package.json +11 -10
  146. package/esm/helpers/dedup-height.d.mts +0 -16
  147. package/esm/helpers/dedup-height.mjs +0 -61
  148. package/lib/helpers/dedup-height.cjs +0 -72
  149. package/lib/helpers/dedup-height.d.cts +0 -16
@@ -0,0 +1,327 @@
1
+ const require_rolldown_runtime = require('./_virtual/rolldown_runtime.cjs');
2
+ const require_ofac_screening = require('./ofac-screening.cjs');
3
+ require('./uniswap-router.cjs');
4
+ const require_transaction_block = require('./transaction-block.cjs');
5
+ let _ocap_mcrypto = require("@ocap/mcrypto");
6
+ let _ocap_util = require("@ocap/util");
7
+ let _ocap_util_lib_error = require("@ocap/util/lib/error");
8
+
9
+ //#region src/uniswap-erc7683-solver.ts
10
+ /**
11
+ * Maximum number of OCAP blocks an ERC-7683 intent can lock Solver sub-vault funds (`<= 30` blocks).
12
+ */
13
+ const MAX_INTENT_TIMEOUT_BLOCKS = 30;
14
+ /**
15
+ * Maximum concurrent `PENDING` intents allowed per user address to prevent Solver liquidity exhaustion.
16
+ */
17
+ const MAX_ACTIVE_INTENTS_PER_USER = 3;
18
+ /**
19
+ * Default maximum number of expired intents swept per block (`<= 50`) to bound per-block GC gas/latency.
20
+ */
21
+ const DEFAULT_MAX_SWEEP_BATCH_SIZE = 50;
22
+ /**
23
+ * Minimum recommended Solver sub-vault shards for parallel Sealevel / 2PC execution.
24
+ */
25
+ const MIN_RECOMMENDED_SOLVER_SHARDS = 16;
26
+ const FORBIDDEN_KEYS = new Set([
27
+ "__proto__",
28
+ "constructor",
29
+ "prototype"
30
+ ]);
31
+ const CANONICAL_UINT_REGEX = /^\d+$/;
32
+ const BYTES32_HEX_REGEX = /^0x[0-9a-fA-F]{64}$/;
33
+ function assertSafeId(val, label) {
34
+ if (typeof val !== "string") throw new _ocap_util_lib_error.CustomError("INVALID_ERC7683_ORDER", `${label} must be a non-empty string`);
35
+ const trimmed = val.trim();
36
+ if (!trimmed || FORBIDDEN_KEYS.has(trimmed)) throw new _ocap_util_lib_error.CustomError("INVALID_ERC7683_ORDER", `Invalid or unsafe ${label}`);
37
+ return trimmed;
38
+ }
39
+ function parsePositiveBn(val, label) {
40
+ if (typeof val !== "string" || !CANONICAL_UINT_REGEX.test(val)) throw new _ocap_util_lib_error.CustomError("INVALID_ERC7683_ORDER", `${label} must be a canonical base-10 integer string`);
41
+ const bn = new _ocap_util.BN(val, 10);
42
+ if (bn.lte(new _ocap_util.BN(0))) throw new _ocap_util_lib_error.CustomError("INVALID_ERC7683_ORDER", `${label} must be strictly positive`);
43
+ return bn;
44
+ }
45
+ function parseNonNegativeBn(val, label) {
46
+ if (typeof val !== "string" || !CANONICAL_UINT_REGEX.test(val)) throw new _ocap_util_lib_error.CustomError("INVALID_ERC7683_ORDER", `${label} must be a canonical non-negative integer string`);
47
+ return new _ocap_util.BN(val, 10);
48
+ }
49
+ /**
50
+ * Deterministically selects a Solver sub-vault shard (`0 .. shards.length - 1`) for an `orderId`
51
+ * so concurrent ERC-7683 fills touch disjoint account state keys in `OverlayStateDB` / `2PC`.
52
+ */
53
+ function selectSolverSubVaultShard(orderId, shards) {
54
+ const safeOrderId = assertSafeId(orderId, "orderId");
55
+ if (!Array.isArray(shards) || shards.length === 0) throw new _ocap_util_lib_error.CustomError("INVALID_ERC7683_SOLVER", "solverSubVaultShards must be a non-empty array");
56
+ const digest = _ocap_mcrypto.Hasher.SHA3.hash256(Buffer.from(safeOrderId, "utf8")).replace(/^0x/, "");
57
+ const shardIndex = Number.parseInt(digest.slice(0, 8), 16) % shards.length;
58
+ return {
59
+ shardIndex,
60
+ shardAddress: assertSafeId(shards[shardIndex], `solverSubVaultShards[${shardIndex}]`)
61
+ };
62
+ }
63
+ /**
64
+ * Non-Custodial UniswapX / ERC-7683 Cross-Chain Intent Solver Engine (`OcapErc7683SolverEngine`).
65
+ *
66
+ * Security, Anti-Vampire & Regulatory Guarantees:
67
+ * 1. **Sharded Solver Vaults**: Routes intents across independent sub-vault shards to eliminate
68
+ * single-vault `LOCK_CONFLICT` bottlenecks during parallel block execution.
69
+ * 2. **Source-Escrow First & Short Timeout Cap (`<= 30` blocks)**: Requires verified origin-chain
70
+ * escrow proof before locking destination liquidity, caps per-user active intents (`<= 3`),
71
+ * and provides paginated `sweepExpiredIntents` rollback (`VOID`).
72
+ * 3. **Canary Net-Inflow Circuit Breaker**: Enforces `#1169` epoch net-inflow watermark limits.
73
+ * 4. **SEC Section 15(a)(2) Dealer Rule & FinCEN Safe Harbor**: Supports open permissionless external
74
+ * fillers and enforces `0 bps` proprietary spread in `AGENCY_PASS_THROUGH` mode (especially for `ABT`).
75
+ */
76
+ var OcapErc7683SolverEngine = class {
77
+ constructor(config, ledger) {
78
+ this.intents = /* @__PURE__ */ new Map();
79
+ this.usedOriginEscrowTxs = /* @__PURE__ */ new Set();
80
+ this.usedSettlementEvidences = /* @__PURE__ */ new Set();
81
+ this.usedDestinationFillTxs = /* @__PURE__ */ new Set();
82
+ this.ofacSet = /* @__PURE__ */ new Set();
83
+ this.currentEpochNetInflow = new _ocap_util.BN(0);
84
+ if (!config || typeof config !== "object") throw new _ocap_util_lib_error.CustomError("INVALID_ERC7683_SOLVER", "Missing SolverEngineConfig");
85
+ const fillerDid = require_ofac_screening.normalizeScreeningAddress(assertSafeId(config.fillerDid, "fillerDid"));
86
+ if (!Array.isArray(config.solverSubVaultShards) || config.solverSubVaultShards.length === 0) throw new _ocap_util_lib_error.CustomError("INVALID_ERC7683_SOLVER", "solverSubVaultShards must contain at least 1 shard address");
87
+ const normalizedShards = config.solverSubVaultShards.map((s, idx) => require_ofac_screening.normalizeScreeningAddress(assertSafeId(s, `solverSubVaultShards[${idx}]`)));
88
+ if (new Set(normalizedShards).size !== normalizedShards.length) throw new _ocap_util_lib_error.CustomError("INVALID_ERC7683_SOLVER", "solverSubVaultShards must not contain duplicate shard addresses");
89
+ if (config.executionMode !== "AGENCY_PASS_THROUGH" && config.executionMode !== "EXTERNAL_THIRD_PARTY_FILLER") throw new _ocap_util_lib_error.CustomError("INVALID_ERC7683_SOLVER", `Unsupported executionMode: ${String(config.executionMode)}`);
90
+ const maxTimeoutBlocks = config.maxTimeoutBlocks ?? MAX_INTENT_TIMEOUT_BLOCKS;
91
+ if (typeof maxTimeoutBlocks !== "number" || !Number.isSafeInteger(maxTimeoutBlocks) || maxTimeoutBlocks <= 0 || maxTimeoutBlocks > MAX_INTENT_TIMEOUT_BLOCKS) throw new _ocap_util_lib_error.CustomError("INVALID_ERC7683_SOLVER", `maxTimeoutBlocks must be an integer between 1 and ${MAX_INTENT_TIMEOUT_BLOCKS}`);
92
+ const maxActiveIntentsPerUser = config.maxActiveIntentsPerUser ?? MAX_ACTIVE_INTENTS_PER_USER;
93
+ if (typeof maxActiveIntentsPerUser !== "number" || !Number.isSafeInteger(maxActiveIntentsPerUser) || maxActiveIntentsPerUser <= 0 || maxActiveIntentsPerUser > MAX_ACTIVE_INTENTS_PER_USER) throw new _ocap_util_lib_error.CustomError("INVALID_ERC7683_SOLVER", `maxActiveIntentsPerUser must be an integer between 1 and ${MAX_ACTIVE_INTENTS_PER_USER}`);
94
+ const maxSweepBatchSize = config.maxSweepBatchSize ?? DEFAULT_MAX_SWEEP_BATCH_SIZE;
95
+ if (typeof maxSweepBatchSize !== "number" || !Number.isSafeInteger(maxSweepBatchSize) || maxSweepBatchSize <= 0 || maxSweepBatchSize > 500) throw new _ocap_util_lib_error.CustomError("INVALID_ERC7683_SOLVER", "maxSweepBatchSize must be an integer between 1 and 500");
96
+ const maxEpochNetInflowCapBn = parsePositiveBn(config.maxEpochNetInflowCap, "maxEpochNetInflowCap");
97
+ const minOriginConfirmations = config.minOriginConfirmations ?? 2;
98
+ if (typeof minOriginConfirmations !== "number" || !Number.isSafeInteger(minOriginConfirmations) || minOriginConfirmations < 1) throw new _ocap_util_lib_error.CustomError("INVALID_ERC7683_SOLVER", "minOriginConfirmations must be an integer >= 1");
99
+ if (config.ofacBlocklist) for (const item of config.ofacBlocklist) this.ofacSet.add(require_ofac_screening.normalizeScreeningAddress(item));
100
+ const abtTokenAddress = config.abtTokenAddress ? require_ofac_screening.normalizeScreeningAddress(assertSafeId(config.abtTokenAddress, "abtTokenAddress")) : void 0;
101
+ require_ofac_screening.assertNotOfacSanctioned([
102
+ fillerDid,
103
+ ...normalizedShards,
104
+ ...abtTokenAddress ? [abtTokenAddress] : []
105
+ ], this.ofacSet);
106
+ this.config = {
107
+ fillerDid,
108
+ solverSubVaultShards: normalizedShards,
109
+ executionMode: config.executionMode,
110
+ abtTokenAddress,
111
+ maxTimeoutBlocks,
112
+ maxActiveIntentsPerUser,
113
+ maxSweepBatchSize,
114
+ maxEpochNetInflowCap: maxEpochNetInflowCapBn.toString(10),
115
+ minOriginConfirmations
116
+ };
117
+ this.ledger = ledger || new require_transaction_block.TwoPhaseTransferLedger();
118
+ }
119
+ /**
120
+ * Phase 1 (`PREPARE / PENDING`):
121
+ * Validates an ERC-7683 `ResolvedCrossChainOrder` and its origin-chain escrow proof, checks OFAC,
122
+ * SEC Dealer / Agency pass-through rules, per-user active intent quota, and Canary net-inflow cap,
123
+ * then locks destination funds in the selected Solver sub-vault shard via `TwoPhaseTransferLedger`.
124
+ */
125
+ async prepareIntentFill(params, statedb) {
126
+ if (!params || typeof params !== "object" || !params.order || !params.originEscrowProof) throw new _ocap_util_lib_error.CustomError("INVALID_ERC7683_ORDER", "Missing order or originEscrowProof");
127
+ const { order, originEscrowProof } = params;
128
+ const orderId = assertSafeId(order.orderId, "order.orderId");
129
+ if (this.intents.has(orderId)) throw new _ocap_util_lib_error.CustomError("DUPLICATE_ERC7683_ORDER", `ERC-7683 order ${orderId} is already registered`);
130
+ const user = require_ofac_screening.normalizeScreeningAddress(assertSafeId(order.user, "order.user"));
131
+ if (typeof order.originChainId !== "number" || !Number.isSafeInteger(order.originChainId) || order.originChainId <= 0) throw new _ocap_util_lib_error.CustomError("INVALID_ERC7683_ORDER", "order.originChainId must be a positive safe integer");
132
+ if (typeof order.openDeadline !== "number" || !Number.isSafeInteger(order.openDeadline) || order.openDeadline <= 0 || typeof order.fillDeadline !== "number" || !Number.isSafeInteger(order.fillDeadline) || order.fillDeadline < order.openDeadline) throw new _ocap_util_lib_error.CustomError("INVALID_ERC7683_ORDER", "order.openDeadline and order.fillDeadline must be positive safe integers with fillDeadline >= openDeadline");
133
+ if (!Array.isArray(order.maxSpent) || order.maxSpent.length !== 1) throw new _ocap_util_lib_error.CustomError("INVALID_ERC7683_ORDER", "order.maxSpent must contain exactly 1 atomic output");
134
+ if (!Array.isArray(order.minReceived) || order.minReceived.length !== 1) throw new _ocap_util_lib_error.CustomError("INVALID_ERC7683_ORDER", "order.minReceived must contain exactly 1 atomic output");
135
+ if (!Array.isArray(order.fillInstructions) || order.fillInstructions.length !== 1) throw new _ocap_util_lib_error.CustomError("INVALID_ERC7683_ORDER", "order.fillInstructions must contain exactly 1 instruction");
136
+ const spentSpec = order.maxSpent[0];
137
+ const receivedSpec = order.minReceived[0];
138
+ const fillInstruction = order.fillInstructions[0];
139
+ if (spentSpec.chainId !== order.originChainId) throw new _ocap_util_lib_error.CustomError("INVALID_ERC7683_ORDER", `maxSpent[0].chainId (${spentSpec.chainId}) must match order.originChainId (${order.originChainId})`);
140
+ if (typeof receivedSpec.chainId !== "number" || !Number.isSafeInteger(receivedSpec.chainId) || receivedSpec.chainId <= 0 || receivedSpec.chainId !== fillInstruction.destinationChainId || receivedSpec.chainId === order.originChainId) throw new _ocap_util_lib_error.CustomError("INVALID_ERC7683_ORDER", "minReceived[0].chainId must match fillInstructions[0].destinationChainId and differ from originChainId");
141
+ const destinationSettler = require_ofac_screening.normalizeScreeningAddress(assertSafeId(fillInstruction.destinationSettler, "fillInstructions[0].destinationSettler"));
142
+ const spentToken = require_ofac_screening.normalizeScreeningAddress(assertSafeId(spentSpec.token, "maxSpent[0].token"));
143
+ const spentRecipient = require_ofac_screening.normalizeScreeningAddress(assertSafeId(spentSpec.recipient, "maxSpent[0].recipient"));
144
+ const maxSpentAmountBn = parsePositiveBn(spentSpec.amount, "maxSpent[0].amount");
145
+ if (spentRecipient !== this.config.fillerDid && !this.config.solverSubVaultShards.includes(spentRecipient)) throw new _ocap_util_lib_error.CustomError("INVALID_ORIGIN_ESCROW_RECIPIENT", `maxSpent[0].recipient (${spentRecipient}) must be bound to Solver fillerDid (${this.config.fillerDid}) or an authorized Solver shard`);
146
+ const destToken = require_ofac_screening.normalizeScreeningAddress(assertSafeId(receivedSpec.token, "minReceived[0].token"));
147
+ const destRecipient = require_ofac_screening.normalizeScreeningAddress(assertSafeId(receivedSpec.recipient, "minReceived[0].recipient"));
148
+ const destAmountBn = parsePositiveBn(receivedSpec.amount, "minReceived[0].amount");
149
+ if (destRecipient === this.config.fillerDid || this.config.solverSubVaultShards.includes(destRecipient)) throw new _ocap_util_lib_error.CustomError("INVALID_DESTINATION_RECIPIENT", `minReceived[0].recipient (${destRecipient}) cannot be a Solver fillerDid or sub-vault shard`);
150
+ const combinedOfac = new Set(this.ofacSet);
151
+ if (params.ofacBlocklist) for (const a of params.ofacBlocklist) combinedOfac.add(require_ofac_screening.normalizeScreeningAddress(a));
152
+ require_ofac_screening.assertNotOfacSanctioned([
153
+ user,
154
+ spentToken,
155
+ spentRecipient,
156
+ destToken,
157
+ destRecipient,
158
+ destinationSettler,
159
+ originEscrowProof.escrowContractAddress,
160
+ originEscrowProof.escrowedToken,
161
+ ...originEscrowProof.escrowRecipient ? [originEscrowProof.escrowRecipient] : []
162
+ ], combinedOfac);
163
+ if (params.currentUnixTimestamp !== void 0) {
164
+ if (typeof params.currentUnixTimestamp !== "number" || !Number.isSafeInteger(params.currentUnixTimestamp) || params.currentUnixTimestamp <= 0) throw new _ocap_util_lib_error.CustomError("INVALID_ERC7683_ORDER", "currentUnixTimestamp must be a positive integer");
165
+ if (params.currentUnixTimestamp > order.fillDeadline) throw new _ocap_util_lib_error.CustomError("EXPIRED_ERC7683_ORDER", `Order ${orderId} fillDeadline (${order.fillDeadline}) has passed`);
166
+ }
167
+ const solverSpreadBps = params.solverSpreadBps ?? 0;
168
+ if (typeof solverSpreadBps !== "number" || !Number.isSafeInteger(solverSpreadBps) || solverSpreadBps < 0 || solverSpreadBps > 500) throw new _ocap_util_lib_error.CustomError("INVALID_ERC7683_ORDER", "solverSpreadBps must be an integer between 0 and 500");
169
+ const isAbtTarget = this.config.abtTokenAddress !== void 0 && destToken === this.config.abtTokenAddress;
170
+ if ((this.config.executionMode === "AGENCY_PASS_THROUGH" || isAbtTarget) && solverSpreadBps !== 0) throw new _ocap_util_lib_error.CustomError("ILLEGAL_DEALER_SPREAD", "Proprietary dealer spread (solverSpreadBps > 0) is strictly prohibited in AGENCY_PASS_THROUGH mode or when settling ABT utility tokens (SEC Section 15(a)(2) Safe Harbor)");
171
+ if (originEscrowProof.originChainId !== order.originChainId) throw new _ocap_util_lib_error.CustomError("INVALID_ORIGIN_ESCROW_PROOF", `originEscrowProof.originChainId (${originEscrowProof.originChainId}) does not match order.originChainId (${order.originChainId})`);
172
+ if (!originEscrowProof.escrowRecipient) throw new _ocap_util_lib_error.CustomError("INVALID_ORIGIN_ESCROW_PROOF", "originEscrowProof.escrowRecipient is required");
173
+ const proofRecipient = require_ofac_screening.normalizeScreeningAddress(assertSafeId(originEscrowProof.escrowRecipient, "originEscrowProof.escrowRecipient"));
174
+ if (proofRecipient !== spentRecipient) throw new _ocap_util_lib_error.CustomError("INVALID_ORIGIN_ESCROW_PROOF", `originEscrowProof.escrowRecipient (${proofRecipient}) does not match order maxSpent[0].recipient (${spentRecipient})`);
175
+ if (typeof originEscrowProof.sourceEscrowTxHash !== "string" || !BYTES32_HEX_REGEX.test(originEscrowProof.sourceEscrowTxHash)) throw new _ocap_util_lib_error.CustomError("INVALID_ORIGIN_ESCROW_PROOF", "sourceEscrowTxHash must be a 32-byte 0x hex string");
176
+ const normalizedEscrowTx = originEscrowProof.sourceEscrowTxHash.toLowerCase();
177
+ const scopedEscrowKey = `${order.originChainId}:${normalizedEscrowTx}`;
178
+ if (this.usedOriginEscrowTxs.has(scopedEscrowKey)) throw new _ocap_util_lib_error.CustomError("REPLAYED_ORIGIN_ESCROW", `sourceEscrowTxHash ${normalizedEscrowTx} on chain ${order.originChainId} has already been used for another intent`);
179
+ const escrowedToken = require_ofac_screening.normalizeScreeningAddress(assertSafeId(originEscrowProof.escrowedToken, "originEscrowProof.escrowedToken"));
180
+ if (escrowedToken !== spentToken) throw new _ocap_util_lib_error.CustomError("INVALID_ORIGIN_ESCROW_PROOF", `Escrowed token (${escrowedToken}) does not match order maxSpent token (${spentToken})`);
181
+ const escrowedAmountBn = parsePositiveBn(originEscrowProof.escrowedAmount, "originEscrowProof.escrowedAmount");
182
+ if (escrowedAmountBn.lt(maxSpentAmountBn)) throw new _ocap_util_lib_error.CustomError("INSUFFICIENT_ORIGIN_ESCROW", `Origin escrowed amount (${escrowedAmountBn.toString(10)}) is less than order maxSpent (${maxSpentAmountBn.toString(10)})`);
183
+ const requiredConfirmations = Math.max(this.config.minOriginConfirmations, originEscrowProof.minRequiredConfirmations ?? 0);
184
+ if (typeof originEscrowProof.confirmations !== "number" || !Number.isSafeInteger(originEscrowProof.confirmations) || originEscrowProof.confirmations < requiredConfirmations) throw new _ocap_util_lib_error.CustomError("INSUFFICIENT_ORIGIN_CONFIRMATIONS", `Origin escrow has ${originEscrowProof.confirmations} confirmations (minimum required: ${requiredConfirmations})`);
185
+ let activeUserIntents = 0;
186
+ for (const rec of this.intents.values()) if (rec.user === user && rec.status === "PENDING") activeUserIntents += 1;
187
+ if (activeUserIntents >= this.config.maxActiveIntentsPerUser) throw new _ocap_util_lib_error.CustomError("USER_ACTIVE_INTENT_LIMIT_EXCEEDED", `User ${user} already has ${activeUserIntents} active PENDING intents (max allowed: ${this.config.maxActiveIntentsPerUser})`);
188
+ if (typeof params.currentHeight !== "number" || !Number.isSafeInteger(params.currentHeight) || params.currentHeight <= 0) throw new _ocap_util_lib_error.CustomError("INVALID_ERC7683_ORDER", "currentHeight must be a positive safe integer");
189
+ const timeoutBlocks = params.timeoutBlocks ?? this.config.maxTimeoutBlocks;
190
+ if (typeof timeoutBlocks !== "number" || !Number.isSafeInteger(timeoutBlocks) || timeoutBlocks <= 0 || timeoutBlocks > this.config.maxTimeoutBlocks) throw new _ocap_util_lib_error.CustomError("INTENT_TIMEOUT_TOO_LONG", `Intent timeoutBlocks (${timeoutBlocks}) must be between 1 and ${this.config.maxTimeoutBlocks} blocks`);
191
+ const timeoutHeight = params.currentHeight + timeoutBlocks;
192
+ const maxCapBn = new _ocap_util.BN(this.config.maxEpochNetInflowCap, 10);
193
+ const projectedInflowBn = this.currentEpochNetInflow.add(destAmountBn);
194
+ if (projectedInflowBn.gt(maxCapBn)) throw new _ocap_util_lib_error.CustomError("CANARY_WATERMARK_EXCEEDED", `Cross-chain intent fill (${destAmountBn.toString(10)}) would push epoch net inflow (${projectedInflowBn.toString(10)}) above Canary watermark cap (${maxCapBn.toString(10)})`);
195
+ const primarySelection = selectSolverSubVaultShard(orderId, this.config.solverSubVaultShards);
196
+ let selectedShardAddress = primarySelection.shardAddress;
197
+ const shardCount = this.config.solverSubVaultShards.length;
198
+ for (let offset = 0; offset < shardCount; offset++) {
199
+ const candidateIdx = (primarySelection.shardIndex + offset) % shardCount;
200
+ const candidateAddr = this.config.solverSubVaultShards[candidateIdx];
201
+ if (new _ocap_util.BN((await statedb?.account?.get?.(candidateAddr))?.tokens?.[destToken] || "0", 10).gte(destAmountBn)) {
202
+ selectedShardAddress = candidateAddr;
203
+ break;
204
+ }
205
+ }
206
+ const pendingTransfer = await this.ledger.createPendingTransfer({
207
+ id: orderId,
208
+ debitAddress: selectedShardAddress,
209
+ creditAddress: destRecipient,
210
+ tokenAddress: destToken,
211
+ amount: destAmountBn.toString(10),
212
+ currentHeight: params.currentHeight,
213
+ timeoutHeight
214
+ }, statedb);
215
+ this.usedOriginEscrowTxs.add(scopedEscrowKey);
216
+ this.currentEpochNetInflow = projectedInflowBn;
217
+ const intent = {
218
+ orderId,
219
+ user,
220
+ fillerDid: this.config.fillerDid,
221
+ shardAddress: selectedShardAddress,
222
+ destinationRecipient: destRecipient,
223
+ destinationToken: destToken,
224
+ destinationAmount: destAmountBn.toString(10),
225
+ originChainId: order.originChainId,
226
+ originEscrowTxHash: normalizedEscrowTx,
227
+ createdAtHeight: params.currentHeight,
228
+ timeoutHeight,
229
+ executionMode: this.config.executionMode,
230
+ solverSpreadBps,
231
+ status: "PENDING"
232
+ };
233
+ this.intents.set(orderId, intent);
234
+ return {
235
+ intent: { ...intent },
236
+ pendingTransfer
237
+ };
238
+ }
239
+ /**
240
+ * Phase 2A (`POST / SETTLE`):
241
+ * Verifies `#1169` cross-chain Rollup settlement evidence and posts the `PENDING` transfer
242
+ * from the Solver sub-vault shard to the destination recipient.
243
+ */
244
+ async settleIntentFill(params, statedb) {
245
+ if (!params || typeof params !== "object" || !params.settlementProof) throw new _ocap_util_lib_error.CustomError("INVALID_SETTLEMENT_PROOF", "Missing CrossChainSettlementProof");
246
+ const { settlementProof, currentHeight } = params;
247
+ if (typeof currentHeight !== "number" || !Number.isSafeInteger(currentHeight) || currentHeight <= 0) throw new _ocap_util_lib_error.CustomError("INVALID_SETTLEMENT_PROOF", "currentHeight must be a positive safe integer");
248
+ const orderId = assertSafeId(settlementProof.orderId, "settlementProof.orderId");
249
+ const intent = this.intents.get(orderId);
250
+ if (!intent) throw new _ocap_util_lib_error.CustomError("NOT_FOUND", `ERC-7683 intent ${orderId} not found`);
251
+ if (intent.status !== "PENDING") throw new _ocap_util_lib_error.CustomError("INVALID_INTENT_STATE", `ERC-7683 intent ${orderId} is already ${intent.status}`);
252
+ if (currentHeight > intent.timeoutHeight) throw new _ocap_util_lib_error.CustomError("EXPIRED_ERC7683_INTENT", `ERC-7683 intent ${orderId} expired at height ${intent.timeoutHeight} (currentHeight: ${currentHeight})`);
253
+ if (settlementProof.rollupVerified !== true) throw new _ocap_util_lib_error.CustomError("UNVERIFIED_ROLLUP_EVIDENCE", `Settlement proof for order ${orderId} is not verified by #1169 Rollup Validator consensus`);
254
+ if (typeof settlementProof.evidenceHash !== "string" || !BYTES32_HEX_REGEX.test(settlementProof.evidenceHash)) throw new _ocap_util_lib_error.CustomError("INVALID_SETTLEMENT_PROOF", "evidenceHash must be a 32-byte 0x hex string");
255
+ const normalizedEvidence = settlementProof.evidenceHash.toLowerCase();
256
+ if (this.usedSettlementEvidences.has(normalizedEvidence)) throw new _ocap_util_lib_error.CustomError("REPLAYED_SETTLEMENT_EVIDENCE", `Evidence ${normalizedEvidence} has already been consumed`);
257
+ if (typeof settlementProof.destinationFillTxHash !== "string" || !BYTES32_HEX_REGEX.test(settlementProof.destinationFillTxHash)) throw new _ocap_util_lib_error.CustomError("INVALID_SETTLEMENT_PROOF", "destinationFillTxHash must be a 32-byte 0x hex string");
258
+ const normalizedDestFillTx = settlementProof.destinationFillTxHash.toLowerCase();
259
+ if (this.usedDestinationFillTxs.has(normalizedDestFillTx)) throw new _ocap_util_lib_error.CustomError("REPLAYED_DESTINATION_FILL_TX", `destinationFillTxHash ${normalizedDestFillTx} has already been consumed`);
260
+ if (typeof settlementProof.originEscrowTxHash !== "string" || settlementProof.originEscrowTxHash.toLowerCase() !== intent.originEscrowTxHash) throw new _ocap_util_lib_error.CustomError("INVALID_SETTLEMENT_PROOF", "settlementProof.originEscrowTxHash does not match intent originEscrowTxHash");
261
+ const settledRecipient = require_ofac_screening.normalizeScreeningAddress(assertSafeId(settlementProof.settledRecipient, "settlementProof.settledRecipient"));
262
+ const settledToken = require_ofac_screening.normalizeScreeningAddress(assertSafeId(settlementProof.settledToken, "settlementProof.settledToken"));
263
+ const settledAmountBn = parsePositiveBn(settlementProof.settledAmount, "settlementProof.settledAmount");
264
+ if (settledRecipient !== intent.destinationRecipient || settledToken !== intent.destinationToken) throw new _ocap_util_lib_error.CustomError("INVALID_SETTLEMENT_PROOF", "Settlement recipient or token does not match prepared intent");
265
+ if (settledAmountBn.lt(new _ocap_util.BN(intent.destinationAmount, 10))) throw new _ocap_util_lib_error.CustomError("INSUFFICIENT_SETTLEMENT_AMOUNT", `Settled amount (${settledAmountBn.toString(10)}) is less than guaranteed destinationAmount (${intent.destinationAmount})`);
266
+ const postedTransfer = await this.ledger.postPendingTransfer({
267
+ id: orderId,
268
+ currentHeight
269
+ }, statedb);
270
+ this.usedSettlementEvidences.add(normalizedEvidence);
271
+ this.usedDestinationFillTxs.add(normalizedDestFillTx);
272
+ intent.status = "POSTED";
273
+ intent.settlementEvidenceHash = normalizedEvidence;
274
+ return {
275
+ intent: { ...intent },
276
+ postedTransfer
277
+ };
278
+ }
279
+ /**
280
+ * Phase 2B (`VOID / PAGINATED ROLLBACK SWEEP`):
281
+ * Sweeps up to `maxBatchSize` expired `PENDING` intents (`currentHeight > intent.timeoutHeight`),
282
+ * returning locked `pendingTokens` back to the Solver sub-vault shard's available `tokens`
283
+ * and releasing the reserved Canary net-inflow quota.
284
+ */
285
+ async sweepExpiredIntents(params, statedb) {
286
+ if (!params || typeof params.currentHeight !== "number" || !Number.isSafeInteger(params.currentHeight) || params.currentHeight <= 0) throw new _ocap_util_lib_error.CustomError("INVALID_ERC7683_SOLVER", "currentHeight must be a positive safe integer");
287
+ const batchCap = Math.min(params.maxBatchSize ?? this.config.maxSweepBatchSize, this.config.maxSweepBatchSize);
288
+ if (!Number.isSafeInteger(batchCap) || batchCap <= 0) throw new _ocap_util_lib_error.CustomError("INVALID_ERC7683_SOLVER", "maxBatchSize must be a positive integer");
289
+ const expiredIntents = [];
290
+ for (const intent of this.intents.values()) if (intent.status === "PENDING" && params.currentHeight > intent.timeoutHeight) expiredIntents.push(intent);
291
+ const toSweep = expiredIntents.slice(0, batchCap);
292
+ const sweptOrderIds = [];
293
+ const failedOrderIds = [];
294
+ for (const intent of toSweep) try {
295
+ await this.ledger.voidPendingTransfer({ id: intent.orderId }, statedb);
296
+ intent.status = "VOIDED";
297
+ const amtBn = parseNonNegativeBn(intent.destinationAmount, "destinationAmount");
298
+ this.currentEpochNetInflow = this.currentEpochNetInflow.gt(amtBn) ? this.currentEpochNetInflow.sub(amtBn) : new _ocap_util.BN(0);
299
+ sweptOrderIds.push(intent.orderId);
300
+ } catch {
301
+ failedOrderIds.push(intent.orderId);
302
+ }
303
+ return {
304
+ sweptOrderIds,
305
+ failedOrderIds,
306
+ remainingExpiredCount: Math.max(0, expiredIntents.length - sweptOrderIds.length - failedOrderIds.length)
307
+ };
308
+ }
309
+ getIntent(orderId) {
310
+ const rec = this.intents.get(orderId);
311
+ return rec ? { ...rec } : void 0;
312
+ }
313
+ getCurrentEpochNetInflow() {
314
+ return this.currentEpochNetInflow.toString(10);
315
+ }
316
+ resetEpochNetInflow() {
317
+ this.currentEpochNetInflow = new _ocap_util.BN(0);
318
+ }
319
+ };
320
+
321
+ //#endregion
322
+ exports.DEFAULT_MAX_SWEEP_BATCH_SIZE = DEFAULT_MAX_SWEEP_BATCH_SIZE;
323
+ exports.MAX_ACTIVE_INTENTS_PER_USER = MAX_ACTIVE_INTENTS_PER_USER;
324
+ exports.MAX_INTENT_TIMEOUT_BLOCKS = MAX_INTENT_TIMEOUT_BLOCKS;
325
+ exports.MIN_RECOMMENDED_SOLVER_SHARDS = MIN_RECOMMENDED_SOLVER_SHARDS;
326
+ exports.OcapErc7683SolverEngine = OcapErc7683SolverEngine;
327
+ exports.selectSolverSubVaultShard = selectSolverSubVaultShard;
@@ -0,0 +1,201 @@
1
+ import { PendingTransferRecord, TwoPhaseTransferLedger } from "./transaction-block.cjs";
2
+
3
+ //#region src/uniswap-erc7683-solver.d.ts
4
+
5
+ /**
6
+ * Maximum number of OCAP blocks an ERC-7683 intent can lock Solver sub-vault funds (`<= 30` blocks).
7
+ */
8
+ declare const MAX_INTENT_TIMEOUT_BLOCKS = 30;
9
+ /**
10
+ * Maximum concurrent `PENDING` intents allowed per user address to prevent Solver liquidity exhaustion.
11
+ */
12
+ declare const MAX_ACTIVE_INTENTS_PER_USER = 3;
13
+ /**
14
+ * Default maximum number of expired intents swept per block (`<= 50`) to bound per-block GC gas/latency.
15
+ */
16
+ declare const DEFAULT_MAX_SWEEP_BATCH_SIZE = 50;
17
+ /**
18
+ * Minimum recommended Solver sub-vault shards for parallel Sealevel / 2PC execution.
19
+ */
20
+ declare const MIN_RECOMMENDED_SOLVER_SHARDS = 16;
21
+ /**
22
+ * Standard ERC-7683 Output specification (`maxSpent` / `minReceived` item).
23
+ */
24
+ interface Erc7683Output {
25
+ token: string;
26
+ amount: string;
27
+ recipient: string;
28
+ chainId: number;
29
+ }
30
+ /**
31
+ * Standard ERC-7683 FillInstruction item.
32
+ */
33
+ interface Erc7683FillInstruction {
34
+ destinationChainId: number;
35
+ destinationSettler: string;
36
+ originData: string;
37
+ }
38
+ /**
39
+ * Standard ERC-7683 `ResolvedCrossChainOrder` structure mapped between EVM (UniswapX / Base / Arbitrum)
40
+ * and OCAP (`TwoPhaseTransferLedger` + `#1169` Rollup Evidence).
41
+ */
42
+ interface Erc7683ResolvedCrossChainOrder {
43
+ orderId: string;
44
+ user: string;
45
+ originChainId: number;
46
+ openDeadline: number;
47
+ fillDeadline: number;
48
+ maxSpent: Erc7683Output[];
49
+ minReceived: Erc7683Output[];
50
+ fillInstructions: Erc7683FillInstruction[];
51
+ }
52
+ /**
53
+ * Proof that the user has already escrowed input tokens on the origin chain (`Permit2` / `InputSettler`)
54
+ * before the OCAP Solver locks destination sub-vault liquidity ("Source-Escrow First" anti-griefing rule).
55
+ */
56
+ interface OriginEscrowProof {
57
+ originChainId: number;
58
+ sourceEscrowTxHash: string;
59
+ escrowContractAddress: string;
60
+ escrowedToken: string;
61
+ escrowedAmount: string;
62
+ escrowRecipient?: string;
63
+ confirmations: number;
64
+ minRequiredConfirmations?: number;
65
+ }
66
+ /**
67
+ * Cryptographic settlement proof (`#1169` Rollup Evidence / Destination Settler Receipt)
68
+ * required to finalize (`POST`) a `PENDING` ERC-7683 transfer.
69
+ */
70
+ interface CrossChainSettlementProof {
71
+ orderId: string;
72
+ evidenceHash: string;
73
+ originEscrowTxHash: string;
74
+ destinationFillTxHash: string;
75
+ settledAmount: string;
76
+ settledRecipient: string;
77
+ settledToken: string;
78
+ rollupVerified: boolean;
79
+ }
80
+ type SolverExecutionMode = 'AGENCY_PASS_THROUGH' | 'EXTERNAL_THIRD_PARTY_FILLER';
81
+ interface SolverEngineConfig {
82
+ /** Open permissionless filler DID operating this Solver instance */
83
+ fillerDid: string;
84
+ /** Sharded sub-vault account addresses to eliminate 2PC single-account lock contention */
85
+ solverSubVaultShards: string[];
86
+ /** Execution mode: 'AGENCY_PASS_THROUGH' enforces 0 bps proprietary spread for ABT utility routing */
87
+ executionMode: SolverExecutionMode;
88
+ /** Optional ABT token address to strictly enforce AGENCY_PASS_THROUGH zero-spread rules */
89
+ abtTokenAddress?: string;
90
+ /** Maximum blocks an intent can stay PENDING before expiring (`<= 30`) */
91
+ maxTimeoutBlocks?: number;
92
+ /** Maximum concurrent PENDING intents per user (`<= 3`) */
93
+ maxActiveIntentsPerUser?: number;
94
+ /** Maximum intents swept per block in `sweepExpiredIntents` (`<= 50`) */
95
+ maxSweepBatchSize?: number;
96
+ /** `#1169` Canary net-inflow cap per epoch in base units */
97
+ maxEpochNetInflowCap: string;
98
+ /** Minimum origin-chain confirmations before locking Solver liquidity */
99
+ minOriginConfirmations?: number;
100
+ ofacBlocklist?: Iterable<string>;
101
+ }
102
+ interface ManagedIntentRecord {
103
+ orderId: string;
104
+ user: string;
105
+ fillerDid: string;
106
+ shardAddress: string;
107
+ destinationRecipient: string;
108
+ destinationToken: string;
109
+ destinationAmount: string;
110
+ originChainId: number;
111
+ originEscrowTxHash: string;
112
+ createdAtHeight: number;
113
+ timeoutHeight: number;
114
+ executionMode: SolverExecutionMode;
115
+ solverSpreadBps: number;
116
+ status: 'PENDING' | 'POSTED' | 'VOIDED';
117
+ settlementEvidenceHash?: string;
118
+ }
119
+ /**
120
+ * Deterministically selects a Solver sub-vault shard (`0 .. shards.length - 1`) for an `orderId`
121
+ * so concurrent ERC-7683 fills touch disjoint account state keys in `OverlayStateDB` / `2PC`.
122
+ */
123
+ declare function selectSolverSubVaultShard(orderId: string, shards: string[]): {
124
+ shardIndex: number;
125
+ shardAddress: string;
126
+ };
127
+ /**
128
+ * Non-Custodial UniswapX / ERC-7683 Cross-Chain Intent Solver Engine (`OcapErc7683SolverEngine`).
129
+ *
130
+ * Security, Anti-Vampire & Regulatory Guarantees:
131
+ * 1. **Sharded Solver Vaults**: Routes intents across independent sub-vault shards to eliminate
132
+ * single-vault `LOCK_CONFLICT` bottlenecks during parallel block execution.
133
+ * 2. **Source-Escrow First & Short Timeout Cap (`<= 30` blocks)**: Requires verified origin-chain
134
+ * escrow proof before locking destination liquidity, caps per-user active intents (`<= 3`),
135
+ * and provides paginated `sweepExpiredIntents` rollback (`VOID`).
136
+ * 3. **Canary Net-Inflow Circuit Breaker**: Enforces `#1169` epoch net-inflow watermark limits.
137
+ * 4. **SEC Section 15(a)(2) Dealer Rule & FinCEN Safe Harbor**: Supports open permissionless external
138
+ * fillers and enforces `0 bps` proprietary spread in `AGENCY_PASS_THROUGH` mode (especially for `ABT`).
139
+ */
140
+ declare class OcapErc7683SolverEngine {
141
+ readonly config: Required<Pick<SolverEngineConfig, 'fillerDid' | 'solverSubVaultShards' | 'executionMode' | 'maxTimeoutBlocks' | 'maxActiveIntentsPerUser' | 'maxSweepBatchSize' | 'maxEpochNetInflowCap' | 'minOriginConfirmations'>> & {
142
+ abtTokenAddress?: string;
143
+ };
144
+ private readonly ledger;
145
+ private readonly intents;
146
+ private readonly usedOriginEscrowTxs;
147
+ private readonly usedSettlementEvidences;
148
+ private readonly usedDestinationFillTxs;
149
+ private readonly ofacSet;
150
+ private currentEpochNetInflow;
151
+ constructor(config: SolverEngineConfig, ledger?: TwoPhaseTransferLedger);
152
+ /**
153
+ * Phase 1 (`PREPARE / PENDING`):
154
+ * Validates an ERC-7683 `ResolvedCrossChainOrder` and its origin-chain escrow proof, checks OFAC,
155
+ * SEC Dealer / Agency pass-through rules, per-user active intent quota, and Canary net-inflow cap,
156
+ * then locks destination funds in the selected Solver sub-vault shard via `TwoPhaseTransferLedger`.
157
+ */
158
+ prepareIntentFill(params: {
159
+ order: Erc7683ResolvedCrossChainOrder;
160
+ originEscrowProof: OriginEscrowProof;
161
+ currentHeight: number;
162
+ timeoutBlocks?: number;
163
+ currentUnixTimestamp?: number;
164
+ solverSpreadBps?: number;
165
+ ofacBlocklist?: Iterable<string>;
166
+ }, statedb: Record<string, any>): Promise<{
167
+ intent: ManagedIntentRecord;
168
+ pendingTransfer: PendingTransferRecord;
169
+ }>;
170
+ /**
171
+ * Phase 2A (`POST / SETTLE`):
172
+ * Verifies `#1169` cross-chain Rollup settlement evidence and posts the `PENDING` transfer
173
+ * from the Solver sub-vault shard to the destination recipient.
174
+ */
175
+ settleIntentFill(params: {
176
+ settlementProof: CrossChainSettlementProof;
177
+ currentHeight: number;
178
+ }, statedb: Record<string, any>): Promise<{
179
+ intent: ManagedIntentRecord;
180
+ postedTransfer: PendingTransferRecord;
181
+ }>;
182
+ /**
183
+ * Phase 2B (`VOID / PAGINATED ROLLBACK SWEEP`):
184
+ * Sweeps up to `maxBatchSize` expired `PENDING` intents (`currentHeight > intent.timeoutHeight`),
185
+ * returning locked `pendingTokens` back to the Solver sub-vault shard's available `tokens`
186
+ * and releasing the reserved Canary net-inflow quota.
187
+ */
188
+ sweepExpiredIntents(params: {
189
+ currentHeight: number;
190
+ maxBatchSize?: number;
191
+ }, statedb: Record<string, any>): Promise<{
192
+ sweptOrderIds: string[];
193
+ failedOrderIds: string[];
194
+ remainingExpiredCount: number;
195
+ }>;
196
+ getIntent(orderId: string): ManagedIntentRecord | undefined;
197
+ getCurrentEpochNetInflow(): string;
198
+ resetEpochNetInflow(): void;
199
+ }
200
+ //#endregion
201
+ export { CrossChainSettlementProof, DEFAULT_MAX_SWEEP_BATCH_SIZE, Erc7683FillInstruction, Erc7683Output, Erc7683ResolvedCrossChainOrder, MAX_ACTIVE_INTENTS_PER_USER, MAX_INTENT_TIMEOUT_BLOCKS, MIN_RECOMMENDED_SOLVER_SHARDS, ManagedIntentRecord, OcapErc7683SolverEngine, OriginEscrowProof, SolverEngineConfig, SolverExecutionMode, selectSolverSubVaultShard };