@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,36 @@
1
+ // SPDX-License-Identifier: MIT
2
+ pragma solidity ^0.8.23;
3
+
4
+ // This contract is used to authorize claimers to claim rewards on the authorizer's behalf
5
+ interface IAuthorizedClaimersBase {
6
+ // Errors
7
+ error AuthorizedClaimers_ClaimerAlreadyAuthorized();
8
+ error AuthorizedClaimers_InvalidSignature();
9
+ error AuthorizedClaimers_ExpiredSignature();
10
+
11
+ // Events
12
+ event AuthorizedClaimerChanged(address indexed authorizer, address indexed claimer);
13
+ event AuthorizedClaimerRemoved(address indexed authorizer);
14
+ }
15
+
16
+ interface IAuthorizedClaimers is IAuthorizedClaimersBase {
17
+ // Authorize a claimer to claim rewards on the callers behalf
18
+ function authorizeClaimer(address claimer) external;
19
+
20
+ // Authorize a claimer to claim rewards on the authorizer's behalf
21
+ function authorizeClaimerBySig(
22
+ address owner,
23
+ address claimer,
24
+ uint256 nonce,
25
+ uint256 expiry,
26
+ uint8 v,
27
+ bytes32 r,
28
+ bytes32 s
29
+ ) external;
30
+
31
+ // Get the authorized claimer for the authorizer
32
+ function getAuthorizedClaimer(address authorizer) external view returns (address);
33
+
34
+ // Remove the authorized claimer for the caller
35
+ function removeAuthorizedClaimer() external;
36
+ }
@@ -0,0 +1,86 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ pragma solidity ^0.8.23;
3
+
4
+ // interfaces
5
+
6
+ import {ICrossDomainMessenger} from "src/base/registry/facets/mainnet/ICrossDomainMessenger.sol";
7
+ import {IMainnetDelegation, IMainnetDelegationBase} from "src/base/registry/facets/mainnet/IMainnetDelegation.sol";
8
+ import {IVotesEnumerable} from "src/diamond/facets/governance/votes/enumerable/IVotesEnumerable.sol";
9
+ import {IAuthorizedClaimers} from "src/tokens/mainnet/claimer/IAuthorizedClaimers.sol";
10
+
11
+ // libraries
12
+ import {SafeTransferLib} from "solady/utils/SafeTransferLib.sol";
13
+
14
+ // contracts
15
+
16
+ contract ProxyBatchDelegation is IMainnetDelegationBase {
17
+ using SafeTransferLib for address;
18
+
19
+ address public immutable MESSENGER;
20
+ address public immutable BASE_REGISTRY;
21
+
22
+ address public immutable TOWNS;
23
+ address public immutable CLAIMER_MANAGER;
24
+
25
+ constructor(address _towns, address _claimers, address _messenger, address _target) {
26
+ TOWNS = _towns;
27
+ CLAIMER_MANAGER = _claimers;
28
+ MESSENGER = _messenger;
29
+ BASE_REGISTRY = _target;
30
+ }
31
+
32
+ function relayDelegationDigest(uint32 minGasLimit) external {
33
+ DelegationMsg[] memory msgs = _getDelegationMsgs();
34
+ bytes32 digest = _digest(msgs);
35
+
36
+ ICrossDomainMessenger(MESSENGER).sendMessage(
37
+ BASE_REGISTRY,
38
+ abi.encodeCall(IMainnetDelegation.setDelegationDigest, digest),
39
+ minGasLimit
40
+ );
41
+ }
42
+
43
+ function getEncodedMsgs() external view returns (bytes memory encodedMsgs) {
44
+ DelegationMsg[] memory msgs = _getDelegationMsgs();
45
+ encodedMsgs = abi.encode(msgs);
46
+ }
47
+
48
+ /// @dev Generates the digest of the delegation messages
49
+ function _digest(DelegationMsg[] memory msgs) internal pure returns (bytes32 digest) {
50
+ digest = keccak256(abi.encode(keccak256(abi.encode(msgs))));
51
+ }
52
+
53
+ /// @dev Gathers the delegation messages
54
+ function _getDelegationMsgs() internal view returns (DelegationMsg[] memory msgs) {
55
+ address[] memory allDelegators = IVotesEnumerable(TOWNS).getDelegators();
56
+ uint256 length = allDelegators.length;
57
+ msgs = new DelegationMsg[](length);
58
+
59
+ for (uint256 i; i < length; ++i) {
60
+ address delegator = allDelegators[i];
61
+ msgs[i].delegator = delegator;
62
+ msgs[i].delegatee = _delegates(TOWNS, delegator);
63
+ msgs[i].quantity = TOWNS.balanceOf(delegator);
64
+ msgs[i].claimer = IAuthorizedClaimers(CLAIMER_MANAGER).getAuthorizedClaimer(delegator);
65
+ }
66
+ }
67
+
68
+ /// @dev Returns the delegate that `account` has chosen.
69
+ /// Returns zero if the `token` does not exist.
70
+ function _delegates(address token, address account) internal view returns (address delegatee) {
71
+ /// @solidity memory-safe-assembly
72
+ assembly {
73
+ mstore(0x14, account) // Store the `account` argument.
74
+ mstore(0x00, 0x587cde1e000000000000000000000000) // `delegates(address)`.
75
+ delegatee := mul(
76
+ // The arguments of `mul` are evaluated from right to left.
77
+ mload(0x20),
78
+ and(
79
+ // The arguments of `and` are evaluated from right to left.
80
+ gt(returndatasize(), 0x1f), // At least 32 bytes returned.
81
+ staticcall(gas(), token, 0x10, 0x24, 0x20, 0x20)
82
+ )
83
+ )
84
+ }
85
+ }
86
+ }
@@ -0,0 +1,35 @@
1
+ // SPDX-License-Identifier: MIT
2
+ pragma solidity ^0.8.23;
3
+
4
+ // interfaces
5
+ import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
6
+
7
+ // libraries
8
+
9
+ // contracts
10
+
11
+ interface ITokenMigrationBase {
12
+ // Errors
13
+ error TokenMigration__InvalidBalance();
14
+ error TokenMigration__InvalidAllowance();
15
+ error TokenMigration__NotEnoughTokenBalance();
16
+ error TokenMigration__InvalidTokens();
17
+
18
+ // Events
19
+ event TokensMigrated(address indexed account, uint256 amount);
20
+ event EmergencyWithdraw(address indexed token, address indexed to, uint256 amount);
21
+ }
22
+
23
+ interface ITokenMigration is ITokenMigrationBase {
24
+ /// @notice Migrates tokens from old token to new token for the specified account
25
+ /// @param account The address of the account to migrate tokens for
26
+ /// @dev The account must have a non-zero balance of old tokens and have approved this contract
27
+ function migrate(address account) external;
28
+
29
+ /// @notice Allows the owner to withdraw tokens from the contract
30
+ /// @dev Only callable by contract owner
31
+ function emergencyWithdraw(IERC20 token, address to) external;
32
+
33
+ /// @notice Returns the token pair
34
+ function tokens() external view returns (IERC20 oldToken, IERC20 newToken);
35
+ }
@@ -0,0 +1,86 @@
1
+ // SPDX-License-Identifier: MIT
2
+ pragma solidity ^0.8.23;
3
+
4
+ // interfaces
5
+ import {ITokenMigration} from "./ITokenMigration.sol";
6
+ import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
7
+
8
+ // libraries
9
+ import {TokenMigrationStorage} from "./TokenMigrationStorage.sol";
10
+ import {Validator} from "../../utils/libraries/Validator.sol";
11
+ import {CustomRevert} from "src/utils/libraries/CustomRevert.sol";
12
+ import {SafeTransferLib} from "solady/utils/SafeTransferLib.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 {PausableBase} from "@towns-protocol/diamond/src/facets/pausable/PausableBase.sol";
18
+
19
+ contract TokenMigrationFacet is OwnableBase, PausableBase, Facet, ITokenMigration {
20
+ using SafeTransferLib for address;
21
+
22
+ function __TokenMigrationFacet_init(
23
+ IERC20 oldToken,
24
+ IERC20 newToken
25
+ ) external onlyInitializing {
26
+ _validateTokens(oldToken, newToken);
27
+
28
+ TokenMigrationStorage.Layout storage ds = TokenMigrationStorage.layout();
29
+ (ds.oldToken, ds.newToken) = (oldToken, newToken);
30
+ _pause();
31
+ }
32
+
33
+ /// @inheritdoc ITokenMigration
34
+ function migrate(address account) external whenNotPaused {
35
+ Validator.checkAddress(account);
36
+
37
+ TokenMigrationStorage.Layout storage ds = TokenMigrationStorage.layout();
38
+
39
+ (IERC20 oldToken, IERC20 newToken) = (ds.oldToken, ds.newToken);
40
+
41
+ uint256 currentBalance = oldToken.balanceOf(account);
42
+ if (currentBalance == 0) {
43
+ CustomRevert.revertWith(TokenMigration__InvalidBalance.selector);
44
+ }
45
+
46
+ if (oldToken.allowance(account, address(this)) < currentBalance) {
47
+ CustomRevert.revertWith(TokenMigration__InvalidAllowance.selector);
48
+ }
49
+
50
+ // check that contract has enough balance of new token
51
+ uint256 newTokenBalance = newToken.balanceOf(address(this));
52
+ if (newTokenBalance < currentBalance) {
53
+ CustomRevert.revertWith(TokenMigration__NotEnoughTokenBalance.selector);
54
+ }
55
+
56
+ // Transfer old tokens from user to this contract
57
+ address(oldToken).safeTransferFrom(account, address(this), currentBalance);
58
+
59
+ // Transfer new tokens to user
60
+ address(newToken).safeTransfer(account, currentBalance);
61
+
62
+ emit TokensMigrated(account, currentBalance);
63
+ }
64
+
65
+ /// @inheritdoc ITokenMigration
66
+ function emergencyWithdraw(IERC20 token, address to) external onlyOwner whenPaused {
67
+ uint256 balance = token.balanceOf(address(this));
68
+ address(token).safeTransfer(to, balance);
69
+ emit EmergencyWithdraw(address(token), to, balance);
70
+ }
71
+
72
+ /// @inheritdoc ITokenMigration
73
+ function tokens() external view returns (IERC20 oldToken, IERC20 newToken) {
74
+ return (TokenMigrationStorage.layout().oldToken, TokenMigrationStorage.layout().newToken);
75
+ }
76
+
77
+ // =============================================================
78
+ // Internal
79
+ // =============================================================
80
+
81
+ function _validateTokens(IERC20 oldToken, IERC20 newToken) internal pure {
82
+ if (address(oldToken) == address(0) || address(newToken) == address(0)) {
83
+ CustomRevert.revertWith(TokenMigration__InvalidTokens.selector);
84
+ }
85
+ }
86
+ }
@@ -0,0 +1,27 @@
1
+ // SPDX-License-Identifier: MIT
2
+ pragma solidity ^0.8.23;
3
+
4
+ // interfaces
5
+ import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
6
+
7
+ // libraries
8
+
9
+ // contracts
10
+
11
+ library TokenMigrationStorage {
12
+ // keccak256(abi.encode(uint256(keccak256("token.migration.storage")) - 1)) &
13
+ // ~bytes32(uint256(0xff))
14
+ bytes32 public constant STORAGE_SLOT =
15
+ 0x70042d58ab6ffbb7e110198cb4fbcbe6957a43f69f02f904ebed551d03013400;
16
+
17
+ struct Layout {
18
+ IERC20 oldToken;
19
+ IERC20 newToken;
20
+ }
21
+
22
+ function layout() internal pure returns (Layout storage l) {
23
+ assembly {
24
+ l.slot := STORAGE_SLOT
25
+ }
26
+ }
27
+ }
@@ -0,0 +1,30 @@
1
+ // SPDX-License-Identifier: MIT
2
+ pragma solidity ^0.8.0;
3
+
4
+ import {IERC165} from "@openzeppelin/contracts/interfaces/IERC165.sol";
5
+
6
+ /// @title IERC7802
7
+ /// @notice Defines the interface for crosschain ERC20 transfers.
8
+ interface IERC7802 is IERC165 {
9
+ /// @notice Emitted when a crosschain transfer mints tokens.
10
+ /// @param to Address of the account tokens are being minted for.
11
+ /// @param amount Amount of tokens minted.
12
+ /// @param sender Address of the account that finalized the crosschain transfer.
13
+ event CrosschainMint(address indexed to, uint256 amount, address indexed sender);
14
+
15
+ /// @notice Emitted when a crosschain transfer burns tokens.
16
+ /// @param from Address of the account tokens are being burned from.
17
+ /// @param amount Amount of tokens burned.
18
+ /// @param sender Address of the account that initiated the crosschain transfer.
19
+ event CrosschainBurn(address indexed from, uint256 amount, address indexed sender);
20
+
21
+ /// @notice Mint tokens through a crosschain transfer.
22
+ /// @param _to Address to mint tokens to.
23
+ /// @param _amount Amount of tokens to mint.
24
+ function crosschainMint(address _to, uint256 _amount) external;
25
+
26
+ /// @notice Burn tokens through a crosschain transfer.
27
+ /// @param _from Address to burn tokens from.
28
+ /// @param _amount Amount of tokens to burn.
29
+ function crosschainBurn(address _from, uint256 _amount) external;
30
+ }
@@ -0,0 +1,31 @@
1
+ // SPDX-License-Identifier: MIT
2
+ pragma solidity ^0.8.0;
3
+
4
+ import {IERC165} from "@openzeppelin/contracts/utils/introspection/IERC165.sol";
5
+
6
+ /// @title IOptimismMintableERC20
7
+ /// @notice This interface is available on the OptimismMintableERC20 contract.
8
+ /// We declare it as a separate interface so that it can be used in
9
+ /// custom implementations of OptimismMintableERC20.
10
+ interface IOptimismMintableERC20 is IERC165 {
11
+ function remoteToken() external view returns (address);
12
+
13
+ function bridge() external returns (address);
14
+
15
+ function mint(address _to, uint256 _amount) external;
16
+
17
+ function burn(address _from, uint256 _amount) external;
18
+ }
19
+
20
+ /// @custom:legacy
21
+ /// @title ILegacyMintableERC20
22
+ /// @notice This interface was available on the legacy L2StandardERC20 contract.
23
+ /// It remains available on the OptimismMintableERC20 contract for
24
+ /// backwards compatibility.
25
+ interface ILegacyMintableERC20 is IERC165 {
26
+ function l1Token() external view returns (address);
27
+
28
+ function mint(address _to, uint256 _amount) external;
29
+
30
+ function burn(address _from, uint256 _amount) external;
31
+ }
@@ -0,0 +1,13 @@
1
+ // SPDX-License-Identifier: MIT
2
+ pragma solidity ^0.8.0;
3
+
4
+ /// @title ISemver
5
+ /// @notice ISemver is a simple contract for ensuring that contracts are
6
+ /// versioned using semantic versioning.
7
+ interface ISemver {
8
+ /// @notice Getter for the semantic version of the contract. This is not
9
+ /// meant to be used onchain but instead meant to be used by offchain
10
+ /// tooling.
11
+ /// @return Semver contract version as a string.
12
+ function version() external view returns (string memory);
13
+ }
@@ -0,0 +1,283 @@
1
+ // SPDX-License-Identifier: MIT
2
+ pragma solidity ^0.8.23;
3
+
4
+ // interfaces
5
+
6
+ import {IVotes} from "@openzeppelin/contracts/governance/utils/IVotes.sol";
7
+ import {IERC6372} from "@openzeppelin/contracts/interfaces/IERC6372.sol";
8
+ import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
9
+ import {IERC20Metadata} from "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol";
10
+ import {IERC20Permit} from "@openzeppelin/contracts/token/ERC20/extensions/IERC20Permit.sol";
11
+ import {IERC165} from "@openzeppelin/contracts/utils/introspection/IERC165.sol";
12
+
13
+ import {IERC7802} from "src/tokens/towns/base/IERC7802.sol";
14
+ import {ILegacyMintableERC20, IOptimismMintableERC20} from "src/tokens/towns/base/IOptimismMintableERC20.sol";
15
+ import {ISemver} from "src/tokens/towns/base/ISemver.sol";
16
+
17
+ // libraries
18
+
19
+ import {TownsLib} from "./TownsLib.sol";
20
+ import {CustomRevert} from "src/utils/libraries/CustomRevert.sol";
21
+
22
+ // contracts
23
+ import {IntrospectionBase} from "@towns-protocol/diamond/src/facets/introspection/IntrospectionBase.sol";
24
+
25
+ import {LockBase} from "src/tokens/lock/LockBase.sol";
26
+ import {Ownable} from "solady/auth/Ownable.sol";
27
+ import {ERC20Votes} from "solady/tokens/ERC20Votes.sol";
28
+ import {Initializable} from "solady/utils/Initializable.sol";
29
+ import {UUPSUpgradeable} from "solady/utils/UUPSUpgradeable.sol";
30
+
31
+ contract Towns is
32
+ IOptimismMintableERC20,
33
+ IERC7802,
34
+ ISemver,
35
+ IntrospectionBase,
36
+ LockBase,
37
+ Initializable,
38
+ ERC20Votes,
39
+ UUPSUpgradeable,
40
+ Ownable
41
+ {
42
+ /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
43
+ /* Errors */
44
+ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
45
+
46
+ error DelegateeSameAsCurrent();
47
+ error TransferLockEnabled();
48
+
49
+ /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
50
+ /* Constants & Immutables */
51
+ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
52
+
53
+ /// @notice The name of the token
54
+ string internal constant NAME = "Towns";
55
+
56
+ /// @notice The symbol of the token
57
+ string internal constant SYMBOL = "TOWNS";
58
+
59
+ /// @notice The name hash of the token
60
+ bytes32 internal constant NAME_HASH = keccak256(bytes(NAME));
61
+
62
+ /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
63
+ /* Modifiers */
64
+ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
65
+
66
+ /// @notice A modifier that only allows the bridge to call
67
+ modifier onlyL2StandardBridge() {
68
+ if (msg.sender != TownsLib.L2_STANDARD_BRIDGE) {
69
+ CustomRevert.revertWith(Unauthorized.selector);
70
+ }
71
+ _;
72
+ }
73
+
74
+ /// @notice A modifier that only allows the super chain to call
75
+ modifier onlyL2SuperChainBridge() {
76
+ if (msg.sender != TownsLib.SUPERCHAIN_TOKEN_BRIDGE) {
77
+ CustomRevert.revertWith(Unauthorized.selector);
78
+ }
79
+ _;
80
+ }
81
+
82
+ /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
83
+ /* Initialization */
84
+ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
85
+
86
+ constructor() {
87
+ _disableInitializers();
88
+ }
89
+
90
+ function initialize(address _remoteToken, address _owner) external initializer {
91
+ // set the owner
92
+ _initializeOwner(_owner);
93
+
94
+ // set the remote token
95
+ TownsLib.initializeRemoteToken(_remoteToken);
96
+
97
+ // initialize the lock
98
+ __LockBase_init(30 days);
99
+
100
+ // add interface
101
+ _addInterface(type(IERC20).interfaceId);
102
+ _addInterface(type(IERC20Metadata).interfaceId);
103
+ _addInterface(type(IERC20Permit).interfaceId);
104
+ _addInterface(type(IERC6372).interfaceId);
105
+ _addInterface(type(IERC165).interfaceId);
106
+ _addInterface(type(IVotes).interfaceId);
107
+ _addInterface(type(IOptimismMintableERC20).interfaceId);
108
+ _addInterface(type(ILegacyMintableERC20).interfaceId);
109
+ _addInterface(type(ISemver).interfaceId);
110
+ _addInterface(type(IERC7802).interfaceId);
111
+ }
112
+
113
+ /// @notice Semantic version
114
+ /// @custom:semver 1.0.0-beta.12
115
+ function version() external view virtual returns (string memory) {
116
+ return "1.0.0-beta.12";
117
+ }
118
+
119
+ /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
120
+ /* Bridge */
121
+ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
122
+
123
+ /// @custom:legacy
124
+ /// @notice Legacy getter for the remote token. Use REMOTE_TOKEN going forward.
125
+ function l1Token() external view returns (address) {
126
+ return TownsLib.layout().remoteToken;
127
+ }
128
+
129
+ /// @custom:legacy
130
+ /// @notice Legacy getter for the bridge. Use BRIDGE going forward.
131
+ function l2Bridge() external pure returns (address) {
132
+ return TownsLib.L2_STANDARD_BRIDGE;
133
+ }
134
+
135
+ /// @custom:legacy
136
+ /// @notice Legacy getter for REMOTE_TOKEN
137
+ function remoteToken() external view returns (address) {
138
+ return TownsLib.layout().remoteToken;
139
+ }
140
+
141
+ /// @custom:legacy
142
+ /// @notice Legacy getter for L2_STANDARD_BRIDGE.
143
+ function bridge() external pure returns (address) {
144
+ return TownsLib.L2_STANDARD_BRIDGE;
145
+ }
146
+
147
+ /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
148
+ /* Super Chain */
149
+ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
150
+
151
+ /// @notice Allows the SuperchainTokenBridge to mint tokens.
152
+ /// @param _to Address to mint tokens to.
153
+ /// @param _amount Amount of tokens to mint.
154
+ function crosschainMint(address _to, uint256 _amount) external onlyL2SuperChainBridge {
155
+ _mint(_to, _amount);
156
+ emit CrosschainMint(_to, _amount, msg.sender);
157
+ }
158
+
159
+ /// @notice Allows the SuperchainTokenBridge to burn tokens.
160
+ /// @param _from Address to burn tokens from.
161
+ /// @param _amount Amount of tokens to burn.
162
+ function crosschainBurn(address _from, uint256 _amount) external onlyL2SuperChainBridge {
163
+ _burn(_from, _amount);
164
+ emit CrosschainBurn(_from, _amount, msg.sender);
165
+ }
166
+
167
+ /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
168
+ /* Introspection */
169
+ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
170
+
171
+ /// @inheritdoc IERC165
172
+ function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
173
+ return _supportsInterface(interfaceId);
174
+ }
175
+
176
+ /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
177
+ /* Lock */
178
+ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
179
+
180
+ function isLockActive(address account) external view virtual returns (bool) {
181
+ return _isLockActive(account);
182
+ }
183
+
184
+ function lockExpiration(address account) external view virtual returns (uint256) {
185
+ return _lockExpiration(account);
186
+ }
187
+
188
+ /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
189
+ /* Overrides */
190
+ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
191
+
192
+ function name() public pure override returns (string memory) {
193
+ return NAME;
194
+ }
195
+
196
+ function symbol() public pure override returns (string memory) {
197
+ return SYMBOL;
198
+ }
199
+
200
+ function decimals() public pure override returns (uint8) {
201
+ return 18;
202
+ }
203
+
204
+ /// @notice Allows the StandardBridge on this network to mint tokens.
205
+ /// @param to Address to mint tokens to.
206
+ /// @param amount Amount of tokens to mint.
207
+ function mint(
208
+ address to,
209
+ uint256 amount
210
+ ) external override(IOptimismMintableERC20) onlyL2StandardBridge {
211
+ _mint(to, amount);
212
+ }
213
+
214
+ /// @notice Allows the StandardBridge on this network to burn tokens.
215
+ /// @param from Address to burn tokens from.
216
+ /// @param amount Amount of tokens to burn.
217
+ function burn(
218
+ address from,
219
+ uint256 amount
220
+ ) external override(IOptimismMintableERC20) onlyL2StandardBridge {
221
+ _burn(from, amount);
222
+ }
223
+
224
+ /// @notice Clock used for flagging checkpoints, overridden to implement timestamp based
225
+ /// checkpoints (and voting).
226
+ function clock() public view override returns (uint48) {
227
+ return uint48(block.timestamp);
228
+ }
229
+
230
+ /// @notice Machine-readable description of the clock as specified in EIP-6372.
231
+ function CLOCK_MODE() public pure override returns (string memory) {
232
+ return "mode=timestamp";
233
+ }
234
+
235
+ /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
236
+ /* Internal Overrides */
237
+ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
238
+
239
+ function _beforeTokenTransfer(address from, address to, uint256 amount) internal override {
240
+ if (from != address(0) && _isLockActive(from)) {
241
+ // allow transferring at minting time
242
+ CustomRevert.revertWith(TransferLockEnabled.selector);
243
+ }
244
+
245
+ super._beforeTokenTransfer(from, to, amount);
246
+ }
247
+
248
+ function _delegate(address account, address delegatee) internal override {
249
+ address currentDelegatee = delegates(account);
250
+
251
+ // revert if the delegatee is the same as the current delegatee
252
+ if (currentDelegatee == delegatee) {
253
+ CustomRevert.revertWith(DelegateeSameAsCurrent.selector);
254
+ }
255
+
256
+ // if the delegatee is the zero address, initialize disable lock
257
+ if (delegatee == address(0)) {
258
+ _disableLock(account);
259
+ } else {
260
+ _enableLock(account);
261
+ }
262
+
263
+ super._delegate(account, delegatee);
264
+ }
265
+
266
+ /// @dev Override the name hash to be a constant value for performance in EIP-712
267
+ function _constantNameHash() internal pure override returns (bytes32) {
268
+ return NAME_HASH;
269
+ }
270
+
271
+ /// @dev This allows Permit2 to be used without prior approval.
272
+ function _givePermit2InfiniteAllowance() internal pure override returns (bool) {
273
+ return true;
274
+ }
275
+
276
+ /// @dev Override the default lock check to disable it.
277
+ function _canLock() internal pure override returns (bool) {
278
+ return false;
279
+ }
280
+
281
+ /// @notice Override the default upgrade check to only allow the owner.
282
+ function _authorizeUpgrade(address newImplementation) internal override onlyOwner {}
283
+ }
@@ -0,0 +1,32 @@
1
+ // SPDX-License-Identifier: MIT
2
+ pragma solidity ^0.8.23;
3
+
4
+ // interfaces
5
+
6
+ // libraries
7
+ import {Create2Utils} from "../../../utils/libraries/Create2Utils.sol";
8
+
9
+ // contracts
10
+ import {ERC1967Proxy} from "@openzeppelin/contracts/proxy/ERC1967/ERC1967Proxy.sol";
11
+ import {Towns} from "src/tokens/towns/base/Towns.sol";
12
+
13
+ contract TownsDeployer {
14
+ constructor(address l1Token, address owner, bytes32 implementationSalt, bytes32 proxySalt) {
15
+ address implementation = Create2Utils.create2Deploy(
16
+ implementationSalt,
17
+ type(Towns).creationCode
18
+ );
19
+
20
+ // Create proxy initialization bytecode
21
+ bytes memory proxyBytecode = abi.encodePacked(
22
+ type(ERC1967Proxy).creationCode,
23
+ abi.encode(
24
+ implementation,
25
+ abi.encodePacked(Towns.initialize.selector, abi.encode(l1Token, owner))
26
+ )
27
+ );
28
+
29
+ // Deploy proxy using create2
30
+ Create2Utils.create2Deploy(proxySalt, proxyBytecode);
31
+ }
32
+ }