@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,21 @@
1
+ // SPDX-License-Identifier: MIT
2
+ pragma solidity ^0.8.23;
3
+
4
+ // interfaces
5
+
6
+ // libraries
7
+
8
+ // contracts
9
+ import {ERC721A} from "./ERC721A.sol";
10
+
11
+ contract ERC721ANonTransferable is ERC721A {
12
+ function _beforeTokenTransfers(
13
+ address from,
14
+ address to,
15
+ uint256 startTokenId,
16
+ uint256 quantity
17
+ ) internal virtual override {
18
+ if (from != address(0)) revert TransferFromIncorrectOwner();
19
+ super._beforeTokenTransfers(from, to, startTokenId, quantity);
20
+ }
21
+ }
@@ -0,0 +1,115 @@
1
+ // SPDX-License-Identifier: MIT
2
+ pragma solidity ^0.8.23;
3
+
4
+ import {IERC721ABase} from "./IERC721A.sol";
5
+
6
+ library ERC721AStorage {
7
+ // keccak256(abi.encode(uint256(keccak256("diamond.facets.token.ERC721A.storage")) - 1)) &
8
+ // ~bytes32(uint256(0xff))
9
+ bytes32 internal constant STORAGE_SLOT =
10
+ 0x6569bde4a160c636ea8b8d11acb83a60d7fec0b8f2e09389306cba0e1340df00;
11
+
12
+ // Mask of an entry in packed address data.
13
+ uint256 internal constant _BITMASK_ADDRESS_DATA_ENTRY = (1 << 64) - 1;
14
+
15
+ // The bit mask of the `burned` bit in packed ownership.
16
+ uint256 internal constant _BITMASK_BURNED = 1 << 224;
17
+
18
+ struct Layout {
19
+ // =============================================================
20
+ // STORAGE
21
+ // =============================================================
22
+
23
+ // The next token ID to be minted.
24
+ uint256 _currentIndex;
25
+ // The number of tokens burned.
26
+ uint256 _burnCounter;
27
+ // Token name
28
+ string _name;
29
+ // Token symbol
30
+ string _symbol;
31
+ // Mapping from token ID to ownership details
32
+ // An empty struct value does not necessarily mean the token is unowned.
33
+ // See {_packedOwnershipOf} implementation for details.
34
+ //
35
+ // Bits Layout:
36
+ // - [0..159] `addr`
37
+ // - [160..223] `startTimestamp`
38
+ // - [224] `burned`
39
+ // - [225] `nextInitialized`
40
+ // - [232..255] `extraData`
41
+ mapping(uint256 => uint256) _packedOwnerships;
42
+ // Mapping owner address to address data.
43
+ //
44
+ // Bits Layout:
45
+ // - [0..63] `balance`
46
+ // - [64..127] `numberMinted`
47
+ // - [128..191] `numberBurned`
48
+ // - [192..255] `aux`
49
+ mapping(address => uint256) _packedAddressData;
50
+ // Mapping from token ID to approved address.
51
+ mapping(uint256 => IERC721ABase.TokenApprovalRef) _tokenApprovals;
52
+ // Mapping from owner to operator approvals
53
+ mapping(address => mapping(address => bool)) _operatorApprovals;
54
+ }
55
+
56
+ function layout() internal pure returns (Layout storage l) {
57
+ bytes32 slot = STORAGE_SLOT;
58
+ assembly {
59
+ l.slot := slot
60
+ }
61
+ }
62
+
63
+ function balanceOf(address owner) internal view returns (uint256) {
64
+ if (owner == address(0)) revert IERC721ABase.BalanceQueryForZeroAddress();
65
+ return layout()._packedAddressData[owner] & _BITMASK_ADDRESS_DATA_ENTRY;
66
+ }
67
+
68
+ function ownerAt(uint256 startTokenId, uint256 tokenId) internal view returns (address) {
69
+ return address(uint160(packedOwnershipOf(startTokenId, tokenId)));
70
+ }
71
+
72
+ /**
73
+ * Returns the packed ownership data of `tokenId`.
74
+ */
75
+ function packedOwnershipOf(
76
+ uint256 startTokenId,
77
+ uint256 tokenId
78
+ ) internal view returns (uint256 packed) {
79
+ if (startTokenId <= tokenId) {
80
+ Layout storage $ = layout();
81
+
82
+ packed = $._packedOwnerships[tokenId];
83
+ // If not burned.
84
+ if (packed & _BITMASK_BURNED == 0) {
85
+ // If the data at the starting slot does not exist, start the scan.
86
+ if (packed == 0) {
87
+ if (tokenId >= $._currentIndex) {
88
+ revert IERC721ABase.OwnerQueryForNonexistentToken();
89
+ }
90
+ // Invariant:
91
+ // There will always be an initialized ownership slot
92
+ // (i.e. `ownership.addr != address(0) && ownership.burned == false`)
93
+ // before an unintialized ownership slot
94
+ // (i.e. `ownership.addr == address(0) && ownership.burned == false`)
95
+ // Hence, `tokenId` will not underflow.
96
+ //
97
+ // We can directly compare the packed value.
98
+ // If the address is zero, packed will be zero.
99
+ for (;;) {
100
+ unchecked {
101
+ packed = $._packedOwnerships[--tokenId];
102
+ }
103
+ if (packed == 0) continue;
104
+ return packed;
105
+ }
106
+ }
107
+ // Otherwise, the data exists and is not burned. We can skip the scan.
108
+ // This is possible because we have already achieved the target condition.
109
+ // This saves 2143 gas on transfers of initialized tokens.
110
+ return packed;
111
+ }
112
+ }
113
+ revert IERC721ABase.OwnerQueryForNonexistentToken();
114
+ }
115
+ }
@@ -0,0 +1,283 @@
1
+ // SPDX-License-Identifier: MIT
2
+ pragma solidity ^0.8.23;
3
+
4
+ /**
5
+ * @dev Interface of ERC721 token receiver.
6
+ */
7
+ interface ERC721A__IERC721ReceiverUpgradeable {
8
+ function onERC721Received(
9
+ address operator,
10
+ address from,
11
+ uint256 tokenId,
12
+ bytes calldata data
13
+ ) external returns (bytes4);
14
+ }
15
+
16
+ interface IERC721ABase {
17
+ // =============================================================
18
+ // STRUCTS
19
+ // =============================================================
20
+ struct TokenApprovalRef {
21
+ address value;
22
+ }
23
+
24
+ struct TokenOwnership {
25
+ // The address of the owner.
26
+ address addr;
27
+ // Stores the start time of ownership with minimal overhead for tokenomics.
28
+ uint64 startTimestamp;
29
+ // Whether the token has been burned.
30
+ bool burned;
31
+ // Arbitrary data similar to `startTimestamp` that can be set via {_extraData}.
32
+ uint24 extraData;
33
+ }
34
+
35
+ // =============================================================
36
+ // ERRORS
37
+ // =============================================================
38
+
39
+ /**
40
+ * The caller must own the token or be an approved operator.
41
+ */
42
+ error ApprovalCallerNotOwnerNorApproved();
43
+
44
+ /**
45
+ * The token does not exist.
46
+ */
47
+ error ApprovalQueryForNonexistentToken();
48
+
49
+ /**
50
+ * Cannot query the balance for the zero address.
51
+ */
52
+ error BalanceQueryForZeroAddress();
53
+
54
+ /**
55
+ * Cannot mint to the zero address.
56
+ */
57
+ error MintToZeroAddress();
58
+
59
+ /**
60
+ * The quantity of tokens minted must be more than zero.
61
+ */
62
+ error MintZeroQuantity();
63
+
64
+ /**
65
+ * The token does not exist.
66
+ */
67
+ error OwnerQueryForNonexistentToken();
68
+
69
+ /**
70
+ * The caller must own the token or be an approved operator.
71
+ */
72
+ error TransferCallerNotOwnerNorApproved();
73
+
74
+ /**
75
+ * The token must be owned by `from`.
76
+ */
77
+ error TransferFromIncorrectOwner();
78
+
79
+ /**
80
+ * Cannot safely transfer to a contract that does not implement the
81
+ * ERC721Receiver interface.
82
+ */
83
+ error TransferToNonERC721ReceiverImplementer();
84
+
85
+ /**
86
+ * Cannot transfer to the zero address.
87
+ */
88
+ error TransferToZeroAddress();
89
+
90
+ /**
91
+ * The token does not exist.
92
+ */
93
+ error URIQueryForNonexistentToken();
94
+
95
+ /**
96
+ * The `quantity` minted with ERC2309 exceeds the safety limit.
97
+ */
98
+ error MintERC2309QuantityExceedsLimit();
99
+
100
+ /**
101
+ * The `extraData` cannot be set on an unintialized ownership slot.
102
+ */
103
+ error OwnershipNotInitializedForExtraData();
104
+
105
+ // =============================================================
106
+ // IERC721
107
+ // =============================================================
108
+
109
+ /**
110
+ * @dev Emitted when `tokenId` token is transferred from `from` to `to`.
111
+ */
112
+ event Transfer(address indexed from, address indexed to, uint256 indexed tokenId);
113
+
114
+ /**
115
+ * @dev Emitted when `owner` enables `approved` to manage the `tokenId` token.
116
+ */
117
+ event Approval(address indexed owner, address indexed approved, uint256 indexed tokenId);
118
+
119
+ /**
120
+ * @dev Emitted when `owner` enables or disables
121
+ * (`approved`) `operator` to manage all of its assets.
122
+ */
123
+ event ApprovalForAll(address indexed owner, address indexed operator, bool approved);
124
+
125
+ // =============================================================
126
+ // IERC2309
127
+ // =============================================================
128
+
129
+ /**
130
+ * @dev Emitted when tokens in `fromTokenId` to `toTokenId`
131
+ * (inclusive) is transferred from `from` to `to`, as defined in the
132
+ * [ERC2309](https://eips.ethereum.org/EIPS/eip-2309) standard.
133
+ *
134
+ * See {_mintERC2309} for more details.
135
+ */
136
+ event ConsecutiveTransfer(
137
+ uint256 indexed fromTokenId,
138
+ uint256 toTokenId,
139
+ address indexed from,
140
+ address indexed to
141
+ );
142
+ }
143
+
144
+ /**
145
+ * @dev Interface of ERC721A.
146
+ */
147
+ interface IERC721A is IERC721ABase {
148
+ // =============================================================
149
+ // TOKEN COUNTERS
150
+ // =============================================================
151
+
152
+ /**
153
+ * @dev Returns the total number of tokens in existence.
154
+ * Burned tokens will reduce the count.
155
+ * To get the total number of tokens minted, please see {_totalMinted}.
156
+ */
157
+ function totalSupply() external view returns (uint256);
158
+
159
+ /**
160
+ * @dev Returns the number of tokens in `owner`'s account.
161
+ */
162
+ function balanceOf(address owner) external view returns (uint256 balance);
163
+
164
+ /**
165
+ * @dev Returns the owner of the `tokenId` token.
166
+ *
167
+ * Requirements:
168
+ *
169
+ * - `tokenId` must exist.
170
+ */
171
+ function ownerOf(uint256 tokenId) external view returns (address owner);
172
+
173
+ /**
174
+ * @dev Safely transfers `tokenId` token from `from` to `to`,
175
+ * checking first that contract recipients are aware of the ERC721 protocol
176
+ * to prevent tokens from being forever locked.
177
+ *
178
+ * Requirements:
179
+ *
180
+ * - `from` cannot be the zero address.
181
+ * - `to` cannot be the zero address.
182
+ * - `tokenId` token must exist and be owned by `from`.
183
+ * - If the caller is not `from`, it must be have been allowed to move
184
+ * this token by either {approve} or {setApprovalForAll}.
185
+ * - If `to` refers to a smart contract, it must implement
186
+ * {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.
187
+ *
188
+ * Emits a {Transfer} event.
189
+ */
190
+ function safeTransferFrom(
191
+ address from,
192
+ address to,
193
+ uint256 tokenId,
194
+ bytes calldata data
195
+ ) external payable;
196
+
197
+ /**
198
+ * @dev Equivalent to `safeTransferFrom(from, to, tokenId, '')`.
199
+ */
200
+ function safeTransferFrom(address from, address to, uint256 tokenId) external payable;
201
+
202
+ /**
203
+ * @dev Transfers `tokenId` from `from` to `to`.
204
+ *
205
+ * WARNING: Usage of this method is discouraged, use {safeTransferFrom}
206
+ * whenever possible.
207
+ *
208
+ * Requirements:
209
+ *
210
+ * - `from` cannot be the zero address.
211
+ * - `to` cannot be the zero address.
212
+ * - `tokenId` token must be owned by `from`.
213
+ * - If the caller is not `from`, it must be approved to move this token
214
+ * by either {approve} or {setApprovalForAll}.
215
+ *
216
+ * Emits a {Transfer} event.
217
+ */
218
+ function transferFrom(address from, address to, uint256 tokenId) external payable;
219
+
220
+ /**
221
+ * @dev Gives permission to `to` to transfer `tokenId` token to another account.
222
+ * The approval is cleared when the token is transferred.
223
+ *
224
+ * Only a single account can be approved at a time, so approving the
225
+ * zero address clears previous approvals.
226
+ *
227
+ * Requirements:
228
+ *
229
+ * - The caller must own the token or be an approved operator.
230
+ * - `tokenId` must exist.
231
+ *
232
+ * Emits an {Approval} event.
233
+ */
234
+ function approve(address to, uint256 tokenId) external payable;
235
+
236
+ /**
237
+ * @dev Approve or remove `operator` as an operator for the caller.
238
+ * Operators can call {transferFrom} or {safeTransferFrom}
239
+ * for any token owned by the caller.
240
+ *
241
+ * Requirements:
242
+ *
243
+ * - The `operator` cannot be the caller.
244
+ *
245
+ * Emits an {ApprovalForAll} event.
246
+ */
247
+ function setApprovalForAll(address operator, bool _approved) external;
248
+
249
+ /**
250
+ * @dev Returns the account approved for `tokenId` token.
251
+ *
252
+ * Requirements:
253
+ *
254
+ * - `tokenId` must exist.
255
+ */
256
+ function getApproved(uint256 tokenId) external view returns (address operator);
257
+
258
+ /**
259
+ * @dev Returns if the `operator` is allowed to manage all of the assets of `owner`.
260
+ *
261
+ * See {setApprovalForAll}.
262
+ */
263
+ function isApprovedForAll(address owner, address operator) external view returns (bool);
264
+
265
+ // =============================================================
266
+ // IERC721Metadata
267
+ // =============================================================
268
+
269
+ /**
270
+ * @dev Returns the token collection name.
271
+ */
272
+ function name() external view returns (string memory);
273
+
274
+ /**
275
+ * @dev Returns the token collection symbol.
276
+ */
277
+ function symbol() external view returns (string memory);
278
+
279
+ /**
280
+ * @dev Returns the Uniform Resource Identifier (URI) for `tokenId` token.
281
+ */
282
+ function tokenURI(uint256 tokenId) external view returns (string memory);
283
+ }
@@ -0,0 +1,134 @@
1
+ // SPDX-License-Identifier: MIT
2
+ pragma solidity ^0.8.23;
3
+
4
+ // interfaces
5
+ import {IERC721AQueryable} from "./IERC721AQueryable.sol";
6
+
7
+ // libraries
8
+
9
+ // contracts
10
+ import {ERC721ABase} from "../ERC721ABase.sol";
11
+
12
+ contract ERC721AQueryable is ERC721ABase, IERC721AQueryable {
13
+ /// @inheritdoc IERC721AQueryable
14
+ function explicitOwnershipOf(
15
+ uint256 tokenId
16
+ ) public view override returns (TokenOwnership memory) {
17
+ TokenOwnership memory ownership;
18
+
19
+ if (tokenId < _startTokenId() || tokenId >= _nextTokenId()) {
20
+ return ownership;
21
+ }
22
+
23
+ ownership = _ownershipAt(tokenId);
24
+ if (ownership.burned) {
25
+ return ownership;
26
+ }
27
+
28
+ return _ownershipOf(tokenId);
29
+ }
30
+
31
+ /// @inheritdoc IERC721AQueryable
32
+ function explicitOwnershipsOf(
33
+ uint256[] calldata tokenIds
34
+ ) external view override returns (TokenOwnership[] memory) {
35
+ unchecked {
36
+ uint256 tokenIdsLen = tokenIds.length;
37
+ TokenOwnership[] memory ownerships = new TokenOwnership[](tokenIdsLen);
38
+ for (uint256 i; i < tokenIdsLen; ++i) {
39
+ ownerships[i] = explicitOwnershipOf(tokenIds[i]);
40
+ }
41
+ return ownerships;
42
+ }
43
+ }
44
+
45
+ /// @inheritdoc IERC721AQueryable
46
+ function tokensOfOwnerIn(
47
+ address owner,
48
+ uint256 start,
49
+ uint256 stop
50
+ ) external view virtual override returns (uint256[] memory) {
51
+ unchecked {
52
+ if (start >= stop) revert InvalidQueryRange();
53
+ uint256 tokenIdsIdx;
54
+ uint256 stopLimit = _nextTokenId();
55
+ // Set `start = max(start, _startTokenId())
56
+ if (start < _startTokenId()) {
57
+ start = _startTokenId();
58
+ }
59
+ // Set `stop = min(stop, _nextTokenId())
60
+ if (stop > stopLimit) {
61
+ stop = stopLimit;
62
+ }
63
+ uint256 tokenIdsMaxLen = _balanceOf(owner);
64
+ // Set `tokenIdsMaxLength = min(balanceOf(owner), stop - start)`,
65
+ // to cater for cases where `balanceOf(owner)` is too large.
66
+ if (start < stop) {
67
+ uint256 rangeLen = stop - start;
68
+ if (rangeLen < tokenIdsMaxLen) {
69
+ tokenIdsMaxLen = rangeLen;
70
+ }
71
+ } else {
72
+ tokenIdsMaxLen = 0;
73
+ }
74
+
75
+ uint256[] memory tokenIds = new uint256[](tokenIdsMaxLen);
76
+ if (tokenIdsMaxLen == 0) {
77
+ return tokenIds;
78
+ }
79
+
80
+ // We need to call `explicitOwnershipOf(start)`,
81
+ // because the slot at `start` may not be initialized
82
+ TokenOwnership memory ownership = explicitOwnershipOf(start);
83
+ address currOwnershipAddr;
84
+ // If starting slot exists (i.e. not burned), initialize `currOwnershipAddr`
85
+ if (!ownership.burned) {
86
+ currOwnershipAddr = ownership.addr;
87
+ }
88
+
89
+ for (uint256 i = start; i != stop && tokenIdsIdx != tokenIdsMaxLen; ++i) {
90
+ ownership = _ownershipAt(i);
91
+ if (ownership.burned) {
92
+ continue;
93
+ }
94
+ if (ownership.addr != address(0)) {
95
+ currOwnershipAddr = ownership.addr;
96
+ }
97
+ if (currOwnershipAddr == owner) {
98
+ tokenIds[tokenIdsIdx++] = i;
99
+ }
100
+ }
101
+ // Downsize array
102
+ assembly {
103
+ mstore(tokenIds, tokenIdsIdx)
104
+ }
105
+ return tokenIds;
106
+ }
107
+ }
108
+
109
+ /// @inheritdoc IERC721AQueryable
110
+ function tokensOfOwner(
111
+ address owner
112
+ ) external view virtual override returns (uint256[] memory) {
113
+ unchecked {
114
+ uint256 tokenIdsIdx;
115
+ address currOwnershipAddr;
116
+ uint256 tokenIdsLen = _balanceOf(owner);
117
+ uint256[] memory tokenIds = new uint256[](tokenIdsLen);
118
+ TokenOwnership memory ownership;
119
+ for (uint256 i = _startTokenId(); tokenIdsIdx != tokenIdsLen; ++i) {
120
+ ownership = _ownershipAt(i);
121
+ if (ownership.burned) {
122
+ continue;
123
+ }
124
+ if (ownership.addr != address(0)) {
125
+ currOwnershipAddr = ownership.addr;
126
+ }
127
+ if (currOwnershipAddr == owner) {
128
+ tokenIds[tokenIdsIdx++] = i;
129
+ }
130
+ }
131
+ return tokenIds;
132
+ }
133
+ }
134
+ }
@@ -0,0 +1,83 @@
1
+ // SPDX-License-Identifier: MIT
2
+ pragma solidity ^0.8.23;
3
+
4
+ // interfaces
5
+ import {IERC721ABase} from "../IERC721A.sol";
6
+
7
+ // libraries
8
+
9
+ // contracts
10
+
11
+ /**
12
+ * @dev Interface of ERC721AQueryable.
13
+ */
14
+ interface IERC721AQueryable is IERC721ABase {
15
+ /**
16
+ * Invalid query range (`start` >= `stop`).
17
+ */
18
+ error InvalidQueryRange();
19
+
20
+ /**
21
+ * @dev Returns the `TokenOwnership` struct at `tokenId` without reverting.
22
+ *
23
+ * If the `tokenId` is out of bounds:
24
+ *
25
+ * - `addr = address(0)`
26
+ * - `startTimestamp = 0`
27
+ * - `burned = false`
28
+ * - `extraData = 0`
29
+ *
30
+ * If the `tokenId` is burned:
31
+ *
32
+ * - `addr = <Address of owner before token was burned>`
33
+ * - `startTimestamp = <Timestamp when token was burned>`
34
+ * - `burned = true`
35
+ * - `extraData = <Extra data when token was burned>`
36
+ *
37
+ * Otherwise:
38
+ *
39
+ * - `addr = <Address of owner>`
40
+ * - `startTimestamp = <Timestamp of start of ownership>`
41
+ * - `burned = false`
42
+ * - `extraData = <Extra data at start of ownership>`
43
+ */
44
+ function explicitOwnershipOf(uint256 tokenId) external view returns (TokenOwnership memory);
45
+
46
+ /**
47
+ * @dev Returns an array of `TokenOwnership` structs at `tokenIds` in order.
48
+ * See {ERC721AQueryable-explicitOwnershipOf}
49
+ */
50
+ function explicitOwnershipsOf(
51
+ uint256[] memory tokenIds
52
+ ) external view returns (TokenOwnership[] memory);
53
+
54
+ /**
55
+ * @dev Returns an array of token IDs owned by `owner`,
56
+ * in the range [`start`, `stop`)
57
+ * (i.e. `start <= tokenId < stop`).
58
+ *
59
+ * This function allows for tokens to be queried if the collection
60
+ * grows too big for a single call of {ERC721AQueryable-tokensOfOwner}.
61
+ *
62
+ * Requirements:
63
+ *
64
+ * - `start < stop`
65
+ */
66
+ function tokensOfOwnerIn(
67
+ address owner,
68
+ uint256 start,
69
+ uint256 stop
70
+ ) external view returns (uint256[] memory);
71
+
72
+ /**
73
+ * @dev Returns an array of token IDs owned by `owner`.
74
+ *
75
+ * This function scans the ownership mapping and is O(`totalSupply`) in complexity.
76
+ * It is meant to be called off-chain.
77
+ *
78
+ * See {ERC721AQueryable-tokensOfOwnerIn} for splitting the scan into
79
+ * multiple smaller scans if the collection is large enough to cause
80
+ * an out-of-gas error (10K collections should be fine).
81
+ */
82
+ function tokensOfOwner(address owner) external view returns (uint256[] memory);
83
+ }
@@ -0,0 +1,19 @@
1
+ // SPDX-License-Identifier: MIT
2
+ pragma solidity ^0.8.23;
3
+
4
+ // interfaces
5
+
6
+ // libraries
7
+
8
+ // contracts
9
+
10
+ abstract contract Context {
11
+ function _msgSender() internal view virtual returns (address) {
12
+ return msg.sender;
13
+ }
14
+
15
+ function _msgData() internal view virtual returns (bytes calldata) {
16
+ this;
17
+ return msg.data;
18
+ }
19
+ }
@@ -0,0 +1,17 @@
1
+ // SPDX-License-Identifier: MIT
2
+ pragma solidity ^0.8.23;
3
+
4
+ // interfaces
5
+ import {ISpaceProxyInitializer} from "src/spaces/facets/proxy/ISpaceProxyInitializer.sol";
6
+
7
+ // libraries
8
+ import {ImplementationStorage} from "src/factory/facets/architect/ImplementationStorage.sol";
9
+
10
+ // contracts
11
+
12
+ contract SpaceFactoryInit {
13
+ function initialize(address proxyInitializer) external {
14
+ ImplementationStorage.Layout storage ds = ImplementationStorage.layout();
15
+ ds.proxyInitializer = ISpaceProxyInitializer(proxyInitializer);
16
+ }
17
+ }