@ocap/tx-pipeline 1.30.26 → 1.31.0

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 +43 -4
  25. package/esm/pipes/decode-tx.d.mts +2 -3
  26. package/esm/pipes/decode-tx.mjs +53 -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 +34 -0
  32. package/esm/pipes/pre-flight-waf.mjs +603 -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 +43 -4
  94. package/lib/pipes/decode-itx.d.cts +1 -1
  95. package/lib/pipes/decode-tx.cjs +52 -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 +616 -0
  102. package/lib/pipes/pre-flight-waf.d.cts +34 -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,383 @@
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
+ let _ocap_mcrypto = require("@ocap/mcrypto");
5
+ let _ocap_util = require("@ocap/util");
6
+ let _ocap_util_lib_error = require("@ocap/util/lib/error");
7
+
8
+ //#region src/arcvault-external-adapter.ts
9
+ const FORBIDDEN_KEYS = new Set([
10
+ "__proto__",
11
+ "constructor",
12
+ "prototype"
13
+ ]);
14
+ const CANONICAL_UINT_REGEX = /^\d+$/;
15
+ const SELECTOR_HEX_REGEX = /^0x[0-9a-fA-F]{8}$/;
16
+ const ACC_PRECISION = new _ocap_util.BN("1000000000000000000", 10);
17
+ /** Forbidden raw ERC-20 / Permit2 selectors that could drain vault funds if called on an arbitrary target */
18
+ const FORBIDDEN_EXTERNAL_CALL_SELECTORS = new Set([
19
+ "0x095ea7b3",
20
+ "0xa9059cbb",
21
+ "0x23b872dd",
22
+ "0xd505accf",
23
+ "0x39509351",
24
+ "0xa457c2d7",
25
+ "0x36c78516",
26
+ "0x0d58b1db",
27
+ "0x87517c45",
28
+ "0x2b67b570",
29
+ "0x2a2d80d1",
30
+ "0x30f28b7a",
31
+ "0xedd9444b"
32
+ ]);
33
+ const MIN_VAULT_LIQUID_BUFFER_BPS = 2e3;
34
+ const MAX_VAULT_STRATEGY_DEPLOYED_BPS = 8e3;
35
+ const MAX_ZAP_PRICE_IMPACT_BPS = 500;
36
+ const MAX_HARVEST_YIELD_BPS = 5e3;
37
+ const MAX_ZAP_ABT_PER_SETTLEMENT_SCALAR = new _ocap_util.BN("100000000000000", 10);
38
+ function assertSafeId(val, label) {
39
+ if (typeof val !== "string") throw new _ocap_util_lib_error.CustomError("INVALID_ARCVAULT_ADAPTER", `${label} must be a non-empty string`);
40
+ const trimmed = val.trim();
41
+ if (!trimmed || FORBIDDEN_KEYS.has(trimmed)) throw new _ocap_util_lib_error.CustomError("INVALID_ARCVAULT_ADAPTER", `Invalid or unsafe ${label}`);
42
+ return trimmed;
43
+ }
44
+ function parsePositiveBn(val, label) {
45
+ if (typeof val !== "string" || !CANONICAL_UINT_REGEX.test(val)) throw new _ocap_util_lib_error.CustomError("INVALID_ARCVAULT_ADAPTER", `${label} must be a canonical base-10 integer string`);
46
+ const bn = new _ocap_util.BN(val, 10);
47
+ if (bn.lte(new _ocap_util.BN(0))) throw new _ocap_util_lib_error.CustomError("INVALID_ARCVAULT_ADAPTER", `${label} must be strictly positive`);
48
+ return bn;
49
+ }
50
+ function parseNonNegativeBn(val, label) {
51
+ if (typeof val !== "string" || !CANONICAL_UINT_REGEX.test(val)) throw new _ocap_util_lib_error.CustomError("INVALID_ARCVAULT_ADAPTER", `${label} must be a canonical non-negative integer string`);
52
+ return new _ocap_util.BN(val, 10);
53
+ }
54
+ /**
55
+ * ArcVault External Swap Hook + ERC-4626 Non-Commingled Yield Adapter + Universal ABT Zap-In Engine (#1170).
56
+ */
57
+ var OcapArcVaultExternalAdapterEngine = class {
58
+ constructor(options) {
59
+ this.allowlistedRouters = /* @__PURE__ */ new Set();
60
+ this.allowlistedSelectors = /* @__PURE__ */ new Set();
61
+ this.consumedSwapIds = /* @__PURE__ */ new Set();
62
+ this.consumedZapIds = /* @__PURE__ */ new Set();
63
+ this.ofacSet = /* @__PURE__ */ new Set();
64
+ this.liquidBufferBn = new _ocap_util.BN(0);
65
+ this.strategyDeployedBn = new _ocap_util.BN(0);
66
+ this.totalPrincipalSharesBn = new _ocap_util.BN(0);
67
+ this.accYieldPerShareScaledBn = new _ocap_util.BN(0);
68
+ this.unclaimedYieldReserveBn = new _ocap_util.BN(0);
69
+ this.shareholders = /* @__PURE__ */ new Map();
70
+ if (!options || typeof options !== "object") throw new _ocap_util_lib_error.CustomError("INVALID_ARCVAULT_ADAPTER", "Missing OcapArcVaultExternalAdapterEngine options");
71
+ this.vaultId = assertSafeId(options.vaultId, "vaultId");
72
+ this.settlementToken = require_ofac_screening.normalizeScreeningAddress(assertSafeId(options.settlementToken, "settlementToken"));
73
+ this.abtTokenAddress = require_ofac_screening.normalizeScreeningAddress(assertSafeId(options.abtTokenAddress, "abtTokenAddress"));
74
+ this.erc4626StrategyVault = require_ofac_screening.normalizeScreeningAddress(assertSafeId(options.erc4626StrategyVault, "erc4626StrategyVault"));
75
+ if (this.settlementToken === this.erc4626StrategyVault || this.settlementToken === this.abtTokenAddress || this.abtTokenAddress === this.erc4626StrategyVault) throw new _ocap_util_lib_error.CustomError("INVALID_ARCVAULT_ADAPTER", "settlementToken, abtTokenAddress, and erc4626StrategyVault must be pairwise distinct");
76
+ if (!Array.isArray(options.allowlistedRouters) || options.allowlistedRouters.length === 0) throw new _ocap_util_lib_error.CustomError("INVALID_ARCVAULT_ADAPTER", "allowlistedRouters must be a non-empty array");
77
+ for (const r of options.allowlistedRouters) {
78
+ const norm = require_ofac_screening.normalizeScreeningAddress(assertSafeId(r, "allowlistedRouter"));
79
+ if (norm === this.settlementToken || norm === this.abtTokenAddress || norm === this.erc4626StrategyVault) throw new _ocap_util_lib_error.CustomError("INVALID_ARCVAULT_ADAPTER", `Router ${norm} cannot be a protected token or strategy vault address`);
80
+ this.allowlistedRouters.add(norm);
81
+ }
82
+ if (!Array.isArray(options.allowlistedSelectors) || options.allowlistedSelectors.length === 0) throw new _ocap_util_lib_error.CustomError("INVALID_ARCVAULT_ADAPTER", "allowlistedSelectors must be a non-empty array");
83
+ for (const sel of options.allowlistedSelectors) {
84
+ if (typeof sel !== "string" || !SELECTOR_HEX_REGEX.test(sel)) throw new _ocap_util_lib_error.CustomError("INVALID_ARCVAULT_ADAPTER", `Invalid 4-byte function selector: ${String(sel)}`);
85
+ const lower = sel.toLowerCase();
86
+ if (FORBIDDEN_EXTERNAL_CALL_SELECTORS.has(lower)) throw new _ocap_util_lib_error.CustomError("FORBIDDEN_SELECTOR", `Selector ${lower} is forbidden on external swap routers to prevent arbitrary token drains`);
87
+ this.allowlistedSelectors.add(lower);
88
+ }
89
+ if (options.ofacBlocklist) for (const a of options.ofacBlocklist) this.ofacSet.add(require_ofac_screening.normalizeScreeningAddress(a));
90
+ require_ofac_screening.assertNotOfacSanctioned([
91
+ this.settlementToken,
92
+ this.abtTokenAddress,
93
+ this.erc4626StrategyVault,
94
+ ...Array.from(this.allowlistedRouters)
95
+ ], this.ofacSet);
96
+ }
97
+ assertNotProtectedProtocolAddress(addr, label) {
98
+ if (addr === this.erc4626StrategyVault || addr === this.settlementToken || addr === this.abtTokenAddress || this.allowlistedRouters.has(addr)) throw new _ocap_util_lib_error.CustomError("SELF_DEALING_ADDRESS_FORBIDDEN", `${label} (${addr}) cannot equal a protected vault, token, or router address`);
99
+ }
100
+ mergeOfacSet(extra) {
101
+ const combined = new Set(this.ofacSet);
102
+ if (extra) for (const a of extra) combined.add(require_ofac_screening.normalizeScreeningAddress(a));
103
+ return combined;
104
+ }
105
+ /**
106
+ * Executes an allowlisted external DEX swap (`executeExternalSwap`) with:
107
+ * - Strict router & selector allowlist enforcement (blocking ERC-20 & Permit2 `approve`/`transferFrom`)
108
+ * - Token pair anchor verification (at least one leg must be `settlementToken` or `abtTokenAddress`, and neither leg can be `erc4626StrategyVault` or a router)
109
+ * - Transient exact-amount approval (`amountIn` before call, `0` immediately after call)
110
+ * - Pre/post balance snapshot verification (`actualAmountOut >= minAmountOut` and exact `amountIn` debit)
111
+ */
112
+ executeExternalSwap(input) {
113
+ if (!input || typeof input !== "object") throw new _ocap_util_lib_error.CustomError("INVALID_EXTERNAL_SWAP", "Missing ExternalSwapHookInput");
114
+ const swapId = assertSafeId(input.swapId, "swapId");
115
+ if (this.consumedSwapIds.has(swapId)) throw new _ocap_util_lib_error.CustomError("REPLAYED_EXTERNAL_SWAP", `External swap ${swapId} has already been executed`);
116
+ const router = require_ofac_screening.normalizeScreeningAddress(assertSafeId(input.routerAddress, "routerAddress"));
117
+ if (!this.allowlistedRouters.has(router)) throw new _ocap_util_lib_error.CustomError("UNAUTHORIZED_SWAP_ROUTER", `Router ${router} is not in allowlistedRouters`);
118
+ if (typeof input.callSelector !== "string" || !SELECTOR_HEX_REGEX.test(input.callSelector)) throw new _ocap_util_lib_error.CustomError("INVALID_EXTERNAL_SWAP", "callSelector must be a 4-byte 0x hex string");
119
+ const selector = input.callSelector.toLowerCase();
120
+ if (FORBIDDEN_EXTERNAL_CALL_SELECTORS.has(selector) || !this.allowlistedSelectors.has(selector)) throw new _ocap_util_lib_error.CustomError("UNAUTHORIZED_SWAP_SELECTOR", `Selector ${selector} is not allowlisted for external swap`);
121
+ const tokenIn = require_ofac_screening.normalizeScreeningAddress(assertSafeId(input.tokenIn, "tokenIn"));
122
+ const tokenOut = require_ofac_screening.normalizeScreeningAddress(assertSafeId(input.tokenOut, "tokenOut"));
123
+ if (tokenIn === tokenOut) throw new _ocap_util_lib_error.CustomError("INVALID_EXTERNAL_SWAP", "tokenIn and tokenOut must be distinct");
124
+ if (tokenIn === this.erc4626StrategyVault || tokenOut === this.erc4626StrategyVault || this.allowlistedRouters.has(tokenIn) || this.allowlistedRouters.has(tokenOut)) throw new _ocap_util_lib_error.CustomError("UNAUTHORIZED_SWAP_TOKEN", "External swap cannot touch erc4626StrategyVault shares or router addresses");
125
+ if (!(tokenIn === this.settlementToken || tokenOut === this.settlementToken || tokenIn === this.abtTokenAddress || tokenOut === this.abtTokenAddress)) throw new _ocap_util_lib_error.CustomError("UNANCHORED_SWAP_PAIR", `External swap (${tokenIn} -> ${tokenOut}) must anchor to settlementToken (${this.settlementToken}) or abtTokenAddress (${this.abtTokenAddress})`);
126
+ require_ofac_screening.assertNotOfacSanctioned([
127
+ router,
128
+ tokenIn,
129
+ tokenOut
130
+ ], this.mergeOfacSet(input.ofacBlocklist));
131
+ const amountInBn = parsePositiveBn(input.amountIn, "amountIn");
132
+ const minAmountOutBn = parsePositiveBn(input.minAmountOut, "minAmountOut");
133
+ const preInBn = parseNonNegativeBn(input.preBalanceIn, "preBalanceIn");
134
+ const postInBn = parseNonNegativeBn(input.postBalanceIn, "postBalanceIn");
135
+ const preOutBn = parseNonNegativeBn(input.preBalanceOut, "preBalanceOut");
136
+ const postOutBn = parseNonNegativeBn(input.postBalanceOut, "postBalanceOut");
137
+ if (tokenIn === this.settlementToken) {
138
+ if (amountInBn.gt(this.liquidBufferBn)) throw new _ocap_util_lib_error.CustomError("SWAP_EXCEEDS_LIQUID_BUFFER", `Swap amountIn (${amountInBn.toString(10)}) exceeds available vault liquidBufferBalance (${this.liquidBufferBn.toString(10)})`);
139
+ const postBackingBn = this.liquidBufferBn.sub(amountInBn).add(this.strategyDeployedBn);
140
+ if (postBackingBn.lt(this.totalPrincipalSharesBn)) throw new _ocap_util_lib_error.CustomError("SWAP_BREACHES_PRINCIPAL_BACKING", `Swap amountIn (${amountInBn.toString(10)}) would reduce total vault backing (${postBackingBn.toString(10)}) below totalPrincipalShares (${this.totalPrincipalSharesBn.toString(10)})`);
141
+ }
142
+ if (preInBn.lt(amountInBn)) throw new _ocap_util_lib_error.CustomError("INSUFFICIENT_SWAP_INPUT", "preBalanceIn is less than amountIn");
143
+ if (postInBn.gt(preInBn)) throw new _ocap_util_lib_error.CustomError("INVALID_SWAP_BALANCE_DELTA", "postBalanceIn cannot exceed preBalanceIn");
144
+ const exactSpentBn = preInBn.sub(postInBn);
145
+ if (!exactSpentBn.eq(amountInBn)) throw new _ocap_util_lib_error.CustomError("UNEXPECTED_INPUT_DEBIT", `External swap spent ${exactSpentBn.toString(10)} of tokenIn, expected exact amountIn (${amountInBn.toString(10)})`);
146
+ if (postOutBn.lt(preOutBn)) throw new _ocap_util_lib_error.CustomError("INVALID_SWAP_BALANCE_DELTA", "postBalanceOut cannot be less than preBalanceOut");
147
+ const actualReceivedBn = postOutBn.sub(preOutBn);
148
+ if (actualReceivedBn.lt(minAmountOutBn)) throw new _ocap_util_lib_error.CustomError("SWAP_SLIPPAGE_EXCEEDED", `Actual output received (${actualReceivedBn.toString(10)}) is less than minAmountOut (${minAmountOutBn.toString(10)})`);
149
+ if (tokenIn === this.settlementToken) this.liquidBufferBn = this.liquidBufferBn.sub(exactSpentBn);
150
+ if (tokenOut === this.settlementToken) this.liquidBufferBn = this.liquidBufferBn.add(actualReceivedBn);
151
+ this.consumedSwapIds.add(swapId);
152
+ const digestPayload = `ocap:arcvault-swap:v1:${this.vaultId.length}:${this.vaultId}:${swapId.length}:${swapId}:${router}:${selector}:${tokenIn}:${tokenOut}:${exactSpentBn.toString(10)}:${actualReceivedBn.toString(10)}`;
153
+ const balanceInvariantDigest = `0x${_ocap_mcrypto.Hasher.SHA3.hash256(Buffer.from(digestPayload, "utf8")).replace(/^0x/, "").toLowerCase()}`;
154
+ return {
155
+ swapId,
156
+ routerAddress: router,
157
+ tokenIn,
158
+ tokenOut,
159
+ exactAmountSpent: exactSpentBn.toString(10),
160
+ actualAmountReceived: actualReceivedBn.toString(10),
161
+ transientApprovalBeforeCall: amountInBn.toString(10),
162
+ transientApprovalAfterCall: "0",
163
+ balanceInvariantDigest
164
+ };
165
+ }
166
+ /**
167
+ * Deposits settlement tokens directly into ArcVault, minting 1:1 principal shares for `holderDid`
168
+ * and routing liquidity according to the 20% Liquid Buffer / 80% ERC-4626 Strategy policy.
169
+ */
170
+ depositAndAllocate(params) {
171
+ const holder = require_ofac_screening.normalizeScreeningAddress(assertSafeId(params.holderDid, "holderDid"));
172
+ this.assertNotProtectedProtocolAddress(holder, "holderDid");
173
+ require_ofac_screening.assertNotOfacSanctioned([holder], this.mergeOfacSet(params.ofacBlocklist));
174
+ const amountBn = parsePositiveBn(params.amount, "amount");
175
+ const existing = this.shareholders.get(holder) || {
176
+ holderDid: holder,
177
+ principalShares: "0",
178
+ yieldDebtScaled: "0",
179
+ accruedUnclaimedYield: "0"
180
+ };
181
+ const prevSharesBn = new _ocap_util.BN(existing.principalShares, 10);
182
+ const prevDebtScaledBn = new _ocap_util.BN(existing.yieldDebtScaled, 10);
183
+ const prevAccruedBn = new _ocap_util.BN(existing.accruedUnclaimedYield, 10);
184
+ const pendingYieldBn = prevSharesBn.mul(this.accYieldPerShareScaledBn).sub(prevDebtScaledBn).div(ACC_PRECISION);
185
+ const nextSharesBn = prevSharesBn.add(amountBn);
186
+ const nextDebtScaledBn = nextSharesBn.mul(this.accYieldPerShareScaledBn);
187
+ this.shareholders.set(holder, {
188
+ holderDid: holder,
189
+ principalShares: nextSharesBn.toString(10),
190
+ yieldDebtScaled: nextDebtScaledBn.toString(10),
191
+ accruedUnclaimedYield: prevAccruedBn.add(pendingYieldBn).toString(10)
192
+ });
193
+ this.totalPrincipalSharesBn = this.totalPrincipalSharesBn.add(amountBn);
194
+ this.liquidBufferBn = this.liquidBufferBn.add(amountBn);
195
+ if (params.autoDeployToStrategy !== false) this.rebalanceToTargetAllocation();
196
+ return this.getVaultState();
197
+ }
198
+ /**
199
+ * Enforces the 20% Liquid Buffer / 80% Allowlisted ERC-4626 Strategy allocation invariant.
200
+ * Uses ceiling division for the 20% minimum liquid buffer so `liquidBufferBalance` is NEVER
201
+ * even 1 wei below 20% of total backing (`liquidBufferBalance + strategyDeployedBalance`).
202
+ */
203
+ rebalanceToTargetAllocation() {
204
+ const totalBackingBn = this.liquidBufferBn.add(this.strategyDeployedBn);
205
+ if (totalBackingBn.isZero()) return this.getVaultState();
206
+ const minLiquidBn = totalBackingBn.muln(MIN_VAULT_LIQUID_BUFFER_BPS).addn(9999).divn(1e4);
207
+ const maxStrategyBn = totalBackingBn.sub(minLiquidBn);
208
+ this.liquidBufferBn = minLiquidBn;
209
+ this.strategyDeployedBn = maxStrategyBn;
210
+ return this.getVaultState();
211
+ }
212
+ /**
213
+ * Withdraws principal shares for `holderDid`. If `withdrawAmount > liquidBufferBalance`,
214
+ * automatically recalls the shortfall from the ERC-4626 strategy adapter AND restores the 20%
215
+ * minimum liquid buffer on the remaining vault backing.
216
+ */
217
+ withdrawWithAutoRecall(params) {
218
+ const holder = require_ofac_screening.normalizeScreeningAddress(assertSafeId(params.holderDid, "holderDid"));
219
+ require_ofac_screening.assertNotOfacSanctioned([holder], this.mergeOfacSet(params.ofacBlocklist));
220
+ const withdrawBn = parsePositiveBn(params.withdrawAmount, "withdrawAmount");
221
+ const existing = this.shareholders.get(holder);
222
+ if (!existing) throw new _ocap_util_lib_error.CustomError("NOT_FOUND", `Shareholder ${holder} not found in vault ${this.vaultId}`);
223
+ const prevSharesBn = new _ocap_util.BN(existing.principalShares, 10);
224
+ if (prevSharesBn.lt(withdrawBn)) throw new _ocap_util_lib_error.CustomError("INSUFFICIENT_VAULT_SHARES", `Shareholder ${holder} has ${prevSharesBn.toString(10)} shares, cannot withdraw ${withdrawBn.toString(10)}`);
225
+ const totalBackingBn = this.liquidBufferBn.add(this.strategyDeployedBn);
226
+ if (totalBackingBn.lt(withdrawBn)) throw new _ocap_util_lib_error.CustomError("VAULT_INSOLVENT", "Total vault backing is insufficient for withdrawal");
227
+ const prevDebtScaledBn = new _ocap_util.BN(existing.yieldDebtScaled, 10);
228
+ const prevAccruedBn = new _ocap_util.BN(existing.accruedUnclaimedYield, 10);
229
+ const pendingYieldBn = prevSharesBn.mul(this.accYieldPerShareScaledBn).sub(prevDebtScaledBn).div(ACC_PRECISION);
230
+ const nextSharesBn = prevSharesBn.sub(withdrawBn);
231
+ const nextDebtScaledBn = nextSharesBn.mul(this.accYieldPerShareScaledBn);
232
+ this.shareholders.set(holder, {
233
+ holderDid: holder,
234
+ principalShares: nextSharesBn.toString(10),
235
+ yieldDebtScaled: nextDebtScaledBn.toString(10),
236
+ accruedUnclaimedYield: prevAccruedBn.add(pendingYieldBn).toString(10)
237
+ });
238
+ this.totalPrincipalSharesBn = this.totalPrincipalSharesBn.sub(withdrawBn);
239
+ const requiredPostLiquidBn = totalBackingBn.sub(withdrawBn).muln(MIN_VAULT_LIQUID_BUFFER_BPS).addn(9999).divn(1e4);
240
+ const totalLiquidNeededNowBn = withdrawBn.add(requiredPostLiquidBn);
241
+ let recalledBn = new _ocap_util.BN(0);
242
+ if (this.liquidBufferBn.lt(totalLiquidNeededNowBn)) {
243
+ const neededRecallBn = totalLiquidNeededNowBn.sub(this.liquidBufferBn);
244
+ recalledBn = neededRecallBn.gt(this.strategyDeployedBn) ? this.strategyDeployedBn : neededRecallBn;
245
+ this.strategyDeployedBn = this.strategyDeployedBn.sub(recalledBn);
246
+ this.liquidBufferBn = this.liquidBufferBn.add(recalledBn);
247
+ }
248
+ this.liquidBufferBn = this.liquidBufferBn.sub(withdrawBn);
249
+ return {
250
+ withdrawnAmount: withdrawBn.toString(10),
251
+ recalledFromStrategy: recalledBn.toString(10),
252
+ vaultState: this.getVaultState()
253
+ };
254
+ }
255
+ /**
256
+ * Harvests yield generated by the allowlisted ERC-4626 strategy vault and distributes it
257
+ * in `O(1)` time via `accYieldPerShareScaled` backed 100% by `unclaimedYieldReserve`.
258
+ */
259
+ harvestVaultYield(yieldAmount) {
260
+ const yieldBn = parsePositiveBn(yieldAmount, "yieldAmount");
261
+ if (this.totalPrincipalSharesBn.isZero()) throw new _ocap_util_lib_error.CustomError("EMPTY_VAULT_SHARES", "Cannot harvest yield when totalPrincipalShares is 0");
262
+ if (this.strategyDeployedBn.isZero()) throw new _ocap_util_lib_error.CustomError("EMPTY_STRATEGY_DEPLOYMENT", "Cannot harvest ERC-4626 strategy yield when strategyDeployedBalance is 0");
263
+ const maxAllowedHarvestBn = this.strategyDeployedBn.muln(MAX_HARVEST_YIELD_BPS).divn(1e4);
264
+ if (yieldBn.gt(maxAllowedHarvestBn)) throw new _ocap_util_lib_error.CustomError("EXCESSIVE_YIELD_HARVEST", `Yield amount (${yieldBn.toString(10)}) exceeds maximum single-harvest cap (${maxAllowedHarvestBn.toString(10)}) on strategyDeployedBalance (${this.strategyDeployedBn.toString(10)})`);
265
+ const deltaAccScaled = yieldBn.mul(ACC_PRECISION).div(this.totalPrincipalSharesBn);
266
+ if (deltaAccScaled.isZero()) throw new _ocap_util_lib_error.CustomError("YIELD_TOO_SMALL_FOR_DISTRIBUTION", "Yield amount is too small relative to totalPrincipalShares and would round to 0 per share");
267
+ this.accYieldPerShareScaledBn = this.accYieldPerShareScaledBn.add(deltaAccScaled);
268
+ this.unclaimedYieldReserveBn = this.unclaimedYieldReserveBn.add(yieldBn);
269
+ return this.getVaultState();
270
+ }
271
+ /**
272
+ * Claims accrued ERC-4626 strategy yield for `holderDid` in `O(1)` time.
273
+ */
274
+ claimVaultYield(holderDid, ofacBlocklist) {
275
+ const holder = require_ofac_screening.normalizeScreeningAddress(assertSafeId(holderDid, "holderDid"));
276
+ require_ofac_screening.assertNotOfacSanctioned([holder], this.mergeOfacSet(ofacBlocklist));
277
+ const pos = this.shareholders.get(holder);
278
+ if (!pos) throw new _ocap_util_lib_error.CustomError("NOT_FOUND", `Shareholder ${holder} not found in vault ${this.vaultId}`);
279
+ const sharesBn = new _ocap_util.BN(pos.principalShares, 10);
280
+ const debtScaledBn = new _ocap_util.BN(pos.yieldDebtScaled, 10);
281
+ const accruedBn = new _ocap_util.BN(pos.accruedUnclaimedYield, 10);
282
+ const newlyEarnedBn = sharesBn.mul(this.accYieldPerShareScaledBn).sub(debtScaledBn).div(ACC_PRECISION);
283
+ const totalClaimableBn = accruedBn.add(newlyEarnedBn);
284
+ if (this.unclaimedYieldReserveBn.lt(totalClaimableBn)) throw new _ocap_util_lib_error.CustomError("INSUFFICIENT_YIELD_RESERVE", "Insufficient unclaimed yield reserve");
285
+ this.unclaimedYieldReserveBn = this.unclaimedYieldReserveBn.sub(totalClaimableBn);
286
+ pos.yieldDebtScaled = sharesBn.mul(this.accYieldPerShareScaledBn).toString(10);
287
+ pos.accruedUnclaimedYield = "0";
288
+ return {
289
+ claimedYield: totalClaimableBn.toString(10),
290
+ shareholderPosition: { ...pos }
291
+ };
292
+ }
293
+ /**
294
+ * Universal `ABT` Zap-In Funnel (`zapInAndBridge`):
295
+ * Converts arbitrary origin-chain `tokenIn` -> `settlementToken` (deposited & allocated into ArcVault)
296
+ * -> `OCAP ABT` for `recipientDid` with router/selector allowlist, slippage caps, exchange-rate bounds, and OFAC screening.
297
+ */
298
+ zapInAndBridge(input) {
299
+ if (!input || typeof input !== "object") throw new _ocap_util_lib_error.CustomError("INVALID_ZAP_IN", "Missing UniversalAbtZapInInput");
300
+ const zapId = assertSafeId(input.zapId, "zapId");
301
+ if (this.consumedZapIds.has(zapId)) throw new _ocap_util_lib_error.CustomError("REPLAYED_ZAP_IN", `Zap-In ${zapId} has already been processed`);
302
+ const sender = require_ofac_screening.normalizeScreeningAddress(assertSafeId(input.senderAddress, "senderAddress"));
303
+ const recipient = require_ofac_screening.normalizeScreeningAddress(assertSafeId(input.recipientDid, "recipientDid"));
304
+ const router = require_ofac_screening.normalizeScreeningAddress(assertSafeId(input.routerAddress, "routerAddress"));
305
+ const tokenIn = require_ofac_screening.normalizeScreeningAddress(assertSafeId(input.tokenIn, "tokenIn"));
306
+ this.assertNotProtectedProtocolAddress(sender, "senderAddress");
307
+ this.assertNotProtectedProtocolAddress(recipient, "recipientDid");
308
+ if (tokenIn === this.erc4626StrategyVault || tokenIn === this.abtTokenAddress || this.allowlistedRouters.has(tokenIn)) throw new _ocap_util_lib_error.CustomError("INVALID_ZAP_TOKEN_IN", `tokenIn (${tokenIn}) cannot be erc4626StrategyVault, abtTokenAddress, or a router address`);
309
+ if (!this.allowlistedRouters.has(router)) throw new _ocap_util_lib_error.CustomError("UNAUTHORIZED_SWAP_ROUTER", `Router ${router} is not in allowlistedRouters`);
310
+ if (typeof input.callSelector !== "string" || !SELECTOR_HEX_REGEX.test(input.callSelector)) throw new _ocap_util_lib_error.CustomError("INVALID_ZAP_IN", "callSelector must be a 4-byte 0x hex string");
311
+ const selector = input.callSelector.toLowerCase();
312
+ if (FORBIDDEN_EXTERNAL_CALL_SELECTORS.has(selector) || !this.allowlistedSelectors.has(selector)) throw new _ocap_util_lib_error.CustomError("UNAUTHORIZED_SWAP_SELECTOR", `Selector ${selector} is not allowlisted`);
313
+ if (!Number.isSafeInteger(input.slippageBps) || input.slippageBps <= 0 || input.slippageBps > MAX_ZAP_PRICE_IMPACT_BPS) throw new _ocap_util_lib_error.CustomError("EXCESSIVE_ZAP_SLIPPAGE", `slippageBps (${input.slippageBps}) must be an integer between 1 and ${MAX_ZAP_PRICE_IMPACT_BPS}`);
314
+ const combinedOfac = this.mergeOfacSet(input.ofacBlocklist);
315
+ require_ofac_screening.assertNotOfacSanctioned([
316
+ sender,
317
+ recipient,
318
+ router,
319
+ tokenIn
320
+ ], combinedOfac);
321
+ const amountInBn = parsePositiveBn(input.amountIn, "amountIn");
322
+ const quotedSettlementBn = parsePositiveBn(input.quotedSettlementOut, "quotedSettlementOut");
323
+ const minSettlementBn = parsePositiveBn(input.minSettlementOut, "minSettlementOut");
324
+ const quotedAbtBn = parsePositiveBn(input.quotedAbtOut, "quotedAbtOut");
325
+ const minAbtBn = parsePositiveBn(input.minAbtOut, "minAbtOut");
326
+ if (tokenIn === this.settlementToken && !quotedSettlementBn.eq(amountInBn)) throw new _ocap_util_lib_error.CustomError("INVALID_ZAP_IN", "When tokenIn equals settlementToken, quotedSettlementOut must equal amountIn");
327
+ const maxAllowedSettlementBn = amountInBn.mul(MAX_ZAP_ABT_PER_SETTLEMENT_SCALAR);
328
+ if (quotedSettlementBn.gt(maxAllowedSettlementBn)) throw new _ocap_util_lib_error.CustomError("EXCESSIVE_ZAP_EXCHANGE_RATE", `quotedSettlementOut (${quotedSettlementBn.toString(10)}) exceeds maximum allowed exchange rate ratio against amountIn (${amountInBn.toString(10)})`);
329
+ const maxAllowedAbtBn = quotedSettlementBn.mul(MAX_ZAP_ABT_PER_SETTLEMENT_SCALAR);
330
+ if (quotedAbtBn.gt(maxAllowedAbtBn)) throw new _ocap_util_lib_error.CustomError("EXCESSIVE_ZAP_EXCHANGE_RATE", `quotedAbtOut (${quotedAbtBn.toString(10)}) exceeds maximum allowed exchange rate ratio against quotedSettlementOut (${quotedSettlementBn.toString(10)})`);
331
+ const minRequiredSettlementFloorBn = quotedSettlementBn.muln(1e4 - input.slippageBps).addn(9999).divn(1e4);
332
+ if (minSettlementBn.lt(minRequiredSettlementFloorBn) || quotedSettlementBn.lt(minSettlementBn)) throw new _ocap_util_lib_error.CustomError("ZAP_SLIPPAGE_FLOOR_VIOLATION", `minSettlementOut (${minSettlementBn.toString(10)}) violates slippage floor (${minRequiredSettlementFloorBn.toString(10)}) or exceeds quotedSettlementOut`);
333
+ let verifiedSettlementOutBn = quotedSettlementBn;
334
+ if (input.preSettlementBalance !== void 0 || input.postSettlementBalance !== void 0) {
335
+ if (input.preSettlementBalance === void 0 || input.postSettlementBalance === void 0) throw new _ocap_util_lib_error.CustomError("INVALID_ZAP_IN", "Both preSettlementBalance and postSettlementBalance must be provided together");
336
+ const preSettleBn = parseNonNegativeBn(input.preSettlementBalance, "preSettlementBalance");
337
+ const postSettleBn = parseNonNegativeBn(input.postSettlementBalance, "postSettlementBalance");
338
+ if (postSettleBn.lt(preSettleBn)) throw new _ocap_util_lib_error.CustomError("INVALID_ZAP_BALANCE_DELTA", "postSettlementBalance cannot be less than preSettlementBalance");
339
+ verifiedSettlementOutBn = postSettleBn.sub(preSettleBn);
340
+ if (verifiedSettlementOutBn.lt(minSettlementBn)) throw new _ocap_util_lib_error.CustomError("ZAP_SLIPPAGE_FLOOR_VIOLATION", `Actual settlement received (${verifiedSettlementOutBn.toString(10)}) is less than minSettlementOut (${minSettlementBn.toString(10)})`);
341
+ }
342
+ const minRequiredAbtFloorBn = quotedAbtBn.muln(1e4 - input.slippageBps).addn(9999).divn(1e4);
343
+ if (minAbtBn.lt(minRequiredAbtFloorBn) || quotedAbtBn.lt(minAbtBn)) throw new _ocap_util_lib_error.CustomError("ZAP_SLIPPAGE_FLOOR_VIOLATION", `minAbtOut (${minAbtBn.toString(10)}) violates slippage floor (${minRequiredAbtFloorBn.toString(10)}) or exceeds quotedAbtOut`);
344
+ this.consumedZapIds.add(zapId);
345
+ const vaultState = this.depositAndAllocate({
346
+ holderDid: recipient,
347
+ amount: verifiedSettlementOutBn.toString(10),
348
+ autoDeployToStrategy: true,
349
+ ofacBlocklist: combinedOfac
350
+ });
351
+ return {
352
+ zapId,
353
+ recipientDid: recipient,
354
+ settlementDepositedToVault: verifiedSettlementOutBn.toString(10),
355
+ abtMintedOnOcap: quotedAbtBn.toString(10),
356
+ vaultState
357
+ };
358
+ }
359
+ getVaultState() {
360
+ const shareholdersObj = {};
361
+ for (const [k, v] of this.shareholders.entries()) shareholdersObj[k] = { ...v };
362
+ return {
363
+ vaultId: this.vaultId,
364
+ settlementToken: this.settlementToken,
365
+ erc4626StrategyVault: this.erc4626StrategyVault,
366
+ liquidBufferBalance: this.liquidBufferBn.toString(10),
367
+ strategyDeployedBalance: this.strategyDeployedBn.toString(10),
368
+ totalPrincipalShares: this.totalPrincipalSharesBn.toString(10),
369
+ accYieldPerShareScaled: this.accYieldPerShareScaledBn.toString(10),
370
+ unclaimedYieldReserve: this.unclaimedYieldReserveBn.toString(10),
371
+ shareholders: shareholdersObj
372
+ };
373
+ }
374
+ };
375
+
376
+ //#endregion
377
+ exports.FORBIDDEN_EXTERNAL_CALL_SELECTORS = FORBIDDEN_EXTERNAL_CALL_SELECTORS;
378
+ exports.MAX_HARVEST_YIELD_BPS = MAX_HARVEST_YIELD_BPS;
379
+ exports.MAX_VAULT_STRATEGY_DEPLOYED_BPS = MAX_VAULT_STRATEGY_DEPLOYED_BPS;
380
+ exports.MAX_ZAP_ABT_PER_SETTLEMENT_SCALAR = MAX_ZAP_ABT_PER_SETTLEMENT_SCALAR;
381
+ exports.MAX_ZAP_PRICE_IMPACT_BPS = MAX_ZAP_PRICE_IMPACT_BPS;
382
+ exports.MIN_VAULT_LIQUID_BUFFER_BPS = MIN_VAULT_LIQUID_BUFFER_BPS;
383
+ exports.OcapArcVaultExternalAdapterEngine = OcapArcVaultExternalAdapterEngine;
@@ -0,0 +1,166 @@
1
+ import { BN } from "@ocap/util";
2
+
3
+ //#region src/arcvault-external-adapter.d.ts
4
+ /** Forbidden raw ERC-20 / Permit2 selectors that could drain vault funds if called on an arbitrary target */
5
+ declare const FORBIDDEN_EXTERNAL_CALL_SELECTORS: Set<string>;
6
+ declare const MIN_VAULT_LIQUID_BUFFER_BPS = 2000;
7
+ declare const MAX_VAULT_STRATEGY_DEPLOYED_BPS = 8000;
8
+ declare const MAX_ZAP_PRICE_IMPACT_BPS = 500;
9
+ declare const MAX_HARVEST_YIELD_BPS = 5000;
10
+ declare const MAX_ZAP_ABT_PER_SETTLEMENT_SCALAR: BN;
11
+ interface ExternalSwapHookInput {
12
+ swapId: string;
13
+ routerAddress: string;
14
+ callSelector: string;
15
+ tokenIn: string;
16
+ tokenOut: string;
17
+ amountIn: string;
18
+ minAmountOut: string;
19
+ preBalanceIn: string;
20
+ postBalanceIn: string;
21
+ preBalanceOut: string;
22
+ postBalanceOut: string;
23
+ ofacBlocklist?: Iterable<string>;
24
+ }
25
+ interface ExternalSwapHookResult {
26
+ swapId: string;
27
+ routerAddress: string;
28
+ tokenIn: string;
29
+ tokenOut: string;
30
+ exactAmountSpent: string;
31
+ actualAmountReceived: string;
32
+ transientApprovalBeforeCall: string;
33
+ transientApprovalAfterCall: string;
34
+ balanceInvariantDigest: string;
35
+ }
36
+ interface ArcVaultShareholderPosition {
37
+ holderDid: string;
38
+ principalShares: string;
39
+ yieldDebtScaled: string;
40
+ accruedUnclaimedYield: string;
41
+ }
42
+ interface ArcVaultLiquidityState {
43
+ vaultId: string;
44
+ settlementToken: string;
45
+ erc4626StrategyVault: string;
46
+ liquidBufferBalance: string;
47
+ strategyDeployedBalance: string;
48
+ totalPrincipalShares: string;
49
+ accYieldPerShareScaled: string;
50
+ unclaimedYieldReserve: string;
51
+ shareholders: Record<string, ArcVaultShareholderPosition>;
52
+ }
53
+ interface UniversalAbtZapInInput {
54
+ zapId: string;
55
+ senderAddress: string;
56
+ recipientDid: string;
57
+ routerAddress: string;
58
+ callSelector: string;
59
+ tokenIn: string;
60
+ amountIn: string;
61
+ quotedSettlementOut: string;
62
+ minSettlementOut: string;
63
+ quotedAbtOut: string;
64
+ minAbtOut: string;
65
+ slippageBps: number;
66
+ preSettlementBalance?: string;
67
+ postSettlementBalance?: string;
68
+ ofacBlocklist?: Iterable<string>;
69
+ }
70
+ interface UniversalAbtZapInResult {
71
+ zapId: string;
72
+ recipientDid: string;
73
+ settlementDepositedToVault: string;
74
+ abtMintedOnOcap: string;
75
+ vaultState: ArcVaultLiquidityState;
76
+ }
77
+ /**
78
+ * ArcVault External Swap Hook + ERC-4626 Non-Commingled Yield Adapter + Universal ABT Zap-In Engine (#1170).
79
+ */
80
+ declare class OcapArcVaultExternalAdapterEngine {
81
+ readonly vaultId: string;
82
+ readonly settlementToken: string;
83
+ readonly abtTokenAddress: string;
84
+ readonly erc4626StrategyVault: string;
85
+ private readonly allowlistedRouters;
86
+ private readonly allowlistedSelectors;
87
+ private readonly consumedSwapIds;
88
+ private readonly consumedZapIds;
89
+ private readonly ofacSet;
90
+ private liquidBufferBn;
91
+ private strategyDeployedBn;
92
+ private totalPrincipalSharesBn;
93
+ private accYieldPerShareScaledBn;
94
+ private unclaimedYieldReserveBn;
95
+ private readonly shareholders;
96
+ constructor(options: {
97
+ vaultId: string;
98
+ settlementToken: string;
99
+ abtTokenAddress: string;
100
+ erc4626StrategyVault: string;
101
+ allowlistedRouters: string[];
102
+ allowlistedSelectors: string[];
103
+ ofacBlocklist?: Iterable<string>;
104
+ });
105
+ private assertNotProtectedProtocolAddress;
106
+ private mergeOfacSet;
107
+ /**
108
+ * Executes an allowlisted external DEX swap (`executeExternalSwap`) with:
109
+ * - Strict router & selector allowlist enforcement (blocking ERC-20 & Permit2 `approve`/`transferFrom`)
110
+ * - Token pair anchor verification (at least one leg must be `settlementToken` or `abtTokenAddress`, and neither leg can be `erc4626StrategyVault` or a router)
111
+ * - Transient exact-amount approval (`amountIn` before call, `0` immediately after call)
112
+ * - Pre/post balance snapshot verification (`actualAmountOut >= minAmountOut` and exact `amountIn` debit)
113
+ */
114
+ executeExternalSwap(input: ExternalSwapHookInput): ExternalSwapHookResult;
115
+ /**
116
+ * Deposits settlement tokens directly into ArcVault, minting 1:1 principal shares for `holderDid`
117
+ * and routing liquidity according to the 20% Liquid Buffer / 80% ERC-4626 Strategy policy.
118
+ */
119
+ depositAndAllocate(params: {
120
+ holderDid: string;
121
+ amount: string;
122
+ autoDeployToStrategy?: boolean;
123
+ ofacBlocklist?: Iterable<string>;
124
+ }): ArcVaultLiquidityState;
125
+ /**
126
+ * Enforces the 20% Liquid Buffer / 80% Allowlisted ERC-4626 Strategy allocation invariant.
127
+ * Uses ceiling division for the 20% minimum liquid buffer so `liquidBufferBalance` is NEVER
128
+ * even 1 wei below 20% of total backing (`liquidBufferBalance + strategyDeployedBalance`).
129
+ */
130
+ rebalanceToTargetAllocation(): ArcVaultLiquidityState;
131
+ /**
132
+ * Withdraws principal shares for `holderDid`. If `withdrawAmount > liquidBufferBalance`,
133
+ * automatically recalls the shortfall from the ERC-4626 strategy adapter AND restores the 20%
134
+ * minimum liquid buffer on the remaining vault backing.
135
+ */
136
+ withdrawWithAutoRecall(params: {
137
+ holderDid: string;
138
+ withdrawAmount: string;
139
+ ofacBlocklist?: Iterable<string>;
140
+ }): {
141
+ withdrawnAmount: string;
142
+ recalledFromStrategy: string;
143
+ vaultState: ArcVaultLiquidityState;
144
+ };
145
+ /**
146
+ * Harvests yield generated by the allowlisted ERC-4626 strategy vault and distributes it
147
+ * in `O(1)` time via `accYieldPerShareScaled` backed 100% by `unclaimedYieldReserve`.
148
+ */
149
+ harvestVaultYield(yieldAmount: string): ArcVaultLiquidityState;
150
+ /**
151
+ * Claims accrued ERC-4626 strategy yield for `holderDid` in `O(1)` time.
152
+ */
153
+ claimVaultYield(holderDid: string, ofacBlocklist?: Iterable<string>): {
154
+ claimedYield: string;
155
+ shareholderPosition: ArcVaultShareholderPosition;
156
+ };
157
+ /**
158
+ * Universal `ABT` Zap-In Funnel (`zapInAndBridge`):
159
+ * Converts arbitrary origin-chain `tokenIn` -> `settlementToken` (deposited & allocated into ArcVault)
160
+ * -> `OCAP ABT` for `recipientDid` with router/selector allowlist, slippage caps, exchange-rate bounds, and OFAC screening.
161
+ */
162
+ zapInAndBridge(input: UniversalAbtZapInInput): UniversalAbtZapInResult;
163
+ getVaultState(): ArcVaultLiquidityState;
164
+ }
165
+ //#endregion
166
+ export { ArcVaultLiquidityState, ArcVaultShareholderPosition, ExternalSwapHookInput, ExternalSwapHookResult, FORBIDDEN_EXTERNAL_CALL_SELECTORS, MAX_HARVEST_YIELD_BPS, MAX_VAULT_STRATEGY_DEPLOYED_BPS, MAX_ZAP_ABT_PER_SETTLEMENT_SCALAR, MAX_ZAP_PRICE_IMPACT_BPS, MIN_VAULT_LIQUID_BUFFER_BPS, OcapArcVaultExternalAdapterEngine, UniversalAbtZapInInput, UniversalAbtZapInResult };