@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,466 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
pragma solidity ^0.8.18;
|
|
3
|
+
|
|
4
|
+
// interfaces
|
|
5
|
+
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
|
|
6
|
+
|
|
7
|
+
// libraries
|
|
8
|
+
import {CustomRevert} from "../../../../../utils/libraries/CustomRevert.sol";
|
|
9
|
+
import {FixedPointMathLib} from "solady/utils/FixedPointMathLib.sol";
|
|
10
|
+
|
|
11
|
+
// contracts
|
|
12
|
+
|
|
13
|
+
/// @notice Staking rewards library that encapsulates the minimal logic for staking and rewards
|
|
14
|
+
/// distribution with delegation commission
|
|
15
|
+
/// @dev The library does not handle the transfer of stakeToken and rewardToken.
|
|
16
|
+
/// @dev The library is designed to be compatible with ERC-7201.
|
|
17
|
+
/// @dev The data structures should be modified with caution.
|
|
18
|
+
library StakingRewards {
|
|
19
|
+
using CustomRevert for bytes4;
|
|
20
|
+
|
|
21
|
+
uint256 internal constant SCALE_FACTOR = 1e36;
|
|
22
|
+
uint256 internal constant MAX_COMMISSION_RATE = 10_000;
|
|
23
|
+
|
|
24
|
+
/// @notice The deposit information
|
|
25
|
+
/// @param amount The amount of stakeToken that is staked
|
|
26
|
+
/// @param owner The address of the depositor
|
|
27
|
+
/// @param commissionEarningPower The amount of stakeToken assigned to the commission
|
|
28
|
+
/// @param delegatee The address of the delegatee
|
|
29
|
+
/// @param pendingWithdrawal The amount of stakeToken that is pending withdrawal
|
|
30
|
+
/// @param beneficiary The address of the beneficiary
|
|
31
|
+
struct Deposit {
|
|
32
|
+
uint96 amount;
|
|
33
|
+
address owner;
|
|
34
|
+
uint96 commissionEarningPower;
|
|
35
|
+
address delegatee;
|
|
36
|
+
uint96 pendingWithdrawal;
|
|
37
|
+
address beneficiary;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/// @notice The account information for a beneficiary
|
|
41
|
+
/// @param earningPower The amount of stakeToken that is yielding rewards
|
|
42
|
+
/// @param rewardPerTokenAccumulated The scaled amount of rewardToken that has been accumulated
|
|
43
|
+
/// per staked token
|
|
44
|
+
/// @param unclaimedRewardSnapshot The snapshot of the unclaimed reward scaled
|
|
45
|
+
struct Treasure {
|
|
46
|
+
uint96 earningPower;
|
|
47
|
+
uint256 rewardPerTokenAccumulated;
|
|
48
|
+
uint256 unclaimedRewardSnapshot;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/// @notice The layout of the staking rewards storage
|
|
52
|
+
/// @param rewardToken The token that is being distributed as rewards
|
|
53
|
+
/// @param stakeToken The token that is being staked
|
|
54
|
+
/// @param totalStaked The total amount of stakeToken that is staked
|
|
55
|
+
/// @param rewardDuration The duration of the reward distribution
|
|
56
|
+
/// @param rewardEndTime The time at which the reward distribution ends
|
|
57
|
+
/// @param lastUpdateTime The time at which the reward was last updated
|
|
58
|
+
/// @param rewardRate The scaled rate of reward distributed per second
|
|
59
|
+
/// @param rewardPerTokenAccumulated The scaled amount of rewardToken that has been accumulated
|
|
60
|
+
/// per staked token
|
|
61
|
+
/// @param nextDepositId The next deposit ID that will be used
|
|
62
|
+
/// @param stakedByDepositor The mapping of the amount of stakeToken that is staked by a
|
|
63
|
+
/// particular depositor
|
|
64
|
+
/// @param treasureByBeneficiary The mapping of the account information for a beneficiary
|
|
65
|
+
/// @param depositById The mapping of the information for a deposit
|
|
66
|
+
struct Layout {
|
|
67
|
+
address rewardToken;
|
|
68
|
+
address stakeToken;
|
|
69
|
+
uint96 totalStaked;
|
|
70
|
+
uint256 rewardDuration;
|
|
71
|
+
uint256 rewardEndTime;
|
|
72
|
+
uint256 lastUpdateTime;
|
|
73
|
+
uint256 rewardRate;
|
|
74
|
+
uint256 rewardPerTokenAccumulated;
|
|
75
|
+
uint256 nextDepositId;
|
|
76
|
+
mapping(address depositor => uint96 amount) stakedByDepositor;
|
|
77
|
+
mapping(address beneficiary => Treasure) treasureByBeneficiary;
|
|
78
|
+
mapping(uint256 depositId => Deposit) depositById;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
|
|
82
|
+
/* CUSTOM ERRORS */
|
|
83
|
+
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
|
|
84
|
+
|
|
85
|
+
error StakingRewards__InvalidAmount();
|
|
86
|
+
error StakingRewards__InvalidAddress();
|
|
87
|
+
error StakingRewards__InvalidRewardRate();
|
|
88
|
+
error StakingRewards__InsufficientReward();
|
|
89
|
+
error StakingRewards__CommissionExceedsStake();
|
|
90
|
+
|
|
91
|
+
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
|
|
92
|
+
/* VIEWERS */
|
|
93
|
+
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
|
|
94
|
+
|
|
95
|
+
/// @notice Gets the last time rewards were distributed (capped at current timestamp)
|
|
96
|
+
function lastTimeRewardDistributed(Layout storage self) internal view returns (uint256) {
|
|
97
|
+
return FixedPointMathLib.min(self.rewardEndTime, block.timestamp);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/// @notice Calculates the current accumulated reward per token
|
|
101
|
+
function currentRewardPerTokenAccumulated(Layout storage self) internal view returns (uint256) {
|
|
102
|
+
// cache storage reads
|
|
103
|
+
(
|
|
104
|
+
uint96 totalStaked,
|
|
105
|
+
uint256 lastUpdateTime,
|
|
106
|
+
uint256 rewardRate,
|
|
107
|
+
uint256 rewardPerTokenAccumulated
|
|
108
|
+
) = (
|
|
109
|
+
self.totalStaked,
|
|
110
|
+
self.lastUpdateTime,
|
|
111
|
+
self.rewardRate,
|
|
112
|
+
self.rewardPerTokenAccumulated
|
|
113
|
+
);
|
|
114
|
+
if (totalStaked == 0) return rewardPerTokenAccumulated;
|
|
115
|
+
|
|
116
|
+
uint256 elapsedTime;
|
|
117
|
+
unchecked {
|
|
118
|
+
elapsedTime = lastTimeRewardDistributed(self) - lastUpdateTime;
|
|
119
|
+
}
|
|
120
|
+
return
|
|
121
|
+
rewardPerTokenAccumulated +
|
|
122
|
+
FixedPointMathLib.fullMulDiv(rewardRate, elapsedTime, totalStaked);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/// @notice Calculates current scaled reward for a beneficiary's treasure
|
|
126
|
+
function currentRewardScaled(
|
|
127
|
+
Layout storage self,
|
|
128
|
+
Treasure storage treasure
|
|
129
|
+
) internal view returns (uint256) {
|
|
130
|
+
uint256 rewardPerTokenGrowth;
|
|
131
|
+
unchecked {
|
|
132
|
+
rewardPerTokenGrowth =
|
|
133
|
+
currentRewardPerTokenAccumulated(self) -
|
|
134
|
+
treasure.rewardPerTokenAccumulated;
|
|
135
|
+
}
|
|
136
|
+
return
|
|
137
|
+
treasure.unclaimedRewardSnapshot +
|
|
138
|
+
(uint256(treasure.earningPower) * rewardPerTokenGrowth);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
|
|
142
|
+
/* STATE MUTATING */
|
|
143
|
+
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
|
|
144
|
+
|
|
145
|
+
/// @notice Updates the global reward accumulation state to current timestamp
|
|
146
|
+
/// @dev Must be called before any storage updates.
|
|
147
|
+
function updateGlobalReward(Layout storage self) internal {
|
|
148
|
+
self.rewardPerTokenAccumulated = currentRewardPerTokenAccumulated(self);
|
|
149
|
+
self.lastUpdateTime = lastTimeRewardDistributed(self);
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/// @notice Updates a beneficiary's reward snapshot based on current global state
|
|
153
|
+
/// @dev Must be called after `updateGlobalReward` and before changing the earning power.
|
|
154
|
+
function updateReward(Layout storage self, Treasure storage treasure) internal {
|
|
155
|
+
treasure.unclaimedRewardSnapshot = currentRewardScaled(self, treasure);
|
|
156
|
+
treasure.rewardPerTokenAccumulated = self.rewardPerTokenAccumulated;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/// @notice Creates a new stake deposit with delegation and commission
|
|
160
|
+
function stake(
|
|
161
|
+
Layout storage self,
|
|
162
|
+
address owner,
|
|
163
|
+
uint96 amount,
|
|
164
|
+
address delegatee,
|
|
165
|
+
address beneficiary,
|
|
166
|
+
uint256 commissionRate
|
|
167
|
+
) internal returns (uint256 depositId) {
|
|
168
|
+
if (amount == 0) StakingRewards__InvalidAmount.selector.revertWith();
|
|
169
|
+
|
|
170
|
+
if (delegatee == address(0) || beneficiary == address(0)) {
|
|
171
|
+
StakingRewards__InvalidAddress.selector.revertWith();
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
depositId = self.nextDepositId++;
|
|
175
|
+
Deposit storage deposit = self.depositById[depositId];
|
|
176
|
+
|
|
177
|
+
// batch storage writes
|
|
178
|
+
(deposit.owner, deposit.beneficiary, deposit.delegatee) = (owner, beneficiary, delegatee);
|
|
179
|
+
|
|
180
|
+
increaseStake(self, deposit, owner, amount, delegatee, beneficiary, commissionRate);
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
/// @notice Increases the stake amount for an existing deposit
|
|
184
|
+
/// @dev Assumes `owner` is the same as `deposit.owner`
|
|
185
|
+
/// @dev Assumes `delegatee` and `beneficiary` match `deposit.delegatee` and `deposit.beneficiary`
|
|
186
|
+
function increaseStake(
|
|
187
|
+
Layout storage self,
|
|
188
|
+
Deposit storage deposit,
|
|
189
|
+
address owner,
|
|
190
|
+
uint96 amount,
|
|
191
|
+
address delegatee,
|
|
192
|
+
address beneficiary,
|
|
193
|
+
uint256 commissionRate
|
|
194
|
+
) internal {
|
|
195
|
+
updateGlobalReward(self);
|
|
196
|
+
|
|
197
|
+
Treasure storage beneficiaryTreasure = self.treasureByBeneficiary[beneficiary];
|
|
198
|
+
updateReward(self, beneficiaryTreasure);
|
|
199
|
+
|
|
200
|
+
self.totalStaked += amount;
|
|
201
|
+
unchecked {
|
|
202
|
+
// because totalStaked >= stakedByDepositor[owner] >= deposit.amount
|
|
203
|
+
// if totalStaked doesn't overflow, they won't
|
|
204
|
+
self.stakedByDepositor[owner] += amount;
|
|
205
|
+
deposit.amount += amount;
|
|
206
|
+
}
|
|
207
|
+
_increaseEarningPower(
|
|
208
|
+
self,
|
|
209
|
+
deposit,
|
|
210
|
+
beneficiaryTreasure,
|
|
211
|
+
amount,
|
|
212
|
+
delegatee,
|
|
213
|
+
commissionRate
|
|
214
|
+
);
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
/// @notice Changes the delegatee for an existing deposit
|
|
218
|
+
function redelegate(
|
|
219
|
+
Layout storage self,
|
|
220
|
+
Deposit storage deposit,
|
|
221
|
+
address newDelegatee,
|
|
222
|
+
uint256 commissionRate
|
|
223
|
+
) internal {
|
|
224
|
+
updateGlobalReward(self);
|
|
225
|
+
|
|
226
|
+
Treasure storage beneficiaryTreasure = self.treasureByBeneficiary[deposit.beneficiary];
|
|
227
|
+
updateReward(self, beneficiaryTreasure);
|
|
228
|
+
|
|
229
|
+
_decreaseEarningPower(self, deposit, beneficiaryTreasure);
|
|
230
|
+
|
|
231
|
+
_increaseEarningPower(
|
|
232
|
+
self,
|
|
233
|
+
deposit,
|
|
234
|
+
beneficiaryTreasure,
|
|
235
|
+
deposit.amount,
|
|
236
|
+
newDelegatee,
|
|
237
|
+
commissionRate
|
|
238
|
+
);
|
|
239
|
+
|
|
240
|
+
deposit.delegatee = newDelegatee;
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
/// @notice Changes the beneficiary for an existing deposit
|
|
244
|
+
/// @dev Assumes `commissionRate` matches the intended rate for the current delegatee
|
|
245
|
+
function changeBeneficiary(
|
|
246
|
+
Layout storage self,
|
|
247
|
+
Deposit storage deposit,
|
|
248
|
+
address newBeneficiary,
|
|
249
|
+
uint256 commissionRate
|
|
250
|
+
) internal {
|
|
251
|
+
if (newBeneficiary == address(0)) StakingRewards__InvalidAddress.selector.revertWith();
|
|
252
|
+
|
|
253
|
+
updateGlobalReward(self);
|
|
254
|
+
|
|
255
|
+
(uint96 amount, address oldBeneficiary, address delegatee) = (
|
|
256
|
+
deposit.amount,
|
|
257
|
+
deposit.beneficiary,
|
|
258
|
+
deposit.delegatee
|
|
259
|
+
);
|
|
260
|
+
deposit.beneficiary = newBeneficiary;
|
|
261
|
+
|
|
262
|
+
Treasure storage oldTreasure = self.treasureByBeneficiary[oldBeneficiary];
|
|
263
|
+
updateReward(self, oldTreasure);
|
|
264
|
+
|
|
265
|
+
_decreaseEarningPower(self, deposit, oldTreasure);
|
|
266
|
+
|
|
267
|
+
Treasure storage newTreasure = self.treasureByBeneficiary[newBeneficiary];
|
|
268
|
+
updateReward(self, newTreasure);
|
|
269
|
+
|
|
270
|
+
_increaseEarningPower(self, deposit, newTreasure, amount, delegatee, commissionRate);
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
/// @notice Withdraws the full amount from a deposit and marks it for pending withdrawal
|
|
274
|
+
function withdraw(Layout storage self, Deposit storage deposit) internal returns (uint96) {
|
|
275
|
+
updateGlobalReward(self);
|
|
276
|
+
|
|
277
|
+
Treasure storage beneficiaryTreasure = self.treasureByBeneficiary[deposit.beneficiary];
|
|
278
|
+
updateReward(self, beneficiaryTreasure);
|
|
279
|
+
|
|
280
|
+
// cache storage reads
|
|
281
|
+
(uint96 amount, address owner) = (deposit.amount, deposit.owner);
|
|
282
|
+
|
|
283
|
+
unchecked {
|
|
284
|
+
// totalStaked >= deposit.amount
|
|
285
|
+
self.totalStaked -= amount;
|
|
286
|
+
// stakedByDepositor[owner] >= deposit.amount
|
|
287
|
+
self.stakedByDepositor[owner] -= amount;
|
|
288
|
+
}
|
|
289
|
+
_decreaseEarningPower(self, deposit, beneficiaryTreasure);
|
|
290
|
+
|
|
291
|
+
(deposit.amount, deposit.delegatee, deposit.pendingWithdrawal) = (0, address(0), amount);
|
|
292
|
+
return amount;
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
/// @notice Claims accumulated rewards for a beneficiary
|
|
296
|
+
function claimReward(
|
|
297
|
+
Layout storage self,
|
|
298
|
+
address beneficiary
|
|
299
|
+
) internal returns (uint256 reward) {
|
|
300
|
+
updateGlobalReward(self);
|
|
301
|
+
|
|
302
|
+
Treasure storage treasure = self.treasureByBeneficiary[beneficiary];
|
|
303
|
+
updateReward(self, treasure);
|
|
304
|
+
|
|
305
|
+
reward = treasure.unclaimedRewardSnapshot / SCALE_FACTOR;
|
|
306
|
+
if (reward != 0) {
|
|
307
|
+
unchecked {
|
|
308
|
+
treasure.unclaimedRewardSnapshot -= reward * SCALE_FACTOR;
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
/// @notice Sets up a new reward distribution period
|
|
314
|
+
/// @dev Manually updates global reward state instead of calling updateGlobalReward()
|
|
315
|
+
/// since it resets the reward period timing. This function combines reward index update
|
|
316
|
+
/// with new period setup in a single operation.
|
|
317
|
+
/// @param self The staking rewards storage layout
|
|
318
|
+
/// @param reward The additional amount of rewards to distribute over the reward duration
|
|
319
|
+
function notifyRewardAmount(Layout storage self, uint256 reward) internal {
|
|
320
|
+
self.rewardPerTokenAccumulated = currentRewardPerTokenAccumulated(self);
|
|
321
|
+
|
|
322
|
+
// cache storage reads
|
|
323
|
+
(uint256 rewardDuration, uint256 rewardEndTime) = (self.rewardDuration, self.rewardEndTime);
|
|
324
|
+
|
|
325
|
+
uint256 rewardRate = FixedPointMathLib.fullMulDiv(reward, SCALE_FACTOR, rewardDuration);
|
|
326
|
+
// if the reward period hasn't ended, add the remaining reward to the reward rate
|
|
327
|
+
if (rewardEndTime > block.timestamp) {
|
|
328
|
+
uint256 remainingTime;
|
|
329
|
+
unchecked {
|
|
330
|
+
remainingTime = rewardEndTime - block.timestamp;
|
|
331
|
+
}
|
|
332
|
+
rewardRate += FixedPointMathLib.fullMulDiv(
|
|
333
|
+
self.rewardRate,
|
|
334
|
+
remainingTime,
|
|
335
|
+
rewardDuration
|
|
336
|
+
);
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
// batch storage writes
|
|
340
|
+
(self.rewardEndTime, self.lastUpdateTime, self.rewardRate) = (
|
|
341
|
+
block.timestamp + rewardDuration,
|
|
342
|
+
block.timestamp,
|
|
343
|
+
rewardRate
|
|
344
|
+
);
|
|
345
|
+
|
|
346
|
+
if (rewardRate < SCALE_FACTOR) StakingRewards__InvalidRewardRate.selector.revertWith();
|
|
347
|
+
|
|
348
|
+
if (
|
|
349
|
+
FixedPointMathLib.fullMulDiv(rewardRate, rewardDuration, SCALE_FACTOR) >
|
|
350
|
+
IERC20(self.rewardToken).balanceOf(address(this))
|
|
351
|
+
) StakingRewards__InsufficientReward.selector.revertWith();
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
/// @notice Sweeps and clears all unclaimed rewards for a beneficiary
|
|
355
|
+
/// @dev Updates global rewards state and beneficiary's reward snapshot before clearing.
|
|
356
|
+
/// This function removes all pending rewards without transferring them elsewhere.
|
|
357
|
+
/// @param self The staking rewards storage layout
|
|
358
|
+
/// @param beneficiary The beneficiary whose rewards will be swept and cleared
|
|
359
|
+
/// @return sweptAmount The amount of scaled rewards that were cleared
|
|
360
|
+
function sweepReward(
|
|
361
|
+
Layout storage self,
|
|
362
|
+
address beneficiary
|
|
363
|
+
) internal returns (uint256 sweptAmount) {
|
|
364
|
+
updateGlobalReward(self);
|
|
365
|
+
|
|
366
|
+
Treasure storage treasure = self.treasureByBeneficiary[beneficiary];
|
|
367
|
+
updateReward(self, treasure);
|
|
368
|
+
|
|
369
|
+
sweptAmount = treasure.unclaimedRewardSnapshot;
|
|
370
|
+
treasure.unclaimedRewardSnapshot = 0;
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
/// @notice Transfers all unclaimed rewards from one beneficiary to another
|
|
374
|
+
/// @dev Sweeps rewards from source beneficiary and transfers them to destination
|
|
375
|
+
/// @param self The staking rewards storage layout
|
|
376
|
+
/// @param from The beneficiary to transfer rewards from
|
|
377
|
+
/// @param to The beneficiary to transfer rewards to
|
|
378
|
+
/// @return transferredAmount The amount of scaled rewards transferred
|
|
379
|
+
function transferReward(
|
|
380
|
+
Layout storage self,
|
|
381
|
+
address from,
|
|
382
|
+
address to
|
|
383
|
+
) internal returns (uint256 transferredAmount) {
|
|
384
|
+
// sweep and clear rewards from source beneficiary
|
|
385
|
+
transferredAmount = sweepReward(self, from);
|
|
386
|
+
if (transferredAmount == 0) return 0;
|
|
387
|
+
|
|
388
|
+
// transfer swept rewards to destination beneficiary
|
|
389
|
+
Treasure storage toTreasure = self.treasureByBeneficiary[to];
|
|
390
|
+
// no updateReward needed: reward math is associative, pending rewards
|
|
391
|
+
// will be correctly calculated on next updateReward call
|
|
392
|
+
toTreasure.unclaimedRewardSnapshot += transferredAmount;
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
|
|
396
|
+
/* ACCOUNTING */
|
|
397
|
+
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
|
|
398
|
+
|
|
399
|
+
/// @dev Increases the earning power of the beneficiary and the delegatee, taking into account
|
|
400
|
+
/// the commission rate
|
|
401
|
+
/// @dev Must be called after `updateReward(self, beneficiaryTreasure)`
|
|
402
|
+
/// @dev Assumes `beneficiaryTreasure` corresponds to the deposit's current beneficiary
|
|
403
|
+
/// @dev Invariant: deposit.amount >= deposit.commissionEarningPower
|
|
404
|
+
/// This is maintained because commission rate <= MAX_COMMISSION_RATE
|
|
405
|
+
function _increaseEarningPower(
|
|
406
|
+
Layout storage self,
|
|
407
|
+
Deposit storage deposit,
|
|
408
|
+
Treasure storage beneficiaryTreasure,
|
|
409
|
+
uint96 amount,
|
|
410
|
+
address delegatee,
|
|
411
|
+
uint256 commissionRate
|
|
412
|
+
) private {
|
|
413
|
+
unchecked {
|
|
414
|
+
if (commissionRate == 0) {
|
|
415
|
+
beneficiaryTreasure.earningPower += amount;
|
|
416
|
+
} else {
|
|
417
|
+
uint96 commissionEarningPower = uint96(
|
|
418
|
+
(uint256(amount) * commissionRate) / MAX_COMMISSION_RATE
|
|
419
|
+
);
|
|
420
|
+
deposit.commissionEarningPower += commissionEarningPower;
|
|
421
|
+
beneficiaryTreasure.earningPower += amount - commissionEarningPower;
|
|
422
|
+
|
|
423
|
+
Treasure storage delegateeTreasure = self.treasureByBeneficiary[delegatee];
|
|
424
|
+
updateReward(self, delegateeTreasure);
|
|
425
|
+
delegateeTreasure.earningPower += commissionEarningPower;
|
|
426
|
+
}
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
/// @dev Decreases the earning power of the beneficiary and the delegatee, taking into account
|
|
431
|
+
/// the commission rate
|
|
432
|
+
/// @dev Must be called after `updateReward(self, beneficiaryTreasure)`
|
|
433
|
+
/// @dev Assumes `beneficiaryTreasure` corresponds to the deposit's current beneficiary
|
|
434
|
+
function _decreaseEarningPower(
|
|
435
|
+
Layout storage self,
|
|
436
|
+
Deposit storage deposit,
|
|
437
|
+
Treasure storage beneficiaryTreasure
|
|
438
|
+
) private {
|
|
439
|
+
unchecked {
|
|
440
|
+
(uint96 amount, uint96 commissionEarningPower, address delegatee) = (
|
|
441
|
+
deposit.amount,
|
|
442
|
+
deposit.commissionEarningPower,
|
|
443
|
+
deposit.delegatee
|
|
444
|
+
);
|
|
445
|
+
|
|
446
|
+
// Defensive check: ensure commission earning power doesn't exceed stake amount
|
|
447
|
+
// While this invariant should mathematically hold through normal operations,
|
|
448
|
+
// explicit validation protects against potential bugs, storage corruption,
|
|
449
|
+
// or future code changes that might violate this critical assumption
|
|
450
|
+
if (commissionEarningPower > amount) {
|
|
451
|
+
StakingRewards__CommissionExceedsStake.selector.revertWith();
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
if (commissionEarningPower == 0) {
|
|
455
|
+
beneficiaryTreasure.earningPower -= amount;
|
|
456
|
+
} else {
|
|
457
|
+
deposit.commissionEarningPower = 0;
|
|
458
|
+
beneficiaryTreasure.earningPower -= amount - commissionEarningPower;
|
|
459
|
+
|
|
460
|
+
Treasure storage delegateeTreasure = self.treasureByBeneficiary[delegatee];
|
|
461
|
+
updateReward(self, delegateeTreasure);
|
|
462
|
+
delegateeTreasure.earningPower -= commissionEarningPower;
|
|
463
|
+
}
|
|
464
|
+
}
|
|
465
|
+
}
|
|
466
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
pragma solidity ^0.8.23;
|
|
3
|
+
|
|
4
|
+
// interfaces
|
|
5
|
+
|
|
6
|
+
// libraries
|
|
7
|
+
|
|
8
|
+
// contracts
|
|
9
|
+
|
|
10
|
+
interface ICrossDomainMessenger {
|
|
11
|
+
event FailedRelayedMessage(bytes32 indexed msgHash);
|
|
12
|
+
event RelayedMessage(bytes32 indexed msgHash);
|
|
13
|
+
event SentMessage(
|
|
14
|
+
address indexed target,
|
|
15
|
+
address sender,
|
|
16
|
+
bytes message,
|
|
17
|
+
uint256 messageNonce,
|
|
18
|
+
uint256 gasLimit
|
|
19
|
+
);
|
|
20
|
+
event SentMessageExtension1(address indexed sender, uint256 value);
|
|
21
|
+
|
|
22
|
+
function MESSAGE_VERSION() external view returns (uint16);
|
|
23
|
+
|
|
24
|
+
function MIN_GAS_CALLDATA_OVERHEAD() external view returns (uint64);
|
|
25
|
+
|
|
26
|
+
function MIN_GAS_CONSTANT_OVERHEAD() external view returns (uint64);
|
|
27
|
+
|
|
28
|
+
function MIN_GAS_DYNAMIC_OVERHEAD_DENOMINATOR() external view returns (uint64);
|
|
29
|
+
|
|
30
|
+
function MIN_GAS_DYNAMIC_OVERHEAD_NUMERATOR() external view returns (uint64);
|
|
31
|
+
|
|
32
|
+
function OTHER_MESSENGER() external view returns (address);
|
|
33
|
+
|
|
34
|
+
function baseGas(bytes memory _message, uint32 _minGasLimit) external pure returns (uint64);
|
|
35
|
+
|
|
36
|
+
function failedMessages(bytes32) external view returns (bool);
|
|
37
|
+
|
|
38
|
+
function messageNonce() external view returns (uint256);
|
|
39
|
+
|
|
40
|
+
function relayMessage(
|
|
41
|
+
uint256 _nonce,
|
|
42
|
+
address _sender,
|
|
43
|
+
address _target,
|
|
44
|
+
uint256 _value,
|
|
45
|
+
uint256 _minGasLimit,
|
|
46
|
+
bytes memory _message
|
|
47
|
+
) external payable;
|
|
48
|
+
|
|
49
|
+
function sendMessage(
|
|
50
|
+
address _target,
|
|
51
|
+
bytes memory _message,
|
|
52
|
+
uint32 _minGasLimit
|
|
53
|
+
) external payable;
|
|
54
|
+
|
|
55
|
+
function successfulMessages(bytes32) external view returns (bool);
|
|
56
|
+
|
|
57
|
+
function xDomainMessageSender() external view returns (address);
|
|
58
|
+
}
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
pragma solidity ^0.8.23;
|
|
3
|
+
|
|
4
|
+
interface IMainnetDelegationBase {
|
|
5
|
+
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
|
|
6
|
+
/* STRUCTS */
|
|
7
|
+
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
|
|
8
|
+
|
|
9
|
+
/// @notice Delegation struct
|
|
10
|
+
/// @param operator The operator address
|
|
11
|
+
/// @param quantity The quantity to delegate
|
|
12
|
+
/// @param delegator The delegator address
|
|
13
|
+
/// @param delegationTime The delegation time
|
|
14
|
+
struct Delegation {
|
|
15
|
+
address operator;
|
|
16
|
+
uint256 quantity;
|
|
17
|
+
address delegator;
|
|
18
|
+
uint256 delegationTime;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/// @notice Delegation message from L1
|
|
22
|
+
/// @param delegator The delegator address
|
|
23
|
+
/// @param delegatee The delegatee address
|
|
24
|
+
/// @param quantity The quantity to delegate
|
|
25
|
+
/// @param claimer The claimer address
|
|
26
|
+
struct DelegationMsg {
|
|
27
|
+
address delegator;
|
|
28
|
+
address delegatee;
|
|
29
|
+
uint256 quantity;
|
|
30
|
+
address claimer;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
|
|
34
|
+
/* EVENTS */
|
|
35
|
+
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
|
|
36
|
+
|
|
37
|
+
event DelegationSet(address indexed delegator, address indexed operator, uint256 quantity);
|
|
38
|
+
|
|
39
|
+
event DelegationRemoved(address indexed delegator);
|
|
40
|
+
|
|
41
|
+
event ClaimerSet(address indexed delegator, address indexed claimer);
|
|
42
|
+
|
|
43
|
+
event DelegationDigestSet(bytes32 digest);
|
|
44
|
+
|
|
45
|
+
event CrossDomainMessengerSet(address messenger);
|
|
46
|
+
|
|
47
|
+
event ProxyDelegationSet(address proxyDelegation);
|
|
48
|
+
|
|
49
|
+
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
|
|
50
|
+
/* ERRORS */
|
|
51
|
+
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
|
|
52
|
+
|
|
53
|
+
error InvalidDelegator(address delegator);
|
|
54
|
+
error InvalidOperator(address operator);
|
|
55
|
+
error InvalidQuantity(uint256 quantity);
|
|
56
|
+
error DelegationAlreadySet(address delegator, address operator);
|
|
57
|
+
error DelegationNotSet();
|
|
58
|
+
error InvalidClaimer(address claimer);
|
|
59
|
+
error InvalidOwner(address owner);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
interface IMainnetDelegation is IMainnetDelegationBase {
|
|
63
|
+
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
|
|
64
|
+
/* ADMIN FUNCTIONS */
|
|
65
|
+
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
|
|
66
|
+
|
|
67
|
+
/// @notice Set proxy delegation
|
|
68
|
+
/// @param proxyDelegation The proxy delegation address
|
|
69
|
+
function setProxyDelegation(address proxyDelegation) external;
|
|
70
|
+
|
|
71
|
+
/// @notice Relay cross-chain delegations
|
|
72
|
+
/// @dev Only the owner can call this function
|
|
73
|
+
/// @param encodedMsgs The encoded delegation messages
|
|
74
|
+
function relayDelegations(bytes calldata encodedMsgs) external;
|
|
75
|
+
|
|
76
|
+
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
|
|
77
|
+
/* DELEGATION */
|
|
78
|
+
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
|
|
79
|
+
|
|
80
|
+
/// @notice Set delegation digest from L1
|
|
81
|
+
/// @dev Only the L2 messenger can call this function
|
|
82
|
+
/// @param digest The delegation digest
|
|
83
|
+
function setDelegationDigest(bytes32 digest) external;
|
|
84
|
+
|
|
85
|
+
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
|
|
86
|
+
/* GETTERS */
|
|
87
|
+
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
|
|
88
|
+
|
|
89
|
+
/// @notice Get the L2 messenger address
|
|
90
|
+
/// @return The L2 messenger address
|
|
91
|
+
function getMessenger() external view returns (address);
|
|
92
|
+
|
|
93
|
+
/// @notice Get proxy delegation
|
|
94
|
+
/// @return The proxy delegation address
|
|
95
|
+
function getProxyDelegation() external view returns (address);
|
|
96
|
+
|
|
97
|
+
/// @notice Get all mainnet delegators
|
|
98
|
+
/// @return Array of all mainnet delegator addresses
|
|
99
|
+
function getMainnetDelegators() external view returns (address[] memory);
|
|
100
|
+
|
|
101
|
+
/// @notice Get the deposit ID by delegator
|
|
102
|
+
/// @param delegator The mainnet delegator address
|
|
103
|
+
/// @return The deposit ID
|
|
104
|
+
function getDepositIdByDelegator(address delegator) external view returns (uint256);
|
|
105
|
+
|
|
106
|
+
/// @notice Get delegation of a delegator
|
|
107
|
+
/// @param delegator The delegator address
|
|
108
|
+
/// @return Delegation of the delegator
|
|
109
|
+
function getDelegationByDelegator(address delegator) external view returns (Delegation memory);
|
|
110
|
+
|
|
111
|
+
/// @notice Get all delegations to a specific operator
|
|
112
|
+
/// @param operator The operator address
|
|
113
|
+
/// @return Array of all delegations to the operator
|
|
114
|
+
function getMainnetDelegationsByOperator(
|
|
115
|
+
address operator
|
|
116
|
+
) external view returns (Delegation[] memory);
|
|
117
|
+
|
|
118
|
+
/// @notice Get the total delegated stake of an operator
|
|
119
|
+
/// @param operator The operator address
|
|
120
|
+
/// @return The total delegated stake of the operator
|
|
121
|
+
function getDelegatedStakeByOperator(address operator) external view returns (uint256);
|
|
122
|
+
|
|
123
|
+
/// @notice Get the authorized claimer for a mainnet delegator
|
|
124
|
+
/// @param delegator The mainnet delegator address
|
|
125
|
+
/// @return The authorized claimer address for the delegator
|
|
126
|
+
function getAuthorizedClaimer(address delegator) external view returns (address);
|
|
127
|
+
}
|