@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.
- package/LICENSE.txt +21 -0
- package/README.md +206 -0
- package/docs/permitAndStake_integration_guide.md +266 -0
- package/docs/swap_integration_guide.md +591 -0
- package/package.json +57 -0
- package/scripts/common/DeployBase.s.sol +26 -0
- package/scripts/common/DeployFacet.s.sol +7 -0
- package/scripts/common/Deployer.s.sol +33 -0
- package/scripts/common/Interaction.s.sol +51 -0
- package/scripts/deployments/diamonds/DeployAppRegistry.s.sol +168 -0
- package/scripts/deployments/diamonds/DeployBaseRegistry.s.sol +263 -0
- package/scripts/deployments/diamonds/DeployRiverAirdrop.s.sol +203 -0
- package/scripts/deployments/diamonds/DeployRiverMigration.s.sol +129 -0
- package/scripts/deployments/diamonds/DeployRiverRegistry.s.sol +175 -0
- package/scripts/deployments/diamonds/DeploySpace.s.sol +285 -0
- package/scripts/deployments/diamonds/DeploySpaceFactory.s.sol +416 -0
- package/scripts/deployments/diamonds/DeploySpaceOwner.s.sol +183 -0
- package/scripts/deployments/diamonds/DeploySwapRouter.s.sol +176 -0
- package/scripts/deployments/diamonds/IDiamondInitHelper.sol +11 -0
- package/scripts/deployments/facets/DeployAppAccount.s.sol +51 -0
- package/scripts/deployments/facets/DeployAppRegistryFacet.s.sol +69 -0
- package/scripts/deployments/facets/DeployArchitect.s.sol +51 -0
- package/scripts/deployments/facets/DeployAttestationRegistry.s.sol +36 -0
- package/scripts/deployments/facets/DeployBanning.s.sol +30 -0
- package/scripts/deployments/facets/DeployChannels.s.sol +35 -0
- package/scripts/deployments/facets/DeployCreateSpace.s.sol +42 -0
- package/scripts/deployments/facets/DeployDropFacet.s.sol +49 -0
- package/scripts/deployments/facets/DeployERC721A.s.sol +48 -0
- package/scripts/deployments/facets/DeployERC721ANonTransferable.s.sol +49 -0
- package/scripts/deployments/facets/DeployERC721AQueryable.s.sol +30 -0
- package/scripts/deployments/facets/DeployEntitlementChecker.s.sol +49 -0
- package/scripts/deployments/facets/DeployEntitlementDataQueryable.s.sol +29 -0
- package/scripts/deployments/facets/DeployEntitlementsManager.s.sol +33 -0
- package/scripts/deployments/facets/DeployExecutorFacet.s.sol +60 -0
- package/scripts/deployments/facets/DeployFeatureManager.s.sol +38 -0
- package/scripts/deployments/facets/DeployGuardianFacet.s.sol +39 -0
- package/scripts/deployments/facets/DeployImplementationRegistry.s.sol +36 -0
- package/scripts/deployments/facets/DeployMainnetDelegation.s.sol +43 -0
- package/scripts/deployments/facets/DeployMembership.s.sol +77 -0
- package/scripts/deployments/facets/DeployMembershipMetadata.s.sol +30 -0
- package/scripts/deployments/facets/DeployMembershipToken.s.sol +47 -0
- package/scripts/deployments/facets/DeployMerkleAirdrop.s.sol +37 -0
- package/scripts/deployments/facets/DeployMetadata.s.sol +39 -0
- package/scripts/deployments/facets/DeployMockLegacyArchitect.s.sol +33 -0
- package/scripts/deployments/facets/DeployNodeOperator.s.sol +49 -0
- package/scripts/deployments/facets/DeployNodeRegistry.s.sol +37 -0
- package/scripts/deployments/facets/DeployOperatorRegistry.s.sol +36 -0
- package/scripts/deployments/facets/DeployPartnerRegistry.s.sol +41 -0
- package/scripts/deployments/facets/DeployPlatformRequirements.s.sol +75 -0
- package/scripts/deployments/facets/DeployPrepayFacet.s.sol +31 -0
- package/scripts/deployments/facets/DeployPricingModules.s.sol +36 -0
- package/scripts/deployments/facets/DeployReferrals.s.sol +34 -0
- package/scripts/deployments/facets/DeployReviewFacet.s.sol +31 -0
- package/scripts/deployments/facets/DeployRewardsDistributionV2.s.sol +76 -0
- package/scripts/deployments/facets/DeployRiverConfig.s.sol +41 -0
- package/scripts/deployments/facets/DeployRoles.s.sol +48 -0
- package/scripts/deployments/facets/DeploySchemaRegistry.s.sol +35 -0
- package/scripts/deployments/facets/DeploySignerFacet.s.sol +47 -0
- package/scripts/deployments/facets/DeploySimpleApp.s.sol +10 -0
- package/scripts/deployments/facets/DeploySpaceDelegation.s.sol +43 -0
- package/scripts/deployments/facets/DeploySpaceEntitlementGated.s.sol +31 -0
- package/scripts/deployments/facets/DeploySpaceFactoryInit.s.sol +33 -0
- package/scripts/deployments/facets/DeploySpaceOwnerFacet.s.sol +71 -0
- package/scripts/deployments/facets/DeployStreamRegistry.s.sol +50 -0
- package/scripts/deployments/facets/DeploySwapFacet.s.sol +33 -0
- package/scripts/deployments/facets/DeploySwapRouterFacet.s.sol +38 -0
- package/scripts/deployments/facets/DeployTipping.s.sol +31 -0
- package/scripts/deployments/facets/DeployTokenMigration.s.sol +40 -0
- package/scripts/deployments/facets/DeployTownsPoints.s.sol +53 -0
- package/scripts/deployments/facets/DeployTreasury.s.sol +30 -0
- package/scripts/deployments/facets/DeployUpgradeableBeacon.s.sol +34 -0
- package/scripts/deployments/facets/DeployWalletLink.s.sol +56 -0
- package/scripts/deployments/facets/DeployXChain.s.sol +35 -0
- package/scripts/deployments/utils/DeployAccountFactory.s.sol +40 -0
- package/scripts/deployments/utils/DeployEntitlementGatedExample.s.sol +23 -0
- package/scripts/deployments/utils/DeployEntrypoint.s.sol +28 -0
- package/scripts/deployments/utils/DeployMember.s.sol +95 -0
- package/scripts/deployments/utils/DeployMockDiamond.s.sol +7 -0
- package/scripts/deployments/utils/DeployMockERC20.s.sol +24 -0
- package/scripts/deployments/utils/DeployMockERC721A.s.sol +45 -0
- package/scripts/deployments/utils/DeployMockLegacyMembership.s.sol +29 -0
- package/scripts/deployments/utils/DeployMockMessenger.s.sol +42 -0
- package/scripts/deployments/utils/DeployMockNFT.s.sol +86 -0
- package/scripts/deployments/utils/DeployPoapEntitlement.s.sol +16 -0
- package/scripts/deployments/utils/DeployProxyBatchDelegation.s.sol +112 -0
- package/scripts/deployments/utils/DeploySpaceProxyInitializer.s.sol +28 -0
- package/scripts/deployments/utils/DeployTieredLogPricingV2.s.sol +23 -0
- package/scripts/deployments/utils/DeployTieredLogPricingV3.s.sol +23 -0
- package/scripts/deployments/utils/DeployTownsBase.s.sol +95 -0
- package/scripts/deployments/utils/DeployTownsMainnet.s.sol +66 -0
- package/scripts/deployments/utils/DeployTownsMulti.s.sol +53 -0
- package/scripts/deployments/utils/DeployWrappedTowns.s.sol +52 -0
- package/scripts/deployments/utils/LibLayerZeroValues.sol +34 -0
- package/scripts/deployments/utils/pricing/TieredLogPricing.s.sol +45 -0
- package/scripts/interactions/InteractAirdrop.s.sol +57 -0
- package/scripts/interactions/InteractAlphaPost.s.sol +32 -0
- package/scripts/interactions/InteractAlphaSparse.s.sol +173 -0
- package/scripts/interactions/InteractBaseAlpha.s.sol +84 -0
- package/scripts/interactions/InteractBaseBridge.s.sol +48 -0
- package/scripts/interactions/InteractBridgeLayerZero.s.sol +102 -0
- package/scripts/interactions/InteractClaimCondition.s.sol +56 -0
- package/scripts/interactions/InteractCreateSpace.s.sol +50 -0
- package/scripts/interactions/InteractDiamondCut.s.sol +47 -0
- package/scripts/interactions/InteractDropFacet.s.sol +32 -0
- package/scripts/interactions/InteractEnableNewSnapshotFormat.s.sol +27 -0
- package/scripts/interactions/InteractEnableNode2NodeAuth.s.sol +27 -0
- package/scripts/interactions/InteractMembership.s.sol +42 -0
- package/scripts/interactions/InteractMockERC721A.s.sol +20 -0
- package/scripts/interactions/InteractNodeOperators.s.sol +41 -0
- package/scripts/interactions/InteractPostDeploy.s.sol +59 -0
- package/scripts/interactions/InteractPrepay.s.sol +30 -0
- package/scripts/interactions/InteractRegisterApp.s.sol +61 -0
- package/scripts/interactions/InteractRiverAlpha.s.sol +30 -0
- package/scripts/interactions/InteractRiverAlphaSparse.s.sol +117 -0
- package/scripts/interactions/InteractRiverMainnet.s.sol +27 -0
- package/scripts/interactions/InteractRiverRegistry.s.sol +36 -0
- package/scripts/interactions/InteractRiverRegistrySetBlocklist.s.sol +30 -0
- package/scripts/interactions/InteractRiverRegistrySetFreq.s.sol +27 -0
- package/scripts/interactions/InteractRiverRegistrySetRepl.s.sol +30 -0
- package/scripts/interactions/InteractSetDefaultUri.s.sol +20 -0
- package/scripts/interactions/InteractSetDefaultUriLocalhost.s.sol +19 -0
- package/scripts/interactions/InteractTransferOwnership.s.sol +21 -0
- package/scripts/interactions/InteractUpdateMbRecencyCheck.s.sol +27 -0
- package/scripts/interactions/InteractUpdateMediaChunkCount.s.sol +27 -0
- package/scripts/interactions/InteractUpdateMediaChunkSize.s.sol +27 -0
- package/scripts/interactions/helpers/AlphaHelper.sol +149 -0
- package/scripts/interactions/helpers/RiverConfigValues.sol +22 -0
- package/scripts/interactions/interfaces/IL1StandardBridge.sol +35 -0
- package/scripts/interactions/interfaces/IL2StandardBridge.sol +69 -0
- package/src/airdrop/drop/DropBase.sol +210 -0
- package/src/airdrop/drop/DropClaim.sol +55 -0
- package/src/airdrop/drop/DropFacet.sol +176 -0
- package/src/airdrop/drop/DropGroup.sol +111 -0
- package/src/airdrop/drop/DropStorage.sol +23 -0
- package/src/airdrop/drop/IDropFacet.sol +136 -0
- package/src/airdrop/points/CheckIn.sol +71 -0
- package/src/airdrop/points/ITownsPoints.sol +64 -0
- package/src/airdrop/points/TownsPoints.sol +196 -0
- package/src/airdrop/points/TownsPointsStorage.sol +22 -0
- package/src/apps/BaseApp.sol +62 -0
- package/src/apps/ITownsApp.sol +28 -0
- package/src/apps/SchemaResolver.sol +170 -0
- package/src/apps/facets/attest/AttestationBase.sol +335 -0
- package/src/apps/facets/attest/AttestationLib.sol +64 -0
- package/src/apps/facets/attest/AttestationRegistry.sol +39 -0
- package/src/apps/facets/attest/AttestationStorage.sol +35 -0
- package/src/apps/facets/attest/IAttestationRegistry.sol +43 -0
- package/src/apps/facets/registry/AppRegistryBase.sol +403 -0
- package/src/apps/facets/registry/AppRegistryFacet.sol +173 -0
- package/src/apps/facets/registry/AppRegistryStorage.sol +53 -0
- package/src/apps/facets/registry/IAppRegistry.sol +159 -0
- package/src/apps/facets/schema/ISchema.sol +14 -0
- package/src/apps/facets/schema/SchemaBase.sol +88 -0
- package/src/apps/facets/schema/SchemaLib.sol +14 -0
- package/src/apps/facets/schema/SchemaRegistry.sol +51 -0
- package/src/apps/facets/schema/SchemaStorage.sol +34 -0
- package/src/apps/helpers/ISimpleApp.sol +51 -0
- package/src/apps/helpers/SimpleApp.sol +97 -0
- package/src/apps/helpers/SimpleAppStorage.sol +27 -0
- package/src/base/registry/facets/checker/EntitlementChecker.sol +237 -0
- package/src/base/registry/facets/checker/EntitlementCheckerStorage.sol +28 -0
- package/src/base/registry/facets/checker/IEntitlementChecker.sol +95 -0
- package/src/base/registry/facets/delegation/ISpaceDelegation.sol +69 -0
- package/src/base/registry/facets/delegation/SpaceDelegationFacet.sol +250 -0
- package/src/base/registry/facets/delegation/SpaceDelegationStorage.sol +35 -0
- package/src/base/registry/facets/distribution/v1/IRewardsDistribution.sol +51 -0
- package/src/base/registry/facets/distribution/v1/RewardsDistribution.sol +439 -0
- package/src/base/registry/facets/distribution/v1/RewardsDistributionStorage.sol +32 -0
- package/src/base/registry/facets/distribution/v2/DelegationProxy.sol +53 -0
- package/src/base/registry/facets/distribution/v2/IRewardsDistribution.sol +372 -0
- package/src/base/registry/facets/distribution/v2/RewardsDistributionBase.sol +299 -0
- package/src/base/registry/facets/distribution/v2/RewardsDistributionStorage.sol +37 -0
- package/src/base/registry/facets/distribution/v2/RewardsDistributionV2.sol +392 -0
- package/src/base/registry/facets/distribution/v2/StakingRewards.sol +466 -0
- package/src/base/registry/facets/mainnet/ICrossDomainMessenger.sol +58 -0
- package/src/base/registry/facets/mainnet/IMainnetDelegation.sol +127 -0
- package/src/base/registry/facets/mainnet/MainnetDelegation.sol +119 -0
- package/src/base/registry/facets/mainnet/MainnetDelegationBase.sol +274 -0
- package/src/base/registry/facets/mainnet/MainnetDelegationStorage.sol +36 -0
- package/src/base/registry/facets/operator/INodeOperator.sol +91 -0
- package/src/base/registry/facets/operator/NodeOperatorFacet.sol +189 -0
- package/src/base/registry/facets/operator/NodeOperatorStorage.sol +39 -0
- package/src/base/registry/facets/xchain/IXChain.sol +54 -0
- package/src/base/registry/facets/xchain/XChain.sol +158 -0
- package/src/base/registry/facets/xchain/XChainCheckLib.sol +105 -0
- package/src/base/registry/facets/xchain/XChainLib.sol +46 -0
- package/src/diamond/facets/beacon/UpgradeableBeacon.sol +38 -0
- package/src/diamond/facets/beacon/UpgradeableBeaconFacet.sol +34 -0
- package/src/diamond/facets/governance/votes/Checkpoints.sol +642 -0
- package/src/diamond/facets/governance/votes/Votes.sol +63 -0
- package/src/diamond/facets/governance/votes/VotesBase.sol +274 -0
- package/src/diamond/facets/governance/votes/VotesStorage.sol +21 -0
- package/src/diamond/facets/governance/votes/enumerable/IVotesEnumerable.sol +38 -0
- package/src/diamond/facets/governance/votes/enumerable/VotesEnumerable.sol +39 -0
- package/src/diamond/facets/governance/votes/enumerable/VotesEnumerableLib.sol +102 -0
- package/src/diamond/facets/metadata/IMetadata.sol +27 -0
- package/src/diamond/facets/metadata/MetadataFacet.sol +71 -0
- package/src/diamond/facets/token/ERC5643/ERC5643.sol +51 -0
- package/src/diamond/facets/token/ERC5643/ERC5643Base.sol +48 -0
- package/src/diamond/facets/token/ERC5643/ERC5643Storage.sol +26 -0
- package/src/diamond/facets/token/ERC5643/IERC5643.sol +44 -0
- package/src/diamond/facets/token/ERC721A/ERC721A.sol +270 -0
- package/src/diamond/facets/token/ERC721A/ERC721ABase.sol +829 -0
- package/src/diamond/facets/token/ERC721A/ERC721ANonTransferable.sol +21 -0
- package/src/diamond/facets/token/ERC721A/ERC721AStorage.sol +115 -0
- package/src/diamond/facets/token/ERC721A/IERC721A.sol +283 -0
- package/src/diamond/facets/token/ERC721A/extensions/ERC721AQueryable.sol +134 -0
- package/src/diamond/facets/token/ERC721A/extensions/IERC721AQueryable.sol +83 -0
- package/src/diamond/utils/Context.sol +19 -0
- package/src/factory/SpaceFactoryInit.sol +17 -0
- package/src/factory/facets/architect/Architect.sol +98 -0
- package/src/factory/facets/architect/ArchitectBase.sol +95 -0
- package/src/factory/facets/architect/ArchitectStorage.sol +28 -0
- package/src/factory/facets/architect/IArchitect.sol +155 -0
- package/src/factory/facets/architect/ImplementationStorage.sol +42 -0
- package/src/factory/facets/architect/pricing/IPricingModules.sol +41 -0
- package/src/factory/facets/architect/pricing/PricingModulesBase.sol +89 -0
- package/src/factory/facets/architect/pricing/PricingModulesFacet.sol +40 -0
- package/src/factory/facets/architect/pricing/PricingModulesStorage.sol +30 -0
- package/src/factory/facets/create/CreateSpace.sol +107 -0
- package/src/factory/facets/create/CreateSpaceLib.sol +335 -0
- package/src/factory/facets/create/ICreateSpace.sol +70 -0
- package/src/factory/facets/feature/FeatureConditionLib.sol +53 -0
- package/src/factory/facets/feature/FeatureManagerFacet.sol +66 -0
- package/src/factory/facets/feature/FeatureManagerLib.sol +168 -0
- package/src/factory/facets/feature/IFeatureManagerFacet.sol +73 -0
- package/src/factory/facets/partner/IPartnerRegistry.sol +56 -0
- package/src/factory/facets/partner/PartnerRegistry.sol +57 -0
- package/src/factory/facets/partner/PartnerRegistryBase.sol +132 -0
- package/src/factory/facets/partner/PartnerRegistryStorage.sol +40 -0
- package/src/factory/facets/platform/requirements/IPlatformRequirements.sol +143 -0
- package/src/factory/facets/platform/requirements/PlatformRequirementsBase.sol +124 -0
- package/src/factory/facets/platform/requirements/PlatformRequirementsFacet.sol +122 -0
- package/src/factory/facets/platform/requirements/PlatformRequirementsStorage.sol +41 -0
- package/src/factory/facets/registry/IImplementationRegistry.sol +46 -0
- package/src/factory/facets/registry/ImplementationRegistry.sol +64 -0
- package/src/factory/facets/registry/ImplementationRegistryStorage.sol +28 -0
- package/src/factory/facets/wallet-link/IWalletLink.sol +218 -0
- package/src/factory/facets/wallet-link/WalletLink.sol +108 -0
- package/src/factory/facets/wallet-link/WalletLinkBase.sol +492 -0
- package/src/factory/facets/wallet-link/interfaces/IDelegateRegistry.sol +63 -0
- package/src/factory/facets/wallet-link/interfaces/IDelegateRegistryV1.sol +35 -0
- package/src/factory/facets/wallet-link/interfaces/ISCL_EIP6565.sol +24 -0
- package/src/factory/facets/wallet-link/libraries/SolanaUtils.sol +161 -0
- package/src/factory/facets/wallet-link/libraries/WalletLib.sol +62 -0
- package/src/river/registry/facets/config/IRiverConfig.sol +117 -0
- package/src/river/registry/facets/config/RiverConfig.sol +174 -0
- package/src/river/registry/facets/node/INodeRegistry.sol +69 -0
- package/src/river/registry/facets/node/NodeRegistry.sol +143 -0
- package/src/river/registry/facets/operator/IOperatorRegistry.sol +28 -0
- package/src/river/registry/facets/operator/OperatorRegistry.sol +86 -0
- package/src/river/registry/facets/stream/IStreamRegistry.sol +184 -0
- package/src/river/registry/facets/stream/StreamRegistry.sol +396 -0
- package/src/river/registry/libraries/RegistryErrors.sol +24 -0
- package/src/river/registry/libraries/RegistryStorage.sol +181 -0
- package/src/router/ISwapRouter.sol +226 -0
- package/src/router/Permit2Hash.sol +92 -0
- package/src/router/SwapRouter.sol +463 -0
- package/src/router/SwapRouterStorage.sol +21 -0
- package/src/spaces/entitlements/ICrossChainEntitlement.sol +22 -0
- package/src/spaces/entitlements/IEntitlement.sol +61 -0
- package/src/spaces/entitlements/PolymarketEntitlement.sol +79 -0
- package/src/spaces/entitlements/poap/IPOAP.sol +26 -0
- package/src/spaces/entitlements/poap/PoapEntitlement.sol +56 -0
- package/src/spaces/entitlements/rule/IRuleEntitlement.sol +174 -0
- package/src/spaces/entitlements/rule/RuleEntitlement.sol +183 -0
- package/src/spaces/entitlements/rule/RuleEntitlementV2.sol +219 -0
- package/src/spaces/entitlements/user/IUserEntitlement.sol +24 -0
- package/src/spaces/entitlements/user/UserEntitlement.sol +273 -0
- package/src/spaces/facets/DependencyLib.sol +60 -0
- package/src/spaces/facets/Entitled.sol +172 -0
- package/src/spaces/facets/Permissions.sol +21 -0
- package/src/spaces/facets/account/AppAccount.sol +93 -0
- package/src/spaces/facets/account/AppAccountBase.sol +275 -0
- package/src/spaces/facets/account/AppAccountStorage.sol +63 -0
- package/src/spaces/facets/account/IAppAccount.sol +71 -0
- package/src/spaces/facets/account/SignerFacet.sol +26 -0
- package/src/spaces/facets/banning/Banning.sol +41 -0
- package/src/spaces/facets/banning/BanningBase.sol +33 -0
- package/src/spaces/facets/banning/BanningStorage.sol +23 -0
- package/src/spaces/facets/banning/IBanning.sol +35 -0
- package/src/spaces/facets/channels/ChannelBase.sol +87 -0
- package/src/spaces/facets/channels/ChannelService.sol +177 -0
- package/src/spaces/facets/channels/ChannelStorage.sol +34 -0
- package/src/spaces/facets/channels/Channels.sol +80 -0
- package/src/spaces/facets/channels/IChannel.sol +98 -0
- package/src/spaces/facets/dispatcher/DispatcherBase.sol +86 -0
- package/src/spaces/facets/dispatcher/DispatcherStorage.sol +21 -0
- package/src/spaces/facets/dispatcher/IDispatcher.sol +6 -0
- package/src/spaces/facets/entitlements/EntitlementsManager.sol +49 -0
- package/src/spaces/facets/entitlements/EntitlementsManagerBase.sol +87 -0
- package/src/spaces/facets/entitlements/EntitlementsManagerService.sol +142 -0
- package/src/spaces/facets/entitlements/EntitlementsManagerStorage.sol +34 -0
- package/src/spaces/facets/entitlements/IEntitlementsManager.sol +67 -0
- package/src/spaces/facets/entitlements/extensions/EntitlementDataQueryable.sol +153 -0
- package/src/spaces/facets/entitlements/extensions/IEntitlementDataQueryable.sol +32 -0
- package/src/spaces/facets/executor/ExecutorBase.sol +564 -0
- package/src/spaces/facets/executor/ExecutorFacet.sol +178 -0
- package/src/spaces/facets/executor/ExecutorStorage.sol +99 -0
- package/src/spaces/facets/executor/GroupLib.sol +128 -0
- package/src/spaces/facets/executor/IExecutor.sol +287 -0
- package/src/spaces/facets/executor/hooks/HookBase.sol +172 -0
- package/src/spaces/facets/executor/hooks/HookLib.sol +38 -0
- package/src/spaces/facets/executor/hooks/IHookBase.sol +48 -0
- package/src/spaces/facets/gated/EntitlementGated.sol +59 -0
- package/src/spaces/facets/gated/EntitlementGatedBase.sol +324 -0
- package/src/spaces/facets/gated/EntitlementGatedStorage.sol +29 -0
- package/src/spaces/facets/gated/IEntitlementGated.sol +55 -0
- package/src/spaces/facets/guardian/GuardianBase.sol +80 -0
- package/src/spaces/facets/guardian/GuardianFacet.sol +43 -0
- package/src/spaces/facets/guardian/GuardianStorage.sol +27 -0
- package/src/spaces/facets/guardian/IGuardian.sol +54 -0
- package/src/spaces/facets/membership/IMembership.sol +216 -0
- package/src/spaces/facets/membership/MembershipBase.sol +272 -0
- package/src/spaces/facets/membership/MembershipFacet.sol +191 -0
- package/src/spaces/facets/membership/MembershipStorage.sol +40 -0
- package/src/spaces/facets/membership/join/MembershipJoin.sol +547 -0
- package/src/spaces/facets/membership/metadata/IMembershipMetadata.sol +9 -0
- package/src/spaces/facets/membership/metadata/MembershipMetadata.sol +32 -0
- package/src/spaces/facets/membership/pricing/IMembershipPricing.sol +18 -0
- package/src/spaces/facets/membership/pricing/fixed/FixedPricing.sol +29 -0
- package/src/spaces/facets/membership/pricing/fixed/FixedPricingStorage.sol +27 -0
- package/src/spaces/facets/membership/pricing/tiered/TieredLogPricingOracleV2.sol +148 -0
- package/src/spaces/facets/membership/pricing/tiered/TieredLogPricingOracleV3.sol +137 -0
- package/src/spaces/facets/membership/token/MembershipToken.sol +25 -0
- package/src/spaces/facets/owner/ISpaceOwner.sol +85 -0
- package/src/spaces/facets/owner/SpaceOwner.sol +174 -0
- package/src/spaces/facets/owner/SpaceOwnerBase.sol +121 -0
- package/src/spaces/facets/owner/SpaceOwnerStorage.sol +41 -0
- package/src/spaces/facets/owner/SpaceOwnerUriBase.sol +54 -0
- package/src/spaces/facets/points/PointsBase.sol +35 -0
- package/src/spaces/facets/prepay/IPrepay.sol +43 -0
- package/src/spaces/facets/prepay/PrepayBase.sol +27 -0
- package/src/spaces/facets/prepay/PrepayFacet.sol +59 -0
- package/src/spaces/facets/prepay/PrepayStorage.sol +26 -0
- package/src/spaces/facets/proxy/ISpaceProxyInitializer.sol +21 -0
- package/src/spaces/facets/proxy/SpaceProxy.sol +15 -0
- package/src/spaces/facets/proxy/SpaceProxyInitializer.sol +55 -0
- package/src/spaces/facets/referrals/IReferrals.sol +98 -0
- package/src/spaces/facets/referrals/ReferralsBase.sol +81 -0
- package/src/spaces/facets/referrals/ReferralsFacet.sol +65 -0
- package/src/spaces/facets/referrals/ReferralsStorage.sol +36 -0
- package/src/spaces/facets/review/IReview.sol +50 -0
- package/src/spaces/facets/review/ReviewFacet.sol +105 -0
- package/src/spaces/facets/review/ReviewStorage.sol +29 -0
- package/src/spaces/facets/roles/IRoles.sol +197 -0
- package/src/spaces/facets/roles/Roles.sol +123 -0
- package/src/spaces/facets/roles/RolesBase.sol +420 -0
- package/src/spaces/facets/roles/RolesStorage.sol +132 -0
- package/src/spaces/facets/swap/ISwapFacet.sol +91 -0
- package/src/spaces/facets/swap/SwapFacet.sol +290 -0
- package/src/spaces/facets/swap/SwapFacetStorage.sol +24 -0
- package/src/spaces/facets/tipping/ITipping.sol +80 -0
- package/src/spaces/facets/tipping/TippingBase.sol +73 -0
- package/src/spaces/facets/tipping/TippingFacet.sol +123 -0
- package/src/spaces/facets/treasury/ITreasury.sol +64 -0
- package/src/spaces/facets/treasury/Treasury.sol +82 -0
- package/src/spaces/facets/xchain/SpaceEntitlementGated.sol +62 -0
- package/src/tokens/Member.sol +246 -0
- package/src/tokens/lock/ILock.sol +42 -0
- package/src/tokens/lock/LockBase.sol +64 -0
- package/src/tokens/lock/LockFacet.sol +44 -0
- package/src/tokens/lock/LockStorage.sol +26 -0
- package/src/tokens/mainnet/claimer/AuthorizedClaimerStorage.sol +26 -0
- package/src/tokens/mainnet/claimer/AuthorizedClaimers.sol +84 -0
- package/src/tokens/mainnet/claimer/IAuthorizedClaimers.sol +36 -0
- package/src/tokens/mainnet/delegation/ProxyBatchDelegation.sol +86 -0
- package/src/tokens/migration/ITokenMigration.sol +35 -0
- package/src/tokens/migration/TokenMigrationFacet.sol +86 -0
- package/src/tokens/migration/TokenMigrationStorage.sol +27 -0
- package/src/tokens/towns/base/IERC7802.sol +30 -0
- package/src/tokens/towns/base/IOptimismMintableERC20.sol +31 -0
- package/src/tokens/towns/base/ISemver.sol +13 -0
- package/src/tokens/towns/base/Towns.sol +283 -0
- package/src/tokens/towns/base/TownsDeployer.sol +32 -0
- package/src/tokens/towns/base/TownsLib.sol +31 -0
- package/src/tokens/towns/base/versions/TownsV2.sol +15 -0
- package/src/tokens/towns/mainnet/ITowns.sol +56 -0
- package/src/tokens/towns/mainnet/Towns.sol +220 -0
- package/src/tokens/towns/mainnet/libs/TokenInflationLib.sol +89 -0
- package/src/tokens/towns/multichain/Towns.sol +19 -0
- package/src/tokens/towns/multichain/wTowns.sol +18 -0
- package/src/utils/Airdrop.sol +156 -0
- package/src/utils/airdrop/merkle/IMerkleAirdrop.sol +55 -0
- package/src/utils/airdrop/merkle/MerkleAirdrop.sol +118 -0
- package/src/utils/airdrop/merkle/MerkleAirdropStorage.sol +29 -0
- package/src/utils/interfaces/AggregatorV3Interface.sol +37 -0
- package/src/utils/interfaces/IMulticall.sol +10 -0
- package/src/utils/interfaces/IWETH.sol +10 -0
- package/src/utils/libraries/BasisPoints.sol +24 -0
- package/src/utils/libraries/Create2Utils.sol +74 -0
- package/src/utils/libraries/CurrencyTransfer.sol +99 -0
- package/src/utils/libraries/CustomRevert.sol +49 -0
- package/src/utils/libraries/Factory.sol +66 -0
- package/src/utils/libraries/StringSet.sol +190 -0
- package/src/utils/libraries/Validator.sol +31 -0
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
pragma solidity ^0.8.23;
|
|
3
|
+
|
|
4
|
+
// interfaces
|
|
5
|
+
|
|
6
|
+
// libraries
|
|
7
|
+
|
|
8
|
+
// contracts
|
|
9
|
+
|
|
10
|
+
library SpaceOwnerStorage {
|
|
11
|
+
// keccak256(abi.encode(uint256(keccak256("spaces.facets.owner.storage")) - 1)) &
|
|
12
|
+
// ~bytes32(uint256(0xff))
|
|
13
|
+
bytes32 internal constant STORAGE_SLOT =
|
|
14
|
+
0x7fc24c9500f4388b797f8975c0991ad4ffd0338c2cbf5335b2bf5b7fe5747700;
|
|
15
|
+
|
|
16
|
+
struct Space {
|
|
17
|
+
string name;
|
|
18
|
+
string uri;
|
|
19
|
+
uint256 tokenId;
|
|
20
|
+
uint256 createdAt;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
struct SpaceMetadata {
|
|
24
|
+
string shortDescription;
|
|
25
|
+
string longDescription;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
struct Layout {
|
|
29
|
+
address factory;
|
|
30
|
+
mapping(uint256 => address) spaceByTokenId;
|
|
31
|
+
mapping(address => Space) spaceByAddress;
|
|
32
|
+
mapping(address => SpaceMetadata) spaceMetadata;
|
|
33
|
+
string defaultUri;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function layout() internal pure returns (Layout storage l) {
|
|
37
|
+
assembly {
|
|
38
|
+
l.slot := STORAGE_SLOT
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
pragma solidity ^0.8.23;
|
|
3
|
+
|
|
4
|
+
// interfaces
|
|
5
|
+
import {ISpaceOwnerBase} from "src/spaces/facets/owner/ISpaceOwner.sol";
|
|
6
|
+
|
|
7
|
+
// libraries
|
|
8
|
+
import {Validator} from "../../../utils/libraries/Validator.sol";
|
|
9
|
+
import {LibString} from "solady/utils/LibString.sol";
|
|
10
|
+
|
|
11
|
+
// contracts
|
|
12
|
+
import {SpaceOwnerStorage} from "src/spaces/facets/owner/SpaceOwnerStorage.sol";
|
|
13
|
+
|
|
14
|
+
abstract contract SpaceOwnerUriBase is ISpaceOwnerBase {
|
|
15
|
+
using LibString for address;
|
|
16
|
+
|
|
17
|
+
function _setDefaultUri(string memory uri) internal {
|
|
18
|
+
Validator.checkLength(uri, 1);
|
|
19
|
+
|
|
20
|
+
SpaceOwnerStorage.layout().defaultUri = uri;
|
|
21
|
+
emit SpaceOwner__SetDefaultUri(uri);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function _getDefaultUri() internal view returns (string memory) {
|
|
25
|
+
return SpaceOwnerStorage.layout().defaultUri;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/// @dev Returns `${space.uri}` or `${defaultUri}/${spaceAddress}`
|
|
29
|
+
function _render(uint256 tokenId) internal view virtual returns (string memory) {
|
|
30
|
+
SpaceOwnerStorage.Layout storage ds = SpaceOwnerStorage.layout();
|
|
31
|
+
address spaceAddress = ds.spaceByTokenId[tokenId];
|
|
32
|
+
|
|
33
|
+
if (spaceAddress == address(0)) revert SpaceOwner__SpaceNotFound();
|
|
34
|
+
|
|
35
|
+
SpaceOwnerStorage.Space storage space = ds.spaceByAddress[spaceAddress];
|
|
36
|
+
|
|
37
|
+
// if the space has set a uri, return it
|
|
38
|
+
if (bytes(space.uri).length != 0) return space.uri;
|
|
39
|
+
|
|
40
|
+
string memory defaultUri = ds.defaultUri;
|
|
41
|
+
|
|
42
|
+
uint256 length = bytes(defaultUri).length;
|
|
43
|
+
if (length == 0) revert SpaceOwner__DefaultUriNotSet();
|
|
44
|
+
|
|
45
|
+
unchecked {
|
|
46
|
+
// the ASCII code for "/" is 0x2f
|
|
47
|
+
if (bytes(defaultUri)[length - 1] != 0x2f) {
|
|
48
|
+
return string.concat(defaultUri, "/", spaceAddress.toHexStringChecksummed());
|
|
49
|
+
} else {
|
|
50
|
+
return string.concat(defaultUri, spaceAddress.toHexStringChecksummed());
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
pragma solidity ^0.8.23;
|
|
3
|
+
|
|
4
|
+
// interfaces
|
|
5
|
+
import {ITownsPoints} from "../../../airdrop/points/ITownsPoints.sol";
|
|
6
|
+
import {IImplementationRegistry} from "../../../factory/facets/registry/IImplementationRegistry.sol";
|
|
7
|
+
|
|
8
|
+
// libraries
|
|
9
|
+
import {MembershipStorage} from "../membership/MembershipStorage.sol";
|
|
10
|
+
|
|
11
|
+
// contracts
|
|
12
|
+
|
|
13
|
+
/// @notice Base contract for interacting with the TownsPoints contract
|
|
14
|
+
abstract contract PointsBase {
|
|
15
|
+
/// @dev The implementation ID for the TownsPoints contract
|
|
16
|
+
bytes32 internal constant AIRDROP_DIAMOND = bytes32("RiverAirdrop");
|
|
17
|
+
|
|
18
|
+
function _getAirdropDiamond() internal view returns (address) {
|
|
19
|
+
return
|
|
20
|
+
IImplementationRegistry(MembershipStorage.layout().spaceFactory)
|
|
21
|
+
.getLatestImplementation(AIRDROP_DIAMOND);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function _getPoints(
|
|
25
|
+
address airdropDiamond,
|
|
26
|
+
ITownsPoints.Action action,
|
|
27
|
+
bytes memory data
|
|
28
|
+
) internal view returns (uint256) {
|
|
29
|
+
return ITownsPoints(airdropDiamond).getPoints(action, data);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function _mintPoints(address airdropDiamond, address to, uint256 amount) internal {
|
|
33
|
+
ITownsPoints(airdropDiamond).mint(to, amount);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
pragma solidity ^0.8.23;
|
|
3
|
+
|
|
4
|
+
// interfaces
|
|
5
|
+
|
|
6
|
+
// libraries
|
|
7
|
+
|
|
8
|
+
// contracts
|
|
9
|
+
interface IPrepayBase {
|
|
10
|
+
// =============================================================
|
|
11
|
+
// ERRORS
|
|
12
|
+
// =============================================================
|
|
13
|
+
error Prepay__InvalidSupplyAmount();
|
|
14
|
+
error Prepay__InvalidAmount();
|
|
15
|
+
error Prepay__InvalidAddress();
|
|
16
|
+
error Prepay__InvalidMembership();
|
|
17
|
+
|
|
18
|
+
// =============================================================
|
|
19
|
+
// EVENTS
|
|
20
|
+
// =============================================================
|
|
21
|
+
event Prepay__Prepaid(uint256 supply);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
interface IPrepay is IPrepayBase {
|
|
25
|
+
/**
|
|
26
|
+
* @notice Prepay a membership
|
|
27
|
+
* @param supply The amount of memberships to prepay
|
|
28
|
+
*/
|
|
29
|
+
function prepayMembership(uint256 supply) external payable;
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* @notice Get the prepaid supply
|
|
33
|
+
* @return The remaining prepaid supply
|
|
34
|
+
*/
|
|
35
|
+
function prepaidMembershipSupply() external view returns (uint256);
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* @notice Calculate the prepay fee for a given supply
|
|
39
|
+
* @param supply The supply to calculate the fee for
|
|
40
|
+
* @return The fee
|
|
41
|
+
*/
|
|
42
|
+
function calculateMembershipPrepayFee(uint256 supply) external view returns (uint256);
|
|
43
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
pragma solidity ^0.8.23;
|
|
3
|
+
|
|
4
|
+
// interfaces
|
|
5
|
+
import {IPrepayBase} from "./IPrepay.sol";
|
|
6
|
+
|
|
7
|
+
// libraries
|
|
8
|
+
import {PrepayStorage} from "./PrepayStorage.sol";
|
|
9
|
+
|
|
10
|
+
// contracts
|
|
11
|
+
|
|
12
|
+
abstract contract PrepayBase is IPrepayBase {
|
|
13
|
+
function _addPrepay(uint256 supply) internal {
|
|
14
|
+
PrepayStorage.Layout storage ds = PrepayStorage.layout();
|
|
15
|
+
ds.supply += supply;
|
|
16
|
+
emit Prepay__Prepaid(supply);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function _reducePrepay(uint256 supply) internal {
|
|
20
|
+
PrepayStorage.Layout storage ds = PrepayStorage.layout();
|
|
21
|
+
ds.supply -= supply;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function _getPrepaidSupply() internal view returns (uint256) {
|
|
25
|
+
return PrepayStorage.layout().supply;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
pragma solidity ^0.8.23;
|
|
3
|
+
|
|
4
|
+
// interfaces
|
|
5
|
+
|
|
6
|
+
import {IPlatformRequirements} from "src/factory/facets/platform/requirements/IPlatformRequirements.sol";
|
|
7
|
+
import {IPrepay} from "src/spaces/facets/prepay/IPrepay.sol";
|
|
8
|
+
|
|
9
|
+
// libraries
|
|
10
|
+
import {MembershipStorage} from "src/spaces/facets/membership/MembershipStorage.sol";
|
|
11
|
+
import {CurrencyTransfer} from "src/utils/libraries/CurrencyTransfer.sol";
|
|
12
|
+
|
|
13
|
+
// contracts
|
|
14
|
+
import {PrepayBase} from "./PrepayBase.sol";
|
|
15
|
+
|
|
16
|
+
import {Facet} from "@towns-protocol/diamond/src/facets/Facet.sol";
|
|
17
|
+
import {Entitled} from "src/spaces/facets/Entitled.sol";
|
|
18
|
+
import {ReentrancyGuard} from "solady/utils/ReentrancyGuard.sol";
|
|
19
|
+
|
|
20
|
+
contract PrepayFacet is IPrepay, PrepayBase, ReentrancyGuard, Entitled, Facet {
|
|
21
|
+
function __PrepayFacet_init() external onlyInitializing {
|
|
22
|
+
_addInterface(type(IPrepay).interfaceId);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function prepayMembership(uint256 supply) external payable nonReentrant {
|
|
26
|
+
if (supply == 0) revert Prepay__InvalidSupplyAmount();
|
|
27
|
+
|
|
28
|
+
MembershipStorage.Layout storage ds = MembershipStorage.layout();
|
|
29
|
+
IPlatformRequirements platform = IPlatformRequirements(ds.spaceFactory);
|
|
30
|
+
|
|
31
|
+
uint256 cost = supply * platform.getMembershipFee();
|
|
32
|
+
|
|
33
|
+
// validate payment covers membership fee
|
|
34
|
+
if (msg.value != cost) revert Prepay__InvalidAmount();
|
|
35
|
+
|
|
36
|
+
// add prepay
|
|
37
|
+
_addPrepay(supply);
|
|
38
|
+
|
|
39
|
+
// transfer fee to platform recipient
|
|
40
|
+
address currency = ds.membershipCurrency;
|
|
41
|
+
address platformRecipient = platform.getFeeRecipient();
|
|
42
|
+
CurrencyTransfer.transferCurrency(
|
|
43
|
+
currency,
|
|
44
|
+
msg.sender, // from
|
|
45
|
+
platformRecipient, // to
|
|
46
|
+
cost
|
|
47
|
+
);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function prepaidMembershipSupply() external view returns (uint256) {
|
|
51
|
+
return _getPrepaidSupply();
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function calculateMembershipPrepayFee(uint256 supply) external view returns (uint256) {
|
|
55
|
+
MembershipStorage.Layout storage ds = MembershipStorage.layout();
|
|
56
|
+
IPlatformRequirements platform = IPlatformRequirements(ds.spaceFactory);
|
|
57
|
+
return supply * platform.getMembershipFee();
|
|
58
|
+
}
|
|
59
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
pragma solidity ^0.8.23;
|
|
3
|
+
|
|
4
|
+
// interfaces
|
|
5
|
+
|
|
6
|
+
// libraries
|
|
7
|
+
|
|
8
|
+
// contracts
|
|
9
|
+
|
|
10
|
+
library PrepayStorage {
|
|
11
|
+
// keccak256(abi.encode(uint256(keccak256("spaces.facets.prepay.storage")) - 1)) &
|
|
12
|
+
// ~bytes32(uint256(0xff))
|
|
13
|
+
bytes32 constant STORAGE_SLOT =
|
|
14
|
+
0x097b4f25b64e012d0cf55f67e9b34fe5d57f15b11b95baa4ddd136b424967c00;
|
|
15
|
+
|
|
16
|
+
struct Layout {
|
|
17
|
+
uint256 supply;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function layout() internal pure returns (Layout storage l) {
|
|
21
|
+
bytes32 slot = STORAGE_SLOT;
|
|
22
|
+
assembly {
|
|
23
|
+
l.slot := slot
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
pragma solidity ^0.8.23;
|
|
3
|
+
|
|
4
|
+
// interfaces
|
|
5
|
+
|
|
6
|
+
import {ITokenOwnableBase} from "@towns-protocol/diamond/src/facets/ownable/token/ITokenOwnable.sol";
|
|
7
|
+
import {IManagedProxyBase} from "@towns-protocol/diamond/src/proxy/managed/IManagedProxy.sol";
|
|
8
|
+
import {IMembershipBase} from "src/spaces/facets/membership/IMembership.sol";
|
|
9
|
+
|
|
10
|
+
// libraries
|
|
11
|
+
|
|
12
|
+
// contracts
|
|
13
|
+
|
|
14
|
+
interface ISpaceProxyInitializer is ITokenOwnableBase, IMembershipBase, IManagedProxyBase {
|
|
15
|
+
function initialize(
|
|
16
|
+
address owner,
|
|
17
|
+
address manager,
|
|
18
|
+
TokenOwnable memory tokenOwnable,
|
|
19
|
+
Membership memory membership
|
|
20
|
+
) external;
|
|
21
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
pragma solidity ^0.8.23;
|
|
3
|
+
|
|
4
|
+
import {Address} from "@openzeppelin/contracts/utils/Address.sol";
|
|
5
|
+
import {ManagedProxyBase} from "@towns-protocol/diamond/src/proxy/managed/ManagedProxyBase.sol";
|
|
6
|
+
import {Multicallable} from "solady/utils/Multicallable.sol";
|
|
7
|
+
|
|
8
|
+
contract SpaceProxy is ManagedProxyBase, Multicallable {
|
|
9
|
+
constructor(ManagedProxy memory init, address initializer, bytes memory data) {
|
|
10
|
+
__ManagedProxyBase_init(init);
|
|
11
|
+
Address.functionDelegateCall(initializer, data);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
receive() external payable {}
|
|
15
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
pragma solidity ^0.8.23;
|
|
3
|
+
|
|
4
|
+
// interfaces
|
|
5
|
+
|
|
6
|
+
import {IERC173} from "@towns-protocol/diamond/src/facets/ownable/IERC173.sol";
|
|
7
|
+
import {IERC5643} from "src/diamond/facets/token/ERC5643/IERC5643.sol";
|
|
8
|
+
import {IMembership} from "src/spaces/facets/membership/IMembership.sol";
|
|
9
|
+
import {ISpaceProxyInitializer} from "src/spaces/facets/proxy/ISpaceProxyInitializer.sol";
|
|
10
|
+
|
|
11
|
+
// libraries
|
|
12
|
+
|
|
13
|
+
// contracts
|
|
14
|
+
|
|
15
|
+
import {Initializable} from "@towns-protocol/diamond/src/facets/initializable/Initializable.sol";
|
|
16
|
+
import {IntrospectionBase} from "@towns-protocol/diamond/src/facets/introspection/IntrospectionBase.sol";
|
|
17
|
+
import {TokenOwnableBase} from "@towns-protocol/diamond/src/facets/ownable/token/TokenOwnableBase.sol";
|
|
18
|
+
import {ERC721ABase} from "src/diamond/facets/token/ERC721A/ERC721ABase.sol";
|
|
19
|
+
import {EntitlementGatedBase} from "src/spaces/facets/gated/EntitlementGatedBase.sol";
|
|
20
|
+
import {MembershipBase} from "src/spaces/facets/membership/MembershipBase.sol";
|
|
21
|
+
|
|
22
|
+
contract SpaceProxyInitializer is
|
|
23
|
+
ISpaceProxyInitializer,
|
|
24
|
+
IntrospectionBase,
|
|
25
|
+
TokenOwnableBase,
|
|
26
|
+
ERC721ABase,
|
|
27
|
+
MembershipBase,
|
|
28
|
+
EntitlementGatedBase,
|
|
29
|
+
Initializable
|
|
30
|
+
{
|
|
31
|
+
function initialize(
|
|
32
|
+
address owner,
|
|
33
|
+
address manager,
|
|
34
|
+
TokenOwnable memory tokenOwnable,
|
|
35
|
+
Membership memory membership
|
|
36
|
+
) external initializer {
|
|
37
|
+
__IntrospectionBase_init();
|
|
38
|
+
__TokenOwnableBase_init(tokenOwnable);
|
|
39
|
+
__ERC721ABase_init(membership.name, membership.symbol);
|
|
40
|
+
__MembershipBase_init(membership, manager);
|
|
41
|
+
|
|
42
|
+
_safeMint(owner, 1);
|
|
43
|
+
_setFallbackEntitlementChecker();
|
|
44
|
+
|
|
45
|
+
_setInterfaceIds();
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function _setInterfaceIds() internal {
|
|
49
|
+
_addInterface(0x80ac58cd); // ERC165 Interface ID for ERC721
|
|
50
|
+
_addInterface(0x5b5e139f); // ERC165 Interface ID for ERC721Metadata
|
|
51
|
+
_addInterface(type(IERC5643).interfaceId); // ERC165 Interface ID for IERC5643
|
|
52
|
+
_addInterface(type(IERC173).interfaceId); // ERC165 Interface ID for IERC173 (owner)
|
|
53
|
+
_addInterface(type(IMembership).interfaceId); // ERC165 Interface ID for IMembership
|
|
54
|
+
}
|
|
55
|
+
}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
pragma solidity ^0.8.23;
|
|
3
|
+
|
|
4
|
+
// interfaces
|
|
5
|
+
|
|
6
|
+
// libraries
|
|
7
|
+
|
|
8
|
+
// contracts
|
|
9
|
+
|
|
10
|
+
/// @title IReferralsBase
|
|
11
|
+
/// @notice Base interface for referral functionality
|
|
12
|
+
interface IReferralsBase {
|
|
13
|
+
/// @notice Structure to represent a referral
|
|
14
|
+
/// @param referralCode Unique code for the referral
|
|
15
|
+
/// @param basisPoints Percentage of the referral reward in basis points
|
|
16
|
+
/// @param recipient Address to receive the referral reward
|
|
17
|
+
struct Referral {
|
|
18
|
+
string referralCode;
|
|
19
|
+
uint256 basisPoints;
|
|
20
|
+
address recipient;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
// errors
|
|
24
|
+
|
|
25
|
+
/// @notice Error thrown when an invalid referral code is provided
|
|
26
|
+
error Referrals__InvalidReferralCode();
|
|
27
|
+
/// @notice Error thrown when invalid basis points are provided
|
|
28
|
+
error Referrals__InvalidBasisPoints();
|
|
29
|
+
/// @notice Error thrown when an invalid recipient address is provided
|
|
30
|
+
error Referrals__InvalidRecipient();
|
|
31
|
+
/// @notice Error thrown when an invalid bps fee is provided
|
|
32
|
+
error Referrals__InvalidBpsFee();
|
|
33
|
+
/// @notice Error thrown when a referral already exists
|
|
34
|
+
error Referrals__ReferralAlreadyExists();
|
|
35
|
+
|
|
36
|
+
// events
|
|
37
|
+
|
|
38
|
+
/// @notice Event emitted when a new referral is registered
|
|
39
|
+
/// @param referralCode Unique identifier for the referral
|
|
40
|
+
/// @param basisPoints Percentage of the referral reward in basis points
|
|
41
|
+
/// @param recipient Address to receive the referral reward
|
|
42
|
+
event ReferralRegistered(bytes32 referralCode, uint256 basisPoints, address recipient);
|
|
43
|
+
|
|
44
|
+
/// @notice Event emitted when a referral is updated
|
|
45
|
+
/// @param referralCode Unique identifier for the referral
|
|
46
|
+
/// @param basisPoints Updated percentage of the referral reward in basis points
|
|
47
|
+
/// @param recipient Updated address to receive the referral reward
|
|
48
|
+
event ReferralUpdated(bytes32 referralCode, uint256 basisPoints, address recipient);
|
|
49
|
+
|
|
50
|
+
/// @notice Event emitted when a referral is removed
|
|
51
|
+
/// @param referralCode Unique identifier for the referral
|
|
52
|
+
event ReferralRemoved(bytes32 referralCode);
|
|
53
|
+
|
|
54
|
+
/// @notice Event emitted when the max bps fee is updated
|
|
55
|
+
/// @param maxBpsFee The new max bps fee
|
|
56
|
+
event MaxBpsFeeUpdated(uint256 maxBpsFee);
|
|
57
|
+
|
|
58
|
+
/// @notice Event emitted when the default bps fee is updated
|
|
59
|
+
/// @param defaultBpsFee The new default bps fee
|
|
60
|
+
event DefaultBpsFeeUpdated(uint256 defaultBpsFee);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/// @title IReferrals
|
|
64
|
+
/// @notice Interface for managing referrals
|
|
65
|
+
interface IReferrals is IReferralsBase {
|
|
66
|
+
/// @notice Register a new referral
|
|
67
|
+
/// @param referral The referral information to register
|
|
68
|
+
function registerReferral(Referral memory referral) external;
|
|
69
|
+
|
|
70
|
+
/// @notice Get information about a specific referral
|
|
71
|
+
/// @param referralCode The unique code of the referral to retrieve
|
|
72
|
+
/// @return The referral information
|
|
73
|
+
function referralInfo(string memory referralCode) external view returns (Referral memory);
|
|
74
|
+
|
|
75
|
+
/// @notice Update a referral
|
|
76
|
+
/// @param referral The referral information to update
|
|
77
|
+
function updateReferral(Referral memory referral) external;
|
|
78
|
+
|
|
79
|
+
/// @notice Remove a referral
|
|
80
|
+
/// @param referralCode The unique code of the referral to remove
|
|
81
|
+
function removeReferral(string memory referralCode) external;
|
|
82
|
+
|
|
83
|
+
/// @notice Set the max bps fee
|
|
84
|
+
/// @param bps The new max bps fee
|
|
85
|
+
function setMaxBpsFee(uint256 bps) external;
|
|
86
|
+
|
|
87
|
+
/// @notice Get the max bps fee
|
|
88
|
+
/// @return The max bps fee
|
|
89
|
+
function maxBpsFee() external view returns (uint256);
|
|
90
|
+
|
|
91
|
+
/// @notice Set the default bps fee
|
|
92
|
+
/// @param bps The new default bps fee
|
|
93
|
+
function setDefaultBpsFee(uint256 bps) external;
|
|
94
|
+
|
|
95
|
+
/// @notice Get the default bps fee
|
|
96
|
+
/// @return The default bps fee
|
|
97
|
+
function defaultBpsFee() external view returns (uint256);
|
|
98
|
+
}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
pragma solidity ^0.8.23;
|
|
3
|
+
|
|
4
|
+
import {IReferralsBase} from "./IReferrals.sol";
|
|
5
|
+
import {ReferralsStorage} from "./ReferralsStorage.sol";
|
|
6
|
+
|
|
7
|
+
abstract contract ReferralsBase is IReferralsBase {
|
|
8
|
+
function _validateReferral(Referral memory referral) internal view {
|
|
9
|
+
if (referral.recipient == address(0)) revert Referrals__InvalidRecipient();
|
|
10
|
+
if (referral.basisPoints == 0) revert Referrals__InvalidBasisPoints();
|
|
11
|
+
if (bytes(referral.referralCode).length == 0) {
|
|
12
|
+
revert Referrals__InvalidReferralCode();
|
|
13
|
+
}
|
|
14
|
+
uint256 maxBpsFee = _maxBpsFee();
|
|
15
|
+
if (maxBpsFee > 0 && referral.basisPoints > maxBpsFee) {
|
|
16
|
+
revert Referrals__InvalidBpsFee();
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function _registerReferral(Referral memory referral) internal {
|
|
21
|
+
bytes32 referralCode = keccak256(bytes(referral.referralCode));
|
|
22
|
+
ReferralsStorage.Layout storage ds = ReferralsStorage.layout();
|
|
23
|
+
if (ds.referrals[referralCode].recipient != address(0)) {
|
|
24
|
+
revert Referrals__ReferralAlreadyExists();
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
_validateReferral(referral);
|
|
28
|
+
|
|
29
|
+
ds.referrals[referralCode] = ReferralsStorage.Referral(
|
|
30
|
+
referral.basisPoints,
|
|
31
|
+
referral.recipient
|
|
32
|
+
);
|
|
33
|
+
|
|
34
|
+
emit ReferralRegistered(referralCode, referral.basisPoints, referral.recipient);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function _referralInfo(string memory referralCode) internal view returns (Referral memory) {
|
|
38
|
+
ReferralsStorage.Referral storage storedReferral = ReferralsStorage.layout().referrals[
|
|
39
|
+
keccak256(bytes(referralCode))
|
|
40
|
+
];
|
|
41
|
+
return Referral(referralCode, storedReferral.bpsFee, storedReferral.recipient);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function _updateReferral(Referral memory referral) internal {
|
|
45
|
+
_validateReferral(referral);
|
|
46
|
+
bytes32 referralCode = keccak256(bytes(referral.referralCode));
|
|
47
|
+
ReferralsStorage.Layout storage ds = ReferralsStorage.layout();
|
|
48
|
+
if (ds.referrals[referralCode].recipient == address(0)) {
|
|
49
|
+
revert Referrals__InvalidReferralCode();
|
|
50
|
+
}
|
|
51
|
+
ds.referrals[referralCode] = ReferralsStorage.Referral(
|
|
52
|
+
referral.basisPoints,
|
|
53
|
+
referral.recipient
|
|
54
|
+
);
|
|
55
|
+
emit ReferralUpdated(referralCode, referral.basisPoints, referral.recipient);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function _removeReferral(string memory referralCode) internal {
|
|
59
|
+
bytes32 referralCodeHash = keccak256(bytes(referralCode));
|
|
60
|
+
delete ReferralsStorage.layout().referrals[referralCodeHash];
|
|
61
|
+
emit ReferralRemoved(referralCodeHash);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function _setMaxBpsFee(uint256 maxBpsFee) internal {
|
|
65
|
+
ReferralsStorage.layout().referralSettings.maxBpsFee = maxBpsFee;
|
|
66
|
+
emit MaxBpsFeeUpdated(maxBpsFee);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function _maxBpsFee() internal view returns (uint256) {
|
|
70
|
+
return ReferralsStorage.layout().referralSettings.maxBpsFee;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function _setDefaultBpsFee(uint256 defaultBpsFee) internal {
|
|
74
|
+
ReferralsStorage.layout().referralSettings.defaultBpsFee = defaultBpsFee;
|
|
75
|
+
emit DefaultBpsFeeUpdated(defaultBpsFee);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
function _defaultBpsFee() internal view returns (uint256) {
|
|
79
|
+
return ReferralsStorage.layout().referralSettings.defaultBpsFee;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
pragma solidity ^0.8.23;
|
|
3
|
+
|
|
4
|
+
// interfaces
|
|
5
|
+
|
|
6
|
+
// libraries
|
|
7
|
+
import {Permissions} from "src/spaces/facets/Permissions.sol";
|
|
8
|
+
|
|
9
|
+
// contracts
|
|
10
|
+
|
|
11
|
+
import {IReferrals} from "./IReferrals.sol";
|
|
12
|
+
import {ReferralsBase} from "./ReferralsBase.sol";
|
|
13
|
+
import {Facet} from "@towns-protocol/diamond/src/facets/Facet.sol";
|
|
14
|
+
import {Entitled} from "src/spaces/facets/Entitled.sol";
|
|
15
|
+
|
|
16
|
+
contract ReferralsFacet is IReferrals, ReferralsBase, Entitled, Facet {
|
|
17
|
+
function __ReferralsFacet_init() external onlyInitializing {
|
|
18
|
+
_addInterface(type(IReferrals).interfaceId);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/// @inheritdoc IReferrals
|
|
22
|
+
function registerReferral(Referral memory referral) external {
|
|
23
|
+
_validatePermission(Permissions.ModifySpaceSettings);
|
|
24
|
+
_registerReferral(referral);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/// @inheritdoc IReferrals
|
|
28
|
+
function referralInfo(string memory referralCode) external view returns (Referral memory) {
|
|
29
|
+
return _referralInfo(referralCode);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/// @inheritdoc IReferrals
|
|
33
|
+
function updateReferral(Referral memory referral) external {
|
|
34
|
+
_validatePermission(Permissions.ModifySpaceSettings);
|
|
35
|
+
_updateReferral(referral);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/// @inheritdoc IReferrals
|
|
39
|
+
function removeReferral(string memory referralCode) external {
|
|
40
|
+
_validatePermission(Permissions.ModifySpaceSettings);
|
|
41
|
+
_removeReferral(referralCode);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/// @inheritdoc IReferrals
|
|
45
|
+
function setMaxBpsFee(uint256 bps) external {
|
|
46
|
+
_validatePermission(Permissions.ModifySpaceSettings);
|
|
47
|
+
_setMaxBpsFee(bps);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/// @inheritdoc IReferrals
|
|
51
|
+
function maxBpsFee() external view returns (uint256) {
|
|
52
|
+
return _maxBpsFee();
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/// @inheritdoc IReferrals
|
|
56
|
+
function setDefaultBpsFee(uint256 bps) external {
|
|
57
|
+
_validatePermission(Permissions.ModifySpaceSettings);
|
|
58
|
+
_setDefaultBpsFee(bps);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/// @inheritdoc IReferrals
|
|
62
|
+
function defaultBpsFee() external view returns (uint256) {
|
|
63
|
+
return _defaultBpsFee();
|
|
64
|
+
}
|
|
65
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
pragma solidity ^0.8.23;
|
|
3
|
+
|
|
4
|
+
// interfaces
|
|
5
|
+
|
|
6
|
+
// libraries
|
|
7
|
+
|
|
8
|
+
// contracts
|
|
9
|
+
|
|
10
|
+
library ReferralsStorage {
|
|
11
|
+
// keccak256(abi.encode(uint256(keccak256("spaces.facets.referrals.v2.storage")) - 1)) &
|
|
12
|
+
// ~bytes32(uint256(0xff))
|
|
13
|
+
bytes32 internal constant STORAGE_SLOT =
|
|
14
|
+
0xaca21cc4d2a125f3e0ae03aa135d42b2b9177631aca87599d42a68b47e900800;
|
|
15
|
+
|
|
16
|
+
struct Referral {
|
|
17
|
+
uint256 bpsFee; // fee in basis points
|
|
18
|
+
address recipient;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
struct ReferralSettings {
|
|
22
|
+
uint256 maxBpsFee; // fee in basis points
|
|
23
|
+
uint256 defaultBpsFee; // fee in basis points
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
struct Layout {
|
|
27
|
+
ReferralSettings referralSettings;
|
|
28
|
+
mapping(bytes32 referralCode => Referral) referrals;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function layout() internal pure returns (Layout storage ds) {
|
|
32
|
+
assembly {
|
|
33
|
+
ds.slot := STORAGE_SLOT
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|