@t-rex-network/t-rex 5.0.0-beta2 → 5.0.0-beta3

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 (386) hide show
  1. package/NOTICE.md +78 -0
  2. package/README.md +19 -22
  3. package/contracts/{roles/AgentRole.sol → ERC-3643/ERC3643ErrorsLib.sol} +60 -33
  4. package/contracts/ERC-3643/IERC3643.sol +61 -5
  5. package/contracts/ERC-3643/IERC3643ClaimTopicsRegistry.sol +11 -2
  6. package/contracts/ERC-3643/IERC3643Compliance.sol +21 -8
  7. package/contracts/ERC-3643/IERC3643IdentityRegistry.sol +33 -0
  8. package/contracts/ERC-3643/IERC3643IdentityRegistryStorage.sol +62 -7
  9. package/contracts/ERC-3643/IERC3643TrustedIssuersRegistry.sol +29 -12
  10. package/contracts/ERC-3643/base/ERC3643ClaimTopicsRegistry.sol +140 -0
  11. package/contracts/ERC-3643/base/ERC3643Compliance.sol +223 -0
  12. package/contracts/ERC-3643/base/ERC3643IdentityRegistry.sol +382 -0
  13. package/contracts/ERC-3643/base/ERC3643IdentityRegistryStorage.sol +290 -0
  14. package/contracts/ERC-3643/base/ERC3643Token.sol +601 -0
  15. package/contracts/ERC-3643/base/ERC3643TrustedIssuersRegistry.sol +237 -0
  16. package/contracts/compliance/modular/ComplianceLedger.sol +175 -0
  17. package/contracts/compliance/modular/ComplianceLedgerLib.sol +120 -0
  18. package/contracts/compliance/modular/IComplianceLedger.sol +104 -0
  19. package/contracts/compliance/modular/IModularCompliance.sol +119 -28
  20. package/contracts/compliance/modular/ITransferValidation.sol +308 -0
  21. package/contracts/compliance/modular/ModularCompliance.sol +399 -240
  22. package/contracts/compliance/modular/ModuleSetLib.sol +182 -0
  23. package/contracts/compliance/modular/MovementKindLib.sol +97 -0
  24. package/contracts/compliance/modular/TransferContextLib.sol +140 -0
  25. package/contracts/compliance/modular/TransferValidation.sol +822 -0
  26. package/contracts/compliance/modular/TransferValidationLib.sol +183 -0
  27. package/contracts/compliance/modular/modules/AbstractModuleUpgradeable.sol +87 -56
  28. package/contracts/compliance/modular/modules/IModule.sol +142 -58
  29. package/contracts/compliance/modular/modules/MaxBalancePerIdentityModule.sol +175 -0
  30. package/contracts/compliance/modular/modules/ModuleProxy.sol +24 -24
  31. package/contracts/compliance/modular/modules/SpenderVerificationModule.sol +149 -0
  32. package/contracts/compliance/modular/modules/SpenderWhitelistModule.sol +215 -0
  33. package/contracts/factory/ITREXFactory.sol +94 -44
  34. package/contracts/factory/TREXFactory.sol +408 -201
  35. package/contracts/interop/ISettlementHandler.sol +101 -0
  36. package/contracts/interop/ITREXMessaging.sol +166 -0
  37. package/contracts/{proxy/ModularComplianceProxy.sol → interop/ITrustedGatewayRegistry.sol} +48 -43
  38. package/contracts/interop/TREXMessaging.sol +189 -0
  39. package/contracts/interop/TREXMessagingLib.sol +425 -0
  40. package/contracts/{proxy/TrustedIssuersRegistryProxy.sol → interop/TrustedGatewayRegistry.sol} +46 -37
  41. package/contracts/libraries/AccessManagerSetupLib.sol +484 -0
  42. package/contracts/libraries/ErrorsLib.sol +172 -65
  43. package/contracts/libraries/EventsLib.sol +168 -66
  44. package/contracts/libraries/MessageTypesLib.sol +259 -0
  45. package/contracts/libraries/RolesLib.sol +146 -0
  46. package/contracts/{roles/Roles.sol → libraries/VersionLib.sol} +46 -49
  47. package/contracts/libraries/WalletKeyLib.sol +156 -0
  48. package/contracts/proxy/beacon/ITREXImplementationAuthority.sol +157 -0
  49. package/contracts/proxy/beacon/TREXImplementationAuthority.sol +188 -0
  50. package/contracts/registry/implementation/IdentityRegistryStorage.sol +215 -163
  51. package/contracts/registry/implementation/TREXRegistry.sol +475 -0
  52. package/contracts/registry/interface/IIdentityRegistryStorage.sol +30 -25
  53. package/contracts/registry/interface/ITREXRegistry.sol +180 -0
  54. package/contracts/token/IToken.sol +210 -49
  55. package/contracts/token/Token.sol +411 -476
  56. package/contracts/token/TokenDelegationLib.sol +339 -0
  57. package/contracts/token/TokenGuardsLib.sol +123 -0
  58. package/contracts/token/TokenLedgerLib.sol +316 -0
  59. package/contracts/token/TokenRecoveryLib.sol +130 -0
  60. package/contracts/{roles/AgentRoleUpgradeable.sol → utils/AccessManagedOwnable.sol} +31 -31
  61. package/contracts/{proxy/IdentityRegistryStorageProxy.sol → utils/AccessManagedOwnableBase.sol} +56 -34
  62. package/contracts/utils/AccessManagedOwnableUpgradeable.sol +116 -0
  63. package/contracts/utils/IUtilityChecker.sol +32 -26
  64. package/contracts/{roles/AbstractAgentRole.sol → utils/TREXAccessManager.sol} +54 -57
  65. package/contracts/utils/UtilityChecker.sol +175 -52
  66. package/contracts/utils/UtilityCheckerProxy.sol +24 -24
  67. package/contracts/{proxy/interface/IProxy.sol → vendor/IERC173.sol} +15 -28
  68. package/out/AbstractModuleUpgradeable.sol/AbstractModuleUpgradeable.json +1 -1
  69. package/out/AbstractSigner.sol/AbstractSigner.json +1 -0
  70. package/out/AccessManaged.sol/AccessManaged.json +1 -0
  71. package/out/AccessManagedOwnable.sol/AccessManagedOwnable.json +1 -0
  72. package/out/AccessManagedOwnableBase.sol/AccessManagedOwnableBase.json +1 -0
  73. package/out/AccessManagedOwnableUpgradeable.sol/AccessManagedOwnableUpgradeable.json +1 -0
  74. package/out/AccessManagedUpgradeable.sol/AccessManagedUpgradeable.json +1 -0
  75. package/out/AccessManager.sol/AccessManager.json +1 -0
  76. package/out/AccessManagerHelper.sol/AccessManagerHelper.json +1 -0
  77. package/out/AccessManagerSetupLib.sol/AccessManagerSetupLib.json +1 -0
  78. package/out/AccessManagerUpgradeable.sol/AccessManagerUpgradeable.json +1 -0
  79. package/out/Account.sol/Account.json +1 -0
  80. package/out/Address.sol/Address.json +1 -1
  81. package/out/Arrays.sol/Arrays.json +1 -1
  82. package/out/AuthorityUtils.sol/AuthorityUtils.json +1 -0
  83. package/out/Base.sol/CommonBase.json +1 -1
  84. package/out/Base.sol/ScriptBase.json +1 -1
  85. package/out/Base.sol/TestBase.json +1 -1
  86. package/out/Base64.sol/Base64.json +1 -0
  87. package/out/BeaconProxy.sol/BeaconProxy.json +1 -0
  88. package/out/BeaconProxyDeployer.sol/BeaconProxyDeployer.json +1 -0
  89. package/out/Bytes.sol/Bytes.json +1 -1
  90. package/out/Calldata.sol/Calldata.json +1 -0
  91. package/out/CapabilityModules.sol/AllTypesModule.json +1 -0
  92. package/out/CapabilityModules.sol/CappedRecipientModule.json +1 -0
  93. package/out/CapabilityModules.sol/DelegatedCapRuleModule.json +1 -0
  94. package/out/CapabilityModules.sol/DuplicateTypeModule.json +1 -0
  95. package/out/CapabilityModules.sol/LockedSenderModule.json +1 -0
  96. package/out/CapabilityModules.sol/NoTypeModule.json +1 -0
  97. package/out/CapabilityModules.sol/RecordingModule.json +1 -0
  98. package/out/CapabilityModules.sol/RuleAndMintTrackerModule.json +1 -0
  99. package/out/CapabilityModules.sol/RuleAndTrackerModule.json +1 -0
  100. package/out/CapabilityModules.sol/RuleOnlyModule.json +1 -0
  101. package/out/CapabilityModules.sol/SpenderOnlyModule.json +1 -0
  102. package/out/CapabilityModules.sol/TrackerOnlyModule.json +1 -0
  103. package/out/CapabilityModules.sol/UndeclaredRuleModule.json +1 -0
  104. package/out/CapabilityModules.sol/WritingRuleModule.json +1 -0
  105. package/out/ClaimIssuerAlwaysReverts.sol/ClaimIssuerAlwaysReverts.json +1 -0
  106. package/out/ClaimIssuerTrick.sol/ClaimIssuerTrick.json +1 -1
  107. package/out/Comparators.sol/Comparators.json +1 -1
  108. package/out/ComplianceLedger.sol/ComplianceLedger.json +1 -0
  109. package/out/ComplianceLedgerLib.sol/ComplianceLedgerLib.json +1 -0
  110. package/out/Context.sol/Context.json +1 -1
  111. package/out/ContextUpgradeable.sol/ContextUpgradeable.json +1 -1
  112. package/out/Countries.sol/Countries.json +1 -1
  113. package/out/Create2.sol/Create2.json +1 -1
  114. package/out/Create3.sol/Create3.json +1 -1
  115. package/out/DeployComplianceModules.s.sol/DeployComplianceModules.json +1 -0
  116. package/out/DeployComplianceModules.s.sol/ITokenCompliance.json +1 -0
  117. package/out/DeployUtilityChecker.s.sol/DeployUtilityChecker.json +1 -0
  118. package/out/ECDSA.sol/ECDSA.json +1 -1
  119. package/out/EIP712.sol/EIP712.json +1 -1
  120. package/out/EIP712Upgradeable.sol/EIP712Upgradeable.json +1 -1
  121. package/out/ERC165.sol/ERC165.json +1 -0
  122. package/out/ERC165Checker.sol/ERC165Checker.json +1 -0
  123. package/out/ERC165Upgradeable.sol/ERC165Upgradeable.json +1 -0
  124. package/out/ERC1967Proxy.sol/ERC1967Proxy.json +1 -1
  125. package/out/ERC1967Utils.sol/ERC1967Utils.json +1 -1
  126. package/out/ERC20.sol/ERC20.json +1 -1
  127. package/out/ERC20Pausable.sol/ERC20Pausable.json +1 -1
  128. package/out/ERC20PermitUpgradeable.sol/ERC20PermitUpgradeable.json +1 -1
  129. package/out/ERC20Upgradeable.sol/ERC20Upgradeable.json +1 -1
  130. package/out/ERC3643ClaimTopicsRegistry.sol/ERC3643ClaimTopicsRegistry.json +1 -0
  131. package/out/ERC3643Compliance.sol/ERC3643Compliance.json +1 -0
  132. package/out/ERC3643ErrorsLib.sol/ERC3643ErrorsLib.json +1 -0
  133. package/out/ERC3643IdentityRegistry.sol/ERC3643IdentityRegistry.json +1 -0
  134. package/out/ERC3643IdentityRegistryStorage.sol/ERC3643IdentityRegistryStorage.json +1 -0
  135. package/out/ERC3643Token.sol/ERC3643Token.json +1 -0
  136. package/out/ERC3643TrustedIssuersRegistry.sol/ERC3643TrustedIssuersRegistry.json +1 -0
  137. package/out/ERC4337Utils.sol/ERC4337Utils.json +1 -0
  138. package/out/ERC4337Utils.sol/IEntryPointExtra.json +1 -0
  139. package/out/ERC734Validator.sol/ERC734Validator.json +1 -0
  140. package/out/ERC7579Validator.sol/ERC7579Validator.json +1 -0
  141. package/out/ERC7786GatewayMock.sol/ERC7786GatewayMock.json +1 -0
  142. package/out/ERC7786Recipient.sol/ERC7786Recipient.json +1 -0
  143. package/out/ERC7913WebAuthnVerifier.sol/ERC7913WebAuthnVerifier.json +1 -0
  144. package/out/EnumerableSet.sol/EnumerableSet.json +1 -1
  145. package/out/Errors.sol/Errors.json +1 -1
  146. package/out/ErrorsLib.sol/ErrorsLib.json +1 -1
  147. package/out/EventsLib.sol/EventsLib.json +1 -1
  148. package/out/Hashes.sol/Hashes.json +1 -0
  149. package/out/HostileModules.sol/RevertEverywhereModule.json +1 -0
  150. package/out/HostileModules.sol/UnbindRevertingModule.json +1 -0
  151. package/out/IAccessManaged.sol/IAccessManaged.json +1 -0
  152. package/out/IAccessManager.sol/IAccessManager.json +1 -0
  153. package/out/IAuthority.sol/IAuthority.json +1 -0
  154. package/out/IBeacon.sol/IBeacon.json +1 -1
  155. package/out/IClaimIssuer.sol/IClaimIssuer.json +1 -1
  156. package/out/IComplianceLedger.sol/IComplianceLedger.json +1 -0
  157. package/out/IERC1271.sol/IERC1271.json +1 -0
  158. package/out/IERC165.sol/IERC165.json +1 -1
  159. package/out/IERC173.sol/IERC173.json +1 -1
  160. package/out/IERC1967.sol/IERC1967.json +1 -1
  161. package/out/IERC20.sol/IERC20.json +1 -1
  162. package/out/IERC20Metadata.sol/IERC20Metadata.json +1 -1
  163. package/out/IERC20Permit.sol/IERC20Permit.json +1 -1
  164. package/out/IERC3643.sol/IERC3643.json +1 -1
  165. package/out/IERC3643ClaimTopicsRegistry.sol/IERC3643ClaimTopicsRegistry.json +1 -1
  166. package/out/IERC3643Compliance.sol/IERC3643Compliance.json +1 -1
  167. package/out/IERC3643IdentityRegistry.sol/IERC3643IdentityRegistry.json +1 -1
  168. package/out/IERC3643IdentityRegistryStorage.sol/IERC3643IdentityRegistryStorage.json +1 -1
  169. package/out/IERC3643TrustedIssuersRegistry.sol/IERC3643TrustedIssuersRegistry.json +1 -1
  170. package/out/IERC4337.sol/IAccount.json +1 -0
  171. package/out/IERC4337.sol/IAccountExecute.json +1 -0
  172. package/out/IERC4337.sol/IAggregator.json +1 -0
  173. package/out/IERC4337.sol/IEntryPoint.json +1 -0
  174. package/out/IERC4337.sol/IEntryPointNonces.json +1 -0
  175. package/out/IERC4337.sol/IEntryPointStake.json +1 -0
  176. package/out/IERC4337.sol/IPaymaster.json +1 -0
  177. package/out/IERC5267.sol/IERC5267.json +1 -1
  178. package/out/IERC734.sol/IERC734.json +1 -1
  179. package/out/IERC735.sol/IERC735.json +1 -1
  180. package/out/IERC7913.sol/IERC7913SignatureVerifier.json +1 -0
  181. package/out/IIdentity.sol/IIdentity.json +1 -1
  182. package/out/IIdentityFactory.sol/IIdentityFactory.json +1 -0
  183. package/out/IIdentityRegistryStorage.sol/IIdentityRegistryStorage.json +1 -1
  184. package/out/IKeyExecutor.sol/IKeyExecutor.json +1 -0
  185. package/out/IModularCompliance.sol/IModularCompliance.json +1 -1
  186. package/out/IModule.sol/IModule.json +1 -1
  187. package/out/IMulticall3.sol/IMulticall3.json +1 -1
  188. package/out/IReputationRegistry.sol/IReputationRegistry.json +1 -0
  189. package/out/ISettlementHandler.sol/ISettlementHandler.json +1 -0
  190. package/out/ITREXFactory.sol/ITREXFactory.json +1 -1
  191. package/out/ITREXImplementationAuthority.sol/ITREXImplementationAuthority.json +1 -1
  192. package/out/ITREXMessaging.sol/ITREXMessaging.json +1 -0
  193. package/out/ITREXRegistry.sol/ITREXRegistry.json +1 -0
  194. package/out/IToken.sol/IToken.json +1 -1
  195. package/out/ITransferValidation.sol/ITransferValidation.json +1 -0
  196. package/out/ITrustedGatewayRegistry.sol/ITrustedGatewayRegistry.json +1 -0
  197. package/out/IUtilityChecker.sol/IUtilityChecker.json +1 -1
  198. package/out/Identity.sol/Identity.json +1 -1
  199. package/out/IdentityFactory.sol/IdentityFactory.json +1 -0
  200. package/out/IdentityModulesHelper.sol/IdentityModulesHelper.json +1 -0
  201. package/out/IdentityRegistryStorage.sol/IdentityRegistryStorage.json +1 -1
  202. package/out/IdentityTypes.sol/IdentityTypes.json +1 -0
  203. package/out/Initializable.sol/Initializable.json +1 -1
  204. package/out/InteropSuiteTest.sol/InteropSuiteTest.json +1 -0
  205. package/out/KeyApprovalModule.sol/IIdentityAccount.json +1 -0
  206. package/out/KeyApprovalModule.sol/KeyApprovalModule.json +1 -0
  207. package/out/KeyManager.sol/KeyManager.json +1 -0
  208. package/out/KeyPurposes.sol/KeyPurposes.json +1 -1
  209. package/out/KeyTypes.sol/KeyTypes.json +1 -1
  210. package/out/LowLevelCall.sol/LowLevelCall.json +1 -1
  211. package/out/Math.sol/Math.json +1 -1
  212. package/out/MaxBalancePerIdentityModule.sol/MaxBalancePerIdentityModule.json +1 -0
  213. package/out/MessageHashUtils.sol/MessageHashUtils.json +1 -1
  214. package/out/MessageTypesLib.sol/MessageTypesLib.json +1 -0
  215. package/out/MockTREXAccessManagerV2.sol/MockTREXAccessManagerV2.json +1 -0
  216. package/out/MockTokenV2.sol/MockTokenV2.json +1 -0
  217. package/out/Mocks.sol/ClaimTopicsRegistryMock.json +1 -0
  218. package/out/Mocks.sol/ComplianceMock.json +1 -0
  219. package/out/Mocks.sol/IdentityRegistryMock.json +1 -0
  220. package/out/Mocks.sol/IdentityRegistryStorageMock.json +1 -0
  221. package/out/Mocks.sol/TokenMock.json +1 -0
  222. package/out/Mocks.sol/TrustedIssuersRegistryMock.json +1 -0
  223. package/out/ModularCompliance.sol/ModularCompliance.json +1 -1
  224. package/out/ModuleNotPnP.sol/ModuleNotPnP.json +1 -1
  225. package/out/ModuleProxy.sol/ModuleProxy.json +1 -1
  226. package/out/ModuleSetLib.sol/ModuleSetLib.json +1 -0
  227. package/out/MovementKindLib.sol/MovementKindLib.json +1 -0
  228. package/out/Multicall.sol/Multicall.json +1 -0
  229. package/out/MulticallUpgradeable.sol/MulticallUpgradeable.json +1 -1
  230. package/out/Nonces.sol/Nonces.json +1 -1
  231. package/out/NoncesUpgradeable.sol/NoncesUpgradeable.json +1 -1
  232. package/out/Ownable.sol/Ownable.json +1 -1
  233. package/out/OwnableUpgradeable.sol/OwnableUpgradeable.json +1 -1
  234. package/out/P256.sol/P256.json +1 -0
  235. package/out/Packing.sol/Packing.json +1 -0
  236. package/out/Panic.sol/Panic.json +1 -1
  237. package/out/Pausable.sol/Pausable.json +1 -1
  238. package/out/PausableUpgradeable.sol/PausableUpgradeable.json +1 -1
  239. package/out/Proxy.sol/Proxy.json +1 -1
  240. package/out/ReentrancyGuardTransient.sol/ReentrancyGuardTransient.json +1 -0
  241. package/out/ReentrantModule.sol/ReentrantModule.json +1 -0
  242. package/out/ReputationRegistry.sol/ReputationRegistry.json +1 -0
  243. package/out/RolesLib.sol/RolesLib.json +1 -0
  244. package/out/SafeCalldataBatch.sol/SafeCalldataBatch.json +1 -0
  245. package/out/SafeCast.sol/SafeCast.json +1 -1
  246. package/out/SatelliteLiteMock.sol/SatelliteLiteMock.json +1 -0
  247. package/out/Script.sol/Script.json +1 -0
  248. package/out/ShortStrings.sol/ShortStrings.json +1 -1
  249. package/out/SignatureChecker.sol/SignatureChecker.json +1 -0
  250. package/out/SignedMath.sol/SignedMath.json +1 -1
  251. package/out/SlotDerivation.sol/SlotDerivation.json +1 -1
  252. package/out/SmartAccount.sol/SmartAccount.json +1 -0
  253. package/out/SpenderVerificationModule.sol/SpenderVerificationModule.json +1 -0
  254. package/out/SpenderWhitelistModule.sol/SpenderWhitelistModule.json +1 -0
  255. package/out/StdAssertions.sol/StdAssertions.json +1 -1
  256. package/out/StdChains.sol/StdChains.json +1 -1
  257. package/out/StdCheats.sol/StdCheats.json +1 -1
  258. package/out/StdCheats.sol/StdCheatsSafe.json +1 -1
  259. package/out/StdConstants.sol/StdConstants.json +1 -1
  260. package/out/StdError.sol/stdError.json +1 -1
  261. package/out/StdInvariant.sol/StdInvariant.json +1 -1
  262. package/out/StdJson.sol/stdJson.json +1 -1
  263. package/out/StdMath.sol/stdMath.json +1 -1
  264. package/out/StdStorage.sol/stdStorage.json +1 -1
  265. package/out/StdStorage.sol/stdStorageSafe.json +1 -1
  266. package/out/StdStyle.sol/StdStyle.json +1 -1
  267. package/out/StdToml.sol/stdToml.json +1 -1
  268. package/out/StdUtils.sol/StdUtils.json +1 -1
  269. package/out/StorageSlot.sol/StorageSlot.json +1 -1
  270. package/out/Strings.sol/Strings.json +1 -1
  271. package/out/Structs.sol/Structs.json +1 -1
  272. package/out/TREXAccessManager.sol/TREXAccessManager.json +1 -0
  273. package/out/TREXFactory.sol/TREXFactory.json +1 -1
  274. package/out/TREXImplementationAuthority.sol/TREXImplementationAuthority.json +1 -1
  275. package/out/TREXMessaging.sol/TREXMessaging.json +1 -0
  276. package/out/TREXMessagingLib.sol/TREXMessagingLib.json +1 -0
  277. package/out/TREXRegistry.sol/TREXRegistry.json +1 -0
  278. package/out/TestERC20.sol/TestERC20.json +1 -1
  279. package/out/TestModule.sol/TestModule.json +1 -1
  280. package/out/TestTREXFactory.sol/TestTREXFactory.json +1 -1
  281. package/out/Time.sol/Time.json +1 -0
  282. package/out/Token.sol/Token.json +1 -1
  283. package/out/TokenDelegationLib.sol/TokenDelegationLib.json +1 -0
  284. package/out/TokenGuardsLib.sol/TokenGuardsLib.json +1 -0
  285. package/out/TokenHandler.sol/TokenHandler.json +1 -0
  286. package/out/TokenLedgerHarness.sol/TokenLedgerHarness.json +1 -0
  287. package/out/TokenLedgerLib.sol/TokenLedgerLib.json +1 -0
  288. package/out/TokenRecoveryLib.sol/TokenRecoveryLib.json +1 -0
  289. package/out/TokenReservationStub.sol/TokenReservationStub.json +1 -0
  290. package/out/TransferContextLib.sol/TransferContextLib.json +1 -0
  291. package/out/TransferValidation.sol/TransferValidation.json +1 -0
  292. package/out/TransferValidationHarness.sol/TransferValidationHarness.json +1 -0
  293. package/out/TransferValidationLib.sol/TransferValidationLib.json +1 -0
  294. package/out/TransientSlot.sol/TransientSlot.json +1 -0
  295. package/out/TrustedGatewayRegistry.sol/TrustedGatewayRegistry.json +1 -0
  296. package/out/UUPSUpgradeable.sol/UUPSUpgradeable.json +1 -1
  297. package/out/UpgradeableBeacon.sol/UpgradeableBeacon.json +1 -0
  298. package/out/UtilityChecker.sol/UtilityChecker.json +1 -1
  299. package/out/UtilityCheckerProxy.sol/UtilityCheckerProxy.json +1 -1
  300. package/out/Utils.sol/Utils.json +1 -1
  301. package/out/VersionLib.sol/VersionLib.json +1 -0
  302. package/out/Vm.sol/Vm.json +1 -1
  303. package/out/Vm.sol/VmSafe.json +1 -1
  304. package/out/WalletKeyLib.sol/WalletKeyLib.json +1 -0
  305. package/out/WebAuthn.sol/WebAuthn.json +1 -0
  306. package/out/console.sol/console.json +1 -1
  307. package/out/draft-AccountERC7579Upgradeable.sol/AccountERC7579Upgradeable.json +1 -0
  308. package/out/draft-ERC7579Utils.sol/ERC7579Utils.json +1 -0
  309. package/out/draft-IERC1822.sol/IERC1822Proxiable.json +1 -1
  310. package/out/draft-IERC6093.sol/IERC1155Errors.json +1 -1
  311. package/out/draft-IERC6093.sol/IERC20Errors.json +1 -1
  312. package/out/draft-IERC6093.sol/IERC721Errors.json +1 -1
  313. package/out/draft-IERC7579.sol/IERC7579AccountConfig.json +1 -0
  314. package/out/draft-IERC7579.sol/IERC7579Execution.json +1 -0
  315. package/out/draft-IERC7579.sol/IERC7579Hook.json +1 -0
  316. package/out/draft-IERC7579.sol/IERC7579Module.json +1 -0
  317. package/out/draft-IERC7579.sol/IERC7579ModuleConfig.json +1 -0
  318. package/out/draft-IERC7579.sol/IERC7579Validator.json +1 -0
  319. package/out/draft-IERC7786.sol/IERC7786GatewaySource.json +1 -0
  320. package/out/draft-IERC7786.sol/IERC7786Recipient.json +1 -0
  321. package/out/draft-InteroperableAddress.sol/InteroperableAddress.json +1 -0
  322. package/out/libraries/Errors.sol/Errors.json +1 -1
  323. package/out/safeconsole.sol/safeconsole.json +1 -1
  324. package/package.json +11 -7
  325. package/contracts/ERC-3643/ERC3643EventsLib.sol +0 -150
  326. package/contracts/factory/ITREXGateway.sol +0 -234
  327. package/contracts/factory/TREXGateway.sol +0 -274
  328. package/contracts/proxy/AbstractProxy.sol +0 -146
  329. package/contracts/proxy/ClaimTopicsRegistryProxy.sol +0 -83
  330. package/contracts/proxy/IdentityRegistryProxy.sol +0 -95
  331. package/contracts/proxy/TokenProxy.sol +0 -97
  332. package/contracts/proxy/authority/IAFactory.sol +0 -122
  333. package/contracts/proxy/authority/IIAFactory.sol +0 -87
  334. package/contracts/proxy/authority/ITREXImplementationAuthority.sol +0 -239
  335. package/contracts/proxy/authority/TREXImplementationAuthority.sol +0 -350
  336. package/contracts/registry/implementation/ClaimTopicsRegistry.sol +0 -152
  337. package/contracts/registry/implementation/IdentityRegistry.sol +0 -352
  338. package/contracts/registry/implementation/TrustedIssuersRegistry.sol +0 -272
  339. package/contracts/registry/interface/IClaimTopicsRegistry.sol +0 -70
  340. package/contracts/registry/interface/IIdentityRegistry.sol +0 -102
  341. package/contracts/registry/interface/ITrustedIssuersRegistry.sol +0 -70
  342. package/contracts/roles/IERC173.sol +0 -21
  343. package/contracts/token/TokenStructs.sol +0 -74
  344. package/contracts/utils/InterfaceIdCalculator.sol +0 -223
  345. package/contracts/vendor/openzeppelin/Create3.sol +0 -143
  346. package/out/AbstractAgentRole.sol/AbstractAgentRole.json +0 -1
  347. package/out/AbstractProxy.sol/AbstractProxy.json +0 -1
  348. package/out/AgentRole.sol/AgentRole.json +0 -1
  349. package/out/AgentRoleUpgradeable.sol/AgentRoleUpgradeable.json +0 -1
  350. package/out/ClaimIssuer.sol/ClaimIssuer.json +0 -1
  351. package/out/ClaimTopicsRegistry.sol/ClaimTopicsRegistry.json +0 -1
  352. package/out/ClaimTopicsRegistryProxy.sol/ClaimTopicsRegistryProxy.json +0 -1
  353. package/out/ERC2771Context.sol/ERC2771Context.json +0 -1
  354. package/out/ERC2771ContextUpgradeable.sol/ERC2771ContextUpgradeable.json +0 -1
  355. package/out/ERC2771Forwarder.sol/ERC2771Forwarder.json +0 -1
  356. package/out/ERC3643EventsLib.sol/ERC3643EventsLib.json +0 -1
  357. package/out/IAFactory.sol/IAFactory.json +0 -1
  358. package/out/IClaimTopicsRegistry.sol/IClaimTopicsRegistry.json +0 -1
  359. package/out/IERC1363.sol/IERC1363.json +0 -1
  360. package/out/IIAFactory.sol/IIAFactory.json +0 -1
  361. package/out/IIdFactory.sol/IIdFactory.json +0 -1
  362. package/out/IIdentityRegistry.sol/IIdentityRegistry.json +0 -1
  363. package/out/IImplementationAuthority.sol/IImplementationAuthority.json +0 -1
  364. package/out/IProxy.sol/IProxy.json +0 -1
  365. package/out/ITREXGateway.sol/ITREXGateway.json +0 -1
  366. package/out/ITrustedIssuersRegistry.sol/ITrustedIssuersRegistry.json +0 -1
  367. package/out/IdFactory.sol/IdFactory.json +0 -1
  368. package/out/IdentityProxy.sol/IdentityProxy.json +0 -1
  369. package/out/IdentityRegistry.sol/IdentityRegistry.json +0 -1
  370. package/out/IdentityRegistryProxy.sol/IdentityRegistryProxy.json +0 -1
  371. package/out/IdentityRegistryStorageProxy.sol/IdentityRegistryStorageProxy.json +0 -1
  372. package/out/ImplementationAuthority.sol/ImplementationAuthority.json +0 -1
  373. package/out/InterfaceIdCalculator.sol/InterfaceIdCalculator.json +0 -1
  374. package/out/ModularComplianceProxy.sol/ModularComplianceProxy.json +0 -1
  375. package/out/Ownable2Step.sol/Ownable2Step.json +0 -1
  376. package/out/Ownable2StepUpgradeable.sol/Ownable2StepUpgradeable.json +0 -1
  377. package/out/Roles.sol/Roles.json +0 -1
  378. package/out/SafeERC20.sol/SafeERC20.json +0 -1
  379. package/out/Storage.sol/Storage.json +0 -1
  380. package/out/TREXGateway.sol/TREXGateway.json +0 -1
  381. package/out/TestAgentRole.sol/TestAgentRole.json +0 -1
  382. package/out/TestAgentRoleUpgradeable.sol/TestAgentRoleUpgradeable.json +0 -1
  383. package/out/TokenProxy.sol/TokenProxy.json +0 -1
  384. package/out/TrustedIssuersRegistry.sol/TrustedIssuersRegistry.json +0 -1
  385. package/out/TrustedIssuersRegistryProxy.sol/TrustedIssuersRegistryProxy.json +0 -1
  386. package/out/Version.sol/Version.json +0 -1
@@ -0,0 +1,183 @@
1
+ // SPDX-License-Identifier: GPL-3.0
2
+ //
3
+ // :+#####%%%%%%%%%%%%%%+
4
+ // .-*@@@%+.:+%@@@@@%%#***%@@%=
5
+ // :=*%@@@#=. :#@@% *@@@%=
6
+ // .-+*%@%*-.:+%@@@@@@+. -*+: .=#. :%@@@%-
7
+ // :=*@@@@%%@@@@@@@@@%@@@- .=#@@@%@%= =@@@@#.
8
+ // -=+#%@@%#*=:. :%@@@@%. -*@@#*@@@@@@@#=:- *@@@@+
9
+ // =@@%=:. :=: *@@@@@%#- =%*%@@@@#+-. =+ :%@@@%-
10
+ // -@@%. .+@@@ =+=-. @@#- +@@@%- =@@@@%:
11
+ // :@@@. .+@@#%: : .=*=-::.-%@@@+*@@= +@@@@#.
12
+ // %@@: +@%%* =%@@@@@@@@@@@#. .*@%- +@@@@*.
13
+ // #@@= .+@@@@%:=*@@@@@- :%@%: .*@@@@+
14
+ // *@@* +@@@#-@@%-:%@@* +@@#. :%@@@@-
15
+ // -@@% .:-=++*##%%%@@@@@@@@@@@@*. :@+.@@@%: .#@@+ =@@@@#:
16
+ // .@@@*-+*#%%%@@@@@@@@@@@@@@@@%%#**@@%@@@. *@=*@@# :#@%= .#@@@@#-
17
+ // -%@@@@@@@@@@@@@@@*+==-:-@@@= *@# .#@*-=*@@@@%= -%@@@* =@@@@@%-
18
+ // -+%@@@#. %@%%= -@@:+@: -@@* *@@*-:: -%@@%=. .*@@@@@#
19
+ // *@@@* +@* *@@##@@- #@*@@+ -@@= . :+@@@#: .-+@@@%+-
20
+ // +@@@%*@@:..=@@@@* .@@@* .#@#. .=+- .=%@@@*. :+#@@@@*=:
21
+ // =@@@@%@@@@@@@@@@@@@@@@@@@@@@%- :+#*. :*@@@%=. .=#@@@@%+:
22
+ // .%@@= ..... .=#@@+. .#@@@*: -*%@@@@%+.
23
+ // +@@#+===---:::... .=%@@*- +@@@+. -*@@@@@%+.
24
+ // -@@@@@@@@@@@@@@@@@@@@@@%@@@@= -@@@+ -#@@@@@#=.
25
+ // ..:::---===+++***###%%%@@@#- .#@@+ -*@@@@@#=.
26
+ // @@@@@@+. +@@*. .+@@@@@%=.
27
+ // -@@@@@= =@@%: -#@@@@%+.
28
+ // +@@@@@. =@@@= .+@@@@@*:
29
+ // #@@@@#:%@@#. :*@@@@#-
30
+ // @@@@@%@@@= :#@@@@+.
31
+ // :@@@@@@@#.:#@@@%-
32
+ // +@@@@@@-.*@@@*:
33
+ // #@@@@#.=@@@+.
34
+ // @@@@+-%@%=
35
+ // :@@@#%@%=
36
+ // +@@@@%-
37
+ // :#%%=
38
+ //
39
+
40
+ // T-REX Smart Contracts
41
+ // The ERC-3643 token suite of the T-REX ecosystem.
42
+ //
43
+ // Copyright (C) 2026 Digital Asset Operational Services ISAC Ltd. ("T-REX Network")
44
+ //
45
+ // This file is part of the T-REX smart contract suite.
46
+ //
47
+ // This program is free software: you can redistribute it and/or modify
48
+ // it under the terms of the GNU General Public License as published by
49
+ // the Free Software Foundation, either version 3 of the License, or
50
+ // (at your option) any later version.
51
+ //
52
+ // This program is distributed in the hope that it will be useful,
53
+ // but WITHOUT ANY WARRANTY; without even the implied warranty of
54
+ // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
55
+ // GNU General Public License for more details.
56
+ //
57
+ // You should have received a copy of the GNU General Public License
58
+ // along with this program. If not, see <https://www.gnu.org/licenses/>.
59
+
60
+ pragma solidity 0.8.30;
61
+
62
+ import { EventsLib } from "../../libraries/EventsLib.sol";
63
+ import { MessageTypesLib } from "../../libraries/MessageTypesLib.sol";
64
+ import { WalletKeyLib } from "../../libraries/WalletKeyLib.sol";
65
+ import { IToken } from "../../token/IToken.sol";
66
+ import { ComplianceLedgerLib } from "./ComplianceLedgerLib.sol";
67
+ import { ITransferValidation } from "./ITransferValidation.sol";
68
+
69
+ /**
70
+ * @title TransferValidationLib
71
+ * @dev The layout of the compliance's validation record, and the last step of an issuance, deployed once
72
+ * and linked: once every question about a requested validation is answered, this takes the next id, keeps
73
+ * the validation, reserves its amount, announces it and encodes what the satellites will execute against.
74
+ *
75
+ * That step is storage writes and ABI encoding the compliance would otherwise carry, and it is what kept
76
+ * it over EIP-170. The compliance reaches it by DELEGATECALL, so the storage is its own namespaces at the
77
+ * slots they always had, the token sees the compliance as its caller, and the event is the compliance's.
78
+ * Deciding whether a validation may be issued, and sending its legs, stay in the compliance.
79
+ */
80
+ library TransferValidationLib {
81
+
82
+ /// @custom:storage-location erc7201:erc3643.storage.TransferValidation
83
+ struct ValidationStorage {
84
+ /// Added to the issuance timestamp to compute `expiry`. Zero blocks issuance.
85
+ uint64 defaultValidityWindow;
86
+ /// Per-chain worst-case reconciliation latency. Zero blocks issuance toward that chain.
87
+ mapping(bytes32 chainKey => uint64 window) reconciliationWindows;
88
+ /// Per-chain issuance pause, set by the manager or a breaching late reconciliation, lifted by the manager
89
+ /// only.
90
+ mapping(bytes32 chainKey => bool paused) issuancePaused;
91
+ /// The last id issued. Ids start at 1.
92
+ uint256 lastValidationId;
93
+ /// Every issued validation, kept forever.
94
+ mapping(uint256 validationId => ITransferValidation.Validation validation) validations;
95
+ }
96
+
97
+ // keccak256(abi.encode(uint256(keccak256("erc3643.storage.TransferValidation")) - 1)) & ~bytes32(uint256(0xff));
98
+ bytes32 private constant VALIDATION_STORAGE_LOCATION =
99
+ 0x518dcda4927033bd42da8dd6047b92b4a950cebbc5bdd8461a5e9bb9c0545400;
100
+
101
+ /// @dev What issuance works out before the first write, in memory so the flow stays one function.
102
+ struct Draft {
103
+ bytes32 fromChainKey;
104
+ bytes32 toChainKey;
105
+ bool twoLegs;
106
+ address fromIdentity;
107
+ address toIdentity;
108
+ bytes32 fromKey;
109
+ uint256 amountMin;
110
+ uint256 amountMax;
111
+ uint64 expiry;
112
+ uint64 reconciliationWindow;
113
+ }
114
+
115
+ /// @dev Turns a settled draft into an issued validation: take the next id, build the object the satellite
116
+ /// will execute against, keep its terms, reserve the amount, then announce it.
117
+ /// @param token the token the compliance is bound to
118
+ /// @return validationId the id issued
119
+ /// @return body the encoded validation, for the compliance to send, one leg per satellite chain involved
120
+ function issue(bytes calldata from, bytes calldata to, bytes calldata spender, Draft memory draft, address token)
121
+ external
122
+ returns (uint256 validationId, bytes memory body)
123
+ {
124
+ validationId = ++layout().lastValidationId;
125
+
126
+ MessageTypesLib.ComplianceValidation memory issued = MessageTypesLib.ComplianceValidation({
127
+ validationId: validationId,
128
+ from: from,
129
+ to: to,
130
+ spender: spender,
131
+ amountMin: draft.amountMin,
132
+ amountMax: draft.amountMax,
133
+ expiry: draft.expiry,
134
+ reconciliationWindow: draft.reconciliationWindow,
135
+ token: token
136
+ });
137
+ _record(validationId, issued, from, to, draft, token);
138
+
139
+ emit EventsLib.TransferValidationIssued(
140
+ validationId, from, to, spender, draft.amountMin, draft.amountMax, draft.expiry, draft.reconciliationWindow
141
+ );
142
+
143
+ body = abi.encode(issued);
144
+ }
145
+
146
+ function layout() internal pure returns (ValidationStorage storage $) {
147
+ assembly ("memory-safe") {
148
+ $.slot := VALIDATION_STORAGE_LOCATION
149
+ }
150
+ }
151
+
152
+ /// @dev Keeps the validation forever and reserves its amount. Everything written here is the issuance half
153
+ /// of {ITransferValidation-Validation}; the lifecycle half stays at its zero value until a settlement or a
154
+ /// discard moves it.
155
+ function _record(
156
+ uint256 validationId,
157
+ MessageTypesLib.ComplianceValidation memory issued,
158
+ bytes calldata from,
159
+ bytes calldata to,
160
+ Draft memory draft,
161
+ address token
162
+ ) private {
163
+ ITransferValidation.Validation storage stored = layout().validations[validationId];
164
+ stored.hash = MessageTypesLib.hashValidation(issued);
165
+ stored.amountMin = draft.amountMin;
166
+ stored.amountMax = draft.amountMax;
167
+ stored.expiry = draft.expiry;
168
+ stored.releaseAt = draft.expiry + draft.reconciliationWindow;
169
+ stored.fromChainKey = draft.fromChainKey;
170
+ stored.toChainKey = draft.toChainKey;
171
+ stored.fromKey = draft.fromKey;
172
+ stored.fromWallet = from;
173
+ stored.toKey = WalletKeyLib.canonicalKey(to);
174
+ stored.twoLegs = draft.twoLegs;
175
+ stored.fromIdentity = draft.fromIdentity;
176
+ stored.toIdentity = draft.toIdentity;
177
+ stored.spender = issued.spender;
178
+ // `reservePending` returns whether it reserved against the identities; it does not on a relocation.
179
+ stored.relocation = !ComplianceLedgerLib.reservePending(draft.fromIdentity, draft.toIdentity, draft.amountMax);
180
+ IToken(token).reserveForValidation(from, draft.amountMax);
181
+ }
182
+
183
+ }
@@ -36,63 +36,78 @@
36
36
  // +@@@@%-
37
37
  // :#%%=
38
38
  //
39
- /**
40
- * NOTICE
41
- *
42
- * The T-REX software is licensed under a proprietary license or the GPL v.3.
43
- * If you choose to receive it under the GPL v.3 license, the following applies:
44
- * T-REX is a suite of smart contracts implementing the ERC-3643 standard and
45
- * developed by Tokeny to manage and transfer financial assets on EVM blockchains
46
- *
47
- * Copyright (C) 2025, Tokeny sàrl.
48
- *
49
- * This program is free software: you can redistribute it and/or modify
50
- * it under the terms of the GNU General Public License as published by
51
- * the Free Software Foundation, either version 3 of the License, or
52
- * (at your option) any later version.
53
- *
54
- * This program is distributed in the hope that it will be useful,
55
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
56
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
57
- * GNU General Public License for more details.
58
- *
59
- * You should have received a copy of the GNU General Public License
60
- * along with this program. If not, see <https://www.gnu.org/licenses/>.
61
- */
39
+
40
+ // T-REX Smart Contracts
41
+ // The ERC-3643 token suite of the T-REX ecosystem.
42
+ //
43
+ // Copyright (C) 2023, Tokeny sàrl.
44
+ // Copyright (C) 2026 Digital Asset Operational Services ISAC Ltd. ("T-REX Network")
45
+ //
46
+ // This file is part of the T-REX smart contract suite. It derives from the
47
+ // T-REX v4 smart contracts developed by Tokeny sàrl and released under the
48
+ // GNU General Public License v3. All modifications made since then are the
49
+ // work of Digital Asset Operational Services ISAC Ltd. ("T-REX Network").
50
+ //
51
+ // This program is free software: you can redistribute it and/or modify
52
+ // it under the terms of the GNU General Public License as published by
53
+ // the Free Software Foundation, either version 3 of the License, or
54
+ // (at your option) any later version.
55
+ //
56
+ // This program is distributed in the hope that it will be useful,
57
+ // but WITHOUT ANY WARRANTY; without even the implied warranty of
58
+ // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
59
+ // GNU General Public License for more details.
60
+ //
61
+ // You should have received a copy of the GNU General Public License
62
+ // along with this program. If not, see <https://www.gnu.org/licenses/>.
62
63
 
63
64
  pragma solidity 0.8.30;
64
65
 
65
- import { Ownable2StepUpgradeable } from "@openzeppelin/contracts-upgradeable/access/Ownable2StepUpgradeable.sol";
66
66
  import { Initializable } from "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
67
67
  import { UUPSUpgradeable } from "@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol";
68
68
  import { MulticallUpgradeable } from "@openzeppelin/contracts-upgradeable/utils/MulticallUpgradeable.sol";
69
- import { IERC165 } from "@openzeppelin/contracts/utils/introspection/IERC165.sol";
69
+ import { ERC165Upgradeable } from "@openzeppelin/contracts-upgradeable/utils/introspection/ERC165Upgradeable.sol";
70
70
 
71
71
  import { ErrorsLib } from "../../../libraries/ErrorsLib.sol";
72
72
  import { EventsLib } from "../../../libraries/EventsLib.sol";
73
- import { IERC173 } from "../../../roles/IERC173.sol";
73
+ import { IModularCompliance } from "../IModularCompliance.sol";
74
74
  import { IModule } from "./IModule.sol";
75
75
 
76
+ /**
77
+ * @dev Base for every compliance module: the binding handshake, the bind nonce, and a default for every
78
+ * question so a module writes only what it answers.
79
+ *
80
+ * A module overrides {moduleTypes} to say what it is, then overrides the functions of those types. The
81
+ * defaults here are the neutral answer: no limit, spender allowed, nothing recorded. A module that names a
82
+ * type and forgets to override its function therefore lets everything through rather than reverting, which is
83
+ * why {moduleTypes} and the overrides are reviewed together.
84
+ *
85
+ * What a module names is read at binding. An upgrade that changes it takes effect once each bound compliance
86
+ * calls `resyncModuleTypes`.
87
+ */
76
88
  abstract contract AbstractModuleUpgradeable is
77
89
  IModule,
78
90
  Initializable,
79
- Ownable2StepUpgradeable,
80
91
  UUPSUpgradeable,
81
92
  MulticallUpgradeable,
82
- IERC165
93
+ ERC165Upgradeable
83
94
  {
84
95
 
85
- /// @custom:storage-location erc7201:ERC3643.storage.AbstractModule
96
+ /// @custom:storage-location erc7201:erc3643.storage.AbstractModuleUpgradeable
86
97
  struct AbstractModuleStorage {
87
- /// compliance contract binding status
88
- mapping(address => bool) complianceBound;
89
- /// nonce for the module
90
- mapping(address => uint256) nonces;
98
+ /// Compliance contract binding status
99
+ mapping(address compliance => bool) complianceBound;
100
+
101
+ /// Bind nonce per compliance, incremented on every unbind.
102
+ /// @dev A module that keys its own per-compliance storage by this nonce drops all of it in a single
103
+ /// write when the compliance unbinds, instead of iterating and clearing entry by entry. The old
104
+ /// entries are never read again and stay behind as harmless orphans.
105
+ mapping(address compliance => uint256) nonces;
91
106
  }
92
107
 
93
- // keccak256(abi.encode(uint256(keccak256("ERC3643.storage.AbstractModule")) - 1)) & ~bytes32(uint256(0xff))
108
+ // keccak256(abi.encode(uint256(keccak256("erc3643.storage.AbstractModuleUpgradeable")) - 1)) & ~bytes32(uint256(0xff))
94
109
  bytes32 private constant _ABSTRACT_MODULE_STORAGE_LOCATION =
95
- 0xf6cc97de1266c180cd39f3b311632644143ce7873d2927755382ad4b39e8ae00;
110
+ 0x444fa4c260ed0f6b1ae0af41fab4e6d2db0fa3e7e1fd34f89c069636d02e9200;
96
111
 
97
112
  /**
98
113
  * @dev Throws if `_compliance` is not a bound compliance contract address.
@@ -120,7 +135,7 @@ abstract contract AbstractModuleUpgradeable is
120
135
  /**
121
136
  * @dev See {IModule-bindCompliance}.
122
137
  */
123
- function bindCompliance(address _compliance) external override onlyProxy {
138
+ function bindCompliance(address _compliance) external onlyProxy {
124
139
  AbstractModuleStorage storage s = _getAbstractModuleStorage();
125
140
  require(_compliance != address(0), ErrorsLib.ZeroAddress());
126
141
  require(!s.complianceBound[_compliance], ErrorsLib.ComplianceAlreadyBound());
@@ -131,11 +146,13 @@ abstract contract AbstractModuleUpgradeable is
131
146
 
132
147
  /**
133
148
  * @dev See {IModule-unbindCompliance}.
149
+ * Increments the bind nonce of `_compliance`, which invalidates any module storage keyed by it.
134
150
  */
135
- function unbindCompliance(address _compliance) external override onlyComplianceCall onlyProxy {
151
+ function unbindCompliance(address _compliance) external onlyComplianceCall onlyProxy {
136
152
  AbstractModuleStorage storage s = _getAbstractModuleStorage();
137
153
  require(_compliance != address(0), ErrorsLib.ZeroAddress());
138
154
  require(msg.sender == _compliance, ErrorsLib.OnlyComplianceContractCanCall());
155
+ require(!IModularCompliance(_compliance).isModuleBound(address(this)), ErrorsLib.ModuleStillBound());
139
156
 
140
157
  s.complianceBound[_compliance] = false;
141
158
  s.nonces[_compliance]++;
@@ -143,14 +160,42 @@ abstract contract AbstractModuleUpgradeable is
143
160
  emit EventsLib.ComplianceUnbound(_compliance);
144
161
  }
145
162
 
163
+ /**
164
+ * @dev See {IModule-afterTransfer}.
165
+ * Default no-op: a module overrides it only when it names `TRACKER`.
166
+ */
167
+ // solhint-disable-next-line no-empty-blocks
168
+ function afterTransfer(TransferContext calldata) external virtual onlyComplianceCall { }
169
+
170
+ /**
171
+ * @dev See {IModule-allowedAmount}.
172
+ * Default no limit: a module overrides it only when it names `RULE`.
173
+ */
174
+ function allowedAmount(TransferContext calldata) external view virtual returns (uint256) {
175
+ return type(uint256).max;
176
+ }
177
+
178
+ /**
179
+ * @dev See {IModule-moduleCheckSpender}.
180
+ * Default allowed: a module overrides it only when it names `SPENDER`.
181
+ */
182
+ function moduleCheckSpender(TransferContext calldata) external view virtual returns (bool) {
183
+ return true;
184
+ }
185
+
146
186
  /**
147
187
  * @dev See {IModule-isComplianceBound}.
148
188
  */
149
- function isComplianceBound(address _compliance) external view override returns (bool) {
189
+ function isComplianceBound(address _compliance) external view returns (bool) {
150
190
  AbstractModuleStorage storage s = _getAbstractModuleStorage();
151
191
  return s.complianceBound[_compliance];
152
192
  }
153
193
 
194
+ /**
195
+ * @dev Returns the current bind nonce of `_compliance`, starting at 0 and incremented on every
196
+ * unbind. Modules key their per-compliance storage by this value so that an unbind discards it.
197
+ * @param _compliance compliance contract address
198
+ */
154
199
  function getNonce(address _compliance) public view returns (uint256) {
155
200
  AbstractModuleStorage storage s = _getAbstractModuleStorage();
156
201
  return s.nonces[_compliance];
@@ -159,33 +204,19 @@ abstract contract AbstractModuleUpgradeable is
159
204
  /**
160
205
  * @dev See {IERC165-supportsInterface}.
161
206
  */
162
- function supportsInterface(bytes4 interfaceId) public pure virtual override returns (bool) {
163
- return interfaceId == type(IModule).interfaceId || interfaceId == type(IERC173).interfaceId
164
- || interfaceId == type(IERC165).interfaceId;
207
+ function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
208
+ return interfaceId == type(IModule).interfaceId || super.supportsInterface(interfaceId);
165
209
  }
166
210
 
167
- // solhint-disable-next-line func-name-mixedcase
168
211
  function __AbstractModule_init() internal onlyInitializing {
169
- __Ownable_init(msg.sender);
212
+ __ERC165_init();
170
213
  __AbstractModule_init_unchained();
171
214
  }
172
215
 
173
- // solhint-disable-next-line no-empty-blocks, func-name-mixedcase
174
216
  function __AbstractModule_init_unchained() internal onlyInitializing { }
175
217
 
176
- // solhint-disable-next-line no-empty-blocks
177
- function _authorizeUpgrade(
178
- address /*newImplementation*/
179
- )
180
- internal
181
- virtual
182
- override
183
- onlyOwner
184
- { }
185
-
186
218
  function _getAbstractModuleStorage() private pure returns (AbstractModuleStorage storage s) {
187
- // solhint-disable-next-line no-inline-assembly
188
- assembly {
219
+ assembly ("memory-safe") {
189
220
  s.slot := _ABSTRACT_MODULE_STORAGE_LOCATION
190
221
  }
191
222
  }
@@ -36,35 +36,103 @@
36
36
  // +@@@@%-
37
37
  // :#%%=
38
38
  //
39
- /**
40
- * NOTICE
41
- *
42
- * The T-REX software is licensed under a proprietary license or the GPL v.3.
43
- * If you choose to receive it under the GPL v.3 license, the following applies:
44
- * T-REX is a suite of smart contracts implementing the ERC-3643 standard and
45
- * developed by Tokeny to manage and transfer financial assets on EVM blockchains
46
- *
47
- * Copyright (C) 2025, Tokeny sàrl.
48
- *
49
- * This program is free software: you can redistribute it and/or modify
50
- * it under the terms of the GNU General Public License as published by
51
- * the Free Software Foundation, either version 3 of the License, or
52
- * (at your option) any later version.
53
- *
54
- * This program is distributed in the hope that it will be useful,
55
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
56
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
57
- * GNU General Public License for more details.
58
- *
59
- * You should have received a copy of the GNU General Public License
60
- * along with this program. If not, see <https://www.gnu.org/licenses/>.
61
- */
39
+
40
+ // T-REX Smart Contracts
41
+ // The ERC-3643 token suite of the T-REX ecosystem.
42
+ //
43
+ // Copyright (C) 2023, Tokeny sàrl.
44
+ // Copyright (C) 2026 Digital Asset Operational Services ISAC Ltd. ("T-REX Network")
45
+ //
46
+ // This file is part of the T-REX smart contract suite. It derives from the
47
+ // T-REX v4 smart contracts developed by Tokeny sàrl and released under the
48
+ // GNU General Public License v3. All modifications made since then are the
49
+ // work of Digital Asset Operational Services ISAC Ltd. ("T-REX Network").
50
+ //
51
+ // This program is free software: you can redistribute it and/or modify
52
+ // it under the terms of the GNU General Public License as published by
53
+ // the Free Software Foundation, either version 3 of the License, or
54
+ // (at your option) any later version.
55
+ //
56
+ // This program is distributed in the hope that it will be useful,
57
+ // but WITHOUT ANY WARRANTY; without even the implied warranty of
58
+ // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
59
+ // GNU General Public License for more details.
60
+ //
61
+ // You should have received a copy of the GNU General Public License
62
+ // along with this program. If not, see <https://www.gnu.org/licenses/>.
62
63
 
63
64
  pragma solidity 0.8.30;
64
65
 
66
+ /// @title IModule
67
+ /// @dev Everything a compliance module implements. One interface, no sub-interfaces, no bitmask.
68
+ ///
69
+ /// A module says what it is through {moduleTypes}, read once at binding, and the compliance calls it only
70
+ /// where it said so:
71
+ /// - `RULE`: asked {allowedAmount}, the largest amount it allows; the compliance takes the minimum;
72
+ /// - `SPENDER`: asked {moduleCheckSpender}, whether the operator named in the context may execute the movement;
73
+ /// - `TRACKER`: told {afterTransfer} after the ledger moved.
74
+ ///
75
+ /// A module never calls another module. It reads the compliance's ledger ({IComplianceLedger}: position and
76
+ /// pending amounts per identity) and the token's identity registry, and keeps nothing but its own settings
77
+ /// and its own counters.
78
+ ///
79
+ /// Reserve before calling out. A module that accumulates state in its own storage (a per-period counter, a
80
+ /// window) must record the amount BEFORE it makes any external call, and rely on transaction rollback to undo
81
+ /// that record if the operation later fails. The token wraps each operation in a reentrancy guard, so a
82
+ /// callback cannot reenter the token itself. That guard does not extend to calls a module makes to other
83
+ /// contracts, which is why the discipline is required here rather than assumed from the guard.
65
84
  interface IModule {
66
85
 
67
- /// functions
86
+ /// @dev What a module is. A module names one, two or all three, never the same one twice.
87
+ enum ModuleType {
88
+ /// Answers {allowedAmount}.
89
+ RULE,
90
+ /// Answers {moduleCheckSpender}.
91
+ SPENDER,
92
+ /// Is told {afterTransfer}.
93
+ TRACKER
94
+ }
95
+
96
+ /// @dev Everything a module needs to know about a movement, resolved once by the compliance.
97
+ struct TransferContext {
98
+ /// The compliance asking. Modules read the ledger and their settings from it, never from
99
+ /// `msg.sender`, so that tooling can ask the same question from any address.
100
+ address compliance;
101
+ /// Identity of the sender. Zero on a mint.
102
+ address fromIdentity;
103
+ /// Identity of the recipient. Zero on a burn.
104
+ address toIdentity;
105
+ /// Canonical key of the sending wallet: a native address padded on the left, or `keccak256` of a
106
+ /// satellite envelope. Zero on a mint.
107
+ bytes32 fromWallet;
108
+ /// Canonical key of the receiving wallet. Zero on a burn.
109
+ bytes32 toWallet;
110
+ /// Inclusive lower bound of the movement. Equal to `amountMax` on a native movement.
111
+ uint256 amountMin;
112
+ /// Inclusive upper bound: the exact amount on a native movement, and the exact amount that moved
113
+ /// when a `TRACKER` is told about one; the requested maximum, already capped at what the sending
114
+ /// wallet holds, on an issuance.
115
+ uint256 amountMax;
116
+ /// What produced the movement: one of the `MovementKindLib` constants, never zero. A number and not an
117
+ /// enum, so a kind this module was not written for decodes instead of reverting. A module MUST NOT
118
+ /// revert on a kind it does not know; what it does with one is its own, deliberate choice.
119
+ uint8 kind;
120
+ /// True while a validation is being issued for a satellite movement.
121
+ bool isIssuance;
122
+ /// ERC-7930 envelope of who executes the movement on the sender's behalf: the caller of `transferFrom`
123
+ /// on a native movement, the spender named on a validation, at its issuance and at its settlement.
124
+ /// Empty when the sender executes itself, which is every direct transfer, mint and burn.
125
+ bytes spender;
126
+ /// Room for what a later compliance has to say that this struct does not carry yet. Empty today.
127
+ /// This struct is a parameter of every module function, so it is part of their selectors: a field
128
+ /// added after modules are deployed changes the selectors and breaks every one of them. A new fact
129
+ /// goes here instead. The compliance that fills it documents the shape as an `abi.encode`d tuple and
130
+ /// only ever appends to that tuple, so a module that decodes the prefix it knows keeps working when
131
+ /// a later fact is added. A module decodes `data` only when it knows the compliance that fills it,
132
+ /// and ignores it otherwise.
133
+ bytes data;
134
+ }
135
+
68
136
  /**
69
137
  * @dev binds the module to a compliance contract
70
138
  * once the module is bound, the compliance contract can interact with the module
@@ -87,50 +155,66 @@ interface IModule {
87
155
  function unbindCompliance(address _compliance) external;
88
156
 
89
157
  /**
90
- * @dev action performed on the module during a transfer action
91
- * this function is used to update variables of the module upon transfer if it is required
92
- * if the module does not require state updates in case of transfer, this function remains empty
93
- * This function can be called ONLY by the compliance contract itself (_compliance)
94
- * This function can be called only on a compliance contract that is bound to the module
95
- * @param _from address of the transfer sender
96
- * @param _to address of the transfer receiver
97
- * @param _value amount of tokens sent
158
+ * @dev the ledger moved. Called on every `TRACKER` module after the compliance updated the positions, on
159
+ * a native transfer, a mint, a burn, a forced transfer, a recovery and a settled validation
160
+ * the movement is entirely in `ctx`: `ctx.amountMax` is the exact amount that moved, `ctx.kind` says
161
+ * what produced it, a zero `fromIdentity` and `fromWallet` mean a mint, a zero `toIdentity` and
162
+ * `toWallet` mean a burn. That is the convention {allowedAmount} already uses, so one function covers
163
+ * what three hooks used to
164
+ * reverting stops the movement: a module that cannot record a move has to stop it. `forceRemoveModule`
165
+ * is the escape hatch for a module that reverts everywhere
166
+ * MUST NOT revert on a `ctx.kind` it does not know: a kind added later has to keep moving through
167
+ * modules deployed before it. The module decides what an unknown kind means for its own count, on
168
+ * purpose: left out, like an agent's movement, or recorded, like any change of ownership
169
+ * This function can be called ONLY by the compliance contract itself
170
+ * @param ctx the movement, see {TransferContext}; `amountMin == amountMax`
98
171
  */
99
- function moduleTransferAction(address _from, address _to, uint256 _value) external;
172
+ function afterTransfer(TransferContext calldata ctx) external;
100
173
 
101
174
  /**
102
- * @dev action performed on the module during a mint action
103
- * this function is used to update variables of the module upon minting if it is required
104
- * if the module does not require state updates in case of mint, this function remains empty
105
- * This function can be called ONLY by the compliance contract itself (_compliance)
106
- * This function can be called only on a compliance contract that is bound to the module
107
- * @param _to address used for minting
108
- * @param _value amount of tokens minted
175
+ * @dev the largest amount this rule allows to move. Called on every `RULE` module, on a native transfer
176
+ * and a mint (`canTransfer`) and on the issuance of a validation (`ctx.isIssuance` set)
177
+ * the compliance takes the minimum over the declaring modules: a native movement passes when `amountMax`
178
+ * is at most that minimum; an issuance narrows its range to `[amountMin, minimum]`
179
+ * `type(uint256).max` means no limit, 0 means refused
180
+ * the rule has to be monotonic: a smaller amount is never less acceptable than a larger one. A rule that
181
+ * is not (a multiple of some unit, for instance) evaluates `ctx.amountMax` and returns `max` or 0, and
182
+ * refuses an issuance whose range is not a point (`ctx.amountMin != ctx.amountMax`), since the satellite
183
+ * may execute any amount inside the range
184
+ * identities arrive resolved and the ledger describes the state before the move
185
+ * a native movement between two wallets of one identity (`ctx.fromIdentity == ctx.toIdentity`, non-zero)
186
+ * reaches this function and a rule about distribution answers `max` on it; the issuance of such a
187
+ * movement does not, because it changes no position
188
+ * MUST be a view: the compliance calls it under `staticcall` and a module that writes there reverts
189
+ * MUST NOT revert on a `ctx.kind` it does not know; it answers for it like for any kind it was not
190
+ * written about
191
+ * @param ctx the movement, see {TransferContext}
192
+ * @return the largest amount allowed
109
193
  */
110
- function moduleMintAction(address _to, uint256 _value) external;
194
+ function allowedAmount(TransferContext calldata ctx) external view returns (uint256);
111
195
 
112
196
  /**
113
- * @dev action performed on the module during a burn action
114
- * this function is used to update variables of the module upon burning if it is required
115
- * if the module does not require state updates in case of burn, this function remains empty
116
- * This function can be called ONLY by the compliance contract itself (_compliance)
117
- * This function can be called only on a compliance contract that is bound to the module
118
- * @param _from address on which tokens are burnt
119
- * @param _value amount of tokens burnt
197
+ * @dev whether `ctx.spender` may execute the movement on the sender's behalf. Called on every `SPENDER`
198
+ * module from `canSpenderCall`, which the token runs before spending an allowance in `transferFrom`, and
199
+ * at the issuance of a validation that names a spender (`ctx.isIssuance` set), since no module runs on
200
+ * the satellite and issuance is the only place that spender can be refused
201
+ * all declaring modules must agree. A direct transfer never reaches this path: the spender is the sender
202
+ * `ctx.spender` is never empty here
203
+ * MUST be a view: the compliance calls it under `staticcall`
204
+ * MUST NOT revert on a `ctx.kind` it does not know
205
+ * @param ctx the movement, see {TransferContext}
206
+ * @return true if the module allows the spender to execute it, false otherwise
120
207
  */
121
- function moduleBurnAction(address _from, uint256 _value) external;
208
+ function moduleCheckSpender(TransferContext calldata ctx) external view returns (bool);
122
209
 
123
210
  /**
124
- * @dev compliance check on the module for a specific transaction on a specific compliance contract
125
- * this function is used to check if the transfer is allowed by the module
126
- * This function can be called only on a compliance contract that is bound to the module
127
- * @param _from address of the transfer sender
128
- * @param _to address of the transfer receiver
129
- * @param _value amount of tokens sent
130
- * @param _compliance address of the compliance contract concerned by the transfer action
131
- * the function returns TRUE if the module allows the transfer, FALSE otherwise
211
+ * @dev what this module is, see {ModuleType}
212
+ * the compliance reads it once, at binding, and routes the module accordingly. A module that names none
213
+ * is refused, and so is one naming the same type twice
214
+ * MUST be pure: a value read from storage would let the recorded routing drift from the real behaviour
215
+ * @return the types this module implements
132
216
  */
133
- function moduleCheck(address _from, address _to, uint256 _value, address _compliance) external view returns (bool);
217
+ function moduleTypes() external pure returns (ModuleType[] memory);
134
218
 
135
219
  /**
136
220
  * @dev getter for compliance binding status on module