@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,420 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
pragma solidity ^0.8.23;
|
|
3
|
+
|
|
4
|
+
// interfaces
|
|
5
|
+
import {IEntitlement} from "../../entitlements/IEntitlement.sol";
|
|
6
|
+
import {IRolesBase} from "./IRoles.sol";
|
|
7
|
+
|
|
8
|
+
// libraries
|
|
9
|
+
import {EnumerableSet} from "@openzeppelin/contracts/utils/structs/EnumerableSet.sol";
|
|
10
|
+
import {CustomRevert} from "../../../utils/libraries/CustomRevert.sol";
|
|
11
|
+
import {StringSet} from "../../../utils/libraries/StringSet.sol";
|
|
12
|
+
import {Validator} from "../../../utils/libraries/Validator.sol";
|
|
13
|
+
|
|
14
|
+
// services
|
|
15
|
+
import {ChannelService} from "../channels/ChannelService.sol";
|
|
16
|
+
import {EntitlementsManagerService} from "../entitlements/EntitlementsManagerService.sol";
|
|
17
|
+
import {RolesStorage} from "./RolesStorage.sol";
|
|
18
|
+
|
|
19
|
+
abstract contract RolesBase is IRolesBase {
|
|
20
|
+
using EnumerableSet for EnumerableSet.UintSet;
|
|
21
|
+
using EnumerableSet for EnumerableSet.Bytes32Set;
|
|
22
|
+
using EnumerableSet for EnumerableSet.AddressSet;
|
|
23
|
+
using CustomRevert for bytes4;
|
|
24
|
+
using StringSet for StringSet.Set;
|
|
25
|
+
using RolesStorage for RolesStorage.Role;
|
|
26
|
+
|
|
27
|
+
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
|
|
28
|
+
/* ROLE */
|
|
29
|
+
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
|
|
30
|
+
|
|
31
|
+
function _createRole(
|
|
32
|
+
string calldata roleName,
|
|
33
|
+
string[] calldata permissions,
|
|
34
|
+
CreateEntitlement[] calldata entitlements
|
|
35
|
+
) internal returns (uint256 roleId) {
|
|
36
|
+
Validator.checkLengthCalldata(roleName, 2);
|
|
37
|
+
|
|
38
|
+
uint256 entitlementsLen = entitlements.length;
|
|
39
|
+
|
|
40
|
+
IEntitlement[] memory entitlementAddresses = new IEntitlement[](entitlementsLen);
|
|
41
|
+
|
|
42
|
+
RolesStorage.Layout storage rs = RolesStorage.layout();
|
|
43
|
+
|
|
44
|
+
roleId = ++rs.roleCount;
|
|
45
|
+
|
|
46
|
+
for (uint256 i; i < entitlementsLen; ++i) {
|
|
47
|
+
CreateEntitlement calldata entitlement = entitlements[i];
|
|
48
|
+
EntitlementsManagerService.validateEntitlement(address(entitlement.module));
|
|
49
|
+
entitlementAddresses[i] = entitlement.module;
|
|
50
|
+
|
|
51
|
+
// check for empty address or data
|
|
52
|
+
Validator.checkLengthCalldata(entitlement.data);
|
|
53
|
+
|
|
54
|
+
EntitlementsManagerService.proxyAddRoleToEntitlement(
|
|
55
|
+
address(entitlement.module),
|
|
56
|
+
roleId,
|
|
57
|
+
entitlement.data
|
|
58
|
+
);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
rs.roles.add(roleId);
|
|
62
|
+
|
|
63
|
+
RolesStorage.Role storage role = rs.roleById[roleId];
|
|
64
|
+
role.add(roleName, false, permissions, entitlementAddresses);
|
|
65
|
+
|
|
66
|
+
emit RoleCreated(msg.sender, roleId);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function _getRoles() internal view returns (Role[] memory roles) {
|
|
70
|
+
uint256[] memory roleIds = _getRoleIds();
|
|
71
|
+
uint256 roleIdLen = roleIds.length;
|
|
72
|
+
|
|
73
|
+
roles = new Role[](roleIdLen);
|
|
74
|
+
|
|
75
|
+
for (uint256 i; i < roleIdLen; ++i) {
|
|
76
|
+
(
|
|
77
|
+
string memory name,
|
|
78
|
+
bool isImmutable,
|
|
79
|
+
string[] memory permissions,
|
|
80
|
+
IEntitlement[] memory entitlements
|
|
81
|
+
) = _getRole(roleIds[i]);
|
|
82
|
+
|
|
83
|
+
roles[i] = Role({
|
|
84
|
+
id: roleIds[i],
|
|
85
|
+
name: name,
|
|
86
|
+
disabled: isImmutable,
|
|
87
|
+
permissions: permissions,
|
|
88
|
+
entitlements: entitlements
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
function _getRolesWithPermission(
|
|
94
|
+
string memory permission
|
|
95
|
+
) internal view returns (Role[] memory) {
|
|
96
|
+
uint256[] memory roleIds = _getRoleIds();
|
|
97
|
+
uint256 roleIdLen = roleIds.length;
|
|
98
|
+
Role[] memory rolesWithPermission = new Role[](roleIdLen);
|
|
99
|
+
uint256 count = 0;
|
|
100
|
+
|
|
101
|
+
bytes32 requestedPermission = keccak256(bytes(permission));
|
|
102
|
+
|
|
103
|
+
for (uint256 i; i < roleIdLen; ++i) {
|
|
104
|
+
(
|
|
105
|
+
string memory name,
|
|
106
|
+
bool isImmutable,
|
|
107
|
+
string[] memory permissions,
|
|
108
|
+
IEntitlement[] memory entitlements
|
|
109
|
+
) = _getRole(roleIds[i]);
|
|
110
|
+
|
|
111
|
+
for (uint256 j; j < permissions.length; ++j) {
|
|
112
|
+
if (keccak256(bytes(permissions[j])) == requestedPermission) {
|
|
113
|
+
rolesWithPermission[count] = Role({
|
|
114
|
+
id: roleIds[i],
|
|
115
|
+
name: name,
|
|
116
|
+
disabled: isImmutable,
|
|
117
|
+
permissions: permissions,
|
|
118
|
+
entitlements: entitlements
|
|
119
|
+
});
|
|
120
|
+
++count;
|
|
121
|
+
break;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
// Resize the array to remove unused slots
|
|
127
|
+
assembly {
|
|
128
|
+
mstore(rolesWithPermission, count)
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
return rolesWithPermission;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
function _getRoleById(uint256 roleId) internal view returns (Role memory role) {
|
|
135
|
+
(
|
|
136
|
+
string memory name,
|
|
137
|
+
bool isImmutable,
|
|
138
|
+
string[] memory permissions,
|
|
139
|
+
IEntitlement[] memory entitlements
|
|
140
|
+
) = _getRole(roleId);
|
|
141
|
+
|
|
142
|
+
return
|
|
143
|
+
Role({
|
|
144
|
+
id: roleId,
|
|
145
|
+
name: name,
|
|
146
|
+
disabled: isImmutable,
|
|
147
|
+
permissions: permissions,
|
|
148
|
+
entitlements: entitlements
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
// make nonreentrant
|
|
153
|
+
function _updateRole(
|
|
154
|
+
uint256 roleId,
|
|
155
|
+
string calldata roleName,
|
|
156
|
+
string[] calldata permissions,
|
|
157
|
+
CreateEntitlement[] calldata entitlements
|
|
158
|
+
) internal {
|
|
159
|
+
// check role exists
|
|
160
|
+
_checkRoleExists(roleId);
|
|
161
|
+
|
|
162
|
+
RolesStorage.Role storage role = RolesStorage.layout().roleById[roleId];
|
|
163
|
+
|
|
164
|
+
if (role.isImmutable) Roles__RoleIsImmutable.selector.revertWith();
|
|
165
|
+
|
|
166
|
+
// get current entitlements before updating them
|
|
167
|
+
IEntitlement[] memory currentEntitlements = role.getEntitlements();
|
|
168
|
+
uint256 currentEntitlementsLen = currentEntitlements.length;
|
|
169
|
+
|
|
170
|
+
uint256 entitlementsLen = entitlements.length;
|
|
171
|
+
IEntitlement[] memory entitlementAddresses = new IEntitlement[](entitlementsLen);
|
|
172
|
+
|
|
173
|
+
for (uint256 i; i < entitlementsLen; ++i) {
|
|
174
|
+
address module = address(entitlements[i].module);
|
|
175
|
+
EntitlementsManagerService.validateEntitlement(module);
|
|
176
|
+
EntitlementsManagerService.checkEntitlement(module);
|
|
177
|
+
entitlementAddresses[i] = IEntitlement(module);
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
// Update the role name
|
|
181
|
+
if (bytes(roleName).length > 0) {
|
|
182
|
+
role.name = roleName;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
// Update permissions
|
|
186
|
+
if (permissions.length > 0) {
|
|
187
|
+
// Remove all the current permissions
|
|
188
|
+
role.permissions.clear();
|
|
189
|
+
|
|
190
|
+
// Add all the new permissions
|
|
191
|
+
role.addPermissions(permissions);
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
if (entitlementsLen == 0) return;
|
|
195
|
+
|
|
196
|
+
for (uint256 i; i < currentEntitlementsLen; ++i) {
|
|
197
|
+
role.removeEntitlement(address(currentEntitlements[i]));
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
// Add all the new entitlements
|
|
201
|
+
for (uint256 i; i < entitlementsLen; ++i) {
|
|
202
|
+
role.addEntitlement(address(entitlementAddresses[i]));
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
// loop through old entitlements and remove them
|
|
206
|
+
for (uint256 i; i < currentEntitlementsLen; ++i) {
|
|
207
|
+
// fetch entitlement data and if it's not empty, remove it
|
|
208
|
+
bytes memory entitlementData = IEntitlement(currentEntitlements[i])
|
|
209
|
+
.getEntitlementDataByRoleId(roleId);
|
|
210
|
+
|
|
211
|
+
if (entitlementData.length > 0) {
|
|
212
|
+
EntitlementsManagerService.proxyRemoveRoleFromEntitlement(
|
|
213
|
+
address(currentEntitlements[i]),
|
|
214
|
+
roleId
|
|
215
|
+
);
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
for (uint256 i; i < entitlementsLen; ++i) {
|
|
220
|
+
CreateEntitlement calldata entitlement = entitlements[i];
|
|
221
|
+
|
|
222
|
+
// check for empty address or data
|
|
223
|
+
Validator.checkLengthCalldata(entitlement.data);
|
|
224
|
+
|
|
225
|
+
EntitlementsManagerService.proxyAddRoleToEntitlement(
|
|
226
|
+
address(entitlement.module),
|
|
227
|
+
roleId,
|
|
228
|
+
entitlement.data
|
|
229
|
+
);
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
emit RoleUpdated(msg.sender, roleId);
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
function _removeRole(uint256 roleId) internal {
|
|
236
|
+
// check role exists
|
|
237
|
+
_checkRoleExists(roleId);
|
|
238
|
+
|
|
239
|
+
RolesStorage.Layout storage rs = RolesStorage.layout();
|
|
240
|
+
RolesStorage.Role storage role = rs.roleById[roleId];
|
|
241
|
+
|
|
242
|
+
// get current entitlements
|
|
243
|
+
IEntitlement[] memory currentEntitlements = role.getEntitlements();
|
|
244
|
+
|
|
245
|
+
role.remove();
|
|
246
|
+
|
|
247
|
+
rs.roles.remove(roleId);
|
|
248
|
+
|
|
249
|
+
bytes32[] memory channelIds = ChannelService.getChannelIdsByRole(roleId);
|
|
250
|
+
uint256 channelIdsLen = channelIds.length;
|
|
251
|
+
|
|
252
|
+
// remove role from channels
|
|
253
|
+
for (uint256 i; i < channelIdsLen; ++i) {
|
|
254
|
+
ChannelService.removeRoleFromChannel(channelIds[i], roleId);
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
// remove role from entitlements
|
|
258
|
+
uint256 currentEntitlementsLen = currentEntitlements.length;
|
|
259
|
+
for (uint256 i; i < currentEntitlementsLen; ++i) {
|
|
260
|
+
EntitlementsManagerService.proxyRemoveRoleFromEntitlement(
|
|
261
|
+
address(currentEntitlements[i]),
|
|
262
|
+
roleId
|
|
263
|
+
);
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
emit RoleRemoved(msg.sender, roleId);
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
|
|
270
|
+
/* CHANNEL PERMISSIONS */
|
|
271
|
+
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
|
|
272
|
+
|
|
273
|
+
function _getChannelPermissionOverrides(
|
|
274
|
+
uint256 roleId,
|
|
275
|
+
bytes32 channelId
|
|
276
|
+
) internal view returns (string[] memory permissions) {
|
|
277
|
+
// check role exists
|
|
278
|
+
_checkRoleExists(roleId);
|
|
279
|
+
|
|
280
|
+
// check channel exists
|
|
281
|
+
ChannelService.checkChannelExists(channelId);
|
|
282
|
+
|
|
283
|
+
return RolesStorage.layout().permissionOverridesByRole[roleId][channelId].values();
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
function _setChannelPermissionOverrides(
|
|
287
|
+
uint256 roleId,
|
|
288
|
+
bytes32 channelId,
|
|
289
|
+
string[] calldata permissions
|
|
290
|
+
) internal {
|
|
291
|
+
// check if new permissions are not empty then add them
|
|
292
|
+
uint256 permissionsLen = permissions.length;
|
|
293
|
+
if (permissionsLen > 0) {
|
|
294
|
+
// check role exists
|
|
295
|
+
_checkRoleExists(roleId);
|
|
296
|
+
|
|
297
|
+
ChannelService.checkChannelExists(channelId);
|
|
298
|
+
|
|
299
|
+
RolesStorage.Layout storage rs = RolesStorage.layout();
|
|
300
|
+
StringSet.Set storage permissionsSet = rs.permissionOverridesByRole[roleId][channelId];
|
|
301
|
+
|
|
302
|
+
// remove current channel permissions
|
|
303
|
+
permissionsSet.clear();
|
|
304
|
+
|
|
305
|
+
for (uint256 i; i < permissionsLen; ++i) {
|
|
306
|
+
_checkEmptyString(permissions[i]);
|
|
307
|
+
permissionsSet.add(permissions[i]);
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
rs.channelOverridesByRole[roleId].add(channelId);
|
|
311
|
+
|
|
312
|
+
emit PermissionsAddedToChannelRole(msg.sender, roleId, channelId);
|
|
313
|
+
} else {
|
|
314
|
+
_clearChannelPermissionOverrides(roleId, channelId);
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
function _clearChannelPermissionOverrides(uint256 roleId, bytes32 channelId) internal {
|
|
319
|
+
// check role exists
|
|
320
|
+
_checkRoleExists(roleId);
|
|
321
|
+
|
|
322
|
+
// check channel exists
|
|
323
|
+
ChannelService.checkChannelExists(channelId);
|
|
324
|
+
|
|
325
|
+
RolesStorage.Layout storage rs = RolesStorage.layout();
|
|
326
|
+
StringSet.Set storage permissionsSet = rs.permissionOverridesByRole[roleId][channelId];
|
|
327
|
+
|
|
328
|
+
permissionsSet.clear();
|
|
329
|
+
|
|
330
|
+
rs.channelOverridesByRole[roleId].remove(channelId);
|
|
331
|
+
|
|
332
|
+
emit PermissionsRemovedFromChannelRole(msg.sender, roleId, channelId);
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
|
|
336
|
+
/* INTERNAL */
|
|
337
|
+
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
|
|
338
|
+
|
|
339
|
+
function _checkRoleExists(uint256 roleId) internal view {
|
|
340
|
+
// check that role exists
|
|
341
|
+
if (!RolesStorage.layout().roles.contains(roleId)) {
|
|
342
|
+
Roles__RoleDoesNotExist.selector.revertWith();
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
function _getRole(
|
|
347
|
+
uint256 roleId
|
|
348
|
+
)
|
|
349
|
+
internal
|
|
350
|
+
view
|
|
351
|
+
returns (
|
|
352
|
+
string memory name,
|
|
353
|
+
bool isImmutable,
|
|
354
|
+
string[] memory permissions,
|
|
355
|
+
IEntitlement[] memory entitlements
|
|
356
|
+
)
|
|
357
|
+
{
|
|
358
|
+
RolesStorage.Role storage role = RolesStorage.layout().roleById[roleId];
|
|
359
|
+
|
|
360
|
+
name = role.name;
|
|
361
|
+
isImmutable = role.isImmutable;
|
|
362
|
+
permissions = role.permissions.values();
|
|
363
|
+
entitlements = role.getEntitlements();
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
function _getRoleIds() internal view returns (uint256[] memory roleIds) {
|
|
367
|
+
return RolesStorage.layout().roles.values();
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
|
|
371
|
+
/* ROLE ENTITLEMENT */
|
|
372
|
+
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
|
|
373
|
+
|
|
374
|
+
function _addRoleToEntitlement(
|
|
375
|
+
uint256 roleId,
|
|
376
|
+
CreateEntitlement calldata entitlement
|
|
377
|
+
) internal {
|
|
378
|
+
// check role exists
|
|
379
|
+
_checkRoleExists(roleId);
|
|
380
|
+
|
|
381
|
+
// check entitlements exists
|
|
382
|
+
EntitlementsManagerService.checkEntitlement(address(entitlement.module));
|
|
383
|
+
|
|
384
|
+
// add entitlement to role
|
|
385
|
+
RolesStorage.Role storage role = RolesStorage.layout().roleById[roleId];
|
|
386
|
+
role.addEntitlement(address(entitlement.module));
|
|
387
|
+
|
|
388
|
+
// set entitlement to role
|
|
389
|
+
EntitlementsManagerService.proxyAddRoleToEntitlement(
|
|
390
|
+
address(entitlement.module),
|
|
391
|
+
roleId,
|
|
392
|
+
entitlement.data
|
|
393
|
+
);
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
function _removeRoleFromEntitlement(
|
|
397
|
+
uint256 roleId,
|
|
398
|
+
CreateEntitlement calldata entitlement
|
|
399
|
+
) internal {
|
|
400
|
+
// check role exists
|
|
401
|
+
_checkRoleExists(roleId);
|
|
402
|
+
|
|
403
|
+
// check entitlements exists
|
|
404
|
+
EntitlementsManagerService.checkEntitlement(address(entitlement.module));
|
|
405
|
+
|
|
406
|
+
// remove entitlement from role
|
|
407
|
+
RolesStorage.Role storage role = RolesStorage.layout().roleById[roleId];
|
|
408
|
+
role.removeEntitlement(address(entitlement.module));
|
|
409
|
+
|
|
410
|
+
// set entitlement to role
|
|
411
|
+
EntitlementsManagerService.proxyRemoveRoleFromEntitlement(
|
|
412
|
+
address(entitlement.module),
|
|
413
|
+
roleId
|
|
414
|
+
);
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
function _checkEmptyString(string calldata str) internal pure {
|
|
418
|
+
if (bytes(str).length == 0) Roles__InvalidPermission.selector.revertWith();
|
|
419
|
+
}
|
|
420
|
+
}
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
pragma solidity ^0.8.23;
|
|
3
|
+
|
|
4
|
+
// interfaces
|
|
5
|
+
import {IEntitlement} from "../../entitlements/IEntitlement.sol";
|
|
6
|
+
import {IRolesBase} from "./IRoles.sol";
|
|
7
|
+
|
|
8
|
+
// libraries
|
|
9
|
+
import {EnumerableSet} from "@openzeppelin/contracts/utils/structs/EnumerableSet.sol";
|
|
10
|
+
import {CustomRevert} from "../../../utils/libraries/CustomRevert.sol";
|
|
11
|
+
import {StringSet} from "../../../utils/libraries/StringSet.sol";
|
|
12
|
+
|
|
13
|
+
// contracts
|
|
14
|
+
|
|
15
|
+
library RolesStorage {
|
|
16
|
+
using EnumerableSet for EnumerableSet.AddressSet;
|
|
17
|
+
using CustomRevert for bytes4;
|
|
18
|
+
using StringSet for StringSet.Set;
|
|
19
|
+
|
|
20
|
+
// keccak256(abi.encode(uint256(keccak256("spaces.facets.roles.storage")) - 1)) &
|
|
21
|
+
// ~bytes32(uint256(0xff))
|
|
22
|
+
bytes32 internal constant STORAGE_SLOT =
|
|
23
|
+
0x672ef851d5f92307da037116e23aa9e31af7e1f7e3ca62c4e6d540631df3fd00;
|
|
24
|
+
|
|
25
|
+
struct Role {
|
|
26
|
+
string name;
|
|
27
|
+
bool isImmutable;
|
|
28
|
+
StringSet.Set permissions;
|
|
29
|
+
EnumerableSet.AddressSet entitlements;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
struct Layout {
|
|
33
|
+
uint256 roleCount;
|
|
34
|
+
EnumerableSet.UintSet roles;
|
|
35
|
+
mapping(uint256 roleId => Role) roleById;
|
|
36
|
+
// Overwrite permissions at a channel level given a role has been assigned to it
|
|
37
|
+
mapping(uint256 roleId => EnumerableSet.Bytes32Set) channelOverridesByRole;
|
|
38
|
+
mapping(uint256 roleId => mapping(bytes32 channelId => StringSet.Set)) permissionOverridesByRole;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function layout() internal pure returns (Layout storage ds) {
|
|
42
|
+
assembly {
|
|
43
|
+
ds.slot := STORAGE_SLOT
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function add(
|
|
48
|
+
Role storage role,
|
|
49
|
+
string calldata roleName,
|
|
50
|
+
bool isImmutable,
|
|
51
|
+
string[] calldata permissions,
|
|
52
|
+
IEntitlement[] memory entitlements
|
|
53
|
+
) internal {
|
|
54
|
+
role.name = roleName;
|
|
55
|
+
role.isImmutable = isImmutable;
|
|
56
|
+
|
|
57
|
+
addPermissions(role, permissions);
|
|
58
|
+
|
|
59
|
+
for (uint256 i; i < entitlements.length; ++i) {
|
|
60
|
+
// if entitlement is empty, skip
|
|
61
|
+
if (address(entitlements[i]) == address(0)) {
|
|
62
|
+
IRolesBase.Roles__InvalidEntitlementAddress.selector.revertWith();
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
role.entitlements.add(address(entitlements[i]));
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function remove(Role storage role) internal {
|
|
70
|
+
role.name = "";
|
|
71
|
+
role.isImmutable = false;
|
|
72
|
+
role.permissions.clear();
|
|
73
|
+
role.entitlements.clear();
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function addPermissions(Role storage role, string[] calldata permissions) internal {
|
|
77
|
+
uint256 permissionLen = permissions.length;
|
|
78
|
+
for (uint256 i; i < permissionLen; ++i) {
|
|
79
|
+
// if permission is empty, revert
|
|
80
|
+
_checkEmptyString(permissions[i]);
|
|
81
|
+
|
|
82
|
+
// if permission already exists, revert
|
|
83
|
+
if (role.permissions.contains(permissions[i])) {
|
|
84
|
+
IRolesBase.Roles__PermissionAlreadyExists.selector.revertWith();
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
role.permissions.add(permissions[i]);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
function removePermissions(Role storage role, string[] calldata permissions) internal {
|
|
92
|
+
uint256 permissionLen = permissions.length;
|
|
93
|
+
for (uint256 i; i < permissionLen; ++i) {
|
|
94
|
+
// if permission is empty, revert
|
|
95
|
+
_checkEmptyString(permissions[i]);
|
|
96
|
+
|
|
97
|
+
if (!role.permissions.contains(permissions[i])) {
|
|
98
|
+
IRolesBase.Roles__PermissionDoesNotExist.selector.revertWith();
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
role.permissions.remove(permissions[i]);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
function addEntitlement(Role storage role, address entitlement) internal {
|
|
106
|
+
if (role.entitlements.contains(entitlement)) {
|
|
107
|
+
IRolesBase.Roles__EntitlementAlreadyExists.selector.revertWith();
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
role.entitlements.add(entitlement);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
function removeEntitlement(Role storage role, address entitlement) internal {
|
|
114
|
+
if (!role.entitlements.contains(entitlement)) {
|
|
115
|
+
IRolesBase.Roles__EntitlementDoesNotExist.selector.revertWith();
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
role.entitlements.remove(entitlement);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
function getEntitlements(Role storage role) internal view returns (IEntitlement[] memory res) {
|
|
122
|
+
address[] memory entitlementAddresses = role.entitlements.values();
|
|
123
|
+
// directly cast the address array to IEntitlement array
|
|
124
|
+
assembly ("memory-safe") {
|
|
125
|
+
res := entitlementAddresses
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
function _checkEmptyString(string calldata str) private pure {
|
|
130
|
+
if (bytes(str).length == 0) IRolesBase.Roles__InvalidPermission.selector.revertWith();
|
|
131
|
+
}
|
|
132
|
+
}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
pragma solidity ^0.8.23;
|
|
3
|
+
|
|
4
|
+
import {ISwapRouterBase} from "../../../router/ISwapRouter.sol";
|
|
5
|
+
|
|
6
|
+
interface ISwapFacetBase {
|
|
7
|
+
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
|
|
8
|
+
/* ERRORS */
|
|
9
|
+
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
|
|
10
|
+
|
|
11
|
+
/// @notice Error thrown when the swap router address is not set
|
|
12
|
+
error SwapFacet__SwapRouterNotSet();
|
|
13
|
+
|
|
14
|
+
/// @notice Error thrown when the total fee exceeds the maximum allowed
|
|
15
|
+
error SwapFacet__TotalFeeTooHigh();
|
|
16
|
+
|
|
17
|
+
/// @notice Error thrown when ETH is sent with permit swap (not supported)
|
|
18
|
+
error SwapFacet__UnexpectedETH();
|
|
19
|
+
|
|
20
|
+
/// @notice Error thrown when poster address is invalid for the current fee configuration
|
|
21
|
+
error SwapFacet__InvalidPosterInput();
|
|
22
|
+
|
|
23
|
+
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
|
|
24
|
+
/* EVENTS */
|
|
25
|
+
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
|
|
26
|
+
|
|
27
|
+
/// @notice Emitted when a swap is successfully executed through the space
|
|
28
|
+
/// @param recipient The address that received the output tokens
|
|
29
|
+
/// @param tokenIn The input token
|
|
30
|
+
/// @param tokenOut The output token
|
|
31
|
+
/// @param amountIn The amount of input tokens sold
|
|
32
|
+
/// @param amountOut The amount of output tokens received
|
|
33
|
+
/// @param poster The address that posted this swap opportunity
|
|
34
|
+
event SwapExecuted(
|
|
35
|
+
address indexed recipient,
|
|
36
|
+
address indexed tokenIn,
|
|
37
|
+
address indexed tokenOut,
|
|
38
|
+
uint256 amountIn,
|
|
39
|
+
uint256 amountOut,
|
|
40
|
+
address poster
|
|
41
|
+
);
|
|
42
|
+
|
|
43
|
+
/// @notice Emitted when swap fee configuration is updated
|
|
44
|
+
/// @param posterFeeBps Poster fee in basis points
|
|
45
|
+
/// @param forwardPosterFee Whether to forward the poster fee to the poster (default: false, fees go to space)
|
|
46
|
+
event SwapFeeConfigUpdated(uint16 posterFeeBps, bool forwardPosterFee);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
interface ISwapFacet is ISwapFacetBase, ISwapRouterBase {
|
|
50
|
+
/// @notice Set the swap fee configuration for this space
|
|
51
|
+
/// @param posterFeeBps Poster fee in basis points
|
|
52
|
+
/// @param forwardPosterFee Whether to forward the poster fee to the poster (default: false, fees go to space)
|
|
53
|
+
function setSwapFeeConfig(uint16 posterFeeBps, bool forwardPosterFee) external;
|
|
54
|
+
|
|
55
|
+
/// @notice Execute a swap within the space context
|
|
56
|
+
/// @param params The parameters for the swap
|
|
57
|
+
/// @param routerParams The router parameters for the swap
|
|
58
|
+
/// @param poster The address that posted this swap opportunity
|
|
59
|
+
/// @return amountOut The amount of tokenOut received
|
|
60
|
+
function executeSwap(
|
|
61
|
+
ExactInputParams calldata params,
|
|
62
|
+
RouterParams calldata routerParams,
|
|
63
|
+
address poster
|
|
64
|
+
) external payable returns (uint256 amountOut);
|
|
65
|
+
|
|
66
|
+
/// @notice Execute a swap with Permit2 witness binding permit to swap intent
|
|
67
|
+
/// @param params The parameters for the swap
|
|
68
|
+
/// @param routerParams The router parameters for the swap
|
|
69
|
+
/// @param permit The Permit2 permit data
|
|
70
|
+
/// @param posterFee The fee configuration bound to the permit
|
|
71
|
+
/// @return amountOut The amount of tokenOut received
|
|
72
|
+
function executeSwapWithPermit(
|
|
73
|
+
ExactInputParams calldata params,
|
|
74
|
+
RouterParams calldata routerParams,
|
|
75
|
+
FeeConfig calldata posterFee,
|
|
76
|
+
Permit2Params calldata permit
|
|
77
|
+
) external payable returns (uint256 amountOut);
|
|
78
|
+
|
|
79
|
+
/// @notice Get the current swap router address
|
|
80
|
+
/// @return The address of the swap router
|
|
81
|
+
function getSwapRouter() external view returns (address);
|
|
82
|
+
|
|
83
|
+
/// @notice Get the swap fees for this space
|
|
84
|
+
/// @return protocolBps Treasury fee in basis points (from protocol config)
|
|
85
|
+
/// @return posterBps Poster fee in basis points (space specific)
|
|
86
|
+
/// @return forwardPosterFee Whether the poster fee is forwarded to the poster (default: false, fees go to space)
|
|
87
|
+
function getSwapFees()
|
|
88
|
+
external
|
|
89
|
+
view
|
|
90
|
+
returns (uint16 protocolBps, uint16 posterBps, bool forwardPosterFee);
|
|
91
|
+
}
|