@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,320 @@
1
+ import { assertNotOfacSanctioned, normalizeScreeningAddress } from "./ofac-screening.mjs";
2
+ import "./uniswap-router.mjs";
3
+ import { CONTRACT_NFT_KIND, executeContractNft } from "./transaction-block.mjs";
4
+ import { Hasher } from "@ocap/mcrypto";
5
+ import { BN } from "@ocap/util";
6
+ import { CustomError } from "@ocap/util/lib/error";
7
+
8
+ //#region src/uniswap-lp-copilot.ts
9
+ /**
10
+ * Uniswap V3 / V4 absolute tick bounds.
11
+ */
12
+ const MIN_UNISWAP_TICK = -887272;
13
+ const MAX_UNISWAP_TICK = 887272;
14
+ /**
15
+ * Maximum allowed LP rebalance slippage in basis points (1.00% = 100 bps).
16
+ */
17
+ const MAX_LP_REBALANCE_SLIPPAGE_BPS = 100;
18
+ /**
19
+ * Default minimum cooldown blocks between automated LP rebalances to prevent rebalance storms.
20
+ */
21
+ const DEFAULT_LP_REBALANCE_COOLDOWN_BLOCKS = 20;
22
+ /**
23
+ * Default deterministic jitter window (in blocks) to spread multi-agent rebalances across blocks.
24
+ */
25
+ const DEFAULT_LP_JITTER_WINDOW_BLOCKS = 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 assertSafeIdentifier(val, label) {
34
+ if (typeof val !== "string") throw new CustomError("INVALID_LP_COPILOT", `${label} must be a non-empty string`);
35
+ const trimmed = val.trim();
36
+ if (!trimmed || FORBIDDEN_KEYS.has(trimmed)) throw new CustomError("INVALID_LP_COPILOT", `Unsafe or empty ${label}`);
37
+ return trimmed;
38
+ }
39
+ function parsePositiveBn(val, label) {
40
+ if (typeof val !== "string" || !CANONICAL_UINT_REGEX.test(val)) throw new CustomError("INVALID_LP_COPILOT", `${label} must be a canonical non-negative integer string`);
41
+ const bn = new BN(val, 10);
42
+ if (bn.lte(new BN(0))) throw new CustomError("INVALID_LP_COPILOT", `${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 CustomError("INVALID_LP_COPILOT", `${label} must be a canonical non-negative integer string`);
47
+ return new BN(val, 10);
48
+ }
49
+ /**
50
+ * Computes a deterministic block slot offset `[0, jitterWindowBlocks - 1]` for a given
51
+ * `contractNftAddress` and volatility epoch so thousands of AIGNE LP Copilots never fire
52
+ * in the exact same block during market spikes (Thundering Herd / Self-DDoS mitigation).
53
+ */
54
+ function computeDeterministicRebalanceSlot(contractNftAddress, epoch, jitterWindowBlocks = DEFAULT_LP_JITTER_WINDOW_BLOCKS) {
55
+ const safeAddr = assertSafeIdentifier(contractNftAddress, "contractNftAddress");
56
+ if (!Number.isSafeInteger(epoch) || epoch < 0) throw new CustomError("INVALID_LP_COPILOT", "epoch must be a non-negative integer");
57
+ if (!Number.isSafeInteger(jitterWindowBlocks) || jitterWindowBlocks <= 0 || jitterWindowBlocks > 1024) throw new CustomError("INVALID_LP_COPILOT", "jitterWindowBlocks must be an integer between 1 and 1024");
58
+ const digest = Hasher.SHA3.hash256(Buffer.from(`${safeAddr}:${epoch}`, "utf8")).replace(/^0x/, "");
59
+ return Number.parseInt(digest.slice(0, 8), 16) % jitterWindowBlocks;
60
+ }
61
+ /**
62
+ * Builds a 100% Non-Custodial `ContractNFT` asset with deterministic on-chain guardrails
63
+ * for managing a single user's Uniswap V3/V4 concentrated liquidity position.
64
+ *
65
+ * Legal & Security Invariants:
66
+ * 1. Strictly prohibits pooled / commingled multi-user funds (`commingledPool: false`, single `ownerDid`).
67
+ * 2. Strictly prohibits `% AUM` management fees, `% Performance` fees, and `% Swap` commissions.
68
+ * 3. Encodes hard declarative guards for `allowedPoolIds`, `maxSlippageBps`, `minTickWidth`,
69
+ * `maxTwapTickDeviation`, `minCooldownBlocks`, and post-rebalance NAV conservation.
70
+ */
71
+ function buildNonCustodialLpContractNft(spec) {
72
+ if (!spec || typeof spec !== "object") throw new CustomError("INVALID_LP_COPILOT", "Missing NonCustodialLpGuardSpec");
73
+ if (spec.commingledPool === true) throw new CustomError("ILLEGAL_COMMINGLED_VAULT", "Pooled or commingled multi-investor LP vaults are strictly prohibited (1940 Investment Company Act Safe Harbor)");
74
+ const contractNftAddress = assertSafeIdentifier(spec.contractNftAddress, "contractNftAddress");
75
+ const ownerDid = normalizeScreeningAddress(assertSafeIdentifier(spec.ownerDid, "ownerDid"));
76
+ const copilotAgentDid = normalizeScreeningAddress(assertSafeIdentifier(spec.copilotAgentDid, "copilotAgentDid"));
77
+ const abtTokenAddress = assertSafeIdentifier(spec.abtTokenAddress, "abtTokenAddress");
78
+ const computeFeeRecipientDid = normalizeScreeningAddress(assertSafeIdentifier(spec.computeFeeRecipientDid, "computeFeeRecipientDid"));
79
+ if (Array.isArray(spec.beneficiaryDids)) {
80
+ if (spec.beneficiaryDids.length === 0 || spec.beneficiaryDids.length > 1) throw new CustomError("ILLEGAL_COMMINGLED_VAULT", "Non-custodial LP ContractNFT can only have a single beneficiary equal to ownerDid");
81
+ const singleBeneficiary = normalizeScreeningAddress(assertSafeIdentifier(spec.beneficiaryDids[0], "beneficiaryDid"));
82
+ if (singleBeneficiary !== ownerDid) throw new CustomError("ILLEGAL_COMMINGLED_VAULT", `beneficiaryDid (${singleBeneficiary}) must match ownerDid (${ownerDid})`);
83
+ }
84
+ if (spec.managementFeeBps !== void 0 && spec.managementFeeBps !== 0 || spec.performanceFeeBps !== void 0 && spec.performanceFeeBps !== 0 || spec.swapCommissionBps !== void 0 && spec.swapCommissionBps !== 0) throw new CustomError("ILLEGAL_ADVISORY_FEE_STRUCTURE", "Percentage management fees, performance fees, and swap brokerage commissions are strictly prohibited; use fixed SaaS / AIGNE ABT compute credits only");
85
+ assertNotOfacSanctioned([
86
+ contractNftAddress,
87
+ ownerDid,
88
+ copilotAgentDid,
89
+ abtTokenAddress,
90
+ computeFeeRecipientDid
91
+ ], spec.ofacBlocklist);
92
+ if (!Array.isArray(spec.allowedPoolIds) || spec.allowedPoolIds.length === 0 || spec.allowedPoolIds.length > 16) throw new CustomError("INVALID_LP_COPILOT", "allowedPoolIds must contain between 1 and 16 32-byte Pool IDs");
93
+ const normalizedPools = spec.allowedPoolIds.map((pid, idx) => {
94
+ if (typeof pid !== "string" || !BYTES32_HEX_REGEX.test(pid)) throw new CustomError("INVALID_LP_COPILOT", `allowedPoolIds[${idx}] must be a 32-byte 0x hex string`);
95
+ return pid.toLowerCase();
96
+ });
97
+ if (typeof spec.maxSlippageBps !== "number" || !Number.isSafeInteger(spec.maxSlippageBps) || spec.maxSlippageBps <= 0 || spec.maxSlippageBps > MAX_LP_REBALANCE_SLIPPAGE_BPS) throw new CustomError("INVALID_LP_COPILOT", `maxSlippageBps must be an integer between 1 and ${MAX_LP_REBALANCE_SLIPPAGE_BPS}`);
98
+ if (typeof spec.minTickWidth !== "number" || !Number.isSafeInteger(spec.minTickWidth) || spec.minTickWidth <= 0 || spec.minTickWidth > MAX_UNISWAP_TICK - MIN_UNISWAP_TICK) throw new CustomError("INVALID_LP_COPILOT", "minTickWidth must be a positive integer within Uniswap tick bounds");
99
+ if (typeof spec.maxTwapTickDeviation !== "number" || !Number.isSafeInteger(spec.maxTwapTickDeviation) || spec.maxTwapTickDeviation <= 0 || spec.maxTwapTickDeviation > MAX_UNISWAP_TICK - MIN_UNISWAP_TICK) throw new CustomError("INVALID_LP_COPILOT", "maxTwapTickDeviation must be a positive integer within Uniswap tick bounds");
100
+ const minCooldownBlocks = spec.minCooldownBlocks ?? DEFAULT_LP_REBALANCE_COOLDOWN_BLOCKS;
101
+ if (typeof minCooldownBlocks !== "number" || !Number.isSafeInteger(minCooldownBlocks) || minCooldownBlocks <= 0) throw new CustomError("INVALID_LP_COPILOT", "minCooldownBlocks must be a positive integer");
102
+ const fixedAbtComputeFeeBn = parseNonNegativeBn(spec.fixedAbtComputeFee, "fixedAbtComputeFee");
103
+ const statementTemplates = [{
104
+ type: "uniswap_v4_rebalance_position",
105
+ typeUrl: "fg:t:uniswap_v4_rebalance_position",
106
+ from: ownerDid,
107
+ itx: {
108
+ owner: ownerDid,
109
+ contractNft: contractNftAddress,
110
+ poolId: "$args.poolId",
111
+ positionId: "$args.positionId",
112
+ newTickLower: "$args.newTickLower",
113
+ newTickUpper: "$args.newTickUpper",
114
+ preRebalanceNavUsd: "$args.preRebalanceNavUsd",
115
+ postRebalanceNavUsd: "$args.postRebalanceNavUsd",
116
+ blockHeight: "$args.currentBlockHeight"
117
+ }
118
+ }];
119
+ if (fixedAbtComputeFeeBn.gt(new BN(0))) statementTemplates.push({
120
+ type: "transfer_v3",
121
+ typeUrl: "fg:t:transfer_v3",
122
+ from: ownerDid,
123
+ itx: {
124
+ to: computeFeeRecipientDid,
125
+ tokens: [{
126
+ address: abtTokenAddress,
127
+ value: fixedAbtComputeFeeBn.toString(10)
128
+ }],
129
+ data: {
130
+ type: "json",
131
+ value: JSON.stringify({
132
+ consumptiveUse: true,
133
+ serviceType: "aigne_lp_copilot_compute_fee",
134
+ contractNft: contractNftAddress
135
+ })
136
+ }
137
+ }
138
+ });
139
+ return {
140
+ address: contractNftAddress,
141
+ owner: ownerDid,
142
+ data: {
143
+ type: "json",
144
+ value: {
145
+ kind: CONTRACT_NFT_KIND,
146
+ name: "AIGNE Non-Custodial Uniswap V4 LP Copilot Guard",
147
+ version: "1.0.0",
148
+ allowedCallers: Array.from(new Set([ownerDid, copilotAgentDid])),
149
+ guards: [
150
+ {
151
+ field: "args.poolId",
152
+ op: "in",
153
+ value: normalizedPools
154
+ },
155
+ {
156
+ field: "args.slippageBps",
157
+ op: "lte",
158
+ value: spec.maxSlippageBps
159
+ },
160
+ {
161
+ field: "args.newTickWidth",
162
+ op: "gte",
163
+ value: spec.minTickWidth
164
+ },
165
+ {
166
+ field: "args.twapTickDeviation",
167
+ op: "lte",
168
+ value: spec.maxTwapTickDeviation
169
+ },
170
+ {
171
+ field: "args.cooldownElapsedBlocks",
172
+ op: "gte",
173
+ value: minCooldownBlocks
174
+ }
175
+ ],
176
+ statementTemplates
177
+ }
178
+ },
179
+ guardSpec: {
180
+ ...spec,
181
+ contractNftAddress,
182
+ ownerDid,
183
+ copilotAgentDid,
184
+ allowedPoolIds: normalizedPools,
185
+ minCooldownBlocks,
186
+ fixedAbtComputeFee: fixedAbtComputeFeeBn.toString(10),
187
+ abtTokenAddress,
188
+ computeFeeRecipientDid,
189
+ commingledPool: false,
190
+ managementFeeBps: 0,
191
+ performanceFeeBps: 0,
192
+ swapCommissionBps: 0
193
+ }
194
+ };
195
+ }
196
+ /**
197
+ * Validates and executes a non-custodial LP rebalance proposal through the user's personal `ContractNFT`:
198
+ * 1. Verifies OFAC sanctions screening.
199
+ * 2. Enforces `minCooldownBlocks` and optional deterministic jitter slot to prevent automated rebalance storms.
200
+ * 3. Trips the Volatility Circuit Breaker if `|spotTick - twapTick| > maxTwapTickDeviation`.
201
+ * 4. Enforces post-condition NAV conservation (`postRebalanceNavUsd >= minRequiredPostNavUsd`).
202
+ * 5. Runs a mandatory pre-flight `dryRun: true` check on the overlay before committing.
203
+ */
204
+ async function executeNonCustodialLpRebalance(input) {
205
+ if (!input || typeof input !== "object" || !input.contractNft) throw new CustomError("INVALID_LP_COPILOT", "Missing LpRebalanceProposalInput");
206
+ const { contractNft } = input;
207
+ const spec = contractNft.guardSpec;
208
+ if (!spec) throw new CustomError("INVALID_LP_COPILOT", "ContractNFT is missing NonCustodialLpGuardSpec");
209
+ const canonicalNft = buildNonCustodialLpContractNft(spec);
210
+ if (contractNft.address !== canonicalNft.address || normalizeScreeningAddress(assertSafeIdentifier(contractNft.owner, "contractNft.owner")) !== canonicalNft.owner || JSON.stringify(contractNft.data) !== JSON.stringify(canonicalNft.data)) throw new CustomError("TAMPERED_CONTRACT_NFT", "ContractNFT payload or ownership has been tampered with and does not match canonical NonCustodialLpGuardSpec");
211
+ const verifiedContractNft = {
212
+ ...canonicalNft,
213
+ consumedTime: contractNft.consumedTime
214
+ };
215
+ const verifiedSpec = canonicalNft.guardSpec;
216
+ const callerDid = normalizeScreeningAddress(assertSafeIdentifier(input.callerDid, "callerDid"));
217
+ const positionId = assertSafeIdentifier(input.positionId, "positionId");
218
+ if (typeof input.poolId !== "string" || !BYTES32_HEX_REGEX.test(input.poolId)) throw new CustomError("INVALID_LP_COPILOT", "poolId must be a 32-byte 0x hex string");
219
+ const poolId = input.poolId.toLowerCase();
220
+ const combinedOfac = /* @__PURE__ */ new Set();
221
+ if (verifiedSpec.ofacBlocklist) for (const a of verifiedSpec.ofacBlocklist) combinedOfac.add(a);
222
+ if (input.ofacBlocklist) for (const a of input.ofacBlocklist) combinedOfac.add(a);
223
+ assertNotOfacSanctioned([
224
+ callerDid,
225
+ verifiedContractNft.owner,
226
+ verifiedContractNft.address,
227
+ verifiedSpec.copilotAgentDid,
228
+ verifiedSpec.abtTokenAddress,
229
+ verifiedSpec.computeFeeRecipientDid,
230
+ positionId
231
+ ], combinedOfac);
232
+ if (!verifiedSpec.allowedPoolIds.includes(poolId)) throw new CustomError("POOL_NOT_ALLOWLISTED", `Pool ${poolId} is not in ContractNFT allowlist`);
233
+ if (typeof input.currentBlockHeight !== "number" || !Number.isSafeInteger(input.currentBlockHeight) || input.currentBlockHeight <= 0) throw new CustomError("INVALID_LP_COPILOT", "currentBlockHeight must be a positive safe integer");
234
+ const existingPos = typeof input.statedb?.asset?.get === "function" ? await input.statedb.asset.get(positionId) : null;
235
+ if (existingPos) {
236
+ if (typeof existingPos.owner === "string" && normalizeScreeningAddress(existingPos.owner) !== verifiedContractNft.owner) throw new CustomError("FORBIDDEN", `Position ${positionId} is owned by ${existingPos.owner}, not ContractNFT owner ${verifiedContractNft.owner}`);
237
+ }
238
+ const onChainLastHeightRaw = existingPos?.updatedAtBlock ?? existingPos?.lastRebalanceHeight;
239
+ const onChainLastHeight = typeof onChainLastHeightRaw === "number" && Number.isSafeInteger(onChainLastHeightRaw) ? onChainLastHeightRaw : void 0;
240
+ if (input.lastRebalanceHeight !== void 0) {
241
+ if (typeof input.lastRebalanceHeight !== "number" || !Number.isSafeInteger(input.lastRebalanceHeight) || input.lastRebalanceHeight < 0 || input.lastRebalanceHeight > input.currentBlockHeight) throw new CustomError("INVALID_LP_COPILOT", "Invalid lastRebalanceHeight");
242
+ if (onChainLastHeight !== void 0 && input.lastRebalanceHeight < onChainLastHeight) throw new CustomError("INVALID_LP_COPILOT", `Provided lastRebalanceHeight (${input.lastRebalanceHeight}) is older than on-chain position updatedAtBlock (${onChainLastHeight})`);
243
+ }
244
+ const effectiveLastHeight = onChainLastHeight !== void 0 ? Math.max(onChainLastHeight, input.lastRebalanceHeight ?? 0) : input.lastRebalanceHeight;
245
+ const minCooldownBlocks = verifiedSpec.minCooldownBlocks ?? DEFAULT_LP_REBALANCE_COOLDOWN_BLOCKS;
246
+ let cooldownElapsedBlocks = minCooldownBlocks;
247
+ if (effectiveLastHeight !== void 0) {
248
+ if (effectiveLastHeight > input.currentBlockHeight) throw new CustomError("INVALID_LP_COPILOT", "effectiveLastHeight cannot exceed currentBlockHeight");
249
+ cooldownElapsedBlocks = input.currentBlockHeight - effectiveLastHeight;
250
+ if (cooldownElapsedBlocks < minCooldownBlocks) throw new CustomError("REBALANCE_COOLDOWN_ACTIVE", `LP rebalance cooldown active: ${cooldownElapsedBlocks} blocks elapsed since height ${effectiveLastHeight} (minimum required: ${minCooldownBlocks})`);
251
+ }
252
+ const jitterWindow = input.jitterWindowBlocks ?? DEFAULT_LP_JITTER_WINDOW_BLOCKS;
253
+ const epoch = Math.floor(input.currentBlockHeight / jitterWindow);
254
+ const jitterSlot = computeDeterministicRebalanceSlot(verifiedContractNft.address, epoch, jitterWindow);
255
+ if (input.enforceJitterSlot && input.currentBlockHeight % jitterWindow !== jitterSlot) throw new CustomError("JITTER_SLOT_MISMATCH", `Rebalance storm protection: ContractNFT ${verifiedContractNft.address} is assigned to block slot ${jitterSlot} (current slot: ${input.currentBlockHeight % jitterWindow})`);
256
+ if (typeof input.spotTick !== "number" || !Number.isSafeInteger(input.spotTick) || input.spotTick < MIN_UNISWAP_TICK || input.spotTick > MAX_UNISWAP_TICK || typeof input.twapTick !== "number" || !Number.isSafeInteger(input.twapTick) || input.twapTick < MIN_UNISWAP_TICK || input.twapTick > MAX_UNISWAP_TICK) throw new CustomError("INVALID_LP_COPILOT", `spotTick and twapTick must be valid integers within [${MIN_UNISWAP_TICK}, ${MAX_UNISWAP_TICK}]`);
257
+ const twapTickDeviation = Math.abs(input.spotTick - input.twapTick);
258
+ if (twapTickDeviation > verifiedSpec.maxTwapTickDeviation) throw new CustomError("VOLATILITY_CIRCUIT_BREAKER_TRIPPED", `Spot tick (${input.spotTick}) deviates from TWAP tick (${input.twapTick}) by ${twapTickDeviation} ticks (max allowed: ${verifiedSpec.maxTwapTickDeviation})`);
259
+ if (typeof input.newTickLower !== "number" || !Number.isSafeInteger(input.newTickLower) || typeof input.newTickUpper !== "number" || !Number.isSafeInteger(input.newTickUpper) || input.newTickLower < MIN_UNISWAP_TICK || input.newTickUpper > MAX_UNISWAP_TICK || input.newTickLower >= input.newTickUpper) throw new CustomError("INVALID_TICK_RANGE", `Invalid Uniswap tick range [${input.newTickLower}, ${input.newTickUpper}]`);
260
+ const newTickWidth = input.newTickUpper - input.newTickLower;
261
+ if (newTickWidth < verifiedSpec.minTickWidth) throw new CustomError("TICK_WIDTH_TOO_NARROW", `New tick width (${newTickWidth}) is narrower than minTickWidth (${verifiedSpec.minTickWidth})`);
262
+ const preNavBn = parsePositiveBn(input.preRebalanceNavUsd, "preRebalanceNavUsd");
263
+ const postNavBn = parsePositiveBn(input.postRebalanceNavUsd, "postRebalanceNavUsd");
264
+ const bpsDenom = new BN(1e4);
265
+ const minRequiredPostNavBn = preNavBn.mul(new BN(1e4 - verifiedSpec.maxSlippageBps)).add(new BN(9999)).div(bpsDenom);
266
+ if (postNavBn.lt(minRequiredPostNavBn)) throw new CustomError("SLIPPAGE_GUARD_VIOLATED", `Post-rebalance NAV (${postNavBn.toString(10)}) is below minimum required NAV (${minRequiredPostNavBn.toString(10)}) for maxSlippageBps=${verifiedSpec.maxSlippageBps}`);
267
+ const navLossBn = preNavBn.gt(postNavBn) ? preNavBn.sub(postNavBn) : new BN(0);
268
+ const actualSlippageBps = navLossBn.isZero() ? 0 : navLossBn.mul(bpsDenom).add(preNavBn.sub(new BN(1))).div(preNavBn).toNumber();
269
+ const contractArgs = {
270
+ poolId,
271
+ positionId,
272
+ newTickLower: input.newTickLower,
273
+ newTickUpper: input.newTickUpper,
274
+ newTickWidth,
275
+ twapTickDeviation,
276
+ cooldownElapsedBlocks,
277
+ slippageBps: actualSlippageBps,
278
+ preRebalanceNavUsd: preNavBn.toString(10),
279
+ postRebalanceNavUsd: postNavBn.toString(10),
280
+ currentBlockHeight: input.currentBlockHeight
281
+ };
282
+ if (!input.dryRun) {
283
+ const preflight = await executeContractNft({
284
+ contractAsset: verifiedContractNft,
285
+ caller: callerDid,
286
+ args: contractArgs,
287
+ statedb: input.statedb,
288
+ executeStatement: input.executeStatement,
289
+ dryRun: true
290
+ });
291
+ if (!preflight.ok) return {
292
+ ...preflight,
293
+ nextAllowedRebalanceHeight: input.currentBlockHeight,
294
+ jitterSlot
295
+ };
296
+ }
297
+ const execRes = await executeContractNft({
298
+ contractAsset: verifiedContractNft,
299
+ caller: callerDid,
300
+ args: contractArgs,
301
+ statedb: input.statedb,
302
+ executeStatement: input.executeStatement,
303
+ dryRun: input.dryRun
304
+ });
305
+ if (execRes.ok && !input.dryRun && input.positionId && typeof input.statedb?.asset?.update === "function") {
306
+ const existingPos$1 = typeof input.statedb?.asset?.get === "function" ? await input.statedb.asset.get(input.positionId) : null;
307
+ if (existingPos$1 && typeof existingPos$1 === "object") await input.statedb.asset.update(input.positionId, {
308
+ ...existingPos$1,
309
+ updatedAtBlock: input.currentBlockHeight
310
+ });
311
+ }
312
+ return {
313
+ ...execRes,
314
+ nextAllowedRebalanceHeight: execRes.ok ? input.currentBlockHeight + minCooldownBlocks : input.currentBlockHeight,
315
+ jitterSlot
316
+ };
317
+ }
318
+
319
+ //#endregion
320
+ export { DEFAULT_LP_JITTER_WINDOW_BLOCKS, DEFAULT_LP_REBALANCE_COOLDOWN_BLOCKS, MAX_LP_REBALANCE_SLIPPAGE_BPS, MAX_UNISWAP_TICK, MIN_UNISWAP_TICK, buildNonCustodialLpContractNft, computeDeterministicRebalanceSlot, executeNonCustodialLpRebalance };
@@ -0,0 +1,335 @@
1
+ import { CrossChainPurchaseInput, TransactionBlockPostConditions, TransactionStatement } from "./transaction-block.mjs";
2
+ import { CHAINALYSIS_OFAC_ORACLE_ADDRESS, assertNotOfacSanctioned, normalizeScreeningAddress } from "./ofac-screening.mjs";
3
+
4
+ //#region src/uniswap-router.d.ts
5
+
6
+ /**
7
+ * Default Integrator Tag for Uniswap Universal Router & Base Builder Attribution.
8
+ */
9
+ declare const DEFAULT_OCAP_INTEGRATOR_ID = "arcblock-ocap-checkout";
10
+ /**
11
+ * Maximum allowed slippage in basis points (5.00% = 500 bps) for 1-click cross-chain zaps.
12
+ */
13
+ declare const MAX_ALLOWED_ZAP_SLIPPAGE_BPS = 500;
14
+ /**
15
+ * Maximum allowed token hops in a single Universal Router path (up to 5 tokens = 4 pool hops).
16
+ */
17
+ declare const MAX_ROUTE_PATH_LENGTH = 5;
18
+ /**
19
+ * Standard Uniswap Universal Router command bytes.
20
+ */
21
+ declare const UNIVERSAL_ROUTER_COMMANDS: {
22
+ readonly V3_SWAP_EXACT_IN: 0;
23
+ readonly SWEEP: 4;
24
+ readonly TRANSFER: 5;
25
+ readonly PAY_PORTION: 6;
26
+ readonly PERMIT2_PERMIT: 10;
27
+ readonly V4_SWAP: 16;
28
+ };
29
+ interface Permit2SingleSpec {
30
+ token: string;
31
+ amount: string;
32
+ expiration: number;
33
+ nonce: number;
34
+ spender: string;
35
+ sigDeadline: number;
36
+ signature: string;
37
+ }
38
+ interface UniversalRouterCrossChainZapInput {
39
+ chainId: string;
40
+ senderEvmAddress: string;
41
+ buyerOcapDid: string;
42
+ universalRouterAddress: string;
43
+ ocapVaultAddress: string;
44
+ tokenIn: string;
45
+ tokenOut: string;
46
+ /** Intermediate hop tokens (e.g. ['0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913', '...'] for USDC -> ABT) */
47
+ routePath: string[];
48
+ poolVersion?: 'v3' | 'v4';
49
+ amountIn: string;
50
+ expectedAmountOut: string;
51
+ maxSlippageBps: number;
52
+ deadline: number;
53
+ currentTimestamp?: number;
54
+ permit2?: Permit2SingleSpec;
55
+ integratorId?: string;
56
+ /**
57
+ * Must ALWAYS be 0 or omitted. Any non-zero swap brokerage fee bps is rejected
58
+ * to enforce the SEC Section 15(a) non-broker-dealer safe harbor.
59
+ */
60
+ brokerageFeeBps?: number;
61
+ ofacBlocklist?: Iterable<string>;
62
+ }
63
+ interface UniversalRouterCrossChainZapPayload {
64
+ chainId: string;
65
+ to: string;
66
+ senderEvmAddress: string;
67
+ buyerOcapDid: string;
68
+ ocapVaultAddress: string;
69
+ commandsHex: string;
70
+ commandNames: string[];
71
+ routePath: string[];
72
+ amountIn: string;
73
+ expectedAmountOut: string;
74
+ amountOutMinimum: string;
75
+ maxSlippageBps: number;
76
+ deadline: number;
77
+ integratorTag: string;
78
+ brokerageFeeBps: 0;
79
+ ofacOracleAddress: string;
80
+ calldataDigest: string;
81
+ }
82
+ /**
83
+ * Builds a deterministic, router-friendly Uniswap Universal Router + Permit2 payload
84
+ * that swaps any ERC-20 token into settlement token (`USDC` or `ABT`) and transfers it
85
+ * into the OCAP Rollup Vault in a single EVM transaction.
86
+ *
87
+ * Security & Compliance Invariants:
88
+ * 1. Rejects any non-zero `brokerageFeeBps` or `PAY_PORTION` fee-skimming (SEC Section 15(a) Safe Harbor).
89
+ * 2. Screens sender, router, vault, token addresses, and OCAP buyer DID against OFAC blocklist.
90
+ * 3. Enforces strict `maxSlippageBps <= 500` (5%), loop-free route paths (`<= 5` tokens), and valid Permit2 hex signatures.
91
+ * 4. Embeds official `ocap:v1:<integratorId>` attribution tag for Uniswap & Base ecosystem alignment.
92
+ */
93
+ declare function buildUniversalRouterCrossChainPayload(input: UniversalRouterCrossChainZapInput): UniversalRouterCrossChainZapPayload;
94
+ interface AbtUtilityPassThroughInput {
95
+ chainId: string;
96
+ senderEvmAddress: string;
97
+ buyerOcapDid: string;
98
+ relayerOcapDid: string;
99
+ rollupAddress: string;
100
+ universalRouterAddress: string;
101
+ ocapVaultAddress: string;
102
+ /** Source payment token on EVM (e.g. USDC, WETH, PEPE) */
103
+ paymentTokenEvmAddress: string;
104
+ /** ABT ERC-20 address on source EVM chain */
105
+ abtEvmAddress: string;
106
+ /** ABT native token address on OCAP chain */
107
+ abtOcapTokenAddress: string;
108
+ /** Full swap route from paymentTokenEvmAddress to abtEvmAddress */
109
+ routePath: string[];
110
+ poolVersion?: 'v3' | 'v4';
111
+ paymentAmountIn: string;
112
+ /** Total ABT output from Uniswap swap (must exactly equal abtServicePrice + abtRelayerFee) */
113
+ abtExpectedOut: string;
114
+ /** ABT consumed immediately on OCAP for Blocklet SaaS, AIGNE compute, or NFT purchase */
115
+ abtServicePrice: string;
116
+ /** Self-liquidating Relayer fee in ABT (must be >= minRelayerFee) */
117
+ abtRelayerFee: string;
118
+ minDepositValue?: string;
119
+ minRelayerFee?: string;
120
+ serviceRecipientDid: string;
121
+ serviceType: 'blocklet_subscription' | 'aigne_compute_credits' | 'nft_purchase' | 'utility_stake';
122
+ targetAssetOrStakeAddress?: string;
123
+ sourceTxEvidenceHash: string;
124
+ maxSlippageBps: number;
125
+ deadline: number;
126
+ currentTimestamp?: number;
127
+ fallbackToDepositOnPurchaseFailure?: boolean;
128
+ integratorId?: string;
129
+ ofacBlocklist?: Iterable<string>;
130
+ }
131
+ interface AbtUtilityPassThroughPlan {
132
+ evmSwapPayload: UniversalRouterCrossChainZapPayload;
133
+ ocapPurchaseBlockInput: CrossChainPurchaseInput;
134
+ economics: {
135
+ treasuryCapitalAtRisk: '0';
136
+ brokerageFeeBps: 0;
137
+ netBuyerSpeculativeAbtRetained: '0';
138
+ holdingPeriodSeconds: 0;
139
+ abtServicePrice: string;
140
+ abtRelayerFee: string;
141
+ totalAbtRouted: string;
142
+ };
143
+ }
144
+ /**
145
+ * Builds an end-to-end "Invisible ABT Utility Fuel" Pass-Through Plan:
146
+ * 1. User pays any token (`USDC`, `ETH`, etc.) on Base/Ethereum via Uniswap `USDC/ABT` pool.
147
+ * 2. Exact `ABT` needed (`abtServicePrice + abtRelayerFee`) is deposited to OCAP and
148
+ * 100% consumed/staked in the same atomic `TransactionBlock` (`holdingPeriodSeconds = 0`,
149
+ * `netBuyerSpeculativeAbtRetained = '0'`, `treasuryCapitalAtRisk = '0'`).
150
+ */
151
+ declare function buildAbtUtilityPassThroughPlan(input: AbtUtilityPassThroughInput): AbtUtilityPassThroughPlan;
152
+ /**
153
+ * Maximum TTL (in seconds) for a USD-anchored dynamic ABT price quote (#1274).
154
+ */
155
+ declare const MAX_USD_QUOTE_TTL_SECONDS = 300;
156
+ /**
157
+ * Default TTL (in seconds) for a USD-anchored dynamic ABT price quote (#1274).
158
+ */
159
+ declare const DEFAULT_USD_QUOTE_TTL_SECONDS = 60;
160
+ /**
161
+ * 18-decimal base unit scale for ABT (`10^18`).
162
+ */
163
+ declare const ABT_DECIMALS_SCALE = "1000000000000000000";
164
+ interface UsdAnchoredAbtQuoteInput {
165
+ quoteId: string;
166
+ serviceId: string;
167
+ buyerOcapDid: string;
168
+ /**
169
+ * Mental price in USD micro-units (`1_000_000` = `$1.00`, e.g. `$0.10` = `'100000'`).
170
+ */
171
+ usdPriceMicro: string;
172
+ /**
173
+ * Uniswap V3/V4 TWAP/Spot price of 1.00 ABT in USD micro-units (e.g. `$0.50` = `'500000'`).
174
+ */
175
+ abtUsdPriceMicro: string;
176
+ /**
177
+ * Maximum allowed slippage tolerance in basis points (`0..500` bps).
178
+ */
179
+ maxSlippageBps?: number;
180
+ issuedAt: number;
181
+ expiresAt?: number;
182
+ oracleSource?: 'UNISWAP_V4_TWAP' | 'UNISWAP_V3_TWAP';
183
+ }
184
+ interface UsdAnchoredAbtQuote {
185
+ quoteId: string;
186
+ serviceId: string;
187
+ buyerOcapDid: string;
188
+ usdPriceMicro: string;
189
+ abtUsdPriceMicro: string;
190
+ /**
191
+ * Exact ceiling ABT amount in 18-decimal wei (`ceil(usdPriceMicro * 10^18 / abtUsdPriceMicro)`).
192
+ */
193
+ requiredAbtWei: string;
194
+ /**
195
+ * Upper bound ABT amount in 18-decimal wei including `maxSlippageBps` buffer.
196
+ */
197
+ maxAbtWithSlippageWei: string;
198
+ maxSlippageBps: number;
199
+ oracleSource: 'UNISWAP_V4_TWAP' | 'UNISWAP_V3_TWAP';
200
+ issuedAt: number;
201
+ expiresAt: number;
202
+ quoteDigest: string;
203
+ }
204
+ interface VerifyUsdAnchoredAbtQuoteInput {
205
+ quote: UsdAnchoredAbtQuote;
206
+ buyerOcapDid: string;
207
+ serviceId: string;
208
+ /**
209
+ * Authoritative catalog USD micro-price for `serviceId` (prevents client-forged underpriced quotes).
210
+ */
211
+ expectedUsdPriceMicro: string;
212
+ /**
213
+ * Trusted Uniswap V3/V4 TWAP oracle price of 1.00 ABT in USD micro-units at verification time
214
+ * (prevents client-forged inflated exchange rates).
215
+ */
216
+ trustedAbtUsdPriceMicro: string;
217
+ /**
218
+ * Maximum allowed deviation (in bps, `0..500`, default `200` = 2%) between `quote.abtUsdPriceMicro`
219
+ * and `trustedAbtUsdPriceMicro`.
220
+ */
221
+ maxOracleDeviationBps?: number;
222
+ paidAbtWei: string;
223
+ nowTimestamp: number;
224
+ usedQuoteIds?: Set<string>;
225
+ }
226
+ /**
227
+ * Issue #1274:
228
+ * Computes a deterministic, CEX-independent USD-anchored `ABT` price quote from a Uniswap V3/V4
229
+ * TWAP/Spot price (`abtUsdPriceMicro`), giving users stable USD mental pricing (`$0.10`, `$1.00`, `$10.00`)
230
+ * while keeping the on-chain settlement 100% pure `ABT`.
231
+ */
232
+ declare function createUsdAnchoredAbtQuote(input: UsdAnchoredAbtQuoteInput): UsdAnchoredAbtQuote;
233
+ /**
234
+ * Verifies a USD-anchored dynamic `ABT` quote for freshness, digest integrity, anti-replay,
235
+ * and exact slippage-bounded `ABT` payment sufficiency (#1274).
236
+ */
237
+ declare function verifyUsdAnchoredAbtQuote(input: VerifyUsdAnchoredAbtQuoteInput): {
238
+ verified: true;
239
+ quoteId: string;
240
+ requiredAbtWei: string;
241
+ paidAbtWei: string;
242
+ };
243
+ interface OutboundWithdrawAndSwapInput {
244
+ chainId: string;
245
+ sellerOcapDid: string;
246
+ relayerOcapDid: string;
247
+ recipientEvmAddress: string;
248
+ ocapBridgeEscrowDid: string;
249
+ abtOcapTokenAddress: string;
250
+ /**
251
+ * Unmodified MultiSigVaultV2 contract address on EVM (holds only ABT).
252
+ */
253
+ ocapVaultAddress: string;
254
+ /**
255
+ * Stateless ABTWithdrawSwapper router/helper contract on EVM that receives released ABT
256
+ * and atomically routes it through Uniswap Universal Router (or falls back to sending ABT to recipientEvmAddress).
257
+ */
258
+ withdrawSwapperAddress: string;
259
+ universalRouterAddress: string;
260
+ abtEvmAddress: string;
261
+ /**
262
+ * Desired exit token on EVM (e.g., USDC, USDT, WETH, or abtEvmAddress for direct ABT exit).
263
+ */
264
+ targetPayoutTokenAddress: string;
265
+ routePath: string[];
266
+ poolVersion?: 'v3' | 'v4';
267
+ /**
268
+ * Total ABT withdrawn from OCAP chain (`netAbtToSwap + relayerExitFeeAbt`).
269
+ */
270
+ grossAbtWithdrawAmount: string;
271
+ /**
272
+ * ABT fee paid by the exiting user to cover EVM withdraw + swap gas (user bears 100% of exit cost).
273
+ */
274
+ relayerExitFeeAbt: string;
275
+ /**
276
+ * Expected amount of `targetPayoutTokenAddress` from Uniswap.
277
+ */
278
+ expectedTargetTokenOut: string;
279
+ maxSlippageBps: number;
280
+ /**
281
+ * 0x-prefixed 32-byte hash of the `OcapPublishedMultiSigCertificate` (`WITHDRAW_ABT`).
282
+ */
283
+ publishedMultiSigCertHash: string;
284
+ deadline: number;
285
+ currentTimestamp?: number;
286
+ fallbackToDirectAbtOnSwapFailure?: boolean;
287
+ integratorId?: string;
288
+ ofacBlocklist?: Iterable<string>;
289
+ }
290
+ interface OutboundWithdrawAndSwapPlan {
291
+ mode: 'WITHDRAW_AND_UNISWAP_SWAP' | 'DIRECT_ABT_WITHDRAW';
292
+ ocapBurnAndFeeStatements: TransactionStatement[];
293
+ ocapPostConditions: TransactionBlockPostConditions;
294
+ evmVaultReleaseSpec: {
295
+ vaultAddress: string;
296
+ vaultContractModified: false;
297
+ vaultTokenReleased: string;
298
+ releaseRecipientAddress: string;
299
+ netAbtReleased: string;
300
+ publishedMultiSigCertHash: string;
301
+ };
302
+ evmSwapPayload?: UniversalRouterCrossChainZapPayload;
303
+ fallbackSafetySpec: {
304
+ fallbackToDirectAbtOnSwapFailure: boolean;
305
+ fallbackRecipientEvmAddress: string;
306
+ fallbackTokenAddress: string;
307
+ fallbackAmountAbt: string;
308
+ swapperRetainsZeroBalanceAfterTx: true;
309
+ };
310
+ economics: {
311
+ userBearsExitCost: true;
312
+ protocolSubsidyAbt: '0';
313
+ grossAbtWithdrawAmount: string;
314
+ relayerExitFeeAbt: string;
315
+ netAbtToSwap: string;
316
+ expectedTargetTokenOut: string;
317
+ minimumTargetTokenOut: string;
318
+ };
319
+ clearSigningSummary: {
320
+ youPay: string;
321
+ actions: string[];
322
+ youReceiveMinimum: string;
323
+ };
324
+ }
325
+ /**
326
+ * Issue #1274:
327
+ * Builds a stateless 1-Click Outbound Withdraw + Uniswap Auto-Swap Plan ("Smooth In, Smooth Out"):
328
+ * - OCAP side: atomically locks/burns `netAbtToSwap` to `ocapBridgeEscrowDid` and pays `relayerExitFeeAbt` to `relayerOcapDid`.
329
+ * - EVM side: `MultiSigVaultV2` (100% unmodified, holding only `ABT`) releases `netAbtToSwap` via `OcapPublishedMultiSigCert`
330
+ * to `withdrawSwapperAddress`, which atomically swaps `ABT -> targetPayoutToken (USDC/USDT/ETH)` via Uniswap Universal Router
331
+ * and sweeps 100% of output to `recipientEvmAddress` (or safely falls back to sending `netAbtToSwap` directly to `recipientEvmAddress`).
332
+ */
333
+ declare function buildOutboundWithdrawAndSwapPlan(input: OutboundWithdrawAndSwapInput): OutboundWithdrawAndSwapPlan;
334
+ //#endregion
335
+ export { ABT_DECIMALS_SCALE, AbtUtilityPassThroughInput, AbtUtilityPassThroughPlan, CHAINALYSIS_OFAC_ORACLE_ADDRESS, DEFAULT_OCAP_INTEGRATOR_ID, DEFAULT_USD_QUOTE_TTL_SECONDS, MAX_ALLOWED_ZAP_SLIPPAGE_BPS, MAX_ROUTE_PATH_LENGTH, MAX_USD_QUOTE_TTL_SECONDS, OutboundWithdrawAndSwapInput, OutboundWithdrawAndSwapPlan, Permit2SingleSpec, UNIVERSAL_ROUTER_COMMANDS, UniversalRouterCrossChainZapInput, UniversalRouterCrossChainZapPayload, UsdAnchoredAbtQuote, UsdAnchoredAbtQuoteInput, VerifyUsdAnchoredAbtQuoteInput, assertNotOfacSanctioned, buildAbtUtilityPassThroughPlan, buildOutboundWithdrawAndSwapPlan, buildUniversalRouterCrossChainPayload, createUsdAnchoredAbtQuote, normalizeScreeningAddress, verifyUsdAnchoredAbtQuote };