@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,425 @@
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 { IERC7786GatewaySource } from "@openzeppelin/contracts/interfaces/draft-IERC7786.sol";
63
+ import { InteroperableAddress } from "@openzeppelin/contracts/utils/draft-InteroperableAddress.sol";
64
+
65
+ import { ErrorsLib } from "../libraries/ErrorsLib.sol";
66
+ import { EventsLib } from "../libraries/EventsLib.sol";
67
+ import { MessageTypesLib } from "../libraries/MessageTypesLib.sol";
68
+ import { TokenLedgerLib } from "../token/TokenLedgerLib.sol";
69
+ import { ISettlementHandler } from "./ISettlementHandler.sol";
70
+ import { ITrustedGatewayRegistry } from "./ITrustedGatewayRegistry.sol";
71
+
72
+ /**
73
+ * @title TREXMessagingLib
74
+ * @dev The body of {TREXMessaging}, deployed once and linked.
75
+ *
76
+ * The messaging layer is envelope parsing, payload decoding and gateway calls: a lot of bytecode that
77
+ * every token would otherwise carry, and that pushed the token past EIP-170. It lives here instead, and
78
+ * the token reaches it by DELEGATECALL, which is what keeps everything the token's:
79
+ *
80
+ * - the storage is the token's own ERC-7201 namespace, at the slot it always had,
81
+ * - `address(this)` is the token, so the default peer is still the token's own address,
82
+ * - the gateway sees the token as `msg.sender`, so the wire still has one author,
83
+ * - events are emitted by the token.
84
+ *
85
+ * Nothing here is an entry point. Who may configure a route, who may dispatch and what an accepted
86
+ * message does are decided by the token, in {TREXMessaging} and its inheritor; this library only
87
+ * carries out what it is handed. Its state-changing functions cannot be called on the library itself.
88
+ */
89
+ library TREXMessagingLib {
90
+
91
+ /// @dev The ERC-7930 prefix behind a `chainKey`, kept so the token can address its own peer there.
92
+ struct ChainPrefix {
93
+ bytes2 chainType;
94
+ bytes chainReference;
95
+ }
96
+
97
+ /// @custom:storage-location erc7201:erc3643.storage.TREXMessaging
98
+ struct MessagingStorage {
99
+ /// The network's vetted gateway set this token resolves trust against.
100
+ ITrustedGatewayRegistry registry;
101
+
102
+ /// The gateway carrying this token's traffic, per chain. Zero closes the chain.
103
+ mapping(bytes32 chainKey => address gateway) routes;
104
+
105
+ /// This token's Lite on each chain, ERC-7930. Empty falls back to the token's own address.
106
+ mapping(bytes32 chainKey => bytes peer) peers;
107
+
108
+ /// Transport-level replay guard, for nonzero receive ids. The pinned receiver base keeps no record of its own.
109
+ mapping(address gateway => mapping(bytes32 receiveId => bool)) received;
110
+
111
+ /// The prefix each known chain key was derived from, recorded on first sight.
112
+ mapping(bytes32 chainKey => ChainPrefix) chains;
113
+
114
+ /// The gateway each validation leg went out through, snapshot at dispatch and never rewritten.
115
+ mapping(uint256 validationId => mapping(bytes32 chainKey => address gateway)) pinnedRoutes;
116
+
117
+ /// `keccak256` of the peer each validation leg was sent to, snapshot with its gateway.
118
+ mapping(uint256 validationId => mapping(bytes32 chainKey => bytes32 peerKey)) pinnedPeers;
119
+ }
120
+
121
+ // keccak256(abi.encode(uint256(keccak256("erc3643.storage.TREXMessaging")) - 1)) & ~bytes32(uint256(0xff));
122
+ bytes32 private constant MESSAGING_STORAGE_LOCATION =
123
+ 0x2b7785d97e35cf618b41c256efdda42212baf2d424180e7d549907f2f911e900;
124
+
125
+ /// @dev Bytes of an ERC-7930 v1 envelope that are not the chain reference or the account: the
126
+ /// version, the chain type, and the two length prefixes.
127
+ uint256 private constant ERC7930_V1_FIXED_LENGTH = 6;
128
+
129
+ /* ----- Views ----- */
130
+
131
+ /// @dev See {ITREXMessaging-chainOf}.
132
+ function chainOf(bytes32 chainKey) external view returns (bytes2 chainType, bytes memory chainReference) {
133
+ ChainPrefix storage chain = layout().chains[chainKey];
134
+ return (chain.chainType, chain.chainReference);
135
+ }
136
+
137
+ /// @dev See {ITREXMessaging-peerFor}.
138
+ function peerFor(bytes32 chainKey) public view returns (bytes memory) {
139
+ MessagingStorage storage s = layout();
140
+
141
+ bytes memory peer = s.peers[chainKey];
142
+ if (peer.length > 0) {
143
+ return peer;
144
+ }
145
+
146
+ ChainPrefix storage chain = s.chains[chainKey];
147
+ if (chain.chainType != MessageTypesLib.EVM_CHAIN_TYPE || chain.chainReference.length == 0) {
148
+ return "";
149
+ }
150
+
151
+ return InteroperableAddress.formatV1(chain.chainType, chain.chainReference, abi.encodePacked(address(this)));
152
+ }
153
+
154
+ /// @dev See {ITREXMessaging-isChainOpen}.
155
+ function isChainOpen(bytes32 chainKey) external view returns (bool) {
156
+ MessagingStorage storage s = layout();
157
+ address gateway = s.routes[chainKey];
158
+
159
+ return gateway != address(0) && s.registry.isTrusted(gateway) && peerFor(chainKey).length > 0;
160
+ }
161
+
162
+ /* ----- Configuration ----- */
163
+
164
+ /// @dev Called once, from the token's initializer. The registry is the network's and the token
165
+ /// exposes no setter for it, so a token can never resolve trust against a registry of its own.
166
+ function setTrustedGatewayRegistry(address registry) external {
167
+ require(registry != address(0), ErrorsLib.ZeroAddress());
168
+
169
+ layout().registry = ITrustedGatewayRegistry(registry);
170
+
171
+ emit EventsLib.TrustedGatewayRegistrySet(registry);
172
+ }
173
+
174
+ /// @dev See {ITREXMessaging-setRoute}. Authorization is the caller's.
175
+ function setRoute(bytes2 chainType, bytes calldata chainReference, address gateway) external {
176
+ MessagingStorage storage s = layout();
177
+
178
+ // The zero gateway is how an issuer closes a chain, so it is the one value not vetted.
179
+ require(gateway == address(0) || s.registry.isTrusted(gateway), ErrorsLib.GatewayNotTrusted(gateway));
180
+
181
+ bytes32 chainKey = _registerChain(s, chainType, chainReference);
182
+ s.routes[chainKey] = gateway;
183
+
184
+ emit EventsLib.RouteSet(chainKey, gateway);
185
+ }
186
+
187
+ /// @dev See {ITREXMessaging-setPeer}. Authorization is the caller's.
188
+ function setPeer(bytes32 chainKey, bytes calldata peer) external {
189
+ MessagingStorage storage s = layout();
190
+
191
+ // Empty restores the default; anything else must be a canonical envelope for this very chain. An EVM
192
+ // account is 20 bytes: a gateway reports its sender that way, so any other length could never match.
193
+ if (peer.length > 0) {
194
+ (bytes2 chainType, bytes calldata chainReference, bytes calldata account) =
195
+ InteroperableAddress.parseV1Calldata(peer);
196
+
197
+ bool hasAccount = account.length > 0;
198
+ bool noTrailingBytes = peer.length == ERC7930_V1_FIXED_LENGTH + chainReference.length + account.length;
199
+ bool accountFitsItsChain = chainType != MessageTypesLib.EVM_CHAIN_TYPE || account.length == 20;
200
+ require(hasAccount && noTrailingBytes && accountFitsItsChain, ErrorsLib.InvalidPeer(peer));
201
+
202
+ bytes32 peerChainKey = _registerChain(s, chainType, chainReference);
203
+ require(peerChainKey == chainKey, ErrorsLib.PeerChainMismatch(chainKey, peerChainKey));
204
+ } else {
205
+ // Nothing to restore on a chain the token has never seen, and the write would be a noop.
206
+ require(s.chains[chainKey].chainReference.length > 0, ErrorsLib.ChainNotRegistered(chainKey));
207
+ }
208
+
209
+ s.peers[chainKey] = peer;
210
+
211
+ emit EventsLib.PeerSet(chainKey, peer);
212
+ }
213
+
214
+ /* ----- Outbound ----- */
215
+
216
+ /// @dev Sends a compliance validation to this token's peer on `chainKey`, pinning the route it took.
217
+ ///
218
+ /// The first dispatch of a validation toward a chain records the gateway and the peer; its settlement
219
+ /// legs from that chain are then matched against those alone, so a later peer change does not strand
220
+ /// them. A re-dispatch through the same gateway to the same peer is allowed, so a lost message can be
221
+ /// re-sent.
222
+ function sendComplianceValidation(bytes32 chainKey, uint256 validationId, bytes memory body)
223
+ external
224
+ returns (bytes32 sendId)
225
+ {
226
+ MessagingStorage storage s = layout();
227
+ (address gateway, bytes memory peer) = _openRoute(s, chainKey);
228
+
229
+ address pinned = s.pinnedRoutes[validationId][chainKey];
230
+ if (pinned == address(0)) {
231
+ s.pinnedRoutes[validationId][chainKey] = gateway;
232
+ s.pinnedPeers[validationId][chainKey] = keccak256(peer);
233
+
234
+ emit EventsLib.ValidationRoutePinned(validationId, chainKey, gateway);
235
+ } else {
236
+ bool sameGateway = pinned == gateway;
237
+ bool samePeer = s.pinnedPeers[validationId][chainKey] == keccak256(peer);
238
+ require(sameGateway, ErrorsLib.ValidationAlreadyRouted(validationId, chainKey, pinned));
239
+ require(samePeer, ErrorsLib.ValidationAlreadyRouted(validationId, chainKey, pinned));
240
+ }
241
+
242
+ sendId = _send(gateway, peer, chainKey, MessageTypesLib.Message.COMPLIANCE_VALIDATION, body);
243
+ }
244
+
245
+ /// @dev Sends one protocol message to this token's peer on `chainKey`, through its current route.
246
+ ///
247
+ /// Fail-closed before anything leaves: a registry must be set, the chain must be routed, the routed
248
+ /// gateway must still be trusted at this instant, and the peer must be addressable.
249
+ function sendMessage(bytes32 chainKey, MessageTypesLib.Message messageType, bytes memory body)
250
+ external
251
+ returns (bytes32 sendId)
252
+ {
253
+ (address gateway, bytes memory peer) = _openRoute(layout(), chainKey);
254
+
255
+ sendId = _send(gateway, peer, chainKey, messageType, body);
256
+ }
257
+
258
+ /* ----- Inbound ----- */
259
+
260
+ /// @dev Attributes and admits one inbound delivery, and hands back what the token must act on.
261
+ ///
262
+ /// Everything that decides whether a message is accepted happens here: the envelope must decode, a
263
+ /// delivery under a nonzero receive id must be new (and is recorded), the type must be one a token receives,
264
+ /// and the author and the gateway must be the ones this message is expected from. A settlement comes from
265
+ /// the peer and gateway its validation was pinned to, or the current ones for an id this token never
266
+ /// dispatched; a burn proof for a recall still open comes from the peer and gateway that recall was
267
+ /// dispatched to, so a later route or peer change cannot strand it, and any other burn proof from the current
268
+ /// peer and route. Acting on the message is left to the token, since only it knows its compliance and its
269
+ /// pause. The gateway's trust is the caller's check, made before this is reached, so a gateway the registry
270
+ /// no longer trusts is refused even when pinned.
271
+ /// @return messageType `SETTLEMENT_NOTIFICATION` or `BURN_PROOF`; anything else reverts.
272
+ /// @return chainKey The chain the message is attributed to.
273
+ /// @return body The still-encoded body, of the type `messageType` names.
274
+ function acceptMessage(address gateway, bytes32 receiveId, bytes calldata sender, bytes calldata payload)
275
+ external
276
+ returns (MessageTypesLib.Message messageType, bytes32 chainKey, bytes memory body)
277
+ {
278
+ (bytes2 chainType, bytes calldata chainReference,) = InteroperableAddress.parseV1Calldata(sender);
279
+ chainKey = MessageTypesLib.chainKey(chainType, chainReference);
280
+
281
+ MessagingStorage storage s = layout();
282
+
283
+ (messageType, body) = MessageTypesLib.decode(payload);
284
+
285
+ // A zero id is a gateway naming no delivery, which ERC-7786 allows; recording it would refuse every later
286
+ // message from that gateway. Its deliveries are still deduplicated by what they carry: a settlement by
287
+ // its validation's status, a burn proof by its recall and the hash of the proof that settled it.
288
+ if (receiveId != bytes32(0)) {
289
+ require(!s.received[gateway][receiveId], ErrorsLib.MessageAlreadyReceived(gateway, receiveId));
290
+ s.received[gateway][receiveId] = true;
291
+ }
292
+
293
+ if (messageType == MessageTypesLib.Message.SETTLEMENT_NOTIFICATION) {
294
+ _requireExpectedOrigin(s, gateway, chainKey, sender, MessageTypesLib.decodeSettlement(body).validationId);
295
+ } else if (messageType == MessageTypesLib.Message.BURN_PROOF) {
296
+ _requireRecallOrigin(s, gateway, chainKey, sender, MessageTypesLib.decodeBurnProof(body).recallId);
297
+ } else {
298
+ revert ErrorsLib.MessageTypeNotInbound(messageType);
299
+ }
300
+ }
301
+
302
+ /// @dev Hands an admitted settlement to `handler`, decoded, and reports whether the token must halt.
303
+ ///
304
+ /// The token calls this from inside its own pause and reentrancy checks. Run by DELEGATECALL, so
305
+ /// the handler sees the token as its caller, which is the only caller a compliance accepts.
306
+ /// @param handler The token's bound compliance.
307
+ /// @param body A settlement body, as {acceptMessage} returned it.
308
+ /// @return halt Whether the handler reported a replayed or never-issued settlement.
309
+ function forwardSettlement(address handler, bytes32 chainKey, bytes memory body) external returns (bool halt) {
310
+ return ISettlementHandler(handler).handleSettlement(chainKey, MessageTypesLib.decodeSettlement(body));
311
+ }
312
+
313
+ /* ----- Storage ----- */
314
+
315
+ /// @dev The token's messaging namespace. Internal, so the cheap reads stay in the token itself.
316
+ function layout() internal pure returns (MessagingStorage storage $) {
317
+ assembly ("memory-safe") {
318
+ $.slot := MESSAGING_STORAGE_LOCATION
319
+ }
320
+ }
321
+
322
+ /* ----- Private ----- */
323
+
324
+ /// @dev Records the prefix behind a chain key the first time it is seen, and returns the key.
325
+ function _registerChain(MessagingStorage storage s, bytes2 chainType, bytes calldata chainReference)
326
+ private
327
+ returns (bytes32 chainKey)
328
+ {
329
+ require(
330
+ chainReference.length > 0 && (chainType != MessageTypesLib.EVM_CHAIN_TYPE || chainReference[0] != 0x00),
331
+ ErrorsLib.InvalidChainReference(chainType, chainReference)
332
+ );
333
+
334
+ chainKey = MessageTypesLib.chainKey(chainType, chainReference);
335
+
336
+ ChainPrefix storage chain = s.chains[chainKey];
337
+ if (chain.chainReference.length == 0) {
338
+ chain.chainType = chainType;
339
+ chain.chainReference = chainReference;
340
+
341
+ emit EventsLib.ChainRegistered(chainKey, chainType, chainReference);
342
+ }
343
+ }
344
+
345
+ function _send(
346
+ address gateway,
347
+ bytes memory peer,
348
+ bytes32 chainKey,
349
+ MessageTypesLib.Message messageType,
350
+ bytes memory body
351
+ ) private returns (bytes32 sendId) {
352
+ sendId = IERC7786GatewaySource(gateway)
353
+ .sendMessage(peer, MessageTypesLib.encode(messageType, body), new bytes[](0));
354
+
355
+ emit EventsLib.ProtocolMessageSent(messageType, chainKey, sendId);
356
+ }
357
+
358
+ /// @dev Resolves the gateway and peer for `chainKey`
359
+ function _openRoute(MessagingStorage storage s, bytes32 chainKey)
360
+ private
361
+ view
362
+ returns (address gateway, bytes memory peer)
363
+ {
364
+ gateway = s.routes[chainKey];
365
+ require(gateway != address(0) && s.registry.isTrusted(gateway), ErrorsLib.ChainNotOpen(chainKey));
366
+
367
+ peer = peerFor(chainKey);
368
+ require(peer.length > 0, ErrorsLib.ChainNotOpen(chainKey));
369
+ }
370
+
371
+ /// @dev The pinned peer and gateway when this token dispatched `validationId` toward `chainKey`, else
372
+ /// the current ones. A closed chain is refused first, pinned or not: closing it stops every settlement
373
+ /// from it, and reopening the route lets them be delivered again. An id this token never dispatched
374
+ /// there is not refused here: whether it was never issued, or issued from the reference side, is the
375
+ /// settlement handler's question.
376
+ function _requireExpectedOrigin(
377
+ MessagingStorage storage s,
378
+ address gateway,
379
+ bytes32 chainKey,
380
+ bytes calldata sender,
381
+ uint256 validationId
382
+ ) private view {
383
+ require(s.routes[chainKey] != address(0), ErrorsLib.ChainNotOpen(chainKey));
384
+
385
+ address pinned = s.pinnedRoutes[validationId][chainKey];
386
+ if (pinned == address(0)) {
387
+ _requireCurrentPeer(chainKey, sender);
388
+ _requireCurrentRoute(s, gateway, chainKey);
389
+ return;
390
+ }
391
+ require(keccak256(sender) == s.pinnedPeers[validationId][chainKey], ErrorsLib.SenderNotPeer(chainKey, sender));
392
+ require(pinned == gateway, ErrorsLib.GatewayNotPinned(gateway, validationId, chainKey));
393
+ }
394
+
395
+ function _requireCurrentPeer(bytes32 chainKey, bytes calldata sender) private view {
396
+ require(keccak256(sender) == keccak256(peerFor(chainKey)), ErrorsLib.SenderNotPeer(chainKey, sender));
397
+ }
398
+
399
+ /// @dev The peer and gateway the recall was dispatched to while it is open; the current ones once it is not,
400
+ /// so a settled or never-issued id still reaches the token's duplicate and replay handling. A closed chain is
401
+ /// refused first, as for a settlement: closing it stops every proof from it until a route is set again.
402
+ function _requireRecallOrigin(
403
+ MessagingStorage storage s,
404
+ address gateway,
405
+ bytes32 chainKey,
406
+ bytes calldata sender,
407
+ uint256 recallId
408
+ ) private view {
409
+ require(s.routes[chainKey] != address(0), ErrorsLib.ChainNotOpen(chainKey));
410
+
411
+ TokenLedgerLib.PendingRecall storage recall = TokenLedgerLib.layout().recalls[recallId];
412
+ if (recall.amount == 0) {
413
+ _requireCurrentPeer(chainKey, sender);
414
+ _requireCurrentRoute(s, gateway, chainKey);
415
+ return;
416
+ }
417
+ require(keccak256(sender) == recall.peerKey, ErrorsLib.SenderNotPeer(chainKey, sender));
418
+ require(recall.gateway == gateway, ErrorsLib.GatewayNotPinned(gateway, recallId, chainKey));
419
+ }
420
+
421
+ function _requireCurrentRoute(MessagingStorage storage s, address gateway, bytes32 chainKey) private view {
422
+ require(s.routes[chainKey] == gateway, ErrorsLib.GatewayNotRouted(gateway, chainKey));
423
+ }
424
+
425
+ }
@@ -37,52 +37,61 @@
37
37
  // :#%%=
38
38
  //
39
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 { ErrorsLib } from "../libraries/ErrorsLib.sol";
63
+ import { EventsLib } from "../libraries/EventsLib.sol";
64
+ import { AccessManagedOwnable } from "../utils/AccessManagedOwnable.sol";
65
+ import { ITrustedGatewayRegistry } from "./ITrustedGatewayRegistry.sol";
66
+
40
67
  /**
41
- * NOTICE
42
- *
43
- * The T-REX software is licensed under a proprietary license or the GPL v.3.
44
- * If you choose to receive it under the GPL v.3 license, the following applies:
45
- * T-REX is a suite of smart contracts implementing the ERC-3643 standard and
46
- * developed by Tokeny to manage and transfer financial assets on EVM blockchains
47
- *
48
- * Copyright (C) 2025, Tokeny sàrl.
49
- *
50
- * This program is free software: you can redistribute it and/or modify
51
- * it under the terms of the GNU General Public License as published by
52
- * the Free Software Foundation, either version 3 of the License, or
53
- * (at your option) any later version.
54
- *
55
- * This program is distributed in the hope that it will be useful,
56
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
57
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
58
- * GNU General Public License for more details.
68
+ * @title TrustedGatewayRegistry
69
+ * @dev The network's set of vetted ERC-7786 gateways.
59
70
  *
60
- * You should have received a copy of the GNU General Public License
61
- * along with this program. If not, see <https://www.gnu.org/licenses/>.
71
+ * A network singleton, deployed once per deployment and shared by every token. It is deliberately not
72
+ * upgradeable and holds nothing but the set.
62
73
  */
74
+ contract TrustedGatewayRegistry is ITrustedGatewayRegistry, AccessManagedOwnable {
63
75
 
64
- pragma solidity 0.8.30;
76
+ mapping(address gateway => bool) private _trusted;
65
77
 
66
- import { ErrorsLib } from "../libraries/ErrorsLib.sol";
67
- import { TrustedIssuersRegistry } from "../registry/implementation/TrustedIssuersRegistry.sol";
68
- import { AbstractProxy } from "./AbstractProxy.sol";
69
- import { ITREXImplementationAuthority } from "./authority/ITREXImplementationAuthority.sol";
78
+ constructor(address accessManager) AccessManagedOwnable(accessManager) {
79
+ // The same line `setAuthority` holds later: an address with no code answers no to every `restricted` call.
80
+ require(accessManager.code.length != 0, ErrorsLib.AccessManagerNotAContract(accessManager));
81
+ }
82
+
83
+ /// @inheritdoc ITrustedGatewayRegistry
84
+ function setTrustedGateway(address gateway, bool trusted) external restricted {
85
+ require(gateway != address(0), ErrorsLib.ZeroAddress());
70
86
 
71
- contract TrustedIssuersRegistryProxy is AbstractProxy {
87
+ _trusted[gateway] = trusted;
72
88
 
73
- constructor(
74
- address implementationAuthority,
75
- address _owner,
76
- address[] memory _issuers,
77
- uint256[][] memory _issuerClaims
78
- ) AbstractProxy(implementationAuthority) {
79
- (bool success,) = getLogic()
80
- .delegatecall(abi.encodeCall(TrustedIssuersRegistry.init, (_owner, _issuers, _issuerClaims)));
81
- require(success, ErrorsLib.InitializationFailed());
89
+ emit EventsLib.TrustedGatewaySet(gateway, trusted);
82
90
  }
83
91
 
84
- function getLogic() internal view override returns (address) {
85
- return (ITREXImplementationAuthority(getImplementationAuthority())).getTIRImplementation();
92
+ /// @inheritdoc ITrustedGatewayRegistry
93
+ function isTrusted(address gateway) external view returns (bool) {
94
+ return _trusted[gateway];
86
95
  }
87
96
 
88
97
  }