@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,119 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
pragma solidity ^0.8.23;
|
|
3
|
+
|
|
4
|
+
// interfaces
|
|
5
|
+
import {ICrossDomainMessenger} from "src/base/registry/facets/mainnet/ICrossDomainMessenger.sol";
|
|
6
|
+
import {IMainnetDelegation} from "src/base/registry/facets/mainnet/IMainnetDelegation.sol";
|
|
7
|
+
|
|
8
|
+
// libraries
|
|
9
|
+
import {MainnetDelegationStorage} from "./MainnetDelegationStorage.sol";
|
|
10
|
+
|
|
11
|
+
// contracts
|
|
12
|
+
import {Facet} from "@towns-protocol/diamond/src/facets/Facet.sol";
|
|
13
|
+
import {OwnableBase} from "@towns-protocol/diamond/src/facets/ownable/OwnableBase.sol";
|
|
14
|
+
import {MainnetDelegationBase} from "src/base/registry/facets/mainnet/MainnetDelegationBase.sol";
|
|
15
|
+
|
|
16
|
+
contract MainnetDelegation is IMainnetDelegation, MainnetDelegationBase, OwnableBase, Facet {
|
|
17
|
+
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
|
|
18
|
+
/* INITIALIZERS */
|
|
19
|
+
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
|
|
20
|
+
|
|
21
|
+
function __MainnetDelegation_init(address messenger) external onlyInitializing {
|
|
22
|
+
__MainnetDelegation_init_unchained(messenger);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function __MainnetDelegation_init_unchained(address messenger) internal {
|
|
26
|
+
_addInterface(type(IMainnetDelegation).interfaceId);
|
|
27
|
+
MainnetDelegationStorage.layout().messenger = messenger;
|
|
28
|
+
|
|
29
|
+
emit CrossDomainMessengerSet(messenger);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
|
|
33
|
+
/* MODIFIER */
|
|
34
|
+
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
|
|
35
|
+
|
|
36
|
+
modifier onlyCrossDomainMessenger() {
|
|
37
|
+
address messenger = _getMessenger();
|
|
38
|
+
|
|
39
|
+
require(
|
|
40
|
+
msg.sender == messenger &&
|
|
41
|
+
ICrossDomainMessenger(messenger).xDomainMessageSender() == _getProxyDelegation(),
|
|
42
|
+
"MainnetDelegation: sender is not the cross-domain messenger"
|
|
43
|
+
);
|
|
44
|
+
_;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
|
|
48
|
+
/* ADMIN FUNCTIONS */
|
|
49
|
+
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
|
|
50
|
+
|
|
51
|
+
/// @inheritdoc IMainnetDelegation
|
|
52
|
+
function setProxyDelegation(address proxyDelegation) external onlyOwner {
|
|
53
|
+
MainnetDelegationStorage.layout().proxyDelegation = proxyDelegation;
|
|
54
|
+
|
|
55
|
+
emit ProxyDelegationSet(proxyDelegation);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/// @inheritdoc IMainnetDelegation
|
|
59
|
+
function relayDelegations(bytes calldata encodedMsgs) external onlyOwner {
|
|
60
|
+
_relayDelegations(encodedMsgs);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
|
|
64
|
+
/* DELEGATION */
|
|
65
|
+
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
|
|
66
|
+
|
|
67
|
+
/// @inheritdoc IMainnetDelegation
|
|
68
|
+
function setDelegationDigest(bytes32 digest) external onlyCrossDomainMessenger {
|
|
69
|
+
MainnetDelegationStorage.layout().delegationDigest = digest;
|
|
70
|
+
|
|
71
|
+
emit DelegationDigestSet(digest);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
|
|
75
|
+
/* GETTERS */
|
|
76
|
+
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
|
|
77
|
+
|
|
78
|
+
/// @inheritdoc IMainnetDelegation
|
|
79
|
+
function getMessenger() external view returns (address) {
|
|
80
|
+
return _getMessenger();
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/// @inheritdoc IMainnetDelegation
|
|
84
|
+
function getProxyDelegation() external view returns (address) {
|
|
85
|
+
return address(_getProxyDelegation());
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/// @inheritdoc IMainnetDelegation
|
|
89
|
+
function getMainnetDelegators() external view returns (address[] memory) {
|
|
90
|
+
return _getMainnetDelegators();
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/// @inheritdoc IMainnetDelegation
|
|
94
|
+
function getDepositIdByDelegator(address delegator) external view returns (uint256) {
|
|
95
|
+
return _getDepositIdByDelegator(delegator);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/// @inheritdoc IMainnetDelegation
|
|
99
|
+
function getDelegationByDelegator(address delegator) external view returns (Delegation memory) {
|
|
100
|
+
return _getDelegationByDelegator(delegator);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/// @inheritdoc IMainnetDelegation
|
|
104
|
+
function getMainnetDelegationsByOperator(
|
|
105
|
+
address operator
|
|
106
|
+
) external view returns (Delegation[] memory) {
|
|
107
|
+
return _getMainnetDelegationsByOperator(operator);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/// @inheritdoc IMainnetDelegation
|
|
111
|
+
function getDelegatedStakeByOperator(address operator) external view returns (uint256) {
|
|
112
|
+
return _getDelegatedStakeByOperator(operator);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/// @inheritdoc IMainnetDelegation
|
|
116
|
+
function getAuthorizedClaimer(address delegator) external view returns (address) {
|
|
117
|
+
return _getAuthorizedClaimer(delegator);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
@@ -0,0 +1,274 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
pragma solidity ^0.8.23;
|
|
3
|
+
|
|
4
|
+
// interfaces
|
|
5
|
+
import {IRewardsDistribution} from "../distribution/v2/IRewardsDistribution.sol";
|
|
6
|
+
import {ICrossDomainMessenger} from "./ICrossDomainMessenger.sol";
|
|
7
|
+
import {IMainnetDelegationBase} from "./IMainnetDelegation.sol";
|
|
8
|
+
|
|
9
|
+
// libraries
|
|
10
|
+
import {MainnetDelegationStorage} from "./MainnetDelegationStorage.sol";
|
|
11
|
+
import {EnumerableSet} from "@openzeppelin/contracts/utils/structs/EnumerableSet.sol";
|
|
12
|
+
import {SafeCastLib} from "solady/utils/SafeCastLib.sol";
|
|
13
|
+
|
|
14
|
+
// contracts
|
|
15
|
+
|
|
16
|
+
abstract contract MainnetDelegationBase is IMainnetDelegationBase {
|
|
17
|
+
using EnumerableSet for EnumerableSet.AddressSet;
|
|
18
|
+
|
|
19
|
+
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
|
|
20
|
+
/* STATE MUTATING */
|
|
21
|
+
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
|
|
22
|
+
|
|
23
|
+
function _relayDelegations(bytes calldata encodedMsgs) internal {
|
|
24
|
+
_verifyDelegations(encodedMsgs);
|
|
25
|
+
|
|
26
|
+
DelegationMsg[] calldata msgs = _decodeDelegations(encodedMsgs);
|
|
27
|
+
|
|
28
|
+
// process the delegation messages
|
|
29
|
+
for (uint256 i; i < msgs.length; ++i) {
|
|
30
|
+
DelegationMsg calldata delegation = msgs[i];
|
|
31
|
+
_setDelegation(delegation.delegator, delegation.delegatee, delegation.quantity);
|
|
32
|
+
_setAuthorizedClaimer(delegation.delegator, delegation.claimer);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
MainnetDelegationStorage.Layout storage ds = MainnetDelegationStorage.layout();
|
|
36
|
+
|
|
37
|
+
address[] memory delegators = ds.delegators.values();
|
|
38
|
+
|
|
39
|
+
// remove stale delegation if a delegator isn't in the encodedMsgs
|
|
40
|
+
for (uint256 i; i < delegators.length; ++i) {
|
|
41
|
+
address delegator = delegators[i];
|
|
42
|
+
bool found;
|
|
43
|
+
for (uint256 j; j < msgs.length; ++j) {
|
|
44
|
+
if (msgs[j].delegator == delegator) {
|
|
45
|
+
found = true;
|
|
46
|
+
break;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
if (!found) {
|
|
50
|
+
_removeDelegation(delegator);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function _removeDelegation(address delegator) internal {
|
|
56
|
+
MainnetDelegationStorage.Layout storage ds = MainnetDelegationStorage.layout();
|
|
57
|
+
|
|
58
|
+
ds.delegators.remove(delegator);
|
|
59
|
+
address currentOperator = ds.delegationByDelegator[delegator].operator;
|
|
60
|
+
ds.delegatorsByOperator[currentOperator].remove(delegator);
|
|
61
|
+
delete ds.delegationByDelegator[delegator];
|
|
62
|
+
|
|
63
|
+
_unstake(delegator);
|
|
64
|
+
|
|
65
|
+
emit DelegationRemoved(delegator);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/// @dev Caller must ensure that operator != address(0)
|
|
69
|
+
function _replaceDelegation(
|
|
70
|
+
Delegation storage delegation,
|
|
71
|
+
address currentOperator,
|
|
72
|
+
address delegator,
|
|
73
|
+
address operator,
|
|
74
|
+
uint256 quantity
|
|
75
|
+
) internal {
|
|
76
|
+
MainnetDelegationStorage.Layout storage ds = MainnetDelegationStorage.layout();
|
|
77
|
+
|
|
78
|
+
if (currentOperator != operator) {
|
|
79
|
+
ds.delegatorsByOperator[currentOperator].remove(delegator);
|
|
80
|
+
ds.delegatorsByOperator[operator].add(delegator);
|
|
81
|
+
delegation.operator = operator;
|
|
82
|
+
delegation.delegationTime = block.timestamp;
|
|
83
|
+
} else if (delegation.quantity != quantity) {
|
|
84
|
+
delegation.delegationTime = block.timestamp;
|
|
85
|
+
}
|
|
86
|
+
delegation.quantity = quantity;
|
|
87
|
+
|
|
88
|
+
_unstake(delegator);
|
|
89
|
+
_stake(delegator, operator, quantity);
|
|
90
|
+
|
|
91
|
+
emit DelegationSet(delegator, operator, quantity);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
function _addDelegation(
|
|
95
|
+
Delegation storage delegation,
|
|
96
|
+
address delegator,
|
|
97
|
+
address operator,
|
|
98
|
+
uint256 quantity
|
|
99
|
+
) internal {
|
|
100
|
+
MainnetDelegationStorage.Layout storage ds = MainnetDelegationStorage.layout();
|
|
101
|
+
|
|
102
|
+
ds.delegators.add(delegator);
|
|
103
|
+
ds.delegatorsByOperator[operator].add(delegator);
|
|
104
|
+
(
|
|
105
|
+
delegation.operator,
|
|
106
|
+
delegation.quantity,
|
|
107
|
+
delegation.delegator,
|
|
108
|
+
delegation.delegationTime
|
|
109
|
+
) = (operator, quantity, delegator, block.timestamp);
|
|
110
|
+
|
|
111
|
+
_stake(delegator, operator, quantity);
|
|
112
|
+
|
|
113
|
+
emit DelegationSet(delegator, operator, quantity);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
function _setDelegation(address delegator, address operator, uint256 quantity) internal {
|
|
117
|
+
MainnetDelegationStorage.Layout storage ds = MainnetDelegationStorage.layout();
|
|
118
|
+
|
|
119
|
+
Delegation storage delegation = ds.delegationByDelegator[delegator];
|
|
120
|
+
address currentOperator = delegation.operator;
|
|
121
|
+
|
|
122
|
+
if (operator == address(0) || quantity == 0) {
|
|
123
|
+
_removeDelegation(delegator);
|
|
124
|
+
} else if (currentOperator == address(0)) {
|
|
125
|
+
_addDelegation(delegation, delegator, operator, quantity);
|
|
126
|
+
} else {
|
|
127
|
+
_replaceDelegation(delegation, currentOperator, delegator, operator, quantity);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/// @dev Reuse the staking deposit if exists, otherwise create a new one
|
|
132
|
+
function _stake(address delegator, address operator, uint256 quantity) internal {
|
|
133
|
+
MainnetDelegationStorage.Layout storage ds = MainnetDelegationStorage.layout();
|
|
134
|
+
|
|
135
|
+
uint256 depositId = ds.depositIdByDelegator[delegator];
|
|
136
|
+
if (depositId == 0) {
|
|
137
|
+
(bool success, bytes memory retData) = address(this).call(
|
|
138
|
+
abi.encodeCall(
|
|
139
|
+
IRewardsDistribution.stake,
|
|
140
|
+
(SafeCastLib.toUint96(quantity), operator, delegator)
|
|
141
|
+
)
|
|
142
|
+
);
|
|
143
|
+
if (success) {
|
|
144
|
+
depositId = abi.decode(retData, (uint256));
|
|
145
|
+
ds.depositIdByDelegator[delegator] = depositId;
|
|
146
|
+
}
|
|
147
|
+
} else {
|
|
148
|
+
(bool success, ) = address(this).call(
|
|
149
|
+
abi.encodeCall(IRewardsDistribution.redelegate, (depositId, operator))
|
|
150
|
+
);
|
|
151
|
+
if (success) {
|
|
152
|
+
IRewardsDistribution(address(this)).increaseStake(
|
|
153
|
+
depositId,
|
|
154
|
+
SafeCastLib.toUint96(quantity)
|
|
155
|
+
);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/// @dev Unstake the delegation of the delegator if exists
|
|
161
|
+
function _unstake(address delegator) internal {
|
|
162
|
+
MainnetDelegationStorage.Layout storage ds = MainnetDelegationStorage.layout();
|
|
163
|
+
|
|
164
|
+
uint256 depositId = ds.depositIdByDelegator[delegator];
|
|
165
|
+
if (depositId != 0) {
|
|
166
|
+
IRewardsDistribution(address(this)).initiateWithdraw(depositId);
|
|
167
|
+
// do not reset depositIdByDelegator[delegator] as we recycle deposit IDs for delegators
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
function _setAuthorizedClaimer(address delegator, address claimer) internal {
|
|
172
|
+
MainnetDelegationStorage.Layout storage ds = MainnetDelegationStorage.layout();
|
|
173
|
+
|
|
174
|
+
address currentClaimer = ds.claimerByDelegator[delegator];
|
|
175
|
+
if (currentClaimer != claimer) {
|
|
176
|
+
ds.delegatorsByAuthorizedClaimer[currentClaimer].remove(delegator);
|
|
177
|
+
ds.claimerByDelegator[delegator] = claimer;
|
|
178
|
+
if (claimer != address(0)) {
|
|
179
|
+
ds.delegatorsByAuthorizedClaimer[claimer].add(delegator);
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
emit ClaimerSet(delegator, claimer);
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
|
|
187
|
+
/* GETTERS */
|
|
188
|
+
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
|
|
189
|
+
|
|
190
|
+
function _getMainnetDelegators() internal view returns (address[] memory) {
|
|
191
|
+
return MainnetDelegationStorage.layout().delegators.values();
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
function _getDepositIdByDelegator(address delegator) internal view returns (uint256) {
|
|
195
|
+
return MainnetDelegationStorage.layout().depositIdByDelegator[delegator];
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
function _getDelegationByDelegator(
|
|
199
|
+
address delegator
|
|
200
|
+
) internal view returns (Delegation memory delegation) {
|
|
201
|
+
assembly ("memory-safe") {
|
|
202
|
+
// By default, memory has been implicitly allocated for `delegation`.
|
|
203
|
+
// But we don't need this implicitly allocated memory.
|
|
204
|
+
// So we just set the free memory pointer to what it was before `delegation` has been
|
|
205
|
+
// allocated.
|
|
206
|
+
mstore(0x40, delegation)
|
|
207
|
+
}
|
|
208
|
+
delegation = MainnetDelegationStorage.layout().delegationByDelegator[delegator];
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
function _getMainnetDelegationsByOperator(
|
|
212
|
+
address operator
|
|
213
|
+
) internal view returns (Delegation[] memory delegations) {
|
|
214
|
+
MainnetDelegationStorage.Layout storage ds = MainnetDelegationStorage.layout();
|
|
215
|
+
EnumerableSet.AddressSet storage delegators = ds.delegatorsByOperator[operator];
|
|
216
|
+
uint256 length = delegators.length();
|
|
217
|
+
delegations = new Delegation[](length);
|
|
218
|
+
|
|
219
|
+
for (uint256 i; i < length; ++i) {
|
|
220
|
+
address delegator = delegators.at(i);
|
|
221
|
+
delegations[i] = ds.delegationByDelegator[delegator];
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
function _getDelegatedStakeByOperator(address operator) internal view returns (uint256 stake) {
|
|
226
|
+
Delegation[] memory delegations = _getMainnetDelegationsByOperator(operator);
|
|
227
|
+
for (uint256 i; i < delegations.length; ++i) {
|
|
228
|
+
stake += delegations[i].quantity;
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
function _getDelegatorsByAuthorizedClaimer(
|
|
233
|
+
address claimer
|
|
234
|
+
) internal view returns (address[] memory) {
|
|
235
|
+
MainnetDelegationStorage.Layout storage ds = MainnetDelegationStorage.layout();
|
|
236
|
+
return ds.delegatorsByAuthorizedClaimer[claimer].values();
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
function _getAuthorizedClaimer(address delegator) internal view returns (address) {
|
|
240
|
+
return MainnetDelegationStorage.layout().claimerByDelegator[delegator];
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
function _getProxyDelegation() internal view returns (address) {
|
|
244
|
+
return MainnetDelegationStorage.layout().proxyDelegation;
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
function _getMessenger() internal view returns (address) {
|
|
248
|
+
return MainnetDelegationStorage.layout().messenger;
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
|
|
252
|
+
/* UTILS */
|
|
253
|
+
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
|
|
254
|
+
|
|
255
|
+
function _verifyDelegations(bytes calldata encodedMsgs) internal view {
|
|
256
|
+
MainnetDelegationStorage.Layout storage ds = MainnetDelegationStorage.layout();
|
|
257
|
+
|
|
258
|
+
bytes32 digest = keccak256(abi.encode(keccak256(encodedMsgs)));
|
|
259
|
+
require(digest == ds.delegationDigest);
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
/// @dev equivalent: abi.decode(encodedMsgs, (DelegationMsg[]));
|
|
263
|
+
function _decodeDelegations(
|
|
264
|
+
bytes calldata encodedMsgs
|
|
265
|
+
) internal pure returns (DelegationMsg[] calldata msgs) {
|
|
266
|
+
assembly {
|
|
267
|
+
// this is a dynamic array, so calldataload(encodedMsgs.offset) is the
|
|
268
|
+
// offset from encodedMsgs.offset at which the array begins
|
|
269
|
+
let lengthPtr := add(encodedMsgs.offset, calldataload(encodedMsgs.offset))
|
|
270
|
+
msgs.length := calldataload(lengthPtr)
|
|
271
|
+
msgs.offset := add(lengthPtr, 0x20)
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
pragma solidity ^0.8.23;
|
|
3
|
+
|
|
4
|
+
// interfaces
|
|
5
|
+
import {IMainnetDelegationBase} from "./IMainnetDelegation.sol";
|
|
6
|
+
|
|
7
|
+
// libraries
|
|
8
|
+
import {EnumerableSet} from "@openzeppelin/contracts/utils/structs/EnumerableSet.sol";
|
|
9
|
+
|
|
10
|
+
// contracts
|
|
11
|
+
|
|
12
|
+
library MainnetDelegationStorage {
|
|
13
|
+
// keccak256(abi.encode(uint256(keccak256("tokens.river.base.delegation.storage")) - 1)) &
|
|
14
|
+
// ~bytes32(uint256(0xff))
|
|
15
|
+
bytes32 internal constant STORAGE_SLOT =
|
|
16
|
+
0x264df150e9e008a39dd109254e3af3cdadbfbd33261903d1163f43eaee68e700;
|
|
17
|
+
|
|
18
|
+
struct Layout {
|
|
19
|
+
mapping(address operator => EnumerableSet.AddressSet) delegatorsByOperator;
|
|
20
|
+
mapping(address delegator => IMainnetDelegationBase.Delegation delegation) delegationByDelegator;
|
|
21
|
+
mapping(address delegator => address claimer) claimerByDelegator;
|
|
22
|
+
address deprecatedProxyDelegation; // Do not use this, use proxyDelegation
|
|
23
|
+
address messenger;
|
|
24
|
+
mapping(address claimer => EnumerableSet.AddressSet delegators) delegatorsByAuthorizedClaimer;
|
|
25
|
+
address proxyDelegation;
|
|
26
|
+
EnumerableSet.AddressSet delegators;
|
|
27
|
+
mapping(address delegator => uint256 depositId) depositIdByDelegator;
|
|
28
|
+
bytes32 delegationDigest;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function layout() internal pure returns (Layout storage s) {
|
|
32
|
+
assembly {
|
|
33
|
+
s.slot := STORAGE_SLOT
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
pragma solidity ^0.8.23;
|
|
3
|
+
|
|
4
|
+
// interfaces
|
|
5
|
+
|
|
6
|
+
// libraries
|
|
7
|
+
import {NodeOperatorStatus} from "src/base/registry/facets/operator/NodeOperatorStorage.sol";
|
|
8
|
+
|
|
9
|
+
// contracts
|
|
10
|
+
interface INodeOperatorBase {
|
|
11
|
+
// =============================================================
|
|
12
|
+
// Errors
|
|
13
|
+
// =============================================================
|
|
14
|
+
error NodeOperator__InvalidAddress();
|
|
15
|
+
error NodeOperator__NotTransferable();
|
|
16
|
+
error NodeOperator__AlreadyRegistered();
|
|
17
|
+
error NodeOperator__StatusNotChanged();
|
|
18
|
+
error NodeOperator__InvalidStatusTransition();
|
|
19
|
+
error NodeOperator__NotRegistered();
|
|
20
|
+
error NodeOperator__InvalidOperator();
|
|
21
|
+
error NodeOperator__InvalidSpace();
|
|
22
|
+
error NodeOperator__AlreadyDelegated(address operator);
|
|
23
|
+
error NodeOperator__NotEnoughStake();
|
|
24
|
+
error NodeOperator__InvalidStakeRequirement();
|
|
25
|
+
error NodeOperator__ClaimAddressNotChanged();
|
|
26
|
+
error NodeOperator__InvalidCommissionRate();
|
|
27
|
+
error NodeOperator__NotClaimer();
|
|
28
|
+
// =============================================================
|
|
29
|
+
// Events
|
|
30
|
+
// =============================================================
|
|
31
|
+
|
|
32
|
+
event OperatorRegistered(address indexed operator);
|
|
33
|
+
event OperatorStatusChanged(address indexed operator, NodeOperatorStatus indexed newStatus);
|
|
34
|
+
event OperatorCommissionChanged(address indexed operator, uint256 indexed commission);
|
|
35
|
+
event OperatorClaimAddressChanged(address indexed operator, address indexed claimAddress);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
interface INodeOperator is INodeOperatorBase {
|
|
39
|
+
// =============================================================
|
|
40
|
+
// Registration
|
|
41
|
+
// =============================================================
|
|
42
|
+
/*
|
|
43
|
+
* @notice Registers an operator.
|
|
44
|
+
*/
|
|
45
|
+
function registerOperator(address claimer) external;
|
|
46
|
+
|
|
47
|
+
/*
|
|
48
|
+
* @notice Returns whether an operator is registered.
|
|
49
|
+
* @param operator Address of the operator.
|
|
50
|
+
*/
|
|
51
|
+
function isOperator(address operator) external view returns (bool);
|
|
52
|
+
|
|
53
|
+
/*
|
|
54
|
+
* @notice Returns the status of an operator.
|
|
55
|
+
* @param operator Address of the operator.
|
|
56
|
+
* @return The status of the operator.
|
|
57
|
+
*/
|
|
58
|
+
function getOperatorStatus(address operator) external view returns (NodeOperatorStatus);
|
|
59
|
+
|
|
60
|
+
/*
|
|
61
|
+
* @notice Sets the status of an operator.
|
|
62
|
+
* @param operator Address of the operator.
|
|
63
|
+
*/
|
|
64
|
+
function setOperatorStatus(address operator, NodeOperatorStatus newStatus) external;
|
|
65
|
+
|
|
66
|
+
// =============================================================
|
|
67
|
+
// Operator Information
|
|
68
|
+
// =============================================================
|
|
69
|
+
function setClaimAddressForOperator(address claimer, address operator) external;
|
|
70
|
+
|
|
71
|
+
function getClaimAddressForOperator(address operator) external view returns (address);
|
|
72
|
+
|
|
73
|
+
function getOperators() external view returns (address[] memory);
|
|
74
|
+
|
|
75
|
+
// =============================================================
|
|
76
|
+
// Commission
|
|
77
|
+
// =============================================================
|
|
78
|
+
/*
|
|
79
|
+
* @notice Sets the commission rate of an operator.
|
|
80
|
+
* @param operator Address of the operator.
|
|
81
|
+
* @param commission The new commission rate.
|
|
82
|
+
*/
|
|
83
|
+
function setCommissionRate(uint256 commission) external;
|
|
84
|
+
|
|
85
|
+
/*
|
|
86
|
+
* @notice Returns the commission rate of an operator.
|
|
87
|
+
* @param operator Address of the operator.
|
|
88
|
+
* @return The commission rate of the operator.
|
|
89
|
+
*/
|
|
90
|
+
function getCommissionRate(address operator) external view returns (uint256);
|
|
91
|
+
}
|