@towns-protocol/contracts 0.0.302

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 (396) hide show
  1. package/LICENSE.txt +21 -0
  2. package/README.md +206 -0
  3. package/docs/permitAndStake_integration_guide.md +266 -0
  4. package/docs/swap_integration_guide.md +591 -0
  5. package/package.json +57 -0
  6. package/scripts/common/DeployBase.s.sol +26 -0
  7. package/scripts/common/DeployFacet.s.sol +7 -0
  8. package/scripts/common/Deployer.s.sol +33 -0
  9. package/scripts/common/Interaction.s.sol +51 -0
  10. package/scripts/deployments/diamonds/DeployAppRegistry.s.sol +168 -0
  11. package/scripts/deployments/diamonds/DeployBaseRegistry.s.sol +263 -0
  12. package/scripts/deployments/diamonds/DeployRiverAirdrop.s.sol +203 -0
  13. package/scripts/deployments/diamonds/DeployRiverMigration.s.sol +129 -0
  14. package/scripts/deployments/diamonds/DeployRiverRegistry.s.sol +175 -0
  15. package/scripts/deployments/diamonds/DeploySpace.s.sol +285 -0
  16. package/scripts/deployments/diamonds/DeploySpaceFactory.s.sol +416 -0
  17. package/scripts/deployments/diamonds/DeploySpaceOwner.s.sol +183 -0
  18. package/scripts/deployments/diamonds/DeploySwapRouter.s.sol +176 -0
  19. package/scripts/deployments/diamonds/IDiamondInitHelper.sol +11 -0
  20. package/scripts/deployments/facets/DeployAppAccount.s.sol +51 -0
  21. package/scripts/deployments/facets/DeployAppRegistryFacet.s.sol +69 -0
  22. package/scripts/deployments/facets/DeployArchitect.s.sol +51 -0
  23. package/scripts/deployments/facets/DeployAttestationRegistry.s.sol +36 -0
  24. package/scripts/deployments/facets/DeployBanning.s.sol +30 -0
  25. package/scripts/deployments/facets/DeployChannels.s.sol +35 -0
  26. package/scripts/deployments/facets/DeployCreateSpace.s.sol +42 -0
  27. package/scripts/deployments/facets/DeployDropFacet.s.sol +49 -0
  28. package/scripts/deployments/facets/DeployERC721A.s.sol +48 -0
  29. package/scripts/deployments/facets/DeployERC721ANonTransferable.s.sol +49 -0
  30. package/scripts/deployments/facets/DeployERC721AQueryable.s.sol +30 -0
  31. package/scripts/deployments/facets/DeployEntitlementChecker.s.sol +49 -0
  32. package/scripts/deployments/facets/DeployEntitlementDataQueryable.s.sol +29 -0
  33. package/scripts/deployments/facets/DeployEntitlementsManager.s.sol +33 -0
  34. package/scripts/deployments/facets/DeployExecutorFacet.s.sol +60 -0
  35. package/scripts/deployments/facets/DeployFeatureManager.s.sol +38 -0
  36. package/scripts/deployments/facets/DeployGuardianFacet.s.sol +39 -0
  37. package/scripts/deployments/facets/DeployImplementationRegistry.s.sol +36 -0
  38. package/scripts/deployments/facets/DeployMainnetDelegation.s.sol +43 -0
  39. package/scripts/deployments/facets/DeployMembership.s.sol +77 -0
  40. package/scripts/deployments/facets/DeployMembershipMetadata.s.sol +30 -0
  41. package/scripts/deployments/facets/DeployMembershipToken.s.sol +47 -0
  42. package/scripts/deployments/facets/DeployMerkleAirdrop.s.sol +37 -0
  43. package/scripts/deployments/facets/DeployMetadata.s.sol +39 -0
  44. package/scripts/deployments/facets/DeployMockLegacyArchitect.s.sol +33 -0
  45. package/scripts/deployments/facets/DeployNodeOperator.s.sol +49 -0
  46. package/scripts/deployments/facets/DeployNodeRegistry.s.sol +37 -0
  47. package/scripts/deployments/facets/DeployOperatorRegistry.s.sol +36 -0
  48. package/scripts/deployments/facets/DeployPartnerRegistry.s.sol +41 -0
  49. package/scripts/deployments/facets/DeployPlatformRequirements.s.sol +75 -0
  50. package/scripts/deployments/facets/DeployPrepayFacet.s.sol +31 -0
  51. package/scripts/deployments/facets/DeployPricingModules.s.sol +36 -0
  52. package/scripts/deployments/facets/DeployReferrals.s.sol +34 -0
  53. package/scripts/deployments/facets/DeployReviewFacet.s.sol +31 -0
  54. package/scripts/deployments/facets/DeployRewardsDistributionV2.s.sol +76 -0
  55. package/scripts/deployments/facets/DeployRiverConfig.s.sol +41 -0
  56. package/scripts/deployments/facets/DeployRoles.s.sol +48 -0
  57. package/scripts/deployments/facets/DeploySchemaRegistry.s.sol +35 -0
  58. package/scripts/deployments/facets/DeploySignerFacet.s.sol +47 -0
  59. package/scripts/deployments/facets/DeploySimpleApp.s.sol +10 -0
  60. package/scripts/deployments/facets/DeploySpaceDelegation.s.sol +43 -0
  61. package/scripts/deployments/facets/DeploySpaceEntitlementGated.s.sol +31 -0
  62. package/scripts/deployments/facets/DeploySpaceFactoryInit.s.sol +33 -0
  63. package/scripts/deployments/facets/DeploySpaceOwnerFacet.s.sol +71 -0
  64. package/scripts/deployments/facets/DeployStreamRegistry.s.sol +50 -0
  65. package/scripts/deployments/facets/DeploySwapFacet.s.sol +33 -0
  66. package/scripts/deployments/facets/DeploySwapRouterFacet.s.sol +38 -0
  67. package/scripts/deployments/facets/DeployTipping.s.sol +31 -0
  68. package/scripts/deployments/facets/DeployTokenMigration.s.sol +40 -0
  69. package/scripts/deployments/facets/DeployTownsPoints.s.sol +53 -0
  70. package/scripts/deployments/facets/DeployTreasury.s.sol +30 -0
  71. package/scripts/deployments/facets/DeployUpgradeableBeacon.s.sol +34 -0
  72. package/scripts/deployments/facets/DeployWalletLink.s.sol +56 -0
  73. package/scripts/deployments/facets/DeployXChain.s.sol +35 -0
  74. package/scripts/deployments/utils/DeployAccountFactory.s.sol +40 -0
  75. package/scripts/deployments/utils/DeployEntitlementGatedExample.s.sol +23 -0
  76. package/scripts/deployments/utils/DeployEntrypoint.s.sol +28 -0
  77. package/scripts/deployments/utils/DeployMember.s.sol +95 -0
  78. package/scripts/deployments/utils/DeployMockDiamond.s.sol +7 -0
  79. package/scripts/deployments/utils/DeployMockERC20.s.sol +24 -0
  80. package/scripts/deployments/utils/DeployMockERC721A.s.sol +45 -0
  81. package/scripts/deployments/utils/DeployMockLegacyMembership.s.sol +29 -0
  82. package/scripts/deployments/utils/DeployMockMessenger.s.sol +42 -0
  83. package/scripts/deployments/utils/DeployMockNFT.s.sol +86 -0
  84. package/scripts/deployments/utils/DeployPoapEntitlement.s.sol +16 -0
  85. package/scripts/deployments/utils/DeployProxyBatchDelegation.s.sol +112 -0
  86. package/scripts/deployments/utils/DeploySpaceProxyInitializer.s.sol +28 -0
  87. package/scripts/deployments/utils/DeployTieredLogPricingV2.s.sol +23 -0
  88. package/scripts/deployments/utils/DeployTieredLogPricingV3.s.sol +23 -0
  89. package/scripts/deployments/utils/DeployTownsBase.s.sol +95 -0
  90. package/scripts/deployments/utils/DeployTownsMainnet.s.sol +66 -0
  91. package/scripts/deployments/utils/DeployTownsMulti.s.sol +53 -0
  92. package/scripts/deployments/utils/DeployWrappedTowns.s.sol +52 -0
  93. package/scripts/deployments/utils/LibLayerZeroValues.sol +34 -0
  94. package/scripts/deployments/utils/pricing/TieredLogPricing.s.sol +45 -0
  95. package/scripts/interactions/InteractAirdrop.s.sol +57 -0
  96. package/scripts/interactions/InteractAlphaPost.s.sol +32 -0
  97. package/scripts/interactions/InteractAlphaSparse.s.sol +173 -0
  98. package/scripts/interactions/InteractBaseAlpha.s.sol +84 -0
  99. package/scripts/interactions/InteractBaseBridge.s.sol +48 -0
  100. package/scripts/interactions/InteractBridgeLayerZero.s.sol +102 -0
  101. package/scripts/interactions/InteractClaimCondition.s.sol +56 -0
  102. package/scripts/interactions/InteractCreateSpace.s.sol +50 -0
  103. package/scripts/interactions/InteractDiamondCut.s.sol +47 -0
  104. package/scripts/interactions/InteractDropFacet.s.sol +32 -0
  105. package/scripts/interactions/InteractEnableNewSnapshotFormat.s.sol +27 -0
  106. package/scripts/interactions/InteractEnableNode2NodeAuth.s.sol +27 -0
  107. package/scripts/interactions/InteractMembership.s.sol +42 -0
  108. package/scripts/interactions/InteractMockERC721A.s.sol +20 -0
  109. package/scripts/interactions/InteractNodeOperators.s.sol +41 -0
  110. package/scripts/interactions/InteractPostDeploy.s.sol +59 -0
  111. package/scripts/interactions/InteractPrepay.s.sol +30 -0
  112. package/scripts/interactions/InteractRegisterApp.s.sol +61 -0
  113. package/scripts/interactions/InteractRiverAlpha.s.sol +30 -0
  114. package/scripts/interactions/InteractRiverAlphaSparse.s.sol +117 -0
  115. package/scripts/interactions/InteractRiverMainnet.s.sol +27 -0
  116. package/scripts/interactions/InteractRiverRegistry.s.sol +36 -0
  117. package/scripts/interactions/InteractRiverRegistrySetBlocklist.s.sol +30 -0
  118. package/scripts/interactions/InteractRiverRegistrySetFreq.s.sol +27 -0
  119. package/scripts/interactions/InteractRiverRegistrySetRepl.s.sol +30 -0
  120. package/scripts/interactions/InteractSetDefaultUri.s.sol +20 -0
  121. package/scripts/interactions/InteractSetDefaultUriLocalhost.s.sol +19 -0
  122. package/scripts/interactions/InteractTransferOwnership.s.sol +21 -0
  123. package/scripts/interactions/InteractUpdateMbRecencyCheck.s.sol +27 -0
  124. package/scripts/interactions/InteractUpdateMediaChunkCount.s.sol +27 -0
  125. package/scripts/interactions/InteractUpdateMediaChunkSize.s.sol +27 -0
  126. package/scripts/interactions/helpers/AlphaHelper.sol +149 -0
  127. package/scripts/interactions/helpers/RiverConfigValues.sol +22 -0
  128. package/scripts/interactions/interfaces/IL1StandardBridge.sol +35 -0
  129. package/scripts/interactions/interfaces/IL2StandardBridge.sol +69 -0
  130. package/src/airdrop/drop/DropBase.sol +210 -0
  131. package/src/airdrop/drop/DropClaim.sol +55 -0
  132. package/src/airdrop/drop/DropFacet.sol +176 -0
  133. package/src/airdrop/drop/DropGroup.sol +111 -0
  134. package/src/airdrop/drop/DropStorage.sol +23 -0
  135. package/src/airdrop/drop/IDropFacet.sol +136 -0
  136. package/src/airdrop/points/CheckIn.sol +71 -0
  137. package/src/airdrop/points/ITownsPoints.sol +64 -0
  138. package/src/airdrop/points/TownsPoints.sol +196 -0
  139. package/src/airdrop/points/TownsPointsStorage.sol +22 -0
  140. package/src/apps/BaseApp.sol +62 -0
  141. package/src/apps/ITownsApp.sol +28 -0
  142. package/src/apps/SchemaResolver.sol +170 -0
  143. package/src/apps/facets/attest/AttestationBase.sol +335 -0
  144. package/src/apps/facets/attest/AttestationLib.sol +64 -0
  145. package/src/apps/facets/attest/AttestationRegistry.sol +39 -0
  146. package/src/apps/facets/attest/AttestationStorage.sol +35 -0
  147. package/src/apps/facets/attest/IAttestationRegistry.sol +43 -0
  148. package/src/apps/facets/registry/AppRegistryBase.sol +403 -0
  149. package/src/apps/facets/registry/AppRegistryFacet.sol +173 -0
  150. package/src/apps/facets/registry/AppRegistryStorage.sol +53 -0
  151. package/src/apps/facets/registry/IAppRegistry.sol +159 -0
  152. package/src/apps/facets/schema/ISchema.sol +14 -0
  153. package/src/apps/facets/schema/SchemaBase.sol +88 -0
  154. package/src/apps/facets/schema/SchemaLib.sol +14 -0
  155. package/src/apps/facets/schema/SchemaRegistry.sol +51 -0
  156. package/src/apps/facets/schema/SchemaStorage.sol +34 -0
  157. package/src/apps/helpers/ISimpleApp.sol +51 -0
  158. package/src/apps/helpers/SimpleApp.sol +97 -0
  159. package/src/apps/helpers/SimpleAppStorage.sol +27 -0
  160. package/src/base/registry/facets/checker/EntitlementChecker.sol +237 -0
  161. package/src/base/registry/facets/checker/EntitlementCheckerStorage.sol +28 -0
  162. package/src/base/registry/facets/checker/IEntitlementChecker.sol +95 -0
  163. package/src/base/registry/facets/delegation/ISpaceDelegation.sol +69 -0
  164. package/src/base/registry/facets/delegation/SpaceDelegationFacet.sol +250 -0
  165. package/src/base/registry/facets/delegation/SpaceDelegationStorage.sol +35 -0
  166. package/src/base/registry/facets/distribution/v1/IRewardsDistribution.sol +51 -0
  167. package/src/base/registry/facets/distribution/v1/RewardsDistribution.sol +439 -0
  168. package/src/base/registry/facets/distribution/v1/RewardsDistributionStorage.sol +32 -0
  169. package/src/base/registry/facets/distribution/v2/DelegationProxy.sol +53 -0
  170. package/src/base/registry/facets/distribution/v2/IRewardsDistribution.sol +372 -0
  171. package/src/base/registry/facets/distribution/v2/RewardsDistributionBase.sol +299 -0
  172. package/src/base/registry/facets/distribution/v2/RewardsDistributionStorage.sol +37 -0
  173. package/src/base/registry/facets/distribution/v2/RewardsDistributionV2.sol +392 -0
  174. package/src/base/registry/facets/distribution/v2/StakingRewards.sol +466 -0
  175. package/src/base/registry/facets/mainnet/ICrossDomainMessenger.sol +58 -0
  176. package/src/base/registry/facets/mainnet/IMainnetDelegation.sol +127 -0
  177. package/src/base/registry/facets/mainnet/MainnetDelegation.sol +119 -0
  178. package/src/base/registry/facets/mainnet/MainnetDelegationBase.sol +274 -0
  179. package/src/base/registry/facets/mainnet/MainnetDelegationStorage.sol +36 -0
  180. package/src/base/registry/facets/operator/INodeOperator.sol +91 -0
  181. package/src/base/registry/facets/operator/NodeOperatorFacet.sol +189 -0
  182. package/src/base/registry/facets/operator/NodeOperatorStorage.sol +39 -0
  183. package/src/base/registry/facets/xchain/IXChain.sol +54 -0
  184. package/src/base/registry/facets/xchain/XChain.sol +158 -0
  185. package/src/base/registry/facets/xchain/XChainCheckLib.sol +105 -0
  186. package/src/base/registry/facets/xchain/XChainLib.sol +46 -0
  187. package/src/diamond/facets/beacon/UpgradeableBeacon.sol +38 -0
  188. package/src/diamond/facets/beacon/UpgradeableBeaconFacet.sol +34 -0
  189. package/src/diamond/facets/governance/votes/Checkpoints.sol +642 -0
  190. package/src/diamond/facets/governance/votes/Votes.sol +63 -0
  191. package/src/diamond/facets/governance/votes/VotesBase.sol +274 -0
  192. package/src/diamond/facets/governance/votes/VotesStorage.sol +21 -0
  193. package/src/diamond/facets/governance/votes/enumerable/IVotesEnumerable.sol +38 -0
  194. package/src/diamond/facets/governance/votes/enumerable/VotesEnumerable.sol +39 -0
  195. package/src/diamond/facets/governance/votes/enumerable/VotesEnumerableLib.sol +102 -0
  196. package/src/diamond/facets/metadata/IMetadata.sol +27 -0
  197. package/src/diamond/facets/metadata/MetadataFacet.sol +71 -0
  198. package/src/diamond/facets/token/ERC5643/ERC5643.sol +51 -0
  199. package/src/diamond/facets/token/ERC5643/ERC5643Base.sol +48 -0
  200. package/src/diamond/facets/token/ERC5643/ERC5643Storage.sol +26 -0
  201. package/src/diamond/facets/token/ERC5643/IERC5643.sol +44 -0
  202. package/src/diamond/facets/token/ERC721A/ERC721A.sol +270 -0
  203. package/src/diamond/facets/token/ERC721A/ERC721ABase.sol +829 -0
  204. package/src/diamond/facets/token/ERC721A/ERC721ANonTransferable.sol +21 -0
  205. package/src/diamond/facets/token/ERC721A/ERC721AStorage.sol +115 -0
  206. package/src/diamond/facets/token/ERC721A/IERC721A.sol +283 -0
  207. package/src/diamond/facets/token/ERC721A/extensions/ERC721AQueryable.sol +134 -0
  208. package/src/diamond/facets/token/ERC721A/extensions/IERC721AQueryable.sol +83 -0
  209. package/src/diamond/utils/Context.sol +19 -0
  210. package/src/factory/SpaceFactoryInit.sol +17 -0
  211. package/src/factory/facets/architect/Architect.sol +98 -0
  212. package/src/factory/facets/architect/ArchitectBase.sol +95 -0
  213. package/src/factory/facets/architect/ArchitectStorage.sol +28 -0
  214. package/src/factory/facets/architect/IArchitect.sol +155 -0
  215. package/src/factory/facets/architect/ImplementationStorage.sol +42 -0
  216. package/src/factory/facets/architect/pricing/IPricingModules.sol +41 -0
  217. package/src/factory/facets/architect/pricing/PricingModulesBase.sol +89 -0
  218. package/src/factory/facets/architect/pricing/PricingModulesFacet.sol +40 -0
  219. package/src/factory/facets/architect/pricing/PricingModulesStorage.sol +30 -0
  220. package/src/factory/facets/create/CreateSpace.sol +107 -0
  221. package/src/factory/facets/create/CreateSpaceLib.sol +335 -0
  222. package/src/factory/facets/create/ICreateSpace.sol +70 -0
  223. package/src/factory/facets/feature/FeatureConditionLib.sol +53 -0
  224. package/src/factory/facets/feature/FeatureManagerFacet.sol +66 -0
  225. package/src/factory/facets/feature/FeatureManagerLib.sol +168 -0
  226. package/src/factory/facets/feature/IFeatureManagerFacet.sol +73 -0
  227. package/src/factory/facets/partner/IPartnerRegistry.sol +56 -0
  228. package/src/factory/facets/partner/PartnerRegistry.sol +57 -0
  229. package/src/factory/facets/partner/PartnerRegistryBase.sol +132 -0
  230. package/src/factory/facets/partner/PartnerRegistryStorage.sol +40 -0
  231. package/src/factory/facets/platform/requirements/IPlatformRequirements.sol +143 -0
  232. package/src/factory/facets/platform/requirements/PlatformRequirementsBase.sol +124 -0
  233. package/src/factory/facets/platform/requirements/PlatformRequirementsFacet.sol +122 -0
  234. package/src/factory/facets/platform/requirements/PlatformRequirementsStorage.sol +41 -0
  235. package/src/factory/facets/registry/IImplementationRegistry.sol +46 -0
  236. package/src/factory/facets/registry/ImplementationRegistry.sol +64 -0
  237. package/src/factory/facets/registry/ImplementationRegistryStorage.sol +28 -0
  238. package/src/factory/facets/wallet-link/IWalletLink.sol +218 -0
  239. package/src/factory/facets/wallet-link/WalletLink.sol +108 -0
  240. package/src/factory/facets/wallet-link/WalletLinkBase.sol +492 -0
  241. package/src/factory/facets/wallet-link/interfaces/IDelegateRegistry.sol +63 -0
  242. package/src/factory/facets/wallet-link/interfaces/IDelegateRegistryV1.sol +35 -0
  243. package/src/factory/facets/wallet-link/interfaces/ISCL_EIP6565.sol +24 -0
  244. package/src/factory/facets/wallet-link/libraries/SolanaUtils.sol +161 -0
  245. package/src/factory/facets/wallet-link/libraries/WalletLib.sol +62 -0
  246. package/src/river/registry/facets/config/IRiverConfig.sol +117 -0
  247. package/src/river/registry/facets/config/RiverConfig.sol +174 -0
  248. package/src/river/registry/facets/node/INodeRegistry.sol +69 -0
  249. package/src/river/registry/facets/node/NodeRegistry.sol +143 -0
  250. package/src/river/registry/facets/operator/IOperatorRegistry.sol +28 -0
  251. package/src/river/registry/facets/operator/OperatorRegistry.sol +86 -0
  252. package/src/river/registry/facets/stream/IStreamRegistry.sol +184 -0
  253. package/src/river/registry/facets/stream/StreamRegistry.sol +396 -0
  254. package/src/river/registry/libraries/RegistryErrors.sol +24 -0
  255. package/src/river/registry/libraries/RegistryStorage.sol +181 -0
  256. package/src/router/ISwapRouter.sol +226 -0
  257. package/src/router/Permit2Hash.sol +92 -0
  258. package/src/router/SwapRouter.sol +463 -0
  259. package/src/router/SwapRouterStorage.sol +21 -0
  260. package/src/spaces/entitlements/ICrossChainEntitlement.sol +22 -0
  261. package/src/spaces/entitlements/IEntitlement.sol +61 -0
  262. package/src/spaces/entitlements/PolymarketEntitlement.sol +79 -0
  263. package/src/spaces/entitlements/poap/IPOAP.sol +26 -0
  264. package/src/spaces/entitlements/poap/PoapEntitlement.sol +56 -0
  265. package/src/spaces/entitlements/rule/IRuleEntitlement.sol +174 -0
  266. package/src/spaces/entitlements/rule/RuleEntitlement.sol +183 -0
  267. package/src/spaces/entitlements/rule/RuleEntitlementV2.sol +219 -0
  268. package/src/spaces/entitlements/user/IUserEntitlement.sol +24 -0
  269. package/src/spaces/entitlements/user/UserEntitlement.sol +273 -0
  270. package/src/spaces/facets/DependencyLib.sol +60 -0
  271. package/src/spaces/facets/Entitled.sol +172 -0
  272. package/src/spaces/facets/Permissions.sol +21 -0
  273. package/src/spaces/facets/account/AppAccount.sol +93 -0
  274. package/src/spaces/facets/account/AppAccountBase.sol +275 -0
  275. package/src/spaces/facets/account/AppAccountStorage.sol +63 -0
  276. package/src/spaces/facets/account/IAppAccount.sol +71 -0
  277. package/src/spaces/facets/account/SignerFacet.sol +26 -0
  278. package/src/spaces/facets/banning/Banning.sol +41 -0
  279. package/src/spaces/facets/banning/BanningBase.sol +33 -0
  280. package/src/spaces/facets/banning/BanningStorage.sol +23 -0
  281. package/src/spaces/facets/banning/IBanning.sol +35 -0
  282. package/src/spaces/facets/channels/ChannelBase.sol +87 -0
  283. package/src/spaces/facets/channels/ChannelService.sol +177 -0
  284. package/src/spaces/facets/channels/ChannelStorage.sol +34 -0
  285. package/src/spaces/facets/channels/Channels.sol +80 -0
  286. package/src/spaces/facets/channels/IChannel.sol +98 -0
  287. package/src/spaces/facets/dispatcher/DispatcherBase.sol +86 -0
  288. package/src/spaces/facets/dispatcher/DispatcherStorage.sol +21 -0
  289. package/src/spaces/facets/dispatcher/IDispatcher.sol +6 -0
  290. package/src/spaces/facets/entitlements/EntitlementsManager.sol +49 -0
  291. package/src/spaces/facets/entitlements/EntitlementsManagerBase.sol +87 -0
  292. package/src/spaces/facets/entitlements/EntitlementsManagerService.sol +142 -0
  293. package/src/spaces/facets/entitlements/EntitlementsManagerStorage.sol +34 -0
  294. package/src/spaces/facets/entitlements/IEntitlementsManager.sol +67 -0
  295. package/src/spaces/facets/entitlements/extensions/EntitlementDataQueryable.sol +153 -0
  296. package/src/spaces/facets/entitlements/extensions/IEntitlementDataQueryable.sol +32 -0
  297. package/src/spaces/facets/executor/ExecutorBase.sol +564 -0
  298. package/src/spaces/facets/executor/ExecutorFacet.sol +178 -0
  299. package/src/spaces/facets/executor/ExecutorStorage.sol +99 -0
  300. package/src/spaces/facets/executor/GroupLib.sol +128 -0
  301. package/src/spaces/facets/executor/IExecutor.sol +287 -0
  302. package/src/spaces/facets/executor/hooks/HookBase.sol +172 -0
  303. package/src/spaces/facets/executor/hooks/HookLib.sol +38 -0
  304. package/src/spaces/facets/executor/hooks/IHookBase.sol +48 -0
  305. package/src/spaces/facets/gated/EntitlementGated.sol +59 -0
  306. package/src/spaces/facets/gated/EntitlementGatedBase.sol +324 -0
  307. package/src/spaces/facets/gated/EntitlementGatedStorage.sol +29 -0
  308. package/src/spaces/facets/gated/IEntitlementGated.sol +55 -0
  309. package/src/spaces/facets/guardian/GuardianBase.sol +80 -0
  310. package/src/spaces/facets/guardian/GuardianFacet.sol +43 -0
  311. package/src/spaces/facets/guardian/GuardianStorage.sol +27 -0
  312. package/src/spaces/facets/guardian/IGuardian.sol +54 -0
  313. package/src/spaces/facets/membership/IMembership.sol +216 -0
  314. package/src/spaces/facets/membership/MembershipBase.sol +272 -0
  315. package/src/spaces/facets/membership/MembershipFacet.sol +191 -0
  316. package/src/spaces/facets/membership/MembershipStorage.sol +40 -0
  317. package/src/spaces/facets/membership/join/MembershipJoin.sol +547 -0
  318. package/src/spaces/facets/membership/metadata/IMembershipMetadata.sol +9 -0
  319. package/src/spaces/facets/membership/metadata/MembershipMetadata.sol +32 -0
  320. package/src/spaces/facets/membership/pricing/IMembershipPricing.sol +18 -0
  321. package/src/spaces/facets/membership/pricing/fixed/FixedPricing.sol +29 -0
  322. package/src/spaces/facets/membership/pricing/fixed/FixedPricingStorage.sol +27 -0
  323. package/src/spaces/facets/membership/pricing/tiered/TieredLogPricingOracleV2.sol +148 -0
  324. package/src/spaces/facets/membership/pricing/tiered/TieredLogPricingOracleV3.sol +137 -0
  325. package/src/spaces/facets/membership/token/MembershipToken.sol +25 -0
  326. package/src/spaces/facets/owner/ISpaceOwner.sol +85 -0
  327. package/src/spaces/facets/owner/SpaceOwner.sol +174 -0
  328. package/src/spaces/facets/owner/SpaceOwnerBase.sol +121 -0
  329. package/src/spaces/facets/owner/SpaceOwnerStorage.sol +41 -0
  330. package/src/spaces/facets/owner/SpaceOwnerUriBase.sol +54 -0
  331. package/src/spaces/facets/points/PointsBase.sol +35 -0
  332. package/src/spaces/facets/prepay/IPrepay.sol +43 -0
  333. package/src/spaces/facets/prepay/PrepayBase.sol +27 -0
  334. package/src/spaces/facets/prepay/PrepayFacet.sol +59 -0
  335. package/src/spaces/facets/prepay/PrepayStorage.sol +26 -0
  336. package/src/spaces/facets/proxy/ISpaceProxyInitializer.sol +21 -0
  337. package/src/spaces/facets/proxy/SpaceProxy.sol +15 -0
  338. package/src/spaces/facets/proxy/SpaceProxyInitializer.sol +55 -0
  339. package/src/spaces/facets/referrals/IReferrals.sol +98 -0
  340. package/src/spaces/facets/referrals/ReferralsBase.sol +81 -0
  341. package/src/spaces/facets/referrals/ReferralsFacet.sol +65 -0
  342. package/src/spaces/facets/referrals/ReferralsStorage.sol +36 -0
  343. package/src/spaces/facets/review/IReview.sol +50 -0
  344. package/src/spaces/facets/review/ReviewFacet.sol +105 -0
  345. package/src/spaces/facets/review/ReviewStorage.sol +29 -0
  346. package/src/spaces/facets/roles/IRoles.sol +197 -0
  347. package/src/spaces/facets/roles/Roles.sol +123 -0
  348. package/src/spaces/facets/roles/RolesBase.sol +420 -0
  349. package/src/spaces/facets/roles/RolesStorage.sol +132 -0
  350. package/src/spaces/facets/swap/ISwapFacet.sol +91 -0
  351. package/src/spaces/facets/swap/SwapFacet.sol +290 -0
  352. package/src/spaces/facets/swap/SwapFacetStorage.sol +24 -0
  353. package/src/spaces/facets/tipping/ITipping.sol +80 -0
  354. package/src/spaces/facets/tipping/TippingBase.sol +73 -0
  355. package/src/spaces/facets/tipping/TippingFacet.sol +123 -0
  356. package/src/spaces/facets/treasury/ITreasury.sol +64 -0
  357. package/src/spaces/facets/treasury/Treasury.sol +82 -0
  358. package/src/spaces/facets/xchain/SpaceEntitlementGated.sol +62 -0
  359. package/src/tokens/Member.sol +246 -0
  360. package/src/tokens/lock/ILock.sol +42 -0
  361. package/src/tokens/lock/LockBase.sol +64 -0
  362. package/src/tokens/lock/LockFacet.sol +44 -0
  363. package/src/tokens/lock/LockStorage.sol +26 -0
  364. package/src/tokens/mainnet/claimer/AuthorizedClaimerStorage.sol +26 -0
  365. package/src/tokens/mainnet/claimer/AuthorizedClaimers.sol +84 -0
  366. package/src/tokens/mainnet/claimer/IAuthorizedClaimers.sol +36 -0
  367. package/src/tokens/mainnet/delegation/ProxyBatchDelegation.sol +86 -0
  368. package/src/tokens/migration/ITokenMigration.sol +35 -0
  369. package/src/tokens/migration/TokenMigrationFacet.sol +86 -0
  370. package/src/tokens/migration/TokenMigrationStorage.sol +27 -0
  371. package/src/tokens/towns/base/IERC7802.sol +30 -0
  372. package/src/tokens/towns/base/IOptimismMintableERC20.sol +31 -0
  373. package/src/tokens/towns/base/ISemver.sol +13 -0
  374. package/src/tokens/towns/base/Towns.sol +283 -0
  375. package/src/tokens/towns/base/TownsDeployer.sol +32 -0
  376. package/src/tokens/towns/base/TownsLib.sol +31 -0
  377. package/src/tokens/towns/base/versions/TownsV2.sol +15 -0
  378. package/src/tokens/towns/mainnet/ITowns.sol +56 -0
  379. package/src/tokens/towns/mainnet/Towns.sol +220 -0
  380. package/src/tokens/towns/mainnet/libs/TokenInflationLib.sol +89 -0
  381. package/src/tokens/towns/multichain/Towns.sol +19 -0
  382. package/src/tokens/towns/multichain/wTowns.sol +18 -0
  383. package/src/utils/Airdrop.sol +156 -0
  384. package/src/utils/airdrop/merkle/IMerkleAirdrop.sol +55 -0
  385. package/src/utils/airdrop/merkle/MerkleAirdrop.sol +118 -0
  386. package/src/utils/airdrop/merkle/MerkleAirdropStorage.sol +29 -0
  387. package/src/utils/interfaces/AggregatorV3Interface.sol +37 -0
  388. package/src/utils/interfaces/IMulticall.sol +10 -0
  389. package/src/utils/interfaces/IWETH.sol +10 -0
  390. package/src/utils/libraries/BasisPoints.sol +24 -0
  391. package/src/utils/libraries/Create2Utils.sol +74 -0
  392. package/src/utils/libraries/CurrencyTransfer.sol +99 -0
  393. package/src/utils/libraries/CustomRevert.sol +49 -0
  394. package/src/utils/libraries/Factory.sol +66 -0
  395. package/src/utils/libraries/StringSet.sol +190 -0
  396. package/src/utils/libraries/Validator.sol +31 -0
@@ -0,0 +1,24 @@
1
+ // SPDX-License-Identifier: MIT
2
+ pragma solidity ^0.8.23;
3
+
4
+ // interfaces
5
+
6
+ // libraries
7
+
8
+ // contracts
9
+
10
+ interface ISCL_EIP6565 {
11
+ function Verify(
12
+ string memory m,
13
+ uint256 r,
14
+ uint256 s,
15
+ uint256[5] memory extKpub
16
+ ) external returns (bool flag);
17
+
18
+ function Verify_LE(
19
+ string memory m,
20
+ uint256 r,
21
+ uint256 s,
22
+ uint256[5] memory extKpub
23
+ ) external returns (bool flag);
24
+ }
@@ -0,0 +1,161 @@
1
+ // SPDX-License-Identifier: MIT
2
+ pragma solidity ^0.8.23;
3
+
4
+ // libraries
5
+ import {LibBit} from "solady/utils/LibBit.sol";
6
+ import {LibString} from "solady/utils/LibString.sol";
7
+
8
+ /**
9
+ * @dev Utility library for Solana address and public key operations
10
+ */
11
+ library SolanaUtils {
12
+ /// @notice Character set for Base58 encoding
13
+ bytes internal constant ALPHABET = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
14
+
15
+ /// @notice Lookup table for the first 32 characters of the Base58 alphabet
16
+ uint256 internal constant ALPHABET0 =
17
+ 0x31323334353637383941424344454647484a4b4c4d4e50515253545556575859;
18
+ /// @notice Lookup table for the last 26 characters of the Base58 alphabet
19
+ uint256 internal constant ALPHABET1 =
20
+ 0x5a6162636465666768696a6b6d6e6f707172737475767778797a000000000000;
21
+ /// @notice XOR mask for the Base58 alphabet to handle both halves
22
+ uint256 internal constant XOR_ALPHABET =
23
+ 0x31323334353637383941424344454647484a4b4c4d4e50515253545556575859 ^
24
+ 0x5a6162636465666768696a6b6d6e6f707172737475767778797a000000000000;
25
+
26
+ /// @notice Precomputed bitmask for Base58 allowed characters
27
+ uint256 internal constant BASE58_MAP = 0x07ffeffe07ff7dfe03fe000000000000;
28
+
29
+ /**
30
+ * @dev Get the compressed public key from an extended public key array
31
+ * @param pubkey The extended public key array (5 elements)
32
+ * @return The compressed public key as bytes32
33
+ */
34
+ function getCompressedPublicKey(uint256[5] memory pubkey) internal pure returns (bytes32) {
35
+ return bytes32(pubkey[4]);
36
+ }
37
+
38
+ /**
39
+ * @dev Convert bytes32 to a Base58 encoded string
40
+ * @param data The bytes32 data to encode
41
+ * @return finalResult The Base58 encoded string
42
+ */
43
+ function toBase58String(bytes32 data) internal pure returns (string memory finalResult) {
44
+ // Count leading zeros using Solady's LibBit.clz
45
+ uint256 value = uint256(data);
46
+ uint256 zeros = LibBit.clz(value) >> 3; // Divide by 8 to convert bits to bytes
47
+
48
+ // Calculate the maximum possible length of the result
49
+ uint8 resultSize = 44; // Max size of a base58 encoded 32 byte value
50
+
51
+ // Perform base58 encoding
52
+ assembly ("memory-safe") {
53
+ let result := mload(0x40)
54
+ mstore(result, resultSize)
55
+ mstore(0x40, add(result, 0x60))
56
+ // pointer to the last byte of the result, 0x4c = 32 + 44
57
+ let end := add(result, 0x4c)
58
+ let ptr := end
59
+ // encode from the end of the result array
60
+ for {} 1 {} {
61
+ if iszero(value) {
62
+ break
63
+ }
64
+ let remainder := mod(value, 58)
65
+ value := div(value, 58)
66
+ // equivalent: table = remainder < 32 ? ALPHABET0 : ALPHABET1
67
+ let table := xor(ALPHABET1, mul(lt(remainder, 32), XOR_ALPHABET))
68
+ ptr := sub(ptr, 1)
69
+ mstore8(ptr, byte(and(remainder, 0x1f), table))
70
+ }
71
+ // Add leading '1's for each leading zero byte
72
+ mstore(
73
+ sub(ptr, 0x20),
74
+ 0x3131313131313131313131313131313131313131313131313131313131313131
75
+ )
76
+ // starting offset of the result
77
+ ptr := sub(ptr, zeros)
78
+ // Create the final string with the correct length
79
+ finalResult := sub(ptr, 0x20)
80
+ mstore(finalResult, sub(end, ptr))
81
+ }
82
+ }
83
+
84
+ /**
85
+ * @dev Get the Solana address as a string from the extended public key
86
+ * @param pubkey The extended public key array (5 elements)
87
+ * @return The Base58 encoded Solana address string
88
+ */
89
+ function getCompressedPublicKeyAsString(
90
+ uint256[5] memory pubkey
91
+ ) internal pure returns (string memory) {
92
+ bytes32 compressedKey = getCompressedPublicKey(pubkey);
93
+ return toBase58String(compressedKey);
94
+ }
95
+
96
+ /**
97
+ * @dev Get Solana address string directly from a compressed public key
98
+ * @param compressedPubkey The compressed public key (typically extPubKey[4])
99
+ * @return The Base58 encoded Solana address
100
+ */
101
+ function getSolanaAddressFromCompressedKey(
102
+ uint256 compressedPubkey
103
+ ) internal pure returns (string memory) {
104
+ return toBase58String(bytes32(compressedPubkey));
105
+ }
106
+
107
+ /**
108
+ * @dev Safely extracts the Solana address from a fixed-size extPubKey array
109
+ * @param extPubKey The extended public key fixed array
110
+ * @return The Base58 encoded Solana address string
111
+ */
112
+ function getSolanaAddressFromFixedExtPubKey(
113
+ uint256[5] memory extPubKey
114
+ ) internal pure returns (string memory) {
115
+ return toBase58String(bytes32(extPubKey[4]));
116
+ }
117
+
118
+ /**
119
+ * @dev Validates if a string matches the Solana address derived from the given public key
120
+ * @param solanaAddress The address string to validate
121
+ * @param extPubKey The extended public key array
122
+ * @return True if the address matches the derived address from the public key
123
+ */
124
+ function isValidSolanaAddress(
125
+ string memory solanaAddress,
126
+ uint256[5] memory extPubKey
127
+ ) internal pure returns (bool) {
128
+ return LibString.eq(solanaAddress, getSolanaAddressFromFixedExtPubKey(extPubKey));
129
+ }
130
+
131
+ /**
132
+ * @dev Validates if a string is a valid Solana address (basic validation only)
133
+ * @param solanaAddress The address string to validate
134
+ * @return True if the address has valid format, false otherwise
135
+ */
136
+ function isValidSolanaAddress(string memory solanaAddress) internal pure returns (bool) {
137
+ uint256 len = bytes(solanaAddress).length;
138
+
139
+ // Solana addresses are between 32-44 characters
140
+ if (len < 32 || len > 44) {
141
+ return false;
142
+ }
143
+
144
+ bool isValid = true;
145
+ assembly ("memory-safe") {
146
+ let ptr := add(solanaAddress, 0x20)
147
+ let end := add(ptr, len)
148
+ for {} lt(ptr, end) {} {
149
+ let char := byte(0, mload(ptr))
150
+ // Check if the character is valid using the bitmask
151
+ // If the bit at position 'char' is not set in the map, the character is invalid
152
+ if iszero(and(shr(char, BASE58_MAP), 1)) {
153
+ isValid := false
154
+ break
155
+ }
156
+ ptr := add(ptr, 1)
157
+ }
158
+ }
159
+ return isValid;
160
+ }
161
+ }
@@ -0,0 +1,62 @@
1
+ // SPDX-License-Identifier: MIT
2
+ pragma solidity ^0.8.23;
3
+
4
+ // interfaces
5
+
6
+ // libraries
7
+
8
+ import {EnumerableSet} from "@openzeppelin/contracts/utils/structs/EnumerableSet.sol";
9
+ // contracts
10
+
11
+ library WalletLib {
12
+ using EnumerableSet for EnumerableSet.Bytes32Set;
13
+
14
+ /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
15
+ /* STORAGE */
16
+ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
17
+
18
+ enum VirtualMachineType {
19
+ EVM, // Ethereum Virtual Machine (Ethereum, BSC, Polygon, etc.)
20
+ SVM, // Solana Virtual Machine
21
+ MOVE, // Move Virtual Machine (Aptos, Sui)
22
+ CVM, // Cosmos Virtual Machine
23
+ WASM, // WebAssembly VM (Polkadot, NEAR)
24
+ AVM, // Avalanche Virtual Machine
25
+ UNKNOWN // For future compatibility
26
+ }
27
+
28
+ struct Wallet {
29
+ string addr; // Base58/Bech32/etc. encoded address
30
+ VirtualMachineType vmType; // Type of VM this wallet belongs to
31
+ }
32
+
33
+ struct RootWallet {
34
+ EnumerableSet.Bytes32Set walletHashes;
35
+ address defaultWallet;
36
+ mapping(bytes32 => Wallet) walletByHash;
37
+ }
38
+
39
+ struct Layout {
40
+ // mapping RootKeys to Ethereum Wallets is a 1 to many relationship, a root key can have many wallets
41
+ mapping(address => EnumerableSet.AddressSet) walletsByRootKey;
42
+ // mapping Ethereum Wallets to RootKey is a 1 to 1 relationship, a wallet can only be linked to 1 root key
43
+ mapping(address => address) rootKeyByWallet;
44
+ // mapping of wallet link external dependencies
45
+ mapping(bytes32 => address) dependencies;
46
+ // mapping of root key to root wallet
47
+ mapping(address => RootWallet) rootWalletByRootKey;
48
+ // mapping of root key hash to root key
49
+ mapping(bytes32 => address) rootKeyByHash;
50
+ }
51
+
52
+ // keccak256(abi.encode(uint256(keccak256("river.wallet.link.storage")) - 1)) & ~bytes32(uint256(0xff))
53
+ bytes32 constant STORAGE_SLOT =
54
+ 0x19511ce7944c192b1007be99b82019218d1decfc513f05239612743360a0dc00;
55
+
56
+ function layout() internal pure returns (Layout storage s) {
57
+ bytes32 slot = STORAGE_SLOT;
58
+ assembly {
59
+ s.slot := slot
60
+ }
61
+ }
62
+ }
@@ -0,0 +1,117 @@
1
+ // SPDX-License-Identifier: MIT
2
+ pragma solidity ^0.8.23;
3
+
4
+ // libraries
5
+ import {Setting} from "src/river/registry/libraries/RegistryStorage.sol";
6
+
7
+ interface IRiverConfigBase {
8
+ /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
9
+ /* EVENTS */
10
+ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
11
+
12
+ /**
13
+ * @notice Emitted when a setting is changed
14
+ * @dev if deleted is true and block is max value of uint64, the setting is deleted on all
15
+ * blocks
16
+ * @param key The setting key that is changed
17
+ * @param block The block number on which the setting becomes active
18
+ * @param value The new setting value
19
+ * @param deleted True if the setting is deleted (value is empty in this case)
20
+ */
21
+ event ConfigurationChanged(bytes32 key, uint64 block, bytes value, bool deleted);
22
+
23
+ /**
24
+ * @notice Emitted when a configuration manager is added
25
+ * @param manager The configuration manager address
26
+ */
27
+ event ConfigurationManagerAdded(address indexed manager);
28
+
29
+ /**
30
+ * @notice Emitted when a configuration manager is removed
31
+ * @param manager The configuration manager address
32
+ */
33
+ event ConfigurationManagerRemoved(address indexed manager);
34
+ }
35
+
36
+ /**
37
+ * @title IRiverConfig
38
+ * @notice The interface for the RiverConfig facet
39
+ */
40
+ interface IRiverConfig is IRiverConfigBase {
41
+ /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
42
+ /* ADMIN FUNCTIONS */
43
+ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
44
+
45
+ /**
46
+ * @notice Add a configuration manager
47
+ * @param manager The address to add
48
+ */
49
+ function approveConfigurationManager(address manager) external;
50
+
51
+ /**
52
+ * @notice Remove a configuration manager
53
+ * @param manager The address to remove
54
+ */
55
+ function removeConfigurationManager(address manager) external;
56
+
57
+ /**
58
+ * @notice Set a bytes setting for the given key
59
+ * @dev Emits ConfigurationChanged event
60
+ * @param key The keccak256 hash of the setting name
61
+ * @param blockNumber The block number on which the setting becomes active, can't be max value
62
+ * of
63
+ * uint64
64
+ * @param value The setting value (value must be its ABI representation), can't be empty
65
+ */
66
+ function setConfiguration(bytes32 key, uint64 blockNumber, bytes calldata value) external;
67
+
68
+ /**
69
+ * @notice Deletes the setting for the given key on all blocks
70
+ * @dev Emits ConfigurationChanged event with deleted flag set to true and block number set to
71
+ * max
72
+ * value of uint64
73
+ * @param key The setting key
74
+ */
75
+ function deleteConfiguration(bytes32 key) external;
76
+
77
+ /**
78
+ * @notice Deletes the setting for the given key at the given block
79
+ * @dev Emits ConfigurationChanged event with deleted flag set to true
80
+ * @param key The setting key
81
+ * @param blockNumber The block number on which the setting becomes active
82
+ */
83
+ function deleteConfigurationOnBlock(bytes32 key, uint64 blockNumber) external;
84
+
85
+ /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
86
+ /* GETTERS */
87
+ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
88
+
89
+ /**
90
+ * @notice Indication if one or more settings exists for the given key
91
+ * @param key The setting key
92
+ * @return True if the setting exists
93
+ */
94
+ function configurationExists(bytes32 key) external view returns (bool);
95
+
96
+ /**
97
+ * @notice Get settings for the given key
98
+ * @dev Note that the returned list isn't ordered by block number
99
+ * @param key The setting key
100
+ * @return The setting value
101
+ */
102
+ function getConfiguration(bytes32 key) external view returns (Setting[] memory);
103
+
104
+ /**
105
+ * @notice Get all settings store in the registry
106
+ * @dev Note that the returned list is ordered on key but NOT on block number
107
+ * @return List will all stored settings
108
+ */
109
+ function getAllConfiguration() external view returns (Setting[] memory);
110
+
111
+ /**
112
+ * @notice Check if the given address is a configuration manager
113
+ * @param manager The address to check
114
+ * @return True if the address is a configuration manager
115
+ */
116
+ function isConfigurationManager(address manager) external view returns (bool);
117
+ }
@@ -0,0 +1,174 @@
1
+ // SPDX-License-Identifier: MIT
2
+ pragma solidity ^0.8.23;
3
+
4
+ // interfaces
5
+ import {IRiverConfig} from "./IRiverConfig.sol";
6
+ import {Setting} from "src/river/registry/libraries/RegistryStorage.sol";
7
+
8
+ // libraries
9
+ import {EnumerableSet} from "@openzeppelin/contracts/utils/structs/EnumerableSet.sol";
10
+
11
+ import {RiverRegistryErrors} from "src/river/registry/libraries/RegistryErrors.sol";
12
+ import {CustomRevert} from "src/utils/libraries/CustomRevert.sol";
13
+
14
+ // contracts
15
+ import {Facet} from "@towns-protocol/diamond/src/facets/Facet.sol";
16
+ import {OwnableBase} from "@towns-protocol/diamond/src/facets/ownable/OwnableBase.sol";
17
+ import {RegistryModifiers} from "src/river/registry/libraries/RegistryStorage.sol";
18
+
19
+ contract RiverConfig is IRiverConfig, RegistryModifiers, OwnableBase, Facet {
20
+ using EnumerableSet for EnumerableSet.AddressSet;
21
+ using EnumerableSet for EnumerableSet.Bytes32Set;
22
+ using CustomRevert for string;
23
+
24
+ /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
25
+ /* ADMIN FUNCTIONS */
26
+ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
27
+
28
+ function __RiverConfig_init(address[] calldata configManagers) external onlyInitializing {
29
+ for (uint256 i; i < configManagers.length; ++i) {
30
+ _approveConfigurationManager(configManagers[i]);
31
+ }
32
+ }
33
+
34
+ /// @inheritdoc IRiverConfig
35
+ function approveConfigurationManager(address manager) external onlyOwner {
36
+ _approveConfigurationManager(manager);
37
+ }
38
+
39
+ /// @inheritdoc IRiverConfig
40
+ function removeConfigurationManager(address manager) external onlyOwner {
41
+ if (manager == address(0)) RiverRegistryErrors.BAD_ARG.revertWith();
42
+
43
+ if (!ds.configurationManagers.remove(manager)) {
44
+ RiverRegistryErrors.NOT_FOUND.revertWith();
45
+ }
46
+
47
+ emit ConfigurationManagerRemoved(manager);
48
+ }
49
+
50
+ /// @inheritdoc IRiverConfig
51
+ function setConfiguration(
52
+ bytes32 key,
53
+ uint64 blockNumber,
54
+ bytes calldata value
55
+ ) external onlyConfigurationManager(msg.sender) {
56
+ if (blockNumber == type(uint64).max) {
57
+ RiverRegistryErrors.BAD_ARG.revertWith();
58
+ }
59
+ if (value.length == 0) RiverRegistryErrors.BAD_ARG.revertWith();
60
+
61
+ if (!ds.configurationKeys.contains(key)) {
62
+ ds.configurationKeys.add(key);
63
+ }
64
+
65
+ // if there is already a setting on the given block override it
66
+ Setting[] storage configs = ds.configuration[key];
67
+ uint256 configurationLen = configs.length;
68
+ for (uint256 i; i < configurationLen; ++i) {
69
+ Setting storage config = configs[i];
70
+ if (config.blockNumber == blockNumber) {
71
+ config.value = value;
72
+ emit ConfigurationChanged(key, blockNumber, value, false);
73
+ return;
74
+ }
75
+ }
76
+
77
+ configs.push(Setting(key, blockNumber, value));
78
+ emit ConfigurationChanged(key, blockNumber, value, false);
79
+ }
80
+
81
+ /// @inheritdoc IRiverConfig
82
+ function deleteConfiguration(
83
+ bytes32 key
84
+ ) external onlyConfigurationManager(msg.sender) configKeyExists(key) {
85
+ delete ds.configuration[key];
86
+
87
+ ds.configurationKeys.remove(key);
88
+
89
+ emit ConfigurationChanged(key, type(uint64).max, "", true);
90
+ }
91
+
92
+ /// @inheritdoc IRiverConfig
93
+ function deleteConfigurationOnBlock(
94
+ bytes32 key,
95
+ uint64 blockNumber
96
+ ) external onlyConfigurationManager(msg.sender) {
97
+ bool found = false;
98
+ Setting[] storage configs = ds.configuration[key];
99
+ uint256 configurationLen = configs.length;
100
+ for (uint256 i; i < configurationLen; ++i) {
101
+ if (configs[i].blockNumber == blockNumber) {
102
+ configs[i] = configs[configurationLen - 1];
103
+ configs.pop();
104
+ found = true;
105
+ break;
106
+ }
107
+ }
108
+
109
+ if (!found) RiverRegistryErrors.NOT_FOUND.revertWith();
110
+
111
+ emit ConfigurationChanged(key, blockNumber, "", true);
112
+ }
113
+
114
+ /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
115
+ /* GETTERS */
116
+ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
117
+
118
+ /// @inheritdoc IRiverConfig
119
+ function configurationExists(bytes32 key) external view returns (bool) {
120
+ return ds.configurationKeys.contains(key);
121
+ }
122
+
123
+ /// @inheritdoc IRiverConfig
124
+ function getConfiguration(
125
+ bytes32 key
126
+ ) external view configKeyExists(key) returns (Setting[] memory) {
127
+ return ds.configuration[key];
128
+ }
129
+
130
+ /// @inheritdoc IRiverConfig
131
+ function getAllConfiguration() external view returns (Setting[] memory settings) {
132
+ uint256 settingCount = 0;
133
+
134
+ uint256 configurationLen = ds.configurationKeys.length();
135
+ for (uint256 i; i < configurationLen; ++i) {
136
+ bytes32 key = ds.configurationKeys.at(i);
137
+ settingCount += ds.configuration[key].length;
138
+ }
139
+
140
+ settings = new Setting[](settingCount);
141
+
142
+ uint256 keysLen = ds.configurationKeys.length();
143
+ uint256 c = 0;
144
+ for (uint256 i; i < keysLen; ++i) {
145
+ bytes32 key = ds.configurationKeys.at(i);
146
+ Setting[] storage configs = ds.configuration[key];
147
+ uint256 configsLen = configs.length;
148
+ for (uint256 j; j < configsLen; ++j) {
149
+ settings[c++] = configs[j];
150
+ }
151
+ }
152
+ }
153
+
154
+ /// @inheritdoc IRiverConfig
155
+ function isConfigurationManager(address manager) external view returns (bool) {
156
+ return ds.configurationManagers.contains(manager);
157
+ }
158
+
159
+ /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
160
+ /* INTERNAL */
161
+ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
162
+
163
+ /// @dev Internal function to approve a configuration manager, doesn't do any
164
+ /// validation
165
+ function _approveConfigurationManager(address manager) internal {
166
+ if (manager == address(0)) RiverRegistryErrors.BAD_ARG.revertWith();
167
+
168
+ if (!ds.configurationManagers.add(manager)) {
169
+ RiverRegistryErrors.ALREADY_EXISTS.revertWith();
170
+ }
171
+
172
+ emit ConfigurationManagerAdded(manager);
173
+ }
174
+ }
@@ -0,0 +1,69 @@
1
+ // SPDX-License-Identifier: MIT
2
+ pragma solidity ^0.8.23;
3
+
4
+ import {Node, NodeStatus} from "src/river/registry/libraries/RegistryStorage.sol";
5
+
6
+ // libraries
7
+
8
+ // contracts
9
+ interface INodeRegistryBase {
10
+ // =============================================================
11
+ // Events
12
+ // =============================================================
13
+ event NodeAdded(
14
+ address indexed nodeAddress,
15
+ address indexed operator,
16
+ string url,
17
+ NodeStatus status
18
+ );
19
+ event NodeStatusUpdated(address indexed nodeAddress, NodeStatus status);
20
+ event NodeUrlUpdated(address indexed nodeAddress, string url);
21
+ event NodeRemoved(address indexed nodeAddress);
22
+ }
23
+
24
+ interface INodeRegistry is INodeRegistryBase {
25
+ // =============================================================
26
+ // Nodes
27
+ // =============================================================
28
+
29
+ function isNode(address nodeAddress) external view returns (bool);
30
+ function registerNode(address nodeAddress, string memory url, NodeStatus status) external;
31
+
32
+ function removeNode(address nodeAddress) external;
33
+
34
+ function updateNodeStatus(address nodeAddress, NodeStatus status) external;
35
+
36
+ function updateNodeUrl(address nodeAddress, string memory url) external;
37
+
38
+ function getNode(address nodeAddress) external view returns (Node memory);
39
+
40
+ function getNodeCount() external view returns (uint256);
41
+
42
+ /**
43
+ * @notice Return array containing all node addresses
44
+ * @dev WARNING: This operation will copy the entire storage to memory, which can be quite
45
+ * expensive. This is designed
46
+ * to mostly be used by view accessors that are queried without any gas fees. Developers should
47
+ * keep in mind that
48
+ * this function has an unbounded cost, and using it as part of a state-changing function may
49
+ * render the function
50
+ * uncallable if the map grows to a point where copying to memory consumes too much gas to fit
51
+ * in
52
+ * a block.
53
+ */
54
+ function getAllNodeAddresses() external view returns (address[] memory);
55
+
56
+ /**
57
+ * @notice Return array containing all nodes
58
+ * @dev WARNING: This operation will copy the entire storage to memory, which can be quite
59
+ * expensive. This is designed
60
+ * to mostly be used by view accessors that are queried without any gas fees. Developers should
61
+ * keep in mind that
62
+ * this function has an unbounded cost, and using it as part of a state-changing function may
63
+ * render the function
64
+ * uncallable if the map grows to a point where copying to memory consumes too much gas to fit
65
+ * in
66
+ * a block.
67
+ */
68
+ function getAllNodes() external view returns (Node[] memory);
69
+ }