@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,35 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
pragma solidity ^0.8.23;
|
|
3
|
+
|
|
4
|
+
// interfaces
|
|
5
|
+
|
|
6
|
+
// libraries
|
|
7
|
+
import {EnumerableSet} from "@openzeppelin/contracts/utils/structs/EnumerableSet.sol";
|
|
8
|
+
|
|
9
|
+
// contracts
|
|
10
|
+
|
|
11
|
+
library SpaceDelegationStorage {
|
|
12
|
+
// keccak256(abi.encode(uint256(keccak256("facets.registry.space.delegation.storage")) - 1)) &
|
|
13
|
+
// ~bytes32(uint256(0xff))
|
|
14
|
+
bytes32 internal constant STORAGE_SLOT =
|
|
15
|
+
0x3355c1fbe959688d71c13b5c967b2a46ceae34fb425fbcad0cb6451b53f36e00;
|
|
16
|
+
|
|
17
|
+
struct Layout {
|
|
18
|
+
// References
|
|
19
|
+
uint256 stakeRequirement; // deprecated
|
|
20
|
+
address spaceOwnerRegistry; // deprecated
|
|
21
|
+
address riverToken; // deprecated
|
|
22
|
+
address mainnetDelegation; // deprecated
|
|
23
|
+
// Delegation Mappings
|
|
24
|
+
mapping(address operator => EnumerableSet.AddressSet) spacesByOperator;
|
|
25
|
+
mapping(address space => address operator) operatorBySpace;
|
|
26
|
+
mapping(address space => uint256) spaceDelegationTime;
|
|
27
|
+
address spaceFactory;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function layout() internal pure returns (Layout storage s) {
|
|
31
|
+
assembly {
|
|
32
|
+
s.slot := STORAGE_SLOT
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
pragma solidity ^0.8.23;
|
|
3
|
+
|
|
4
|
+
// interfaces
|
|
5
|
+
|
|
6
|
+
// libraries
|
|
7
|
+
|
|
8
|
+
// contracts
|
|
9
|
+
interface IRewardsDistributionBase {
|
|
10
|
+
error RewardsDistribution_NoActiveOperators();
|
|
11
|
+
error RewardsDistribution_NoRewardsToClaim();
|
|
12
|
+
error RewardsDistribution_InsufficientRewardBalance();
|
|
13
|
+
error RewardsDistribution_InvalidOperator();
|
|
14
|
+
|
|
15
|
+
event RewardsDistributed(address operator, uint256 amount);
|
|
16
|
+
|
|
17
|
+
error RewardsDistribution_UnauthorizedClaimer(address delegator, address claimer);
|
|
18
|
+
error RewardsDistribution_UnauthorizedOperatorClaimer(address operator, address claimer);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
interface IRewardsDistribution is IRewardsDistributionBase {
|
|
22
|
+
function getClaimableAmountForOperator(address addr) external view returns (uint256);
|
|
23
|
+
|
|
24
|
+
function getClaimableAmountForAuthorizedClaimer(address addr) external view returns (uint256);
|
|
25
|
+
|
|
26
|
+
function getClaimableAmountForDelegator(address addr) external view returns (uint256);
|
|
27
|
+
|
|
28
|
+
function operatorClaim() external;
|
|
29
|
+
|
|
30
|
+
function mainnetClaim() external;
|
|
31
|
+
|
|
32
|
+
function delegatorClaim() external;
|
|
33
|
+
|
|
34
|
+
function distributeRewards(address operator) external;
|
|
35
|
+
|
|
36
|
+
function setPeriodDistributionAmount(uint256 amount) external;
|
|
37
|
+
|
|
38
|
+
function getPeriodDistributionAmount() external view returns (uint256);
|
|
39
|
+
|
|
40
|
+
function setActivePeriodLength(uint256 length) external;
|
|
41
|
+
|
|
42
|
+
function getActivePeriodLength() external view returns (uint256);
|
|
43
|
+
|
|
44
|
+
function getActiveOperators() external view returns (address[] memory);
|
|
45
|
+
|
|
46
|
+
function setWithdrawalRecipient(address recipient) external;
|
|
47
|
+
|
|
48
|
+
function getWithdrawalRecipient() external view returns (address);
|
|
49
|
+
|
|
50
|
+
function withdraw() external;
|
|
51
|
+
}
|
|
@@ -0,0 +1,439 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
pragma solidity ^0.8.23;
|
|
3
|
+
|
|
4
|
+
// interfaces
|
|
5
|
+
import {IVotesEnumerable} from "src/diamond/facets/governance/votes/enumerable/IVotesEnumerable.sol"; // make this into
|
|
6
|
+
// interface
|
|
7
|
+
import {IVotes} from "@openzeppelin/contracts/governance/utils/IVotes.sol";
|
|
8
|
+
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
|
|
9
|
+
import {IRewardsDistribution} from "src/base/registry/facets/distribution/v1/IRewardsDistribution.sol";
|
|
10
|
+
|
|
11
|
+
// libraries
|
|
12
|
+
import {EnumerableSet} from "@openzeppelin/contracts/utils/structs/EnumerableSet.sol";
|
|
13
|
+
|
|
14
|
+
import {SpaceDelegationStorage} from "src/base/registry/facets/delegation/SpaceDelegationStorage.sol";
|
|
15
|
+
import {RewardsDistributionStorage} from "src/base/registry/facets/distribution/v1/RewardsDistributionStorage.sol";
|
|
16
|
+
import {NodeOperatorStatus, NodeOperatorStorage} from "src/base/registry/facets/operator/NodeOperatorStorage.sol";
|
|
17
|
+
import {CurrencyTransfer} from "src/utils/libraries/CurrencyTransfer.sol";
|
|
18
|
+
|
|
19
|
+
// contracts
|
|
20
|
+
import {Facet} from "@towns-protocol/diamond/src/facets/Facet.sol";
|
|
21
|
+
|
|
22
|
+
import {OwnableBase} from "@towns-protocol/diamond/src/facets/ownable/OwnableBase.sol";
|
|
23
|
+
import {MainnetDelegationBase} from "src/base/registry/facets/mainnet/MainnetDelegationBase.sol";
|
|
24
|
+
import {ERC721ABase} from "src/diamond/facets/token/ERC721A/ERC721ABase.sol";
|
|
25
|
+
|
|
26
|
+
contract RewardsDistribution is
|
|
27
|
+
IRewardsDistribution,
|
|
28
|
+
ERC721ABase,
|
|
29
|
+
MainnetDelegationBase,
|
|
30
|
+
OwnableBase,
|
|
31
|
+
Facet
|
|
32
|
+
{
|
|
33
|
+
using EnumerableSet for EnumerableSet.AddressSet;
|
|
34
|
+
|
|
35
|
+
function __RewardsDistribution_init() external onlyInitializing {
|
|
36
|
+
_addInterface(type(IRewardsDistribution).interfaceId);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function getClaimableAmountForOperator(address operator) public view returns (uint256) {
|
|
40
|
+
RewardsDistributionStorage.Layout storage ds = RewardsDistributionStorage.layout();
|
|
41
|
+
return ds.distributionByOperator[operator];
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function getClaimableAmountForDelegator(address delegator) public view returns (uint256) {
|
|
45
|
+
RewardsDistributionStorage.Layout storage ds = RewardsDistributionStorage.layout();
|
|
46
|
+
return ds.distributionByDelegator[delegator];
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function getClaimableAmountForAuthorizedClaimer(address claimer) public view returns (uint256) {
|
|
50
|
+
RewardsDistributionStorage.Layout storage ds = RewardsDistributionStorage.layout();
|
|
51
|
+
address[] memory delegatorsForClaimer = _getDelegatorsByAuthorizedClaimer(claimer);
|
|
52
|
+
uint256 totalClaimableAmount = 0;
|
|
53
|
+
for (uint256 i = 0; i < delegatorsForClaimer.length; i++) {
|
|
54
|
+
totalClaimableAmount += ds.distributionByDelegator[delegatorsForClaimer[i]];
|
|
55
|
+
}
|
|
56
|
+
return totalClaimableAmount;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function operatorClaim() external {
|
|
60
|
+
RewardsDistributionStorage.Layout storage ds = RewardsDistributionStorage.layout();
|
|
61
|
+
|
|
62
|
+
NodeOperatorStorage.Layout storage nos = NodeOperatorStorage.layout();
|
|
63
|
+
address[] memory operatorsForClaimer = nos.operatorsByClaimer[msg.sender].values();
|
|
64
|
+
|
|
65
|
+
uint256 amount = 0;
|
|
66
|
+
for (uint256 i = 0; i < operatorsForClaimer.length; i++) {
|
|
67
|
+
amount += getClaimableAmountForOperator(operatorsForClaimer[i]);
|
|
68
|
+
|
|
69
|
+
ds.distributionByOperator[operatorsForClaimer[i]] = 0;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
_transferRewards(amount, msg.sender);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function _transferRewards(uint256 amount, address recipient) internal {
|
|
76
|
+
if (amount == 0) revert RewardsDistribution_NoRewardsToClaim();
|
|
77
|
+
|
|
78
|
+
SpaceDelegationStorage.Layout storage sd = SpaceDelegationStorage.layout();
|
|
79
|
+
address riverToken = sd.riverToken;
|
|
80
|
+
if (IERC20(riverToken).balanceOf(address(this)) < amount) {
|
|
81
|
+
revert RewardsDistribution_InsufficientRewardBalance();
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
CurrencyTransfer.transferCurrency(riverToken, address(this), recipient, amount);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
function operatorClaimByAddress(address operatorAddress) external {
|
|
88
|
+
NodeOperatorStorage.Layout storage nos = NodeOperatorStorage.layout();
|
|
89
|
+
if (nos.claimerByOperator[operatorAddress] != msg.sender) {
|
|
90
|
+
revert RewardsDistribution_UnauthorizedOperatorClaimer(operatorAddress, msg.sender);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
uint256 amount = getClaimableAmountForOperator(operatorAddress);
|
|
94
|
+
|
|
95
|
+
RewardsDistributionStorage.Layout storage ds = RewardsDistributionStorage.layout();
|
|
96
|
+
ds.distributionByOperator[operatorAddress] = 0;
|
|
97
|
+
|
|
98
|
+
_transferRewards(amount, msg.sender);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
function mainnetClaim() external {
|
|
102
|
+
RewardsDistributionStorage.Layout storage ds = RewardsDistributionStorage.layout();
|
|
103
|
+
address[] memory delegatorsForClaimer = _getDelegatorsByAuthorizedClaimer(msg.sender);
|
|
104
|
+
uint256 totalClaimableAmount = 0;
|
|
105
|
+
for (uint256 i = 0; i < delegatorsForClaimer.length; i++) {
|
|
106
|
+
totalClaimableAmount += ds.distributionByDelegator[delegatorsForClaimer[i]];
|
|
107
|
+
ds.distributionByDelegator[delegatorsForClaimer[i]] = 0;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
_transferRewards(totalClaimableAmount, msg.sender);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
function mainnetClaimByAddress(address mainnetDelegatorToClaim) external {
|
|
114
|
+
if (_getAuthorizedClaimer(mainnetDelegatorToClaim) != msg.sender) {
|
|
115
|
+
revert RewardsDistribution_UnauthorizedClaimer(mainnetDelegatorToClaim, msg.sender);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
uint256 amount = getClaimableAmountForDelegator(mainnetDelegatorToClaim);
|
|
119
|
+
|
|
120
|
+
RewardsDistributionStorage.Layout storage ds = RewardsDistributionStorage.layout();
|
|
121
|
+
ds.distributionByDelegator[mainnetDelegatorToClaim] = 0;
|
|
122
|
+
|
|
123
|
+
_transferRewards(amount, msg.sender);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
function delegatorClaim() external {
|
|
127
|
+
uint256 amount = getClaimableAmountForDelegator(msg.sender);
|
|
128
|
+
|
|
129
|
+
RewardsDistributionStorage.Layout storage ds = RewardsDistributionStorage.layout();
|
|
130
|
+
ds.distributionByDelegator[msg.sender] = 0;
|
|
131
|
+
|
|
132
|
+
_transferRewards(amount, msg.sender);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
function distributeRewards(address operator) external onlyOwner {
|
|
136
|
+
address[] memory activeOperators = _getActiveOperators();
|
|
137
|
+
uint256 totalActiveOperators = activeOperators.length;
|
|
138
|
+
|
|
139
|
+
if (totalActiveOperators == 0) {
|
|
140
|
+
revert RewardsDistribution_NoActiveOperators();
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
bool isActiveOperator = false;
|
|
144
|
+
for (uint256 i = 0; i < totalActiveOperators; i++) {
|
|
145
|
+
if (operator == activeOperators[i]) {
|
|
146
|
+
isActiveOperator = true;
|
|
147
|
+
break;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
if (!isActiveOperator) revert RewardsDistribution_InvalidOperator();
|
|
152
|
+
|
|
153
|
+
RewardsDistributionStorage.Layout storage ds = RewardsDistributionStorage.layout();
|
|
154
|
+
|
|
155
|
+
SpaceDelegationStorage.Layout storage sd = SpaceDelegationStorage.layout();
|
|
156
|
+
|
|
157
|
+
//Rewards are distributed equally amongst all active node operators
|
|
158
|
+
uint256 amountPerOperator = ds.periodDistributionAmount / totalActiveOperators;
|
|
159
|
+
|
|
160
|
+
uint256 operatorClaimAmount = _calculateOperatorDistribution(operator, amountPerOperator);
|
|
161
|
+
//set that amount to the operator distribution
|
|
162
|
+
ds.distributionByOperator[operator] += operatorClaimAmount;
|
|
163
|
+
emit RewardsDistributed(operator, operatorClaimAmount);
|
|
164
|
+
|
|
165
|
+
//distribute the remainder across the delgators to this operator
|
|
166
|
+
uint256 delegatorClaimAmount = amountPerOperator - operatorClaimAmount;
|
|
167
|
+
_distributeDelegatorsRewards(sd, operator, delegatorClaimAmount);
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
function setPeriodDistributionAmount(uint256 amount) external onlyOwner {
|
|
171
|
+
RewardsDistributionStorage.layout().periodDistributionAmount = amount;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
function getPeriodDistributionAmount() public view returns (uint256) {
|
|
175
|
+
return RewardsDistributionStorage.layout().periodDistributionAmount;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
function setActivePeriodLength(uint256 length) external onlyOwner {
|
|
179
|
+
RewardsDistributionStorage.layout().activePeriodLength = length;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
function getActivePeriodLength() public view returns (uint256) {
|
|
183
|
+
return RewardsDistributionStorage.layout().activePeriodLength;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
function getActiveOperators() public view returns (address[] memory) {
|
|
187
|
+
return _getActiveOperators();
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
function setWithdrawalRecipient(address recipient) external onlyOwner {
|
|
191
|
+
RewardsDistributionStorage.layout().withdrawalRecipient = recipient;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
function getWithdrawalRecipient() public view returns (address) {
|
|
195
|
+
return RewardsDistributionStorage.layout().withdrawalRecipient;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
function withdraw() external onlyOwner {
|
|
199
|
+
address riverToken = SpaceDelegationStorage.layout().riverToken;
|
|
200
|
+
CurrencyTransfer.transferCurrency(
|
|
201
|
+
riverToken,
|
|
202
|
+
address(this),
|
|
203
|
+
RewardsDistributionStorage.layout().withdrawalRecipient,
|
|
204
|
+
IERC20(riverToken).balanceOf(address(this))
|
|
205
|
+
);
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
// =============================================================
|
|
209
|
+
// Internal
|
|
210
|
+
// =============================================================
|
|
211
|
+
|
|
212
|
+
function _calculateOperatorDistribution(
|
|
213
|
+
address operator,
|
|
214
|
+
uint256 amountPerOperator
|
|
215
|
+
) internal view returns (uint256) {
|
|
216
|
+
NodeOperatorStorage.Layout storage nos = NodeOperatorStorage.layout();
|
|
217
|
+
uint256 commission = nos.commissionByOperator[operator];
|
|
218
|
+
uint256 operatorClaimAmount = (commission * amountPerOperator) / 10_000;
|
|
219
|
+
return operatorClaimAmount;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
function _distributeDelegatorsRewards(
|
|
223
|
+
SpaceDelegationStorage.Layout storage sd,
|
|
224
|
+
address operator,
|
|
225
|
+
uint256 delegatorsClaimAmount
|
|
226
|
+
) internal {
|
|
227
|
+
//Get all the delegators from the Base token
|
|
228
|
+
address[] memory delegators = _getValidDelegators(sd, operator);
|
|
229
|
+
|
|
230
|
+
//Get all the spaces delegating to this operator
|
|
231
|
+
address[] memory delegatingSpaces = _getValidDelegatingSpaces(sd, operator);
|
|
232
|
+
uint256 spaceDelegatorsLen = delegatingSpaces.length;
|
|
233
|
+
|
|
234
|
+
uint256 totalLength = delegators.length;
|
|
235
|
+
|
|
236
|
+
//get all the delegators delegating to those spaces
|
|
237
|
+
for (uint256 i = 0; i < spaceDelegatorsLen; i++) {
|
|
238
|
+
totalLength += _getValidDelegators(sd, delegatingSpaces[i]).length;
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
//get all the delegators delegating to the operator on the mainnet
|
|
242
|
+
Delegation[] memory mainnetDelegations = _getValidMainnetDelegationsByOperator(operator);
|
|
243
|
+
totalLength += mainnetDelegations.length;
|
|
244
|
+
|
|
245
|
+
//build new array to hold all individual user delegators
|
|
246
|
+
address[] memory combinedDelegators = new address[](totalLength);
|
|
247
|
+
uint256 count = 0;
|
|
248
|
+
uint256 totalDelegation = 0;
|
|
249
|
+
address riverToken = sd.riverToken;
|
|
250
|
+
|
|
251
|
+
//iterate through each of the categories of delegation and build an array of all the
|
|
252
|
+
// delegator
|
|
253
|
+
// addresses
|
|
254
|
+
//and the sum of their combined delegations
|
|
255
|
+
|
|
256
|
+
// Copy elements from the Base delegators
|
|
257
|
+
for (uint256 i = 0; i < delegators.length; i++) {
|
|
258
|
+
combinedDelegators[count++] = delegators[i];
|
|
259
|
+
//balance is retrieved from the Base token directly
|
|
260
|
+
totalDelegation += IERC20(riverToken).balanceOf(delegators[i]);
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
// Copy elements from the space delegators
|
|
264
|
+
for (uint256 i = 0; i < spaceDelegatorsLen; i++) {
|
|
265
|
+
//get all the spaces delegating to this operator
|
|
266
|
+
address[] memory spaceDelegatorDelegators = _getValidDelegators(
|
|
267
|
+
sd,
|
|
268
|
+
delegatingSpaces[i]
|
|
269
|
+
);
|
|
270
|
+
|
|
271
|
+
//for each space, get all the users delegating to it
|
|
272
|
+
for (uint256 j = 0; j < spaceDelegatorDelegators.length; j++) {
|
|
273
|
+
combinedDelegators[count++] = spaceDelegatorDelegators[j];
|
|
274
|
+
//get their balance from the Base token since Spaces live on Base
|
|
275
|
+
totalDelegation += IERC20(riverToken).balanceOf(spaceDelegatorDelegators[j]);
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
// Copy elements from the mainnet delegations
|
|
280
|
+
for (uint256 i = 0; i < mainnetDelegations.length; i++) {
|
|
281
|
+
combinedDelegators[count++] = mainnetDelegations[i].delegator;
|
|
282
|
+
totalDelegation += mainnetDelegations[i].quantity;
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
//allocate the rewards to the delegators
|
|
286
|
+
_allocateDelegatorRewards(
|
|
287
|
+
sd,
|
|
288
|
+
combinedDelegators,
|
|
289
|
+
operator,
|
|
290
|
+
totalDelegation,
|
|
291
|
+
delegatorsClaimAmount
|
|
292
|
+
);
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
function _allocateDelegatorRewards(
|
|
296
|
+
SpaceDelegationStorage.Layout storage sd,
|
|
297
|
+
address[] memory combinedDelegators,
|
|
298
|
+
address operator,
|
|
299
|
+
uint256 totalDelegation,
|
|
300
|
+
uint256 delegatorsClaimAmount
|
|
301
|
+
) internal {
|
|
302
|
+
uint256 delegatorsLen = combinedDelegators.length;
|
|
303
|
+
|
|
304
|
+
RewardsDistributionStorage.Layout storage ds = RewardsDistributionStorage.layout();
|
|
305
|
+
|
|
306
|
+
address riverToken = sd.riverToken;
|
|
307
|
+
address[] memory seenAddresses = new address[](delegatorsLen);
|
|
308
|
+
for (uint256 i = 0; i < delegatorsLen; i++) {
|
|
309
|
+
//check if this address has already been distributed since it could be in here twice
|
|
310
|
+
//from a Base and Mainnet delegation and the calculation already takes both into account
|
|
311
|
+
bool seen;
|
|
312
|
+
for (uint256 j = 0; j < seenAddresses.length; j++) {
|
|
313
|
+
if (seenAddresses[j] == combinedDelegators[i]) {
|
|
314
|
+
seen = true;
|
|
315
|
+
break;
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
if (seen == true) {
|
|
319
|
+
continue;
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
uint256 amount = 0;
|
|
323
|
+
//check if this user is delegating to the operator on Base
|
|
324
|
+
if (IVotes(riverToken).delegates(combinedDelegators[i]) == operator) {
|
|
325
|
+
amount = IERC20(riverToken).balanceOf(combinedDelegators[i]);
|
|
326
|
+
}
|
|
327
|
+
//check if this user is delegating to the operator on the Spaces
|
|
328
|
+
address spaceDelegatee = sd.operatorBySpace[
|
|
329
|
+
IVotes(riverToken).delegates(combinedDelegators[i])
|
|
330
|
+
];
|
|
331
|
+
if (spaceDelegatee == operator) {
|
|
332
|
+
amount += IERC20(riverToken).balanceOf(combinedDelegators[i]);
|
|
333
|
+
}
|
|
334
|
+
//check if this user is delegating to the operator on the mainnet
|
|
335
|
+
if (_getDelegationByDelegator(combinedDelegators[i]).operator == operator) {
|
|
336
|
+
amount += _getDelegationByDelegator(combinedDelegators[i]).quantity;
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
seenAddresses[i] = combinedDelegators[i];
|
|
340
|
+
|
|
341
|
+
uint256 delegatorProRata = (amount * delegatorsClaimAmount) / totalDelegation;
|
|
342
|
+
ds.distributionByDelegator[combinedDelegators[i]] += delegatorProRata;
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
function _getActiveOperators() internal view returns (address[] memory) {
|
|
347
|
+
uint256 totalOperators = _totalSupply();
|
|
348
|
+
uint256 totalActiveOperators = 0;
|
|
349
|
+
|
|
350
|
+
address[] memory expectedOperators = new address[](totalOperators);
|
|
351
|
+
for (uint256 i = 0; i < totalOperators; i++) {
|
|
352
|
+
address operator = _ownerOf(i);
|
|
353
|
+
|
|
354
|
+
NodeOperatorStorage.Layout storage nos = NodeOperatorStorage.layout();
|
|
355
|
+
NodeOperatorStatus currentStatus = nos.statusByOperator[operator];
|
|
356
|
+
|
|
357
|
+
if (
|
|
358
|
+
currentStatus == NodeOperatorStatus.Active &&
|
|
359
|
+
_isActiveSinceLastCycle(nos.approvalTimeByOperator[operator])
|
|
360
|
+
) {
|
|
361
|
+
expectedOperators[totalActiveOperators] = operator;
|
|
362
|
+
totalActiveOperators++;
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
// trim the array
|
|
367
|
+
assembly {
|
|
368
|
+
mstore(expectedOperators, totalActiveOperators)
|
|
369
|
+
}
|
|
370
|
+
return expectedOperators;
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
function _getValidDelegators(
|
|
374
|
+
SpaceDelegationStorage.Layout storage sd,
|
|
375
|
+
address operator
|
|
376
|
+
) internal view returns (address[] memory) {
|
|
377
|
+
address riverToken = sd.riverToken;
|
|
378
|
+
address[] memory delegators = IVotesEnumerable(riverToken).getDelegatorsByDelegatee(
|
|
379
|
+
operator
|
|
380
|
+
);
|
|
381
|
+
address[] memory validDelegators = new address[](delegators.length);
|
|
382
|
+
uint256 activeDelegators = 0;
|
|
383
|
+
for (uint256 i = 0; i < delegators.length; i++) {
|
|
384
|
+
if (
|
|
385
|
+
_isActiveSinceLastCycle(
|
|
386
|
+
IVotesEnumerable(riverToken).getDelegationTimeForDelegator(delegators[i])
|
|
387
|
+
)
|
|
388
|
+
) {
|
|
389
|
+
validDelegators[activeDelegators] = delegators[i];
|
|
390
|
+
activeDelegators++;
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
return validDelegators;
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
function _getValidDelegatingSpaces(
|
|
397
|
+
SpaceDelegationStorage.Layout storage sd,
|
|
398
|
+
address operator
|
|
399
|
+
) internal view returns (address[] memory) {
|
|
400
|
+
address[] memory delegatingSpaces = sd.spacesByOperator[operator].values();
|
|
401
|
+
address[] memory validDelegatingSpaces = new address[](delegatingSpaces.length);
|
|
402
|
+
for (uint256 i = 0; i < delegatingSpaces.length; i++) {
|
|
403
|
+
if (_isActiveSinceLastCycle(sd.spaceDelegationTime[delegatingSpaces[i]])) {
|
|
404
|
+
validDelegatingSpaces[i] = delegatingSpaces[i];
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
return validDelegatingSpaces;
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
function _getValidMainnetDelegationsByOperator(
|
|
411
|
+
address operator
|
|
412
|
+
) internal view returns (Delegation[] memory) {
|
|
413
|
+
//get all the delegators delegating to the operator on the mainnet
|
|
414
|
+
Delegation[] memory mainnetDelegations = _getMainnetDelegationsByOperator(operator);
|
|
415
|
+
Delegation[] memory validMainnetDelegations = new Delegation[](mainnetDelegations.length);
|
|
416
|
+
for (uint256 i = 0; i < mainnetDelegations.length; i++) {
|
|
417
|
+
if (_isActiveSinceLastCycle(mainnetDelegations[i].delegationTime)) {
|
|
418
|
+
validMainnetDelegations[i] = mainnetDelegations[i];
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
return validMainnetDelegations;
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
function _getOperatorDelegatee(address delegator) internal view returns (address) {
|
|
426
|
+
SpaceDelegationStorage.Layout storage sd = SpaceDelegationStorage.layout();
|
|
427
|
+
|
|
428
|
+
// get the delegatee that the delegator is voting for
|
|
429
|
+
address delegatee = IVotes(sd.riverToken).delegates(delegator);
|
|
430
|
+
// if the delegatee is a space, get the operator that the space is delegating to
|
|
431
|
+
address spaceDelegatee = sd.operatorBySpace[delegatee];
|
|
432
|
+
address actualOperator = spaceDelegatee != address(0) ? spaceDelegatee : delegatee;
|
|
433
|
+
return actualOperator;
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
function _isActiveSinceLastCycle(uint256 startTime) internal view returns (bool) {
|
|
437
|
+
return startTime < (block.timestamp - getActivePeriodLength());
|
|
438
|
+
}
|
|
439
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
pragma solidity ^0.8.23;
|
|
3
|
+
|
|
4
|
+
// interfaces
|
|
5
|
+
|
|
6
|
+
// libraries
|
|
7
|
+
|
|
8
|
+
// contracts
|
|
9
|
+
|
|
10
|
+
library RewardsDistributionStorage {
|
|
11
|
+
// keccak256(abi.encode(uint256(keccak256("facets.registry.rewards.distribution.storage")) - 1))
|
|
12
|
+
// &
|
|
13
|
+
// ~bytes32(uint256(0xff))
|
|
14
|
+
bytes32 internal constant STORAGE_SLOT =
|
|
15
|
+
0x3aada9ab9895514d3d0ef2741e3ec98f1d47c16f2d989bcb69404f24fbcef700;
|
|
16
|
+
|
|
17
|
+
struct Layout {
|
|
18
|
+
mapping(address operator => uint256) distributionByOperator;
|
|
19
|
+
mapping(address delegator => uint256) distributionByDelegator;
|
|
20
|
+
mapping(address operator => address[]) delegatorsByOperator;
|
|
21
|
+
uint256 periodDistributionAmount;
|
|
22
|
+
uint256 activePeriodLength;
|
|
23
|
+
address withdrawalRecipient;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function layout() internal pure returns (Layout storage s) {
|
|
27
|
+
bytes32 slot = STORAGE_SLOT;
|
|
28
|
+
assembly {
|
|
29
|
+
s.slot := slot
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
pragma solidity ^0.8.18;
|
|
3
|
+
|
|
4
|
+
import {IVotes} from "@openzeppelin/contracts/governance/utils/IVotes.sol";
|
|
5
|
+
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
|
|
6
|
+
import {Initializable} from "@towns-protocol/diamond/src/facets/initializable/Initializable.sol";
|
|
7
|
+
|
|
8
|
+
/// @title DelegationProxy
|
|
9
|
+
/// @notice A contract that holds the stake token and delegates it to a given address
|
|
10
|
+
contract DelegationProxy is Initializable {
|
|
11
|
+
address public factory;
|
|
12
|
+
address public stakeToken;
|
|
13
|
+
|
|
14
|
+
constructor() payable {
|
|
15
|
+
_disableInitializers();
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
modifier onlyFactory() {
|
|
19
|
+
require(msg.sender == factory);
|
|
20
|
+
_;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/// @notice Initializes the contract with the stake token, delegates it to the given address
|
|
24
|
+
/// and approves the factory to withdraw the stake token
|
|
25
|
+
/// @dev Must be called by the factory upon deployment
|
|
26
|
+
/// @param stakeToken_ The address of the stake token
|
|
27
|
+
/// @param delegatee The address to delegate the stake token to
|
|
28
|
+
function initialize(address stakeToken_, address delegatee) external payable initializer {
|
|
29
|
+
factory = msg.sender;
|
|
30
|
+
stakeToken = stakeToken_;
|
|
31
|
+
IVotes(stakeToken_).delegate(delegatee);
|
|
32
|
+
IERC20(stakeToken_).approve(msg.sender, type(uint256).max);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/// @notice Reinitializes the contract with the stake token and delegates it to the same address
|
|
36
|
+
/// @dev Must be called by the factory
|
|
37
|
+
/// @param stakeToken_ The address of the stake token
|
|
38
|
+
function reinitialize(address stakeToken_) external payable onlyFactory reinitializer(3) {
|
|
39
|
+
address currentDelegatee = IVotes(stakeToken).delegates(address(this));
|
|
40
|
+
stakeToken = stakeToken_;
|
|
41
|
+
IERC20(stakeToken_).approve(msg.sender, type(uint256).max);
|
|
42
|
+
if (currentDelegatee != address(0)) {
|
|
43
|
+
IVotes(stakeToken_).delegate(currentDelegatee);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/// @notice Delegates the stake token to the given address
|
|
48
|
+
/// @dev Must be called by the factory
|
|
49
|
+
/// @param delegatee The address to delegate the stake token to
|
|
50
|
+
function redelegate(address delegatee) external payable onlyFactory {
|
|
51
|
+
IVotes(stakeToken).delegate(delegatee);
|
|
52
|
+
}
|
|
53
|
+
}
|