{
"language": "Solidity",
"sources": {
"contracts/crowdfund/Crowdfund.sol": {
"content": "// SPDX-License-Identifier: GPL-3.0\npragma solidity 0.8.17;\n\nimport \"../utils/LibAddress.sol\";\nimport \"../utils/LibRawResult.sol\";\nimport \"../utils/LibSafeCast.sol\";\nimport \"../tokens/ERC721Receiver.sol\";\nimport \"../party/Party.sol\";\nimport \"../globals/IGlobals.sol\";\nimport \"../gatekeepers/IGateKeeper.sol\";\nimport \"../renderers/RendererStorage.sol\";\n\nimport \"./CrowdfundNFT.sol\";\n\n// Base contract for AuctionCrowdfund/BuyCrowdfund.\n// Holds post-win/loss logic. E.g., burning contribution NFTs and creating a\n// party after winning.\nabstract contract Crowdfund is Implementation, ERC721Receiver, CrowdfundNFT {\n using LibRawResult for bytes;\n using LibSafeCast for uint256;\n using LibAddress for address payable;\n\n enum CrowdfundLifecycle {\n Invalid,\n Active,\n Expired,\n Busy, // Temporary. mid-settlement state\n Lost,\n Won\n }\n\n // PartyGovernance options that must be known and fixed at crowdfund creation.\n // This is a subset of PartyGovernance.GovernanceOpts.\n struct FixedGovernanceOpts {\n // Address of initial party hosts.\n address[] hosts;\n // How long people can vote on a proposal.\n uint40 voteDuration;\n // How long to wait after a proposal passes before it can be\n // executed.\n uint40 executionDelay;\n // Minimum ratio of accept votes to consider a proposal passed,\n // in bps, where 10,000 == 100%.\n uint16 passThresholdBps;\n // Fee bps for governance distributions.\n uint16 feeBps;\n // Fee recipeint for governance distributions.\n address payable feeRecipient;\n }\n\n // Options to be passed into `_initialize()` when the crowdfund is created.\n struct CrowdfundOptions {\n string name;\n string symbol;\n uint256 customizationPresetId;\n address payable splitRecipient;\n uint16 splitBps;\n address initialContributor;\n address initialDelegate;\n IGateKeeper gateKeeper;\n bytes12 gateKeeperId;\n FixedGovernanceOpts governanceOpts;\n }\n\n // A record of a single contribution made by a user.\n // Stored in `_contributionsByContributor`.\n struct Contribution {\n // The value of `Crowdfund.totalContributions` when this contribution was made.\n uint96 previousTotalContributions;\n // How much was this contribution.\n uint96 amount;\n }\n\n // A record of the refund and governance NFT owed to a contributor if it\n // could not be received by them from `burn()`.\n struct Claim {\n uint256 refund;\n uint256 governanceTokenId;\n }\n\n error PartyAlreadyExistsError(Party party);\n error WrongLifecycleError(CrowdfundLifecycle lc);\n error InvalidGovernanceOptionsError();\n error InvalidDelegateError();\n error NoPartyError();\n error NotAllowedByGateKeeperError(\n address contributor,\n IGateKeeper gateKeeper,\n bytes12 gateKeeperId,\n bytes gateData\n );\n error SplitRecipientAlreadyBurnedError();\n error InvalidBpsError(uint16 bps);\n error ExceedsTotalContributionsError(uint96 value, uint96 totalContributions);\n error NothingToClaimError();\n error OnlyPartyHostError();\n error OnlyContributorError();\n error MissingHostsError();\n error OnlyPartyDaoError(address notDao);\n error OnlyPartyDaoOrHostError(address notDao);\n error OnlyWhenEmergencyActionsAllowedError();\n\n event Burned(address contributor, uint256 ethUsed, uint256 ethOwed, uint256 votingPower);\n event Contributed(\n address contributor,\n uint256 amount,\n address delegate,\n uint256 previousTotalContributions\n );\n event EmergencyExecute(address target, bytes data, uint256 amountEth);\n event EmergencyExecuteDisabled();\n\n // The `Globals` contract storing global configuration values. This contract\n // is immutable and it’s address will never change.\n IGlobals private immutable _GLOBALS;\n\n /// @notice The party instance created by `_createParty()`, if any after a\n /// successful crowdfund.\n Party public party;\n /// @notice The total (recorded) ETH contributed to this crowdfund.\n uint96 public totalContributions;\n /// @notice The gatekeeper contract to use (if non-null) to restrict who can\n /// contribute to the party.\n IGateKeeper public gateKeeper;\n /// @notice The ID of the gatekeeper strategy to use.\n bytes12 public gateKeeperId;\n /// @notice Who will receive a reserved portion of governance power when\n /// the governance party is created.\n address payable public splitRecipient;\n /// @notice How much governance power to reserve for `splitRecipient`,\n /// in bps, where 10,000 = 100%.\n uint16 public splitBps;\n // Whether the share for split recipient has been claimed through `burn()`.\n bool private _splitRecipientHasBurned;\n /// @notice Hash of party governance options passed into `initialize()`.\n /// Used to check whether the `GovernanceOpts` passed into\n /// `_createParty()` matches.\n bytes32 public governanceOptsHash;\n /// @notice Who a contributor last delegated to.\n mapping(address => address) public delegationsByContributor;\n // Array of contributions by a contributor.\n // One is created for every nonzero contribution made.\n // `internal` for testing purposes only.\n mapping(address => Contribution[]) internal _contributionsByContributor;\n /// @notice Stores the amount of ETH owed back to a contributor and governance NFT\n /// that should be minted to them if it could not be transferred to\n /// them with `burn()`.\n mapping(address => Claim) public claims;\n /// @notice Whether the DAO has emergency powers for this party.\n bool public emergencyExecuteDisabled;\n\n // Set the `Globals` contract.\n constructor(IGlobals globals) CrowdfundNFT(globals) {\n _GLOBALS = globals;\n }\n\n // Initialize storage for proxy contracts, credit initial contribution (if\n // any), and setup gatekeeper.\n function _initialize(CrowdfundOptions memory opts) internal {\n CrowdfundNFT._initialize(opts.name, opts.symbol, opts.customizationPresetId);\n // Check that BPS values do not exceed the max.\n if (opts.governanceOpts.feeBps > 1e4) {\n revert InvalidBpsError(opts.governanceOpts.feeBps);\n }\n if (opts.governanceOpts.passThresholdBps > 1e4) {\n revert InvalidBpsError(opts.governanceOpts.passThresholdBps);\n }\n if (opts.splitBps > 1e4) {\n revert InvalidBpsError(opts.splitBps);\n }\n governanceOptsHash = _hashFixedGovernanceOpts(opts.governanceOpts);\n splitRecipient = opts.splitRecipient;\n splitBps = opts.splitBps;\n // If the deployer passed in some ETH during deployment, credit them\n // for the initial contribution.\n uint96 initialContribution = msg.value.safeCastUint256ToUint96();\n if (initialContribution > 0) {\n // If this contract has ETH, either passed in during deployment or\n // pre-existing, credit it to the `initialContributor`.\n _contribute(opts.initialContributor, initialContribution, opts.initialDelegate, 0, \"\");\n }\n // Set up gatekeeper after initial contribution (initial always gets in).\n gateKeeper = opts.gateKeeper;\n gateKeeperId = opts.gateKeeperId;\n }\n\n /// @notice As the DAO, execute an arbitrary function call from this contract.\n /// @dev Emergency actions must not be revoked for this to work.\n /// @param targetAddress The contract to call.\n /// @param targetCallData The data to pass to the contract.\n /// @param amountEth The amount of ETH to send to the contract.\n function emergencyExecute(\n address targetAddress,\n bytes calldata targetCallData,\n uint256 amountEth\n ) external payable onlyDelegateCall {\n // Must be called by the DAO.\n if (!_isPartyDao(msg.sender)) {\n revert OnlyPartyDaoError(msg.sender);\n }\n // Must not be disabled by DAO or host.\n if (emergencyExecuteDisabled) {\n revert OnlyWhenEmergencyActionsAllowedError();\n }\n (bool success, bytes memory res) = targetAddress.call{ value: amountEth }(targetCallData);\n if (!success) {\n res.rawRevert();\n }\n emit EmergencyExecute(targetAddress, targetCallData, amountEth);\n }\n\n /// @notice Revoke the DAO's ability to call emergencyExecute().\n /// @dev Either the DAO or the party host can call this.\n /// @param governanceOpts The fixed governance opts the crowdfund was created with.\n /// @param hostIndex The index of the party host (caller).\n function disableEmergencyExecute(\n FixedGovernanceOpts memory governanceOpts,\n uint256 hostIndex\n ) external onlyDelegateCall {\n // Only the DAO or a host can call this.\n if (!_isHost(msg.sender, governanceOpts, hostIndex) && !_isPartyDao(msg.sender)) {\n revert OnlyPartyDaoOrHostError(msg.sender);\n }\n emergencyExecuteDisabled = true;\n emit EmergencyExecuteDisabled();\n }\n\n /// @notice Burn the participation NFT for `contributor`, potentially\n /// minting voting power and/or refunding unused ETH. `contributor`\n /// may also be the split recipient, regardless of whether they are\n /// also a contributor or not. This can be called by anyone on a\n /// contributor's behalf to unlock their voting power in the\n /// governance stage ensuring delegates receive their voting\n /// power and governance is not stalled.\n /// @param contributor The contributor whose NFT to burn for.\n function burn(address payable contributor) public {\n return _burn(contributor, getCrowdfundLifecycle(), party);\n }\n\n /// @dev Alias for `burn()`.\n function activateOrRefund(address payable contributor) external {\n burn(contributor);\n }\n\n /// @notice `burn()` in batch form.\n /// Will not revert if any individual burn fails.\n /// @param contributors The contributors whose NFT to burn for.\n /// @param revertOnFailure If true, revert if any burn fails.\n function batchBurn(address payable[] calldata contributors, bool revertOnFailure) public {\n for (uint256 i = 0; i < contributors.length; ++i) {\n (bool s, bytes memory r) = address(this).delegatecall(\n abi.encodeCall(this.burn, (contributors[i]))\n );\n if (revertOnFailure && !s) {\n r.rawRevert();\n }\n }\n }\n\n /// @dev Alias for `batchBurn()`.\n function batchActivateOrRefund(\n address payable[] calldata contributors,\n bool revertOnFailure\n ) external {\n batchBurn(contributors, revertOnFailure);\n }\n\n /// @notice Claim a governance NFT or refund that is owed back but could not be\n /// given due to error in `_burn()` (eg. a contract that does not\n /// implement `onERC721Received()` or cannot receive ETH). Only call\n /// this if refund and governance NFT minting could not be returned\n /// with `burn()`.\n /// @param receiver The address to receive the NFT or refund.\n function claim(address payable receiver) external {\n Claim memory claimInfo = claims[msg.sender];\n delete claims[msg.sender];\n\n if (claimInfo.refund == 0 && claimInfo.governanceTokenId == 0) {\n revert NothingToClaimError();\n }\n\n if (claimInfo.refund != 0) {\n receiver.transferEth(claimInfo.refund);\n }\n\n if (claimInfo.governanceTokenId != 0) {\n party.safeTransferFrom(address(this), receiver, claimInfo.governanceTokenId);\n }\n }\n\n /// @notice Contribute to this crowdfund and/or update your delegation for the\n /// governance phase should the crowdfund succeed.\n /// For restricted crowdfunds, `gateData` can be provided to prove\n /// membership to the gatekeeper.\n /// @param delegate The address to delegate to for the governance phase.\n /// @param gateData Data to pass to the gatekeeper to prove eligibility.\n function contribute(address delegate, bytes memory gateData) public payable onlyDelegateCall {\n _contribute(\n msg.sender,\n msg.value.safeCastUint256ToUint96(),\n delegate,\n // We cannot use `address(this).balance - msg.value` as the previous\n // total contributions in case someone forces (suicides) ETH into this\n // contract. This wouldn't be such a big deal for open crowdfunds\n // but private ones (protected by a gatekeeper) could be griefed\n // because it would ultimately result in governance power that\n // is unattributed/unclaimable, meaning that party will never be\n // able to reach 100% consensus.\n totalContributions,\n gateData\n );\n }\n\n /// @inheritdoc EIP165\n function supportsInterface(\n bytes4 interfaceId\n ) public pure override(ERC721Receiver, CrowdfundNFT) returns (bool) {\n return\n ERC721Receiver.supportsInterface(interfaceId) ||\n CrowdfundNFT.supportsInterface(interfaceId);\n }\n\n /// @notice Retrieve info about a participant's contributions.\n /// @dev This will only be called off-chain so doesn't have to be optimal.\n /// @param contributor The contributor to retrieve contributions for.\n /// @return ethContributed The total ETH contributed by `contributor`.\n /// @return ethUsed The total ETH used by `contributor` to acquire the NFT.\n /// @return ethOwed The total ETH refunded back to `contributor`.\n /// @return votingPower The total voting power minted to `contributor`.\n function getContributorInfo(\n address contributor\n )\n external\n view\n returns (uint256 ethContributed, uint256 ethUsed, uint256 ethOwed, uint256 votingPower)\n {\n CrowdfundLifecycle lc = getCrowdfundLifecycle();\n if (lc == CrowdfundLifecycle.Won || lc == CrowdfundLifecycle.Lost) {\n (ethUsed, ethOwed, votingPower) = _getFinalContribution(contributor);\n ethContributed = ethUsed + ethOwed;\n } else {\n Contribution[] memory contributions = _contributionsByContributor[contributor];\n uint256 numContributions = contributions.length;\n for (uint256 i; i < numContributions; ++i) {\n ethContributed += contributions[i].amount;\n }\n }\n }\n\n /// @notice Get the current lifecycle of the crowdfund.\n function getCrowdfundLifecycle() public view virtual returns (CrowdfundLifecycle lifecycle);\n\n // Get the final sale price of the bought assets. This will also be the total\n // voting power of the governance party.\n function _getFinalPrice() internal view virtual returns (uint256);\n\n // Assert that `who` is a host at `governanceOpts.hosts[hostIndex]` and,\n // if so, assert that the governance opts is the same as the crowdfund\n // was created with.\n // Return true if `governanceOpts` was validated in the process.\n function _assertIsHost(\n address who,\n FixedGovernanceOpts memory governanceOpts,\n uint256 hostIndex\n ) internal view {\n if (!_isHost(who, governanceOpts, hostIndex)) {\n revert OnlyPartyHostError();\n }\n }\n\n // Check if `who` is a host at `hostIndex` index. Validates governance opts if so.\n function _isHost(\n address who,\n FixedGovernanceOpts memory governanceOpts,\n uint256 hostIndex\n ) private view returns (bool isHost) {\n if (hostIndex < governanceOpts.hosts.length && who == governanceOpts.hosts[hostIndex]) {\n // Validate governance opts if the host was found.\n _assertValidGovernanceOpts(governanceOpts);\n return true;\n }\n return false;\n }\n\n function _isPartyDao(address who) private view returns (bool isPartyDao) {\n return who == _GLOBALS.getAddress(LibGlobals.GLOBAL_DAO_WALLET);\n }\n\n // Assert that `who` is a contributor to the crowdfund.\n function _assertIsContributor(address who) internal view {\n if (_contributionsByContributor[who].length == 0) {\n revert OnlyContributorError();\n }\n }\n\n // Can be called after a party has won.\n // Deploys and initializes a `Party` instance via the `PartyFactory`\n // and transfers the bought NFT to it.\n // After calling this, anyone can burn CF tokens on a contributor's behalf\n // with the `burn()` function.\n function _createParty(\n FixedGovernanceOpts memory governanceOpts,\n bool governanceOptsAlreadyValidated,\n IERC721[] memory preciousTokens,\n uint256[] memory preciousTokenIds\n ) internal returns (Party party_) {\n if (party != Party(payable(0))) {\n revert PartyAlreadyExistsError(party);\n }\n // If the governance opts haven't already been validated, make sure that\n // it hasn't been tampered with.\n if (!governanceOptsAlreadyValidated) {\n _assertValidGovernanceOpts(governanceOpts);\n }\n // Create a party.\n party = party_ = _getPartyFactory().createParty(\n address(this),\n Party.PartyOptions({\n name: name,\n symbol: symbol,\n // Indicates to the party to use the same customization preset as the crowdfund.\n customizationPresetId: 0,\n governance: PartyGovernance.GovernanceOpts({\n hosts: governanceOpts.hosts,\n voteDuration: governanceOpts.voteDuration,\n executionDelay: governanceOpts.executionDelay,\n passThresholdBps: governanceOpts.passThresholdBps,\n totalVotingPower: _getFinalPrice().safeCastUint256ToUint96(),\n feeBps: governanceOpts.feeBps,\n feeRecipient: governanceOpts.feeRecipient\n })\n }),\n preciousTokens,\n preciousTokenIds\n );\n // Transfer the acquired NFTs to the new party.\n for (uint256 i; i < preciousTokens.length; ++i) {\n preciousTokens[i].transferFrom(address(this), address(party_), preciousTokenIds[i]);\n }\n }\n\n // Overloaded single token wrapper for _createParty()\n function _createParty(\n FixedGovernanceOpts memory governanceOpts,\n bool governanceOptsAlreadyValidated,\n IERC721 preciousToken,\n uint256 preciousTokenId\n ) internal returns (Party party_) {\n IERC721[] memory tokens = new IERC721[](1);\n tokens[0] = preciousToken;\n uint256[] memory tokenIds = new uint256[](1);\n tokenIds[0] = preciousTokenId;\n return _createParty(governanceOpts, governanceOptsAlreadyValidated, tokens, tokenIds);\n }\n\n // Assert that the hash of `opts` matches the hash this crowdfund was initialized with.\n function _assertValidGovernanceOpts(FixedGovernanceOpts memory governanceOpts) private view {\n bytes32 governanceOptsHash_ = _hashFixedGovernanceOpts(governanceOpts);\n if (governanceOptsHash_ != governanceOptsHash) {\n revert InvalidGovernanceOptionsError();\n }\n }\n\n function _hashFixedGovernanceOpts(\n FixedGovernanceOpts memory opts\n ) internal pure returns (bytes32 h) {\n // Hash in place.\n assembly {\n // Replace the address[] hosts field with its hash temporarily.\n let oldHostsFieldValue := mload(opts)\n mstore(\n opts,\n keccak256(add(oldHostsFieldValue, 0x20), mul(mload(oldHostsFieldValue), 32))\n )\n // Hash the entire struct.\n h := keccak256(opts, 0xC0)\n // Restore old hosts field value.\n mstore(opts, oldHostsFieldValue)\n }\n }\n\n function _getFinalContribution(\n address contributor\n ) internal view returns (uint256 ethUsed, uint256 ethOwed, uint256 votingPower) {\n uint256 totalEthUsed = _getFinalPrice();\n {\n Contribution[] memory contributions = _contributionsByContributor[contributor];\n uint256 numContributions = contributions.length;\n for (uint256 i; i < numContributions; ++i) {\n Contribution memory c = contributions[i];\n if (c.previousTotalContributions >= totalEthUsed) {\n // This entire contribution was not used.\n ethOwed += c.amount;\n } else if (c.previousTotalContributions + c.amount <= totalEthUsed) {\n // This entire contribution was used.\n ethUsed += c.amount;\n } else {\n // This contribution was partially used.\n uint256 partialEthUsed = totalEthUsed - c.previousTotalContributions;\n ethUsed += partialEthUsed;\n ethOwed = c.amount - partialEthUsed;\n }\n }\n }\n // one SLOAD with optimizer on\n address splitRecipient_ = splitRecipient;\n uint256 splitBps_ = splitBps;\n if (splitRecipient_ == address(0)) {\n splitBps_ = 0;\n }\n votingPower = ((1e4 - splitBps_) * ethUsed) / 1e4;\n if (splitRecipient_ == contributor) {\n // Split recipient is also the contributor so just add the split\n // voting power.\n votingPower += (splitBps_ * totalEthUsed + (1e4 - 1)) / 1e4; // round up\n }\n }\n\n function _contribute(\n address contributor,\n uint96 amount,\n address delegate,\n uint96 previousTotalContributions,\n bytes memory gateData\n ) private {\n // Require a non-null delegate.\n if (delegate == address(0)) {\n revert InvalidDelegateError();\n }\n // Must not be blocked by gatekeeper.\n IGateKeeper _gateKeeper = gateKeeper;\n if (_gateKeeper != IGateKeeper(address(0))) {\n if (!_gateKeeper.isAllowed(contributor, gateKeeperId, gateData)) {\n revert NotAllowedByGateKeeperError(\n contributor,\n _gateKeeper,\n gateKeeperId,\n gateData\n );\n }\n }\n\n // Update delegate.\n // OK if this happens out of cycle.\n delegationsByContributor[contributor] = delegate;\n emit Contributed(contributor, amount, delegate, previousTotalContributions);\n\n // OK to contribute with zero just to update delegate.\n if (amount != 0) {\n // Only allow contributions while the crowdfund is active.\n {\n CrowdfundLifecycle lc = getCrowdfundLifecycle();\n if (lc != CrowdfundLifecycle.Active) {\n revert WrongLifecycleError(lc);\n }\n }\n // Increase total contributions.\n totalContributions += amount;\n // Create contributions entry for this contributor.\n Contribution[] storage contributions = _contributionsByContributor[contributor];\n uint256 numContributions = contributions.length;\n if (numContributions >= 1) {\n Contribution memory lastContribution = contributions[numContributions - 1];\n // If no one else (other than this contributor) has contributed since,\n // we can just reuse this contributor's last entry.\n uint256 totalContributionsAmountForReuse = lastContribution\n .previousTotalContributions + lastContribution.amount;\n if (totalContributionsAmountForReuse == previousTotalContributions) {\n lastContribution.amount += amount;\n contributions[numContributions - 1] = lastContribution;\n return;\n }\n }\n // Add a new contribution entry.\n contributions.push(\n Contribution({\n previousTotalContributions: previousTotalContributions,\n amount: amount\n })\n );\n // Mint a participation NFT if this is their first contribution.\n if (numContributions == 0) {\n _mint(contributor);\n }\n }\n }\n\n function _burn(address payable contributor, CrowdfundLifecycle lc, Party party_) private {\n // If the CF has won, a party must have been created prior.\n if (lc == CrowdfundLifecycle.Won) {\n if (party_ == Party(payable(0))) {\n revert NoPartyError();\n }\n } else if (lc != CrowdfundLifecycle.Lost) {\n // Otherwise it must have lost.\n revert WrongLifecycleError(lc);\n }\n // Split recipient can burn even if they don't have a token.\n {\n address splitRecipient_ = splitRecipient;\n if (contributor == splitRecipient_) {\n if (_splitRecipientHasBurned) {\n revert SplitRecipientAlreadyBurnedError();\n }\n _splitRecipientHasBurned = true;\n }\n // Revert if already burned or does not exist.\n if (splitRecipient_ != contributor || _doesTokenExistFor(contributor)) {\n CrowdfundNFT._burn(contributor);\n }\n }\n // Compute the contributions used and owed to the contributor, along\n // with the voting power they'll have in the governance stage.\n (uint256 ethUsed, uint256 ethOwed, uint256 votingPower) = _getFinalContribution(\n contributor\n );\n if (votingPower > 0) {\n // Get the address to delegate voting power to. If null, delegate to self.\n address delegate = delegationsByContributor[contributor];\n if (delegate == address(0)) {\n // Delegate can be unset for the split recipient if they never\n // contribute. Self-delegate if this occurs.\n delegate = contributor;\n }\n // Mint governance NFT for the contributor.\n try party_.mint(contributor, votingPower, delegate) returns (uint256) {\n // OK\n } catch {\n // Mint to the crowdfund itself to escrow for contributor to\n // come claim later on.\n uint256 tokenId = party_.mint(address(this), votingPower, delegate);\n claims[contributor].governanceTokenId = tokenId;\n }\n }\n // Refund any ETH owed back to the contributor.\n (bool s, ) = contributor.call{ value: ethOwed }(\"\");\n if (!s) {\n // If the transfer fails, the contributor can still come claim it\n // from the crowdfund.\n claims[contributor].refund = ethOwed;\n }\n emit Burned(contributor, ethUsed, ethOwed, votingPower);\n }\n\n function _getPartyFactory() internal view returns (IPartyFactory) {\n return IPartyFactory(_GLOBALS.getAddress(LibGlobals.GLOBAL_PARTY_FACTORY));\n }\n}\n"
},
"contracts/crowdfund/CrowdfundNFT.sol": {
"content": "// SPDX-License-Identifier: GPL-3.0\npragma solidity 0.8.17;\n\nimport \"../tokens/IERC721.sol\";\nimport \"../utils/ReadOnlyDelegateCall.sol\";\nimport \"../utils/EIP165.sol\";\nimport \"../globals/IGlobals.sol\";\nimport \"../globals/LibGlobals.sol\";\nimport \"../renderers/RendererStorage.sol\";\n\n/// @notice NFT functionality for crowdfund types. This NFT is soulbound and read-only.\ncontract CrowdfundNFT is IERC721, EIP165, ReadOnlyDelegateCall {\n error AlreadyMintedError(address owner, uint256 tokenId);\n error AlreadyBurnedError(address owner, uint256 tokenId);\n error InvalidTokenError(uint256 tokenId);\n error InvalidAddressError();\n\n // The `Globals` contract storing global configuration values. This contract\n // is immutable and it’s address will never change.\n IGlobals private immutable _GLOBALS;\n\n /// @notice The name of the crowdfund. This will also carry over to the\n /// governance party.\n string public name;\n /// @notice The token symbol for the crowdfund. This will also carry over to\n /// the governance party.\n string public symbol;\n\n mapping(uint256 => address) private _owners;\n\n modifier alwaysRevert() {\n revert(\"ALWAYS FAILING\");\n _; // Compiler requires this.\n }\n\n // Set the `Globals` contract.\n constructor(IGlobals globals) {\n _GLOBALS = globals;\n }\n\n // Initialize name and symbol for crowdfund.\n function _initialize(\n string memory name_,\n string memory symbol_,\n uint256 customizationPresetId\n ) internal virtual {\n name = name_;\n symbol = symbol_;\n if (customizationPresetId != 0) {\n RendererStorage(_GLOBALS.getAddress(LibGlobals.GLOBAL_RENDERER_STORAGE))\n .useCustomizationPreset(customizationPresetId);\n }\n }\n\n /// @notice DO NOT CALL. This is a soulbound NFT and cannot be transferred.\n /// Attempting to call this function will always fail.\n function transferFrom(address, address, uint256) external pure alwaysRevert {}\n\n /// @notice DO NOT CALL. This is a soulbound NFT and cannot be transferred.\n /// Attempting to call this function will always fail.\n function safeTransferFrom(address, address, uint256) external pure alwaysRevert {}\n\n /// @notice DO NOT CALL. This is a soulbound NFT and cannot be transferred.\n /// Attempting to call this function will always fail.\n function safeTransferFrom(\n address,\n address,\n uint256,\n bytes calldata\n ) external pure alwaysRevert {}\n\n /// @notice DO NOT CALL. This is a soulbound NFT and cannot be transferred.\n /// Attempting to call this function will always fail.\n function approve(address, uint256) external pure alwaysRevert {}\n\n /// @notice DO NOT CALL. This is a soulbound NFT and cannot be transferred.\n /// Attempting to call this function will always fail.\n function setApprovalForAll(address, bool) external pure alwaysRevert {}\n\n /// @notice This is a soulbound NFT and cannot be transferred.\n /// Attempting to call this function will always return null.\n function getApproved(uint256) external pure returns (address) {\n return address(0);\n }\n\n /// @notice This is a soulbound NFT and cannot be transferred.\n /// Attempting to call this function will always return false.\n function isApprovedForAll(address, address) external pure returns (bool) {\n return false;\n }\n\n /// @inheritdoc EIP165\n function supportsInterface(bytes4 interfaceId) public pure virtual override returns (bool) {\n return super.supportsInterface(interfaceId) || interfaceId == type(IERC721).interfaceId;\n }\n\n /// @notice Returns a URI to render the NFT.\n function tokenURI(uint256) external view returns (string memory) {\n return _delegateToRenderer();\n }\n\n /// @notice Returns a URI for the storefront-level metadata for your contract.\n function contractURI() external view returns (string memory) {\n return _delegateToRenderer();\n }\n\n /// @inheritdoc IERC721\n function ownerOf(uint256 tokenId) external view returns (address owner) {\n owner = _owners[tokenId];\n if (owner == address(0)) {\n revert InvalidTokenError(tokenId);\n }\n }\n\n /// @inheritdoc IERC721\n function balanceOf(address owner) external view returns (uint256 numTokens) {\n return _doesTokenExistFor(owner) ? 1 : 0;\n }\n\n function _doesTokenExistFor(address owner) internal view returns (bool) {\n return _owners[uint256(uint160(owner))] != address(0);\n }\n\n function _mint(address owner) internal returns (uint256 tokenId) {\n if (owner == address(0)) revert InvalidAddressError();\n tokenId = uint256(uint160(owner));\n if (_owners[tokenId] != owner) {\n _owners[tokenId] = owner;\n emit Transfer(address(0), owner, tokenId);\n } else {\n revert AlreadyMintedError(owner, tokenId);\n }\n }\n\n function _burn(address owner) internal {\n uint256 tokenId = uint256(uint160(owner));\n if (_owners[tokenId] == owner) {\n _owners[tokenId] = address(0);\n emit Transfer(owner, address(0), tokenId);\n return;\n }\n revert AlreadyBurnedError(owner, tokenId);\n }\n\n function _delegateToRenderer() private view returns (string memory) {\n _readOnlyDelegateCall(\n // Instance of IERC721Renderer.\n _GLOBALS.getAddress(LibGlobals.GLOBAL_CF_NFT_RENDER_IMPL),\n msg.data\n );\n assert(false); // Will not be reached.\n return \"\";\n }\n}\n"
},
"contracts/distribution/ITokenDistributor.sol": {
"content": "// SPDX-License-Identifier: GPL-3.0\npragma solidity 0.8.17;\n\nimport \"../tokens/IERC20.sol\";\n\nimport \"./ITokenDistributorParty.sol\";\n\n/// @notice Creates token distributions for parties.\ninterface ITokenDistributor {\n enum TokenType {\n Native,\n Erc20\n }\n\n // Info on a distribution, created by createDistribution().\n struct DistributionInfo {\n // Type of distribution/token.\n TokenType tokenType;\n // ID of the distribution. Assigned by createDistribution().\n uint256 distributionId;\n // The party whose members can claim the distribution.\n ITokenDistributorParty party;\n // Who can claim `fee`.\n address payable feeRecipient;\n // The token being distributed.\n address token;\n // Total amount of `token` that can be claimed by party members.\n uint128 memberSupply;\n // Amount of `token` to be redeemed by `feeRecipient`.\n uint128 fee;\n }\n\n event DistributionCreated(ITokenDistributorParty indexed party, DistributionInfo info);\n event DistributionFeeClaimed(\n ITokenDistributorParty indexed party,\n address indexed feeRecipient,\n TokenType tokenType,\n address token,\n uint256 amount\n );\n event DistributionClaimedByPartyToken(\n ITokenDistributorParty indexed party,\n uint256 indexed partyTokenId,\n address indexed owner,\n TokenType tokenType,\n address token,\n uint256 amountClaimed\n );\n\n /// @notice Create a new distribution for an outstanding native token balance\n /// governed by a party.\n /// @dev Native tokens should be transferred directly into this contract\n /// immediately prior (same tx) to calling `createDistribution()` or\n /// attached to the call itself.\n /// @param party The party whose members can claim the distribution.\n /// @param feeRecipient Who can claim `fee`.\n /// @param feeBps Percentage (in bps) of the distribution `feeRecipient` receives.\n /// @return info Information on the created distribution.\n function createNativeDistribution(\n ITokenDistributorParty party,\n address payable feeRecipient,\n uint16 feeBps\n ) external payable returns (DistributionInfo memory info);\n\n /// @notice Create a new distribution for an outstanding ERC20 token balance\n /// governed by a party.\n /// @dev ERC20 tokens should be transferred directly into this contract\n /// immediately prior (same tx) to calling `createDistribution()` or\n /// attached to the call itself.\n /// @param token The ERC20 token to distribute.\n /// @param party The party whose members can claim the distribution.\n /// @param feeRecipient Who can claim `fee`.\n /// @param feeBps Percentage (in bps) of the distribution `feeRecipient` receives.\n /// @return info Information on the created distribution.\n function createErc20Distribution(\n IERC20 token,\n ITokenDistributorParty party,\n address payable feeRecipient,\n uint16 feeBps\n ) external returns (DistributionInfo memory info);\n\n /// @notice Claim a portion of a distribution owed to a `partyTokenId` belonging\n /// to the party that created the distribution. The caller\n /// must own this token.\n /// @param info Information on the distribution being claimed.\n /// @param partyTokenId The ID of the party token to claim for.\n /// @return amountClaimed The amount of the distribution claimed.\n function claim(\n DistributionInfo calldata info,\n uint256 partyTokenId\n ) external returns (uint128 amountClaimed);\n\n /// @notice Claim the fee for a distribution. Only a distribution's `feeRecipient`\n /// can call this.\n /// @param info Information on the distribution being claimed.\n /// @param recipient The address to send the fee to.\n function claimFee(DistributionInfo calldata info, address payable recipient) external;\n\n /// @notice Batch version of `claim()`.\n /// @param infos Information on the distributions being claimed.\n /// @param partyTokenIds The ID of the party tokens to claim for.\n /// @return amountsClaimed The amount of the distributions claimed.\n function batchClaim(\n DistributionInfo[] calldata infos,\n uint256[] calldata partyTokenIds\n ) external returns (uint128[] memory amountsClaimed);\n\n /// @notice Batch version of `claimFee()`.\n /// @param infos Information on the distributions to claim fees for.\n /// @param recipients The addresses to send the fees to.\n function batchClaimFee(\n DistributionInfo[] calldata infos,\n address payable[] calldata recipients\n ) external;\n\n /// @notice Compute the amount of a distribution's token are owed to a party\n /// member, identified by the `partyTokenId`.\n /// @param party The party to use for computing the claim amount.\n /// @param memberSupply Total amount of tokens that can be claimed in the distribution.\n /// @param partyTokenId The ID of the party token to claim for.\n /// @return claimAmount The amount of the distribution owed to the party member.\n function getClaimAmount(\n ITokenDistributorParty party,\n uint256 memberSupply,\n uint256 partyTokenId\n ) external view returns (uint128);\n\n /// @notice Check whether the fee has been claimed for a distribution.\n /// @param party The party to use for checking whether the fee has been claimed.\n /// @param distributionId The ID of the distribution to check.\n /// @return feeClaimed Whether the fee has been claimed.\n function wasFeeClaimed(\n ITokenDistributorParty party,\n uint256 distributionId\n ) external view returns (bool);\n\n /// @notice Check whether a `partyTokenId` has claimed their share of a distribution.\n /// @param party The party to use for checking whether the `partyTokenId` has claimed.\n /// @param partyTokenId The ID of the party token to check.\n /// @param distributionId The ID of the distribution to check.\n /// @return hasClaimed Whether the `partyTokenId` has claimed.\n function hasPartyTokenIdClaimed(\n ITokenDistributorParty party,\n uint256 partyTokenId,\n uint256 distributionId\n ) external view returns (bool);\n\n /// @notice Get how much unclaimed member tokens are left in a distribution.\n /// @param party The party to use for checking the unclaimed member tokens.\n /// @param distributionId The ID of the distribution to check.\n /// @return remainingMemberSupply The amount of distribution supply remaining.\n function getRemainingMemberSupply(\n ITokenDistributorParty party,\n uint256 distributionId\n ) external view returns (uint128);\n}\n"
},
"contracts/distribution/ITokenDistributorParty.sol": {
"content": "// SPDX-License-Identifier: GPL-3.0\npragma solidity 0.8.17;\n\n// Interface the caller of `ITokenDistributor.createDistribution()` must implement.\ninterface ITokenDistributorParty {\n /// @notice Return the owner of a token.\n /// @param tokenId The token ID to query.\n /// @return owner The owner of `tokenId`.\n function ownerOf(uint256 tokenId) external view returns (address);\n\n /// @notice Return the distribution share of a token. Denominated fractions\n /// of 1e18. I.e., 1e18 = 100%.\n /// @param tokenId The token ID to query.\n /// @return share The distribution percentage of `tokenId`.\n function getDistributionShareOf(uint256 tokenId) external view returns (uint256);\n}\n"
},
"contracts/gatekeepers/IGateKeeper.sol": {
"content": "// SPDX-License-Identifier: GPL-3.0\npragma solidity 0.8.17;\n\n// Interface for a gatekeeper contract used for private crowdfund instances.\ninterface IGateKeeper {\n /// @notice Check if a participant is eligible to participate in a crowdfund.\n /// @param participant The address of the participant.\n /// @param id The ID of the gate to eligibility against.\n /// @param userData The data used to check eligibility.\n /// @return `true` if the participant is allowed to participate, `false` otherwise.\n function isAllowed(\n address participant,\n bytes12 id,\n bytes memory userData\n ) external view returns (bool);\n}\n"
},
"contracts/globals/IGlobals.sol": {
"content": "// SPDX-License-Identifier: GPL-3.0\npragma solidity 0.8.17;\n\nimport \"../utils/Implementation.sol\";\n\n// Single registry of global values controlled by multisig.\n// See `LibGlobals` for all valid keys.\ninterface IGlobals {\n function getBytes32(uint256 key) external view returns (bytes32);\n\n function getUint256(uint256 key) external view returns (uint256);\n\n function getBool(uint256 key) external view returns (bool);\n\n function getAddress(uint256 key) external view returns (address);\n\n function getImplementation(uint256 key) external view returns (Implementation);\n\n function getIncludesBytes32(uint256 key, bytes32 value) external view returns (bool);\n\n function getIncludesUint256(uint256 key, uint256 value) external view returns (bool);\n\n function getIncludesAddress(uint256 key, address value) external view returns (bool);\n\n function setBytes32(uint256 key, bytes32 value) external;\n\n function setUint256(uint256 key, uint256 value) external;\n\n function setBool(uint256 key, bool value) external;\n\n function setAddress(uint256 key, address value) external;\n\n function setIncludesBytes32(uint256 key, bytes32 value, bool isIncluded) external;\n\n function setIncludesUint256(uint256 key, uint256 value, bool isIncluded) external;\n\n function setIncludesAddress(uint256 key, address value, bool isIncluded) external;\n}\n"
},
"contracts/globals/LibGlobals.sol": {
"content": "// SPDX-License-Identifier: GPL-3.0\npragma solidity 0.8.17;\n\n// Valid keys in `IGlobals`. Append-only.\nlibrary LibGlobals {\n uint256 internal constant GLOBAL_PARTY_IMPL = 1;\n uint256 internal constant GLOBAL_PROPOSAL_ENGINE_IMPL = 2;\n uint256 internal constant GLOBAL_PARTY_FACTORY = 3;\n uint256 internal constant GLOBAL_GOVERNANCE_NFT_RENDER_IMPL = 4;\n uint256 internal constant GLOBAL_CF_NFT_RENDER_IMPL = 5;\n uint256 internal constant GLOBAL_OS_ZORA_AUCTION_TIMEOUT = 6;\n uint256 internal constant GLOBAL_OS_ZORA_AUCTION_DURATION = 7;\n uint256 internal constant GLOBAL_AUCTION_CF_IMPL = 8;\n uint256 internal constant GLOBAL_BUY_CF_IMPL = 9;\n uint256 internal constant GLOBAL_COLLECTION_BUY_CF_IMPL = 10;\n uint256 internal constant GLOBAL_DAO_WALLET = 11;\n uint256 internal constant GLOBAL_TOKEN_DISTRIBUTOR = 12;\n uint256 internal constant GLOBAL_OPENSEA_CONDUIT_KEY = 13;\n uint256 internal constant GLOBAL_OPENSEA_ZONE = 14;\n uint256 internal constant GLOBAL_PROPOSAL_MAX_CANCEL_DURATION = 15;\n uint256 internal constant GLOBAL_ZORA_MIN_AUCTION_DURATION = 16;\n uint256 internal constant GLOBAL_ZORA_MAX_AUCTION_DURATION = 17;\n uint256 internal constant GLOBAL_ZORA_MAX_AUCTION_TIMEOUT = 18;\n uint256 internal constant GLOBAL_OS_MIN_ORDER_DURATION = 19;\n uint256 internal constant GLOBAL_OS_MAX_ORDER_DURATION = 20;\n uint256 internal constant GLOBAL_DISABLE_PARTY_ACTIONS = 21;\n uint256 internal constant GLOBAL_RENDERER_STORAGE = 22;\n uint256 internal constant GLOBAL_PROPOSAL_MIN_CANCEL_DURATION = 23;\n}\n"
},
"contracts/party/IPartyFactory.sol": {
"content": "// SPDX-License-Identifier: GPL-3.0\npragma solidity 0.8.17;\n\nimport \"../globals/IGlobals.sol\";\nimport \"../tokens/IERC721.sol\";\n\nimport \"./Party.sol\";\n\n// Creates generic Party instances.\ninterface IPartyFactory {\n event PartyCreated(\n Party indexed party,\n Party.PartyOptions opts,\n IERC721[] preciousTokens,\n uint256[] preciousTokenIds,\n address creator\n );\n\n /// @notice Deploy a new party instance. Afterwards, governance NFTs can be minted\n /// for party members using the `mint()` function from the newly\n /// created party.\n /// @param authority The address that can call `mint()`.\n /// @param opts Options used to initialize the party. These are fixed\n /// and cannot be changed later.\n /// @param preciousTokens The tokens that are considered precious by the\n /// party.These are protected assets and are subject\n /// to extra restrictions in proposals vs other\n /// assets.\n /// @param preciousTokenIds The IDs associated with each token in `preciousTokens`.\n /// @return party The newly created `Party` instance.\n function createParty(\n address authority,\n Party.PartyOptions calldata opts,\n IERC721[] memory preciousTokens,\n uint256[] memory preciousTokenIds\n ) external returns (Party party);\n\n /// @notice The `Globals` contract storing global configuration values. This contract\n /// is immutable and it’s address will never change.\n function GLOBALS() external view returns (IGlobals);\n}\n"
},
"contracts/party/Party.sol": {
"content": "// SPDX-License-Identifier: GPL-3.0\npragma solidity 0.8.17;\n\nimport \"../tokens/IERC721.sol\";\n\nimport \"./PartyGovernanceNFT.sol\";\nimport \"./PartyGovernance.sol\";\n\n/// @notice The governance contract that also custodies the precious NFTs. This\n/// is also the Governance NFT 721 contract.\ncontract Party is PartyGovernanceNFT {\n // Arguments used to initialize the party.\n struct PartyOptions {\n PartyGovernance.GovernanceOpts governance;\n string name;\n string symbol;\n uint256 customizationPresetId;\n }\n\n // Arguments used to initialize the `PartyGovernanceNFT`.\n struct PartyInitData {\n PartyOptions options;\n IERC721[] preciousTokens;\n uint256[] preciousTokenIds;\n address mintAuthority;\n }\n\n // Set the `Globals` contract.\n constructor(IGlobals globals) PartyGovernanceNFT(globals) {}\n\n /// @notice Initializer to be delegatecalled by `Proxy` constructor. Will\n /// revert if called outside the constructor.\n /// @param initData Options used to initialize the party governance.\n function initialize(PartyInitData memory initData) external onlyConstructor {\n PartyGovernanceNFT._initialize(\n initData.options.name,\n initData.options.symbol,\n initData.options.customizationPresetId,\n initData.options.governance,\n initData.preciousTokens,\n initData.preciousTokenIds,\n initData.mintAuthority\n );\n }\n\n receive() external payable {}\n}\n"
},
"contracts/party/PartyGovernance.sol": {
"content": "// SPDX-License-Identifier: GPL-3.0\npragma solidity 0.8.17;\n\nimport \"../distribution/ITokenDistributorParty.sol\";\nimport \"../distribution/ITokenDistributor.sol\";\nimport \"../utils/ReadOnlyDelegateCall.sol\";\nimport \"../tokens/IERC721.sol\";\nimport \"../tokens/IERC20.sol\";\nimport \"../tokens/IERC1155.sol\";\nimport \"../tokens/ERC721Receiver.sol\";\nimport \"../tokens/ERC1155Receiver.sol\";\nimport \"../utils/LibERC20Compat.sol\";\nimport \"../utils/LibRawResult.sol\";\nimport \"../utils/LibSafeCast.sol\";\nimport \"../globals/IGlobals.sol\";\nimport \"../globals/LibGlobals.sol\";\nimport \"../proposals/IProposalExecutionEngine.sol\";\nimport \"../proposals/LibProposal.sol\";\nimport \"../proposals/ProposalStorage.sol\";\n\nimport \"./IPartyFactory.sol\";\n\n/// @notice Base contract for a Party encapsulating all governance functionality.\nabstract contract PartyGovernance is\n ITokenDistributorParty,\n ERC721Receiver,\n ERC1155Receiver,\n ProposalStorage,\n Implementation,\n ReadOnlyDelegateCall\n{\n using LibERC20Compat for IERC20;\n using LibRawResult for bytes;\n using LibSafeCast for uint256;\n using LibSafeCast for int192;\n using LibSafeCast for uint96;\n\n // States a proposal can be in.\n enum ProposalStatus {\n // The proposal does not exist.\n Invalid,\n // The proposal has been proposed (via `propose()`), has not been vetoed\n // by a party host, and is within the voting window. Members can vote on\n // the proposal and party hosts can veto the proposal.\n Voting,\n // The proposal has either exceeded its voting window without reaching\n // `passThresholdBps` of votes or was vetoed by a party host.\n Defeated,\n // The proposal reached at least `passThresholdBps` of votes but is still\n // waiting for `executionDelay` to pass before it can be executed. Members\n // can continue to vote on the proposal and party hosts can veto at this time.\n Passed,\n // Same as `Passed` but now `executionDelay` has been satisfied. Any member\n // may execute the proposal via `execute()`, unless `maxExecutableTime`\n // has arrived.\n Ready,\n // The proposal has been executed at least once but has further steps to\n // complete so it needs to be executed again. No other proposals may be\n // executed while a proposal is in the `InProgress` state. No voting or\n // vetoing of the proposal is allowed, however it may be forcibly cancelled\n // via `cancel()` if the `cancelDelay` has passed since being first executed.\n InProgress,\n // The proposal was executed and completed all its steps. No voting or\n // vetoing can occur and it cannot be cancelled nor executed again.\n Complete,\n // The proposal was executed at least once but did not complete before\n // `cancelDelay` seconds passed since the first execute and was forcibly cancelled.\n Cancelled\n }\n\n struct GovernanceOpts {\n // Address of initial party hosts.\n address[] hosts;\n // How long people can vote on a proposal.\n uint40 voteDuration;\n // How long to wait after a proposal passes before it can be\n // executed.\n uint40 executionDelay;\n // Minimum ratio of accept votes to consider a proposal passed,\n // in bps, where 10,000 == 100%.\n uint16 passThresholdBps;\n // Total voting power of governance NFTs.\n uint96 totalVotingPower;\n // Fee bps for distributions.\n uint16 feeBps;\n // Fee recipeint for distributions.\n address payable feeRecipient;\n }\n\n // Subset of `GovernanceOpts` that are commonly read together for\n // efficiency.\n struct GovernanceValues {\n uint40 voteDuration;\n uint40 executionDelay;\n uint16 passThresholdBps;\n uint96 totalVotingPower;\n }\n\n // A snapshot of voting power for a member.\n struct VotingPowerSnapshot {\n // The timestamp when the snapshot was taken.\n uint40 timestamp;\n // Voting power that was delegated to this user by others.\n uint96 delegatedVotingPower;\n // The intrinsic (not delegated from someone else) voting power of this user.\n uint96 intrinsicVotingPower;\n // Whether the user was delegated to another at this snapshot.\n bool isDelegated;\n }\n\n // Proposal details chosen by proposer.\n struct Proposal {\n // Time beyond which the proposal can no longer be executed.\n // If the proposal has already been executed, and is still InProgress,\n // this value is ignored.\n uint40 maxExecutableTime;\n // The minimum seconds this proposal can remain in the InProgress status\n // before it can be cancelled.\n uint40 cancelDelay;\n // Encoded proposal data. The first 4 bytes are the proposal type, followed\n // by encoded proposal args specific to the proposal type. See\n // ProposalExecutionEngine for details.\n bytes proposalData;\n }\n\n // Accounting and state tracking values for a proposal.\n // Fits in a word.\n struct ProposalStateValues {\n // When the proposal was proposed.\n uint40 proposedTime;\n // When the proposal passed the vote.\n uint40 passedTime;\n // When the proposal was first executed.\n uint40 executedTime;\n // When the proposal completed.\n uint40 completedTime;\n // Number of accept votes.\n uint96 votes; // -1 == vetoed\n }\n\n // Storage states for a proposal.\n struct ProposalState {\n // Accounting and state tracking values.\n ProposalStateValues values;\n // Hash of the proposal.\n bytes32 hash;\n // Whether a member has voted for (accepted) this proposal already.\n mapping(address => bool) hasVoted;\n }\n\n event Proposed(uint256 proposalId, address proposer, Proposal proposal);\n event ProposalAccepted(uint256 proposalId, address voter, uint256 weight);\n event EmergencyExecute(address target, bytes data, uint256 amountEth);\n\n event ProposalPassed(uint256 indexed proposalId);\n event ProposalVetoed(uint256 indexed proposalId, address host);\n event ProposalExecuted(uint256 indexed proposalId, address executor, bytes nextProgressData);\n event ProposalCancelled(uint256 indexed proposalId);\n event DistributionCreated(\n ITokenDistributor.TokenType tokenType,\n address token,\n uint256 tokenId\n );\n event VotingPowerDelegated(address indexed owner, address indexed delegate);\n event HostStatusTransferred(address oldHost, address newHost);\n event EmergencyExecuteDisabled();\n\n error MismatchedPreciousListLengths();\n error BadProposalStatusError(ProposalStatus status);\n error BadProposalHashError(bytes32 proposalHash, bytes32 actualHash);\n error ExecutionTimeExceededError(uint40 maxExecutableTime, uint40 timestamp);\n error OnlyPartyHostError();\n error OnlyActiveMemberError();\n error InvalidDelegateError();\n error BadPreciousListError();\n error OnlyPartyDaoError(address notDao, address partyDao);\n error OnlyPartyDaoOrHostError(address notDao, address partyDao);\n error OnlyWhenEmergencyActionsAllowedError();\n error OnlyWhenEnabledError();\n error AlreadyVotedError(address voter);\n error InvalidNewHostError();\n error ProposalCannotBeCancelledYetError(uint40 currentTime, uint40 cancelTime);\n error InvalidBpsError(uint16 bps);\n\n uint256 private constant UINT40_HIGH_BIT = 1 << 39;\n uint96 private constant VETO_VALUE = type(uint96).max;\n\n // The `Globals` contract storing global configuration values. This contract\n // is immutable and it’s address will never change.\n IGlobals private immutable _GLOBALS;\n\n /// @notice Whether the DAO has emergency powers for this party.\n bool public emergencyExecuteDisabled;\n /// @notice Distribution fee bps.\n uint16 public feeBps;\n /// @notice Distribution fee recipient.\n address payable public feeRecipient;\n /// @notice The hash of the list of precious NFTs guarded by the party.\n bytes32 public preciousListHash;\n /// @notice The last proposal ID that was used. 0 means no proposals have been made.\n uint256 public lastProposalId;\n /// @notice Whether an address is a party host.\n mapping(address => bool) public isHost;\n /// @notice The last person a voter delegated its voting power to.\n mapping(address => address) public delegationsByVoter;\n // Constant governance parameters, fixed from the inception of this party.\n GovernanceValues internal _governanceValues;\n // ProposalState by proposal ID.\n mapping(uint256 => ProposalState) private _proposalStateByProposalId;\n // Snapshots of voting power per user, each sorted by increasing time.\n mapping(address => VotingPowerSnapshot[]) private _votingPowerSnapshotsByVoter;\n\n modifier onlyHost() {\n if (!isHost[msg.sender]) {\n revert OnlyPartyHostError();\n }\n _;\n }\n\n // Caller must have voting power at the current time.\n modifier onlyActiveMember() {\n {\n VotingPowerSnapshot memory snap = _getLastVotingPowerSnapshotForVoter(msg.sender);\n // Must have either delegated voting power or intrinsic voting power.\n if (snap.intrinsicVotingPower == 0 && snap.delegatedVotingPower == 0) {\n revert OnlyActiveMemberError();\n }\n }\n _;\n }\n\n // Caller must have voting power at the current time or be the `Party` instance.\n modifier onlyActiveMemberOrSelf() {\n // Ignore if the party is calling functions on itself, like with\n // `FractionalizeProposal` calling `distribute()`.\n if (msg.sender != address(this)) {\n VotingPowerSnapshot memory snap = _getLastVotingPowerSnapshotForVoter(msg.sender);\n // Must have either delegated voting power or intrinsic voting power.\n if (snap.intrinsicVotingPower == 0 && snap.delegatedVotingPower == 0) {\n revert OnlyActiveMemberError();\n }\n }\n _;\n }\n\n // Only the party DAO multisig can call.\n modifier onlyPartyDao() {\n {\n address partyDao = _GLOBALS.getAddress(LibGlobals.GLOBAL_DAO_WALLET);\n if (msg.sender != partyDao) {\n revert OnlyPartyDaoError(msg.sender, partyDao);\n }\n }\n _;\n }\n\n // Only the party DAO multisig or a party host can call.\n modifier onlyPartyDaoOrHost() {\n address partyDao = _GLOBALS.getAddress(LibGlobals.GLOBAL_DAO_WALLET);\n if (msg.sender != partyDao && !isHost[msg.sender]) {\n revert OnlyPartyDaoOrHostError(msg.sender, partyDao);\n }\n _;\n }\n\n // Only if `emergencyExecuteDisabled` is not true.\n modifier onlyWhenEmergencyExecuteAllowed() {\n if (emergencyExecuteDisabled) {\n revert OnlyWhenEmergencyActionsAllowedError();\n }\n _;\n }\n\n modifier onlyWhenNotGloballyDisabled() {\n if (_GLOBALS.getBool(LibGlobals.GLOBAL_DISABLE_PARTY_ACTIONS)) {\n revert OnlyWhenEnabledError();\n }\n _;\n }\n\n // Set the `Globals` contract.\n constructor(IGlobals globals) {\n _GLOBALS = globals;\n }\n\n // Initialize storage for proxy contracts and initialize the proposal execution engine.\n function _initialize(\n GovernanceOpts memory opts,\n IERC721[] memory preciousTokens,\n uint256[] memory preciousTokenIds\n ) internal virtual {\n // Check BPS are valid.\n if (opts.feeBps > 1e4) {\n revert InvalidBpsError(opts.feeBps);\n }\n if (opts.passThresholdBps > 1e4) {\n revert InvalidBpsError(opts.passThresholdBps);\n }\n // Initialize the proposal execution engine.\n _initProposalImpl(\n IProposalExecutionEngine(_GLOBALS.getAddress(LibGlobals.GLOBAL_PROPOSAL_ENGINE_IMPL)),\n \"\"\n );\n // Set the governance parameters.\n _governanceValues = GovernanceValues({\n voteDuration: opts.voteDuration,\n executionDelay: opts.executionDelay,\n passThresholdBps: opts.passThresholdBps,\n totalVotingPower: opts.totalVotingPower\n });\n // Set fees.\n feeBps = opts.feeBps;\n feeRecipient = opts.feeRecipient;\n // Set the precious list.\n _setPreciousList(preciousTokens, preciousTokenIds);\n // Set the party hosts.\n for (uint256 i = 0; i < opts.hosts.length; ++i) {\n isHost[opts.hosts[i]] = true;\n }\n }\n\n /// @dev Forward all unknown read-only calls to the proposal execution engine.\n /// Initial use case is to facilitate eip-1271 signatures.\n fallback() external {\n _readOnlyDelegateCall(address(_getProposalExecutionEngine()), msg.data);\n }\n\n /// @inheritdoc EIP165\n /// @dev Combined logic for `ERC721Receiver` and `ERC1155Receiver`.\n function supportsInterface(\n bytes4 interfaceId\n ) public pure virtual override(ERC721Receiver, ERC1155Receiver) returns (bool) {\n return\n ERC721Receiver.supportsInterface(interfaceId) ||\n ERC1155Receiver.supportsInterface(interfaceId);\n }\n\n /// @notice Get the current `ProposalExecutionEngine` instance.\n function getProposalExecutionEngine() external view returns (IProposalExecutionEngine) {\n return _getProposalExecutionEngine();\n }\n\n /// @notice Get the total voting power of `voter` at a `timestamp`.\n /// @param voter The address of the voter.\n /// @param timestamp The timestamp to get the voting power at.\n /// @return votingPower The total voting power of `voter` at `timestamp`.\n function getVotingPowerAt(\n address voter,\n uint40 timestamp\n ) external view returns (uint96 votingPower) {\n return getVotingPowerAt(voter, timestamp, type(uint256).max);\n }\n\n /// @notice Get the total voting power of `voter` at a snapshot `snapIndex`, with checks to\n /// make sure it is the latest voting snapshot =< `timestamp`.\n /// @param voter The address of the voter.\n /// @param timestamp The timestamp to get the voting power at.\n /// @param snapIndex The index of the snapshot to get the voting power at.\n /// @return votingPower The total voting power of `voter` at `timestamp`.\n function getVotingPowerAt(\n address voter,\n uint40 timestamp,\n uint256 snapIndex\n ) public view returns (uint96 votingPower) {\n VotingPowerSnapshot memory snap = _getVotingPowerSnapshotAt(voter, timestamp, snapIndex);\n return (snap.isDelegated ? 0 : snap.intrinsicVotingPower) + snap.delegatedVotingPower;\n }\n\n /// @notice Get the state of a proposal.\n /// @param proposalId The ID of the proposal.\n /// @return status The status of the proposal.\n /// @return values The state of the proposal.\n function getProposalStateInfo(\n uint256 proposalId\n ) external view returns (ProposalStatus status, ProposalStateValues memory values) {\n values = _proposalStateByProposalId[proposalId].values;\n status = _getProposalStatus(values);\n }\n\n /// @notice Retrieve fixed governance parameters.\n /// @return gv The governance parameters of this party.\n function getGovernanceValues() external view returns (GovernanceValues memory gv) {\n return _governanceValues;\n }\n\n /// @notice Get the hash of a proposal.\n /// @dev Proposal details are not stored on-chain so the hash is used to enforce\n /// consistency between calls.\n /// @param proposal The proposal to hash.\n /// @return proposalHash The hash of the proposal.\n function getProposalHash(Proposal memory proposal) public pure returns (bytes32 proposalHash) {\n // Hash the proposal in-place. Equivalent to:\n // keccak256(abi.encode(\n // proposal.maxExecutableTime,\n // proposal.cancelDelay,\n // keccak256(proposal.proposalData)\n // ))\n bytes32 dataHash = keccak256(proposal.proposalData);\n assembly {\n // Overwrite the data field with the hash of its contents and then\n // hash the struct.\n let dataPos := add(proposal, 0x40)\n let t := mload(dataPos)\n mstore(dataPos, dataHash)\n proposalHash := keccak256(proposal, 0x60)\n // Restore the data field.\n mstore(dataPos, t)\n }\n }\n\n /// @notice Get the index of the most recent voting power snapshot <= `timestamp`.\n /// @param voter The address of the voter.\n /// @param timestamp The timestamp to get the snapshot index at.\n /// @return index The index of the snapshot.\n function findVotingPowerSnapshotIndex(\n address voter,\n uint40 timestamp\n ) public view returns (uint256 index) {\n VotingPowerSnapshot[] storage snaps = _votingPowerSnapshotsByVoter[voter];\n\n // Derived from Open Zeppelin binary search\n // ref: https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/utils/Checkpoints.sol#L39\n uint256 high = snaps.length;\n uint256 low = 0;\n while (low < high) {\n uint256 mid = (low + high) / 2;\n if (snaps[mid].timestamp > timestamp) {\n // Entry is too recent.\n high = mid;\n } else {\n // Entry is older. This is our best guess for now.\n low = mid + 1;\n }\n }\n\n // Return `type(uint256).max` if no valid voting snapshots found.\n return high == 0 ? type(uint256).max : high - 1;\n }\n\n /// @notice Pledge your intrinsic voting power to a new delegate, removing it from\n /// the old one (if any).\n /// @param delegate The address to delegating voting power to.\n function delegateVotingPower(address delegate) external onlyDelegateCall {\n _adjustVotingPower(msg.sender, 0, delegate);\n emit VotingPowerDelegated(msg.sender, delegate);\n }\n\n /// @notice Transfer party host status to another.\n /// @param newPartyHost The address of the new host.\n function abdicate(address newPartyHost) external onlyHost onlyDelegateCall {\n // 0 is a special case burn address.\n if (newPartyHost != address(0)) {\n // Cannot transfer host status to an existing host.\n if (isHost[newPartyHost]) {\n revert InvalidNewHostError();\n }\n isHost[newPartyHost] = true;\n }\n isHost[msg.sender] = false;\n emit HostStatusTransferred(msg.sender, newPartyHost);\n }\n\n /// @notice Create a token distribution by moving the party's entire balance\n /// to the `TokenDistributor` contract and immediately creating a\n /// distribution governed by this party.\n /// @dev The `feeBps` and `feeRecipient` this party was created with will be\n /// propagated to the distribution. Party members are entitled to a\n /// share of the distribution's tokens proportionate to their relative\n /// voting power in this party (less the fee).\n /// @dev Allow this to be called by the party itself for `FractionalizeProposal`.\n /// @param tokenType The type of token to distribute.\n /// @param token The address of the token to distribute.\n /// @param tokenId The ID of the token to distribute. Currently unused but\n /// may be used in the future to support other distribution types.\n /// @return distInfo The information about the created distribution.\n function distribute(\n ITokenDistributor.TokenType tokenType,\n address token,\n uint256 tokenId\n )\n external\n onlyActiveMemberOrSelf\n onlyWhenNotGloballyDisabled\n onlyDelegateCall\n returns (ITokenDistributor.DistributionInfo memory distInfo)\n {\n // Get the address of the token distributor.\n ITokenDistributor distributor = ITokenDistributor(\n _GLOBALS.getAddress(LibGlobals.GLOBAL_TOKEN_DISTRIBUTOR)\n );\n emit DistributionCreated(tokenType, token, tokenId);\n // Create a native token distribution.\n address payable feeRecipient_ = feeRecipient;\n uint16 feeBps_ = feeBps;\n if (tokenType == ITokenDistributor.TokenType.Native) {\n return\n distributor.createNativeDistribution{ value: address(this).balance }(\n this,\n feeRecipient_,\n feeBps_\n );\n }\n // Otherwise must be an ERC20 token distribution.\n assert(tokenType == ITokenDistributor.TokenType.Erc20);\n IERC20(token).compatTransfer(address(distributor), IERC20(token).balanceOf(address(this)));\n return distributor.createErc20Distribution(IERC20(token), this, feeRecipient_, feeBps_);\n }\n\n /// @notice Make a proposal for members to vote on and cast a vote to accept it\n /// as well.\n /// @dev Only an active member (has voting power) can call this.\n /// Afterwards, members can vote to support it with `accept()` or a party\n /// host can unilaterally reject the proposal with `veto()`.\n /// @param proposal The details of the proposal.\n /// @param latestSnapIndex The index of the caller's most recent voting power\n /// snapshot before the proposal was created. Should\n /// be retrieved off-chain and passed in.\n function propose(\n Proposal memory proposal,\n uint256 latestSnapIndex\n ) external onlyActiveMember onlyDelegateCall returns (uint256 proposalId) {\n proposalId = ++lastProposalId;\n // Store the time the proposal was created and the proposal hash.\n (\n _proposalStateByProposalId[proposalId].values,\n _proposalStateByProposalId[proposalId].hash\n ) = (\n ProposalStateValues({\n proposedTime: uint40(block.timestamp),\n passedTime: 0,\n executedTime: 0,\n completedTime: 0,\n votes: 0\n }),\n getProposalHash(proposal)\n );\n emit Proposed(proposalId, msg.sender, proposal);\n accept(proposalId, latestSnapIndex);\n }\n\n /// @notice Vote to support a proposed proposal.\n /// @dev The voting power cast will be the effective voting power of the caller\n /// just before `propose()` was called (see `getVotingPowerAt()`).\n /// If the proposal reaches `passThresholdBps` acceptance ratio then the\n /// proposal will be in the `Passed` state and will be executable after\n /// the `executionDelay` has passed, putting it in the `Ready` state.\n /// @param proposalId The ID of the proposal to accept.\n /// @param snapIndex The index of the caller's last voting power snapshot\n /// before the proposal was created. Should be retrieved\n /// off-chain and passed in.\n /// @return totalVotes The total votes cast on the proposal.\n function accept(\n uint256 proposalId,\n uint256 snapIndex\n ) public onlyDelegateCall returns (uint256 totalVotes) {\n // Get the information about the proposal.\n ProposalState storage info = _proposalStateByProposalId[proposalId];\n ProposalStateValues memory values = info.values;\n\n // Can only vote in certain proposal statuses.\n {\n ProposalStatus status = _getProposalStatus(values);\n // Allow voting even if the proposal is passed/ready so it can\n // potentially reach 100% consensus, which unlocks special\n // behaviors for certain proposal types.\n if (\n status != ProposalStatus.Voting &&\n status != ProposalStatus.Passed &&\n status != ProposalStatus.Ready\n ) {\n revert BadProposalStatusError(status);\n }\n }\n\n // Cannot vote twice.\n if (info.hasVoted[msg.sender]) {\n revert AlreadyVotedError(msg.sender);\n }\n // Mark the caller as having voted.\n info.hasVoted[msg.sender] = true;\n\n // Increase the total votes that have been cast on this proposal.\n uint96 votingPower = getVotingPowerAt(msg.sender, values.proposedTime - 1, snapIndex);\n values.votes += votingPower;\n info.values = values;\n emit ProposalAccepted(proposalId, msg.sender, votingPower);\n\n // Update the proposal status if it has reached the pass threshold.\n if (\n values.passedTime == 0 &&\n _areVotesPassing(\n values.votes,\n _governanceValues.totalVotingPower,\n _governanceValues.passThresholdBps\n )\n ) {\n info.values.passedTime = uint40(block.timestamp);\n emit ProposalPassed(proposalId);\n }\n return values.votes;\n }\n\n /// @notice As a party host, veto a proposal, unilaterally rejecting it.\n /// @dev The proposal will never be executable and cannot be voted on anymore.\n /// A proposal that has been already executed at least once (in the `InProgress` status)\n /// cannot be vetoed.\n /// @param proposalId The ID of the proposal to veto.\n function veto(uint256 proposalId) external onlyHost onlyDelegateCall {\n // Setting `votes` to -1 indicates a veto.\n ProposalState storage info = _proposalStateByProposalId[proposalId];\n ProposalStateValues memory values = info.values;\n\n {\n ProposalStatus status = _getProposalStatus(values);\n // Proposal must be in one of the following states.\n if (\n status != ProposalStatus.Voting &&\n status != ProposalStatus.Passed &&\n status != ProposalStatus.Ready\n ) {\n revert BadProposalStatusError(status);\n }\n }\n\n // -1 indicates veto.\n info.values.votes = VETO_VALUE;\n emit ProposalVetoed(proposalId, msg.sender);\n }\n\n /// @notice Executes a proposal that has passed governance.\n /// @dev The proposal must be in the `Ready` or `InProgress` status.\n /// A `ProposalExecuted` event will be emitted with a non-empty `nextProgressData`\n /// if the proposal has extra steps (must be executed again) to carry out,\n /// in which case `nextProgressData` should be passed into the next `execute()` call.\n /// The `ProposalExecutionEngine` enforces that only one `InProgress` proposal\n /// is active at a time, so that proposal must be completed or cancelled via `cancel()`\n /// in order to execute a different proposal.\n /// `extraData` is optional, off-chain data a proposal might need to execute a step.\n /// @param proposalId The ID of the proposal to execute.\n /// @param proposal The details of the proposal.\n /// @param preciousTokens The tokens that the party considers precious.\n /// @param preciousTokenIds The token IDs associated with each precious token.\n /// @param progressData The data returned from the last `execute()` call, if any.\n /// @param extraData Off-chain data a proposal might need to execute a step.\n function execute(\n uint256 proposalId,\n Proposal memory proposal,\n IERC721[] memory preciousTokens,\n uint256[] memory preciousTokenIds,\n bytes calldata progressData,\n bytes calldata extraData\n ) external payable onlyActiveMember onlyWhenNotGloballyDisabled onlyDelegateCall {\n // Get information about the proposal.\n ProposalState storage proposalState = _proposalStateByProposalId[proposalId];\n // Proposal details must remain the same from `propose()`.\n _validateProposalHash(proposal, proposalState.hash);\n ProposalStateValues memory values = proposalState.values;\n ProposalStatus status = _getProposalStatus(values);\n // The proposal must be executable or have already been executed but still\n // has more steps to go.\n if (status != ProposalStatus.Ready && status != ProposalStatus.InProgress) {\n revert BadProposalStatusError(status);\n }\n if (status == ProposalStatus.Ready) {\n // If the proposal has not been executed yet, make sure it hasn't\n // expired. Note that proposals that have been executed\n // (but still have more steps) ignore `maxExecutableTime`.\n if (proposal.maxExecutableTime < block.timestamp) {\n revert ExecutionTimeExceededError(\n proposal.maxExecutableTime,\n uint40(block.timestamp)\n );\n }\n proposalState.values.executedTime = uint40(block.timestamp);\n }\n // Check that the precious list is valid.\n if (!_isPreciousListCorrect(preciousTokens, preciousTokenIds)) {\n revert BadPreciousListError();\n }\n // Preemptively set the proposal to completed to avoid it being executed\n // again in a deeper call.\n proposalState.values.completedTime = uint40(block.timestamp);\n // Execute the proposal.\n bool completed = _executeProposal(\n proposalId,\n proposal,\n preciousTokens,\n preciousTokenIds,\n _getProposalFlags(values),\n progressData,\n extraData\n );\n if (!completed) {\n // Proposal did not complete.\n proposalState.values.completedTime = 0;\n }\n }\n\n /// @notice Cancel a (probably stuck) InProgress proposal.\n /// @dev `proposal.cancelDelay` seconds must have passed since it was first\n /// executed for this to be valid. The currently active proposal will\n /// simply be yeeted out of existence so another proposal can execute.\n /// This is intended to be a last resort and can leave the party in a\n /// broken state. Whenever possible, active proposals should be\n /// allowed to complete their lifecycle.\n /// @param proposalId The ID of the proposal to cancel.\n /// @param proposal The details of the proposal to cancel.\n function cancel(\n uint256 proposalId,\n Proposal calldata proposal\n ) external onlyActiveMember onlyDelegateCall {\n // Get information about the proposal.\n ProposalState storage proposalState = _proposalStateByProposalId[proposalId];\n // Proposal details must remain the same from `propose()`.\n _validateProposalHash(proposal, proposalState.hash);\n ProposalStateValues memory values = proposalState.values;\n {\n // Must be `InProgress`.\n ProposalStatus status = _getProposalStatus(values);\n if (status != ProposalStatus.InProgress) {\n revert BadProposalStatusError(status);\n }\n }\n {\n // Limit the `cancelDelay` to the global max and min cancel delay\n // to mitigate parties accidentally getting stuck forever by setting an\n // unrealistic `cancelDelay` or being reckless with too low a\n // cancel delay.\n uint256 cancelDelay = proposal.cancelDelay;\n uint256 globalMaxCancelDelay = _GLOBALS.getUint256(\n LibGlobals.GLOBAL_PROPOSAL_MAX_CANCEL_DURATION\n );\n uint256 globalMinCancelDelay = _GLOBALS.getUint256(\n LibGlobals.GLOBAL_PROPOSAL_MIN_CANCEL_DURATION\n );\n if (globalMaxCancelDelay != 0) {\n // Only if we have one set.\n if (cancelDelay > globalMaxCancelDelay) {\n cancelDelay = globalMaxCancelDelay;\n }\n }\n if (globalMinCancelDelay != 0) {\n // Only if we have one set.\n if (cancelDelay < globalMinCancelDelay) {\n cancelDelay = globalMinCancelDelay;\n }\n }\n uint256 cancelTime = values.executedTime + cancelDelay;\n // Must not be too early.\n if (block.timestamp < cancelTime) {\n revert ProposalCannotBeCancelledYetError(\n uint40(block.timestamp),\n uint40(cancelTime)\n );\n }\n }\n // Mark the proposal as cancelled by setting the completed time to the current\n // time with the high bit set.\n proposalState.values.completedTime = uint40(block.timestamp | UINT40_HIGH_BIT);\n {\n // Delegatecall into the proposal engine impl to perform the cancel.\n (bool success, bytes memory resultData) = (address(_getProposalExecutionEngine()))\n .delegatecall(\n abi.encodeCall(IProposalExecutionEngine.cancelProposal, (proposalId))\n );\n if (!success) {\n resultData.rawRevert();\n }\n }\n emit ProposalCancelled(proposalId);\n }\n\n /// @notice As the DAO, execute an arbitrary function call from this contract.\n /// @dev Emergency actions must not be revoked for this to work.\n /// @param targetAddress The contract to call.\n /// @param targetCallData The data to pass to the contract.\n /// @param amountEth The amount of ETH to send to the contract.\n function emergencyExecute(\n address targetAddress,\n bytes calldata targetCallData,\n uint256 amountEth\n ) external payable onlyPartyDao onlyWhenEmergencyExecuteAllowed onlyDelegateCall {\n (bool success, bytes memory res) = targetAddress.call{ value: amountEth }(targetCallData);\n if (!success) {\n res.rawRevert();\n }\n emit EmergencyExecute(targetAddress, targetCallData, amountEth);\n }\n\n /// @notice Revoke the DAO's ability to call emergencyExecute().\n /// @dev Either the DAO or the party host can call this.\n function disableEmergencyExecute() external onlyPartyDaoOrHost onlyDelegateCall {\n emergencyExecuteDisabled = true;\n emit EmergencyExecuteDisabled();\n }\n\n function _executeProposal(\n uint256 proposalId,\n Proposal memory proposal,\n IERC721[] memory preciousTokens,\n uint256[] memory preciousTokenIds,\n uint256 flags,\n bytes memory progressData,\n bytes memory extraData\n ) private returns (bool completed) {\n // Setup the arguments for the proposal execution engine.\n IProposalExecutionEngine.ExecuteProposalParams\n memory executeParams = IProposalExecutionEngine.ExecuteProposalParams({\n proposalId: proposalId,\n proposalData: proposal.proposalData,\n progressData: progressData,\n extraData: extraData,\n preciousTokens: preciousTokens,\n preciousTokenIds: preciousTokenIds,\n flags: flags\n });\n // Get the progress data returned after the proposal is executed.\n bytes memory nextProgressData;\n {\n // Execute the proposal.\n (bool success, bytes memory resultData) = address(_getProposalExecutionEngine())\n .delegatecall(\n abi.encodeCall(IProposalExecutionEngine.executeProposal, (executeParams))\n );\n if (!success) {\n resultData.rawRevert();\n }\n nextProgressData = abi.decode(resultData, (bytes));\n }\n emit ProposalExecuted(proposalId, msg.sender, nextProgressData);\n // If the returned progress data is empty, then the proposal completed\n // and it should not be executed again.\n return nextProgressData.length == 0;\n }\n\n // Get the most recent voting power snapshot <= timestamp using `hintindex` as a \"hint\".\n function _getVotingPowerSnapshotAt(\n address voter,\n uint40 timestamp,\n uint256 hintIndex\n ) internal view returns (VotingPowerSnapshot memory snap) {\n VotingPowerSnapshot[] storage snaps = _votingPowerSnapshotsByVoter[voter];\n uint256 snapsLength = snaps.length;\n if (snapsLength != 0) {\n if (\n // Hint is within bounds.\n hintIndex < snapsLength &&\n // Snapshot is not too recent.\n snaps[hintIndex].timestamp <= timestamp &&\n // Snapshot is not too old.\n (hintIndex == snapsLength - 1 || snaps[hintIndex + 1].timestamp > timestamp)\n ) {\n return snaps[hintIndex];\n }\n\n // Hint was wrong, fallback to binary search to find snapshot.\n hintIndex = findVotingPowerSnapshotIndex(voter, timestamp);\n // Check that snapshot was found.\n if (hintIndex != type(uint256).max) {\n return snaps[hintIndex];\n }\n }\n\n // No snapshot found.\n return snap;\n }\n\n // Transfers some voting power of `from` to `to`. The total voting power of\n // their respective delegates will be updated as well.\n function _transferVotingPower(address from, address to, uint256 power) internal {\n int192 powerI192 = power.safeCastUint256ToInt192();\n _adjustVotingPower(from, -powerI192, address(0));\n _adjustVotingPower(to, powerI192, address(0));\n }\n\n // Increase `voter`'s intrinsic voting power and update their delegate if delegate is nonzero.\n function _adjustVotingPower(address voter, int192 votingPower, address delegate) internal {\n VotingPowerSnapshot memory oldSnap = _getLastVotingPowerSnapshotForVoter(voter);\n address oldDelegate = delegationsByVoter[voter];\n // If `oldDelegate` is zero and `voter` never delegated, then have\n // `voter` delegate to themself.\n oldDelegate = oldDelegate == address(0) ? voter : oldDelegate;\n // If the new `delegate` is zero, use the current (old) delegate.\n delegate = delegate == address(0) ? oldDelegate : delegate;\n\n VotingPowerSnapshot memory newSnap = VotingPowerSnapshot({\n timestamp: uint40(block.timestamp),\n delegatedVotingPower: oldSnap.delegatedVotingPower,\n intrinsicVotingPower: (oldSnap.intrinsicVotingPower.safeCastUint96ToInt192() +\n votingPower).safeCastInt192ToUint96(),\n isDelegated: delegate != voter\n });\n _insertVotingPowerSnapshot(voter, newSnap);\n delegationsByVoter[voter] = delegate;\n // Handle rebalancing delegates.\n _rebalanceDelegates(voter, oldDelegate, delegate, oldSnap, newSnap);\n }\n\n function _getTotalVotingPower() internal view returns (uint256) {\n return _governanceValues.totalVotingPower;\n }\n\n // Update the delegated voting power of the old and new delegates delegated to\n // by `voter` based on the snapshot change.\n function _rebalanceDelegates(\n address voter,\n address oldDelegate,\n address newDelegate,\n VotingPowerSnapshot memory oldSnap,\n VotingPowerSnapshot memory newSnap\n ) private {\n if (newDelegate == address(0) || oldDelegate == address(0)) {\n revert InvalidDelegateError();\n }\n if (oldDelegate != voter && oldDelegate != newDelegate) {\n // Remove past voting power from old delegate.\n VotingPowerSnapshot memory oldDelegateSnap = _getLastVotingPowerSnapshotForVoter(\n oldDelegate\n );\n VotingPowerSnapshot memory updatedOldDelegateSnap = VotingPowerSnapshot({\n timestamp: uint40(block.timestamp),\n delegatedVotingPower: oldDelegateSnap.delegatedVotingPower -\n oldSnap.intrinsicVotingPower,\n intrinsicVotingPower: oldDelegateSnap.intrinsicVotingPower,\n isDelegated: oldDelegateSnap.isDelegated\n });\n _insertVotingPowerSnapshot(oldDelegate, updatedOldDelegateSnap);\n }\n if (newDelegate != voter) {\n // Not delegating to self.\n // Add new voting power to new delegate.\n VotingPowerSnapshot memory newDelegateSnap = _getLastVotingPowerSnapshotForVoter(\n newDelegate\n );\n uint96 newDelegateDelegatedVotingPower = newDelegateSnap.delegatedVotingPower +\n newSnap.intrinsicVotingPower;\n if (newDelegate == oldDelegate) {\n // If the old and new delegate are the same, subtract the old\n // intrinsic voting power of the voter, or else we will double\n // count a portion of it.\n newDelegateDelegatedVotingPower -= oldSnap.intrinsicVotingPower;\n }\n VotingPowerSnapshot memory updatedNewDelegateSnap = VotingPowerSnapshot({\n timestamp: uint40(block.timestamp),\n delegatedVotingPower: newDelegateDelegatedVotingPower,\n intrinsicVotingPower: newDelegateSnap.intrinsicVotingPower,\n isDelegated: newDelegateSnap.isDelegated\n });\n _insertVotingPowerSnapshot(newDelegate, updatedNewDelegateSnap);\n }\n }\n\n // Append a new voting power snapshot, overwriting the last one if possible.\n function _insertVotingPowerSnapshot(address voter, VotingPowerSnapshot memory snap) private {\n VotingPowerSnapshot[] storage voterSnaps = _votingPowerSnapshotsByVoter[voter];\n uint256 n = voterSnaps.length;\n // If same timestamp as last entry, overwrite the last snapshot, otherwise append.\n if (n != 0) {\n VotingPowerSnapshot memory lastSnap = voterSnaps[n - 1];\n if (lastSnap.timestamp == snap.timestamp) {\n voterSnaps[n - 1] = snap;\n return;\n }\n }\n voterSnaps.push(snap);\n }\n\n function _getLastVotingPowerSnapshotForVoter(\n address voter\n ) private view returns (VotingPowerSnapshot memory snap) {\n VotingPowerSnapshot[] storage voterSnaps = _votingPowerSnapshotsByVoter[voter];\n uint256 n = voterSnaps.length;\n if (n != 0) {\n snap = voterSnaps[n - 1];\n }\n }\n\n function _getProposalFlags(ProposalStateValues memory pv) private view returns (uint256) {\n if (_isUnanimousVotes(pv.votes, _governanceValues.totalVotingPower)) {\n return LibProposal.PROPOSAL_FLAG_UNANIMOUS;\n }\n return 0;\n }\n\n function _getProposalStatus(\n ProposalStateValues memory pv\n ) private view returns (ProposalStatus status) {\n // Never proposed.\n if (pv.proposedTime == 0) {\n return ProposalStatus.Invalid;\n }\n // Executed at least once.\n if (pv.executedTime != 0) {\n if (pv.completedTime == 0) {\n return ProposalStatus.InProgress;\n }\n // completedTime high bit will be set if cancelled.\n if (pv.completedTime & UINT40_HIGH_BIT == UINT40_HIGH_BIT) {\n return ProposalStatus.Cancelled;\n }\n return ProposalStatus.Complete;\n }\n // Vetoed.\n if (pv.votes == type(uint96).max) {\n return ProposalStatus.Defeated;\n }\n uint40 t = uint40(block.timestamp);\n GovernanceValues memory gv = _governanceValues;\n if (pv.passedTime != 0) {\n // Ready.\n if (pv.passedTime + gv.executionDelay <= t) {\n return ProposalStatus.Ready;\n }\n // If unanimous, we skip the execution delay.\n if (_isUnanimousVotes(pv.votes, gv.totalVotingPower)) {\n return ProposalStatus.Ready;\n }\n // Passed.\n return ProposalStatus.Passed;\n }\n // Voting window expired.\n if (pv.proposedTime + gv.voteDuration <= t) {\n return ProposalStatus.Defeated;\n }\n return ProposalStatus.Voting;\n }\n\n function _isUnanimousVotes(\n uint96 totalVotes,\n uint96 totalVotingPower\n ) private pure returns (bool) {\n uint256 acceptanceRatio = (totalVotes * 1e4) / totalVotingPower;\n // If >= 99.99% acceptance, consider it unanimous.\n // The minting formula for voting power is a bit lossy, so we check\n // for slightly less than 100%.\n return acceptanceRatio >= 0.9999e4;\n }\n\n function _areVotesPassing(\n uint96 voteCount,\n uint96 totalVotingPower,\n uint16 passThresholdBps\n ) private pure returns (bool) {\n return (uint256(voteCount) * 1e4) / uint256(totalVotingPower) >= uint256(passThresholdBps);\n }\n\n function _setPreciousList(\n IERC721[] memory preciousTokens,\n uint256[] memory preciousTokenIds\n ) private {\n if (preciousTokens.length != preciousTokenIds.length) {\n revert MismatchedPreciousListLengths();\n }\n preciousListHash = _hashPreciousList(preciousTokens, preciousTokenIds);\n }\n\n function _isPreciousListCorrect(\n IERC721[] memory preciousTokens,\n uint256[] memory preciousTokenIds\n ) private view returns (bool) {\n return preciousListHash == _hashPreciousList(preciousTokens, preciousTokenIds);\n }\n\n function _hashPreciousList(\n IERC721[] memory preciousTokens,\n uint256[] memory preciousTokenIds\n ) internal pure returns (bytes32 h) {\n assembly {\n mstore(0x00, keccak256(add(preciousTokens, 0x20), mul(mload(preciousTokens), 0x20)))\n mstore(0x20, keccak256(add(preciousTokenIds, 0x20), mul(mload(preciousTokenIds), 0x20)))\n h := keccak256(0x00, 0x40)\n }\n }\n\n // Assert that the hash of a proposal matches expectedHash.\n function _validateProposalHash(Proposal memory proposal, bytes32 expectedHash) private pure {\n bytes32 actualHash = getProposalHash(proposal);\n if (expectedHash != actualHash) {\n revert BadProposalHashError(actualHash, expectedHash);\n }\n }\n}\n"
},
"contracts/party/PartyGovernanceNFT.sol": {
"content": "// SPDX-License-Identifier: GPL-3.0\npragma solidity 0.8.17;\n\nimport \"../utils/ReadOnlyDelegateCall.sol\";\nimport \"../utils/LibSafeCast.sol\";\nimport \"openzeppelin/contracts/interfaces/IERC2981.sol\";\nimport \"../globals/IGlobals.sol\";\nimport \"../tokens/IERC721.sol\";\nimport \"../vendor/solmate/ERC721.sol\";\nimport \"./PartyGovernance.sol\";\nimport \"../renderers/RendererStorage.sol\";\n\n/// @notice ERC721 functionality built on top of `PartyGovernance`.\ncontract PartyGovernanceNFT is PartyGovernance, ERC721, IERC2981 {\n using LibSafeCast for uint256;\n using LibSafeCast for uint96;\n\n error OnlyMintAuthorityError(address actual, address expected);\n\n // The `Globals` contract storing global configuration values. This contract\n // is immutable and it’s address will never change.\n IGlobals private immutable _GLOBALS;\n\n /// @notice Who can call `mint()`. Usually this will be the crowdfund contract that\n /// created the party.\n address public mintAuthority;\n /// @notice The number of tokens that have been minted.\n uint96 public tokenCount;\n /// @notice The total minted voting power.\n /// Capped to `_governanceValues.totalVotingPower`\n uint96 public mintedVotingPower;\n /// @notice The voting power of `tokenId`.\n mapping(uint256 => uint256) public votingPowerByTokenId;\n\n modifier onlyMinter() {\n address minter = mintAuthority;\n if (msg.sender != minter) {\n revert OnlyMintAuthorityError(msg.sender, minter);\n }\n _;\n }\n\n // Set the `Globals` contract. The name of symbol of ERC721 does not matter;\n // it will be set in `_initialize()`.\n constructor(IGlobals globals) PartyGovernance(globals) ERC721(\"\", \"\") {\n _GLOBALS = globals;\n }\n\n // Initialize storage for proxy contracts.\n function _initialize(\n string memory name_,\n string memory symbol_,\n uint256 customizationPresetId,\n PartyGovernance.GovernanceOpts memory governanceOpts,\n IERC721[] memory preciousTokens,\n uint256[] memory preciousTokenIds,\n address mintAuthority_\n ) internal {\n PartyGovernance._initialize(governanceOpts, preciousTokens, preciousTokenIds);\n name = name_;\n symbol = symbol_;\n mintAuthority = mintAuthority_;\n if (customizationPresetId != 0) {\n RendererStorage(_GLOBALS.getAddress(LibGlobals.GLOBAL_RENDERER_STORAGE))\n .useCustomizationPreset(customizationPresetId);\n }\n }\n\n /// @inheritdoc ERC721\n function ownerOf(\n uint256 tokenId\n ) public view override(ERC721, ITokenDistributorParty) returns (address owner) {\n return ERC721.ownerOf(tokenId);\n }\n\n /// @inheritdoc EIP165\n function supportsInterface(\n bytes4 interfaceId\n ) public pure override(PartyGovernance, ERC721, IERC165) returns (bool) {\n return\n PartyGovernance.supportsInterface(interfaceId) ||\n ERC721.supportsInterface(interfaceId) ||\n interfaceId == type(IERC2981).interfaceId;\n }\n\n /// @inheritdoc ERC721\n function tokenURI(uint256) public view override returns (string memory) {\n _delegateToRenderer();\n return \"\"; // Just to make the compiler happy.\n }\n\n /// @notice Returns a URI for the storefront-level metadata for your contract.\n function contractURI() external view returns (string memory) {\n _delegateToRenderer();\n return \"\"; // Just to make the compiler happy.\n }\n\n /// @notice Called with the sale price to determine how much royalty\n // is owed and to whom.\n function royaltyInfo(uint256, uint256) external view returns (address, uint256) {\n _delegateToRenderer();\n return (address(0), 0); // Just to make the compiler happy.\n }\n\n /// @inheritdoc ITokenDistributorParty\n function getDistributionShareOf(uint256 tokenId) external view returns (uint256) {\n return (votingPowerByTokenId[tokenId] * 1e18) / _getTotalVotingPower();\n }\n\n /// @notice Mint a governance NFT for `owner` with `votingPower` and\n /// immediately delegate voting power to `delegate.`\n /// @param owner The owner of the NFT.\n /// @param votingPower The voting power of the NFT.\n /// @param delegate The address to delegate voting power to.\n function mint(\n address owner,\n uint256 votingPower,\n address delegate\n ) external onlyMinter onlyDelegateCall returns (uint256 tokenId) {\n (uint96 tokenCount_, uint96 mintedVotingPower_) = (tokenCount, mintedVotingPower);\n uint96 totalVotingPower = _governanceValues.totalVotingPower;\n // Cap voting power to remaining unminted voting power supply.\n uint96 votingPower_ = votingPower.safeCastUint256ToUint96();\n if (totalVotingPower - mintedVotingPower_ < votingPower_) {\n votingPower_ = totalVotingPower - mintedVotingPower_;\n }\n mintedVotingPower_ += votingPower_;\n // Update state.\n tokenId = tokenCount = tokenCount_ + 1;\n mintedVotingPower = mintedVotingPower_;\n votingPowerByTokenId[tokenId] = votingPower_;\n\n // Use delegate from party over the one set during crowdfund.\n address delegate_ = delegationsByVoter[owner];\n if (delegate_ != address(0)) {\n delegate = delegate_;\n }\n\n _adjustVotingPower(owner, votingPower_.safeCastUint96ToInt192(), delegate);\n _safeMint(owner, tokenId);\n }\n\n /// @inheritdoc ERC721\n function transferFrom(\n address owner,\n address to,\n uint256 tokenId\n ) public override onlyDelegateCall {\n // Transfer voting along with token.\n _transferVotingPower(owner, to, votingPowerByTokenId[tokenId]);\n super.transferFrom(owner, to, tokenId);\n }\n\n /// @inheritdoc ERC721\n function safeTransferFrom(\n address owner,\n address to,\n uint256 tokenId\n ) public override onlyDelegateCall {\n // super.safeTransferFrom() will call transferFrom() first which will\n // transfer voting power.\n super.safeTransferFrom(owner, to, tokenId);\n }\n\n /// @inheritdoc ERC721\n function safeTransferFrom(\n address owner,\n address to,\n uint256 tokenId,\n bytes calldata data\n ) public override onlyDelegateCall {\n // super.safeTransferFrom() will call transferFrom() first which will\n // transfer voting power.\n super.safeTransferFrom(owner, to, tokenId, data);\n }\n\n /// @notice Relinquish the ability to call `mint()` by an authority.\n function abdicate() external onlyMinter onlyDelegateCall {\n delete mintAuthority;\n }\n\n function _delegateToRenderer() private view {\n _readOnlyDelegateCall(\n // Instance of IERC721Renderer.\n _GLOBALS.getAddress(LibGlobals.GLOBAL_GOVERNANCE_NFT_RENDER_IMPL),\n msg.data\n );\n assert(false); // Will not be reached.\n }\n}\n"
},
"contracts/proposals/IProposalExecutionEngine.sol": {
"content": "// SPDX-License-Identifier: GPL-3.0\npragma solidity 0.8.17;\n\nimport \"../tokens/IERC721.sol\";\n\n// Upgradeable proposals logic contract interface.\ninterface IProposalExecutionEngine {\n struct ExecuteProposalParams {\n uint256 proposalId;\n bytes proposalData;\n bytes progressData;\n bytes extraData;\n uint256 flags;\n IERC721[] preciousTokens;\n uint256[] preciousTokenIds;\n }\n\n function initialize(address oldImpl, bytes memory initData) external;\n\n /// @notice Execute a proposal.\n /// @dev Must be delegatecalled into by PartyGovernance.\n /// If the proposal is incomplete, continues its next step (if possible).\n /// If another proposal is incomplete, this will fail. Only one\n /// incomplete proposal is allowed at a time.\n /// @param params The data needed to execute the proposal.\n /// @return nextProgressData Bytes to be passed into the next `execute()` call,\n /// if the proposal execution is incomplete. Otherwise, empty bytes\n /// to indicate the proposal is complete.\n function executeProposal(\n ExecuteProposalParams memory params\n ) external returns (bytes memory nextProgressData);\n\n /// @notice Forcibly cancel an incomplete proposal.\n /// @param proposalId The ID of the proposal to cancel.\n /// @dev This is intended to be a last resort as it can leave a party in a\n /// broken step. Whenever possible, proposals should be allowed to\n /// complete their entire lifecycle.\n function cancelProposal(uint256 proposalId) external;\n}\n"
},
"contracts/proposals/LibProposal.sol": {
"content": "// SPDX-License-Identifier: GPL-3.0\npragma solidity 0.8.17;\n\nimport \"../tokens/IERC721.sol\";\n\nlibrary LibProposal {\n uint256 internal constant PROPOSAL_FLAG_UNANIMOUS = 0x1;\n\n function isTokenPrecious(\n IERC721 token,\n IERC721[] memory preciousTokens\n ) internal pure returns (bool) {\n for (uint256 i; i < preciousTokens.length; ++i) {\n if (token == preciousTokens[i]) {\n return true;\n }\n }\n return false;\n }\n\n function isTokenIdPrecious(\n IERC721 token,\n uint256 tokenId,\n IERC721[] memory preciousTokens,\n uint256[] memory preciousTokenIds\n ) internal pure returns (bool) {\n for (uint256 i; i < preciousTokens.length; ++i) {\n if (token == preciousTokens[i] && tokenId == preciousTokenIds[i]) {\n return true;\n }\n }\n return false;\n }\n}\n"
},
"contracts/proposals/ProposalStorage.sol": {
"content": "// SPDX-License-Identifier: GPL-3.0\npragma solidity 0.8.17;\n\nimport \"./IProposalExecutionEngine.sol\";\nimport \"../utils/LibRawResult.sol\";\n\n// The storage bucket shared by `PartyGovernance` and the `ProposalExecutionEngine`.\n// Read this for more context on the pattern motivating this:\n// https://github.com/dragonfly-xyz/useful-solidity-patterns/tree/main/patterns/explicit-storage-buckets\nabstract contract ProposalStorage {\n using LibRawResult for bytes;\n\n struct SharedProposalStorage {\n IProposalExecutionEngine engineImpl;\n }\n\n uint256 internal constant PROPOSAL_FLAG_UNANIMOUS = 0x1;\n uint256 private constant SHARED_STORAGE_SLOT =\n uint256(keccak256(\"ProposalStorage.SharedProposalStorage\"));\n\n function _getProposalExecutionEngine() internal view returns (IProposalExecutionEngine impl) {\n return _getSharedProposalStorage().engineImpl;\n }\n\n function _setProposalExecutionEngine(IProposalExecutionEngine impl) internal {\n _getSharedProposalStorage().engineImpl = impl;\n }\n\n function _initProposalImpl(IProposalExecutionEngine impl, bytes memory initData) internal {\n SharedProposalStorage storage stor = _getSharedProposalStorage();\n IProposalExecutionEngine oldImpl = stor.engineImpl;\n stor.engineImpl = impl;\n (bool s, bytes memory r) = address(impl).delegatecall(\n abi.encodeCall(IProposalExecutionEngine.initialize, (address(oldImpl), initData))\n );\n if (!s) {\n r.rawRevert();\n }\n }\n\n function _getSharedProposalStorage() private pure returns (SharedProposalStorage storage stor) {\n uint256 s = SHARED_STORAGE_SLOT;\n assembly {\n stor.slot := s\n }\n }\n}\n"
},
"contracts/renderers/CrowdfundNFTRenderer.sol": {
"content": "// SPDX-License-Identifier: GPL-3.0\npragma solidity 0.8.17;\n\nimport \"../utils/LibSafeCast.sol\";\nimport \"../utils/vendor/Strings.sol\";\nimport \"../utils/vendor/Base64.sol\";\n\nimport \"./RendererBase.sol\";\nimport \"../crowdfund/Crowdfund.sol\";\n\ncontract CrowdfundNFTRenderer is RendererBase {\n using LibSafeCast for uint256;\n using Strings for uint256;\n using Strings for address;\n\n error InvalidTokenIdError();\n\n enum CrowdfundStatus {\n LIVE,\n WON,\n LOST\n }\n\n uint256 constant CROWDFUND_CARD_DATA = 0;\n\n constructor(\n IGlobals globals,\n RendererStorage rendererStorage,\n IFont font\n ) RendererBase(globals, rendererStorage, font) {}\n\n // The renderer is called via delegateCall, so we need to declare the storage layout.\n // Run `yarn build && yarn layout Crowdfund.sol/Crowdfund` to generate the current layout.\n string name;\n string symbol;\n mapping(uint256 => address) _owners;\n Party party;\n uint96 totalContributions;\n IGateKeeper gateKeeper;\n bytes12 gateKeeperId;\n address payable splitRecipient;\n uint16 splitBps;\n bool _splitRecipientHasBurned;\n bytes32 governanceOptsHash;\n mapping(address => address) delegationsByContributor;\n mapping(address => Crowdfund.Contribution[]) _contributionsByContributor;\n mapping(address => Crowdfund.Claim) claims;\n\n function tokenURI(uint256 tokenId) external view returns (string memory) {\n address owner = _owners[tokenId];\n if (owner == address(0)) {\n revert InvalidTokenIdError();\n }\n\n // Get the customization data for this crowdfund.\n (bool isDarkMode, Color color) = getCustomizationChoices();\n\n // Construct metadata.\n return\n string.concat(\n \"data:application/json;base64,\",\n Base64.encode(\n abi.encodePacked(\n '{\"name\":\"',\n generateName(owner),\n '\", \"description\":\"',\n generateDescription(name, owner),\n '\", \"external_url\":\"',\n generateExternalURL(),\n '\", \"image\":\"',\n generateSVG(\n name,\n getContribution(owner),\n getCrowdfundStatus(),\n color,\n isDarkMode\n ),\n '\"}'\n )\n )\n );\n }\n\n function generateName(address owner) private view returns (string memory) {\n return string.concat(getContribution(owner), \" ETH Contribution\");\n }\n\n function generateExternalURL() private view returns (string memory) {\n return string.concat(\"https://partybid.app/join/\", address(this).toHexString());\n }\n\n function generateDescription(\n string memory partyName,\n address owner\n ) private view returns (string memory) {\n CrowdfundStatus status = getCrowdfundStatus();\n string memory externalURL = generateExternalURL();\n string memory contribution = getContribution(owner);\n\n if (status == CrowdfundStatus.WON) {\n return\n string.concat(\n partyName,\n \" has won! You can use this Party Card to activate your membership in the Party. Head to \",\n externalURL,\n \" to activate.\"\n );\n } else if (status == CrowdfundStatus.LOST) {\n return\n string.concat(\n partyName,\n \" has lost. You can use this Party Card to claim your ETH back from the Party. Head to \",\n externalURL,\n \" to claim.\"\n );\n } else {\n return\n string.concat(\n \"This Party Card represents your contribution of \",\n contribution,\n \" ETH to the \",\n partyName,\n \" crowdfund. When the crowdfund concludes, you can use this Party Card to claim your ETH or activate your membership in the Party. During the crowdfund, Party Cards are non-transferable. Head to \",\n externalURL,\n \" to see more.\"\n );\n }\n }\n\n function generateCollectionName() internal view override returns (string memory) {\n return string.concat(\"Party Contributions: \", name);\n }\n\n function generateCollectionDescription() internal view override returns (string memory) {\n return\n string.concat(\n \"Party Cards in this collection represent contributions to the \",\n name,\n \" crowdfund. When the crowdfund concludes, Party Cards can be used to claim ETH or activate membership in the Party. During the crowdfund, Party Cards are non-transferable. Head to \",\n generateExternalURL(),\n \" to learn more about this Party.\"\n );\n }\n\n function generateSVG(\n string memory partyName,\n string memory contributionAmount,\n CrowdfundStatus status,\n Color color,\n bool isDarkMode\n ) public view returns (string memory) {\n return\n string.concat(\n \"data:image/svg+xml;base64,\",\n Base64.encode(\n abi.encodePacked(\n // Split to avoid stack too deep errors\n generateSVG1(color, isDarkMode),\n generateSVG2(partyName, color),\n generateSVG3(contributionAmount, color),\n generateSVG4(status, color),\n generateSVG5(partyName)\n )\n )\n );\n }\n\n function generateSVG1(Color color, bool isDarkMode) private pure returns (string memory) {\n return\n string.concat(\n ''\n )\n );\n\n files[PARTY_CARD_DATA] = SSTORE2.write(\n bytes(\n ' d=\"M188 444.3h2.4l2.6 8.2 2.7-8.2h2.3l-3.7 10.7h-2.8l-3.5-10.7zm10.5 5.3c0-3.2 2.2-5.6 5.3-5.6 3.1 0 5.3 2.3 5.3 5.6 0 3.2-2.2 5.5-5.3 5.5-3.1.1-5.3-2.2-5.3-5.5zm5.3 3.5c1.8 0 3-1.3 3-3.4 0-2.1-1.1-3.5-3-3.5s-3 1.3-3 3.5c0 2.1 1.1 3.4 3 3.4zm8.7-6.7h-3.1v-2.1h8.4v2.1h-3.1v8.6h-2.2v-8.6zm6.9-2.1h2.2V455h-2.2v-10.7zm4.3 0h2.9l4 8.2v-8.2h2.1V455h-2.9l-4-8.2v8.2h-2.1v-10.7zm10.6 5.4c0-3.4 2.3-5.6 6-5.6 1.2 0 2.3.2 3.1.6v2.3c-.9-.6-1.9-.8-3.1-.8-2.4 0-3.8 1.3-3.8 3.5 0 2.1 1.3 3.4 3.5 3.4.5 0 .9-.1 1.3-.2v-2.2h-2.2v-1.9h4.3v5.6c-1 .5-2.2.8-3.4.8-3.5 0-5.7-2.2-5.7-5.5zm15.1-5.4h4.3c2.3 0 3.7 1.3 3.7 3.5s-1.4 3.5-3.7 3.5h-2.1v3.7h-2.2v-10.7zm4.1 5c1.1 0 1.6-.5 1.6-1.5s-.5-1.5-1.6-1.5h-1.9v2.9h1.9zm4.8.3c0-3.2 2.2-5.6 5.3-5.6 3.1 0 5.3 2.3 5.3 5.6 0 3.2-2.2 5.5-5.3 5.5-3.1.1-5.3-2.2-5.3-5.5zm5.3 3.5c1.8 0 3-1.3 3-3.4 0-2.1-1.1-3.5-3-3.5s-3 1.3-3 3.5c0 2.1 1.1 3.4 3 3.4zm5.8-8.8h2.3l1.7 7.8 1.9-7.8h2.4l1.8 7.8 1.8-7.8h2.3l-2.7 10.7h-2.5l-1.9-8.2-1.8 8.2h-2.5l-2.8-10.7zm15.4 0h6.9v2.1H287v2.2h4.5v2.1H287v2.3h4.9v2.1h-7v-10.8zm9 0h4.5c2 0 3.3 1.3 3.3 3.2 0 1.9-1.2 3.1-3 3.2l3.5 4.3h-2.7l-3.5-4.4v4.4h-2.1v-10.7zm4.1 4.8c1 0 1.5-.5 1.5-1.4 0-.9-.6-1.4-1.5-1.4h-2v2.9h2zM30 444.3h4.3c3 0 5.2 2.1 5.2 5.4s-2.1 5.4-5.2 5.4H30v-10.8zm4 8.6c2.1 0 3.2-1.2 3.2-3.2s-1.2-3.3-3.2-3.3h-1.8v6.5H34zm7.7-8.6h2.2V455h-2.2v-10.7zm4.8 10V452c1 .7 2.1 1.1 3.2 1.1s1.7-.5 1.7-1.2-.4-1-1.2-1.2l-1.2-.3c-1.8-.5-2.7-1.5-2.7-3.1 0-2 1.5-3.2 3.9-3.2 1 0 2.1.2 2.9.7v2.3c-.9-.6-1.9-.8-3-.8-.9 0-1.6.4-1.6 1.1 0 .6.4.9 1.2 1.1l1.3.4c1.8.5 2.6 1.4 2.6 3.1 0 2.1-1.5 3.4-3.8 3.4-1.1-.2-2.3-.5-3.3-1.1zm12-7.9h-3.1v-2.1h8.4v2.1h-3.1v8.6h-2.2v-8.6zm7.5-2.1h4.5c2 0 3.3 1.3 3.3 3.2 0 1.9-1.2 3.1-3 3.2l3.5 4.3h-2.7l-3.5-4.4v4.4H66v-10.7zm4.1 4.8c1 0 1.5-.5 1.5-1.4s-.6-1.4-1.5-1.4h-2v2.9h2zm6.1-4.8h2.2V455h-2.2v-10.7zm5 0h4.5c2 0 3.2 1.1 3.2 2.8 0 1.1-.5 1.9-1.4 2.3 1.1.3 1.8 1.3 1.8 2.5 0 1.9-1.3 3.1-3.5 3.1h-4.6v-10.7zm4.2 4.4c.9 0 1.4-.5 1.4-1.3s-.5-1.3-1.4-1.3h-2.1v2.5l2.1.1zm.3 4.4c.9 0 1.5-.5 1.5-1.3s-.6-1.3-1.5-1.3h-2.4v2.6h2.4zm5.7-2.5v-6.3h2.2v6.3c0 1.6.9 2.5 2.3 2.5s2.3-.9 2.3-2.5v-6.3h2.2v6.3c0 2.9-1.7 4.6-4.5 4.6s-4.6-1.7-4.5-4.6zm14.2-4.2h-3.1v-2.1h8.4v2.1h-3.1v8.6h-2.2v-8.6zm7.5-2.1h2.2V455h-2.2v-10.7zm4.5 5.3c0-3.2 2.2-5.6 5.3-5.6s5.3 2.3 5.3 5.6-2.2 5.5-5.3 5.5-5.3-2.2-5.3-5.5zm5.3 3.5c1.8 0 3-1.3 3-3.5s-1.2-3.5-3-3.5-3 1.3-3 3.5 1.1 3.5 3 3.5zm7.5-8.8h2.9l4 8.2v-8.2h2.1V455h-2.9l-4-8.2v8.2h-2.1v-10.7zm11.7 10V452c1 .7 2.1 1.1 3.2 1.1s1.7-.5 1.7-1.2-.4-1-1.2-1.2l-1.2-.3c-1.8-.5-2.6-1.5-2.6-3.1 0-2 1.5-3.2 3.9-3.2 1.1 0 2.1.2 2.9.7v2.3c-.9-.6-1.9-.8-3-.8-.9 0-1.6.4-1.6 1.1 0 .6.4.9 1.2 1.1l1.3.4c1.8.5 2.6 1.4 2.6 3.1 0 2.1-1.5 3.4-3.8 3.4a9.7 9.7 0 0 1-3.4-1.1zM30 259.3h4.3c2.2 0 3.7 1.3 3.7 3.5s-1.4 3.5-3.7 3.5h-2.1v3.7H30v-10.7zm4.1 5c1.1 0 1.6-.5 1.6-1.5s-.5-1.5-1.6-1.5h-1.9v2.9h1.9zm6.1-5h4.5c2 0 3.3 1.3 3.3 3.2 0 1.9-1.2 3.1-3 3.2l3.5 4.3h-2.7l-3.5-4.4v4.4h-2.1v-10.7zm4.1 4.8c1 0 1.5-.5 1.5-1.4s-.6-1.4-1.5-1.4h-2v2.9h2zm5.4.5c0-3.2 2.2-5.6 5.3-5.6s5.3 2.3 5.3 5.6-2.2 5.5-5.3 5.5-5.3-2.2-5.3-5.5zm5.3 3.5c1.8 0 3-1.3 3-3.5s-1.2-3.5-3-3.5-3 1.3-3 3.5 1.1 3.5 3 3.5zm7.6-8.8h4.3c2.2 0 3.7 1.3 3.7 3.5s-1.4 3.5-3.7 3.5h-2.1v3.7h-2.2v-10.7zm4.1 5c1.1 0 1.6-.5 1.6-1.5s-.6-1.5-1.6-1.5h-1.9v2.9h1.9zm5.4.4c0-3.2 2.2-5.6 5.3-5.6s5.3 2.3 5.3 5.6-2.2 5.5-5.3 5.5-5.3-2.3-5.3-5.5zm5.4 3.4c1.8 0 3-1.3 3-3.5s-1.2-3.5-3-3.5-3 1.3-3 3.5 1.1 3.5 3 3.5zm7.2 1.2V267c1 .7 2.1 1.1 3.2 1.1s1.7-.5 1.7-1.2-.4-1-1.2-1.2l-1.2-.3c-1.8-.5-2.7-1.5-2.7-3.1 0-2 1.5-3.2 3.9-3.2 1.1 0 2.1.2 2.9.7v2.3c-.9-.6-1.9-.8-3-.8-.9 0-1.6.4-1.6 1.1 0 .6.4.9 1.2 1.1l1.3.4c1.8.5 2.6 1.4 2.6 3.1 0 2.1-1.5 3.4-3.8 3.4-1.1-.2-2.3-.5-3.3-1.1zm12.2-10h2.8l3.7 10.7h-2.3l-.8-2.5h-4l-.8 2.5h-2.2l3.6-10.7zm2.8 6.3-1.4-4.2-1.4 4.2h2.8zm5.7-6.3h2.2v8.6h4.7v2.1h-6.9v-10.7zm9.1 10V267c1 .7 2.1 1.1 3.2 1.1s1.7-.5 1.7-1.2-.4-1-1.2-1.2l-1.2-.3c-1.8-.5-2.7-1.5-2.7-3.1 0-2 1.5-3.2 3.9-3.2 1.1 0 2.1.2 2.9.7v2.3c-.9-.6-1.9-.8-3-.8-.9 0-1.6.4-1.6 1.1 0 .6.4.9 1.2 1.1l1.3.4c1.8.5 2.6 1.4 2.6 3.1 0 2.1-1.5 3.4-3.8 3.4-1.1-.2-2.3-.5-3.3-1.1zm-84.5-70h2.9l4 8.2v-8.2H39V210h-2.9l-4-8.2v8.2H30v-10.7zm14.7 0h2.8l3.7 10.7h-2.3l-.8-2.6h-4l-.8 2.6H41l3.7-10.7zm2.8 6.2-1.4-4.2-1.4 4.2h2.8zm5.7-6.2h3.3l2.5 8.2 2.5-8.2h3.3V210h-2v-8.6L60 210h-2.1l-2.7-8.5v8.5h-2v-10.7zm14.4 0h6.9v2.1h-4.8v2.2h4.4v2.1h-4.4v2.3h4.9v2.1h-7v-10.8z\" />'\n )\n );\n }\n\n /// @notice Transfer ownership to a new owner.\n /// @param newOwner The address to transfer ownership to.\n function transferOwnership(address newOwner) external onlyOwner {\n emit OwnershipTransferred(owner, newOwner);\n owner = newOwner;\n }\n\n /// @notice Write data to be accessed by a given file key.\n /// @param key The key to access the written data.\n /// @param data The data to be written.\n function writeFile(uint256 key, string memory data) external onlyOwner {\n files[key] = SSTORE2.write(bytes(data));\n }\n\n /// @notice Read data using a given file key.\n /// @param key The key to access the stored data.\n /// @return data The data stored at the given key.\n function readFile(uint256 key) external view returns (string memory data) {\n return string(SSTORE2.read(files[key]));\n }\n\n /// @notice Create or set a customization preset for renderers to use.\n /// @param id The ID of the customization preset.\n /// @param customizationData Data decoded by renderers used to render the SVG according to the preset.\n function createCustomizationPreset(\n uint256 id,\n bytes memory customizationData\n ) external onlyOwner {\n customizationPresets[id] = customizationData;\n }\n\n /// @notice For crowdfund or party instances to set the customization preset they want to use.\n /// @param id The ID of the customization preset.\n function useCustomizationPreset(uint256 id) external {\n getPresetFor[msg.sender] = id;\n }\n}\n"
},
"contracts/renderers/fonts/IFont.sol": {
"content": "// SPDX-License-Identifier: MIT\npragma solidity ^0.8.4;\n\n/// @title The interface on-chain font contracts must implement to be added to the registry.\n///\n/// Uploading fonts to chain is open ended and up to the dev (SSTORE2 or hardcoded string or etc).\n///\n/// As long as the font contract implements this interface and has immutable font data, it can be added\n/// to the registry.\n///\n/// @author @0x_beans\ninterface IFont {\n /// @notice Address that uploaded font for credits\n function fontUploader() external returns (address);\n\n /// @notice Format type of font (eg. ttf, woff, otf, etc). Must be lowercase.\n /// This info is necessary so projects know how to properly render the fonts.\n function fontFormatType() external returns (string memory);\n\n /// @notice Font name (ie. 'space-grotesk'). Must be lowercase.\n function fontName() external returns (string memory);\n\n /// @notice Weight used by the font (eg. bold, medium, light, etc). Must be lowercase.\n /// Necessary to differentiate uploaded fonts that are the same but different weights.\n function fontWeight() external returns (string memory);\n\n /// @notice Style used by the font (eg. lowercase normal, italic, oblique, etc). Must be lowercase.\n // Necessary to differentiate uploaded fonts that are the same but different style.\n function fontStyle() external returns (string memory);\n\n /// @notice The full base64 encoded font with data URI scheme prefix\n /// (eg. 'data:font/ttf;charset=utf-8;base64,').\n function getFont() external view returns (string memory);\n}\n"
},
"contracts/tokens/ERC1155Receiver.sol": {
"content": "// SPDX-License-Identifier: Apache-2.0\npragma solidity ^0.8;\n\nimport \"../vendor/solmate/ERC1155.sol\";\nimport \"../utils/EIP165.sol\";\n\nabstract contract ERC1155Receiver is EIP165, ERC1155TokenReceiverBase {\n /// @inheritdoc EIP165\n function supportsInterface(bytes4 interfaceId) public pure virtual override returns (bool) {\n return\n super.supportsInterface(interfaceId) ||\n interfaceId == type(ERC1155TokenReceiverBase).interfaceId;\n }\n}\n"
},
"contracts/tokens/ERC721Receiver.sol": {
"content": "// SPDX-License-Identifier: Apache-2.0\npragma solidity ^0.8;\n\nimport \"./IERC721Receiver.sol\";\nimport \"../utils/EIP165.sol\";\nimport \"../vendor/solmate/ERC721.sol\";\n\n/// @notice Mixin for contracts that want to receive ERC721 tokens.\n/// @dev Use this instead of solmate's ERC721TokenReceiver because the\n/// compiler has issues when overriding EIP165/IERC721Receiver functions.\nabstract contract ERC721Receiver is IERC721Receiver, EIP165, ERC721TokenReceiver {\n /// @inheritdoc IERC721Receiver\n function onERC721Received(\n address,\n address,\n uint256,\n bytes memory\n ) public virtual override(IERC721Receiver, ERC721TokenReceiver) returns (bytes4) {\n return IERC721Receiver.onERC721Received.selector;\n }\n\n /// @inheritdoc EIP165\n function supportsInterface(bytes4 interfaceId) public pure virtual override returns (bool) {\n return\n EIP165.supportsInterface(interfaceId) ||\n interfaceId == type(IERC721Receiver).interfaceId;\n }\n}\n"
},
"contracts/tokens/IERC1155.sol": {
"content": "// SPDX-License-Identifier: Apache-2.0\npragma solidity ^0.8;\n\n// Minimal ERC1155 interface.\ninterface IERC1155 {\n event TransferSingle(\n address indexed operator,\n address indexed from,\n address indexed to,\n uint256 id,\n uint256 amount\n );\n event TransferBatch(\n address indexed operator,\n address indexed from,\n address indexed to,\n uint256[] ids,\n uint256[] amounts\n );\n event ApprovalForAll(address indexed owner, address indexed operator, bool approved);\n\n function setApprovalForAll(address operator, bool approved) external;\n\n function safeTransferFrom(\n address from,\n address to,\n uint256 id,\n uint256 amount,\n bytes calldata data\n ) external;\n\n function safeBatchTransferFrom(\n address from,\n address to,\n uint256[] calldata ids,\n uint256[] calldata amounts,\n bytes calldata data\n ) external;\n\n function balanceOf(address owner, uint256 tokenId) external view returns (uint256);\n\n function isApprovedForAll(address owner, address spender) external view returns (bool);\n\n function balanceOfBatch(\n address[] calldata owners,\n uint256[] calldata ids\n ) external view returns (uint256[] memory balances);\n}\n"
},
"contracts/tokens/IERC20.sol": {
"content": "// SPDX-License-Identifier: Apache-2.0\npragma solidity ^0.8;\n\n// Minimal ERC20 interface.\ninterface IERC20 {\n event Transfer(address indexed owner, address indexed to, uint256 amount);\n event Approval(address indexed owner, address indexed spender, uint256 allowance);\n\n function transfer(address to, uint256 amount) external returns (bool);\n\n function transferFrom(address from, address to, uint256 amount) external returns (bool);\n\n function approve(address spender, uint256 allowance) external returns (bool);\n\n function allowance(address owner, address spender) external view returns (uint256);\n\n function balanceOf(address owner) external view returns (uint256);\n}\n"
},
"contracts/tokens/IERC721.sol": {
"content": "// SPDX-License-Identifier: Apache-2.0\npragma solidity ^0.8;\n\n// Minimal ERC721 interface.\ninterface IERC721 {\n event Transfer(address indexed owner, address indexed to, uint256 indexed tokenId);\n event Approval(address indexed owner, address indexed operator, uint256 indexed tokenId);\n event ApprovalForAll(address indexed owner, address indexed operator, bool approved);\n\n function transferFrom(address from, address to, uint256 tokenId) external;\n\n function safeTransferFrom(\n address from,\n address to,\n uint256 tokenId,\n bytes calldata data\n ) external;\n\n function safeTransferFrom(address from, address to, uint256 tokenId) external;\n\n function approve(address operator, uint256 tokenId) external;\n\n function setApprovalForAll(address operator, bool isApproved) external;\n\n function name() external view returns (string memory);\n\n function symbol() external view returns (string memory);\n\n function getApproved(uint256 tokenId) external view returns (address);\n\n function isApprovedForAll(address owner, address operator) external view returns (bool);\n\n function ownerOf(uint256 tokenId) external view returns (address);\n\n function balanceOf(address owner) external view returns (uint256);\n}\n"
},
"contracts/tokens/IERC721Receiver.sol": {
"content": "// SPDX-License-Identifier: Apache-2.0\npragma solidity ^0.8;\n\ninterface IERC721Receiver {\n function onERC721Received(\n address operator,\n address from,\n uint256 tokenId,\n bytes memory data\n ) external returns (bytes4);\n}\n"
},
"contracts/utils/EIP165.sol": {
"content": "// SPDX-License-Identifier: GPL-3.0\npragma solidity 0.8.17;\n\nabstract contract EIP165 {\n /// @notice Query if a contract implements an interface.\n /// @param interfaceId The interface identifier, as specified in ERC-165\n /// @return `true` if the contract implements `interfaceId` and\n /// `interfaceId` is not 0xffffffff, `false` otherwise\n function supportsInterface(bytes4 interfaceId) public pure virtual returns (bool) {\n return interfaceId == this.supportsInterface.selector;\n }\n}\n"
},
"contracts/utils/Implementation.sol": {
"content": "// SPDX-License-Identifier: GPL-3.0\npragma solidity 0.8.17;\n\n// Base contract for all contracts intended to be delegatecalled into.\nabstract contract Implementation {\n error OnlyDelegateCallError();\n error OnlyConstructorError();\n\n address public immutable IMPL;\n\n constructor() {\n IMPL = address(this);\n }\n\n // Reverts if the current function context is not inside of a delegatecall.\n modifier onlyDelegateCall() virtual {\n if (address(this) == IMPL) {\n revert OnlyDelegateCallError();\n }\n _;\n }\n\n // Reverts if the current function context is not inside of a constructor.\n modifier onlyConstructor() {\n if (address(this).code.length != 0) {\n revert OnlyConstructorError();\n }\n _;\n }\n}\n"
},
"contracts/utils/LibAddress.sol": {
"content": "// SPDX-License-Identifier: GPL-3.0\npragma solidity 0.8.17;\n\nlibrary LibAddress {\n error EthTransferFailed(address receiver, bytes errData);\n\n // Transfer ETH with full gas stipend.\n function transferEth(address payable receiver, uint256 amount) internal {\n if (amount == 0) return;\n\n (bool s, bytes memory r) = receiver.call{ value: amount }(\"\");\n if (!s) {\n revert EthTransferFailed(receiver, r);\n }\n }\n}\n"
},
"contracts/utils/LibERC20Compat.sol": {
"content": "// SPDX-License-Identifier: GPL-3.0\npragma solidity 0.8.17;\n\nimport \"../tokens/IERC20.sol\";\n\n// Compatibility helpers for ERC20s.\nlibrary LibERC20Compat {\n error NotATokenError(IERC20 token);\n error TokenTransferFailedError(IERC20 token, address to, uint256 amount);\n\n // Perform an `IERC20.transfer()` handling non-compliant implementations.\n function compatTransfer(IERC20 token, address to, uint256 amount) internal {\n (bool s, bytes memory r) = address(token).call(\n abi.encodeCall(IERC20.transfer, (to, amount))\n );\n if (s) {\n if (r.length == 0) {\n uint256 cs;\n assembly {\n cs := extcodesize(token)\n }\n if (cs == 0) {\n revert NotATokenError(token);\n }\n return;\n }\n if (abi.decode(r, (bool))) {\n return;\n }\n }\n revert TokenTransferFailedError(token, to, amount);\n }\n}\n"
},
"contracts/utils/LibRawResult.sol": {
"content": "// SPDX-License-Identifier: GPL-3.0\npragma solidity 0.8.17;\n\nlibrary LibRawResult {\n // Revert with the data in `b`.\n function rawRevert(bytes memory b) internal pure {\n assembly {\n revert(add(b, 32), mload(b))\n }\n }\n\n // Return with the data in `b`.\n function rawReturn(bytes memory b) internal pure {\n assembly {\n return(add(b, 32), mload(b))\n }\n }\n}\n"
},
"contracts/utils/LibSafeCast.sol": {
"content": "// SPDX-License-Identifier: GPL-3.0\npragma solidity 0.8.17;\n\nlibrary LibSafeCast {\n error Uint256ToUint96CastOutOfRange(uint256 v);\n error Uint256ToInt192CastOutOfRange(uint256 v);\n error Int192ToUint96CastOutOfRange(int192 i192);\n error Uint256ToInt128CastOutOfRangeError(uint256 u256);\n error Uint256ToUint128CastOutOfRangeError(uint256 u256);\n error Uint256ToUint40CastOutOfRangeError(uint256 u256);\n\n function safeCastUint256ToUint96(uint256 v) internal pure returns (uint96) {\n if (v > uint256(type(uint96).max)) {\n revert Uint256ToUint96CastOutOfRange(v);\n }\n return uint96(v);\n }\n\n function safeCastUint256ToUint128(uint256 v) internal pure returns (uint128) {\n if (v > uint256(type(uint128).max)) {\n revert Uint256ToUint128CastOutOfRangeError(v);\n }\n return uint128(v);\n }\n\n function safeCastUint256ToInt192(uint256 v) internal pure returns (int192) {\n if (v > uint256(uint192(type(int192).max))) {\n revert Uint256ToInt192CastOutOfRange(v);\n }\n return int192(uint192(v));\n }\n\n function safeCastUint96ToInt192(uint96 v) internal pure returns (int192) {\n return int192(uint192(v));\n }\n\n function safeCastInt192ToUint96(int192 i192) internal pure returns (uint96) {\n if (i192 < 0 || i192 > int192(uint192(type(uint96).max))) {\n revert Int192ToUint96CastOutOfRange(i192);\n }\n return uint96(uint192(i192));\n }\n\n function safeCastUint256ToInt128(uint256 x) internal pure returns (int128) {\n if (x > uint256(uint128(type(int128).max))) {\n revert Uint256ToInt128CastOutOfRangeError(x);\n }\n return int128(uint128(x));\n }\n\n function safeCastUint256ToUint40(uint256 x) internal pure returns (uint40) {\n if (x > uint256(type(uint40).max)) {\n revert Uint256ToUint40CastOutOfRangeError(x);\n }\n return uint40(x);\n }\n}\n"
},
"contracts/utils/Multicall.sol": {
"content": "// SPDX-License-Identifier: GPL-3.0\npragma solidity 0.8.17;\n\nimport \"../utils/LibRawResult.sol\";\n\nabstract contract Multicall {\n using LibRawResult for bytes;\n\n /// @notice Perform multiple delegatecalls on ourselves.\n function multicall(bytes[] calldata multicallData) external {\n for (uint256 i; i < multicallData.length; ++i) {\n (bool s, bytes memory r) = address(this).delegatecall(multicallData[i]);\n if (!s) {\n r.rawRevert();\n }\n }\n }\n}\n"
},
"contracts/utils/ReadOnlyDelegateCall.sol": {
"content": "// SPDX-License-Identifier: GPL-3.0\npragma solidity 0.8.17;\n\nimport \"./LibRawResult.sol\";\n\ninterface IReadOnlyDelegateCall {\n // Marked `view` so that `_readOnlyDelegateCall` can be `view` as well.\n function delegateCallAndRevert(address impl, bytes memory callData) external view;\n}\n\n// Inherited by contracts to perform read-only delegate calls.\nabstract contract ReadOnlyDelegateCall {\n using LibRawResult for bytes;\n\n // Delegatecall into implement and revert with the raw result.\n function delegateCallAndRevert(address impl, bytes memory callData) external {\n // Attempt to gate to only `_readOnlyDelegateCall()` invocations.\n require(msg.sender == address(this));\n (bool s, bytes memory r) = impl.delegatecall(callData);\n // Revert with success status and return data.\n abi.encode(s, r).rawRevert();\n }\n\n // Perform a `delegateCallAndRevert()` then return the raw result data.\n function _readOnlyDelegateCall(address impl, bytes memory callData) internal view {\n try IReadOnlyDelegateCall(address(this)).delegateCallAndRevert(impl, callData) {\n // Should never happen.\n assert(false);\n } catch (bytes memory r) {\n (bool success, bytes memory resultData) = abi.decode(r, (bool, bytes));\n if (!success) {\n resultData.rawRevert();\n }\n resultData.rawReturn();\n }\n }\n}\n"
},
"contracts/utils/vendor/Base64.sol": {
"content": "// SPDX-License-Identifier: GPL-3.0\npragma solidity ^0.8;\n\n/// [MIT License]\n/// @title Base64\n/// @notice Provides a function for encoding some bytes in base64\n/// @author Brecht Devos \nlibrary Base64 {\n bytes internal constant TABLE = \"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/\";\n\n /// @notice Encodes some bytes to the base64 representation\n function encode(bytes memory data) internal pure returns (string memory) {\n uint256 len = data.length;\n if (len == 0) return \"\";\n\n // multiply by 4/3 rounded up\n uint256 encodedLen = 4 * ((len + 2) / 3);\n\n // Add some extra buffer at the end\n bytes memory result = new bytes(encodedLen + 32);\n\n bytes memory table = TABLE;\n\n assembly {\n let tablePtr := add(table, 1)\n let resultPtr := add(result, 32)\n\n for {\n let i := 0\n } lt(i, len) {\n\n } {\n i := add(i, 3)\n let input := and(mload(add(data, i)), 0xffffff)\n\n let out := mload(add(tablePtr, and(shr(18, input), 0x3F)))\n out := shl(8, out)\n out := add(out, and(mload(add(tablePtr, and(shr(12, input), 0x3F))), 0xFF))\n out := shl(8, out)\n out := add(out, and(mload(add(tablePtr, and(shr(6, input), 0x3F))), 0xFF))\n out := shl(8, out)\n out := add(out, and(mload(add(tablePtr, and(input, 0x3F))), 0xFF))\n out := shl(224, out)\n\n mstore(resultPtr, out)\n\n resultPtr := add(resultPtr, 4)\n }\n\n switch mod(len, 3)\n case 1 {\n mstore(sub(resultPtr, 2), shl(240, 0x3d3d))\n }\n case 2 {\n mstore(sub(resultPtr, 1), shl(248, 0x3d))\n }\n\n mstore(result, encodedLen)\n }\n\n return string(result);\n }\n}"
},
"contracts/utils/vendor/Strings.sol": {
"content": "// SPDX-License-Identifier: GPL-3.0\npragma solidity ^0.8;\n\n// Modified from https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/utils/Strings.sol\nlibrary Strings {\n bytes16 private constant _HEX_SYMBOLS = \"0123456789abcdef\";\n uint8 private constant _ADDRESS_LENGTH = 20;\n\n /**\n * @dev Converts a `uint256` to its ASCII `string` decimal representation.\n */\n function toString(uint256 value) internal pure returns (string memory) {\n // Inspired by OraclizeAPI's implementation - MIT licence\n // https://github.com/oraclize/ethereum-api/blob/b42146b063c7d6ee1358846c198246239e9360e8/oraclizeAPI_0.4.25.sol\n\n if (value == 0) {\n return \"0\";\n }\n uint256 temp = value;\n uint256 digits;\n while (temp != 0) {\n digits++;\n temp /= 10;\n }\n bytes memory buffer = new bytes(digits);\n while (value != 0) {\n digits -= 1;\n buffer[digits] = bytes1(uint8(48 + uint256(value % 10)));\n value /= 10;\n }\n return string(buffer);\n }\n\n /**\n * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation.\n */\n function toHexString(uint256 value) internal pure returns (string memory) {\n if (value == 0) {\n return \"0x00\";\n }\n uint256 temp = value;\n uint256 length = 0;\n while (temp != 0) {\n length++;\n temp >>= 8;\n }\n return toHexString(value, length);\n }\n\n /**\n * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length.\n */\n function toHexString(uint256 value, uint256 length) internal pure returns (string memory) {\n bytes memory buffer = new bytes(2 * length + 2);\n buffer[0] = \"0\";\n buffer[1] = \"x\";\n for (uint256 i = 2 * length + 1; i > 1; --i) {\n buffer[i] = _HEX_SYMBOLS[value & 0xf];\n value >>= 4;\n }\n require(value == 0, \"Strings: hex length insufficient\");\n return string(buffer);\n }\n\n /**\n * @dev Converts an `address` with fixed length of 20 bytes to its not checksummed ASCII `string` hexadecimal representation.\n */\n function toHexString(address addr) internal pure returns (string memory) {\n return toHexString(uint256(uint160(addr)), _ADDRESS_LENGTH);\n }\n\n function substring(string memory str, uint startIndex, uint endIndex) internal pure returns (string memory ) {\n bytes memory strBytes = bytes(str);\n bytes memory result = new bytes(endIndex-startIndex);\n for(uint i = startIndex; i < endIndex; i++) {\n result[i-startIndex] = strBytes[i];\n }\n return string(result);\n }\n}"
},
"contracts/vendor/solmate/ERC1155.sol": {
"content": "// SPDX-License-Identifier: AGPL-3.0-only\n// Based on solmate commit 1681dc505f4897ef636f0435d01b1aa027fdafaf (v6.4.0)\n// @ https://github.com/Rari-Capital/solmate/blob/1681dc505f4897ef636f0435d01b1aa027fdafaf/src/tokens/ERC1155.sol\n// Only modified to inherit IERC1155 and rename ERC1155TokenReceiver -> ERC1155TokenReceiverBase.\npragma solidity ^0.8;\n\nimport \"../../tokens/IERC1155.sol\";\n\n/// @notice Minimalist and gas efficient standard ERC1155 implementation.\n/// @author Solmate (https://github.com/Rari-Capital/solmate/blob/main/src/tokens/ERC1155.sol)\nabstract contract ERC1155 is IERC1155 {\n /*//////////////////////////////////////////////////////////////\n EVENTS\n //////////////////////////////////////////////////////////////*/\n\n event URI(string value, uint256 indexed id);\n\n /*//////////////////////////////////////////////////////////////\n ERC1155 STORAGE\n //////////////////////////////////////////////////////////////*/\n\n mapping(address => mapping(uint256 => uint256)) public balanceOf;\n\n mapping(address => mapping(address => bool)) public isApprovedForAll;\n\n /*//////////////////////////////////////////////////////////////\n METADATA LOGIC\n //////////////////////////////////////////////////////////////*/\n\n function uri(uint256 id) public view virtual returns (string memory);\n\n /*//////////////////////////////////////////////////////////////\n ERC1155 LOGIC\n //////////////////////////////////////////////////////////////*/\n\n function setApprovalForAll(address operator, bool approved) public virtual {\n isApprovedForAll[msg.sender][operator] = approved;\n\n emit ApprovalForAll(msg.sender, operator, approved);\n }\n\n function safeTransferFrom(\n address from,\n address to,\n uint256 id,\n uint256 amount,\n bytes calldata data\n ) public virtual {\n require(msg.sender == from || isApprovedForAll[from][msg.sender], \"NOT_AUTHORIZED\");\n\n balanceOf[from][id] -= amount;\n balanceOf[to][id] += amount;\n\n emit TransferSingle(msg.sender, from, to, id, amount);\n\n require(\n to.code.length == 0\n ? to != address(0)\n : ERC1155TokenReceiverBase(to).onERC1155Received(msg.sender, from, id, amount, data) ==\n ERC1155TokenReceiverBase.onERC1155Received.selector,\n \"UNSAFE_RECIPIENT\"\n );\n }\n\n function safeBatchTransferFrom(\n address from,\n address to,\n uint256[] calldata ids,\n uint256[] calldata amounts,\n bytes calldata data\n ) public virtual {\n require(ids.length == amounts.length, \"LENGTH_MISMATCH\");\n\n require(msg.sender == from || isApprovedForAll[from][msg.sender], \"NOT_AUTHORIZED\");\n\n // Storing these outside the loop saves ~15 gas per iteration.\n uint256 id;\n uint256 amount;\n\n for (uint256 i; i < ids.length; ) {\n id = ids[i];\n amount = amounts[i];\n\n balanceOf[from][id] -= amount;\n balanceOf[to][id] += amount;\n\n // An array can't have a total length\n // larger than the max uint256 value.\n unchecked {\n ++i;\n }\n }\n\n emit TransferBatch(msg.sender, from, to, ids, amounts);\n\n require(\n to.code.length == 0\n ? to != address(0)\n : ERC1155TokenReceiverBase(to).onERC1155BatchReceived(msg.sender, from, ids, amounts, data) ==\n ERC1155TokenReceiverBase.onERC1155BatchReceived.selector,\n \"UNSAFE_RECIPIENT\"\n );\n }\n\n function balanceOfBatch(address[] calldata owners, uint256[] calldata ids)\n public\n view\n virtual\n returns (uint256[] memory balances)\n {\n require(owners.length == ids.length, \"LENGTH_MISMATCH\");\n\n balances = new uint256[](owners.length);\n\n // Unchecked because the only math done is incrementing\n // the array index counter which cannot possibly overflow.\n unchecked {\n for (uint256 i; i < owners.length; ++i) {\n balances[i] = balanceOf[owners[i]][ids[i]];\n }\n }\n }\n\n /*//////////////////////////////////////////////////////////////\n ERC165 LOGIC\n //////////////////////////////////////////////////////////////*/\n\n function supportsInterface(bytes4 interfaceId) public view virtual returns (bool) {\n return\n interfaceId == 0x01ffc9a7 || // ERC165 Interface ID for ERC165\n interfaceId == 0xd9b67a26 || // ERC165 Interface ID for ERC1155\n interfaceId == 0x0e89341c; // ERC165 Interface ID for ERC1155MetadataURI\n }\n\n /*//////////////////////////////////////////////////////////////\n INTERNAL MINT/BURN LOGIC\n //////////////////////////////////////////////////////////////*/\n\n function _mint(\n address to,\n uint256 id,\n uint256 amount,\n bytes memory data\n ) internal virtual {\n balanceOf[to][id] += amount;\n\n emit TransferSingle(msg.sender, address(0), to, id, amount);\n\n require(\n to.code.length == 0\n ? to != address(0)\n : ERC1155TokenReceiverBase(to).onERC1155Received(msg.sender, address(0), id, amount, data) ==\n ERC1155TokenReceiverBase.onERC1155Received.selector,\n \"UNSAFE_RECIPIENT\"\n );\n }\n\n function _batchMint(\n address to,\n uint256[] memory ids,\n uint256[] memory amounts,\n bytes memory data\n ) internal virtual {\n uint256 idsLength = ids.length; // Saves MLOADs.\n\n require(idsLength == amounts.length, \"LENGTH_MISMATCH\");\n\n for (uint256 i; i < idsLength; ) {\n balanceOf[to][ids[i]] += amounts[i];\n\n // An array can't have a total length\n // larger than the max uint256 value.\n unchecked {\n ++i;\n }\n }\n\n emit TransferBatch(msg.sender, address(0), to, ids, amounts);\n\n require(\n to.code.length == 0\n ? to != address(0)\n : ERC1155TokenReceiverBase(to).onERC1155BatchReceived(msg.sender, address(0), ids, amounts, data) ==\n ERC1155TokenReceiverBase.onERC1155BatchReceived.selector,\n \"UNSAFE_RECIPIENT\"\n );\n }\n\n function _batchBurn(\n address from,\n uint256[] memory ids,\n uint256[] memory amounts\n ) internal virtual {\n uint256 idsLength = ids.length; // Saves MLOADs.\n\n require(idsLength == amounts.length, \"LENGTH_MISMATCH\");\n\n for (uint256 i; i < idsLength; ) {\n balanceOf[from][ids[i]] -= amounts[i];\n\n // An array can't have a total length\n // larger than the max uint256 value.\n unchecked {\n ++i;\n }\n }\n\n emit TransferBatch(msg.sender, from, address(0), ids, amounts);\n }\n\n function _burn(\n address from,\n uint256 id,\n uint256 amount\n ) internal virtual {\n balanceOf[from][id] -= amount;\n\n emit TransferSingle(msg.sender, from, address(0), id, amount);\n }\n}\n\n/// @notice A generic interface for a contract which properly accepts ERC1155 tokens.\n/// @author Solmate (https://github.com/Rari-Capital/solmate/blob/main/src/tokens/ERC1155.sol)\nabstract contract ERC1155TokenReceiverBase {\n function onERC1155Received(\n address,\n address,\n uint256,\n uint256,\n bytes calldata\n ) external virtual returns (bytes4) {\n return ERC1155TokenReceiverBase.onERC1155Received.selector;\n }\n\n function onERC1155BatchReceived(\n address,\n address,\n uint256[] calldata,\n uint256[] calldata,\n bytes calldata\n ) external virtual returns (bytes4) {\n return ERC1155TokenReceiverBase.onERC1155BatchReceived.selector;\n }\n}\n"
},
"contracts/vendor/solmate/ERC721.sol": {
"content": "// SPDX-License-Identifier: AGPL-3.0-only\n// Based on solmate commit 1681dc505f4897ef636f0435d01b1aa027fdafaf (v6.4.0)\n// @ https://github.com/Rari-Capital/solmate/blob/1681dc505f4897ef636f0435d01b1aa027fdafaf/src/tokens/ERC1155.sol\n// Only modified to inherit IERC721 and EIP165.\npragma solidity >=0.8.0;\n\n// NOTE: Only modified to inherit IERC20 and EIP165\nimport \"../../tokens/IERC721.sol\";\nimport \"../../utils/EIP165.sol\";\n\n\n/// @notice Modern, minimalist, and gas efficient ERC-721 implementation.\n/// @author Solmate (https://github.com/Rari-Capital/solmate/blob/main/src/tokens/ERC721.sol)\nabstract contract ERC721 is IERC721, EIP165 {\n\n /*//////////////////////////////////////////////////////////////\n METADATA STORAGE/LOGIC\n //////////////////////////////////////////////////////////////*/\n\n string public name;\n\n string public symbol;\n\n function tokenURI(uint256 id) public /* view */ virtual returns (string memory);\n\n /*//////////////////////////////////////////////////////////////\n ERC721 BALANCE/OWNER STORAGE\n //////////////////////////////////////////////////////////////*/\n\n mapping(uint256 => address) internal _ownerOf;\n\n mapping(address => uint256) internal _balanceOf;\n\n function ownerOf(uint256 id) public view virtual returns (address owner) {\n require((owner = _ownerOf[id]) != address(0), \"NOT_MINTED\");\n }\n\n function balanceOf(address owner) public view virtual returns (uint256) {\n require(owner != address(0), \"ZERO_ADDRESS\");\n\n return _balanceOf[owner];\n }\n\n /*//////////////////////////////////////////////////////////////\n ERC721 APPROVAL STORAGE\n //////////////////////////////////////////////////////////////*/\n\n mapping(uint256 => address) public getApproved;\n\n mapping(address => mapping(address => bool)) public isApprovedForAll;\n\n /*//////////////////////////////////////////////////////////////\n CONSTRUCTOR\n //////////////////////////////////////////////////////////////*/\n\n constructor(string memory _name, string memory _symbol) {\n name = _name;\n symbol = _symbol;\n }\n\n /*//////////////////////////////////////////////////////////////\n ERC721 LOGIC\n //////////////////////////////////////////////////////////////*/\n\n function approve(address spender, uint256 id) public virtual {\n address owner = _ownerOf[id];\n\n require(msg.sender == owner || isApprovedForAll[owner][msg.sender], \"NOT_AUTHORIZED\");\n\n getApproved[id] = spender;\n\n emit Approval(owner, spender, id);\n }\n\n function setApprovalForAll(address operator, bool approved) public virtual {\n isApprovedForAll[msg.sender][operator] = approved;\n\n emit ApprovalForAll(msg.sender, operator, approved);\n }\n\n function transferFrom(\n address from,\n address to,\n uint256 id\n ) public virtual {\n require(from == _ownerOf[id], \"WRONG_FROM\");\n\n require(to != address(0), \"INVALID_RECIPIENT\");\n\n require(\n msg.sender == from || isApprovedForAll[from][msg.sender] || msg.sender == getApproved[id],\n \"NOT_AUTHORIZED\"\n );\n\n // Underflow of the sender's balance is impossible because we check for\n // ownership above and the recipient's balance can't realistically overflow.\n unchecked {\n _balanceOf[from]--;\n\n _balanceOf[to]++;\n }\n\n _ownerOf[id] = to;\n\n delete getApproved[id];\n\n emit Transfer(from, to, id);\n }\n\n function safeTransferFrom(\n address from,\n address to,\n uint256 id\n ) public virtual {\n transferFrom(from, to, id);\n\n require(\n to.code.length == 0 ||\n ERC721TokenReceiver(to).onERC721Received(msg.sender, from, id, \"\") ==\n ERC721TokenReceiver.onERC721Received.selector,\n \"UNSAFE_RECIPIENT\"\n );\n }\n\n function safeTransferFrom(\n address from,\n address to,\n uint256 id,\n bytes calldata data\n ) public virtual {\n transferFrom(from, to, id);\n\n require(\n to.code.length == 0 ||\n ERC721TokenReceiver(to).onERC721Received(msg.sender, from, id, data) ==\n ERC721TokenReceiver.onERC721Received.selector,\n \"UNSAFE_RECIPIENT\"\n );\n }\n\n /*//////////////////////////////////////////////////////////////\n ERC165 LOGIC\n //////////////////////////////////////////////////////////////*/\n\n function supportsInterface(bytes4 interfaceId) public pure virtual override returns (bool) {\n // NOTE: modified from original to call super.\n return super.supportsInterface(interfaceId) ||\n interfaceId == 0x80ac58cd || // ERC165 Interface ID for ERC721\n interfaceId == 0x5b5e139f; // ERC165 Interface ID for ERC721Metadata\n }\n\n /*//////////////////////////////////////////////////////////////\n INTERNAL MINT/BURN LOGIC\n //////////////////////////////////////////////////////////////*/\n\n function _mint(address to, uint256 id) internal virtual {\n require(to != address(0), \"INVALID_RECIPIENT\");\n\n require(_ownerOf[id] == address(0), \"ALREADY_MINTED\");\n\n // Counter overflow is incredibly unrealistic.\n unchecked {\n _balanceOf[to]++;\n }\n\n _ownerOf[id] = to;\n\n emit Transfer(address(0), to, id);\n }\n\n function _burn(uint256 id) internal virtual {\n address owner = _ownerOf[id];\n\n require(owner != address(0), \"NOT_MINTED\");\n\n // Ownership check above ensures no underflow.\n unchecked {\n _balanceOf[owner]--;\n }\n\n delete _ownerOf[id];\n\n delete getApproved[id];\n\n emit Transfer(owner, address(0), id);\n }\n\n /*//////////////////////////////////////////////////////////////\n INTERNAL SAFE MINT LOGIC\n //////////////////////////////////////////////////////////////*/\n\n function _safeMint(address to, uint256 id) internal virtual {\n _mint(to, id);\n\n require(\n to.code.length == 0 ||\n ERC721TokenReceiver(to).onERC721Received(msg.sender, address(0), id, \"\") ==\n ERC721TokenReceiver.onERC721Received.selector,\n \"UNSAFE_RECIPIENT\"\n );\n }\n\n function _safeMint(\n address to,\n uint256 id,\n bytes memory data\n ) internal virtual {\n _mint(to, id);\n\n require(\n to.code.length == 0 ||\n ERC721TokenReceiver(to).onERC721Received(msg.sender, address(0), id, data) ==\n ERC721TokenReceiver.onERC721Received.selector,\n \"UNSAFE_RECIPIENT\"\n );\n }\n}\n\n/// @notice A generic interface for a contract which properly accepts ERC721 tokens.\n/// @author Solmate (https://github.com/Rari-Capital/solmate/blob/main/src/tokens/ERC721.sol)\nabstract contract ERC721TokenReceiver {\n function onERC721Received(\n address,\n address,\n uint256,\n bytes calldata\n ) external virtual returns (bytes4) {\n return ERC721TokenReceiver.onERC721Received.selector;\n }\n}\n"
},
"lib/openzeppelin-contracts/contracts/interfaces/IERC2981.sol": {
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.6.0) (interfaces/IERC2981.sol)\n\npragma solidity ^0.8.0;\n\nimport \"../utils/introspection/IERC165.sol\";\n\n/**\n * @dev Interface for the NFT Royalty Standard.\n *\n * A standardized way to retrieve royalty payment information for non-fungible tokens (NFTs) to enable universal\n * support for royalty payments across all NFT marketplaces and ecosystem participants.\n *\n * _Available since v4.5._\n */\ninterface IERC2981 is IERC165 {\n /**\n * @dev Returns how much royalty is owed and to whom, based on a sale price that may be denominated in any unit of\n * exchange. The royalty amount is denominated and should be paid in that same unit of exchange.\n */\n function royaltyInfo(uint256 tokenId, uint256 salePrice)\n external\n view\n returns (address receiver, uint256 royaltyAmount);\n}\n"
},
"lib/openzeppelin-contracts/contracts/utils/introspection/IERC165.sol": {
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts v4.4.1 (utils/introspection/IERC165.sol)\n\npragma solidity ^0.8.0;\n\n/**\n * @dev Interface of the ERC165 standard, as defined in the\n * https://eips.ethereum.org/EIPS/eip-165[EIP].\n *\n * Implementers can declare support of contract interfaces, which can then be\n * queried by others ({ERC165Checker}).\n *\n * For an implementation, see {ERC165}.\n */\ninterface IERC165 {\n /**\n * @dev Returns true if this contract implements the interface defined by\n * `interfaceId`. See the corresponding\n * https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section]\n * to learn more about how these ids are created.\n *\n * This function call must use less than 30 000 gas.\n */\n function supportsInterface(bytes4 interfaceId) external view returns (bool);\n}\n"
},
"lib/solmate/src/utils/SSTORE2.sol": {
"content": "// SPDX-License-Identifier: AGPL-3.0-only\npragma solidity >=0.8.0;\n\n/// @notice Read and write to persistent storage at a fraction of the cost.\n/// @author Solmate (https://github.com/transmissions11/solmate/blob/main/src/utils/SSTORE2.sol)\n/// @author Modified from 0xSequence (https://github.com/0xSequence/sstore2/blob/master/contracts/SSTORE2.sol)\nlibrary SSTORE2 {\n uint256 internal constant DATA_OFFSET = 1; // We skip the first byte as it's a STOP opcode to ensure the contract can't be called.\n\n /*//////////////////////////////////////////////////////////////\n WRITE LOGIC\n //////////////////////////////////////////////////////////////*/\n\n function write(bytes memory data) internal returns (address pointer) {\n // Prefix the bytecode with a STOP opcode to ensure it cannot be called.\n bytes memory runtimeCode = abi.encodePacked(hex\"00\", data);\n\n bytes memory creationCode = abi.encodePacked(\n //---------------------------------------------------------------------------------------------------------------//\n // Opcode | Opcode + Arguments | Description | Stack View //\n //---------------------------------------------------------------------------------------------------------------//\n // 0x60 | 0x600B | PUSH1 11 | codeOffset //\n // 0x59 | 0x59 | MSIZE | 0 codeOffset //\n // 0x81 | 0x81 | DUP2 | codeOffset 0 codeOffset //\n // 0x38 | 0x38 | CODESIZE | codeSize codeOffset 0 codeOffset //\n // 0x03 | 0x03 | SUB | (codeSize - codeOffset) 0 codeOffset //\n // 0x80 | 0x80 | DUP | (codeSize - codeOffset) (codeSize - codeOffset) 0 codeOffset //\n // 0x92 | 0x92 | SWAP3 | codeOffset (codeSize - codeOffset) 0 (codeSize - codeOffset) //\n // 0x59 | 0x59 | MSIZE | 0 codeOffset (codeSize - codeOffset) 0 (codeSize - codeOffset) //\n // 0x39 | 0x39 | CODECOPY | 0 (codeSize - codeOffset) //\n // 0xf3 | 0xf3 | RETURN | //\n //---------------------------------------------------------------------------------------------------------------//\n hex\"60_0B_59_81_38_03_80_92_59_39_F3\", // Returns all code in the contract except for the first 11 (0B in hex) bytes.\n runtimeCode // The bytecode we want the contract to have after deployment. Capped at 1 byte less than the code size limit.\n );\n\n assembly {\n // Deploy a new contract with the generated creation code.\n // We start 32 bytes into the code to avoid copying the byte length.\n pointer := create(0, add(creationCode, 32), mload(creationCode))\n }\n\n require(pointer != address(0), \"DEPLOYMENT_FAILED\");\n }\n\n /*//////////////////////////////////////////////////////////////\n READ LOGIC\n //////////////////////////////////////////////////////////////*/\n\n function read(address pointer) internal view returns (bytes memory) {\n return readBytecode(pointer, DATA_OFFSET, pointer.code.length - DATA_OFFSET);\n }\n\n function read(address pointer, uint256 start) internal view returns (bytes memory) {\n start += DATA_OFFSET;\n\n return readBytecode(pointer, start, pointer.code.length - start);\n }\n\n function read(\n address pointer,\n uint256 start,\n uint256 end\n ) internal view returns (bytes memory) {\n start += DATA_OFFSET;\n end += DATA_OFFSET;\n\n require(pointer.code.length >= end, \"OUT_OF_BOUNDS\");\n\n return readBytecode(pointer, start, end - start);\n }\n\n /*//////////////////////////////////////////////////////////////\n INTERNAL HELPER LOGIC\n //////////////////////////////////////////////////////////////*/\n\n function readBytecode(\n address pointer,\n uint256 start,\n uint256 size\n ) private view returns (bytes memory data) {\n assembly {\n // Get a pointer to some free memory.\n data := mload(0x40)\n\n // Update the free memory pointer to prevent overriding our data.\n // We use and(x, not(31)) as a cheaper equivalent to sub(x, mod(x, 32)).\n // Adding 31 to size and running the result through the logic above ensures\n // the memory pointer remains word-aligned, following the Solidity convention.\n mstore(0x40, add(data, and(add(add(size, 32), 31), not(31))))\n\n // Store the size of the data in the first 32 byte chunk of free memory.\n mstore(data, size)\n\n // Copy the code into memory right after the 32 bytes we used to store the size.\n extcodecopy(pointer, add(data, 32), start, size)\n }\n }\n}\n"
}
},
"settings": {
"remappings": [
"ds-test/=lib/forge-std/lib/ds-test/src/",
"forge-std/=lib/forge-std/src/",
"openzeppelin/=lib/openzeppelin-contracts/",
"solmate/=lib/solmate/src/"
],
"optimizer": {
"enabled": true,
"runs": 200
},
"metadata": {
"bytecodeHash": "ipfs"
},
"outputSelection": {
"*": {
"*": [
"evm.bytecode",
"evm.deployedBytecode",
"devdoc",
"userdoc",
"metadata",
"abi"
]
}
},
"evmVersion": "london",
"libraries": {}
}
}