@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,601 @@
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) 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/>.
63
+
64
+ pragma solidity 0.8.30;
65
+
66
+ import { IIdentity } from "@onchain-id/solidity/contracts/interface/IIdentity.sol";
67
+ import { ERC20Upgradeable } from "@openzeppelin/contracts-upgradeable/token/ERC20/ERC20Upgradeable.sol";
68
+ import { PausableUpgradeable } from "@openzeppelin/contracts-upgradeable/utils/PausableUpgradeable.sol";
69
+ import { IERC20Errors } from "@openzeppelin/contracts/interfaces/draft-IERC6093.sol";
70
+ import { IERC20Metadata } from "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol";
71
+ import { ReentrancyGuardTransient } from "@openzeppelin/contracts/utils/ReentrancyGuardTransient.sol";
72
+
73
+ import { ERC3643ErrorsLib } from "../ERC3643ErrorsLib.sol";
74
+ import { IERC3643 } from "../IERC3643.sol";
75
+ import { IERC3643Compliance } from "../IERC3643Compliance.sol";
76
+ import { IERC3643IdentityRegistry } from "../IERC3643IdentityRegistry.sol";
77
+
78
+ /// @title ERC3643Token
79
+ /// @dev The ERC-3643 token surface and nothing else, over its own ERC-7201 namespace. Extend through
80
+ /// the internal hooks; hook names match openzeppelin-contracts#5838 so a swap renames nothing.
81
+ /// Storage shape and the deliberate divergences from that PR: see docs/erc3643-oz-swap.md.
82
+ abstract contract ERC3643Token is ERC20Upgradeable, PausableUpgradeable, ReentrancyGuardTransient, IERC3643 {
83
+
84
+ /// @custom:storage-location erc7201:erc3643.storage.ERC3643Token
85
+ struct ERC3643TokenStorage {
86
+ mapping(address account => bool) frozen;
87
+ mapping(address account => uint256) frozenTokens;
88
+ IERC3643IdentityRegistry identityRegistry;
89
+ IERC3643Compliance compliance;
90
+ address onchainId;
91
+ }
92
+
93
+ // keccak256(abi.encode(uint256(keccak256("erc3643.storage.ERC3643Token")) - 1)) & ~bytes32(uint256(0xff));
94
+ bytes32 private constant ERC3643_TOKEN_STORAGE_LOCATION =
95
+ 0x1c6ea0581535d63a38daa138246885c0e308b5f6335af4548c056841c5c18f00;
96
+
97
+ /* ----- Token information ----- */
98
+
99
+ /// @inheritdoc IERC3643
100
+ /// @dev Changing the name rotates any EIP-712 domain separator derived from it, which invalidates
101
+ /// outstanding ERC-2612 permit signatures. Derived contracts that bind permit to the name should
102
+ /// say so on their own override.
103
+ function setName(string calldata _name) external virtual {
104
+ _checkTokenAdmin(this.setName.selector);
105
+ _setName(_name);
106
+ _emitUpdatedTokenInformation();
107
+ }
108
+
109
+ /// @inheritdoc IERC3643
110
+ function setSymbol(string calldata _symbol) external virtual {
111
+ _checkTokenAdmin(this.setSymbol.selector);
112
+ _setSymbol(_symbol);
113
+ _emitUpdatedTokenInformation();
114
+ }
115
+
116
+ /// @inheritdoc IERC3643
117
+ function version() external view virtual returns (string memory) {
118
+ return _version();
119
+ }
120
+
121
+ /// @inheritdoc IERC3643
122
+ function setOnchainID(address _onchainID) external virtual {
123
+ _checkTokenAdmin(this.setOnchainID.selector);
124
+ _setOnchainID(_onchainID);
125
+ }
126
+
127
+ /// @inheritdoc IERC3643
128
+ function setIdentityRegistry(address _identityRegistry) external virtual {
129
+ _checkTokenAdmin(this.setIdentityRegistry.selector);
130
+ _setIdentityRegistry(_identityRegistry);
131
+ }
132
+
133
+ /// @inheritdoc IERC3643
134
+ function setCompliance(address _compliance) external virtual {
135
+ _checkTokenAdmin(this.setCompliance.selector);
136
+ _setCompliance(_compliance);
137
+ }
138
+
139
+ /// @inheritdoc IERC3643
140
+ function onchainID() external view virtual returns (address) {
141
+ return _erc3643TokenStorage().onchainId;
142
+ }
143
+
144
+ /// @inheritdoc IERC3643
145
+ function identityRegistry() external view virtual returns (IERC3643IdentityRegistry) {
146
+ return _getIdentityRegistry();
147
+ }
148
+
149
+ /// @inheritdoc IERC3643
150
+ function compliance() external view virtual returns (IERC3643Compliance) {
151
+ return _getCompliance();
152
+ }
153
+
154
+ /* ----- Pause ----- */
155
+
156
+ /// @inheritdoc IERC3643
157
+ function pause() external virtual {
158
+ _checkTokenAdmin(this.pause.selector);
159
+ _pause();
160
+ }
161
+
162
+ /// @inheritdoc IERC3643
163
+ function unpause() external virtual {
164
+ _checkTokenAdmin(this.unpause.selector);
165
+ _unpause();
166
+ }
167
+
168
+ /* ----- Mint and burn ----- */
169
+
170
+ /// @inheritdoc IERC3643
171
+ function mint(address _to, uint256 _amount) external virtual {
172
+ _checkTokenAdmin(this.mint.selector);
173
+ _mint(_to, _amount);
174
+ }
175
+
176
+ /// @inheritdoc IERC3643
177
+ function burn(address _userAddress, uint256 _amount) external virtual {
178
+ _checkTokenAdmin(this.burn.selector);
179
+ _burn(_userAddress, _amount);
180
+ }
181
+
182
+ /// @inheritdoc IERC3643
183
+ function batchMint(address[] calldata _toList, uint256[] calldata _amounts) external virtual {
184
+ _checkTokenAdmin(this.mint.selector);
185
+ require(_toList.length == _amounts.length, ERC3643ErrorsLib.ArrayLengthMismatch());
186
+ for (uint256 i = 0; i < _toList.length; i++) {
187
+ _mint(_toList[i], _amounts[i]);
188
+ }
189
+ }
190
+
191
+ /// @inheritdoc IERC3643
192
+ function batchBurn(address[] calldata _userAddresses, uint256[] calldata _amounts) external virtual {
193
+ _checkTokenAdmin(this.burn.selector);
194
+ require(_userAddresses.length == _amounts.length, ERC3643ErrorsLib.ArrayLengthMismatch());
195
+ for (uint256 i = 0; i < _userAddresses.length; i++) {
196
+ _burn(_userAddresses[i], _amounts[i]);
197
+ }
198
+ }
199
+
200
+ /* ----- Freezing ----- */
201
+
202
+ /// @inheritdoc IERC3643
203
+ function setAddressFrozen(address _userAddress, bool _freeze) external virtual {
204
+ _checkTokenAdmin(this.setAddressFrozen.selector);
205
+ _setAddressFrozen(_userAddress, _freeze);
206
+ }
207
+
208
+ /// @inheritdoc IERC3643
209
+ function freezePartialTokens(address _userAddress, uint256 _amount) external virtual {
210
+ _checkTokenAdmin(this.freezePartialTokens.selector);
211
+ _freezePartialTokens(_userAddress, _amount);
212
+ }
213
+
214
+ /// @inheritdoc IERC3643
215
+ function unfreezePartialTokens(address _userAddress, uint256 _amount) external virtual {
216
+ _checkTokenAdmin(this.unfreezePartialTokens.selector);
217
+ _unfreezePartialTokens(_userAddress, _amount);
218
+ }
219
+
220
+ /// @inheritdoc IERC3643
221
+ function batchSetAddressFrozen(address[] calldata _userAddresses, bool[] calldata _freeze) external virtual {
222
+ _checkTokenAdmin(this.setAddressFrozen.selector);
223
+ require(_userAddresses.length == _freeze.length, ERC3643ErrorsLib.ArrayLengthMismatch());
224
+ for (uint256 i = 0; i < _userAddresses.length; i++) {
225
+ _setAddressFrozen(_userAddresses[i], _freeze[i]);
226
+ }
227
+ }
228
+
229
+ /// @inheritdoc IERC3643
230
+ function batchFreezePartialTokens(address[] calldata _userAddresses, uint256[] calldata _amounts) external virtual {
231
+ _checkTokenAdmin(this.freezePartialTokens.selector);
232
+ require(_userAddresses.length == _amounts.length, ERC3643ErrorsLib.ArrayLengthMismatch());
233
+ for (uint256 i = 0; i < _userAddresses.length; i++) {
234
+ _freezePartialTokens(_userAddresses[i], _amounts[i]);
235
+ }
236
+ }
237
+
238
+ /// @inheritdoc IERC3643
239
+ function batchUnfreezePartialTokens(address[] calldata _userAddresses, uint256[] calldata _amounts)
240
+ external
241
+ virtual
242
+ {
243
+ _checkTokenAdmin(this.unfreezePartialTokens.selector);
244
+ require(_userAddresses.length == _amounts.length, ERC3643ErrorsLib.ArrayLengthMismatch());
245
+ for (uint256 i = 0; i < _userAddresses.length; i++) {
246
+ _unfreezePartialTokens(_userAddresses[i], _amounts[i]);
247
+ }
248
+ }
249
+
250
+ /// @inheritdoc IERC3643
251
+ function isFrozen(address _userAddress) external view virtual returns (bool) {
252
+ return _isFrozen(_userAddress);
253
+ }
254
+
255
+ /// @inheritdoc IERC3643
256
+ function getFrozenTokens(address _userAddress) external view virtual returns (uint256) {
257
+ return _getFrozenTokens(_userAddress);
258
+ }
259
+
260
+ /* ----- Transfers ----- */
261
+
262
+ /// @inheritdoc IERC3643
263
+ function forcedTransfer(address _from, address _to, uint256 _amount) external virtual returns (bool) {
264
+ _checkTokenAdmin(this.forcedTransfer.selector);
265
+ return _forcedTransfer(_from, _to, _amount);
266
+ }
267
+
268
+ /// @inheritdoc IERC3643
269
+ function batchForcedTransfer(address[] calldata _fromList, address[] calldata _toList, uint256[] calldata _amounts)
270
+ external
271
+ virtual
272
+ {
273
+ _checkTokenAdmin(this.forcedTransfer.selector);
274
+ require(
275
+ _fromList.length == _toList.length && _fromList.length == _amounts.length,
276
+ ERC3643ErrorsLib.ArrayLengthMismatch()
277
+ );
278
+ for (uint256 i = 0; i < _fromList.length; i++) {
279
+ _forcedTransfer(_fromList[i], _toList[i], _amounts[i]);
280
+ }
281
+ }
282
+
283
+ /// @inheritdoc IERC3643
284
+ function batchTransfer(address[] calldata _toList, uint256[] calldata _amounts) external virtual {
285
+ require(_toList.length == _amounts.length, ERC3643ErrorsLib.ArrayLengthMismatch());
286
+ for (uint256 i = 0; i < _toList.length; i++) {
287
+ transfer(_toList[i], _amounts[i]);
288
+ }
289
+ }
290
+
291
+ /// @inheritdoc IERC3643
292
+ function recoveryAddress(address _lostWallet, address _newWallet, address _investorOnchainID)
293
+ external
294
+ virtual
295
+ returns (bool)
296
+ {
297
+ _checkTokenAdmin(this.recoveryAddress.selector);
298
+ return _recoveryAddress(_lostWallet, _newWallet, _investorOnchainID);
299
+ }
300
+
301
+ /* ----- ERC-20 surface ----- */
302
+
303
+ /// @inheritdoc IERC3643
304
+ function paused() public view virtual override(PausableUpgradeable, IERC3643) returns (bool) {
305
+ return super.paused();
306
+ }
307
+
308
+ /// @inheritdoc IERC20Metadata
309
+ function decimals() public view virtual override(ERC20Upgradeable, IERC20Metadata) returns (uint8) {
310
+ return super.decimals();
311
+ }
312
+
313
+ /* ----- Extension hooks ----- */
314
+
315
+ /// @dev Reverts unless `_msgSender()` may call `selector`. Batches pass their single-item
316
+ /// counterpart, so `batchMint` needs whatever `mint` needs. Left abstract: the standard defines no
317
+ /// access model. Named for openzeppelin-contracts#5838, unlike the `_authorize*` hooks elsewhere.
318
+ function _checkTokenAdmin(bytes4 selector) internal virtual;
319
+
320
+ /// @dev Replaces the ERC-20 name. Name and symbol belong to the ERC-20 base (issue #54), whose
321
+ /// storage accessor is private and which ships no setter, so the slot is reached directly here.
322
+ /// These two hook names match openzeppelin-contracts#5838, so the swap renames nothing.
323
+ function _setName(string memory name_) internal virtual {
324
+ _erc20Storage().name = name_;
325
+ }
326
+
327
+ /// @dev Replaces the ERC-20 symbol. See the note on `_setName`.
328
+ function _setSymbol(string memory symbol_) internal virtual {
329
+ _erc20Storage().symbol = symbol_;
330
+ }
331
+
332
+ /// @dev Writes the three pointers without validation, for initialization only. The overridable
333
+ /// setters would run T-REX's bind/unbind handshake, which does not apply here: there is no previous
334
+ /// compliance to unbind, and the deployer binds separately.
335
+ function _initERC3643(address identityRegistry_, address compliance_, address onchainId_) internal virtual {
336
+ ERC3643TokenStorage storage s = _erc3643TokenStorage();
337
+ s.identityRegistry = IERC3643IdentityRegistry(identityRegistry_);
338
+ s.compliance = IERC3643Compliance(compliance_);
339
+ s.onchainId = onchainId_;
340
+ _emitUpdatedTokenInformation();
341
+ }
342
+
343
+ /// @dev Sets the token's ONCHAINID. The zero address means no ONCHAINID is bound.
344
+ function _setOnchainID(address onchainId_) internal virtual {
345
+ _erc3643TokenStorage().onchainId = onchainId_;
346
+ _emitUpdatedTokenInformation();
347
+ }
348
+
349
+ /// @dev Points the token at a new identity registry. A wrong registry halts the token, since
350
+ /// `isVerified` runs on every transfer; derived contracts add their own validation here.
351
+ function _setIdentityRegistry(address identityRegistry_) internal virtual {
352
+ _erc3643TokenStorage().identityRegistry = IERC3643IdentityRegistry(identityRegistry_);
353
+ emit IdentityRegistryAdded(identityRegistry_);
354
+ }
355
+
356
+ /// @dev Points the token at a new compliance contract.
357
+ function _setCompliance(address compliance_) internal virtual {
358
+ _writeCompliance(compliance_);
359
+ emit ComplianceAdded(compliance_);
360
+ }
361
+
362
+ /// @dev Stores the compliance pointer without emitting, so a derived contract doing a bind handshake
363
+ /// can emit `ComplianceAdded` after it, once the binding has actually succeeded.
364
+ function _writeCompliance(address compliance_) internal {
365
+ _erc3643TokenStorage().compliance = IERC3643Compliance(compliance_);
366
+ }
367
+
368
+ /// @dev Freezes part of a wallet's balance. The frozen amount may never exceed the balance.
369
+ function _freezePartialTokens(address userAddress, uint256 amount) internal virtual {
370
+ ERC3643TokenStorage storage s = _erc3643TokenStorage();
371
+ uint256 balance = balanceOf(userAddress);
372
+ // Subtracting cannot underflow, since the frozen amount never exceeds the balance; adding could overflow and
373
+ // revert with a panic instead of the error below.
374
+ require(
375
+ amount <= balance - s.frozenTokens[userAddress],
376
+ IERC20Errors.ERC20InsufficientBalance(userAddress, balance, amount)
377
+ );
378
+ s.frozenTokens[userAddress] += amount;
379
+ emit TokensFrozen(userAddress, amount);
380
+ }
381
+
382
+ /// @dev Releases part of a wallet's frozen balance.
383
+ function _unfreezePartialTokens(address userAddress, uint256 amount) internal virtual {
384
+ ERC3643TokenStorage storage s = _erc3643TokenStorage();
385
+ uint256 frozenAmount = s.frozenTokens[userAddress];
386
+ require(frozenAmount >= amount, ERC3643ErrorsLib.AmountAboveFrozenTokens(amount, frozenAmount));
387
+ s.frozenTokens[userAddress] = frozenAmount - amount;
388
+ emit TokensUnfrozen(userAddress, amount);
389
+ }
390
+
391
+ /// @dev Sets a wallet's frozen flag. `owner_` is the actor recorded in the event.
392
+ function _setAddressFrozen(address userAddress, bool freeze, address owner_) internal virtual {
393
+ _erc3643TokenStorage().frozen[userAddress] = freeze;
394
+ emit AddressFrozen(userAddress, freeze, owner_);
395
+ }
396
+
397
+ /// @dev Sets a wallet's frozen flag, recording `_msgSender()` as the actor.
398
+ function _setAddressFrozen(address userAddress, bool freeze) internal virtual {
399
+ _setAddressFrozen(userAddress, freeze, _msgSender());
400
+ }
401
+
402
+ /// @dev Moves tokens irrespective of freezes, unfreezing just enough to cover the amount, then tells
403
+ /// compliance the move happened. Recipient identity is still verified. Reverts while the token is
404
+ /// paused: a forced transfer is privileged, not exempt from an incident halt.
405
+ /// @dev Guarded like {_update}: this path reaches compliance through `_forceUpdate`, which bypasses
406
+ /// {_update}, so it needs its own guard to cover the `transferred` hook. An override that does not
407
+ /// call `super` must carry `nonReentrant` itself.
408
+ function _forcedTransfer(address from, address to, uint256 amount)
409
+ internal
410
+ virtual
411
+ whenNotPaused
412
+ nonReentrant
413
+ returns (bool)
414
+ {
415
+ require(_getIdentityRegistry().isVerified(to), ERC3643ErrorsLib.UnverifiedIdentity());
416
+ _forceUpdate(from, to, amount);
417
+ _getCompliance().transferred(from, to, amount);
418
+ return true;
419
+ }
420
+
421
+ /// @dev Moves a lost wallet's balance, freezes and identity onto a new wallet. Reverts while the token
422
+ /// is paused: recovery moves a balance like any transfer and waits for the halt to be lifted.
423
+ /// @dev Guarded like {_update}: this path reaches compliance through `_forceUpdate`, which bypasses
424
+ /// {_update}, so it needs its own guard to cover the `transferred` hook. An override that does not
425
+ /// call `super` must carry `nonReentrant` itself.
426
+ function _recoveryAddress(address lostWallet, address newWallet, address investorOnchainID)
427
+ internal
428
+ virtual
429
+ whenNotPaused
430
+ nonReentrant
431
+ returns (bool)
432
+ {
433
+ ERC3643TokenStorage storage s = _erc3643TokenStorage();
434
+ uint256 investorTokens = balanceOf(lostWallet);
435
+ uint256 frozenTokens = s.frozenTokens[lostWallet];
436
+
437
+ // The new wallet is registered before the move and the lost wallet is deleted after the compliance
438
+ // hook, so that during `transferred` both wallets still resolve to the identities that hold and
439
+ // receive the tokens. A module keyed by identity can then debit and credit through the registry.
440
+ bool migrateIdentity = _registerRecoveredWallet(lostWallet, newWallet, investorOnchainID);
441
+
442
+ _forceUpdate(lostWallet, newWallet, investorTokens);
443
+ _migrateFrozenAmount(newWallet, frozenTokens);
444
+ _migrateAddressFrozen(lostWallet, newWallet);
445
+
446
+ _getCompliance().transferred(lostWallet, newWallet, investorTokens);
447
+
448
+ if (migrateIdentity) _getIdentityRegistry().deleteIdentity(lostWallet);
449
+
450
+ emit RecoverySuccess(lostWallet, newWallet, investorOnchainID);
451
+ return true;
452
+ }
453
+
454
+ /// @dev Carries the lost wallet's frozen-token amount onto the new wallet. The amount is captured by
455
+ /// the caller before `_forceUpdate` runs, since `_forceUpdate` auto-unfreezes and zeroes the lost wallet.
456
+ function _migrateFrozenAmount(address newWallet, uint256 frozenAmount) internal virtual {
457
+ if (frozenAmount > 0) {
458
+ _erc3643TokenStorage().frozenTokens[newWallet] += frozenAmount;
459
+ emit TokensFrozen(newWallet, frozenAmount);
460
+ }
461
+ }
462
+
463
+ /// @dev Carries the address-frozen flag from the lost wallet onto the new wallet (only when the new
464
+ /// wallet is not already frozen).
465
+ function _migrateAddressFrozen(address lostWallet, address newWallet) internal virtual {
466
+ ERC3643TokenStorage storage s = _erc3643TokenStorage();
467
+ if (s.frozen[lostWallet]) {
468
+ _setAddressFrozen(lostWallet, false, address(this));
469
+ if (!s.frozen[newWallet]) {
470
+ _setAddressFrozen(newWallet, true, address(this));
471
+ }
472
+ }
473
+ }
474
+
475
+ /// @dev First half of the identity migration: registers the new wallet under `investorOnchainID`
476
+ /// when the lost wallet is known and the new one is not. Returns whether the lost wallet is known,
477
+ /// i.e. whether the caller must delete it once compliance has been notified.
478
+ function _registerRecoveredWallet(address lostWallet, address newWallet, address investorOnchainID)
479
+ internal
480
+ virtual
481
+ returns (bool lostWalletRegistered)
482
+ {
483
+ IERC3643IdentityRegistry registry = _getIdentityRegistry();
484
+ lostWalletRegistered = registry.contains(lostWallet);
485
+ if (lostWalletRegistered && !registry.contains(newWallet)) {
486
+ registry.registerIdentity(newWallet, IIdentity(investorOnchainID), registry.investorCountry(lostWallet));
487
+ }
488
+ }
489
+
490
+ /// @dev The ERC-20 state transition plus the ERC-3643 rules. Transfers are blocked while paused,
491
+ /// from or to a frozen wallet, and beyond the free balance. Mints and burns are allowed while
492
+ /// paused, and a burn auto-unfreezes just enough to cover itself. Identity and compliance are
493
+ /// checked for mints and transfers but not burns.
494
+ /// @dev `nonReentrant` spans the whole operation: the compliance check, the balance move and the
495
+ /// post-move compliance hook. A module hook is an unguarded call into arbitrary code, so without
496
+ /// the guard an early module could reenter and have a later stateful module evaluate both the outer
497
+ /// and the nested operation against accounting that records neither yet. Batch entry points call
498
+ /// this in a loop rather than nested, and the guard clears on return, so they are unaffected.
499
+ function _update(address from, address to, uint256 value) internal virtual override nonReentrant {
500
+ ERC3643TokenStorage storage s = _erc3643TokenStorage();
501
+ bool isMint = from == address(0);
502
+ bool isBurn = to == address(0);
503
+
504
+ if (!isMint && !isBurn) {
505
+ _requireNotPaused();
506
+ require(!s.frozen[from], ERC3643ErrorsLib.FrozenWallet(from));
507
+ require(!s.frozen[to], ERC3643ErrorsLib.FrozenWallet(to));
508
+ uint256 freeBalance = balanceOf(from) - s.frozenTokens[from];
509
+ require(value <= freeBalance, IERC20Errors.ERC20InsufficientBalance(from, freeBalance, value));
510
+ } else if (isBurn) {
511
+ _autoUnfreezeFor(from, value);
512
+ }
513
+
514
+ if (!isBurn) {
515
+ require(_getIdentityRegistry().isVerified(to), ERC3643ErrorsLib.UnverifiedIdentity());
516
+ require(_getCompliance().canTransfer(from, to, value), ERC3643ErrorsLib.ComplianceNotFollowed());
517
+ }
518
+
519
+ super._update(from, to, value);
520
+
521
+ if (isMint) _getCompliance().created(to, value);
522
+ else if (isBurn) _getCompliance().destroyed(from, value);
523
+ else _getCompliance().transferred(from, to, value);
524
+ }
525
+
526
+ /// @dev Moves tokens bypassing {_update}: no pause, freeze, identity or compliance check, and no
527
+ /// compliance notification. Pause policy: the pause halts every balance movement between wallets,
528
+ /// and every caller of this function enforces it before calling; `_forcedTransfer` and
529
+ /// `_recoveryAddress` both use `whenNotPaused`. Mints and burns stay allowed while paused, see
530
+ /// {_update}. Callers are also responsible for notifying compliance themselves, which is why
531
+ /// `_forcedTransfer` and `_recoveryAddress` each call `transferred` explicitly.
532
+ function _forceUpdate(address from, address to, uint256 value) internal virtual {
533
+ _autoUnfreezeFor(from, value);
534
+ super._update(from, to, value);
535
+ }
536
+
537
+ /// @dev Releases just enough of `from`'s frozen balance to let `value` move.
538
+ function _autoUnfreezeFor(address from, uint256 value) internal virtual {
539
+ ERC3643TokenStorage storage s = _erc3643TokenStorage();
540
+ uint256 balance = balanceOf(from);
541
+ require(value <= balance, IERC20Errors.ERC20InsufficientBalance(from, balance, value));
542
+ uint256 freeBalance = balance - s.frozenTokens[from];
543
+ if (value > freeBalance) {
544
+ uint256 toUnfreeze = value - freeBalance;
545
+ s.frozenTokens[from] -= toUnfreeze;
546
+ emit TokensUnfrozen(from, toUnfreeze);
547
+ }
548
+ }
549
+
550
+ /// @dev Emits the token information event. Derived contracts supply the version string.
551
+ function _emitUpdatedTokenInformation() internal virtual {
552
+ emit UpdatedTokenInformation(name(), symbol(), decimals(), _version(), _erc3643TokenStorage().onchainId);
553
+ }
554
+
555
+ /// @dev The implementation version reported in `UpdatedTokenInformation`.
556
+ function _version() internal view virtual returns (string memory);
557
+
558
+ function _isFrozen(address userAddress) internal view virtual returns (bool) {
559
+ return _erc3643TokenStorage().frozen[userAddress];
560
+ }
561
+
562
+ function _getFrozenTokens(address userAddress) internal view virtual returns (uint256) {
563
+ return _erc3643TokenStorage().frozenTokens[userAddress];
564
+ }
565
+
566
+ function _getIdentityRegistry() internal view virtual returns (IERC3643IdentityRegistry) {
567
+ return _erc3643TokenStorage().identityRegistry;
568
+ }
569
+
570
+ function _getCompliance() internal view virtual returns (IERC3643Compliance) {
571
+ return _erc3643TokenStorage().compliance;
572
+ }
573
+
574
+ /// @dev Mirror of `ERC20Upgradeable.ERC20Storage`, needed only to reach the name and symbol slots.
575
+ /// The field order and the location constant must match `ERC20Upgradeable` exactly.
576
+ struct ERC20NameSymbolStorage {
577
+ mapping(address account => uint256) balances;
578
+ mapping(address account => mapping(address spender => uint256)) allowances;
579
+ uint256 totalSupply;
580
+ string name;
581
+ string symbol;
582
+ }
583
+
584
+ // keccak256(abi.encode(uint256(keccak256("openzeppelin.storage.ERC20")) - 1)) & ~bytes32(uint256(0xff));
585
+ // Declared by ERC20Upgradeable, which keeps its own accessor private.
586
+ bytes32 private constant ERC20_STORAGE_LOCATION =
587
+ 0x52c63247e1f47db19d5ce0460030c497f067ca4cebf71ba98eeadabe20bace00;
588
+
589
+ function _erc20Storage() private pure returns (ERC20NameSymbolStorage storage s) {
590
+ assembly ("memory-safe") {
591
+ s.slot := ERC20_STORAGE_LOCATION
592
+ }
593
+ }
594
+
595
+ function _erc3643TokenStorage() internal pure returns (ERC3643TokenStorage storage s) {
596
+ assembly ("memory-safe") {
597
+ s.slot := ERC3643_TOKEN_STORAGE_LOCATION
598
+ }
599
+ }
600
+
601
+ }