@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,800 @@
1
+ Object.defineProperty(exports, '__esModule', { value: true });
2
+ const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
3
+ let _ocap_mcrypto = require("@ocap/mcrypto");
4
+ let _ocap_util = require("@ocap/util");
5
+ let _ocap_util_lib_error = require("@ocap/util/lib/error");
6
+ let _ocap_state = require("@ocap/state");
7
+ let lodash_cloneDeep = require("lodash/cloneDeep");
8
+ lodash_cloneDeep = require_rolldown_runtime.__toESM(lodash_cloneDeep);
9
+ let _arcblock_did = require("@arcblock/did");
10
+ let lodash_isEqual = require("lodash/isEqual");
11
+ lodash_isEqual = require_rolldown_runtime.__toESM(lodash_isEqual);
12
+
13
+ //#region src/pipes/post-execution-invariant-gate.ts
14
+ const { RoleType } = _ocap_mcrypto.types;
15
+ const ZERO = new _ocap_util.BN(0);
16
+ const CANONICAL_UINT_STRING_PATTERN = /^(?:0|[1-9]\d*)$/;
17
+ const MAX_POST_EXECUTION_WRITE_SET_ENTRIES = 256;
18
+ const TRACKED_STATE_TABLES = [
19
+ "account",
20
+ "stake",
21
+ "token",
22
+ "tokenFactory",
23
+ "asset",
24
+ "factory",
25
+ "delegation",
26
+ "rollup",
27
+ "rollupBlock",
28
+ "evidence",
29
+ "balance"
30
+ ];
31
+ const TX_TYPES_ALLOWED_TO_CREATE_ASSET = new Set([
32
+ "fg:t:create_asset",
33
+ "create_asset",
34
+ "fg:t:mint_asset",
35
+ "mint_asset",
36
+ "fg:t:acquire_asset_v2",
37
+ "acquire_asset_v2",
38
+ "fg:t:acquire_asset_v3",
39
+ "acquire_asset_v3",
40
+ "fg:t:create_token",
41
+ "create_token",
42
+ "fg:t:create_token_factory",
43
+ "create_token_factory",
44
+ "fg:t:update_token_factory",
45
+ "update_token_factory"
46
+ ]);
47
+ const TX_TYPES_ALLOWED_TO_CREATE_TOKEN = new Set([
48
+ "fg:t:create_token",
49
+ "create_token",
50
+ "fg:t:create_token_factory",
51
+ "create_token_factory"
52
+ ]);
53
+ const TX_TYPES_ALLOWED_TO_MUTATE_EXISTING_TOKEN_SUPPLY = new Set([
54
+ "fg:t:mint_token",
55
+ "mint_token",
56
+ "fg:t:burn_token",
57
+ "burn_token"
58
+ ]);
59
+ function createInvariantError(code, message) {
60
+ return new _ocap_util_lib_error.CustomError(code, message, { persist: true });
61
+ }
62
+ /**
63
+ * Canonicalizes a DID or hex address key so that `did:abt:` prefixes and
64
+ * Ethereum hex casing (`0xabc...` vs EIP-55 `0xAbC...`) always map to a single
65
+ * deterministic key across `beforeStates`, `afterStates`, `stateSnapshot`,
66
+ * and token balance maps.
67
+ */
68
+ function normalizeEntityKey(rawKey) {
69
+ if (typeof rawKey !== "string") return "";
70
+ const trimmed = rawKey.trim();
71
+ if (!trimmed) return "";
72
+ const candidate = (trimmed.startsWith("did:abt:") ? trimmed.slice(8) : (0, _ocap_util.toAddress)(trimmed)) || trimmed;
73
+ if (/^0x[0-9a-fA-F]{40}$/.test(candidate)) return _ocap_state.account.ensureChecksumAddress(candidate.toLowerCase());
74
+ return _ocap_state.account.ensureChecksumAddress(candidate);
75
+ }
76
+ function getDidRoleSafe(addr) {
77
+ const norm = normalizeEntityKey(addr);
78
+ if (!norm) return -1;
79
+ try {
80
+ if (!(0, _arcblock_did.isValid)(norm)) return -1;
81
+ return (0, _arcblock_did.toTypeInfo)(norm).role;
82
+ } catch {
83
+ return -1;
84
+ }
85
+ }
86
+ function createEmptyTracker() {
87
+ const beforeStates = /* @__PURE__ */ new Map();
88
+ const afterStates = /* @__PURE__ */ new Map();
89
+ const writtenKeys = /* @__PURE__ */ new Map();
90
+ for (const t of TRACKED_STATE_TABLES) {
91
+ beforeStates.set(t, /* @__PURE__ */ new Map());
92
+ afterStates.set(t, /* @__PURE__ */ new Map());
93
+ writtenKeys.set(t, /* @__PURE__ */ new Set());
94
+ }
95
+ return {
96
+ beforeStates,
97
+ afterStates,
98
+ writtenKeys,
99
+ addressAliases: /* @__PURE__ */ new Map(),
100
+ totalWriteOps: 0,
101
+ unauthorizedDeletions: 0
102
+ };
103
+ }
104
+ function getEntityKey(table, rawKey, stateObj) {
105
+ if (stateObj && typeof stateObj === "object") {
106
+ const rec = stateObj;
107
+ if (typeof rec.address === "string" && rec.address) return normalizeEntityKey(rec.address);
108
+ if ((table === "evidence" || table === "rollupBlock") && typeof rec.hash === "string" && rec.hash) return rec.hash.trim();
109
+ }
110
+ if (typeof rawKey === "string" && rawKey) {
111
+ if (table === "evidence" || table === "rollupBlock") return rawKey.trim();
112
+ return normalizeEntityKey(rawKey);
113
+ }
114
+ return "";
115
+ }
116
+ function findSnapshotEntry(snapshotMap, canonicalKey) {
117
+ if (!snapshotMap || typeof snapshotMap !== "object" || !canonicalKey) return void 0;
118
+ if (snapshotMap[canonicalKey]) return snapshotMap[canonicalKey];
119
+ for (const [k, v] of Object.entries(snapshotMap)) if (normalizeEntityKey(k) === canonicalKey || (0, _ocap_util.isSameDid)(k, canonicalKey)) return v;
120
+ }
121
+ /**
122
+ * Installs a non-mutating Proxy interceptor over `context.statedb` so every
123
+ * state read (`get`) and state write (`create`, `update`, `updateOrCreate`)
124
+ * during protocol execution is captured in `context._stateWriteTracker`.
125
+ *
126
+ * Even if a protocol mutates a state record in `statedb` without assigning the
127
+ * resulting object back onto `context`, the interceptor captures both the
128
+ * pre-mutation snapshot and the post-mutation state for Gate 2 verification.
129
+ */
130
+ function installStateWriteInterceptor(context) {
131
+ const tracker = createEmptyTracker();
132
+ Object.defineProperty(context, "_stateWriteTracker", {
133
+ value: tracker,
134
+ enumerable: false,
135
+ configurable: true,
136
+ writable: true
137
+ });
138
+ const rawStateDb = context.statedb;
139
+ if (!rawStateDb || typeof rawStateDb !== "object") return tracker;
140
+ const underlyingStateDb = rawStateDb._underlyingStateDb || rawStateDb;
141
+ const tableProxies = /* @__PURE__ */ new Map();
142
+ for (const tableName of TRACKED_STATE_TABLES) {
143
+ const origTable = underlyingStateDb[tableName];
144
+ if (!origTable || typeof origTable !== "object") continue;
145
+ const bMap = tracker.beforeStates.get(tableName);
146
+ const aMap = tracker.afterStates.get(tableName);
147
+ const wSet = tracker.writtenKeys.get(tableName);
148
+ const recordBeforeIfAbsent = (canonicalKey, preObj, rawAddress) => {
149
+ if (!canonicalKey) return;
150
+ if (!wSet.has(canonicalKey) && !bMap.has(canonicalKey)) bMap.set(canonicalKey, preObj && typeof preObj === "object" ? (0, lodash_cloneDeep.default)(preObj) : null);
151
+ if (typeof rawAddress === "string" && rawAddress) {
152
+ const normRaw = normalizeEntityKey(rawAddress);
153
+ if (normRaw && normRaw !== canonicalKey) {
154
+ tracker.addressAliases.set(normRaw, canonicalKey);
155
+ tracker.addressAliases.set(rawAddress, canonicalKey);
156
+ }
157
+ }
158
+ };
159
+ const reconcileFinalKeyBeforeState = (tentativeKey, finalKey) => {
160
+ if (!tentativeKey || !finalKey || tentativeKey === finalKey) return;
161
+ tracker.addressAliases.set(tentativeKey, finalKey);
162
+ if (bMap.has(tentativeKey)) {
163
+ const preVal = bMap.get(tentativeKey) ?? null;
164
+ if (!bMap.has(finalKey)) bMap.set(finalKey, preVal);
165
+ if (!wSet.has(tentativeKey)) bMap.delete(tentativeKey);
166
+ }
167
+ };
168
+ const prefetchBeforeState = async (lookupAddr, canonicalKey, fallbackBeforeState, callCtx) => {
169
+ if (!canonicalKey || wSet.has(canonicalKey) || bMap.has(canonicalKey)) return;
170
+ const snapshotMap = context.stateSnapshot;
171
+ const snap = findSnapshotEntry(snapshotMap, canonicalKey);
172
+ if (snap) {
173
+ bMap.set(canonicalKey, (0, lodash_cloneDeep.default)(snap));
174
+ return;
175
+ }
176
+ if (typeof origTable.get === "function" && lookupAddr) try {
177
+ let pre = await origTable.get.call(origTable, lookupAddr, callCtx ?? context);
178
+ if (pre == null && canonicalKey && canonicalKey !== lookupAddr) pre = await origTable.get.call(origTable, canonicalKey, callCtx ?? context);
179
+ const resolvedKey = getEntityKey(tableName, canonicalKey, pre) || canonicalKey;
180
+ recordBeforeIfAbsent(resolvedKey, pre, lookupAddr);
181
+ reconcileFinalKeyBeforeState(canonicalKey, resolvedKey);
182
+ return;
183
+ } catch {}
184
+ if (fallbackBeforeState !== void 0) bMap.set(canonicalKey, fallbackBeforeState && typeof fallbackBeforeState === "object" ? (0, lodash_cloneDeep.default)(fallbackBeforeState) : null);
185
+ };
186
+ const tableProxy = new Proxy(Object.create(origTable), { get(_target, prop) {
187
+ const origVal = Reflect.get(origTable, prop, origTable);
188
+ if (typeof origVal !== "function") return origVal;
189
+ if (prop === "get") return async function interceptedGet(address, ...rest) {
190
+ const res = await origVal.apply(origTable, [address, ...rest]);
191
+ if (Array.isArray(address) && Array.isArray(res)) {
192
+ res.forEach((item, idx) => {
193
+ const reqAddr = address[idx];
194
+ const key$1 = getEntityKey(tableName, reqAddr, item);
195
+ if (key$1) recordBeforeIfAbsent(key$1, item, reqAddr);
196
+ });
197
+ return res;
198
+ }
199
+ const key = getEntityKey(tableName, address, res);
200
+ if (key) recordBeforeIfAbsent(key, res, address);
201
+ return res;
202
+ };
203
+ if (prop === "create") return async function interceptedCreate(address, state, ...rest) {
204
+ const tentativeKey = getEntityKey(tableName, address, state);
205
+ if (tentativeKey) await prefetchBeforeState(typeof address === "string" && address ? address : tentativeKey, tentativeKey, null, rest[0]);
206
+ const res = await origVal.apply(origTable, [
207
+ address,
208
+ state,
209
+ ...rest
210
+ ]);
211
+ const finalObj = res && typeof res === "object" ? res : state;
212
+ const finalKey = getEntityKey(tableName, tentativeKey || address, finalObj);
213
+ if (finalKey && finalObj && typeof finalObj === "object") {
214
+ reconcileFinalKeyBeforeState(tentativeKey, finalKey);
215
+ if (!bMap.has(finalKey)) bMap.set(finalKey, null);
216
+ wSet.add(finalKey);
217
+ aMap.set(finalKey, (0, lodash_cloneDeep.default)(finalObj));
218
+ tracker.totalWriteOps += 1;
219
+ }
220
+ return res;
221
+ };
222
+ if (prop === "update") return async function interceptedUpdate(address, state, ...rest) {
223
+ const rawAddrStr = typeof address === "string" ? address : "";
224
+ const normInput = normalizeEntityKey(rawAddrStr);
225
+ const tentativeKey = getEntityKey(tableName, tracker.addressAliases.get(normInput) || tracker.addressAliases.get(rawAddrStr) || normInput || address, state);
226
+ if (tentativeKey) await prefetchBeforeState(rawAddrStr || tentativeKey, tentativeKey, void 0, rest[0]);
227
+ const res = await origVal.apply(origTable, [
228
+ address,
229
+ state,
230
+ ...rest
231
+ ]);
232
+ const finalObj = res && typeof res === "object" ? res : state;
233
+ const finalKey = getEntityKey(tableName, tentativeKey || address, finalObj);
234
+ if (finalKey && finalObj && typeof finalObj === "object") {
235
+ reconcileFinalKeyBeforeState(tentativeKey, finalKey);
236
+ wSet.add(finalKey);
237
+ aMap.set(finalKey, (0, lodash_cloneDeep.default)(finalObj));
238
+ tracker.totalWriteOps += 1;
239
+ }
240
+ return res;
241
+ };
242
+ if (prop === "updateOrCreate") return async function interceptedUpdateOrCreate(beforeState, state, ...rest) {
243
+ const tentativeKey = getEntityKey(tableName, void 0, state) || getEntityKey(tableName, void 0, beforeState) || "";
244
+ if (tentativeKey) await prefetchBeforeState(tentativeKey, tentativeKey, beforeState ?? null, rest[0]);
245
+ const res = await origVal.apply(origTable, [
246
+ beforeState,
247
+ state,
248
+ ...rest
249
+ ]);
250
+ const finalObj = res && typeof res === "object" ? res : state;
251
+ const finalKey = getEntityKey(tableName, tentativeKey, finalObj);
252
+ if (finalKey && finalObj && typeof finalObj === "object") {
253
+ reconcileFinalKeyBeforeState(tentativeKey, finalKey);
254
+ if (!bMap.has(finalKey)) bMap.set(finalKey, beforeState && typeof beforeState === "object" ? (0, lodash_cloneDeep.default)(beforeState) : null);
255
+ wSet.add(finalKey);
256
+ aMap.set(finalKey, (0, lodash_cloneDeep.default)(finalObj));
257
+ tracker.totalWriteOps += 1;
258
+ }
259
+ return res;
260
+ };
261
+ if (prop === "remove" || prop === "delete" || prop === "destroy" || prop === "clear") return async function interceptedDelete(...args) {
262
+ tracker.unauthorizedDeletions += 1;
263
+ tracker.totalWriteOps += 1;
264
+ return origVal.apply(origTable, args);
265
+ };
266
+ return origVal.bind(origTable);
267
+ } });
268
+ tableProxies.set(tableName, tableProxy);
269
+ }
270
+ const statedbProxy = new Proxy(Object.create(underlyingStateDb), {
271
+ get(_target, prop) {
272
+ if (prop === "_underlyingStateDb") return underlyingStateDb;
273
+ if (typeof prop === "string" && tableProxies.has(prop)) return tableProxies.get(prop);
274
+ const val = Reflect.get(underlyingStateDb, prop, underlyingStateDb);
275
+ return typeof val === "function" ? val.bind(underlyingStateDb) : val;
276
+ },
277
+ set(_target, prop, value) {
278
+ return Reflect.set(underlyingStateDb, prop, value, underlyingStateDb);
279
+ }
280
+ });
281
+ Object.defineProperty(context, "statedb", {
282
+ value: statedbProxy,
283
+ enumerable: true,
284
+ configurable: true,
285
+ writable: true
286
+ });
287
+ return tracker;
288
+ }
289
+ /**
290
+ * Rolls back all tracked `statedb` writes recorded in `context._stateWriteTracker`
291
+ * to their pre-execution `beforeStates` (or deletes newly created records).
292
+ *
293
+ * Used by the non-`runAsLambda` execution fallback path in `execute.ts` when a
294
+ * protocol or Gate 2 (`inspectPostExecutionInvariants`) fails after partial or
295
+ * complete `statedb` writes, guaranteeing that no invariant-violating state
296
+ * remains in `statedb` before `ensureGasFeePaid` runs.
297
+ */
298
+ async function rollbackTrackedStateWrites(context) {
299
+ const tracker = context._stateWriteTracker;
300
+ const rawStateDb = context.statedb;
301
+ if (!rawStateDb || typeof rawStateDb !== "object") return;
302
+ const underlyingStateDb = rawStateDb._underlyingStateDb || rawStateDb;
303
+ if (tracker) for (const tableName of TRACKED_STATE_TABLES) {
304
+ const wSet = tracker.writtenKeys.get(tableName);
305
+ if (!wSet || wSet.size === 0) continue;
306
+ const bMap = tracker.beforeStates.get(tableName);
307
+ const origTable = underlyingStateDb[tableName];
308
+ if (!origTable || typeof origTable !== "object") continue;
309
+ for (const key of wSet) {
310
+ const beforeState = bMap.get(key) ?? null;
311
+ if (beforeState && typeof beforeState === "object") {
312
+ if (typeof origTable.update === "function") await origTable.update.call(origTable, key, (0, lodash_cloneDeep.default)(beforeState), context);
313
+ } else {
314
+ const keyField = tableName === "evidence" || tableName === "rollupBlock" ? "hash" : "address";
315
+ const collection = origTable.collection;
316
+ const mapStore = origTable.store;
317
+ if (typeof origTable.remove === "function") await origTable.remove.call(origTable, key, context);
318
+ else if (typeof origTable.delete === "function") await origTable.delete.call(origTable, key, context);
319
+ else if (collection && typeof collection.removeWhere === "function") collection.removeWhere({ [keyField]: key });
320
+ else if (mapStore instanceof Map) mapStore.delete(key);
321
+ }
322
+ }
323
+ }
324
+ const txFrom = context.tx?.from ? normalizeEntityKey(context.tx.from) : "";
325
+ if (txFrom) {
326
+ const snapSender = tracker?.beforeStates.get("account")?.get(txFrom) ?? findSnapshotEntry(context.stateSnapshot, txFrom);
327
+ if (snapSender) context.senderState = (0, lodash_cloneDeep.default)(snapSender);
328
+ }
329
+ context.gasPaid = false;
330
+ }
331
+ function assertCanonicalNonNegativeUintString(val, label) {
332
+ if (typeof val !== "string" || !CANONICAL_UINT_STRING_PATTERN.test(val)) throw createInvariantError("TOKEN_CONSERVATION_VIOLATION", `Post-Execution Invariant Gate: non-canonical or negative integer string "${String(val)}" in ${label}`);
333
+ const bn = new _ocap_util.BN(val, 10);
334
+ if (bn.isNeg()) throw createInvariantError("TOKEN_CONSERVATION_VIOLATION", `Post-Execution Invariant Gate: negative balance "${val}" in ${label}`);
335
+ return bn;
336
+ }
337
+ function classifyContextStateTable(stateObj) {
338
+ const addr = typeof stateObj.address === "string" ? normalizeEntityKey(stateObj.address) : "";
339
+ if (!addr) return null;
340
+ const role = getDidRoleSafe(addr);
341
+ if (role === RoleType.ROLE_STAKE || "revocable" in stateObj || "revokedTokens" in stateObj) return "stake";
342
+ if (role === RoleType.ROLE_TOKEN_FACTORY || "reserveAddress" in stateObj && "reserveBalance" in stateObj) return "tokenFactory";
343
+ if (role === RoleType.ROLE_TOKEN && ("totalSupply" in stateObj || "symbol" in stateObj)) return "token";
344
+ if (role === RoleType.ROLE_FACTORY || "numMinted" in stateObj && "output" in stateObj && "input" in stateObj) return "factory";
345
+ if (role === RoleType.ROLE_ASSET && ("transferrable" in stateObj || "readonly" in stateObj || "consumedTime" in stateObj) && !("tokens" in stateObj)) return "asset";
346
+ if ("tokens" in stateObj && stateObj.tokens && typeof stateObj.tokens === "object") return "account";
347
+ return null;
348
+ }
349
+ function collectUnifiedBeforeAndAfterStates(context) {
350
+ const tracker = context._stateWriteTracker;
351
+ const beforeByTable = /* @__PURE__ */ new Map();
352
+ const afterByTable = /* @__PURE__ */ new Map();
353
+ for (const t of TRACKED_STATE_TABLES) {
354
+ const bMap = /* @__PURE__ */ new Map();
355
+ const aMap = /* @__PURE__ */ new Map();
356
+ const trackedBefore = tracker?.beforeStates.get(t);
357
+ const trackedAfter = tracker?.afterStates.get(t);
358
+ if (trackedBefore) for (const [rawK, v] of trackedBefore.entries()) {
359
+ const k = t === "evidence" || t === "rollupBlock" ? rawK : normalizeEntityKey(rawK);
360
+ if (k && !bMap.has(k)) bMap.set(k, v);
361
+ }
362
+ if (trackedAfter) for (const [rawK, v] of trackedAfter.entries()) {
363
+ const k = t === "evidence" || t === "rollupBlock" ? rawK : normalizeEntityKey(rawK);
364
+ if (k) aMap.set(k, v);
365
+ }
366
+ beforeByTable.set(t, bMap);
367
+ afterByTable.set(t, aMap);
368
+ }
369
+ const snapshotMap = context.stateSnapshot;
370
+ if (snapshotMap && typeof snapshotMap === "object") for (const [rawAddr, snapState] of Object.entries(snapshotMap)) {
371
+ if (!snapState || typeof snapState !== "object") continue;
372
+ const table = classifyContextStateTable(snapState);
373
+ if (!table) continue;
374
+ const addr = normalizeEntityKey(snapState.address || rawAddr);
375
+ if (!addr) continue;
376
+ const bMap = beforeByTable.get(table);
377
+ if (!bMap.has(addr)) bMap.set(addr, (0, lodash_cloneDeep.default)(snapState));
378
+ }
379
+ let contextMutatedCount = 0;
380
+ for (const [key, val] of Object.entries(context)) {
381
+ if (key === "stateSnapshot" || key === "_stateWriteTracker" || key === "statedb" || key === "config" || key === "tx" || key === "itx") continue;
382
+ const candidates = Array.isArray(val) ? val : [val];
383
+ for (const item of candidates) {
384
+ if (!item || typeof item !== "object") continue;
385
+ const rec = item;
386
+ if (!rec.context || typeof rec.address !== "string") continue;
387
+ const table = classifyContextStateTable(rec);
388
+ if (!table) continue;
389
+ const addr = normalizeEntityKey(rec.address);
390
+ if (!addr) continue;
391
+ const aMap = afterByTable.get(table);
392
+ const bMap = beforeByTable.get(table);
393
+ const wSet = tracker?.writtenKeys.get(table);
394
+ const existingAfter = aMap.get(addr);
395
+ if (!existingAfter) {
396
+ aMap.set(addr, rec);
397
+ if (!bMap.has(addr)) bMap.set(addr, null);
398
+ if (!(0, lodash_isEqual.default)(bMap.get(addr), rec)) contextMutatedCount += 1;
399
+ } else if (!wSet?.has(addr)) {
400
+ if (!(0, lodash_isEqual.default)(bMap.get(addr), rec) || (rec._retrievedAt || 0) >= (existingAfter._retrievedAt || 0)) aMap.set(addr, rec);
401
+ }
402
+ }
403
+ }
404
+ for (const t of TRACKED_STATE_TABLES) {
405
+ const bMap = beforeByTable.get(t);
406
+ const aMap = afterByTable.get(t);
407
+ for (const [addr, bState] of bMap.entries()) if (bState && !aMap.has(addr)) aMap.set(addr, bState);
408
+ }
409
+ let writtenCount = 0;
410
+ if (tracker) {
411
+ for (const wSet of tracker.writtenKeys.values()) writtenCount += wSet.size;
412
+ writtenCount = Math.max(writtenCount, tracker.totalWriteOps, contextMutatedCount);
413
+ } else writtenCount = contextMutatedCount;
414
+ return {
415
+ beforeByTable,
416
+ afterByTable,
417
+ writtenCount
418
+ };
419
+ }
420
+ function normalizeTokenBalanceRecord(rawTokens, label) {
421
+ const result = {};
422
+ if (!rawTokens || typeof rawTokens !== "object") return result;
423
+ for (const [rawTokAddr, rawVal] of Object.entries(rawTokens)) {
424
+ const tokAddr = normalizeEntityKey(rawTokAddr);
425
+ if (!tokAddr) continue;
426
+ const bn = assertCanonicalNonNegativeUintString(rawVal, `${label}[${rawTokAddr}]`);
427
+ if (bn.gt(ZERO)) result[tokAddr] = (result[tokAddr] || ZERO).add(bn);
428
+ }
429
+ return result;
430
+ }
431
+ function getActiveAccountTokens(accountState, label) {
432
+ if (!accountState) return {};
433
+ const result = normalizeTokenBalanceRecord(accountState.tokens, `${label}.tokens`);
434
+ const migratedTo = accountState.migratedTo;
435
+ if (Array.isArray(migratedTo) && migratedTo.length > 0) return {};
436
+ return result;
437
+ }
438
+ function getStakeCombinedTokens(stakeState, label) {
439
+ const result = {};
440
+ if (!stakeState) return result;
441
+ addTokenMapInto(result, normalizeTokenBalanceRecord(stakeState.tokens, `${label}.tokens`));
442
+ addTokenMapInto(result, normalizeTokenBalanceRecord(stakeState.revokedTokens, `${label}.revokedTokens`));
443
+ return result;
444
+ }
445
+ function getTokenFactoryReserveTokens(factoryState, label) {
446
+ const result = {};
447
+ if (!factoryState) return result;
448
+ const reserveAddress = normalizeEntityKey(factoryState.reserveAddress);
449
+ const reserveBalance = factoryState.reserveBalance;
450
+ if (factoryState.currentSupply !== void 0) assertCanonicalNonNegativeUintString(factoryState.currentSupply, `${label}.currentSupply`);
451
+ if (reserveAddress && reserveBalance !== void 0) {
452
+ const bn = assertCanonicalNonNegativeUintString(reserveBalance, `${label}.reserveBalance`);
453
+ if (bn.gt(ZERO)) result[reserveAddress] = (result[reserveAddress] || ZERO).add(bn);
454
+ }
455
+ return result;
456
+ }
457
+ function addTokenMapInto(acc, source) {
458
+ for (const [tok, val] of Object.entries(source)) {
459
+ const normTok = normalizeEntityKey(tok);
460
+ if (!normTok) continue;
461
+ acc[normTok] = (acc[normTok] || ZERO).add(val);
462
+ }
463
+ }
464
+ /**
465
+ * Synchronous/stateless Post-Execution Invariant Gate (Gate 2) verifier.
466
+ *
467
+ * Enforces the 5 Hard Invariants across the transaction's before/after state set:
468
+ * 1. Token Zero-Sum Conservation across `account.tokens + stake.tokens + stake.revokedTokens + tokenFactory.reserveBalance`
469
+ * 2. Official Token (`config.token.address`) Immutable Supply & Non-Negative Canonical Balances
470
+ * 3. Asset Conservation, Non-Destruction (`readonly: true`, `transferrable: false`, `consumedTime`) & Stake Asset Bijection
471
+ * 4. Protocol Stake Protection (`revocable === false` cannot be unlocked or drained)
472
+ * 5. Tombstone Account Protection (`migratedTo.length > 0`), Sender Nonce Monotonicity & RW-Set Containment
473
+ */
474
+ function inspectPostExecutionInvariants(context) {
475
+ const txType = context.txType || "";
476
+ const officialTokenAddress = normalizeEntityKey(context.config?.token?.address || "");
477
+ const maxWriteSetEntries = (context.config?.transaction)?.maxWriteSetSize || MAX_POST_EXECUTION_WRITE_SET_ENTRIES;
478
+ const tracker = context._stateWriteTracker;
479
+ if (tracker && tracker.unauthorizedDeletions > 0) throw createInvariantError("STATE_DELETION_FORBIDDEN", `Post-Execution Invariant Gate: unauthorized state deletion detected (${tracker.unauthorizedDeletions} delete operation(s))`);
480
+ const { beforeByTable, afterByTable, writtenCount } = collectUnifiedBeforeAndAfterStates(context);
481
+ if (writtenCount > maxWriteSetEntries) throw createInvariantError("RW_SET_LIMIT_EXCEEDED", `Post-Execution Invariant Gate: transaction modified ${writtenCount} state entries, exceeding ceiling ${maxWriteSetEntries}`);
482
+ const beforeAccounts = beforeByTable.get("account");
483
+ const afterAccounts = afterByTable.get("account");
484
+ const beforeStakes = beforeByTable.get("stake");
485
+ const afterStakes = afterByTable.get("stake");
486
+ const beforeTokens = beforeByTable.get("token");
487
+ const afterTokens = afterByTable.get("token");
488
+ const beforeFactories = beforeByTable.get("tokenFactory");
489
+ const afterFactories = afterByTable.get("tokenFactory");
490
+ const beforeAssetFactories = beforeByTable.get("factory");
491
+ const afterAssetFactories = afterByTable.get("factory");
492
+ const beforeAssets = beforeByTable.get("asset");
493
+ const afterAssets = afterByTable.get("asset");
494
+ const isAccountMigrateTx = txType === "fg:t:account_migrate" || txType === "account_migrate";
495
+ const txFrom = normalizeEntityKey(context.tx?.from);
496
+ const txNonce = context.tx?.nonce;
497
+ for (const [addr, afterAcc] of afterAccounts.entries()) {
498
+ const beforeAcc = beforeAccounts.get(addr) ?? null;
499
+ const afterMigratedTo = afterAcc.migratedTo || [];
500
+ if (!beforeAcc) {
501
+ if (afterMigratedTo.length > 0) {
502
+ const isDeclaredSender = isAccountMigrateTx && !!txFrom && (0, _ocap_util.isSameDid)(addr, txFrom);
503
+ let hasBalance = false;
504
+ if (isDeclaredSender) {
505
+ const postTokens = normalizeTokenBalanceRecord(afterAcc.tokens, `afterAccount[${addr}].tokens`);
506
+ hasBalance = Object.values(postTokens).some((v) => v.gt(ZERO));
507
+ }
508
+ if (!isDeclaredSender || hasBalance) throw createInvariantError("TOMBSTONE_ACCOUNT_VIOLATION", `Post-Execution Invariant Gate: newly created account ${addr} cannot have non-empty migratedTo`);
509
+ }
510
+ continue;
511
+ }
512
+ const beforeMigratedTo = beforeAcc.migratedTo || [];
513
+ if (beforeMigratedTo.length > 0) {
514
+ const preNormTokens = normalizeTokenBalanceRecord(beforeAcc.tokens, `beforeAccount[${addr}].tokens`);
515
+ const postNormTokens = normalizeTokenBalanceRecord(afterAcc.tokens, `afterAccount[${addr}].tokens`);
516
+ const tokenKeys = new Set([...Object.keys(preNormTokens), ...Object.keys(postNormTokens)]);
517
+ for (const k of tokenKeys) if (!(preNormTokens[k] || ZERO).eq(postNormTokens[k] || ZERO)) throw createInvariantError("TOMBSTONE_ACCOUNT_VIOLATION", `Post-Execution Invariant Gate: cannot mutate token balances on already-migrated tombstone account ${addr}`);
518
+ if (String(beforeAcc.nonce ?? 0) !== String(afterAcc.nonce ?? 0)) throw createInvariantError("TOMBSTONE_ACCOUNT_VIOLATION", `Post-Execution Invariant Gate: cannot mutate nonce on already-migrated tombstone account ${addr}`);
519
+ if (String(beforeAcc.pk ?? "") !== String(afterAcc.pk ?? "")) throw createInvariantError("TOMBSTONE_ACCOUNT_VIOLATION", `Post-Execution Invariant Gate: cannot mutate pk on already-migrated tombstone account ${addr}`);
520
+ if (!isAccountMigrateTx && !(0, lodash_isEqual.default)(beforeMigratedTo, afterMigratedTo)) throw createInvariantError("TOMBSTONE_ACCOUNT_VIOLATION", `Post-Execution Invariant Gate: cannot mutate migratedTo on tombstone account ${addr} outside account_migrate`);
521
+ } else if (afterMigratedTo.length > 0) {
522
+ if (!isAccountMigrateTx || !txFrom || !(0, _ocap_util.isSameDid)(addr, txFrom)) throw createInvariantError("TOMBSTONE_ACCOUNT_VIOLATION", `Post-Execution Invariant Gate: account ${addr} cannot set migratedTo (only tx.from during account_migrate is permitted)`);
523
+ const preTokens = normalizeTokenBalanceRecord(beforeAcc.tokens, `beforeAccount[${addr}].tokens`);
524
+ const postTokens = normalizeTokenBalanceRecord(afterAcc.tokens, `afterAccount[${addr}].tokens`);
525
+ for (const [tok, postBn] of Object.entries(postTokens)) {
526
+ const preBn = preTokens[tok] || ZERO;
527
+ if (postBn.gt(preBn)) throw createInvariantError("TOMBSTONE_ACCOUNT_VIOLATION", `Post-Execution Invariant Gate: newly migrated account ${addr} inflated historical balance for token ${tok}`);
528
+ }
529
+ }
530
+ if (txFrom && (0, _ocap_util.isSameDid)(addr, txFrom) && txNonce !== void 0 && txNonce !== null) {
531
+ const beforeNonceBn = (0, _ocap_state.parseNonceBn)(beforeAcc.nonce) ?? ZERO;
532
+ const afterNonceBn = (0, _ocap_state.parseNonceBn)(afterAcc.nonce);
533
+ if (!afterNonceBn || afterNonceBn.lte(beforeNonceBn)) throw createInvariantError("NONCE_MONOTONICITY_VIOLATION", `Post-Execution Invariant Gate: sender ${addr} nonce must strictly increase (before=${beforeNonceBn.toString(10)}, after=${String(afterAcc.nonce)})`);
534
+ }
535
+ }
536
+ if (txFrom && txNonce !== void 0 && txNonce !== null && writtenCount > 0) {
537
+ const senderWritten = tracker?.writtenKeys.get("account")?.has(txFrom);
538
+ if (beforeAccounts.get(txFrom) && tracker && !senderWritten) throw createInvariantError("NONCE_MONOTONICITY_VIOLATION", `Post-Execution Invariant Gate: existing sender ${txFrom} was not updated during state-mutating transaction`);
539
+ }
540
+ const expectedNetSupplyDelta = {};
541
+ const isMintTokenTx = txType === "fg:t:mint_token" || txType === "mint_token";
542
+ const isBurnTokenTx = txType === "fg:t:burn_token" || txType === "burn_token";
543
+ const isCreateTokenTx = txType === "fg:t:create_token" || txType === "create_token";
544
+ let createdTokenCount = 0;
545
+ for (const [tokAddr, afterTok] of afterTokens.entries()) {
546
+ const beforeTok = beforeTokens.get(tokAddr) ?? null;
547
+ const afterSupply = assertCanonicalNonNegativeUintString(afterTok.totalSupply ?? "0", `token[${tokAddr}].totalSupply`);
548
+ if (beforeTok) {
549
+ const beforeSupply = assertCanonicalNonNegativeUintString(beforeTok.totalSupply ?? "0", `beforeToken[${tokAddr}].totalSupply`);
550
+ const supplyDelta = afterSupply.sub(beforeSupply);
551
+ if (officialTokenAddress && (0, _ocap_util.isSameDid)(tokAddr, officialTokenAddress) && !supplyDelta.isZero()) throw createInvariantError("OFFICIAL_TOKEN_SUPPLY_VIOLATION", `Post-Execution Invariant Gate: official token ${officialTokenAddress} totalSupply is immutable (delta=${supplyDelta.toString(10)})`);
552
+ if (!supplyDelta.isZero()) {
553
+ if (!TX_TYPES_ALLOWED_TO_MUTATE_EXISTING_TOKEN_SUPPLY.has(txType)) throw createInvariantError("TOKEN_CONSERVATION_VIOLATION", `Post-Execution Invariant Gate: txType "${txType}" is not permitted to change totalSupply of existing token ${tokAddr}`);
554
+ if (isMintTokenTx && !supplyDelta.gt(ZERO)) throw createInvariantError("TOKEN_CONSERVATION_VIOLATION", `Post-Execution Invariant Gate: mint_token must strictly increase totalSupply of token ${tokAddr}`);
555
+ if (isBurnTokenTx && !supplyDelta.lt(ZERO)) throw createInvariantError("TOKEN_CONSERVATION_VIOLATION", `Post-Execution Invariant Gate: burn_token must strictly decrease totalSupply of token ${tokAddr}`);
556
+ expectedNetSupplyDelta[tokAddr] = (expectedNetSupplyDelta[tokAddr] || ZERO).add(supplyDelta);
557
+ }
558
+ } else {
559
+ createdTokenCount += 1;
560
+ if (createdTokenCount > 1) throw createInvariantError("TOKEN_CONSERVATION_VIOLATION", "Post-Execution Invariant Gate: cannot create multiple tokens in a single transaction");
561
+ if (officialTokenAddress && (0, _ocap_util.isSameDid)(tokAddr, officialTokenAddress)) throw createInvariantError("OFFICIAL_TOKEN_SUPPLY_VIOLATION", `Post-Execution Invariant Gate: cannot re-create official token ${officialTokenAddress}`);
562
+ if (!TX_TYPES_ALLOWED_TO_CREATE_TOKEN.has(txType)) throw createInvariantError("TOKEN_CONSERVATION_VIOLATION", `Post-Execution Invariant Gate: txType "${txType}" cannot create token ${tokAddr}`);
563
+ if (isCreateTokenTx) {
564
+ const itxObj = context.itx;
565
+ if (itxObj?.address && !(0, _ocap_util.isSameDid)(tokAddr, itxObj.address)) throw createInvariantError("TOKEN_CONSERVATION_VIOLATION", `Post-Execution Invariant Gate: created token ${tokAddr} does not match itx.address ${itxObj.address}`);
566
+ const tokInitSupply = afterTok.initialSupply;
567
+ const itxInitSupply = itxObj?.initialSupply;
568
+ if (tokInitSupply !== void 0 && itxInitSupply !== void 0 && String(tokInitSupply) !== String(itxInitSupply)) throw createInvariantError("TOKEN_CONSERVATION_VIOLATION", `Post-Execution Invariant Gate: token ${tokAddr} initialSupply (${tokInitSupply}) diverges from itx.initialSupply (${itxInitSupply})`);
569
+ const initSupplyBn = assertCanonicalNonNegativeUintString(tokInitSupply ?? itxInitSupply ?? "0", `token[${tokAddr}].initialSupply`);
570
+ if (initSupplyBn.gt(afterSupply)) throw createInvariantError("TOKEN_CONSERVATION_VIOLATION", `Post-Execution Invariant Gate: token ${tokAddr} initialSupply (${initSupplyBn.toString(10)}) exceeds totalSupply (${afterSupply.toString(10)})`);
571
+ expectedNetSupplyDelta[tokAddr] = initSupplyBn;
572
+ } else if (!afterSupply.isZero()) throw createInvariantError("TOKEN_CONSERVATION_VIOLATION", `Post-Execution Invariant Gate: create_token_factory must initialize token ${tokAddr} with totalSupply = 0`);
573
+ }
574
+ }
575
+ const factoryByTokenAddr = /* @__PURE__ */ new Map();
576
+ for (const [factoryAddr, afterFac] of afterFactories.entries()) {
577
+ const beforeFac = beforeFactories.get(factoryAddr) ?? null;
578
+ const afterCurSupply = assertCanonicalNonNegativeUintString(afterFac.currentSupply ?? "0", `tokenFactory[${factoryAddr}].currentSupply`);
579
+ const beforeCurSupply = beforeFac ? assertCanonicalNonNegativeUintString(beforeFac.currentSupply ?? "0", `beforeTokenFactory[${factoryAddr}].currentSupply`) : ZERO;
580
+ const facSupplyDelta = afterCurSupply.sub(beforeCurSupply);
581
+ const facTokenAddr = normalizeEntityKey(afterFac.tokenAddress);
582
+ const facReserveAddr = normalizeEntityKey(afterFac.reserveAddress);
583
+ if (beforeFac) {
584
+ const beforeTokenAddr = normalizeEntityKey(beforeFac.tokenAddress);
585
+ const beforeReserveAddr = normalizeEntityKey(beforeFac.reserveAddress);
586
+ if (beforeTokenAddr && facTokenAddr !== beforeTokenAddr) throw createInvariantError("TOKEN_CONSERVATION_VIOLATION", `Post-Execution Invariant Gate: tokenFactory ${factoryAddr} tokenAddress is immutable`);
587
+ if (beforeReserveAddr && facReserveAddr !== beforeReserveAddr) throw createInvariantError("TOKEN_CONSERVATION_VIOLATION", `Post-Execution Invariant Gate: tokenFactory ${factoryAddr} reserveAddress is immutable`);
588
+ }
589
+ if (facTokenAddr) {
590
+ if (factoryByTokenAddr.has(facTokenAddr) && factoryByTokenAddr.get(facTokenAddr) !== factoryAddr) throw createInvariantError("TOKEN_CONSERVATION_VIOLATION", `Post-Execution Invariant Gate: multiple tokenFactories referencing token ${facTokenAddr}`);
591
+ factoryByTokenAddr.set(facTokenAddr, factoryAddr);
592
+ if (!facSupplyDelta.isZero() || afterTokens.has(facTokenAddr)) {
593
+ const tokSupplyDelta = expectedNetSupplyDelta[facTokenAddr] || ZERO;
594
+ if (!facSupplyDelta.eq(tokSupplyDelta)) throw createInvariantError("TOKEN_CONSERVATION_VIOLATION", `Post-Execution Invariant Gate: tokenFactory ${factoryAddr} currentSupply delta (${facSupplyDelta.toString(10)}) does not match token ${facTokenAddr} totalSupply delta (${tokSupplyDelta.toString(10)})`);
595
+ }
596
+ }
597
+ }
598
+ if (isMintTokenTx || isBurnTokenTx) {
599
+ for (const [tokAddr, delta] of Object.entries(expectedNetSupplyDelta)) if (!delta.isZero() && !factoryByTokenAddr.has(tokAddr)) throw createInvariantError("TOKEN_CONSERVATION_VIOLATION", `Post-Execution Invariant Gate: ${txType} changed totalSupply of token ${tokAddr} without a matching tokenFactory update`);
600
+ }
601
+ const isCreateRollupBlockTx = txType === "fg:t:create_rollup_block" || txType === "create_rollup_block";
602
+ if (isCreateRollupBlockTx) {
603
+ const rollupState = context.rollupState;
604
+ const defaultRollupToken = normalizeEntityKey(rollupState?.tokenAddress || officialTokenAddress);
605
+ const txStates = context.txStates || [];
606
+ const seenRollupTxHashes = /* @__PURE__ */ new Set();
607
+ for (const txItem of txStates) {
608
+ if (txItem?.hash) {
609
+ if (seenRollupTxHashes.has(txItem.hash)) throw createInvariantError("TOKEN_CONSERVATION_VIOLATION", `Post-Execution Invariant Gate: duplicate transaction ${txItem.hash} in create_rollup_block txStates`);
610
+ seenRollupTxHashes.add(txItem.hash);
611
+ }
612
+ if (txItem?.code && txItem.code !== "OK") throw createInvariantError("TOKEN_CONSERVATION_VIOLATION", `Post-Execution Invariant Gate: non-OK transaction (${txItem.code}) in create_rollup_block txStates`);
613
+ const itxJson = txItem?.tx?.itxJson;
614
+ if (!itxJson) continue;
615
+ const tokObj = itxJson.token;
616
+ const tokAddr = normalizeEntityKey(tokObj?.address || defaultRollupToken);
617
+ if (!tokAddr || tokObj?.value === void 0) continue;
618
+ if (defaultRollupToken && !(0, _ocap_util.isSameDid)(tokAddr, defaultRollupToken)) throw createInvariantError("TOKEN_CONSERVATION_VIOLATION", `Post-Execution Invariant Gate: rollup tx token ${tokAddr} does not match rollup token ${defaultRollupToken}`);
619
+ if (txItem.type === "deposit_token_v2") {
620
+ const userVal = assertCanonicalNonNegativeUintString(String(tokObj.value), "rollup.deposit.value");
621
+ const feeVal = assertCanonicalNonNegativeUintString(String(itxJson.actualFee ?? "0"), "rollup.deposit.actualFee");
622
+ expectedNetSupplyDelta[tokAddr] = (expectedNetSupplyDelta[tokAddr] || ZERO).add(userVal).add(feeVal);
623
+ } else if (txItem.type === "withdraw_token_v2") {
624
+ const userVal = assertCanonicalNonNegativeUintString(String(tokObj.value), "rollup.withdraw.value");
625
+ expectedNetSupplyDelta[tokAddr] = (expectedNetSupplyDelta[tokAddr] || ZERO).sub(userVal);
626
+ }
627
+ }
628
+ }
629
+ const totalBeforeTokens = {};
630
+ const totalAfterTokens = {};
631
+ for (const [addr, bAcc] of beforeAccounts.entries()) addTokenMapInto(totalBeforeTokens, getActiveAccountTokens(bAcc, `beforeAccount[${addr}]`));
632
+ for (const [addr, aAcc] of afterAccounts.entries()) addTokenMapInto(totalAfterTokens, getActiveAccountTokens(aAcc, `afterAccount[${addr}]`));
633
+ for (const [addr, bStake] of beforeStakes.entries()) addTokenMapInto(totalBeforeTokens, getStakeCombinedTokens(bStake, `beforeStake[${addr}]`));
634
+ for (const [addr, aStake] of afterStakes.entries()) addTokenMapInto(totalAfterTokens, getStakeCombinedTokens(aStake, `afterStake[${addr}]`));
635
+ for (const [addr, bFac] of beforeFactories.entries()) addTokenMapInto(totalBeforeTokens, getTokenFactoryReserveTokens(bFac, `beforeTokenFactory[${addr}]`));
636
+ for (const [addr, aFac] of afterFactories.entries()) addTokenMapInto(totalAfterTokens, getTokenFactoryReserveTokens(aFac, `afterTokenFactory[${addr}]`));
637
+ for (const [addr, bAssetFac] of beforeAssetFactories.entries()) addTokenMapInto(totalBeforeTokens, getActiveAccountTokens(bAssetFac, `beforeFactory[${addr}]`));
638
+ for (const [addr, aAssetFac] of afterAssetFactories.entries()) addTokenMapInto(totalAfterTokens, getActiveAccountTokens(aAssetFac, `afterFactory[${addr}]`));
639
+ const allTouchedTokenAddresses = new Set([
640
+ ...Object.keys(totalBeforeTokens),
641
+ ...Object.keys(totalAfterTokens),
642
+ ...Object.keys(expectedNetSupplyDelta)
643
+ ]);
644
+ for (const tokAddr of allTouchedTokenAddresses) {
645
+ const beforeSum = totalBeforeTokens[tokAddr] || ZERO;
646
+ const actualContainerDelta = (totalAfterTokens[tokAddr] || ZERO).sub(beforeSum);
647
+ const expectedDelta = expectedNetSupplyDelta[tokAddr] || ZERO;
648
+ if (!actualContainerDelta.eq(expectedDelta)) throw createInvariantError("TOKEN_CONSERVATION_VIOLATION", `Post-Execution Invariant Gate: token ${tokAddr} conservation violated (netContainerDelta=${actualContainerDelta.toString(10)}, expectedSupplyDelta=${expectedDelta.toString(10)})`);
649
+ if (officialTokenAddress && (0, _ocap_util.isSameDid)(tokAddr, officialTokenAddress) && !isCreateRollupBlockTx && !actualContainerDelta.isZero()) throw createInvariantError("OFFICIAL_TOKEN_SUPPLY_VIOLATION", `Post-Execution Invariant Gate: official token ${officialTokenAddress} net container delta must be 0 (got ${actualContainerDelta.toString(10)})`);
650
+ }
651
+ const isCharterOnlyAssetCreationTx = txType === "fg:t:create_token" || txType === "create_token" || txType === "fg:t:create_token_factory" || txType === "create_token_factory" || txType === "fg:t:update_token_factory" || txType === "update_token_factory";
652
+ for (const [assetAddr, afterAssetRec] of afterAssets.entries()) {
653
+ const beforeAssetRec = beforeAssets.get(assetAddr) ?? null;
654
+ const afterAsset = afterAssetRec;
655
+ const afterOwner = normalizeEntityKey(afterAsset.owner);
656
+ if (!beforeAssetRec) {
657
+ if (!TX_TYPES_ALLOWED_TO_CREATE_ASSET.has(txType)) throw createInvariantError("ASSET_CONSERVATION_VIOLATION", `Post-Execution Invariant Gate: txType "${txType}" is not permitted to create asset ${assetAddr}`);
658
+ if (isCharterOnlyAssetCreationTx && !_ocap_state.token.isTokenCharterAsset(afterAsset)) throw createInvariantError("ASSET_CONSERVATION_VIOLATION", `Post-Execution Invariant Gate: ${txType} may only create a Token Charter asset, got ${assetAddr}`);
659
+ if (getDidRoleSafe(afterOwner) === RoleType.ROLE_STAKE) {
660
+ const targetStake = afterStakes.get(afterOwner);
661
+ const stakeAssets = new Set([...targetStake?.assets || [], ...targetStake?.revokedAssets || []].map((x) => normalizeEntityKey(x)));
662
+ if (!targetStake || !stakeAssets.has(assetAddr)) throw createInvariantError("ASSET_CONSERVATION_VIOLATION", `Post-Execution Invariant Gate: asset ${assetAddr} owned by stake ${afterOwner} is missing from stake.assets`);
663
+ }
664
+ } else {
665
+ const beforeAsset = beforeAssetRec;
666
+ const beforeOwner = normalizeEntityKey(beforeAsset.owner);
667
+ if (normalizeEntityKey(afterAsset.address) !== normalizeEntityKey(beforeAsset.address)) throw createInvariantError("ASSET_IMMUTABILITY_VIOLATION", `Post-Execution Invariant Gate: asset ${assetAddr} address cannot be mutated`);
668
+ if (normalizeEntityKey(afterAsset.issuer || "") !== normalizeEntityKey(beforeAsset.issuer || "")) throw createInvariantError("ASSET_IMMUTABILITY_VIOLATION", `Post-Execution Invariant Gate: asset ${assetAddr} issuer cannot be mutated`);
669
+ if (beforeAsset.readonly === true) {
670
+ if (afterAsset.readonly !== true) throw createInvariantError("ASSET_IMMUTABILITY_VIOLATION", `Post-Execution Invariant Gate: readonly asset ${assetAddr} cannot have readonly set to false`);
671
+ if (afterAsset.moniker !== beforeAsset.moniker || !(0, lodash_isEqual.default)(afterAsset.data, beforeAsset.data)) throw createInvariantError("ASSET_IMMUTABILITY_VIOLATION", `Post-Execution Invariant Gate: readonly asset ${assetAddr} cannot have moniker or data mutated`);
672
+ }
673
+ if (beforeAsset.transferrable === false) {
674
+ if (afterAsset.transferrable !== false) throw createInvariantError("ASSET_IMMUTABILITY_VIOLATION", `Post-Execution Invariant Gate: non-transferrable asset ${assetAddr} cannot become transferrable`);
675
+ if (afterOwner !== beforeOwner) throw createInvariantError("ASSET_IMMUTABILITY_VIOLATION", `Post-Execution Invariant Gate: non-transferrable asset ${assetAddr} cannot change owner`);
676
+ }
677
+ if (beforeAsset.consumedTime && String(beforeAsset.consumedTime).trim() !== "") {
678
+ if (afterAsset.consumedTime !== beforeAsset.consumedTime) throw createInvariantError("ASSET_IMMUTABILITY_VIOLATION", `Post-Execution Invariant Gate: already-consumed asset ${assetAddr} cannot un-consume or change consumedTime`);
679
+ const isConsumedStakeExit = (() => {
680
+ if (afterOwner === beforeOwner) return false;
681
+ if (![
682
+ "fg:t:claim_stake",
683
+ "claim_stake",
684
+ "fg:t:return_stake",
685
+ "return_stake"
686
+ ].includes(txType)) return false;
687
+ if (getDidRoleSafe(beforeOwner) !== RoleType.ROLE_STAKE) return false;
688
+ const heldBefore = beforeStakes.get(beforeOwner);
689
+ if (!heldBefore || normalizeEntityKey(heldBefore.address) !== beforeOwner) return false;
690
+ return new Set([...heldBefore.assets || [], ...heldBefore.revokedAssets || []].map((x) => normalizeEntityKey(x))).has(assetAddr) && normalizeEntityKey(heldBefore.sender) === afterOwner;
691
+ })();
692
+ if (afterOwner !== beforeOwner && !isConsumedStakeExit) throw createInvariantError("ASSET_IMMUTABILITY_VIOLATION", `Post-Execution Invariant Gate: already-consumed asset ${assetAddr} cannot be transferred to a new owner`);
693
+ }
694
+ if (afterOwner !== beforeOwner) {
695
+ if (getDidRoleSafe(beforeOwner) === RoleType.ROLE_STAKE) {
696
+ const prevStake = afterStakes.get(beforeOwner);
697
+ const prevStakeAssets = new Set([...prevStake?.assets || [], ...prevStake?.revokedAssets || []].map((x) => normalizeEntityKey(x)));
698
+ if (!prevStake || prevStakeAssets.has(assetAddr)) throw createInvariantError("ASSET_CONSERVATION_VIOLATION", `Post-Execution Invariant Gate: staked asset ${assetAddr} transferred out of stake ${beforeOwner} without removing it from stake state`);
699
+ }
700
+ if (getDidRoleSafe(afterOwner) === RoleType.ROLE_STAKE) {
701
+ const nextStake = afterStakes.get(afterOwner);
702
+ const nextStakeAssets = new Set([...nextStake?.assets || [], ...nextStake?.revokedAssets || []].map((x) => normalizeEntityKey(x)));
703
+ if (!nextStake || !nextStakeAssets.has(assetAddr)) throw createInvariantError("ASSET_CONSERVATION_VIOLATION", `Post-Execution Invariant Gate: asset ${assetAddr} transferred to stake ${afterOwner} without recording it in stake.assets`);
704
+ }
705
+ }
706
+ }
707
+ }
708
+ const isCloseRollupTx = txType === "fg:t:close_rollup" || txType === "close_rollup";
709
+ const isLeaveRollupTx = txType === "fg:t:leave_rollup" || txType === "leave_rollup";
710
+ const isSlashStakeTx = txType === "fg:t:slash_stake" || txType === "slash_stake";
711
+ const isRollupDepositTx = txType === "fg:t:deposit_token_v2" || txType === "deposit_token_v2";
712
+ const isClaimBlockRewardTx = txType === "fg:t:claim_block_reward" || txType === "claim_block_reward";
713
+ for (const [stakeAddr, afterStakeRec] of afterStakes.entries()) {
714
+ const beforeStakeRec = beforeStakes.get(stakeAddr) ?? null;
715
+ const afterStake = afterStakeRec;
716
+ const stakedAssets = (Array.isArray(afterStake.assets) ? afterStake.assets : []).map((x) => normalizeEntityKey(x));
717
+ const revokedAssets = (Array.isArray(afterStake.revokedAssets) ? afterStake.revokedAssets : []).map((x) => normalizeEntityKey(x));
718
+ if (new Set(stakedAssets).size !== stakedAssets.length) throw createInvariantError("ASSET_CONSERVATION_VIOLATION", `Post-Execution Invariant Gate: duplicate asset addresses in stake ${stakeAddr}.assets`);
719
+ if (new Set(revokedAssets).size !== revokedAssets.length) throw createInvariantError("ASSET_CONSERVATION_VIOLATION", `Post-Execution Invariant Gate: duplicate asset addresses in stake ${stakeAddr}.revokedAssets`);
720
+ const stakedSet = new Set(stakedAssets);
721
+ const revokedSet = new Set(revokedAssets);
722
+ for (const revAsset of revokedAssets) if (stakedSet.has(revAsset)) throw createInvariantError("ASSET_CONSERVATION_VIOLATION", `Post-Execution Invariant Gate: asset ${revAsset} appears in both assets and revokedAssets of stake ${stakeAddr}`);
723
+ const beforeStakedAssets = beforeStakeRec ? (Array.isArray(beforeStakeRec.assets) ? beforeStakeRec.assets : []).map((x) => normalizeEntityKey(x)) : [];
724
+ const beforeRevokedAssets = beforeStakeRec ? (Array.isArray(beforeStakeRec.revokedAssets) ? beforeStakeRec.revokedAssets : []).map((x) => normalizeEntityKey(x)) : [];
725
+ const beforeCombinedAssetSet = new Set([...beforeStakedAssets, ...beforeRevokedAssets]);
726
+ const afterCombinedAssetSet = new Set([...stakedAssets, ...revokedAssets]);
727
+ for (const lockedAssetAddr of afterCombinedAssetSet) {
728
+ const trackedAsset = afterAssets.get(lockedAssetAddr);
729
+ if (!beforeCombinedAssetSet.has(lockedAssetAddr) && !trackedAsset) throw createInvariantError("ASSET_CONSERVATION_VIOLATION", `Post-Execution Invariant Gate: asset ${lockedAssetAddr} added to stake ${stakeAddr} without updating asset owner`);
730
+ if (trackedAsset && normalizeEntityKey(trackedAsset.owner) !== stakeAddr) throw createInvariantError("ASSET_CONSERVATION_VIOLATION", `Post-Execution Invariant Gate: staked asset ${lockedAssetAddr} has owner ${trackedAsset.owner} !== stake ${stakeAddr}`);
731
+ }
732
+ for (const prevAssetAddr of beforeCombinedAssetSet) if (!afterCombinedAssetSet.has(prevAssetAddr)) {
733
+ const trackedAsset = afterAssets.get(prevAssetAddr);
734
+ if (!trackedAsset || normalizeEntityKey(trackedAsset.owner) === stakeAddr) throw createInvariantError("ASSET_CONSERVATION_VIOLATION", `Post-Execution Invariant Gate: asset ${prevAssetAddr} removed from stake ${stakeAddr} without transferring asset.owner`);
735
+ }
736
+ if (beforeStakeRec) {
737
+ const beforeStake = beforeStakeRec;
738
+ const beforeSender = normalizeEntityKey(beforeStake.sender || "");
739
+ const afterSender = normalizeEntityKey(afterStake.sender || "");
740
+ const beforeReceiver = normalizeEntityKey(beforeStake.receiver || "");
741
+ const afterReceiver = normalizeEntityKey(afterStake.receiver || "");
742
+ if (beforeSender && afterSender && beforeSender !== afterSender) throw createInvariantError("STAKE_PROTECTION_VIOLATION", `Post-Execution Invariant Gate: stake ${stakeAddr} sender is immutable`);
743
+ if (beforeReceiver && afterReceiver && beforeReceiver !== afterReceiver) throw createInvariantError("STAKE_PROTECTION_VIOLATION", `Post-Execution Invariant Gate: stake ${stakeAddr} receiver is immutable`);
744
+ const receiverAddr = beforeReceiver || afterReceiver;
745
+ const receiverRole = getDidRoleSafe(receiverAddr);
746
+ const isProtocolTokenOrAssetStake = Boolean(officialTokenAddress) && (0, _ocap_util.isSameDid)(receiverAddr, officialTokenAddress) || receiverRole === RoleType.ROLE_TOKEN || receiverRole === RoleType.ROLE_TOKEN_FACTORY || receiverRole === RoleType.ROLE_ASSET;
747
+ const isRollupStake = receiverRole === RoleType.ROLE_ROLLUP && !isProtocolTokenOrAssetStake;
748
+ if (beforeStake.revocable === false) {
749
+ const isAllowedRollupCloseUnlock = (isCloseRollupTx || isLeaveRollupTx) && isRollupStake;
750
+ if (afterStake.revocable !== false && !isAllowedRollupCloseUnlock) throw createInvariantError("STAKE_PROTECTION_VIOLATION", `Post-Execution Invariant Gate: permanently locked stake ${stakeAddr} (revocable=false) cannot be unlocked`);
751
+ if (!isAllowedRollupCloseUnlock) {
752
+ const hasConfiguredSlashers = Array.isArray(beforeStake.slashers) && beforeStake.slashers.length > 0;
753
+ const isAllowedLockedStakeSlash = isSlashStakeTx && !isProtocolTokenOrAssetStake && hasConfiguredSlashers;
754
+ for (const lockedAsset of beforeStakedAssets) if (revokedSet.has(lockedAsset) || !stakedSet.has(lockedAsset) && !isAllowedLockedStakeSlash) throw createInvariantError("STAKE_PROTECTION_VIOLATION", `Post-Execution Invariant Gate: permanently locked stake ${stakeAddr} cannot revoke or drain asset ${lockedAsset}`);
755
+ const preRevokedToks = normalizeTokenBalanceRecord(beforeStake.revokedTokens, `beforeStake[${stakeAddr}].revokedTokens`);
756
+ const postRevokedToks = normalizeTokenBalanceRecord(afterStake.revokedTokens, `afterStake[${stakeAddr}].revokedTokens`);
757
+ for (const [tok, postRevBn] of Object.entries(postRevokedToks)) {
758
+ const preRevBn = preRevokedToks[tok] || ZERO;
759
+ if (postRevBn.gt(preRevBn)) throw createInvariantError("STAKE_PROTECTION_VIOLATION", `Post-Execution Invariant Gate: permanently locked protocol stake ${stakeAddr} cannot move token ${tok} into revokedTokens`);
760
+ }
761
+ if (isProtocolTokenOrAssetStake || !(isRollupStake && (isCreateRollupBlockTx || isRollupDepositTx || isClaimBlockRewardTx)) && !isAllowedLockedStakeSlash) {
762
+ const beforeToks = normalizeTokenBalanceRecord(beforeStake.tokens, `beforeStake[${stakeAddr}].tokens`);
763
+ const afterToks = normalizeTokenBalanceRecord(afterStake.tokens, `afterStake[${stakeAddr}].tokens`);
764
+ for (const [tok, preBn] of Object.entries(beforeToks)) {
765
+ const postBn = afterToks[tok] || ZERO;
766
+ if (postBn.lt(preBn)) throw createInvariantError("STAKE_PROTECTION_VIOLATION", `Post-Execution Invariant Gate: permanently locked protocol stake ${stakeAddr} cannot reduce balance of token ${tok} (before=${preBn.toString(10)}, after=${postBn.toString(10)})`);
767
+ }
768
+ }
769
+ }
770
+ }
771
+ }
772
+ }
773
+ context._postExecutionInvariantVerified = true;
774
+ }
775
+ /**
776
+ * Pipeline pipe wrapper around `inspectPostExecutionInvariants`.
777
+ * Can be used directly in a `Runner` pipeline or invoked by `execute.ts`
778
+ * immediately after `protocol.run` and before `statedb.tx.create`.
779
+ */
780
+ function CreatePostExecutionInvariantGatePipe() {
781
+ return function PostExecutionInvariantGate(context, next) {
782
+ try {
783
+ inspectPostExecutionInvariants(context);
784
+ return next();
785
+ } catch (err) {
786
+ return next(err);
787
+ }
788
+ };
789
+ }
790
+ var post_execution_invariant_gate_default = CreatePostExecutionInvariantGatePipe;
791
+
792
+ //#endregion
793
+ exports.CreatePostExecutionInvariantGatePipe = CreatePostExecutionInvariantGatePipe;
794
+ exports.MAX_POST_EXECUTION_WRITE_SET_ENTRIES = MAX_POST_EXECUTION_WRITE_SET_ENTRIES;
795
+ exports.TRACKED_STATE_TABLES = TRACKED_STATE_TABLES;
796
+ exports.default = post_execution_invariant_gate_default;
797
+ exports.inspectPostExecutionInvariants = inspectPostExecutionInvariants;
798
+ exports.installStateWriteInterceptor = installStateWriteInterceptor;
799
+ exports.normalizeEntityKey = normalizeEntityKey;
800
+ exports.rollbackTrackedStateWrites = rollbackTrackedStateWrites;