@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,275 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
pragma solidity ^0.8.23;
|
|
3
|
+
|
|
4
|
+
// interfaces
|
|
5
|
+
import {IAppAccountBase} from "./IAppAccount.sol";
|
|
6
|
+
import {IAppRegistry} from "src/apps/facets/registry/AppRegistryFacet.sol";
|
|
7
|
+
import {ITownsApp} from "src/apps/ITownsApp.sol";
|
|
8
|
+
import {IERC6900Module} from "@erc6900/reference-implementation/interfaces/IERC6900Module.sol";
|
|
9
|
+
import {IERC6900ExecutionModule} from "@erc6900/reference-implementation/interfaces/IERC6900ExecutionModule.sol";
|
|
10
|
+
import {IERC6900Account} from "@erc6900/reference-implementation/interfaces/IERC6900Account.sol";
|
|
11
|
+
import {IERC165} from "@openzeppelin/contracts/utils/introspection/IERC165.sol";
|
|
12
|
+
import {IDiamondCut} from "@towns-protocol/diamond/src/facets/cut/IDiamondCut.sol";
|
|
13
|
+
import {IAppRegistryBase} from "src/apps/facets/registry/IAppRegistry.sol";
|
|
14
|
+
|
|
15
|
+
// libraries
|
|
16
|
+
import {MembershipStorage} from "src/spaces/facets/membership/MembershipStorage.sol";
|
|
17
|
+
import {CustomRevert} from "src/utils/libraries/CustomRevert.sol";
|
|
18
|
+
import {DependencyLib} from "../DependencyLib.sol";
|
|
19
|
+
import {LibCall} from "solady/utils/LibCall.sol";
|
|
20
|
+
import {AppAccountStorage} from "./AppAccountStorage.sol";
|
|
21
|
+
import {EnumerableSetLib} from "solady/utils/EnumerableSetLib.sol";
|
|
22
|
+
|
|
23
|
+
// contracts
|
|
24
|
+
import {ExecutorBase} from "../executor/ExecutorBase.sol";
|
|
25
|
+
import {TokenOwnableBase} from "@towns-protocol/diamond/src/facets/ownable/token/TokenOwnableBase.sol";
|
|
26
|
+
|
|
27
|
+
// types
|
|
28
|
+
import {ExecutionManifest, ManifestExecutionFunction} from "@erc6900/reference-implementation/interfaces/IERC6900ExecutionModule.sol";
|
|
29
|
+
import {Attestation, EMPTY_UID} from "@ethereum-attestation-service/eas-contracts/Common.sol";
|
|
30
|
+
|
|
31
|
+
abstract contract AppAccountBase is
|
|
32
|
+
IAppAccountBase,
|
|
33
|
+
IAppRegistryBase,
|
|
34
|
+
TokenOwnableBase,
|
|
35
|
+
ExecutorBase
|
|
36
|
+
{
|
|
37
|
+
using CustomRevert for bytes4;
|
|
38
|
+
using EnumerableSetLib for EnumerableSetLib.AddressSet;
|
|
39
|
+
using DependencyLib for MembershipStorage.Layout;
|
|
40
|
+
|
|
41
|
+
uint48 private constant DEFAULT_DURATION = 365 days;
|
|
42
|
+
|
|
43
|
+
// External Functions
|
|
44
|
+
function _onlyRegistry() internal view {
|
|
45
|
+
if (msg.sender != address(_getAppRegistry())) InvalidCaller.selector.revertWith();
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function _installApp(bytes32 appId, bytes calldata postInstallData) internal {
|
|
49
|
+
if (appId == EMPTY_UID) InvalidAppId.selector.revertWith();
|
|
50
|
+
|
|
51
|
+
// get the app
|
|
52
|
+
App memory app = _getAppRegistry().getAppById(appId);
|
|
53
|
+
|
|
54
|
+
if (app.appId == EMPTY_UID) AppNotRegistered.selector.revertWith();
|
|
55
|
+
|
|
56
|
+
// verify if already installed
|
|
57
|
+
if (_isAppInstalled(app.module)) AppAlreadyInstalled.selector.revertWith();
|
|
58
|
+
|
|
59
|
+
// set the group status to active
|
|
60
|
+
_setGroupStatus(app.appId, true, _getAppExpiration(app.appId, app.duration));
|
|
61
|
+
_addApp(app.module, app.appId);
|
|
62
|
+
_grantGroupAccess({
|
|
63
|
+
groupId: app.appId,
|
|
64
|
+
account: app.client,
|
|
65
|
+
grantDelay: _getGroupGrantDelay(app.appId),
|
|
66
|
+
executionDelay: 0
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
// Set up execution functions with the same module groupId
|
|
70
|
+
uint256 executionFunctionsLength = app.manifest.executionFunctions.length;
|
|
71
|
+
for (uint256 i; i < executionFunctionsLength; ++i) {
|
|
72
|
+
ManifestExecutionFunction memory func = app.manifest.executionFunctions[i];
|
|
73
|
+
|
|
74
|
+
// check if the function is a native function
|
|
75
|
+
if (_isInvalidSelector(func.executionSelector)) {
|
|
76
|
+
UnauthorizedSelector.selector.revertWith();
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
_setTargetFunctionGroup(app.module, func.executionSelector, app.appId);
|
|
80
|
+
|
|
81
|
+
if (!func.allowGlobalValidation) {
|
|
82
|
+
_setTargetFunctionDisabled(app.module, func.executionSelector, true);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
// Call module's onInstall if it has install data using LibCall
|
|
87
|
+
// revert if it fails
|
|
88
|
+
if (postInstallData.length > 0) {
|
|
89
|
+
bytes memory callData = abi.encodeCall(IERC6900Module.onInstall, (postInstallData));
|
|
90
|
+
LibCall.callContract(app.module, 0, callData);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
emit IERC6900Account.ExecutionInstalled(app.module, app.manifest);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
function _uninstallApp(bytes32 appId, bytes calldata uninstallData) internal {
|
|
97
|
+
if (appId == EMPTY_UID) InvalidAppId.selector.revertWith();
|
|
98
|
+
|
|
99
|
+
App memory app = _getAppRegistry().getAppById(appId);
|
|
100
|
+
|
|
101
|
+
if (app.appId == EMPTY_UID) AppNotRegistered.selector.revertWith();
|
|
102
|
+
if (!_isAppInstalled(app.module)) AppNotInstalled.selector.revertWith();
|
|
103
|
+
|
|
104
|
+
_removeApp(app.module);
|
|
105
|
+
|
|
106
|
+
// Remove function _group mappings
|
|
107
|
+
uint256 executionFunctionsLength = app.manifest.executionFunctions.length;
|
|
108
|
+
for (uint256 i; i < executionFunctionsLength; ++i) {
|
|
109
|
+
ManifestExecutionFunction memory func = app.manifest.executionFunctions[i];
|
|
110
|
+
// Set the group to 0 to remove the mapping
|
|
111
|
+
_setTargetFunctionGroup(app.module, func.executionSelector, EMPTY_UID);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
// Revoke module's group access
|
|
115
|
+
_revokeGroupAccess(app.appId, app.client);
|
|
116
|
+
|
|
117
|
+
// Call module's onUninstall if uninstall data is provided
|
|
118
|
+
// don't revert if it fails
|
|
119
|
+
bool onUninstallSuccess = true;
|
|
120
|
+
if (uninstallData.length > 0) {
|
|
121
|
+
// solhint-disable-next-line no-empty-blocks
|
|
122
|
+
try IERC6900Module(app.module).onUninstall(uninstallData) {} catch {
|
|
123
|
+
onUninstallSuccess = false;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
emit IERC6900Account.ExecutionUninstalled(app.module, onUninstallSuccess, app.manifest);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
function _onRenewApp(bytes32 appId, bytes calldata /* data */) internal {
|
|
131
|
+
// Get the app data to determine the duration
|
|
132
|
+
App memory app = _getAppRegistry().getAppById(appId);
|
|
133
|
+
if (app.appId == EMPTY_UID) AppNotRegistered.selector.revertWith();
|
|
134
|
+
|
|
135
|
+
// Calculate the new expiration time (extends current expiration by app duration)
|
|
136
|
+
uint48 newExpiration = _getAppExpiration(app.appId, app.duration);
|
|
137
|
+
|
|
138
|
+
// Update the group expiration
|
|
139
|
+
_setGroupExpiration(app.appId, newExpiration);
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
function _onExecute(
|
|
143
|
+
address target,
|
|
144
|
+
uint256,
|
|
145
|
+
bytes calldata data
|
|
146
|
+
) internal returns (bytes memory result) {
|
|
147
|
+
_checkAuthorized(target);
|
|
148
|
+
(result, ) = _execute(target, 0, data);
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
// Internal Functions
|
|
152
|
+
function _getAppExpiration(
|
|
153
|
+
bytes32 appId,
|
|
154
|
+
uint48 duration
|
|
155
|
+
) internal view returns (uint48 expiration) {
|
|
156
|
+
uint48 currentExpiration = _getGroupExpiration(appId);
|
|
157
|
+
if (currentExpiration > block.timestamp) {
|
|
158
|
+
expiration = currentExpiration + duration;
|
|
159
|
+
} else {
|
|
160
|
+
expiration = uint48(block.timestamp) + duration;
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
function _addApp(address module, bytes32 appId) internal {
|
|
165
|
+
AppAccountStorage.Layout storage $ = AppAccountStorage.getLayout();
|
|
166
|
+
$.installedApps.add(module);
|
|
167
|
+
$.appIdByApp[module] = appId;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
function _removeApp(address module) internal {
|
|
171
|
+
AppAccountStorage.getLayout().installedApps.remove(module);
|
|
172
|
+
delete AppAccountStorage.getLayout().appIdByApp[module];
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
function _enableApp(address app) internal {
|
|
176
|
+
bytes32 appId = AppAccountStorage.getInstalledAppId(app);
|
|
177
|
+
if (appId == EMPTY_UID) AppNotRegistered.selector.revertWith();
|
|
178
|
+
_setGroupStatus(appId, true);
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
function _disableApp(address app) internal {
|
|
182
|
+
bytes32 appId = AppAccountStorage.getInstalledAppId(app);
|
|
183
|
+
if (appId == EMPTY_UID) AppNotRegistered.selector.revertWith();
|
|
184
|
+
_setGroupStatus(appId, false);
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
function _isAppEntitled(
|
|
188
|
+
address module,
|
|
189
|
+
address client,
|
|
190
|
+
bytes32 permission
|
|
191
|
+
) internal view returns (bool) {
|
|
192
|
+
return AppAccountStorage.isAppEntitled(module, client, permission);
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
function _getInstalledAppId(address module) internal view returns (bytes32) {
|
|
196
|
+
return AppAccountStorage.getInstalledAppId(module);
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
function _getApp(address module) internal view returns (App memory app) {
|
|
200
|
+
return AppAccountStorage.getApp(module);
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
function _getAppRegistry() internal view returns (IAppRegistry) {
|
|
204
|
+
return DependencyLib.getAppRegistry();
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
function _getApps() internal view returns (address[] memory) {
|
|
208
|
+
return AppAccountStorage.getLayout().installedApps.values();
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
function _isAppInstalled(address module) internal view returns (bool) {
|
|
212
|
+
return AppAccountStorage.getLayout().installedApps.contains(module);
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
function _checkAuthorized(address module) internal view {
|
|
216
|
+
if (module == address(0)) InvalidAppAddress.selector.revertWith();
|
|
217
|
+
|
|
218
|
+
MembershipStorage.Layout storage ms = MembershipStorage.layout();
|
|
219
|
+
address factory = ms.spaceFactory;
|
|
220
|
+
|
|
221
|
+
bytes32[] memory dependencies = new bytes32[](4);
|
|
222
|
+
dependencies[0] = DependencyLib.RIVER_AIRDROP;
|
|
223
|
+
dependencies[1] = DependencyLib.SPACE_OPERATOR;
|
|
224
|
+
dependencies[2] = DependencyLib.SPACE_OWNER;
|
|
225
|
+
dependencies[3] = DependencyLib.APP_REGISTRY;
|
|
226
|
+
address[] memory deps = ms.getDependencies(dependencies);
|
|
227
|
+
|
|
228
|
+
// Check if app is banned
|
|
229
|
+
if (IAppRegistry(deps[3]).isAppBanned(module)) {
|
|
230
|
+
UnauthorizedApp.selector.revertWith(module);
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
// Check against unauthorized targets
|
|
234
|
+
if (_isUnauthorizedTarget(module, factory, deps)) {
|
|
235
|
+
UnauthorizedApp.selector.revertWith(module);
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
function _isUnauthorizedTarget(
|
|
240
|
+
address module,
|
|
241
|
+
address factory,
|
|
242
|
+
address[] memory deps
|
|
243
|
+
) private pure returns (bool) {
|
|
244
|
+
return
|
|
245
|
+
module == factory || // SpaceFactory
|
|
246
|
+
module == deps[0] || // RiverAirdrop
|
|
247
|
+
module == deps[1] || // BaseRegistry
|
|
248
|
+
module == deps[2] || // SpaceOwner
|
|
249
|
+
module == deps[3]; // AppRegistry
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
function _isInvalidSelector(bytes4 selector) internal pure returns (bool) {
|
|
253
|
+
return
|
|
254
|
+
selector == IERC6900Account.installExecution.selector ||
|
|
255
|
+
selector == IERC6900Account.uninstallExecution.selector ||
|
|
256
|
+
selector == IERC6900Account.installValidation.selector ||
|
|
257
|
+
selector == IERC6900Account.uninstallValidation.selector ||
|
|
258
|
+
selector == IERC6900Account.execute.selector ||
|
|
259
|
+
selector == IERC6900Account.executeBatch.selector ||
|
|
260
|
+
selector == IERC6900Account.executeWithRuntimeValidation.selector ||
|
|
261
|
+
selector == IERC6900Account.accountId.selector ||
|
|
262
|
+
selector == IERC165.supportsInterface.selector ||
|
|
263
|
+
selector == IERC6900Module.moduleId.selector ||
|
|
264
|
+
selector == IERC6900Module.onInstall.selector ||
|
|
265
|
+
selector == IERC6900Module.onUninstall.selector ||
|
|
266
|
+
selector == IERC6900ExecutionModule.executionManifest.selector ||
|
|
267
|
+
selector == IDiamondCut.diamondCut.selector ||
|
|
268
|
+
selector == ITownsApp.requiredPermissions.selector;
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
// Override Functions
|
|
272
|
+
function _getOwner() internal view virtual override returns (address) {
|
|
273
|
+
return _owner();
|
|
274
|
+
}
|
|
275
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
pragma solidity ^0.8.23;
|
|
3
|
+
|
|
4
|
+
// interfaces
|
|
5
|
+
import {IAppRegistry} from "src/apps/facets/registry/IAppRegistry.sol";
|
|
6
|
+
|
|
7
|
+
// libraries
|
|
8
|
+
import {EnumerableSetLib} from "solady/utils/EnumerableSetLib.sol";
|
|
9
|
+
import {ExecutorStorage} from "src/spaces/facets/executor/ExecutorStorage.sol";
|
|
10
|
+
import {DependencyLib} from "src/spaces/facets/DependencyLib.sol";
|
|
11
|
+
import {EMPTY_UID} from "@ethereum-attestation-service/eas-contracts/Common.sol";
|
|
12
|
+
|
|
13
|
+
// contracts
|
|
14
|
+
|
|
15
|
+
library AppAccountStorage {
|
|
16
|
+
// keccak256(abi.encode(uint256(keccak256("spaces.facets.account.storage")) - 1)) & ~bytes32(uint256(0xff))
|
|
17
|
+
bytes32 internal constant STORAGE_SLOT =
|
|
18
|
+
0x5203018779d8301358307033923a3bd0a3a759f1f58591c01f878744c0f8c200;
|
|
19
|
+
|
|
20
|
+
struct Layout {
|
|
21
|
+
EnumerableSetLib.AddressSet installedApps;
|
|
22
|
+
mapping(address app => bytes32 appId) appIdByApp;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function getLayout() internal pure returns (Layout storage $) {
|
|
26
|
+
assembly {
|
|
27
|
+
$.slot := STORAGE_SLOT
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function getInstalledAppId(address module) internal view returns (bytes32) {
|
|
32
|
+
return getLayout().appIdByApp[module];
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function getApp(address module) internal view returns (IAppRegistry.App memory app) {
|
|
36
|
+
bytes32 appId = getInstalledAppId(module);
|
|
37
|
+
if (appId == EMPTY_UID) return app;
|
|
38
|
+
return DependencyLib.getAppRegistry().getAppById(appId);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function isAppEntitled(
|
|
42
|
+
address module,
|
|
43
|
+
address client,
|
|
44
|
+
bytes32 permission
|
|
45
|
+
) internal view returns (bool) {
|
|
46
|
+
IAppRegistry.App memory app = getApp(module);
|
|
47
|
+
|
|
48
|
+
if (app.appId == EMPTY_UID) return false;
|
|
49
|
+
|
|
50
|
+
(bool hasClientAccess, , bool isGroupActive) = ExecutorStorage.hasGroupAccess(
|
|
51
|
+
app.appId,
|
|
52
|
+
client
|
|
53
|
+
);
|
|
54
|
+
if (!hasClientAccess || !isGroupActive) return false;
|
|
55
|
+
|
|
56
|
+
uint256 permissionsLength = app.permissions.length;
|
|
57
|
+
for (uint256 i; i < permissionsLength; ++i) {
|
|
58
|
+
if (app.permissions[i] == permission) return true;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
return false;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
pragma solidity ^0.8.23;
|
|
3
|
+
|
|
4
|
+
// interfaces
|
|
5
|
+
|
|
6
|
+
// libraries
|
|
7
|
+
|
|
8
|
+
// contracts
|
|
9
|
+
interface IAppAccountBase {
|
|
10
|
+
error InvalidAppAddress(address app);
|
|
11
|
+
error InvalidManifest();
|
|
12
|
+
error UnauthorizedSelector();
|
|
13
|
+
error NotEnoughEth();
|
|
14
|
+
error AppAlreadyInstalled();
|
|
15
|
+
error UnauthorizedApp(address app);
|
|
16
|
+
error InvalidCaller();
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
interface IAppAccount is IAppAccountBase {
|
|
20
|
+
/// @notice Installs an app
|
|
21
|
+
/// @param appId The ID of the app to install
|
|
22
|
+
/// @param data The initialization data for the app
|
|
23
|
+
function onInstallApp(bytes32 appId, bytes calldata data) external;
|
|
24
|
+
|
|
25
|
+
/// @notice Uninstalls an app
|
|
26
|
+
/// @param appId The ID of the app to uninstall
|
|
27
|
+
/// @param data The data required for app uninstallation
|
|
28
|
+
function onUninstallApp(bytes32 appId, bytes calldata data) external;
|
|
29
|
+
|
|
30
|
+
/// @notice Renews an app
|
|
31
|
+
/// @param appId The ID of the app to renew
|
|
32
|
+
/// @param data The data required for app renewal
|
|
33
|
+
function onRenewApp(bytes32 appId, bytes calldata data) external;
|
|
34
|
+
|
|
35
|
+
/// @notice Enables an app
|
|
36
|
+
/// @param app The address of the app to enable
|
|
37
|
+
function enableApp(address app) external;
|
|
38
|
+
|
|
39
|
+
/// @notice Disables an app
|
|
40
|
+
/// @param app The address of the app to disable
|
|
41
|
+
function disableApp(address app) external;
|
|
42
|
+
|
|
43
|
+
/// @notice Checks if an app is installed
|
|
44
|
+
/// @param app The address of the app
|
|
45
|
+
function isAppInstalled(address app) external view returns (bool);
|
|
46
|
+
|
|
47
|
+
/// @notice Gets the ID of an app
|
|
48
|
+
/// @param app The address of the app to get the ID of
|
|
49
|
+
/// @return The ID of the app
|
|
50
|
+
function getAppId(address app) external view returns (bytes32);
|
|
51
|
+
|
|
52
|
+
/// @notice Gets the expiration of an app
|
|
53
|
+
/// @param app The address of the app to get the expiration of
|
|
54
|
+
/// @return The expiration of the app
|
|
55
|
+
function getAppExpiration(address app) external view returns (uint48);
|
|
56
|
+
|
|
57
|
+
/// @notice Gets the apps installed on the account
|
|
58
|
+
/// @return The apps installed on the account
|
|
59
|
+
function getInstalledApps() external view returns (address[] memory);
|
|
60
|
+
|
|
61
|
+
/// @notice Checks if a client is entitled to a permission for an app
|
|
62
|
+
/// @param app The address of the app to check
|
|
63
|
+
/// @param publicKey The public key to check
|
|
64
|
+
/// @param permission The permission to check
|
|
65
|
+
/// @return True if the client is entitled to the permission, false otherwise
|
|
66
|
+
function isAppEntitled(
|
|
67
|
+
address app,
|
|
68
|
+
address publicKey,
|
|
69
|
+
bytes32 permission
|
|
70
|
+
) external view returns (bool);
|
|
71
|
+
}
|
|
@@ -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
|
+
import {ERC1271Facet} from "@towns-protocol/diamond/src/facets/accounts/ERC1271Facet.sol";
|
|
10
|
+
import {EIP712Facet} from "@towns-protocol/diamond/src/utils/cryptography/EIP712Facet.sol";
|
|
11
|
+
import {TokenOwnableBase} from "@towns-protocol/diamond/src/facets/ownable/token/TokenOwnableBase.sol";
|
|
12
|
+
|
|
13
|
+
contract SignerFacet is ERC1271Facet, EIP712Facet, TokenOwnableBase {
|
|
14
|
+
function _domainNameAndVersion()
|
|
15
|
+
internal
|
|
16
|
+
pure
|
|
17
|
+
override
|
|
18
|
+
returns (string memory name, string memory version)
|
|
19
|
+
{
|
|
20
|
+
return ("Towns", "1");
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function _erc1271Signer() internal view override returns (address) {
|
|
24
|
+
return _owner();
|
|
25
|
+
}
|
|
26
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
pragma solidity ^0.8.23;
|
|
3
|
+
|
|
4
|
+
// interfaces
|
|
5
|
+
import {IBanning} from "src/spaces/facets/banning/IBanning.sol";
|
|
6
|
+
|
|
7
|
+
// libraries
|
|
8
|
+
import {Permissions} from "src/spaces/facets/Permissions.sol";
|
|
9
|
+
|
|
10
|
+
// contracts
|
|
11
|
+
|
|
12
|
+
import {BanningBase} from "./BanningBase.sol";
|
|
13
|
+
import {Facet} from "@towns-protocol/diamond/src/facets/Facet.sol";
|
|
14
|
+
import {ERC721ABase} from "src/diamond/facets/token/ERC721A/ERC721ABase.sol";
|
|
15
|
+
import {Entitled} from "src/spaces/facets/Entitled.sol";
|
|
16
|
+
|
|
17
|
+
contract Banning is IBanning, BanningBase, ERC721ABase, Entitled, Facet {
|
|
18
|
+
function ban(uint256 tokenId) external {
|
|
19
|
+
_validatePermission(Permissions.ModifyBanning);
|
|
20
|
+
if (!_exists(tokenId)) revert Banning__InvalidTokenId(tokenId);
|
|
21
|
+
if (_ownerOf(tokenId) == _owner()) revert Banning__CannotBanOwner();
|
|
22
|
+
if (_ownerOf(tokenId) == msg.sender) revert Banning__CannotBanSelf();
|
|
23
|
+
if (_isBanned(tokenId)) revert Banning__AlreadyBanned(tokenId);
|
|
24
|
+
_ban(tokenId);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function unban(uint256 tokenId) external {
|
|
28
|
+
if (!_exists(tokenId)) revert Banning__InvalidTokenId(tokenId);
|
|
29
|
+
if (!_isBanned(tokenId)) revert Banning__NotBanned(tokenId);
|
|
30
|
+
_validatePermission(Permissions.ModifyBanning);
|
|
31
|
+
_unban(tokenId);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function isBanned(uint256 tokenId) external view returns (bool) {
|
|
35
|
+
return _isBanned(tokenId);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function banned() external view returns (uint256[] memory) {
|
|
39
|
+
return _bannedTokenIds();
|
|
40
|
+
}
|
|
41
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
pragma solidity ^0.8.23;
|
|
3
|
+
|
|
4
|
+
// interfaces
|
|
5
|
+
import {IBanningBase} from "./IBanning.sol";
|
|
6
|
+
|
|
7
|
+
// libraries
|
|
8
|
+
import {BanningStorage} from "./BanningStorage.sol";
|
|
9
|
+
import {EnumerableSet} from "@openzeppelin/contracts/utils/structs/EnumerableSet.sol";
|
|
10
|
+
|
|
11
|
+
// contracts
|
|
12
|
+
|
|
13
|
+
abstract contract BanningBase is IBanningBase {
|
|
14
|
+
using EnumerableSet for EnumerableSet.UintSet;
|
|
15
|
+
|
|
16
|
+
function _ban(uint256 tokenId) internal {
|
|
17
|
+
BanningStorage.layout().bannedIds.add(tokenId);
|
|
18
|
+
emit Banned(msg.sender, tokenId);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function _isBanned(uint256 tokenId) internal view returns (bool isBanned) {
|
|
22
|
+
return BanningStorage.layout().bannedIds.contains(tokenId);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function _unban(uint256 tokenId) internal {
|
|
26
|
+
BanningStorage.layout().bannedIds.remove(tokenId);
|
|
27
|
+
emit Unbanned(msg.sender, tokenId);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function _bannedTokenIds() internal view returns (uint256[] memory) {
|
|
31
|
+
return BanningStorage.layout().bannedIds.values();
|
|
32
|
+
}
|
|
33
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
pragma solidity ^0.8.23;
|
|
3
|
+
|
|
4
|
+
import {EnumerableSet} from "@openzeppelin/contracts/utils/structs/EnumerableSet.sol";
|
|
5
|
+
|
|
6
|
+
library BanningStorage {
|
|
7
|
+
// keccak256(abi.encode(uint256(keccak256("spaces.facets.banning.storage")) - 1)) &
|
|
8
|
+
// ~bytes32(uint256(0xff))
|
|
9
|
+
bytes32 internal constant STORAGE_SLOT =
|
|
10
|
+
0x49daf035076c43671ca9f9fb568d931e51ab7f9098a5a694781b45341112cf00;
|
|
11
|
+
|
|
12
|
+
struct Layout {
|
|
13
|
+
EnumerableSet.UintSet bannedIds;
|
|
14
|
+
// deprecated
|
|
15
|
+
mapping(uint256 => bool) bannedFromSpace;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function layout() internal pure returns (Layout storage s) {
|
|
19
|
+
assembly {
|
|
20
|
+
s.slot := STORAGE_SLOT
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
pragma solidity ^0.8.23;
|
|
3
|
+
|
|
4
|
+
// interfaces
|
|
5
|
+
|
|
6
|
+
// libraries
|
|
7
|
+
|
|
8
|
+
// contracts
|
|
9
|
+
|
|
10
|
+
interface IBanningBase {
|
|
11
|
+
// =============================================================
|
|
12
|
+
// Errors
|
|
13
|
+
// =============================================================
|
|
14
|
+
error Banning__InvalidTokenId(uint256 tokenId);
|
|
15
|
+
error Banning__AlreadyBanned(uint256 tokenId);
|
|
16
|
+
error Banning__NotBanned(uint256 tokenId);
|
|
17
|
+
error Banning__CannotBanSelf();
|
|
18
|
+
error Banning__CannotBanOwner();
|
|
19
|
+
|
|
20
|
+
// =============================================================
|
|
21
|
+
// Events
|
|
22
|
+
// =============================================================
|
|
23
|
+
event Banned(address indexed moderator, uint256 indexed tokenId);
|
|
24
|
+
event Unbanned(address indexed moderator, uint256 indexed tokenId);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
interface IBanning is IBanningBase {
|
|
28
|
+
function ban(uint256 tokenId) external;
|
|
29
|
+
|
|
30
|
+
function unban(uint256 tokenId) external;
|
|
31
|
+
|
|
32
|
+
function isBanned(uint256 tokenId) external view returns (bool);
|
|
33
|
+
|
|
34
|
+
function banned() external view returns (uint256[] memory);
|
|
35
|
+
}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
pragma solidity ^0.8.23;
|
|
3
|
+
|
|
4
|
+
// interfaces
|
|
5
|
+
import {IChannelBase} from "./IChannel.sol";
|
|
6
|
+
|
|
7
|
+
// libraries
|
|
8
|
+
|
|
9
|
+
// services
|
|
10
|
+
import {ChannelService} from "./ChannelService.sol";
|
|
11
|
+
import {Validator} from "../../../utils/libraries/Validator.sol";
|
|
12
|
+
|
|
13
|
+
abstract contract ChannelBase is IChannelBase {
|
|
14
|
+
function _createChannel(
|
|
15
|
+
bytes32 channelId,
|
|
16
|
+
string calldata metadata,
|
|
17
|
+
uint256[] memory roleIds
|
|
18
|
+
) internal {
|
|
19
|
+
Validator.checkLengthCalldata(metadata, 0);
|
|
20
|
+
ChannelService.createChannel(channelId, metadata, roleIds);
|
|
21
|
+
emit ChannelCreated(msg.sender, channelId);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function _getChannel(bytes32 channelId) internal view returns (Channel memory channel) {
|
|
25
|
+
(, string memory metadata, bool disabled) = ChannelService.getChannel(channelId);
|
|
26
|
+
|
|
27
|
+
uint256[] memory roleIds = ChannelService.getRolesByChannel(channelId);
|
|
28
|
+
|
|
29
|
+
(channel.id, channel.disabled, channel.metadata, channel.roleIds) = (
|
|
30
|
+
channelId,
|
|
31
|
+
disabled,
|
|
32
|
+
metadata,
|
|
33
|
+
roleIds
|
|
34
|
+
);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function _getChannels() internal view returns (Channel[] memory channels) {
|
|
38
|
+
bytes32[] memory channelIds = ChannelService.getChannelIds();
|
|
39
|
+
|
|
40
|
+
channels = new Channel[](channelIds.length);
|
|
41
|
+
|
|
42
|
+
for (uint256 i; i < channelIds.length; ++i) {
|
|
43
|
+
(bytes32 id, string memory metadata, bool disabled) = ChannelService.getChannel(
|
|
44
|
+
channelIds[i]
|
|
45
|
+
);
|
|
46
|
+
uint256[] memory roleIds = ChannelService.getRolesByChannel(channelIds[i]);
|
|
47
|
+
|
|
48
|
+
Channel memory channel = channels[i];
|
|
49
|
+
(channel.id, channel.disabled, channel.metadata, channel.roleIds) = (
|
|
50
|
+
id,
|
|
51
|
+
disabled,
|
|
52
|
+
metadata,
|
|
53
|
+
roleIds
|
|
54
|
+
);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function _setChannelRoleOverrides(bytes32 channelId, uint256[] memory roleIds) internal {
|
|
59
|
+
for (uint256 i; i < roleIds.length; ++i) {
|
|
60
|
+
_addRoleToChannel(channelId, roleIds[i]);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function _updateChannel(bytes32 channelId, string calldata metadata, bool disabled) internal {
|
|
65
|
+
ChannelService.updateChannel(channelId, metadata, disabled);
|
|
66
|
+
emit ChannelUpdated(msg.sender, channelId);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function _removeChannel(bytes32 channelId) internal {
|
|
70
|
+
ChannelService.removeChannel(channelId);
|
|
71
|
+
emit ChannelRemoved(msg.sender, channelId);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function _getRolesByChannel(bytes32 channelId) internal view returns (uint256[] memory) {
|
|
75
|
+
return ChannelService.getRolesByChannel(channelId);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
function _addRoleToChannel(bytes32 channelId, uint256 roleId) internal {
|
|
79
|
+
ChannelService.addRoleToChannel(channelId, roleId);
|
|
80
|
+
emit ChannelRoleAdded(msg.sender, channelId, roleId);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
function _removeRoleFromChannel(bytes32 channelId, uint256 roleId) internal {
|
|
84
|
+
ChannelService.removeRoleFromChannel(channelId, roleId);
|
|
85
|
+
emit ChannelRoleRemoved(msg.sender, channelId, roleId);
|
|
86
|
+
}
|
|
87
|
+
}
|