@gzeoneth/gov-tracker 0.1.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 (203) hide show
  1. package/LICENSE +191 -0
  2. package/README.md +201 -0
  3. package/dist/abis.d.ts +79 -0
  4. package/dist/abis.d.ts.map +1 -0
  5. package/dist/abis.js +159 -0
  6. package/dist/abis.js.map +1 -0
  7. package/dist/cli/lib/cli.d.ts +92 -0
  8. package/dist/cli/lib/cli.d.ts.map +1 -0
  9. package/dist/cli/lib/cli.js +562 -0
  10. package/dist/cli/lib/cli.js.map +1 -0
  11. package/dist/cli/lib/election-check.d.ts +46 -0
  12. package/dist/cli/lib/election-check.d.ts.map +1 -0
  13. package/dist/cli/lib/election-check.js +136 -0
  14. package/dist/cli/lib/election-check.js.map +1 -0
  15. package/dist/cli/lib/json-state.d.ts +100 -0
  16. package/dist/cli/lib/json-state.d.ts.map +1 -0
  17. package/dist/cli/lib/json-state.js +225 -0
  18. package/dist/cli/lib/json-state.js.map +1 -0
  19. package/dist/cli/monitor.d.ts +3 -0
  20. package/dist/cli/monitor.d.ts.map +1 -0
  21. package/dist/cli/monitor.js +442 -0
  22. package/dist/cli/monitor.js.map +1 -0
  23. package/dist/constants.d.ts +235 -0
  24. package/dist/constants.d.ts.map +1 -0
  25. package/dist/constants.js +293 -0
  26. package/dist/constants.js.map +1 -0
  27. package/dist/discovery/governor-discovery.d.ts +84 -0
  28. package/dist/discovery/governor-discovery.d.ts.map +1 -0
  29. package/dist/discovery/governor-discovery.js +310 -0
  30. package/dist/discovery/governor-discovery.js.map +1 -0
  31. package/dist/discovery/security-council.d.ts +68 -0
  32. package/dist/discovery/security-council.d.ts.map +1 -0
  33. package/dist/discovery/security-council.js +181 -0
  34. package/dist/discovery/security-council.js.map +1 -0
  35. package/dist/discovery/timelock-discovery.d.ts +99 -0
  36. package/dist/discovery/timelock-discovery.d.ts.map +1 -0
  37. package/dist/discovery/timelock-discovery.js +322 -0
  38. package/dist/discovery/timelock-discovery.js.map +1 -0
  39. package/dist/election.d.ts +172 -0
  40. package/dist/election.d.ts.map +1 -0
  41. package/dist/election.js +464 -0
  42. package/dist/election.js.map +1 -0
  43. package/dist/index.d.ts +56 -0
  44. package/dist/index.d.ts.map +1 -0
  45. package/dist/index.js +164 -0
  46. package/dist/index.js.map +1 -0
  47. package/dist/stages/base.d.ts +127 -0
  48. package/dist/stages/base.d.ts.map +1 -0
  49. package/dist/stages/base.js +280 -0
  50. package/dist/stages/base.js.map +1 -0
  51. package/dist/stages/l2-to-l1-message.d.ts +108 -0
  52. package/dist/stages/l2-to-l1-message.d.ts.map +1 -0
  53. package/dist/stages/l2-to-l1-message.js +422 -0
  54. package/dist/stages/l2-to-l1-message.js.map +1 -0
  55. package/dist/stages/proposal-created.d.ts +20 -0
  56. package/dist/stages/proposal-created.d.ts.map +1 -0
  57. package/dist/stages/proposal-created.js +62 -0
  58. package/dist/stages/proposal-created.js.map +1 -0
  59. package/dist/stages/proposal-queued.d.ts +39 -0
  60. package/dist/stages/proposal-queued.d.ts.map +1 -0
  61. package/dist/stages/proposal-queued.js +131 -0
  62. package/dist/stages/proposal-queued.js.map +1 -0
  63. package/dist/stages/retryables.d.ts +79 -0
  64. package/dist/stages/retryables.d.ts.map +1 -0
  65. package/dist/stages/retryables.js +307 -0
  66. package/dist/stages/retryables.js.map +1 -0
  67. package/dist/stages/stage-builder.d.ts +46 -0
  68. package/dist/stages/stage-builder.d.ts.map +1 -0
  69. package/dist/stages/stage-builder.js +87 -0
  70. package/dist/stages/stage-builder.js.map +1 -0
  71. package/dist/stages/timelock.d.ts +100 -0
  72. package/dist/stages/timelock.d.ts.map +1 -0
  73. package/dist/stages/timelock.js +552 -0
  74. package/dist/stages/timelock.js.map +1 -0
  75. package/dist/stages/voting.d.ts +18 -0
  76. package/dist/stages/voting.d.ts.map +1 -0
  77. package/dist/stages/voting.js +109 -0
  78. package/dist/stages/voting.js.map +1 -0
  79. package/dist/tracker/context.d.ts +111 -0
  80. package/dist/tracker/context.d.ts.map +1 -0
  81. package/dist/tracker/context.js +264 -0
  82. package/dist/tracker/context.js.map +1 -0
  83. package/dist/tracker/discovery.d.ts +89 -0
  84. package/dist/tracker/discovery.d.ts.map +1 -0
  85. package/dist/tracker/discovery.js +228 -0
  86. package/dist/tracker/discovery.js.map +1 -0
  87. package/dist/tracker/execute.d.ts +44 -0
  88. package/dist/tracker/execute.d.ts.map +1 -0
  89. package/dist/tracker/execute.js +126 -0
  90. package/dist/tracker/execute.js.map +1 -0
  91. package/dist/tracker/index.d.ts +18 -0
  92. package/dist/tracker/index.d.ts.map +1 -0
  93. package/dist/tracker/index.js +70 -0
  94. package/dist/tracker/index.js.map +1 -0
  95. package/dist/tracker/pipeline.d.ts +47 -0
  96. package/dist/tracker/pipeline.d.ts.map +1 -0
  97. package/dist/tracker/pipeline.js +299 -0
  98. package/dist/tracker/pipeline.js.map +1 -0
  99. package/dist/tracker/query.d.ts +45 -0
  100. package/dist/tracker/query.d.ts.map +1 -0
  101. package/dist/tracker/query.js +159 -0
  102. package/dist/tracker/query.js.map +1 -0
  103. package/dist/tracker/state.d.ts +104 -0
  104. package/dist/tracker/state.d.ts.map +1 -0
  105. package/dist/tracker/state.js +287 -0
  106. package/dist/tracker/state.js.map +1 -0
  107. package/dist/tracker.d.ts +261 -0
  108. package/dist/tracker.d.ts.map +1 -0
  109. package/dist/tracker.js +556 -0
  110. package/dist/tracker.js.map +1 -0
  111. package/dist/types/config.d.ts +81 -0
  112. package/dist/types/config.d.ts.map +1 -0
  113. package/dist/types/config.js +6 -0
  114. package/dist/types/config.js.map +1 -0
  115. package/dist/types/core.d.ts +51 -0
  116. package/dist/types/core.d.ts.map +1 -0
  117. package/dist/types/core.js +6 -0
  118. package/dist/types/core.js.map +1 -0
  119. package/dist/types/cross-chain.d.ts +80 -0
  120. package/dist/types/cross-chain.d.ts.map +1 -0
  121. package/dist/types/cross-chain.js +6 -0
  122. package/dist/types/cross-chain.js.map +1 -0
  123. package/dist/types/election.d.ts +59 -0
  124. package/dist/types/election.d.ts.map +1 -0
  125. package/dist/types/election.js +6 -0
  126. package/dist/types/election.js.map +1 -0
  127. package/dist/types/governor.d.ts +71 -0
  128. package/dist/types/governor.d.ts.map +1 -0
  129. package/dist/types/governor.js +6 -0
  130. package/dist/types/governor.js.map +1 -0
  131. package/dist/types/index.d.ts +22 -0
  132. package/dist/types/index.d.ts.map +1 -0
  133. package/dist/types/index.js +21 -0
  134. package/dist/types/index.js.map +1 -0
  135. package/dist/types/stages.d.ts +189 -0
  136. package/dist/types/stages.d.ts.map +1 -0
  137. package/dist/types/stages.js +23 -0
  138. package/dist/types/stages.js.map +1 -0
  139. package/dist/types/timelock.d.ts +108 -0
  140. package/dist/types/timelock.d.ts.map +1 -0
  141. package/dist/types/timelock.js +6 -0
  142. package/dist/types/timelock.js.map +1 -0
  143. package/dist/types/tracking.d.ts +180 -0
  144. package/dist/types/tracking.d.ts.map +1 -0
  145. package/dist/types/tracking.js +6 -0
  146. package/dist/types/tracking.js.map +1 -0
  147. package/dist/types.d.ts +6 -0
  148. package/dist/types.d.ts.map +1 -0
  149. package/dist/types.js +22 -0
  150. package/dist/types.js.map +1 -0
  151. package/dist/utils/chain.d.ts +18 -0
  152. package/dist/utils/chain.d.ts.map +1 -0
  153. package/dist/utils/chain.js +34 -0
  154. package/dist/utils/chain.js.map +1 -0
  155. package/dist/utils/log-filters.d.ts +67 -0
  156. package/dist/utils/log-filters.d.ts.map +1 -0
  157. package/dist/utils/log-filters.js +116 -0
  158. package/dist/utils/log-filters.js.map +1 -0
  159. package/dist/utils/log-search.d.ts +76 -0
  160. package/dist/utils/log-search.d.ts.map +1 -0
  161. package/dist/utils/log-search.js +142 -0
  162. package/dist/utils/log-search.js.map +1 -0
  163. package/dist/utils/logger.d.ts +41 -0
  164. package/dist/utils/logger.d.ts.map +1 -0
  165. package/dist/utils/logger.js +50 -0
  166. package/dist/utils/logger.js.map +1 -0
  167. package/dist/utils/operation-id.d.ts +48 -0
  168. package/dist/utils/operation-id.d.ts.map +1 -0
  169. package/dist/utils/operation-id.js +102 -0
  170. package/dist/utils/operation-id.js.map +1 -0
  171. package/dist/utils/rpc-utils.d.ts +30 -0
  172. package/dist/utils/rpc-utils.d.ts.map +1 -0
  173. package/dist/utils/rpc-utils.js +99 -0
  174. package/dist/utils/rpc-utils.js.map +1 -0
  175. package/dist/utils/salt-computation.d.ts +78 -0
  176. package/dist/utils/salt-computation.d.ts.map +1 -0
  177. package/dist/utils/salt-computation.js +132 -0
  178. package/dist/utils/salt-computation.js.map +1 -0
  179. package/dist/utils/salt-resolver.d.ts +63 -0
  180. package/dist/utils/salt-resolver.d.ts.map +1 -0
  181. package/dist/utils/salt-resolver.js +144 -0
  182. package/dist/utils/salt-resolver.js.map +1 -0
  183. package/dist/utils/scoped-logger.d.ts +43 -0
  184. package/dist/utils/scoped-logger.d.ts.map +1 -0
  185. package/dist/utils/scoped-logger.js +72 -0
  186. package/dist/utils/scoped-logger.js.map +1 -0
  187. package/dist/utils/stage-helpers.d.ts +51 -0
  188. package/dist/utils/stage-helpers.d.ts.map +1 -0
  189. package/dist/utils/stage-helpers.js +143 -0
  190. package/dist/utils/stage-helpers.js.map +1 -0
  191. package/dist/utils/stage-metadata.d.ts +62 -0
  192. package/dist/utils/stage-metadata.d.ts.map +1 -0
  193. package/dist/utils/stage-metadata.js +140 -0
  194. package/dist/utils/stage-metadata.js.map +1 -0
  195. package/dist/utils/timing.d.ts +115 -0
  196. package/dist/utils/timing.d.ts.map +1 -0
  197. package/dist/utils/timing.js +303 -0
  198. package/dist/utils/timing.js.map +1 -0
  199. package/dist/utils/urls.d.ts +20 -0
  200. package/dist/utils/urls.d.ts.map +1 -0
  201. package/dist/utils/urls.js +51 -0
  202. package/dist/utils/urls.js.map +1 -0
  203. package/package.json +72 -0
@@ -0,0 +1,78 @@
1
+ /**
2
+ * Salt Computation for Timelock Operations
3
+ *
4
+ * Centralized salt computation logic for different proposal types.
5
+ * Salt is computed during tracking and cached in stage data.
6
+ */
7
+ import { ethers, BigNumber } from "ethers";
8
+ import { TrackedStage } from "../types";
9
+ /**
10
+ * Derive salt from a proposal description (Governor pattern)
11
+ *
12
+ * The Governor contract uses `keccak256(bytes(description))` as the salt
13
+ * In Solidity, bytes(string) converts to UTF-8 bytes, which is equivalent to id()
14
+ */
15
+ export declare function saltFromDescription(description: string): string;
16
+ /**
17
+ * Generate salt for a Security Council member update using on-chain contract
18
+ *
19
+ * Calls SecurityCouncilManager.generateSalt() for 100% accuracy.
20
+ *
21
+ * Security Council uses `keccak256(abi.encode(newMembers, nonce))`
22
+ */
23
+ export declare function generateSecurityCouncilSalt(members: string[], nonce: BigNumber, provider: ethers.providers.Provider): Promise<string>;
24
+ /**
25
+ * Decoded L1 timelock schedule call parameters
26
+ */
27
+ export type DecodedTimelockSchedule = {
28
+ type: "single";
29
+ target: string;
30
+ value: BigNumber;
31
+ data: string;
32
+ predecessor: string;
33
+ salt: string;
34
+ delay: BigNumber;
35
+ } | {
36
+ type: "batch";
37
+ targets: string[];
38
+ values: BigNumber[];
39
+ payloads: string[];
40
+ predecessor: string;
41
+ salt: string;
42
+ delay: BigNumber;
43
+ };
44
+ /**
45
+ * Decode L1 timelock schedule call from L2ToL1Tx event data
46
+ *
47
+ * Extracts the actual schedule/scheduleBatch parameters that were sent to L1.
48
+ * This is the ground truth for what was scheduled on L1 timelock.
49
+ *
50
+ * @param l2ToL1TxData - The `data` field from L2ToL1Tx event
51
+ * @returns Decoded schedule parameters or null if not a timelock schedule call
52
+ */
53
+ export declare function decodeL1TimelockSchedule(l2ToL1TxData: string): DecodedTimelockSchedule | null;
54
+ /**
55
+ * Compute salt for L2 timelock stage
56
+ *
57
+ * Priority:
58
+ * 1. Security Council: use on-chain generateSalt(members, nonce)
59
+ * 2. Governor: use keccak256(description)
60
+ * 3. Fallback: HashZero
61
+ */
62
+ export declare function computeL2TimelockSalt(stageData: {
63
+ isSecurityCouncilOperation?: boolean;
64
+ securityCouncilMembers?: string[];
65
+ securityCouncilNonce?: string | number | BigNumber;
66
+ }, allStages?: TrackedStage[], provider?: ethers.providers.Provider): Promise<string>;
67
+ /**
68
+ * Compute salt for L1 timelock stage
69
+ *
70
+ * Priority:
71
+ * 1. Decoded from L2→L1 message event (100% accurate - this is the actual salt sent)
72
+ * 2. Fallback: HashZero
73
+ */
74
+ export declare function computeL1TimelockSalt(allStages?: TrackedStage[]): {
75
+ salt: string;
76
+ predecessor?: string;
77
+ };
78
+ //# sourceMappingURL=salt-computation.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"salt-computation.d.ts","sourceRoot":"","sources":["../../src/utils/salt-computation.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AAC3C,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAKxC;;;;;GAKG;AACH,wBAAgB,mBAAmB,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM,CAE/D;AAED;;;;;;GAMG;AACH,wBAAsB,2BAA2B,CAC/C,OAAO,EAAE,MAAM,EAAE,EACjB,KAAK,EAAE,SAAS,EAChB,QAAQ,EAAE,MAAM,CAAC,SAAS,CAAC,QAAQ,GAClC,OAAO,CAAC,MAAM,CAAC,CASjB;AAED;;GAEG;AACH,MAAM,MAAM,uBAAuB,GAC/B;IACE,IAAI,EAAE,QAAQ,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,SAAS,CAAC;IACjB,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,SAAS,CAAC;CAClB,GACD;IACE,IAAI,EAAE,OAAO,CAAC;IACd,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,MAAM,EAAE,SAAS,EAAE,CAAC;IACpB,QAAQ,EAAE,MAAM,EAAE,CAAC;IACnB,WAAW,EAAE,MAAM,CAAC;IACpB,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,SAAS,CAAC;CAClB,CAAC;AAEN;;;;;;;;GAQG;AACH,wBAAgB,wBAAwB,CAAC,YAAY,EAAE,MAAM,GAAG,uBAAuB,GAAG,IAAI,CA4B7F;AAED;;;;;;;GAOG;AACH,wBAAsB,qBAAqB,CACzC,SAAS,EAAE;IACT,0BAA0B,CAAC,EAAE,OAAO,CAAC;IACrC,sBAAsB,CAAC,EAAE,MAAM,EAAE,CAAC;IAClC,oBAAoB,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAAC;CACpD,EACD,SAAS,CAAC,EAAE,YAAY,EAAE,EAC1B,QAAQ,CAAC,EAAE,MAAM,CAAC,SAAS,CAAC,QAAQ,GACnC,OAAO,CAAC,MAAM,CAAC,CA2BjB;AAED;;;;;;GAMG;AACH,wBAAgB,qBAAqB,CAAC,SAAS,CAAC,EAAE,YAAY,EAAE,GAAG;IACjE,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB,CAiBA"}
@@ -0,0 +1,132 @@
1
+ "use strict";
2
+ /**
3
+ * Salt Computation for Timelock Operations
4
+ *
5
+ * Centralized salt computation logic for different proposal types.
6
+ * Salt is computed during tracking and cached in stage data.
7
+ */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.saltFromDescription = saltFromDescription;
10
+ exports.generateSecurityCouncilSalt = generateSecurityCouncilSalt;
11
+ exports.decodeL1TimelockSchedule = decodeL1TimelockSchedule;
12
+ exports.computeL2TimelockSalt = computeL2TimelockSalt;
13
+ exports.computeL1TimelockSalt = computeL1TimelockSalt;
14
+ const ethers_1 = require("ethers");
15
+ const abis_1 = require("../abis");
16
+ const constants_1 = require("../constants");
17
+ const rpc_utils_1 = require("./rpc-utils");
18
+ /**
19
+ * Derive salt from a proposal description (Governor pattern)
20
+ *
21
+ * The Governor contract uses `keccak256(bytes(description))` as the salt
22
+ * In Solidity, bytes(string) converts to UTF-8 bytes, which is equivalent to id()
23
+ */
24
+ function saltFromDescription(description) {
25
+ return ethers_1.ethers.utils.id(description);
26
+ }
27
+ /**
28
+ * Generate salt for a Security Council member update using on-chain contract
29
+ *
30
+ * Calls SecurityCouncilManager.generateSalt() for 100% accuracy.
31
+ *
32
+ * Security Council uses `keccak256(abi.encode(newMembers, nonce))`
33
+ */
34
+ async function generateSecurityCouncilSalt(members, nonce, provider) {
35
+ const manager = new ethers_1.ethers.Contract(constants_1.ADDRESSES.SECURITY_COUNCIL_MANAGER, abis_1.SECURITY_COUNCIL_MANAGER_ABI, provider);
36
+ // Use contract's generateSalt function for consistency
37
+ return await (0, rpc_utils_1.queryWithRetry)(() => manager.generateSalt(members, nonce));
38
+ }
39
+ /**
40
+ * Decode L1 timelock schedule call from L2ToL1Tx event data
41
+ *
42
+ * Extracts the actual schedule/scheduleBatch parameters that were sent to L1.
43
+ * This is the ground truth for what was scheduled on L1 timelock.
44
+ *
45
+ * @param l2ToL1TxData - The `data` field from L2ToL1Tx event
46
+ * @returns Decoded schedule parameters or null if not a timelock schedule call
47
+ */
48
+ function decodeL1TimelockSchedule(l2ToL1TxData) {
49
+ const timelockInterface = new ethers_1.ethers.utils.Interface(abis_1.TIMELOCK_ABI);
50
+ // Try to decode as scheduleBatch first
51
+ try {
52
+ const batch = timelockInterface.decodeFunctionData("scheduleBatch", l2ToL1TxData);
53
+ return {
54
+ type: "batch",
55
+ targets: batch[0],
56
+ values: batch[1],
57
+ payloads: batch[2],
58
+ predecessor: batch[3],
59
+ salt: batch[4],
60
+ delay: batch[5],
61
+ };
62
+ }
63
+ catch {
64
+ // Not a batch, try single schedule
65
+ const single = timelockInterface.decodeFunctionData("schedule", l2ToL1TxData);
66
+ return {
67
+ type: "single",
68
+ target: single[0],
69
+ value: single[1],
70
+ data: single[2],
71
+ predecessor: single[3],
72
+ salt: single[4],
73
+ delay: single[5],
74
+ };
75
+ }
76
+ }
77
+ /**
78
+ * Compute salt for L2 timelock stage
79
+ *
80
+ * Priority:
81
+ * 1. Security Council: use on-chain generateSalt(members, nonce)
82
+ * 2. Governor: use keccak256(description)
83
+ * 3. Fallback: HashZero
84
+ */
85
+ async function computeL2TimelockSalt(stageData, allStages, provider) {
86
+ // Priority 1: Security Council operation
87
+ if (stageData.isSecurityCouncilOperation &&
88
+ stageData.securityCouncilMembers &&
89
+ stageData.securityCouncilNonce !== undefined &&
90
+ provider) {
91
+ const members = stageData.securityCouncilMembers;
92
+ const nonce = ethers_1.BigNumber.isBigNumber(stageData.securityCouncilNonce)
93
+ ? stageData.securityCouncilNonce
94
+ : ethers_1.BigNumber.from(stageData.securityCouncilNonce);
95
+ // Use on-chain generation for maximum accuracy
96
+ return await generateSecurityCouncilSalt(members, nonce, provider);
97
+ }
98
+ // Priority 2: Governor proposal with description
99
+ if (allStages) {
100
+ const proposalStage = allStages.find((s) => s.type === "PROPOSAL_CREATED");
101
+ if (proposalStage?.data.description) {
102
+ return saltFromDescription(proposalStage.data.description);
103
+ }
104
+ }
105
+ // Priority 3: HashZero fallback
106
+ return ethers_1.ethers.constants.HashZero;
107
+ }
108
+ /**
109
+ * Compute salt for L1 timelock stage
110
+ *
111
+ * Priority:
112
+ * 1. Decoded from L2→L1 message event (100% accurate - this is the actual salt sent)
113
+ * 2. Fallback: HashZero
114
+ */
115
+ function computeL1TimelockSalt(allStages) {
116
+ if (allStages) {
117
+ const l2ToL1Stage = allStages.find((s) => s.type === "L2_TO_L1_MESSAGE");
118
+ if (l2ToL1Stage?.data.l2ToL1TxEvent) {
119
+ // Decode salt and predecessor from the L2ToL1Tx event data
120
+ const decoded = decodeL1TimelockSchedule(l2ToL1Stage.data.l2ToL1TxEvent.data);
121
+ if (decoded) {
122
+ return {
123
+ salt: decoded.salt,
124
+ predecessor: decoded.predecessor,
125
+ };
126
+ }
127
+ }
128
+ }
129
+ // Fallback
130
+ return { salt: ethers_1.ethers.constants.HashZero };
131
+ }
132
+ //# sourceMappingURL=salt-computation.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"salt-computation.js","sourceRoot":"","sources":["../../src/utils/salt-computation.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;AAcH,kDAEC;AASD,kEAaC;AAkCD,4DA4BC;AAUD,sDAmCC;AASD,sDAoBC;AA5KD,mCAA2C;AAE3C,kCAAqE;AACrE,4CAAyC;AACzC,2CAA6C;AAE7C;;;;;GAKG;AACH,SAAgB,mBAAmB,CAAC,WAAmB;IACrD,OAAO,eAAM,CAAC,KAAK,CAAC,EAAE,CAAC,WAAW,CAAC,CAAC;AACtC,CAAC;AAED;;;;;;GAMG;AACI,KAAK,UAAU,2BAA2B,CAC/C,OAAiB,EACjB,KAAgB,EAChB,QAAmC;IAEnC,MAAM,OAAO,GAAG,IAAI,eAAM,CAAC,QAAQ,CACjC,qBAAS,CAAC,wBAAwB,EAClC,mCAA4B,EAC5B,QAAQ,CACT,CAAC;IAEF,uDAAuD;IACvD,OAAO,MAAM,IAAA,0BAAc,EAAC,GAAG,EAAE,CAAC,OAAO,CAAC,YAAY,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC,CAAC;AAC1E,CAAC;AAyBD;;;;;;;;GAQG;AACH,SAAgB,wBAAwB,CAAC,YAAoB;IAC3D,MAAM,iBAAiB,GAAG,IAAI,eAAM,CAAC,KAAK,CAAC,SAAS,CAAC,mBAAY,CAAC,CAAC;IAEnE,uCAAuC;IACvC,IAAI,CAAC;QACH,MAAM,KAAK,GAAG,iBAAiB,CAAC,kBAAkB,CAAC,eAAe,EAAE,YAAY,CAAC,CAAC;QAClF,OAAO;YACL,IAAI,EAAE,OAAO;YACb,OAAO,EAAE,KAAK,CAAC,CAAC,CAAa;YAC7B,MAAM,EAAE,KAAK,CAAC,CAAC,CAAgB;YAC/B,QAAQ,EAAE,KAAK,CAAC,CAAC,CAAa;YAC9B,WAAW,EAAE,KAAK,CAAC,CAAC,CAAW;YAC/B,IAAI,EAAE,KAAK,CAAC,CAAC,C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AC,CAAC;QAC3E,IAAI,aAAa,EAAE,IAAI,CAAC,WAAW,EAAE,CAAC;YACpC,OAAO,mBAAmB,CAAC,aAAa,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;QAC7D,CAAC;IACH,CAAC;IAED,gCAAgC;IAChC,OAAO,eAAM,CAAC,SAAS,CAAC,QAAQ,CAAC;AACnC,CAAC;AAED;;;;;;GAMG;AACH,SAAgB,qBAAqB,CAAC,SAA0B;IAI9D,IAAI,SAAS,EAAE,CAAC;QACd,MAAM,WAAW,GAAG,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,kBAAkB,CAAC,CAAC;QACzE,IAAI,WAAW,EAAE,IAAI,CAAC,aAAa,EAAE,CAAC;YACpC,2DAA2D;YAC3D,MAAM,OAAO,GAAG,wBAAwB,CAAC,WAAW,CAAC,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC;YAC9E,IAAI,OAAO,EAAE,CAAC;gBACZ,OAAO;oBACL,IAAI,EAAE,OAAO,CAAC,IAAI;oBAClB,WAAW,EAAE,OAAO,CAAC,WAAW;iBACjC,CAAC;YACJ,CAAC;QACH,CAAC;IACH,CAAC;IAED,WAAW;IACX,OAAO,EAAE,IAAI,EAAE,eAAM,CAAC,SAAS,CAAC,QAAQ,EAAE,CAAC;AAC7C,CAAC"}
@@ -0,0 +1,63 @@
1
+ /**
2
+ * Salt Resolution for Timelock Execution
3
+ *
4
+ * Salt resolution hierarchy:
5
+ * 1. options.salt (explicit override)
6
+ * 2. stage.data.salt (cached from tracking)
7
+ * 3. Security Council: generateSalt(members, nonce)
8
+ * 4. Governor: keccak256(description)
9
+ * 5. HashZero (0x00...00) - last resort for operations that use default salt
10
+ * 6. FAIL - throw error if no salt matches the operation ID
11
+ *
12
+ * Each resolved salt is validated against the expected operation ID before use.
13
+ * If validation fails, the next option in the hierarchy is tried.
14
+ */
15
+ import { ethers } from "ethers";
16
+ import { PrepareOptions, TrackedStage } from "../types";
17
+ import { saltFromDescription, saltForSecurityCouncil } from "../utils/operation-id";
18
+ export { saltFromDescription, saltForSecurityCouncil };
19
+ /**
20
+ * Resolved prepare options with required salt and predecessor
21
+ */
22
+ export type ResolvedExecuteOptions = Required<Pick<PrepareOptions, "salt" | "predecessor">> & Omit<PrepareOptions, "salt" | "predecessor">;
23
+ /**
24
+ * Candidate salts in priority order for validation
25
+ */
26
+ export interface SaltCandidate {
27
+ salt: string;
28
+ source: "explicit" | "cached" | "security-council" | "description" | "hash-zero";
29
+ }
30
+ /**
31
+ * Get all candidate salts from a TrackedStage in priority order.
32
+ *
33
+ * Returns an array of salt candidates to try, in order of priority.
34
+ * The caller is responsible for validating each salt against the operation ID.
35
+ *
36
+ * @param stage - The stage being prepared (L2_TIMELOCK or L1_TIMELOCK)
37
+ * @param options - Preparation options (can include explicit salt override)
38
+ * @param provider - Provider for on-chain salt generation
39
+ * @param allStages - All tracked stages (used to extract context from other stages)
40
+ */
41
+ export declare function getSaltCandidates(stage: TrackedStage, options?: PrepareOptions, provider?: ethers.providers.Provider, allStages?: TrackedStage[]): Promise<SaltCandidate[]>;
42
+ /**
43
+ * Error thrown when salt cannot be resolved from available sources.
44
+ * This prevents silent failures that would cause mysterious on-chain errors.
45
+ */
46
+ export declare class SaltResolutionError extends Error {
47
+ readonly attemptedSources: SaltCandidate["source"][];
48
+ readonly stageType: string;
49
+ constructor(message: string, attemptedSources: SaltCandidate["source"][], stageType: string);
50
+ }
51
+ /**
52
+ * Get prepare options with resolved salt for a stage.
53
+ *
54
+ * IMPORTANT: Throws SaltResolutionError if salt cannot be resolved from any source.
55
+ *
56
+ * @param stage - The stage being prepared
57
+ * @param options - Preparation options
58
+ * @param provider - Provider for on-chain operations
59
+ * @param allStages - All tracked stages (used to extract context)
60
+ * @throws {SaltResolutionError} if no salt can be resolved
61
+ */
62
+ export declare function resolveExecuteOptionsForStage(stage: TrackedStage, options?: PrepareOptions, provider?: ethers.providers.Provider, allStages?: TrackedStage[]): Promise<ResolvedExecuteOptions>;
63
+ //# sourceMappingURL=salt-resolver.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"salt-resolver.d.ts","sourceRoot":"","sources":["../../src/utils/salt-resolver.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,EAAE,MAAM,EAAa,MAAM,QAAQ,CAAC;AAC3C,OAAO,EAAE,cAAc,EAAE,YAAY,EAAgB,MAAM,UAAU,CAAC;AACtE,OAAO,EAAE,mBAAmB,EAAE,sBAAsB,EAAE,MAAM,uBAAuB,CAAC;AAIpF,OAAO,EAAE,mBAAmB,EAAE,sBAAsB,EAAE,CAAC;AAEvD;;GAEG;AACH,MAAM,MAAM,sBAAsB,GAAG,QAAQ,CAAC,IAAI,CAAC,cAAc,EAAE,MAAM,GAAG,aAAa,CAAC,CAAC,GACzF,IAAI,CAAC,cAAc,EAAE,MAAM,GAAG,aAAa,CAAC,CAAC;AAE/C;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,UAAU,GAAG,QAAQ,GAAG,kBAAkB,GAAG,aAAa,GAAG,WAAW,CAAC;CAClF;AAED;;;;;;;;;;GAUG;AACH,wBAAsB,iBAAiB,CACrC,KAAK,EAAE,YAAY,EACnB,OAAO,GAAE,cAAmB,EAC5B,QAAQ,CAAC,EAAE,MAAM,CAAC,SAAS,CAAC,QAAQ,EACpC,SAAS,CAAC,EAAE,YAAY,EAAE,GACzB,OAAO,CAAC,aAAa,EAAE,CAAC,CAsE1B;AAED;;;GAGG;AACH,qBAAa,mBAAoB,SAAQ,KAAK;aAG1B,gBAAgB,EAAE,aAAa,CAAC,QAAQ,CAAC,EAAE;aAC3C,SAAS,EAAE,MAAM;gBAFjC,OAAO,EAAE,MAAM,EACC,gBAAgB,EAAE,aAAa,CAAC,QAAQ,CAAC,EAAE,EAC3C,SAAS,EAAE,MAAM;CAKpC;AAED;;;;;;;;;;GAUG;AACH,wBAAsB,6BAA6B,CACjD,KAAK,EAAE,YAAY,EACnB,OAAO,GAAE,cAAmB,EAC5B,QAAQ,CAAC,EAAE,MAAM,CAAC,SAAS,CAAC,QAAQ,EACpC,SAAS,CAAC,EAAE,YAAY,EAAE,GACzB,OAAO,CAAC,sBAAsB,CAAC,CA4BjC"}
@@ -0,0 +1,144 @@
1
+ "use strict";
2
+ /**
3
+ * Salt Resolution for Timelock Execution
4
+ *
5
+ * Salt resolution hierarchy:
6
+ * 1. options.salt (explicit override)
7
+ * 2. stage.data.salt (cached from tracking)
8
+ * 3. Security Council: generateSalt(members, nonce)
9
+ * 4. Governor: keccak256(description)
10
+ * 5. HashZero (0x00...00) - last resort for operations that use default salt
11
+ * 6. FAIL - throw error if no salt matches the operation ID
12
+ *
13
+ * Each resolved salt is validated against the expected operation ID before use.
14
+ * If validation fails, the next option in the hierarchy is tried.
15
+ */
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.SaltResolutionError = exports.saltForSecurityCouncil = exports.saltFromDescription = void 0;
18
+ exports.getSaltCandidates = getSaltCandidates;
19
+ exports.resolveExecuteOptionsForStage = resolveExecuteOptionsForStage;
20
+ const ethers_1 = require("ethers");
21
+ const types_1 = require("../types");
22
+ const operation_id_1 = require("../utils/operation-id");
23
+ Object.defineProperty(exports, "saltFromDescription", { enumerable: true, get: function () { return operation_id_1.saltFromDescription; } });
24
+ Object.defineProperty(exports, "saltForSecurityCouncil", { enumerable: true, get: function () { return operation_id_1.saltForSecurityCouncil; } });
25
+ const security_council_1 = require("../discovery/security-council");
26
+ /**
27
+ * Get all candidate salts from a TrackedStage in priority order.
28
+ *
29
+ * Returns an array of salt candidates to try, in order of priority.
30
+ * The caller is responsible for validating each salt against the operation ID.
31
+ *
32
+ * @param stage - The stage being prepared (L2_TIMELOCK or L1_TIMELOCK)
33
+ * @param options - Preparation options (can include explicit salt override)
34
+ * @param provider - Provider for on-chain salt generation
35
+ * @param allStages - All tracked stages (used to extract context from other stages)
36
+ */
37
+ async function getSaltCandidates(stage, options = {}, provider, allStages) {
38
+ const candidates = [];
39
+ // 1. Explicit user override (highest priority)
40
+ if (options.salt) {
41
+ candidates.push({ salt: options.salt, source: "explicit" });
42
+ }
43
+ // Try to get typed stage data from any timelock stage type
44
+ const stageData = (0, types_1.getStageData)(stage, "L2_TIMELOCK") ?? (0, types_1.getStageData)(stage, "L1_TIMELOCK");
45
+ // 2. Cached salt from tracking
46
+ if (stageData?.salt) {
47
+ candidates.push({ salt: stageData.salt, source: "cached" });
48
+ }
49
+ // 3. Decoded salt from L2→L1 message (L1 timelock scheduling call)
50
+ // This is the actual salt that was sent to L1 - 100% accurate!
51
+ // This was decoded during L2_TO_L1_MESSAGE tracking and stored in stage data
52
+ if (allStages && stage.type === "L1_TIMELOCK") {
53
+ const l2ToL1Stage = allStages.find((s) => s.type === "L2_TO_L1_MESSAGE");
54
+ if (l2ToL1Stage) {
55
+ const l2ToL1Data = (0, types_1.getStageData)(l2ToL1Stage, "L2_TO_L1_MESSAGE");
56
+ if (l2ToL1Data?.l1TimelockSalt) {
57
+ candidates.push({ salt: l2ToL1Data.l1TimelockSalt, source: "cached" });
58
+ // Also use the decoded predecessor if available and not overridden
59
+ if (!options.predecessor && l2ToL1Data.l1TimelockPredecessor) {
60
+ options.predecessor = l2ToL1Data.l1TimelockPredecessor;
61
+ }
62
+ }
63
+ }
64
+ }
65
+ // 4. Security Council: use on-chain generation
66
+ // Security Council data is enriched in L2_TIMELOCK stage during tracking
67
+ const members = stageData?.securityCouncilMembers;
68
+ const nonce = stageData?.securityCouncilNonce;
69
+ if (members?.length && nonce !== undefined) {
70
+ const nonceValue = ethers_1.BigNumber.isBigNumber(nonce) ? nonce : ethers_1.BigNumber.from(nonce);
71
+ try {
72
+ const scSalt = provider
73
+ ? await (0, security_council_1.generateSecurityCouncilSalt)(members, nonceValue, provider)
74
+ : (0, operation_id_1.saltForSecurityCouncil)(members, nonceValue);
75
+ candidates.push({ salt: scSalt, source: "security-council" });
76
+ }
77
+ catch {
78
+ // Skip if security council salt generation fails
79
+ }
80
+ }
81
+ // 5. Derive from proposal description
82
+ // Description is stored in PROPOSAL_CREATED stage, extract it if allStages provided
83
+ let description;
84
+ if (allStages) {
85
+ const proposalStage = allStages.find((s) => s.type === "PROPOSAL_CREATED");
86
+ if (proposalStage) {
87
+ const proposalData = (0, types_1.getStageData)(proposalStage, "PROPOSAL_CREATED");
88
+ description = proposalData?.description;
89
+ }
90
+ }
91
+ // Fallback to options or stage data (for backward compatibility)
92
+ description = description ?? options.description ?? stageData?.description;
93
+ if (description) {
94
+ candidates.push({ salt: (0, operation_id_1.saltFromDescription)(description), source: "description" });
95
+ }
96
+ // 6. HashZero as last resort
97
+ candidates.push({ salt: ethers_1.ethers.constants.HashZero, source: "hash-zero" });
98
+ return candidates;
99
+ }
100
+ /**
101
+ * Error thrown when salt cannot be resolved from available sources.
102
+ * This prevents silent failures that would cause mysterious on-chain errors.
103
+ */
104
+ class SaltResolutionError extends Error {
105
+ constructor(message, attemptedSources, stageType) {
106
+ super(message);
107
+ this.attemptedSources = attemptedSources;
108
+ this.stageType = stageType;
109
+ this.name = "SaltResolutionError";
110
+ }
111
+ }
112
+ exports.SaltResolutionError = SaltResolutionError;
113
+ /**
114
+ * Get prepare options with resolved salt for a stage.
115
+ *
116
+ * IMPORTANT: Throws SaltResolutionError if salt cannot be resolved from any source.
117
+ *
118
+ * @param stage - The stage being prepared
119
+ * @param options - Preparation options
120
+ * @param provider - Provider for on-chain operations
121
+ * @param allStages - All tracked stages (used to extract context)
122
+ * @throws {SaltResolutionError} if no salt can be resolved
123
+ */
124
+ async function resolveExecuteOptionsForStage(stage, options = {}, provider, allStages) {
125
+ const candidates = await getSaltCandidates(stage, options, provider, allStages);
126
+ // If only HashZero is available, it means no actual salt source was found
127
+ // This should be an error because we don't know the correct salt
128
+ const hasActualSaltSource = candidates.some((c) => c.source !== "hash-zero");
129
+ if (!hasActualSaltSource) {
130
+ const attemptedSources = candidates.map((c) => c.source);
131
+ throw new SaltResolutionError(`Cannot resolve salt for stage ${stage.type}. ` +
132
+ `Attempted sources: ${attemptedSources.length > 0 ? attemptedSources.join(", ") : "none available"}. ` +
133
+ `Provide an explicit salt via options.salt or ensure stage.data contains the required salt source ` +
134
+ `(description for governor proposals, securityCouncilMembers+nonce for SC updates).`, attemptedSources, stage.type);
135
+ }
136
+ const resolvedSalt = candidates[0]?.salt ?? ethers_1.ethers.constants.HashZero;
137
+ return {
138
+ ...options,
139
+ salt: resolvedSalt,
140
+ predecessor: options.predecessor ?? ethers_1.ethers.constants.HashZero,
141
+ skipSaltValidation: options.skipSaltValidation ?? false,
142
+ };
143
+ }
144
+ //# sourceMappingURL=salt-resolver.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"salt-resolver.js","sourceRoot":"","sources":["../../src/utils/salt-resolver.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;GAaG;;;AAmCH,8CA2EC;AA4BD,sEAiCC;AAzKD,mCAA2C;AAC3C,oCAAsE;AACtE,wDAAoF;AAI3E,oGAJA,kCAAmB,OAIA;AAAE,uGAJA,qCAAsB,OAIA;AAHpD,oEAA4E;AAmB5E;;;;;;;;;;GAUG;AACI,KAAK,UAAU,iBAAiB,CACrC,KAAmB,EACnB,UAA0B,EAAE,EAC5B,QAAoC,EACpC,SAA0B;IAE1B,MAAM,UAAU,GAAoB,EAAE,CAAC;IAEvC,+CAA+C;IAC/C,IAAI,OAAO,CAAC,IAAI,EAAE,CAAC;QACjB,UAAU,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,OAAO,CAAC,IAAI,EAAE,MAAM,EAAE,UAAU,EAAE,CAAC,CAAC;IAC9D,CAAC;IAED,2DAA2D;IAC3D,MAAM,SAAS,GAAG,IAAA,oBAAY,EAAC,KAAK,EAAE,aAAa,CAAC,IAAI,IAAA,oBAAY,EAAC,KAAK,EAAE,aAAa,CAAC,CAAC;IAE3F,+BAA+B;IAC/B,IAAI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AAO,CAAC,kBAAkB,IAAI,KAAK;KACxD,CAAC;AACJ,CAAC"}
@@ -0,0 +1,43 @@
1
+ /**
2
+ * Scoped Logger using AsyncLocalStorage
3
+ *
4
+ * Provides automatic context prefixing for concurrent operations.
5
+ * All log calls within a scope automatically include the scope prefix.
6
+ *
7
+ * Usage:
8
+ * import { withScope, scopedLog } from "./scoped-logger";
9
+ *
10
+ * // Create scoped logger
11
+ * const log = scopedLog("gov-tracker:discovery");
12
+ *
13
+ * // Run with scope - all nested logs get the prefix
14
+ * await withScope("core-gov", async () => {
15
+ * log("discovering..."); // outputs: [core-gov] discovering...
16
+ * await nestedFunction(); // nested calls also get prefix
17
+ * });
18
+ */
19
+ /**
20
+ * Get current scope prefix, or empty string if not in a scope.
21
+ */
22
+ export declare function getCurrentScope(): string;
23
+ /**
24
+ * Run a function within a logging scope.
25
+ * All scopedLog calls within this function (and nested calls) will
26
+ * automatically include the scope prefix.
27
+ *
28
+ * Scopes can be nested - inner scopes override outer scopes.
29
+ */
30
+ export declare function withScope<T>(prefix: string, fn: () => T): T;
31
+ /**
32
+ * Create a scoped debug logger.
33
+ * Returns a function that automatically prepends the current scope.
34
+ *
35
+ * Unlike regular debug loggers, the scope is dynamically determined
36
+ * at call time using AsyncLocalStorage.
37
+ */
38
+ export declare function scopedLog(namespace: string): (fmt: string, ...args: unknown[]) => void;
39
+ /**
40
+ * Create multiple scoped loggers for common namespaces.
41
+ */
42
+ export declare function createScopedLoggers<K extends string>(namespaces: Record<K, string>): Record<K, (fmt: string, ...args: unknown[]) => void>;
43
+ //# sourceMappingURL=scoped-logger.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scoped-logger.d.ts","sourceRoot":"","sources":["../../src/utils/scoped-logger.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAWH;;GAEG;AACH,wBAAgB,eAAe,IAAI,MAAM,CAExC;AAED;;;;;;GAMG;AACH,wBAAgB,SAAS,CAAC,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,CAAC,GAAG,CAAC,CAE3D;AAED;;;;;;GAMG;AACH,wBAAgB,SAAS,CAAC,SAAS,EAAE,MAAM,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,IAAI,CAQtF;AAED;;GAEG;AACH,wBAAgB,mBAAmB,CAAC,CAAC,SAAS,MAAM,EAClD,UAAU,EAAE,MAAM,CAAC,CAAC,EAAE,MAAM,CAAC,GAC5B,MAAM,CAAC,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,IAAI,CAAC,CAMtD"}
@@ -0,0 +1,72 @@
1
+ "use strict";
2
+ /**
3
+ * Scoped Logger using AsyncLocalStorage
4
+ *
5
+ * Provides automatic context prefixing for concurrent operations.
6
+ * All log calls within a scope automatically include the scope prefix.
7
+ *
8
+ * Usage:
9
+ * import { withScope, scopedLog } from "./scoped-logger";
10
+ *
11
+ * // Create scoped logger
12
+ * const log = scopedLog("gov-tracker:discovery");
13
+ *
14
+ * // Run with scope - all nested logs get the prefix
15
+ * await withScope("core-gov", async () => {
16
+ * log("discovering..."); // outputs: [core-gov] discovering...
17
+ * await nestedFunction(); // nested calls also get prefix
18
+ * });
19
+ */
20
+ var __importDefault = (this && this.__importDefault) || function (mod) {
21
+ return (mod && mod.__esModule) ? mod : { "default": mod };
22
+ };
23
+ Object.defineProperty(exports, "__esModule", { value: true });
24
+ exports.getCurrentScope = getCurrentScope;
25
+ exports.withScope = withScope;
26
+ exports.scopedLog = scopedLog;
27
+ exports.createScopedLoggers = createScopedLoggers;
28
+ const async_hooks_1 = require("async_hooks");
29
+ const debug_1 = __importDefault(require("debug"));
30
+ const scopeStorage = new async_hooks_1.AsyncLocalStorage();
31
+ /**
32
+ * Get current scope prefix, or empty string if not in a scope.
33
+ */
34
+ function getCurrentScope() {
35
+ return scopeStorage.getStore()?.prefix ?? "";
36
+ }
37
+ /**
38
+ * Run a function within a logging scope.
39
+ * All scopedLog calls within this function (and nested calls) will
40
+ * automatically include the scope prefix.
41
+ *
42
+ * Scopes can be nested - inner scopes override outer scopes.
43
+ */
44
+ function withScope(prefix, fn) {
45
+ return scopeStorage.run({ prefix }, fn);
46
+ }
47
+ /**
48
+ * Create a scoped debug logger.
49
+ * Returns a function that automatically prepends the current scope.
50
+ *
51
+ * Unlike regular debug loggers, the scope is dynamically determined
52
+ * at call time using AsyncLocalStorage.
53
+ */
54
+ function scopedLog(namespace) {
55
+ const baseLog = (0, debug_1.default)(namespace);
56
+ return (fmt, ...args) => {
57
+ const scope = getCurrentScope();
58
+ const prefix = scope ? `[${scope}] ` : "";
59
+ baseLog(prefix + fmt, ...args);
60
+ };
61
+ }
62
+ /**
63
+ * Create multiple scoped loggers for common namespaces.
64
+ */
65
+ function createScopedLoggers(namespaces) {
66
+ const loggers = {};
67
+ for (const [key, ns] of Object.entries(namespaces)) {
68
+ loggers[key] = scopedLog(ns);
69
+ }
70
+ return loggers;
71
+ }
72
+ //# sourceMappingURL=scoped-logger.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scoped-logger.js","sourceRoot":"","sources":["../../src/utils/scoped-logger.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;GAiBG;;;;;AAcH,0CAEC;AASD,8BAEC;AASD,8BAQC;AAKD,kDAQC;AAvDD,6CAAgD;AAChD,kDAAgC;AAMhC,MAAM,YAAY,GAAG,IAAI,+BAAiB,EAAY,CAAC;AAEvD;;GAEG;AACH,SAAgB,eAAe;IAC7B,OAAO,YAAY,CAAC,QAAQ,EAAE,EAAE,MAAM,IAAI,EAAE,CAAC;AAC/C,CAAC;AAED;;;;;;GAMG;AACH,SAAgB,SAAS,CAAI,MAAc,EAAE,EAAW;IACtD,OAAO,YAAY,CAAC,GAAG,CAAC,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC,CAAC;AAC1C,CAAC;AAED;;;;;;GAMG;AACH,SAAgB,SAAS,CAAC,SAAiB;IACzC,MAAM,OAAO,GAAG,IAAA,eAAW,EAAC,SAAS,CAAC,CAAC;IAEvC,OAAO,CAAC,GAAW,EAAE,GAAG,IAAe,EAAE,EAAE;QACzC,MAAM,KAAK,GAAG,eAAe,EAAE,CAAC;QAChC,MAAM,MAAM,GAAG,KAAK,CAAC,CAAC,CAAC,IAAI,KAAK,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC;QAC1C,OAAO,CAAC,MAAM,GAAG,GAAG,EAAE,GAAG,IAAI,CAAC,CAAC;IACjC,CAAC,CAAC;AACJ,CAAC;AAED;;GAEG;AACH,SAAgB,mBAAmB,CACjC,UAA6B;IAE7B,MAAM,OAAO,GAAG,EAA0D,CAAC;IAC3E,KAAK,MAAM,CAAC,GAAG,EAAE,EAAE,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,UAAU,CAAkB,EAAE,CAAC;QACpE,OAAO,CAAC,GAAG,CAAC,GAAG,SAAS,CAAC,EAAE,CAAC,CAAC;IAC/B,CAAC;IACD,OAAO,OAAO,CAAC;AACjB,CAAC"}
@@ -0,0 +1,51 @@
1
+ /**
2
+ * Stage Helpers
3
+ *
4
+ * Utility functions for timelock stage operations and validation.
5
+ */
6
+ import { ethers } from "ethers";
7
+ import { TrackedStage, PrepareResult, StageType, ChainType, CallScheduledData, TimelockState, OperationState } from "../types";
8
+ export { serialize, deserialize, serializeCallScheduledData, deserializeCallScheduledData, serializeCallScheduledDataArray, deserializeCallScheduledDataArray, } from "../stages/base";
9
+ /** Execution payload data for timelock operations. */
10
+ export interface TimelockExecutionPayload {
11
+ timelockAddress: string;
12
+ operationId: string;
13
+ callScheduledData: CallScheduledData[];
14
+ isSecurityCouncilOperation?: boolean;
15
+ securityCouncilMembers?: string[];
16
+ securityCouncilNonce?: string;
17
+ }
18
+ /** Extract timelock execution payload from a stage. */
19
+ export declare function createTimelockStageData(stage: TrackedStage): TimelockExecutionPayload | null;
20
+ /** Collect all CallScheduledData from a timelock state. */
21
+ export declare function collectAllScheduledData(timelockState: TimelockState): CallScheduledData[];
22
+ /** Calculate ETA for a timelock operation. */
23
+ export declare function calculateTimelockEta(timelockState: TimelockState, operationState: OperationState, provider: ethers.providers.Provider): Promise<number | undefined>;
24
+ /** Build serialized execution payload data for stage storage. */
25
+ export declare function buildExecutionPayloadData(timelockAddress: string, operationId: string, allScheduledData: CallScheduledData[]): Record<string, unknown>;
26
+ export interface PrepareValidationOptions {
27
+ force?: boolean;
28
+ expectedTypes?: StageType[];
29
+ }
30
+ /** Validate stage for preparation. Returns error or null if valid. */
31
+ export declare function validateStageForPrepare(stage: TrackedStage, options?: PrepareValidationOptions): PrepareResult | null;
32
+ export interface BulkPrepareResult<T extends ChainType = ChainType> {
33
+ total: number;
34
+ results: PrepareResult[];
35
+ targetChain: T;
36
+ }
37
+ export interface SimpleBulkResult {
38
+ total: number;
39
+ results: PrepareResult[];
40
+ }
41
+ export declare function bulkPrepareError<T extends ChainType>(error: string, targetChain: T): BulkPrepareResult<T>;
42
+ export declare function simpleBulkError(error: string): SimpleBulkResult;
43
+ export declare function validateStageForBulkPrepare<T extends ChainType>(stage: TrackedStage, targetChain: T, options?: PrepareValidationOptions): BulkPrepareResult<T> | null;
44
+ export declare function validateStageForSimpleBulk(stage: TrackedStage, options?: PrepareValidationOptions): SimpleBulkResult | null;
45
+ /** Search for timelock execution event and complete stage. */
46
+ export declare function searchAndCompleteTimelockExecution(stage: TrackedStage, timelockAddress: string, operationId: string, provider: ethers.providers.Provider, chain: ChainType, fromBlock: number, toBlock?: number, queueTimestamp?: number): Promise<{
47
+ stage: TrackedStage;
48
+ executionTxHash: string | null;
49
+ executionBlock: number | null;
50
+ }>;
51
+ //# sourceMappingURL=stage-helpers.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stage-helpers.d.ts","sourceRoot":"","sources":["../../src/utils/stage-helpers.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAA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