@agenticprimitives/contracts 1.0.0-alpha.5 → 1.0.0-alpha.50

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 (145) hide show
  1. package/AUDIT.md +119 -27
  2. package/README.md +47 -12
  3. package/deployments-base-sepolia.json +52 -1
  4. package/deployments-faithchain.json +103 -0
  5. package/deployments-hopechain.json +78 -0
  6. package/deployments-paymaster-anvil.json +1 -0
  7. package/deployments-registries-base-sepolia.json +1 -0
  8. package/deployments-registries-hopechain.json +1 -0
  9. package/dist/abi/AccountBootstrap.json +99 -0
  10. package/dist/abi/AgentAccount.json +461 -67
  11. package/dist/abi/AgentAccountFactory.json +309 -0
  12. package/dist/abi/AgentNameAttributeResolver.json +212 -0
  13. package/dist/abi/AgentNameRegistry.json +544 -0
  14. package/dist/abi/AgentNameUniversalResolver.json +222 -0
  15. package/dist/abi/AgentProfileResolver.json +236 -0
  16. package/dist/abi/AgentRegistryBase.json +1003 -0
  17. package/dist/abi/AgentRelationship.json +405 -0
  18. package/dist/abi/AgenticGovernance.json +155 -0
  19. package/dist/abi/AgreementRegistry.json +203 -5
  20. package/dist/abi/AllowedMethodsEnforcer.json +193 -0
  21. package/dist/abi/AllowedTargetsEnforcer.json +193 -0
  22. package/dist/abi/ApprovedHashRegistry.json +267 -2
  23. package/dist/abi/AttestationRegistry.json +242 -0
  24. package/dist/abi/AttributeStorage.json +24 -0
  25. package/dist/abi/CallDataHashEnforcer.json +193 -0
  26. package/dist/abi/CustodyPolicy.json +422 -55
  27. package/dist/abi/DelegationManager.json +292 -0
  28. package/dist/abi/DigestBindingEnforcer.json +541 -0
  29. package/dist/abi/Eip7702.json +13 -0
  30. package/dist/abi/EstateProjectionRegistry.json +599 -0
  31. package/dist/abi/Generation5Bridge.json +355 -0
  32. package/dist/abi/GeoFeatureRegistry.json +235 -0
  33. package/dist/abi/IAgentAccountFactoryView.json +26 -0
  34. package/dist/abi/IAgentAccountGovernanceTimelockView.json +15 -0
  35. package/dist/abi/IApprovedHashRegistryWrite.json +35 -0
  36. package/dist/abi/ICustodyEpochView.json +28 -0
  37. package/dist/abi/ICustodyPolicyAccountModuleView.json +31 -0
  38. package/dist/abi/ICustodyPolicyFactoryView.json +13 -0
  39. package/dist/abi/ICustodyPolicyPasskeyView.json +50 -0
  40. package/dist/abi/IDelegationManager.json +18 -0
  41. package/dist/abi/IGeneration4Reads.json +143 -0
  42. package/dist/abi/IGeneration5Account.json +33 -0
  43. package/dist/abi/IGeneration5Voucher.json +26 -0
  44. package/dist/abi/IMoveAccountView.json +57 -0
  45. package/dist/abi/IMoveCustodyView.json +169 -0
  46. package/dist/abi/IMoveFactoryView.json +41 -0
  47. package/dist/abi/IPaymentReceiptRegistry.json +50 -0
  48. package/dist/abi/IRedemptionContext.json +15 -0
  49. package/dist/abi/IRegistryMembershipPolicy.json +70 -0
  50. package/dist/abi/ITimelockVeto.json +93 -0
  51. package/dist/abi/ITreasurySpendPolicyAccountView.json +44 -0
  52. package/dist/abi/IUpgradeVoucherView.json +26 -0
  53. package/dist/abi/MockUSDC.json +621 -0
  54. package/dist/abi/OntologyTermRegistry.json +268 -0
  55. package/dist/abi/PayloadClassesEnforcer.json +310 -0
  56. package/dist/abi/PaymentEnforcer.json +639 -0
  57. package/dist/abi/PaymentEscrow.json +501 -0
  58. package/dist/abi/PaymentReceiptRegistry.json +388 -0
  59. package/dist/abi/PermissionlessSubregistry.json +353 -0
  60. package/dist/abi/PricedSubregistry.json +1141 -0
  61. package/dist/abi/QuorumEnforcer.json +209 -0
  62. package/dist/abi/ReceiptAnchorRegistry.json +346 -0
  63. package/dist/abi/RelationshipTypeRegistry.json +268 -0
  64. package/dist/abi/ShapeRegistry.json +268 -0
  65. package/dist/abi/SignatureVerifier.json +196 -0
  66. package/dist/abi/SkillDefinitionRegistry.json +235 -0
  67. package/dist/abi/SmartAgentPaymaster.json +445 -1
  68. package/dist/abi/StableProxyGoverned.json +190 -0
  69. package/dist/abi/StableProxyGovernedOneShot.json +172 -0
  70. package/dist/abi/TimestampEnforcer.json +193 -0
  71. package/dist/abi/TreasurySpendPolicy.json +667 -0
  72. package/dist/abi/UpgradeVoucher.json +328 -0
  73. package/dist/abi/ValueEnforcer.json +193 -0
  74. package/dist/abi/index.d.ts +35 -0
  75. package/dist/abi/index.js +35 -0
  76. package/dist/deployments/base-sepolia.d.ts +11 -0
  77. package/dist/deployments/base-sepolia.js +51 -28
  78. package/dist/deployments/faithchain.d.ts +77 -0
  79. package/dist/deployments/faithchain.js +107 -0
  80. package/dist/deployments/hopechain.d.ts +68 -0
  81. package/dist/deployments/hopechain.js +82 -0
  82. package/dist/deployments/index.d.ts +7 -2
  83. package/dist/deployments/index.js +15 -0
  84. package/dist/deployments/paymaster-anvil.d.ts +11 -0
  85. package/dist/deployments/paymaster-anvil.js +9 -0
  86. package/dist/deployments/registries-base-sepolia.d.ts +10 -0
  87. package/dist/deployments/registries-base-sepolia.js +8 -0
  88. package/dist/deployments/registries-hopechain.d.ts +10 -0
  89. package/dist/deployments/registries-hopechain.js +8 -0
  90. package/package.json +37 -7
  91. package/src/AccountBootstrap.sol +38 -0
  92. package/src/AgentAccount.sol +1091 -134
  93. package/src/AgentAccountFactory.sol +198 -21
  94. package/src/ApprovedHashRegistry.sol +134 -10
  95. package/src/IAgentAccount.sol +37 -0
  96. package/src/SmartAgentPaymaster.sol +275 -22
  97. package/src/UniversalSignatureValidator.sol +7 -0
  98. package/src/UpgradeVoucher.sol +87 -0
  99. package/src/agency/DelegationManager.sol +299 -76
  100. package/src/agency/ICaveatEnforcer.sol +10 -0
  101. package/src/agency/IDelegationManager.sol +37 -5
  102. package/src/agreement/AgreementRegistry.sol +105 -35
  103. package/src/attestation/AttestationRegistry.sol +220 -40
  104. package/src/custody/CustodyPolicy.sol +588 -70
  105. package/src/custody/TreasurySpendPolicy.sol +338 -0
  106. package/src/enforcers/AllowedMethodsEnforcer.sol +13 -2
  107. package/src/enforcers/AllowedTargetsEnforcer.sol +13 -2
  108. package/src/enforcers/CallDataHashEnforcer.sol +7 -1
  109. package/src/enforcers/DigestBindingEnforcer.sol +182 -0
  110. package/src/enforcers/PayloadClassesEnforcer.sol +36 -0
  111. package/src/enforcers/PaymentEnforcer.sol +291 -0
  112. package/src/enforcers/QuorumEnforcer.sol +24 -3
  113. package/src/enforcers/TimestampEnforcer.sol +7 -1
  114. package/src/enforcers/ValueEnforcer.sol +13 -2
  115. package/src/geo/GeoFeatureRegistry.sol +67 -22
  116. package/src/governance/AgenticGovernance.sol +187 -4
  117. package/src/governance/GovernanceManaged.sol +2 -0
  118. package/src/governance/StableProxyGoverned.sol +79 -0
  119. package/src/governance/StableProxyGovernedOneShot.sol +93 -0
  120. package/src/identity/AgentProfilePredicates.sol +23 -0
  121. package/src/identity/AgentProfileResolver.sol +22 -2
  122. package/src/libraries/Eip7702.sol +36 -0
  123. package/src/libraries/SignatureSlotRecovery.sol +28 -7
  124. package/src/libraries/SignatureVerifier.sol +52 -0
  125. package/src/libraries/WebAuthnLib.sol +16 -0
  126. package/src/migration/Generation5Bridge.sol +364 -0
  127. package/src/mocks/MockUSDC.sol +152 -0
  128. package/src/naming/AgentNameAttributeResolver.sol +29 -4
  129. package/src/naming/AgentNamePredicates.sol +89 -0
  130. package/src/naming/AgentNameRegistry.sol +324 -20
  131. package/src/naming/AgentNameUniversalResolver.sol +35 -2
  132. package/src/naming/PermissionlessSubregistry.sol +82 -25
  133. package/src/naming/PricedSubregistry.sol +293 -0
  134. package/src/ontology/AttributeStorage.sol +93 -80
  135. package/src/ontology/OntologyTermRegistry.sol +58 -2
  136. package/src/ontology/ShapeRegistry.sol +58 -2
  137. package/src/payments/PaymentEscrow.sol +187 -0
  138. package/src/payments/PaymentReceiptRegistry.sol +100 -0
  139. package/src/provenance/ReceiptAnchorRegistry.sol +67 -0
  140. package/src/registry/AgentRegistryBase.sol +372 -0
  141. package/src/registry/EstateProjectionRegistry.sol +177 -0
  142. package/src/registry/IRegistryMembershipPolicy.sol +30 -0
  143. package/src/relationships/AgentRelationship.sol +129 -8
  144. package/src/relationships/RelationshipTypeRegistry.sol +58 -2
  145. package/src/skills/SkillDefinitionRegistry.sol +61 -17
@@ -86,97 +86,91 @@ abstract contract AttributeStorage {
86
86
  function DT_ADDRESS_ARR_PUB() external pure returns (uint8) { return DT_ADDRESS_ARR; }
87
87
  function DT_BYTES32_ARR_PUB() external pure returns (uint8) { return DT_BYTES32_ARR; }
88
88
 
89
+ // ─── Storage key (spec 445 / REG-4) ─────────────────────────────
90
+
91
+ /// @notice The key a subject's VALUES are stored under. Identity by default. A subclass whose subject can
92
+ /// change hands (a name node) overrides this to fold in an owner epoch, so a record written by a
93
+ /// previous owner is unreachable for the next one WITHOUT a delete loop and without a log scan:
94
+ /// every setter and every getter goes through this one function, so a read can never see a value
95
+ /// the current key did not write. Enumeration (`allSubjects`) and the version watermark stay keyed
96
+ /// by the OUTWARD subject — they are indexes, not records.
97
+ function _storageKey(bytes32 subject) internal view virtual returns (bytes32) {
98
+ return subject;
99
+ }
100
+
89
101
  // ─── Internal setters (subclass-only) ───────────────────────────
90
102
 
91
103
  function _setString(bytes32 subject, bytes32 predicate, string memory value) internal {
92
- _requirePredicate(predicate);
93
- _string[subject][predicate] = value;
94
- _record(subject, predicate, DT_STRING);
104
+ bytes32 k = _write(subject, predicate, DT_STRING, false);
105
+ _string[k][predicate] = value;
95
106
  }
96
107
 
97
108
  function _setAddress(bytes32 subject, bytes32 predicate, address value) internal {
98
- _requirePredicate(predicate);
99
- _address[subject][predicate] = value;
100
- _record(subject, predicate, DT_ADDRESS);
109
+ bytes32 k = _write(subject, predicate, DT_ADDRESS, false);
110
+ _address[k][predicate] = value;
101
111
  }
102
112
 
103
113
  function _setBool(bytes32 subject, bytes32 predicate, bool value) internal {
104
- _requirePredicate(predicate);
105
- _bool[subject][predicate] = value;
106
- _record(subject, predicate, DT_BOOL);
114
+ bytes32 k = _write(subject, predicate, DT_BOOL, false);
115
+ _bool[k][predicate] = value;
107
116
  }
108
117
 
109
118
  function _setUint(bytes32 subject, bytes32 predicate, uint256 value) internal {
110
- _requirePredicate(predicate);
111
- _uint[subject][predicate] = value;
112
- _record(subject, predicate, DT_UINT256);
119
+ bytes32 k = _write(subject, predicate, DT_UINT256, false);
120
+ _uint[k][predicate] = value;
113
121
  }
114
122
 
115
123
  function _setBytes32(bytes32 subject, bytes32 predicate, bytes32 value) internal {
116
- _requirePredicate(predicate);
117
- _bytes32[subject][predicate] = value;
118
- _record(subject, predicate, DT_BYTES32);
124
+ bytes32 k = _write(subject, predicate, DT_BYTES32, false);
125
+ _bytes32[k][predicate] = value;
119
126
  }
120
127
 
121
128
  function _setStringArr(bytes32 subject, bytes32 predicate, string[] memory values) internal {
122
- _requirePredicate(predicate);
123
- delete _stringArr[subject][predicate];
129
+ bytes32 k = _write(subject, predicate, DT_STRING_ARR, false);
130
+ delete _stringArr[k][predicate];
124
131
  for (uint256 i = 0; i < values.length; i++) {
125
- _stringArr[subject][predicate].push(values[i]);
132
+ _stringArr[k][predicate].push(values[i]);
126
133
  }
127
- _record(subject, predicate, DT_STRING_ARR);
128
134
  }
129
135
 
130
136
  function _setAddressArr(bytes32 subject, bytes32 predicate, address[] memory values) internal {
131
- _requirePredicate(predicate);
132
- delete _addressArr[subject][predicate];
137
+ bytes32 k = _write(subject, predicate, DT_ADDRESS_ARR, false);
138
+ delete _addressArr[k][predicate];
133
139
  for (uint256 i = 0; i < values.length; i++) {
134
- _addressArr[subject][predicate].push(values[i]);
140
+ _addressArr[k][predicate].push(values[i]);
135
141
  }
136
- _record(subject, predicate, DT_ADDRESS_ARR);
137
142
  }
138
143
 
139
144
  function _setBytes32Arr(bytes32 subject, bytes32 predicate, bytes32[] memory values) internal {
140
- _requirePredicate(predicate);
141
- delete _bytes32Arr[subject][predicate];
145
+ bytes32 k = _write(subject, predicate, DT_BYTES32_ARR, false);
146
+ delete _bytes32Arr[k][predicate];
142
147
  for (uint256 i = 0; i < values.length; i++) {
143
- _bytes32Arr[subject][predicate].push(values[i]);
148
+ _bytes32Arr[k][predicate].push(values[i]);
144
149
  }
145
- _record(subject, predicate, DT_BYTES32_ARR);
146
150
  }
147
151
 
148
152
  function _appendString(bytes32 subject, bytes32 predicate, string memory value) internal {
149
- _requirePredicate(predicate);
150
- _stringArr[subject][predicate].push(value);
151
- _recordAppend(subject, predicate, DT_STRING_ARR);
153
+ bytes32 k = _write(subject, predicate, DT_STRING_ARR, true);
154
+ _stringArr[k][predicate].push(value);
152
155
  }
153
156
 
154
157
  function _appendAddress(bytes32 subject, bytes32 predicate, address value) internal {
155
- _requirePredicate(predicate);
156
- _addressArr[subject][predicate].push(value);
157
- _recordAppend(subject, predicate, DT_ADDRESS_ARR);
158
+ bytes32 k = _write(subject, predicate, DT_ADDRESS_ARR, true);
159
+ _addressArr[k][predicate].push(value);
158
160
  }
159
161
 
160
162
  function _appendBytes32(bytes32 subject, bytes32 predicate, bytes32 value) internal {
161
- _requirePredicate(predicate);
162
- _bytes32Arr[subject][predicate].push(value);
163
- _recordAppend(subject, predicate, DT_BYTES32_ARR);
163
+ bytes32 k = _write(subject, predicate, DT_BYTES32_ARR, true);
164
+ _bytes32Arr[k][predicate].push(value);
164
165
  }
165
166
 
166
167
  function _unset(bytes32 subject, bytes32 predicate) internal {
167
- if (!_isSet[subject][predicate]) revert AttributeNotSet();
168
- uint8 dt = _datatype[subject][predicate];
169
- if (dt == DT_STRING) delete _string[subject][predicate];
170
- else if (dt == DT_ADDRESS) delete _address[subject][predicate];
171
- else if (dt == DT_BOOL) delete _bool[subject][predicate];
172
- else if (dt == DT_UINT256) delete _uint[subject][predicate];
173
- else if (dt == DT_BYTES32) delete _bytes32[subject][predicate];
174
- else if (dt == DT_STRING_ARR) delete _stringArr[subject][predicate];
175
- else if (dt == DT_ADDRESS_ARR) delete _addressArr[subject][predicate];
176
- else if (dt == DT_BYTES32_ARR) delete _bytes32Arr[subject][predicate];
177
- _isSet[subject][predicate] = false;
178
- delete _datatype[subject][predicate];
179
- delete _updatedAt[subject][predicate];
168
+ bytes32 k = _storageKey(subject);
169
+ if (!_isSet[k][predicate]) revert AttributeNotSet();
170
+ _clearValue(k, predicate, _datatype[k][predicate]);
171
+ _isSet[k][predicate] = false;
172
+ delete _datatype[k][predicate];
173
+ delete _updatedAt[k][predicate];
180
174
  uint64 v = _bumpVersion(subject);
181
175
  emit AttributeUnset(subject, predicate, v);
182
176
  }
@@ -184,51 +178,62 @@ abstract contract AttributeStorage {
184
178
  // ─── Public getters ─────────────────────────────────────────────
185
179
 
186
180
  function getString(bytes32 subject, bytes32 predicate) external view returns (string memory) {
187
- return _string[subject][predicate];
181
+ return _string[_storageKey(subject)][predicate];
188
182
  }
189
183
  function getAddress(bytes32 subject, bytes32 predicate) external view returns (address) {
190
- return _address[subject][predicate];
184
+ return _address[_storageKey(subject)][predicate];
191
185
  }
192
186
  function getBool(bytes32 subject, bytes32 predicate) external view returns (bool) {
193
- return _bool[subject][predicate];
187
+ return _bool[_storageKey(subject)][predicate];
194
188
  }
195
189
  function getUint(bytes32 subject, bytes32 predicate) external view returns (uint256) {
196
- return _uint[subject][predicate];
190
+ return _uint[_storageKey(subject)][predicate];
197
191
  }
198
192
  function getBytes32(bytes32 subject, bytes32 predicate) external view returns (bytes32) {
199
- return _bytes32[subject][predicate];
193
+ return _bytes32[_storageKey(subject)][predicate];
200
194
  }
201
195
  function getStringArr(bytes32 subject, bytes32 predicate) external view returns (string[] memory) {
202
- return _stringArr[subject][predicate];
196
+ return _stringArr[_storageKey(subject)][predicate];
203
197
  }
204
198
  function getAddressArr(bytes32 subject, bytes32 predicate) external view returns (address[] memory) {
205
- return _addressArr[subject][predicate];
199
+ return _addressArr[_storageKey(subject)][predicate];
206
200
  }
207
201
  function getBytes32Arr(bytes32 subject, bytes32 predicate) external view returns (bytes32[] memory) {
208
- return _bytes32Arr[subject][predicate];
202
+ return _bytes32Arr[_storageKey(subject)][predicate];
209
203
  }
210
204
 
211
205
  function predicatesOf(bytes32 subject) external view returns (bytes32[] memory) {
212
- return _predicates[subject];
206
+ return _predicates[_storageKey(subject)];
213
207
  }
214
208
  function datatypeOf(bytes32 subject, bytes32 predicate) external view returns (uint8) {
215
- return _datatype[subject][predicate];
209
+ return _datatype[_storageKey(subject)][predicate];
216
210
  }
217
211
  function updatedAt(bytes32 subject, bytes32 predicate) external view returns (uint64) {
218
- return _updatedAt[subject][predicate];
212
+ return _updatedAt[_storageKey(subject)][predicate];
219
213
  }
220
214
  function isSet(bytes32 subject, bytes32 predicate) external view returns (bool) {
221
- return _isSet[subject][predicate];
215
+ return _isSet[_storageKey(subject)][predicate];
222
216
  }
223
217
  function subjectVersion(bytes32 subject) external view returns (uint64) {
224
218
  return _subjectVersion[subject];
225
219
  }
220
+ /// @dev REG-12: unbounded — anyone who can write a first record extends it. Kept for small deployments;
221
+ /// a reader of a large one uses `subjectsPage`.
226
222
  function allSubjects() external view returns (bytes32[] memory) {
227
223
  return _allSubjects;
228
224
  }
229
225
  function subjectCount() external view returns (uint256) {
230
226
  return _allSubjects.length;
231
227
  }
228
+ /// @notice REG-12 — a bounded window of the subject index: `limit` entries from `offset` (fewer at the end).
229
+ function subjectsPage(uint256 offset, uint256 limit) external view returns (bytes32[] memory page) {
230
+ uint256 n = _allSubjects.length;
231
+ if (offset >= n) return new bytes32[](0);
232
+ uint256 end = offset + limit;
233
+ if (end > n) end = n;
234
+ page = new bytes32[](end - offset);
235
+ for (uint256 i = offset; i < end; i++) page[i - offset] = _allSubjects[i];
236
+ }
232
237
 
233
238
  // ─── Internal helpers ───────────────────────────────────────────
234
239
 
@@ -236,28 +241,36 @@ abstract contract AttributeStorage {
236
241
  if (!ONTOLOGY.isActive(predicate)) revert PredicateNotActive();
237
242
  }
238
243
 
239
- function _record(bytes32 subject, bytes32 predicate, uint8 dt) internal {
240
- _trackSubject(subject);
241
- if (!_isSet[subject][predicate]) {
242
- _predicates[subject].push(predicate);
243
- _isSet[subject][predicate] = true;
244
- }
245
- _datatype[subject][predicate] = dt;
246
- uint64 v = _bumpVersion(subject);
247
- _updatedAt[subject][predicate] = v;
248
- emit AttributeSet(subject, predicate, dt, v);
249
- }
250
-
251
- function _recordAppend(bytes32 subject, bytes32 predicate, uint8 dt) internal {
244
+ /// @dev One write path: predicate active → storage key → (REG-14) if the predicate was set with ANOTHER
245
+ /// datatype, delete that family's value so `getString` cannot keep answering after the predicate was
246
+ /// rewritten as an address → index + version + event. Returns the key the caller writes under.
247
+ function _write(bytes32 subject, bytes32 predicate, uint8 dt, bool append) private returns (bytes32 k) {
248
+ _requirePredicate(predicate);
249
+ k = _storageKey(subject);
252
250
  _trackSubject(subject);
253
- if (!_isSet[subject][predicate]) {
254
- _predicates[subject].push(predicate);
255
- _isSet[subject][predicate] = true;
251
+ if (!_isSet[k][predicate]) {
252
+ _predicates[k].push(predicate);
253
+ _isSet[k][predicate] = true;
254
+ } else {
255
+ uint8 prior = _datatype[k][predicate];
256
+ if (prior != dt) _clearValue(k, predicate, prior);
256
257
  }
257
- _datatype[subject][predicate] = dt;
258
+ _datatype[k][predicate] = dt;
258
259
  uint64 v = _bumpVersion(subject);
259
- _updatedAt[subject][predicate] = v;
260
- emit AttributeAppended(subject, predicate, dt, v);
260
+ _updatedAt[k][predicate] = v;
261
+ if (append) emit AttributeAppended(subject, predicate, dt, v);
262
+ else emit AttributeSet(subject, predicate, dt, v);
263
+ }
264
+
265
+ function _clearValue(bytes32 k, bytes32 predicate, uint8 dt) private {
266
+ if (dt == DT_STRING) delete _string[k][predicate];
267
+ else if (dt == DT_ADDRESS) delete _address[k][predicate];
268
+ else if (dt == DT_BOOL) delete _bool[k][predicate];
269
+ else if (dt == DT_UINT256) delete _uint[k][predicate];
270
+ else if (dt == DT_BYTES32) delete _bytes32[k][predicate];
271
+ else if (dt == DT_STRING_ARR) delete _stringArr[k][predicate];
272
+ else if (dt == DT_ADDRESS_ARR) delete _addressArr[k][predicate];
273
+ else if (dt == DT_BYTES32_ARR) delete _bytes32Arr[k][predicate];
261
274
  }
262
275
 
263
276
  function _trackSubject(bytes32 subject) internal {
@@ -1,5 +1,7 @@
1
1
  // SPDX-License-Identifier: MIT
2
2
  pragma solidity ^0.8.28;
3
+ import "../governance/StableProxyGoverned.sol";
4
+ import {Eip7702} from "../libraries/Eip7702.sol";
3
5
 
4
6
  /**
5
7
  * @title OntologyTermRegistry
@@ -21,7 +23,7 @@ pragma solidity ^0.8.28;
21
23
  * structurally identical; copied here to keep the agenticprimitives
22
24
  * trust fabric self-contained.
23
25
  */
24
- contract OntologyTermRegistry {
26
+ contract OntologyTermRegistry is StableProxyGoverned {
25
27
  struct Term {
26
28
  bytes32 id; // keccak256("atl:displayName")
27
29
  string curie; // "atl:displayName"
@@ -45,13 +47,35 @@ contract OntologyTermRegistry {
45
47
  error TermExists();
46
48
  error TermNotFound();
47
49
  error ZeroGovernor();
50
+ /// @dev Spec 447 — `initialize(address)` alone would leave the governor unset.
51
+ error GovernorRequired();
48
52
 
49
53
  modifier onlyGovernor() {
54
+ Eip7702.refuseDelegatedEOA(msg.sender); // spec 448 §0 (EIP-7702)
50
55
  if (msg.sender != governor) revert NotGovernor();
51
56
  _;
52
57
  }
53
58
 
54
- constructor(address governor_) {
59
+ /// @notice A DIRECT deployment: `governor_` runs the registry, and there is no upgrade governance (the code is
60
+ /// frozen, as before). Spec 447 — behind a stable proxy, `initialize(governance_, governor_)` instead.
61
+ constructor(address governor_) initializer {
62
+ _initGovernor(governor_);
63
+ }
64
+
65
+ /// @notice Spec 447 — the proxy's initializer: `governance_` is the upgrade authority (only); `governor_` runs
66
+ /// the registry, exactly as the constructor's argument does. Once per proxy; never on the implementation.
67
+ function initialize(address governance_, address governor_) external initializer {
68
+ _initializeGovernance(governance_);
69
+ _initGovernor(governor_);
70
+ }
71
+
72
+ /// @dev Spec 447 — the one-argument path would leave `governor` unset (a registry nobody can run), so it is
73
+ /// refused: `initialize(governance_, governor_)` is this contract's only initializer.
74
+ function initialize(address) external pure override {
75
+ revert GovernorRequired();
76
+ }
77
+
78
+ function _initGovernor(address governor_) private {
55
79
  if (governor_ == address(0)) revert ZeroGovernor();
56
80
  governor = governor_;
57
81
  }
@@ -60,6 +84,35 @@ contract OntologyTermRegistry {
60
84
  if (newGovernor == address(0)) revert ZeroGovernor();
61
85
  emit GovernorTransferred(governor, newGovernor);
62
86
  governor = newGovernor;
87
+ pendingGovernor = address(0); // a proposal made by the previous governor does not survive it
88
+ }
89
+
90
+ // ─── Two-step governor hand-over (spec 445 / REG-11) ────────────
91
+ //
92
+ // `transferGovernor` is one step: a wrong address is permanent. It stays for the scripted bootstrap
93
+ // hand-over, where the deploy script asserts the end state in the same run (spec 445 §2.1). Every
94
+ // LATER rotation should use this pair — the successor proves it can act before the role moves.
95
+
96
+ /// @notice The successor named by `proposeGovernor`, until it accepts. Zero otherwise.
97
+ address public pendingGovernor;
98
+
99
+ event GovernorProposed(address indexed governor, address indexed pendingGovernor);
100
+
101
+ error NotPendingGovernor();
102
+
103
+ /// @notice Name a successor (zero cancels). The governor keeps the role until the successor accepts.
104
+ function proposeGovernor(address newGovernor) external onlyGovernor {
105
+ pendingGovernor = newGovernor;
106
+ emit GovernorProposed(governor, newGovernor);
107
+ }
108
+
109
+ /// @notice Take the governor role. Only the proposed successor.
110
+ function acceptGovernor() external {
111
+ Eip7702.refuseDelegatedEOA(msg.sender); // spec 448 §0 (EIP-7702)
112
+ if (msg.sender != pendingGovernor || msg.sender == address(0)) revert NotPendingGovernor();
113
+ emit GovernorTransferred(governor, msg.sender);
114
+ governor = msg.sender;
115
+ pendingGovernor = address(0);
63
116
  }
64
117
 
65
118
  function registerTerm(
@@ -143,4 +196,7 @@ contract OntologyTermRegistry {
143
196
  function getAllTermIds() external view returns (bytes32[] memory) {
144
197
  return _termIds;
145
198
  }
199
+
200
+ /// @dev Spec 447 — storage gap: the registry may sit behind a stable proxy; layout gated by `check:storage-layouts`.
201
+ uint256[46] private __gap;
146
202
  }
@@ -2,6 +2,8 @@
2
2
  pragma solidity ^0.8.28;
3
3
 
4
4
  import "./AttributeStorage.sol";
5
+ import {Eip7702} from "../libraries/Eip7702.sol";
6
+ import "../governance/StableProxyGoverned.sol";
5
7
 
6
8
  /**
7
9
  * @title ShapeRegistry
@@ -22,7 +24,7 @@ import "./AttributeStorage.sol";
22
24
  * (`packages/contracts/src/ShapeRegistry.sol`, 231 LOC) —
23
25
  * structurally identical.
24
26
  */
25
- contract ShapeRegistry {
27
+ contract ShapeRegistry is StableProxyGoverned {
26
28
  address public governor;
27
29
 
28
30
  enum Cardinality {
@@ -71,13 +73,35 @@ contract ShapeRegistry {
71
73
  error EnumValueNotAllowed(bytes32 predicate, bytes32 actualValue);
72
74
  error EnumSetEmpty();
73
75
  error ZeroGovernor();
76
+ /// @dev Spec 447 — `initialize(address)` alone would leave the governor unset.
77
+ error GovernorRequired();
74
78
 
75
79
  modifier onlyGovernor() {
80
+ Eip7702.refuseDelegatedEOA(msg.sender); // spec 448 §0 (EIP-7702)
76
81
  if (msg.sender != governor) revert NotGovernor();
77
82
  _;
78
83
  }
79
84
 
80
- constructor(address governor_) {
85
+ /// @notice A DIRECT deployment: `governor_` runs the registry, and there is no upgrade governance (the code is
86
+ /// frozen, as before). Spec 447 — behind a stable proxy, `initialize(governance_, governor_)` instead.
87
+ constructor(address governor_) initializer {
88
+ _initGovernor(governor_);
89
+ }
90
+
91
+ /// @notice Spec 447 — the proxy's initializer: `governance_` is the upgrade authority (only); `governor_` runs
92
+ /// the registry, exactly as the constructor's argument does. Once per proxy; never on the implementation.
93
+ function initialize(address governance_, address governor_) external initializer {
94
+ _initializeGovernance(governance_);
95
+ _initGovernor(governor_);
96
+ }
97
+
98
+ /// @dev Spec 447 — the one-argument path would leave `governor` unset (a registry nobody can run), so it is
99
+ /// refused: `initialize(governance_, governor_)` is this contract's only initializer.
100
+ function initialize(address) external pure override {
101
+ revert GovernorRequired();
102
+ }
103
+
104
+ function _initGovernor(address governor_) private {
81
105
  if (governor_ == address(0)) revert ZeroGovernor();
82
106
  governor = governor_;
83
107
  }
@@ -86,6 +110,35 @@ contract ShapeRegistry {
86
110
  if (newGovernor == address(0)) revert ZeroGovernor();
87
111
  emit GovernorTransferred(governor, newGovernor);
88
112
  governor = newGovernor;
113
+ pendingGovernor = address(0); // a proposal made by the previous governor does not survive it
114
+ }
115
+
116
+ // ─── Two-step governor hand-over (spec 445 / REG-11) ────────────
117
+ //
118
+ // `transferGovernor` is one step: a wrong address is permanent. It stays for the scripted bootstrap
119
+ // hand-over, where the deploy script asserts the end state in the same run (spec 445 §2.1). Every
120
+ // LATER rotation should use this pair — the successor proves it can act before the role moves.
121
+
122
+ /// @notice The successor named by `proposeGovernor`, until it accepts. Zero otherwise.
123
+ address public pendingGovernor;
124
+
125
+ event GovernorProposed(address indexed governor, address indexed pendingGovernor);
126
+
127
+ error NotPendingGovernor();
128
+
129
+ /// @notice Name a successor (zero cancels). The governor keeps the role until the successor accepts.
130
+ function proposeGovernor(address newGovernor) external onlyGovernor {
131
+ pendingGovernor = newGovernor;
132
+ emit GovernorProposed(governor, newGovernor);
133
+ }
134
+
135
+ /// @notice Take the governor role. Only the proposed successor.
136
+ function acceptGovernor() external {
137
+ Eip7702.refuseDelegatedEOA(msg.sender); // spec 448 §0 (EIP-7702)
138
+ if (msg.sender != pendingGovernor || msg.sender == address(0)) revert NotPendingGovernor();
139
+ emit GovernorTransferred(governor, msg.sender);
140
+ governor = msg.sender;
141
+ pendingGovernor = address(0);
89
142
  }
90
143
 
91
144
  // ─── Shape definition ───────────────────────────────────────────
@@ -237,4 +290,7 @@ contract ShapeRegistry {
237
290
  function getClassIdAt(uint256 index) external view returns (bytes32) {
238
291
  return _classIds[index];
239
292
  }
293
+
294
+ /// @dev Spec 447 — storage gap: the registry may sit behind a stable proxy; layout gated by `check:storage-layouts`.
295
+ uint256[43] private __gap;
240
296
  }
@@ -0,0 +1,187 @@
1
+ // SPDX-License-Identifier: MIT
2
+ pragma solidity ^0.8.28;
3
+
4
+ import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
5
+ import {Eip7702} from "../libraries/Eip7702.sol";
6
+ import {SafeERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
7
+ import {ReentrancyGuard} from "@openzeppelin/contracts/utils/ReentrancyGuard.sol";
8
+ import "../governance/StableProxyGoverned.sol";
9
+
10
+ /**
11
+ * @title PaymentEscrow
12
+ * @notice Hold-and-capture for an exchange order (spec 243 §5.5 escrow rail, FG-PAY-7).
13
+ * A payer funds a hold keyed by `orderHash`; funds then move on exactly ONE terminal path:
14
+ * - release → captured to the payee (on fulfillment evidence)
15
+ * - refund → returned to the payer (payee-consented, before capture)
16
+ * - reclaim → returned to the payer (payer-initiated, after expiry)
17
+ * Symmetric-escrow doctrine (273 EXC-D4): any escrowable leg can be held. Ports the
18
+ * smart-agent `CommitmentRegistry` status-machine pattern; no third-party escrow dependency.
19
+ *
20
+ * @dev HASH-ONLY events (orderHash only — no amounts/addresses leak; privacy posture §6). Apps read
21
+ * hold state via the `getHold` view (`readContract`), never inline `eth_getLogs` (ADR-0012).
22
+ * Fail-closed: a hold moves Held → {Captured|Refunded|Reclaimed} once and never again
23
+ * (checks-effects-interactions + ReentrancyGuard). Uses OZ SafeERC20 for fee/no-return tokens.
24
+ */
25
+ contract PaymentEscrow is ReentrancyGuard, StableProxyGoverned {
26
+ /// @notice Spec 447 — a DIRECT deployment, initialized here with no governance (its code is frozen, as
27
+ /// before). Behind a stable proxy, `initialize(governance_)` instead; the governance is then the only
28
+ /// upgrade authority. This contract has no admin of its own: governance can replace the code behind
29
+ /// the proxy and nothing else. `ReentrancyGuard` (OZ 5.0.2, non-upgradeable) keeps `_status` in slot 0;
30
+ /// behind a proxy it starts at 0, which it treats as not-entered (it reverts only on `ENTERED == 2`).
31
+ constructor() initializer {}
32
+
33
+ using SafeERC20 for IERC20;
34
+
35
+ enum Status {
36
+ None,
37
+ Held,
38
+ Captured,
39
+ Refunded,
40
+ Reclaimed
41
+ }
42
+
43
+ struct Hold {
44
+ address payer; // funded the hold
45
+ address asset; // ERC-20
46
+ uint256 amount;
47
+ address payee; // captures on release
48
+ address refundTo; // receives refund / reclaim
49
+ address releaser; // OPTIONAL extra party authorized to release (0 = payee-only)
50
+ uint64 expiry; // payer may reclaim at/after this time
51
+ Status status;
52
+ }
53
+
54
+ // EXT-PMT-3: holds are keyed by (payer, orderHash), NOT orderHash alone — so a stranger cannot
55
+ // squat a predictable orderHash to block the real payer's deposit (HoldExists griefing). Each payer
56
+ // has an independent namespace for any given orderHash.
57
+ mapping(bytes32 holdKey => Hold) private _holds;
58
+
59
+ event EscrowDeposited(bytes32 indexed orderHash);
60
+ event EscrowReleased(bytes32 indexed orderHash);
61
+ event EscrowRefunded(bytes32 indexed orderHash);
62
+ event EscrowReclaimed(bytes32 indexed orderHash);
63
+
64
+ error HoldExists();
65
+ error NoHold();
66
+ error NotHeld();
67
+ error ZeroAmount();
68
+ error ZeroAddress();
69
+ error BadExpiry();
70
+ error NotAuthorized();
71
+ error NotYetExpired();
72
+ error Expired();
73
+
74
+ /// @dev The (payer, orderHash) namespace key. Terminal calls by the payee/releaser pass `payer`;
75
+ /// the payer's own `reclaim`/`deposit` derive it from `msg.sender`.
76
+ function _key(address payer, bytes32 orderHash) private pure returns (bytes32) {
77
+ return keccak256(abi.encode(payer, orderHash));
78
+ }
79
+
80
+ /**
81
+ * @notice Fund a hold for `orderHash`. Pulls `amount` of `asset` from the caller (the payer).
82
+ * @param refundTo Where refund/reclaim returns funds; 0 defaults to the payer.
83
+ * @param releaser Extra address allowed to `release` besides `payee`; 0 = payee-only.
84
+ */
85
+ function deposit(
86
+ bytes32 orderHash,
87
+ address asset,
88
+ uint256 amount,
89
+ address payee,
90
+ address refundTo,
91
+ address releaser,
92
+ uint64 expiry
93
+ ) external nonReentrant {
94
+ bytes32 key = _key(msg.sender, orderHash);
95
+ if (_holds[key].status != Status.None) revert HoldExists();
96
+ if (amount == 0) revert ZeroAmount();
97
+ if (asset == address(0) || payee == address(0)) revert ZeroAddress();
98
+ if (expiry <= block.timestamp) revert BadExpiry();
99
+
100
+ // Spec 445 (Slither `reentrancy-no-eth`): the hold is WRITTEN BEFORE the token is called. It
101
+ // is created `Held` with amount 0, so the (payer, orderHash) key is occupied for the whole of
102
+ // the pull — a token that calls back into `deposit` meets `HoldExists` on its own key even if
103
+ // the guard were not there, and nothing written during the callback can be overwritten by the
104
+ // tail of this function. `nonReentrant` (on every entry point) still blocks the callback
105
+ // outright; the ordering makes the property structural rather than guard-dependent.
106
+ _holds[key] = Hold({
107
+ payer: msg.sender,
108
+ asset: asset,
109
+ amount: 0,
110
+ payee: payee,
111
+ refundTo: refundTo == address(0) ? msg.sender : refundTo,
112
+ releaser: releaser,
113
+ expiry: expiry,
114
+ status: Status.Held
115
+ });
116
+
117
+ // EXT-PMT-3: credit the REALIZED amount received (balance delta), not the requested `amount`. A
118
+ // fee-on-transfer / rebasing asset delivers less than `amount`, which would otherwise over-credit
119
+ // the hold and let it draw from other holds' funds in the shared pool (cross-hold drain).
120
+ uint256 beforeBal = IERC20(asset).balanceOf(address(this));
121
+ // Triaged: every entry point is `nonReentrant`, so the balance delta cannot be manipulated by
122
+ // re-entering between the two reads, and the only post-call write is the realized amount of the
123
+ // hold this call already owns (created above; no other frame can reach it while the guard is held).
124
+ // slither-disable-next-line reentrancy-balance,reentrancy-no-eth
125
+ IERC20(asset).safeTransferFrom(msg.sender, address(this), amount);
126
+ uint256 received = IERC20(asset).balanceOf(address(this)) - beforeBal;
127
+ // A pull that delivered nothing is no deposit: revert (which also unwinds the hold above).
128
+ // slither-disable-next-line incorrect-equality
129
+ if (received == 0) revert ZeroAmount();
130
+ _holds[key].amount = received;
131
+
132
+ emit EscrowDeposited(orderHash);
133
+ }
134
+
135
+ /// @notice Capture a held order to the payee. Authorized: the payee, or the configured releaser.
136
+ /// `payer` namespaces the hold (EXT-PMT-3). Cannot release at/after expiry — that window is
137
+ /// the payer's `reclaim` (removes the prior release/reclaim race; spec 243 §reclaim intent).
138
+ function release(address payer, bytes32 orderHash) external nonReentrant {
139
+ Hold storage h = _held(_key(payer, orderHash));
140
+ Eip7702.refuseDelegatedEOA(msg.sender); // spec 448 §0 (EIP-7702)
141
+ if (msg.sender != h.payee && (h.releaser == address(0) || msg.sender != h.releaser)) revert NotAuthorized();
142
+ if (block.timestamp >= h.expiry) revert Expired();
143
+ h.status = Status.Captured;
144
+ emit EscrowReleased(orderHash);
145
+ IERC20(h.asset).safeTransfer(h.payee, h.amount);
146
+ }
147
+
148
+ /// @notice Payee-consented refund of a held order to the payer (before capture). `payer` namespaces.
149
+ function refund(address payer, bytes32 orderHash) external nonReentrant {
150
+ Hold storage h = _held(_key(payer, orderHash));
151
+ Eip7702.refuseDelegatedEOA(msg.sender); // spec 448 §0 (EIP-7702)
152
+ if (msg.sender != h.payee) revert NotAuthorized();
153
+ h.status = Status.Refunded;
154
+ emit EscrowRefunded(orderHash);
155
+ IERC20(h.asset).safeTransfer(h.refundTo, h.amount);
156
+ }
157
+
158
+ /// @notice Payer reclaims a held order after expiry (never released). Payer-initiated → the hold is
159
+ /// derived from `msg.sender`, so only the payer can reach their own hold.
160
+ function reclaim(bytes32 orderHash) external nonReentrant {
161
+ Eip7702.refuseDelegatedEOA(msg.sender); // spec 448 §0 (EIP-7702)
162
+ Hold storage h = _held(_key(msg.sender, orderHash));
163
+ if (block.timestamp < h.expiry) revert NotYetExpired();
164
+ h.status = Status.Reclaimed;
165
+ emit EscrowReclaimed(orderHash);
166
+ IERC20(h.asset).safeTransfer(h.refundTo, h.amount);
167
+ }
168
+
169
+ /// @notice Full hold record for (payer, orderHash) — app reads via this view, not log scans (ADR-0012).
170
+ function getHold(address payer, bytes32 orderHash) external view returns (Hold memory) {
171
+ return _holds[_key(payer, orderHash)];
172
+ }
173
+
174
+ function statusOf(address payer, bytes32 orderHash) external view returns (Status) {
175
+ return _holds[_key(payer, orderHash)].status;
176
+ }
177
+
178
+ /// @dev Load a hold that MUST be in `Held` (fail-closed): missing → NoHold; terminal → NotHeld.
179
+ function _held(bytes32 key) private view returns (Hold storage h) {
180
+ h = _holds[key];
181
+ if (h.status == Status.None) revert NoHold();
182
+ if (h.status != Status.Held) revert NotHeld();
183
+ }
184
+
185
+ /// @dev Spec 447 — storage gap: the contract may sit behind a stable proxy; layout gated by `check:storage-layouts`.
186
+ uint256[48] private __gap;
187
+ }