@t-rex-network/t-rex 4.2.0-beta1 → 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 +24 -27
  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 +14 -11
  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,484 @@
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 { IIdentityFactory } from "@onchain-id/solidity/contracts/factory/IIdentityFactory.sol";
63
+ import { IdentityTypes } from "@onchain-id/solidity/contracts/libraries/IdentityTypes.sol";
64
+ import { IAccessManager } from "@openzeppelin/contracts/access/manager/IAccessManager.sol";
65
+
66
+ import { IERC3643 } from "../ERC-3643/IERC3643.sol";
67
+ import { IERC3643ClaimTopicsRegistry } from "../ERC-3643/IERC3643ClaimTopicsRegistry.sol";
68
+ import { IERC3643Compliance } from "../ERC-3643/IERC3643Compliance.sol";
69
+ import { IERC3643IdentityRegistry } from "../ERC-3643/IERC3643IdentityRegistry.sol";
70
+ import { IERC3643IdentityRegistryStorage } from "../ERC-3643/IERC3643IdentityRegistryStorage.sol";
71
+ import { IERC3643TrustedIssuersRegistry } from "../ERC-3643/IERC3643TrustedIssuersRegistry.sol";
72
+ import { ITransferValidation } from "../compliance/modular/ITransferValidation.sol";
73
+ import { ModularCompliance } from "../compliance/modular/ModularCompliance.sol";
74
+ import { ITREXFactory } from "../factory/ITREXFactory.sol";
75
+ import { ITREXMessaging } from "../interop/ITREXMessaging.sol";
76
+ import { TrustedGatewayRegistry } from "../interop/TrustedGatewayRegistry.sol";
77
+ import { TREXImplementationAuthority } from "../proxy/beacon/TREXImplementationAuthority.sol";
78
+ import { IdentityRegistryStorage } from "../registry/implementation/IdentityRegistryStorage.sol";
79
+ import { TREXRegistry } from "../registry/implementation/TREXRegistry.sol";
80
+ import { IIdentityRegistryStorage } from "../registry/interface/IIdentityRegistryStorage.sol";
81
+ import { IToken } from "../token/IToken.sol";
82
+ import { TREXAccessManager } from "../utils/TREXAccessManager.sol";
83
+ import { ErrorsLib } from "./ErrorsLib.sol";
84
+ import { RolesLib } from "./RolesLib.sol";
85
+
86
+ /// @title AccessManagerSetupLib
87
+ /// @notice Library for setting up roles and functions in AccessManager for the TREX suite contracts
88
+ library AccessManagerSetupLib {
89
+
90
+ struct SelectorRole {
91
+ bytes4 selector;
92
+ RolesLib.Role role;
93
+ }
94
+
95
+ struct RoleAdmin {
96
+ RolesLib.Role role;
97
+ RolesLib.Role admin;
98
+ }
99
+
100
+ uint64 internal constant ADMIN_ROLE = 0;
101
+ uint64 internal constant PUBLIC_ROLE = RolesLib.PUBLIC_ROLE;
102
+
103
+ function setupTokenRoles(IAccessManager accessManager, address token, uint32 domainId) internal {
104
+ _apply(accessManager, token, tokenTable(), domainId);
105
+ }
106
+
107
+ function setupIdentityRegistryStorageRoles(
108
+ IAccessManager accessManager,
109
+ address identityRegistryStorage,
110
+ uint32 domainId
111
+ ) internal {
112
+ _apply(accessManager, identityRegistryStorage, storageTable(), domainId);
113
+ }
114
+
115
+ function setupTREXRegistryRoles(IAccessManager accessManager, address registry, uint32 domainId) internal {
116
+ _apply(accessManager, registry, registryTable(), domainId);
117
+ }
118
+
119
+ function setupModularComplianceRoles(IAccessManager accessManager, address modularCompliance, uint32 domainId)
120
+ internal
121
+ {
122
+ _apply(accessManager, modularCompliance, complianceTable(), domainId);
123
+ }
124
+
125
+ /// @dev Each batch has a row of its own, on the role of its single-item function. Without one it is
126
+ /// authorized through that function's role with immediate permission only, so an agent granted with
127
+ /// an execution delay could not schedule it. To restrict a batch further, map it to a nonzero role:
128
+ /// `ADMIN_ROLE` is role zero, which reads as "no row" (see `_checkCanCallSelector`).
129
+ function tokenTable() internal pure returns (SelectorRole[] memory table) {
130
+ table = new SelectorRole[](25);
131
+ table[0] = SelectorRole(IERC3643.setName.selector, RolesLib.Role.TOKEN_MANAGER);
132
+ table[1] = SelectorRole(IERC3643.setSymbol.selector, RolesLib.Role.TOKEN_MANAGER);
133
+ table[2] = SelectorRole(IERC3643.setOnchainID.selector, RolesLib.Role.IDENTITY_MANAGER);
134
+ table[3] = SelectorRole(IERC3643.setIdentityRegistry.selector, RolesLib.Role.IDENTITY_MANAGER);
135
+ table[4] = SelectorRole(IERC3643.setCompliance.selector, RolesLib.Role.IDENTITY_MANAGER);
136
+ table[5] = SelectorRole(ITREXMessaging.setRoute.selector, RolesLib.Role.IDENTITY_MANAGER);
137
+ table[6] = SelectorRole(ITREXMessaging.setPeer.selector, RolesLib.Role.IDENTITY_MANAGER);
138
+ table[7] = SelectorRole(IToken.delegateOut.selector, RolesLib.Role.AGENT);
139
+ table[8] = SelectorRole(IToken.instructRecall.selector, RolesLib.Role.AGENT);
140
+ table[9] = SelectorRole(IToken.resend.selector, RolesLib.Role.AGENT);
141
+ table[10] = SelectorRole(IERC3643.mint.selector, RolesLib.Role.AGENT_MINTER);
142
+ table[11] = SelectorRole(IERC3643.batchMint.selector, RolesLib.Role.AGENT_MINTER);
143
+ table[12] = SelectorRole(IERC3643.burn.selector, RolesLib.Role.AGENT_BURNER);
144
+ table[13] = SelectorRole(IERC3643.batchBurn.selector, RolesLib.Role.AGENT_BURNER);
145
+ table[14] = SelectorRole(IERC3643.freezePartialTokens.selector, RolesLib.Role.AGENT_PARTIAL_FREEZER);
146
+ table[15] = SelectorRole(IERC3643.batchFreezePartialTokens.selector, RolesLib.Role.AGENT_PARTIAL_FREEZER);
147
+ table[16] = SelectorRole(IERC3643.unfreezePartialTokens.selector, RolesLib.Role.AGENT_PARTIAL_FREEZER);
148
+ table[17] = SelectorRole(IERC3643.batchUnfreezePartialTokens.selector, RolesLib.Role.AGENT_PARTIAL_FREEZER);
149
+ table[18] = SelectorRole(IERC3643.setAddressFrozen.selector, RolesLib.Role.AGENT_ADDRESS_FREEZER);
150
+ table[19] = SelectorRole(IERC3643.batchSetAddressFrozen.selector, RolesLib.Role.AGENT_ADDRESS_FREEZER);
151
+ table[20] = SelectorRole(IERC3643.recoveryAddress.selector, RolesLib.Role.AGENT_RECOVERY_ADDRESS);
152
+ table[21] = SelectorRole(IERC3643.forcedTransfer.selector, RolesLib.Role.AGENT_FORCED_TRANSFER);
153
+ table[22] = SelectorRole(IERC3643.batchForcedTransfer.selector, RolesLib.Role.AGENT_FORCED_TRANSFER);
154
+ table[23] = SelectorRole(IERC3643.pause.selector, RolesLib.Role.AGENT_PAUSER);
155
+ table[24] = SelectorRole(IERC3643.unpause.selector, RolesLib.Role.AGENT_PAUSER);
156
+ }
157
+
158
+ function registryTable() internal pure returns (SelectorRole[] memory table) {
159
+ table = new SelectorRole[](13);
160
+ table[0] = SelectorRole(TREXRegistry.disableEligibilityChecks.selector, RolesLib.Role.OWNER);
161
+ table[1] = SelectorRole(TREXRegistry.enableEligibilityChecks.selector, RolesLib.Role.OWNER);
162
+ table[2] = SelectorRole(IERC3643TrustedIssuersRegistry.addTrustedIssuer.selector, RolesLib.Role.OWNER);
163
+ table[3] = SelectorRole(IERC3643TrustedIssuersRegistry.removeTrustedIssuer.selector, RolesLib.Role.OWNER);
164
+ table[4] = SelectorRole(IERC3643TrustedIssuersRegistry.updateIssuerClaimTopics.selector, RolesLib.Role.OWNER);
165
+ table[5] = SelectorRole(IERC3643ClaimTopicsRegistry.addClaimTopic.selector, RolesLib.Role.OWNER);
166
+ table[6] = SelectorRole(IERC3643ClaimTopicsRegistry.removeClaimTopic.selector, RolesLib.Role.OWNER);
167
+ table[7] = SelectorRole(TREXRegistry.addClaimTopicForIdentityType.selector, RolesLib.Role.OWNER);
168
+ table[8] = SelectorRole(TREXRegistry.removeClaimTopicForIdentityType.selector, RolesLib.Role.OWNER);
169
+ // {_requireFreshOrInDomain} reads this row to tell which domain a registry is in.
170
+ table[9] = SelectorRole(IERC3643IdentityRegistry.registerIdentity.selector, RolesLib.Role.AGENT);
171
+ table[10] = SelectorRole(IERC3643IdentityRegistry.batchRegisterIdentity.selector, RolesLib.Role.AGENT);
172
+ table[11] = SelectorRole(IERC3643IdentityRegistry.updateIdentity.selector, RolesLib.Role.AGENT);
173
+ table[12] = SelectorRole(IERC3643IdentityRegistry.deleteIdentity.selector, RolesLib.Role.AGENT);
174
+ }
175
+
176
+ function storageTable() internal pure returns (SelectorRole[] memory table) {
177
+ table = new SelectorRole[](5);
178
+ table[0] = SelectorRole(IdentityRegistryStorage.bindIdentityRegistry.selector, RolesLib.Role.IRS_BINDER);
179
+ table[1] = SelectorRole(IdentityRegistryStorage.unbindIdentityRegistry.selector, RolesLib.Role.OWNER);
180
+ // {_requireFreshOrInDomain} reads this row to tell which domain a storage is in.
181
+ table[2] = SelectorRole(IERC3643IdentityRegistryStorage.addIdentityToStorage.selector, RolesLib.Role.IRS_WRITER);
182
+ table[3] = SelectorRole(IERC3643IdentityRegistryStorage.modifyStoredIdentity.selector, RolesLib.Role.IRS_WRITER);
183
+ table[4] =
184
+ SelectorRole(IERC3643IdentityRegistryStorage.removeIdentityFromStorage.selector, RolesLib.Role.IRS_WRITER);
185
+ }
186
+
187
+ function complianceTable() internal pure returns (SelectorRole[] memory table) {
188
+ table = new SelectorRole[](14);
189
+ table[0] = SelectorRole(ModularCompliance.removeModule.selector, RolesLib.Role.OWNER);
190
+ table[1] = SelectorRole(ModularCompliance.forceRemoveModule.selector, RolesLib.Role.OWNER);
191
+ table[2] = SelectorRole(ModularCompliance.addAndSetModule.selector, RolesLib.Role.OWNER);
192
+ // {_requireFreshOrInDomain} reads this row to tell which domain a compliance is in.
193
+ table[3] = SelectorRole(ModularCompliance.addModule.selector, RolesLib.Role.OWNER);
194
+ table[4] = SelectorRole(ModularCompliance.callModuleFunction.selector, RolesLib.Role.OWNER);
195
+ table[5] = SelectorRole(IERC3643Compliance.bindToken.selector, RolesLib.Role.OWNER);
196
+ table[6] = SelectorRole(IERC3643Compliance.unbindToken.selector, RolesLib.Role.OWNER);
197
+ table[7] = SelectorRole(ModularCompliance.resyncModuleTypes.selector, RolesLib.Role.OWNER);
198
+ table[8] = SelectorRole(ModularCompliance.setDefaultValidityWindow.selector, RolesLib.Role.COMPLIANCE_MANAGER);
199
+ table[9] = SelectorRole(ModularCompliance.setReconciliationWindow.selector, RolesLib.Role.COMPLIANCE_MANAGER);
200
+ table[10] = SelectorRole(ModularCompliance.setIssuancePaused.selector, RolesLib.Role.COMPLIANCE_MANAGER);
201
+ table[11] = SelectorRole(ITransferValidation.requestTransferValidation.selector, RolesLib.Role.AGENT);
202
+ table[12] = SelectorRole(ModularCompliance.discardExpiredValidations.selector, RolesLib.Role.VALIDATION_KEEPER);
203
+ table[13] = SelectorRole(ModularCompliance.resolveStuckValidation.selector, RolesLib.Role.VALIDATION_KEEPER);
204
+ }
205
+
206
+ function roleAdminTable() internal pure returns (RoleAdmin[] memory table) {
207
+ table = new RoleAdmin[](13);
208
+ table[0] = RoleAdmin(RolesLib.Role.AGENT, RolesLib.Role.AGENT_ADMIN);
209
+ table[1] = RoleAdmin(RolesLib.Role.AGENT_MINTER, RolesLib.Role.AGENT_ADMIN);
210
+ table[2] = RoleAdmin(RolesLib.Role.AGENT_BURNER, RolesLib.Role.AGENT_ADMIN);
211
+ table[3] = RoleAdmin(RolesLib.Role.AGENT_PARTIAL_FREEZER, RolesLib.Role.AGENT_ADMIN);
212
+ table[4] = RoleAdmin(RolesLib.Role.AGENT_ADDRESS_FREEZER, RolesLib.Role.AGENT_ADMIN);
213
+ table[5] = RoleAdmin(RolesLib.Role.AGENT_RECOVERY_ADDRESS, RolesLib.Role.AGENT_ADMIN);
214
+ table[6] = RoleAdmin(RolesLib.Role.AGENT_FORCED_TRANSFER, RolesLib.Role.AGENT_ADMIN);
215
+ table[7] = RoleAdmin(RolesLib.Role.AGENT_PAUSER, RolesLib.Role.AGENT_ADMIN);
216
+ table[8] = RoleAdmin(RolesLib.Role.IRS_BINDER, RolesLib.Role.AGENT_ADMIN);
217
+ table[9] = RoleAdmin(RolesLib.Role.VALIDATION_KEEPER, RolesLib.Role.AGENT_ADMIN);
218
+ table[10] = RoleAdmin(RolesLib.Role.TOKEN_MANAGER, RolesLib.Role.SUITE_ADMIN);
219
+ table[11] = RoleAdmin(RolesLib.Role.IDENTITY_MANAGER, RolesLib.Role.SUITE_ADMIN);
220
+ table[12] = RoleAdmin(RolesLib.Role.COMPLIANCE_MANAGER, RolesLib.Role.SUITE_ADMIN);
221
+ }
222
+
223
+ /// @notice Commissions the suite of `token` into the domain the manager assigned it to. The identity
224
+ /// storage joins that same domain: a fresh storage is assigned to it, a storage already in it
225
+ /// keeps its rows, and a storage of another domain is refused. The same rule holds for the
226
+ /// registry and the compliance: a fresh one joins the domain, one already set up in another
227
+ /// domain is refused.
228
+ /// @dev Why a storage belongs to one domain: it holds one record per wallet, whichever registry wrote
229
+ /// it. If a registry of domain B wrote into the storage of domain A, an agent of B could register
230
+ /// wallets under, and revoke the wallets of, A's holders through B's registry. So every registry
231
+ /// bound to a storage holds `IRS_WRITER` in the storage's domain. Tokens of one domain still share
232
+ /// a storage. The isolation is between the domains' roles, not from the manager's admin: every
233
+ /// domain of one manager shares its `ADMIN_ROLE`, which can grant `IRS_WRITER` of any domain by hand.
234
+ /// @dev Why a registry and a compliance belong to one domain: commissioning maps their functions to the
235
+ /// roles of the token's domain. Two tokens of one domain may share a registry (share classes of one
236
+ /// fund, say) and the rows just get written again with the same roles. A second token of another
237
+ /// domain would move the registry's rows to its own domain and lock the first domain's agents out
238
+ /// of their own registry, so it is refused.
239
+ /// @dev Two things say which domain a storage is in, and both are checked. The manager's domain record
240
+ /// (`domainOf`) is checked here, so a storage recorded in another domain is refused even before its
241
+ /// rows are mapped. The storage's own selector rows, which actually decide who may write it, are
242
+ /// checked in {_commission} together with the registry's and the compliance's rows, so a contract
243
+ /// mapped to another domain is refused whichever form of `commissionSuite` is called and whatever
244
+ /// the record says.
245
+ function commissionSuite(TREXAccessManager accessManager, address token) internal {
246
+ uint32 domainId = accessManager.domainOf(token);
247
+ require(domainId != 0, ErrorsLib.NotAssigned(token));
248
+ address registry = _registryOf(token);
249
+ address identityRegistryStorage = _storageOf(registry);
250
+
251
+ uint32 recordedDomainId = accessManager.domainOf(identityRegistryStorage);
252
+ if (recordedDomainId == 0) {
253
+ accessManager.assign(domainId, identityRegistryStorage);
254
+ } else {
255
+ require(
256
+ recordedDomainId == domainId, ErrorsLib.SuiteAlreadySetUp(identityRegistryStorage, recordedDomainId)
257
+ );
258
+ }
259
+
260
+ _commission(accessManager, token, registry, identityRegistryStorage, domainId);
261
+ }
262
+
263
+ /// @notice The pure form of {commissionSuite}, for any `IAccessManager`: the caller names the domain, and
264
+ /// the suite's four contracts, the storage included, are all set up in it.
265
+ /// @dev A plain `IAccessManager` keeps no record of domains, so this form reads the domain a contract is
266
+ /// in from the contract's own selector rows, see {_commission}: a storage, a registry or a
267
+ /// compliance whose rows belong to another domain is refused, a fresh one is mapped to `domainId`.
268
+ function commissionSuite(IAccessManager accessManager, address token, uint32 domainId) internal {
269
+ address registry = _registryOf(token);
270
+ _commission(accessManager, token, registry, _storageOf(registry), domainId);
271
+ }
272
+
273
+ /// @notice Maps the factory's five functions to the roles that own their subjects. `suiteDeployerRole` uses the
274
+ /// factory: it deploys suites. Each setter decides something for every later suite, so it goes to the
275
+ /// role that already owns that subject: `versionManagerRole` repoints the implementation authority,
276
+ /// which decides the code new suites run; `interopManagerRole` repoints the trusted gateway registry,
277
+ /// which decides the bridges new tokens trust; `platformOwnerRole` repoints the identity factory, which
278
+ /// creates new tokens' identities. No role exists only to configure the factory, so nobody can go
279
+ /// around the version manager or the interop manager by repointing the factory. The ids are data, not
280
+ /// constants: a {RolesLib.PlatformRole}, a name through {RolesLib.platform(bytes32)} or a raw id.
281
+ /// @dev Refuses the shapes that would let a suite deployer change what later suites get: the suite deployer
282
+ /// role as any of the three setter roles, `ADMIN_ROLE` as the suite deployer role (an admin can grant
283
+ /// itself any role), and the public role for any of the four. `ADMIN_ROLE` as a setter role is fine,
284
+ /// since admins can do everything anyway.
285
+ /// @dev This is a check on the ids, not a separation guarantee: the role hierarchy the manager keeps
286
+ /// (`getRoleAdmin`) can later make the suite deployer role the admin of a setter role, and nothing here
287
+ /// can prevent that.
288
+ function setupTREXFactoryRoles(
289
+ IAccessManager accessManager,
290
+ address trexFactory,
291
+ uint64 suiteDeployerRole,
292
+ uint64 versionManagerRole,
293
+ uint64 interopManagerRole,
294
+ uint64 platformOwnerRole
295
+ ) internal {
296
+ require(
297
+ suiteDeployerRole != versionManagerRole && suiteDeployerRole != interopManagerRole
298
+ && suiteDeployerRole != platformOwnerRole,
299
+ ErrorsLib.SuiteDeployerCannotConfigureFactory()
300
+ );
301
+ require(suiteDeployerRole != ADMIN_ROLE, ErrorsLib.SuiteDeployerCannotConfigureFactory());
302
+ _requireNotPublicRole(suiteDeployerRole);
303
+ _requireNotPublicRole(versionManagerRole);
304
+ _requireNotPublicRole(interopManagerRole);
305
+ _requireNotPublicRole(platformOwnerRole);
306
+
307
+ // Building suites.
308
+ bytes4[] memory deployFunctions = new bytes4[](2);
309
+ deployFunctions[0] = ITREXFactory.deployTREXSuite.selector;
310
+ deployFunctions[1] = ITREXFactory.deployTREXSuiteIsolated.selector;
311
+ accessManager.setTargetFunctionRole(trexFactory, deployFunctions, suiteDeployerRole);
312
+
313
+ // Which code new suites run.
314
+ bytes4[] memory versionFunctions = new bytes4[](1);
315
+ versionFunctions[0] = ITREXFactory.setImplementationAuthority.selector;
316
+ accessManager.setTargetFunctionRole(trexFactory, versionFunctions, versionManagerRole);
317
+
318
+ // Which bridges new tokens trust.
319
+ bytes4[] memory interopFunctions = new bytes4[](1);
320
+ interopFunctions[0] = ITREXFactory.setTrustedGatewayRegistry.selector;
321
+ accessManager.setTargetFunctionRole(trexFactory, interopFunctions, interopManagerRole);
322
+
323
+ // Who creates new tokens' identities.
324
+ bytes4[] memory identityFunctions = new bytes4[](1);
325
+ identityFunctions[0] = ITREXFactory.setIdFactory.selector;
326
+ accessManager.setTargetFunctionRole(trexFactory, identityFunctions, platformOwnerRole);
327
+ }
328
+
329
+ /// @dev Every platform function configures something all suites depend on; none may be open to anyone.
330
+ function _requireNotPublicRole(uint64 role) private pure {
331
+ require(role != PUBLIC_ROLE, ErrorsLib.PlatformRoleCannotBePublic());
332
+ }
333
+
334
+ function setupTrustedGatewayRegistryRoles(IAccessManager accessManager, address trustedGatewayRegistry) internal {
335
+ bytes4[] memory functions = new bytes4[](1);
336
+ functions[0] = TrustedGatewayRegistry.setTrustedGateway.selector;
337
+ accessManager.setTargetFunctionRole(
338
+ trustedGatewayRegistry, functions, RolesLib.platform(RolesLib.PlatformRole.INTEROP_MANAGER)
339
+ );
340
+ }
341
+
342
+ /// @notice Wires the two prerequisites the {TREXFactory} auto-mint path needs, so a deployer does
343
+ /// not have to rediscover them. Without both, `deployTREXSuite` reverts with
344
+ /// `NotAuthorizedForIdentityType` whenever `TokenDetails.ONCHAINID` is left at zero.
345
+ /// @dev Call order does not matter, but both must land before the first auto-mint deploy.
346
+ /// 1. Register the `ASSET` type on the IdentityFactory, gated behind the platform ASSET_DEPLOYER
347
+ /// role and with self-deploy off: only a registered factory mints token OIDs, and a token
348
+ /// must not be able to sign one for itself.
349
+ /// 2. Grant that role to the TREX factory.
350
+ /// @dev `accessManager` MUST be the IdentityFactory's own authority, which is not necessarily the
351
+ /// suite AccessManager: `createIdentityFor` resolves the role against `authority()` on the
352
+ /// IdentityFactory. Granting the role on the wrong manager leaves the auto-mint path reverting.
353
+ /// @dev The caller must be able to reach both calls: `setIdentityTypePolicy` is `restricted` on the
354
+ /// IdentityFactory, and `grantRole` requires the caller to be the role's admin.
355
+ /// @dev The ASSET module bundle is ONCHAINID configuration, registered on the IdentityFactory
356
+ /// via `setIdentityTypeModules` as part of its own deployment. An identity minted for a
357
+ /// type without modules cannot initialize, so that registration must also land before the
358
+ /// first auto-mint deploy.
359
+ /// @param accessManager The IdentityFactory's authority, where the role is resolved
360
+ /// @param identityFactory The ONCHAINID IdentityFactory that mints token OIDs
361
+ /// @param trexFactory The TREX factory that calls `createIdentityFor` on the auto-mint path
362
+ function setupIdentityFactoryPolicy(
363
+ IAccessManager accessManager,
364
+ IIdentityFactory identityFactory,
365
+ address trexFactory
366
+ ) internal {
367
+ uint64 assetDeployer = RolesLib.platform(RolesLib.PlatformRole.ASSET_DEPLOYER);
368
+ // ASSET is single-binding: a token OID binds to exactly one token and cannot be re-linked.
369
+ identityFactory.setIdentityTypePolicy(IdentityTypes.ASSET, assetDeployer, false, true);
370
+ accessManager.grantRole(assetDeployer, trexFactory, 0);
371
+ }
372
+
373
+ function setupTREXImplementationAuthorityRoles(IAccessManager accessManager, address trexImplementationAuthority)
374
+ internal
375
+ {
376
+ bytes4[] memory functions = new bytes4[](3);
377
+ functions[0] = TREXImplementationAuthority.publish.selector;
378
+ functions[1] = TREXImplementationAuthority.upgrade.selector;
379
+ functions[2] = TREXImplementationAuthority.publishAndUpgrade.selector;
380
+ accessManager.setTargetFunctionRole(
381
+ trexImplementationAuthority, functions, RolesLib.platform(RolesLib.PlatformRole.VERSION_MANAGER)
382
+ );
383
+ }
384
+
385
+ function setupRoleAdmins(IAccessManager accessManager, uint32 domainId) internal {
386
+ RoleAdmin[] memory table = roleAdminTable();
387
+ for (uint256 i = 0; i < table.length; i++) {
388
+ accessManager.setRoleAdmin(
389
+ RolesLib.forDomain(domainId, table[i].role), RolesLib.forDomain(domainId, table[i].admin)
390
+ );
391
+ }
392
+ }
393
+
394
+ /// @dev The three contracts a second token can share, the storage, the registry and the compliance, are
395
+ /// checked first, so a refused suite leaves nothing behind. Then the token is made an agent of its
396
+ /// registry (recovery, cross-chain instructions), and the registry a writer of the storage, since
397
+ /// only a registry writes into a storage, never a person. Both grants land in the suite's own domain.
398
+ function _commission(
399
+ IAccessManager accessManager,
400
+ address token,
401
+ address registry,
402
+ address identityRegistryStorage,
403
+ uint32 domainId
404
+ ) private {
405
+ address compliance = _complianceOf(token);
406
+ _requireFreshOrInDomain(
407
+ accessManager,
408
+ identityRegistryStorage,
409
+ IERC3643IdentityRegistryStorage.addIdentityToStorage.selector,
410
+ domainId
411
+ );
412
+ _requireFreshOrInDomain(accessManager, registry, IERC3643IdentityRegistry.registerIdentity.selector, domainId);
413
+ _requireFreshOrInDomain(accessManager, compliance, ModularCompliance.addModule.selector, domainId);
414
+
415
+ accessManager.grantRole(RolesLib.forDomain(domainId, RolesLib.Role.AGENT), token, 0);
416
+ accessManager.grantRole(RolesLib.forDomain(domainId, RolesLib.Role.IRS_WRITER), registry, 0);
417
+
418
+ setupTokenRoles(accessManager, token, domainId);
419
+ setupTREXRegistryRoles(accessManager, registry, domainId);
420
+ setupModularComplianceRoles(accessManager, compliance, domainId);
421
+ setupRoleAdmins(accessManager, domainId);
422
+ if (!IIdentityRegistryStorage(identityRegistryStorage).isIdentityRegistryBound(registry)) {
423
+ IERC3643IdentityRegistryStorage(identityRegistryStorage).bindIdentityRegistry(registry);
424
+ }
425
+ setupIdentityRegistryStorageRoles(accessManager, identityRegistryStorage, domainId);
426
+ }
427
+
428
+ /// @dev Refuses a suite contract whose rows belong to another domain. One row of `target` is read, the
429
+ /// row of `selector`, chosen as the function that decides who controls the contract: who may write a
430
+ /// storage (`addIdentityToStorage`), who may admit investors through a registry (`registerIdentity`),
431
+ /// who may change the rules of a compliance (`addModule`). Three cases:
432
+ /// 1. The row is `ADMIN_ROLE`: no row was ever set, the contract is fresh and is let through. It will
433
+ /// be mapped to `domainId` by the caller.
434
+ /// 2. The row is a role of `domainId`: the contract is already in this domain, let through. Its rows
435
+ /// are written again with the same roles.
436
+ /// 3. The row is a role of another domain: refused with `SuiteAlreadySetUp(target, thatDomain)`.
437
+ /// The domain a role belongs to is the upper half of its id, see {RolesLib.forDomain}.
438
+ function _requireFreshOrInDomain(IAccessManager accessManager, address target, bytes4 selector, uint32 domainId)
439
+ private
440
+ view
441
+ {
442
+ uint64 role = accessManager.getTargetFunctionRole(target, selector);
443
+ if (role == ADMIN_ROLE) return;
444
+
445
+ (uint32 targetDomainId,,) = RolesLib.decode(role);
446
+ require(targetDomainId == domainId, ErrorsLib.SuiteAlreadySetUp(target, targetDomainId));
447
+ }
448
+
449
+ /// @dev Walks `table` as runs of consecutive same-role entries and maps each run with one
450
+ /// `setTargetFunctionRole`. The tables above keep every role's selectors consecutive; a table that
451
+ /// interleaves roles still maps every selector correctly, since the manager writes per selector, it
452
+ /// only spends one extra call per extra run.
453
+ function _apply(IAccessManager accessManager, address target, SelectorRole[] memory table, uint32 domainId)
454
+ private
455
+ {
456
+ uint256 start;
457
+ while (start < table.length) {
458
+ RolesLib.Role role = table[start].role;
459
+ uint256 end = start;
460
+ while (end < table.length && table[end].role == role) {
461
+ end++;
462
+ }
463
+ bytes4[] memory selectors = new bytes4[](end - start);
464
+ for (uint256 i = start; i < end; i++) {
465
+ selectors[i - start] = table[i].selector;
466
+ }
467
+ accessManager.setTargetFunctionRole(target, selectors, RolesLib.forDomain(domainId, role));
468
+ start = end;
469
+ }
470
+ }
471
+
472
+ function _registryOf(address token) private view returns (address) {
473
+ return address(IERC3643(token).identityRegistry());
474
+ }
475
+
476
+ function _storageOf(address registry) private view returns (address) {
477
+ return address(IERC3643IdentityRegistry(registry).identityStorage());
478
+ }
479
+
480
+ function _complianceOf(address token) private view returns (address) {
481
+ return address(IERC3643(token).compliance());
482
+ }
483
+
484
+ }