@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,642 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
// OpenZeppelin Contracts (last updated v4.9.0) (utils/Checkpoints.sol)
|
|
3
|
+
// This file was procedurally generated from scripts/generate/templates/Checkpoints.js.
|
|
4
|
+
|
|
5
|
+
pragma solidity ^0.8.0;
|
|
6
|
+
|
|
7
|
+
import {FixedPointMathLib} from "solady/utils/FixedPointMathLib.sol";
|
|
8
|
+
import {SafeCastLib} from "solady/utils/SafeCastLib.sol";
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* @dev This library defines the `History` struct, for checkpointing values as they change at
|
|
12
|
+
* different points in
|
|
13
|
+
* time, and later looking up past values by block number. See {Votes} as an example.
|
|
14
|
+
*
|
|
15
|
+
* To create a history of checkpoints define a variable type `Checkpoints.History` in your contract,
|
|
16
|
+
* and store a new
|
|
17
|
+
* checkpoint for the current transaction block using the {push} function.
|
|
18
|
+
*
|
|
19
|
+
* _Available since v4.5._
|
|
20
|
+
*/
|
|
21
|
+
library Checkpoints {
|
|
22
|
+
struct History {
|
|
23
|
+
Checkpoint[] _checkpoints;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
struct Checkpoint {
|
|
27
|
+
uint32 _blockNumber;
|
|
28
|
+
uint224 _value;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* @dev Returns the value at a given block number. If a checkpoint is not available at that
|
|
33
|
+
* block,
|
|
34
|
+
* the closest one
|
|
35
|
+
* before it is returned, or zero otherwise. Because the number returned corresponds to that at
|
|
36
|
+
* the end of the
|
|
37
|
+
* block, the requested block number must be in the past, excluding the current block.
|
|
38
|
+
*/
|
|
39
|
+
function getAtBlock(History storage self, uint256 blockNumber) internal view returns (uint256) {
|
|
40
|
+
require(blockNumber < block.number, "Checkpoints: block not yet mined");
|
|
41
|
+
uint32 key = SafeCastLib.toUint32(blockNumber);
|
|
42
|
+
|
|
43
|
+
uint256 len = self._checkpoints.length;
|
|
44
|
+
uint256 pos = _upperBinaryLookup(self._checkpoints, key, 0, len);
|
|
45
|
+
return pos == 0 ? 0 : _unsafeAccess(self._checkpoints, pos - 1)._value;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* @dev Returns the value at a given block number. If a checkpoint is not available at that
|
|
50
|
+
* block,
|
|
51
|
+
* the closest one
|
|
52
|
+
* before it is returned, or zero otherwise. Similar to {upperLookup} but optimized for the case
|
|
53
|
+
* when the searched
|
|
54
|
+
* checkpoint is probably "recent", defined as being among the last sqrt(N) checkpoints where N
|
|
55
|
+
* is
|
|
56
|
+
* the number of
|
|
57
|
+
* checkpoints.
|
|
58
|
+
*/
|
|
59
|
+
function getAtProbablyRecentBlock(
|
|
60
|
+
History storage self,
|
|
61
|
+
uint256 blockNumber
|
|
62
|
+
) internal view returns (uint256) {
|
|
63
|
+
require(blockNumber < block.number, "Checkpoints: block not yet mined");
|
|
64
|
+
uint32 key = SafeCastLib.toUint32(blockNumber);
|
|
65
|
+
|
|
66
|
+
uint256 len = self._checkpoints.length;
|
|
67
|
+
|
|
68
|
+
uint256 low = 0;
|
|
69
|
+
uint256 high = len;
|
|
70
|
+
|
|
71
|
+
if (len > 5) {
|
|
72
|
+
uint256 mid = len - FixedPointMathLib.sqrt(len);
|
|
73
|
+
if (key < _unsafeAccess(self._checkpoints, mid)._blockNumber) {
|
|
74
|
+
high = mid;
|
|
75
|
+
} else {
|
|
76
|
+
low = mid + 1;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
uint256 pos = _upperBinaryLookup(self._checkpoints, key, low, high);
|
|
81
|
+
|
|
82
|
+
return pos == 0 ? 0 : _unsafeAccess(self._checkpoints, pos - 1)._value;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* @dev Pushes a value onto a History so that it is stored as the checkpoint for the current
|
|
87
|
+
* block.
|
|
88
|
+
*
|
|
89
|
+
* Returns previous value and new value.
|
|
90
|
+
*/
|
|
91
|
+
function push(History storage self, uint256 value) internal returns (uint256, uint256) {
|
|
92
|
+
return
|
|
93
|
+
_insert(
|
|
94
|
+
self._checkpoints,
|
|
95
|
+
SafeCastLib.toUint32(block.number),
|
|
96
|
+
SafeCastLib.toUint224(value)
|
|
97
|
+
);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* @dev Pushes a value onto a History, by updating the latest value using binary operation `op`.
|
|
102
|
+
* The new value will
|
|
103
|
+
* be set to `op(latest, delta)`.
|
|
104
|
+
*
|
|
105
|
+
* Returns previous value and new value.
|
|
106
|
+
*/
|
|
107
|
+
function push(
|
|
108
|
+
History storage self,
|
|
109
|
+
function(uint256, uint256) view returns (uint256) op,
|
|
110
|
+
uint256 delta
|
|
111
|
+
) internal returns (uint256, uint256) {
|
|
112
|
+
return push(self, op(latest(self), delta));
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* @dev Returns the value in the most recent checkpoint, or zero if there are no checkpoints.
|
|
117
|
+
*/
|
|
118
|
+
function latest(History storage self) internal view returns (uint224) {
|
|
119
|
+
uint256 pos = self._checkpoints.length;
|
|
120
|
+
return pos == 0 ? 0 : _unsafeAccess(self._checkpoints, pos - 1)._value;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* @dev Returns whether there is a checkpoint in the structure (i.e. it is not empty), and if so
|
|
125
|
+
* the key and value
|
|
126
|
+
* in the most recent checkpoint.
|
|
127
|
+
*/
|
|
128
|
+
function latestCheckpoint(
|
|
129
|
+
History storage self
|
|
130
|
+
) internal view returns (bool exists, uint32 _blockNumber, uint224 _value) {
|
|
131
|
+
uint256 pos = self._checkpoints.length;
|
|
132
|
+
if (pos == 0) {
|
|
133
|
+
return (false, 0, 0);
|
|
134
|
+
} else {
|
|
135
|
+
Checkpoint memory ckpt = _unsafeAccess(self._checkpoints, pos - 1);
|
|
136
|
+
return (true, ckpt._blockNumber, ckpt._value);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* @dev Returns the number of checkpoint.
|
|
142
|
+
*/
|
|
143
|
+
function length(History storage self) internal view returns (uint256) {
|
|
144
|
+
return self._checkpoints.length;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* @dev Pushes a (`key`, `value`) pair into an ordered list of checkpoints, either by inserting
|
|
149
|
+
* a
|
|
150
|
+
* new checkpoint,
|
|
151
|
+
* or by updating the last one.
|
|
152
|
+
*/
|
|
153
|
+
function _insert(
|
|
154
|
+
Checkpoint[] storage self,
|
|
155
|
+
uint32 key,
|
|
156
|
+
uint224 value
|
|
157
|
+
) private returns (uint224, uint224) {
|
|
158
|
+
uint256 pos = self.length;
|
|
159
|
+
|
|
160
|
+
if (pos > 0) {
|
|
161
|
+
// Copying to memory is important here.
|
|
162
|
+
Checkpoint memory last = _unsafeAccess(self, pos - 1);
|
|
163
|
+
|
|
164
|
+
// Checkpoint keys must be non-decreasing.
|
|
165
|
+
require(last._blockNumber <= key, "Checkpoint: decreasing keys");
|
|
166
|
+
|
|
167
|
+
// Update or push new checkpoint
|
|
168
|
+
if (last._blockNumber == key) {
|
|
169
|
+
_unsafeAccess(self, pos - 1)._value = value;
|
|
170
|
+
} else {
|
|
171
|
+
self.push(Checkpoint({_blockNumber: key, _value: value}));
|
|
172
|
+
}
|
|
173
|
+
return (last._value, value);
|
|
174
|
+
} else {
|
|
175
|
+
self.push(Checkpoint({_blockNumber: key, _value: value}));
|
|
176
|
+
return (0, value);
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* @dev Return the index of the last (most recent) checkpoint with key lower or equal than the
|
|
182
|
+
* search key, or `high` if there is none.
|
|
183
|
+
* `low` and `high` define a section where to do the search, with inclusive `low` and exclusive
|
|
184
|
+
* `high`.
|
|
185
|
+
*
|
|
186
|
+
* WARNING: `high` should not be greater than the array's length.
|
|
187
|
+
*/
|
|
188
|
+
function _upperBinaryLookup(
|
|
189
|
+
Checkpoint[] storage self,
|
|
190
|
+
uint32 key,
|
|
191
|
+
uint256 low,
|
|
192
|
+
uint256 high
|
|
193
|
+
) private view returns (uint256) {
|
|
194
|
+
while (low < high) {
|
|
195
|
+
uint256 mid = FixedPointMathLib.avg(low, high);
|
|
196
|
+
if (_unsafeAccess(self, mid)._blockNumber > key) {
|
|
197
|
+
high = mid;
|
|
198
|
+
} else {
|
|
199
|
+
low = mid + 1;
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
return high;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
/**
|
|
206
|
+
* @dev Return the index of the first (oldest) checkpoint with key is greater or equal than the
|
|
207
|
+
* search key, or `high` if there is none.
|
|
208
|
+
* `low` and `high` define a section where to do the search, with inclusive `low` and exclusive
|
|
209
|
+
* `high`.
|
|
210
|
+
*
|
|
211
|
+
* WARNING: `high` should not be greater than the array's length.
|
|
212
|
+
*/
|
|
213
|
+
function _lowerBinaryLookup(
|
|
214
|
+
Checkpoint[] storage self,
|
|
215
|
+
uint32 key,
|
|
216
|
+
uint256 low,
|
|
217
|
+
uint256 high
|
|
218
|
+
) private view returns (uint256) {
|
|
219
|
+
while (low < high) {
|
|
220
|
+
uint256 mid = FixedPointMathLib.avg(low, high);
|
|
221
|
+
if (_unsafeAccess(self, mid)._blockNumber < key) {
|
|
222
|
+
low = mid + 1;
|
|
223
|
+
} else {
|
|
224
|
+
high = mid;
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
return high;
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
/**
|
|
231
|
+
* @dev Access an element of the array without performing bounds check. The position is assumed
|
|
232
|
+
* to
|
|
233
|
+
* be within bounds.
|
|
234
|
+
*/
|
|
235
|
+
function _unsafeAccess(
|
|
236
|
+
Checkpoint[] storage self,
|
|
237
|
+
uint256 pos
|
|
238
|
+
) private pure returns (Checkpoint storage result) {
|
|
239
|
+
assembly {
|
|
240
|
+
mstore(0, self.slot)
|
|
241
|
+
result.slot := add(keccak256(0, 0x20), pos)
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
struct Trace224 {
|
|
246
|
+
Checkpoint224[] _checkpoints;
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
struct Checkpoint224 {
|
|
250
|
+
uint32 _key;
|
|
251
|
+
uint224 _value;
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
/**
|
|
255
|
+
* @dev Pushes a (`key`, `value`) pair into a Trace224 so that it is stored as the checkpoint.
|
|
256
|
+
*
|
|
257
|
+
* Returns previous value and new value.
|
|
258
|
+
*/
|
|
259
|
+
function push(
|
|
260
|
+
Trace224 storage self,
|
|
261
|
+
uint32 key,
|
|
262
|
+
uint224 value
|
|
263
|
+
) internal returns (uint224, uint224) {
|
|
264
|
+
return _insert(self._checkpoints, key, value);
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
/**
|
|
268
|
+
* @dev Returns the value in the first (oldest) checkpoint with key greater or equal than the
|
|
269
|
+
* search key, or zero if there is none.
|
|
270
|
+
*/
|
|
271
|
+
function lowerLookup(Trace224 storage self, uint32 key) internal view returns (uint224) {
|
|
272
|
+
uint256 len = self._checkpoints.length;
|
|
273
|
+
uint256 pos = _lowerBinaryLookup(self._checkpoints, key, 0, len);
|
|
274
|
+
return pos == len ? 0 : _unsafeAccess(self._checkpoints, pos)._value;
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
/**
|
|
278
|
+
* @dev Returns the value in the last (most recent) checkpoint with key lower or equal than the
|
|
279
|
+
* search key, or zero if there is none.
|
|
280
|
+
*/
|
|
281
|
+
function upperLookup(Trace224 storage self, uint32 key) internal view returns (uint224) {
|
|
282
|
+
uint256 len = self._checkpoints.length;
|
|
283
|
+
uint256 pos = _upperBinaryLookup(self._checkpoints, key, 0, len);
|
|
284
|
+
return pos == 0 ? 0 : _unsafeAccess(self._checkpoints, pos - 1)._value;
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
/**
|
|
288
|
+
* @dev Returns the value in the last (most recent) checkpoint with key lower or equal than the
|
|
289
|
+
* search key, or zero if there is none.
|
|
290
|
+
*
|
|
291
|
+
* NOTE: This is a variant of {upperLookup} that is optimised to find "recent" checkpoint
|
|
292
|
+
* (checkpoints with high keys).
|
|
293
|
+
*/
|
|
294
|
+
function upperLookupRecent(Trace224 storage self, uint32 key) internal view returns (uint224) {
|
|
295
|
+
uint256 len = self._checkpoints.length;
|
|
296
|
+
|
|
297
|
+
uint256 low = 0;
|
|
298
|
+
uint256 high = len;
|
|
299
|
+
|
|
300
|
+
if (len > 5) {
|
|
301
|
+
uint256 mid = len - FixedPointMathLib.sqrt(len);
|
|
302
|
+
if (key < _unsafeAccess(self._checkpoints, mid)._key) {
|
|
303
|
+
high = mid;
|
|
304
|
+
} else {
|
|
305
|
+
low = mid + 1;
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
uint256 pos = _upperBinaryLookup(self._checkpoints, key, low, high);
|
|
310
|
+
|
|
311
|
+
return pos == 0 ? 0 : _unsafeAccess(self._checkpoints, pos - 1)._value;
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
/**
|
|
315
|
+
* @dev Returns the value in the most recent checkpoint, or zero if there are no checkpoints.
|
|
316
|
+
*/
|
|
317
|
+
function latest(Trace224 storage self) internal view returns (uint224) {
|
|
318
|
+
uint256 pos = self._checkpoints.length;
|
|
319
|
+
return pos == 0 ? 0 : _unsafeAccess(self._checkpoints, pos - 1)._value;
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
/**
|
|
323
|
+
* @dev Returns whether there is a checkpoint in the structure (i.e. it is not empty), and if so
|
|
324
|
+
* the key and value
|
|
325
|
+
* in the most recent checkpoint.
|
|
326
|
+
*/
|
|
327
|
+
function latestCheckpoint(
|
|
328
|
+
Trace224 storage self
|
|
329
|
+
) internal view returns (bool exists, uint32 _key, uint224 _value) {
|
|
330
|
+
uint256 pos = self._checkpoints.length;
|
|
331
|
+
if (pos == 0) {
|
|
332
|
+
return (false, 0, 0);
|
|
333
|
+
} else {
|
|
334
|
+
Checkpoint224 memory ckpt = _unsafeAccess(self._checkpoints, pos - 1);
|
|
335
|
+
return (true, ckpt._key, ckpt._value);
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
/**
|
|
340
|
+
* @dev Returns the number of checkpoint.
|
|
341
|
+
*/
|
|
342
|
+
function length(Trace224 storage self) internal view returns (uint256) {
|
|
343
|
+
return self._checkpoints.length;
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
/**
|
|
347
|
+
* @dev Pushes a (`key`, `value`) pair into an ordered list of checkpoints, either by inserting
|
|
348
|
+
* a
|
|
349
|
+
* new checkpoint,
|
|
350
|
+
* or by updating the last one.
|
|
351
|
+
*/
|
|
352
|
+
function _insert(
|
|
353
|
+
Checkpoint224[] storage self,
|
|
354
|
+
uint32 key,
|
|
355
|
+
uint224 value
|
|
356
|
+
) private returns (uint224, uint224) {
|
|
357
|
+
uint256 pos = self.length;
|
|
358
|
+
|
|
359
|
+
if (pos > 0) {
|
|
360
|
+
// Copying to memory is important here.
|
|
361
|
+
Checkpoint224 memory last = _unsafeAccess(self, pos - 1);
|
|
362
|
+
|
|
363
|
+
// Checkpoint keys must be non-decreasing.
|
|
364
|
+
require(last._key <= key, "Checkpoint: decreasing keys");
|
|
365
|
+
|
|
366
|
+
// Update or push new checkpoint
|
|
367
|
+
if (last._key == key) {
|
|
368
|
+
_unsafeAccess(self, pos - 1)._value = value;
|
|
369
|
+
} else {
|
|
370
|
+
self.push(Checkpoint224({_key: key, _value: value}));
|
|
371
|
+
}
|
|
372
|
+
return (last._value, value);
|
|
373
|
+
} else {
|
|
374
|
+
self.push(Checkpoint224({_key: key, _value: value}));
|
|
375
|
+
return (0, value);
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
/**
|
|
380
|
+
* @dev Return the index of the last (most recent) checkpoint with key lower or equal than the
|
|
381
|
+
* search key, or `high` if there is none.
|
|
382
|
+
* `low` and `high` define a section where to do the search, with inclusive `low` and exclusive
|
|
383
|
+
* `high`.
|
|
384
|
+
*
|
|
385
|
+
* WARNING: `high` should not be greater than the array's length.
|
|
386
|
+
*/
|
|
387
|
+
function _upperBinaryLookup(
|
|
388
|
+
Checkpoint224[] storage self,
|
|
389
|
+
uint32 key,
|
|
390
|
+
uint256 low,
|
|
391
|
+
uint256 high
|
|
392
|
+
) private view returns (uint256) {
|
|
393
|
+
while (low < high) {
|
|
394
|
+
uint256 mid = FixedPointMathLib.avg(low, high);
|
|
395
|
+
if (_unsafeAccess(self, mid)._key > key) {
|
|
396
|
+
high = mid;
|
|
397
|
+
} else {
|
|
398
|
+
low = mid + 1;
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
return high;
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
/**
|
|
405
|
+
* @dev Return the index of the first (oldest) checkpoint with key is greater or equal than the
|
|
406
|
+
* search key, or `high` if there is none.
|
|
407
|
+
* `low` and `high` define a section where to do the search, with inclusive `low` and exclusive
|
|
408
|
+
* `high`.
|
|
409
|
+
*
|
|
410
|
+
* WARNING: `high` should not be greater than the array's length.
|
|
411
|
+
*/
|
|
412
|
+
function _lowerBinaryLookup(
|
|
413
|
+
Checkpoint224[] storage self,
|
|
414
|
+
uint32 key,
|
|
415
|
+
uint256 low,
|
|
416
|
+
uint256 high
|
|
417
|
+
) private view returns (uint256) {
|
|
418
|
+
while (low < high) {
|
|
419
|
+
uint256 mid = FixedPointMathLib.avg(low, high);
|
|
420
|
+
if (_unsafeAccess(self, mid)._key < key) {
|
|
421
|
+
low = mid + 1;
|
|
422
|
+
} else {
|
|
423
|
+
high = mid;
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
return high;
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
/**
|
|
430
|
+
* @dev Access an element of the array without performing bounds check. The position is assumed
|
|
431
|
+
* to
|
|
432
|
+
* be within bounds.
|
|
433
|
+
*/
|
|
434
|
+
function _unsafeAccess(
|
|
435
|
+
Checkpoint224[] storage self,
|
|
436
|
+
uint256 pos
|
|
437
|
+
) private pure returns (Checkpoint224 storage result) {
|
|
438
|
+
assembly {
|
|
439
|
+
mstore(0, self.slot)
|
|
440
|
+
result.slot := add(keccak256(0, 0x20), pos)
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
struct Trace160 {
|
|
445
|
+
Checkpoint160[] _checkpoints;
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
struct Checkpoint160 {
|
|
449
|
+
uint96 _key;
|
|
450
|
+
uint160 _value;
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
/**
|
|
454
|
+
* @dev Pushes a (`key`, `value`) pair into a Trace160 so that it is stored as the checkpoint.
|
|
455
|
+
*
|
|
456
|
+
* Returns previous value and new value.
|
|
457
|
+
*/
|
|
458
|
+
function push(
|
|
459
|
+
Trace160 storage self,
|
|
460
|
+
uint96 key,
|
|
461
|
+
uint160 value
|
|
462
|
+
) internal returns (uint160, uint160) {
|
|
463
|
+
return _insert(self._checkpoints, key, value);
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
/**
|
|
467
|
+
* @dev Returns the value in the first (oldest) checkpoint with key greater or equal than the
|
|
468
|
+
* search key, or zero if there is none.
|
|
469
|
+
*/
|
|
470
|
+
function lowerLookup(Trace160 storage self, uint96 key) internal view returns (uint160) {
|
|
471
|
+
uint256 len = self._checkpoints.length;
|
|
472
|
+
uint256 pos = _lowerBinaryLookup(self._checkpoints, key, 0, len);
|
|
473
|
+
return pos == len ? 0 : _unsafeAccess(self._checkpoints, pos)._value;
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
/**
|
|
477
|
+
* @dev Returns the value in the last (most recent) checkpoint with key lower or equal than the
|
|
478
|
+
* search key, or zero if there is none.
|
|
479
|
+
*/
|
|
480
|
+
function upperLookup(Trace160 storage self, uint96 key) internal view returns (uint160) {
|
|
481
|
+
uint256 len = self._checkpoints.length;
|
|
482
|
+
uint256 pos = _upperBinaryLookup(self._checkpoints, key, 0, len);
|
|
483
|
+
return pos == 0 ? 0 : _unsafeAccess(self._checkpoints, pos - 1)._value;
|
|
484
|
+
}
|
|
485
|
+
|
|
486
|
+
/**
|
|
487
|
+
* @dev Returns the value in the last (most recent) checkpoint with key lower or equal than the
|
|
488
|
+
* search key, or zero if there is none.
|
|
489
|
+
*
|
|
490
|
+
* NOTE: This is a variant of {upperLookup} that is optimised to find "recent" checkpoint
|
|
491
|
+
* (checkpoints with high keys).
|
|
492
|
+
*/
|
|
493
|
+
function upperLookupRecent(Trace160 storage self, uint96 key) internal view returns (uint160) {
|
|
494
|
+
uint256 len = self._checkpoints.length;
|
|
495
|
+
|
|
496
|
+
uint256 low = 0;
|
|
497
|
+
uint256 high = len;
|
|
498
|
+
|
|
499
|
+
if (len > 5) {
|
|
500
|
+
uint256 mid = len - FixedPointMathLib.sqrt(len);
|
|
501
|
+
if (key < _unsafeAccess(self._checkpoints, mid)._key) {
|
|
502
|
+
high = mid;
|
|
503
|
+
} else {
|
|
504
|
+
low = mid + 1;
|
|
505
|
+
}
|
|
506
|
+
}
|
|
507
|
+
|
|
508
|
+
uint256 pos = _upperBinaryLookup(self._checkpoints, key, low, high);
|
|
509
|
+
|
|
510
|
+
return pos == 0 ? 0 : _unsafeAccess(self._checkpoints, pos - 1)._value;
|
|
511
|
+
}
|
|
512
|
+
|
|
513
|
+
/**
|
|
514
|
+
* @dev Returns the value in the most recent checkpoint, or zero if there are no checkpoints.
|
|
515
|
+
*/
|
|
516
|
+
function latest(Trace160 storage self) internal view returns (uint160) {
|
|
517
|
+
uint256 pos = self._checkpoints.length;
|
|
518
|
+
return pos == 0 ? 0 : _unsafeAccess(self._checkpoints, pos - 1)._value;
|
|
519
|
+
}
|
|
520
|
+
|
|
521
|
+
/**
|
|
522
|
+
* @dev Returns whether there is a checkpoint in the structure (i.e. it is not empty), and if so
|
|
523
|
+
* the key and value
|
|
524
|
+
* in the most recent checkpoint.
|
|
525
|
+
*/
|
|
526
|
+
function latestCheckpoint(
|
|
527
|
+
Trace160 storage self
|
|
528
|
+
) internal view returns (bool exists, uint96 _key, uint160 _value) {
|
|
529
|
+
uint256 pos = self._checkpoints.length;
|
|
530
|
+
if (pos == 0) {
|
|
531
|
+
return (false, 0, 0);
|
|
532
|
+
} else {
|
|
533
|
+
Checkpoint160 memory ckpt = _unsafeAccess(self._checkpoints, pos - 1);
|
|
534
|
+
return (true, ckpt._key, ckpt._value);
|
|
535
|
+
}
|
|
536
|
+
}
|
|
537
|
+
|
|
538
|
+
/**
|
|
539
|
+
* @dev Returns the number of checkpoint.
|
|
540
|
+
*/
|
|
541
|
+
function length(Trace160 storage self) internal view returns (uint256) {
|
|
542
|
+
return self._checkpoints.length;
|
|
543
|
+
}
|
|
544
|
+
|
|
545
|
+
/**
|
|
546
|
+
* @dev Pushes a (`key`, `value`) pair into an ordered list of checkpoints, either by inserting
|
|
547
|
+
* a
|
|
548
|
+
* new checkpoint,
|
|
549
|
+
* or by updating the last one.
|
|
550
|
+
*/
|
|
551
|
+
function _insert(
|
|
552
|
+
Checkpoint160[] storage self,
|
|
553
|
+
uint96 key,
|
|
554
|
+
uint160 value
|
|
555
|
+
) private returns (uint160, uint160) {
|
|
556
|
+
uint256 pos = self.length;
|
|
557
|
+
|
|
558
|
+
if (pos > 0) {
|
|
559
|
+
// Copying to memory is important here.
|
|
560
|
+
Checkpoint160 memory last = _unsafeAccess(self, pos - 1);
|
|
561
|
+
|
|
562
|
+
// Checkpoint keys must be non-decreasing.
|
|
563
|
+
require(last._key <= key, "Checkpoint: decreasing keys");
|
|
564
|
+
|
|
565
|
+
// Update or push new checkpoint
|
|
566
|
+
if (last._key == key) {
|
|
567
|
+
_unsafeAccess(self, pos - 1)._value = value;
|
|
568
|
+
} else {
|
|
569
|
+
self.push(Checkpoint160({_key: key, _value: value}));
|
|
570
|
+
}
|
|
571
|
+
return (last._value, value);
|
|
572
|
+
} else {
|
|
573
|
+
self.push(Checkpoint160({_key: key, _value: value}));
|
|
574
|
+
return (0, value);
|
|
575
|
+
}
|
|
576
|
+
}
|
|
577
|
+
|
|
578
|
+
/**
|
|
579
|
+
* @dev Return the index of the last (most recent) checkpoint with key lower or equal than the
|
|
580
|
+
* search key, or `high` if there is none.
|
|
581
|
+
* `low` and `high` define a section where to do the search, with inclusive `low` and exclusive
|
|
582
|
+
* `high`.
|
|
583
|
+
*
|
|
584
|
+
* WARNING: `high` should not be greater than the array's length.
|
|
585
|
+
*/
|
|
586
|
+
function _upperBinaryLookup(
|
|
587
|
+
Checkpoint160[] storage self,
|
|
588
|
+
uint96 key,
|
|
589
|
+
uint256 low,
|
|
590
|
+
uint256 high
|
|
591
|
+
) private view returns (uint256) {
|
|
592
|
+
while (low < high) {
|
|
593
|
+
uint256 mid = FixedPointMathLib.avg(low, high);
|
|
594
|
+
if (_unsafeAccess(self, mid)._key > key) {
|
|
595
|
+
high = mid;
|
|
596
|
+
} else {
|
|
597
|
+
low = mid + 1;
|
|
598
|
+
}
|
|
599
|
+
}
|
|
600
|
+
return high;
|
|
601
|
+
}
|
|
602
|
+
|
|
603
|
+
/**
|
|
604
|
+
* @dev Return the index of the first (oldest) checkpoint with key is greater or equal than the
|
|
605
|
+
* search key, or `high` if there is none.
|
|
606
|
+
* `low` and `high` define a section where to do the search, with inclusive `low` and exclusive
|
|
607
|
+
* `high`.
|
|
608
|
+
*
|
|
609
|
+
* WARNING: `high` should not be greater than the array's length.
|
|
610
|
+
*/
|
|
611
|
+
function _lowerBinaryLookup(
|
|
612
|
+
Checkpoint160[] storage self,
|
|
613
|
+
uint96 key,
|
|
614
|
+
uint256 low,
|
|
615
|
+
uint256 high
|
|
616
|
+
) private view returns (uint256) {
|
|
617
|
+
while (low < high) {
|
|
618
|
+
uint256 mid = FixedPointMathLib.avg(low, high);
|
|
619
|
+
if (_unsafeAccess(self, mid)._key < key) {
|
|
620
|
+
low = mid + 1;
|
|
621
|
+
} else {
|
|
622
|
+
high = mid;
|
|
623
|
+
}
|
|
624
|
+
}
|
|
625
|
+
return high;
|
|
626
|
+
}
|
|
627
|
+
|
|
628
|
+
/**
|
|
629
|
+
* @dev Access an element of the array without performing bounds check. The position is assumed
|
|
630
|
+
* to
|
|
631
|
+
* be within bounds.
|
|
632
|
+
*/
|
|
633
|
+
function _unsafeAccess(
|
|
634
|
+
Checkpoint160[] storage self,
|
|
635
|
+
uint256 pos
|
|
636
|
+
) private pure returns (Checkpoint160 storage result) {
|
|
637
|
+
assembly {
|
|
638
|
+
mstore(0, self.slot)
|
|
639
|
+
result.slot := add(keccak256(0, 0x20), pos)
|
|
640
|
+
}
|
|
641
|
+
}
|
|
642
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
pragma solidity ^0.8.23;
|
|
3
|
+
|
|
4
|
+
// interfaces
|
|
5
|
+
|
|
6
|
+
import {IVotes} from "@openzeppelin/contracts/governance/utils/IVotes.sol";
|
|
7
|
+
import {IERC5805} from "@openzeppelin/contracts/interfaces/IERC5805.sol";
|
|
8
|
+
import {IERC6372} from "@openzeppelin/contracts/interfaces/IERC6372.sol";
|
|
9
|
+
|
|
10
|
+
// contracts
|
|
11
|
+
import {VotesBase} from "./VotesBase.sol";
|
|
12
|
+
|
|
13
|
+
abstract contract Votes is VotesBase, IERC5805 {
|
|
14
|
+
/// @inheritdoc IERC6372
|
|
15
|
+
function clock() public view virtual returns (uint48) {
|
|
16
|
+
return _clock();
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/// @inheritdoc IERC6372
|
|
20
|
+
function CLOCK_MODE() public view virtual returns (string memory) {
|
|
21
|
+
return _clockMode();
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/// @inheritdoc IVotes
|
|
25
|
+
function getVotes(address account) public view virtual returns (uint256) {
|
|
26
|
+
return _getVotes(account);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/// @inheritdoc IVotes
|
|
30
|
+
function getPastVotes(
|
|
31
|
+
address account,
|
|
32
|
+
uint256 timepoint
|
|
33
|
+
) public view virtual returns (uint256) {
|
|
34
|
+
return _getPastVotes(account, timepoint);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/// @inheritdoc IVotes
|
|
38
|
+
function getPastTotalSupply(uint256 timepoint) public view virtual returns (uint256) {
|
|
39
|
+
return _getPastTotalSupply(timepoint);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/// @inheritdoc IVotes
|
|
43
|
+
function delegates(address account) public view virtual returns (address) {
|
|
44
|
+
return _delegates(account);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/// @inheritdoc IVotes
|
|
48
|
+
function delegate(address delegatee) public virtual {
|
|
49
|
+
_delegate(msg.sender, delegatee);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/// @inheritdoc IVotes
|
|
53
|
+
function delegateBySig(
|
|
54
|
+
address delegatee,
|
|
55
|
+
uint256 nonce,
|
|
56
|
+
uint256 expiry,
|
|
57
|
+
uint8 v,
|
|
58
|
+
bytes32 r,
|
|
59
|
+
bytes32 s
|
|
60
|
+
) public virtual {
|
|
61
|
+
return _delegateBySig(delegatee, nonce, expiry, v, r, s);
|
|
62
|
+
}
|
|
63
|
+
}
|