Overview
ETH Balance
0 ETH
Eth Value
$0.00More Info
Private Name Tags
ContractCreator
View more zero value Internal Transactions in Advanced View mode
Advanced mode:
Loading...
Loading
This contract may be a proxy contract. Click on More Options and select Is this a proxy? to confirm and enable the "Read as Proxy" & "Write as Proxy" tabs.
Contract Name:
NounsDAOData
Compiler Version
v0.8.19+commit.7dd6d404
Optimization Enabled:
Yes with 200 runs
Other Settings:
paris EvmVersion
Contract Source Code (Solidity Standard Json-Input format)
// SPDX-License-Identifier: GPL-3.0 /// @title Nouns DAO Data Contract /********************************* * ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ * * ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ * * ░░░░░░█████████░░█████████░░░ * * ░░░░░░██░░░████░░██░░░████░░░ * * ░░██████░░░████████░░░████░░░ * * ░░██░░██░░░████░░██░░░████░░░ * * ░░██░░██░░░████░░██░░░████░░░ * * ░░░░░░█████████░░█████████░░░ * * ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ * * ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ * *********************************/ pragma solidity ^0.8.19; import { OwnableUpgradeable } from '@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol'; import { NounsDAOV3Proposals } from '../NounsDAOV3Proposals.sol'; import { NounsTokenLike, NounsDAOStorageV3 } from '../NounsDAOInterfaces.sol'; import { SignatureChecker } from '../../external/openzeppelin/SignatureChecker.sol'; import { UUPSUpgradeable } from '@openzeppelin/contracts/proxy/utils/UUPSUpgradeable.sol'; import { NounsDAODataEvents } from './NounsDAODataEvents.sol'; interface INounsDAO { function proposalsV3(uint256 proposalId) external view returns (NounsDAOStorageV3.ProposalCondensed memory); } contract NounsDAOData is OwnableUpgradeable, UUPSUpgradeable, NounsDAODataEvents { /** * ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ * ERRORS * ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ */ error MustBeNounerOrPaySufficientFee(); error SlugAlreadyUsed(); error SlugDoesNotExist(); error AmountExceedsBalance(); error FailedWithdrawingETH(bytes data); error InvalidSignature(); error InvalidSupportValue(); error ProposalToUpdateMustBeUpdatable(); error OnlyProposerCanCreateUpdateCandidate(); error UpdateProposalCandidatesOnlyWorkWithProposalsBySigs(); /** * ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ * EVENTS * ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ */ /** * ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ * STATE * ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ */ /// @notice The number of blocks before the current block where account votes are counted. uint256 public constant PRIOR_VOTES_BLOCKS_AGO = 1; /// @notice The Nouns token contract. NounsTokenLike public immutable nounsToken; /// @notice The Nouns DAO contract. address public immutable nounsDao; /// @notice The cost non-Nouners must pay in ETH in order to emit a new proposal candidate event from this contract. uint256 public createCandidateCost; /// @notice The cost non-Nouners must pay in ETH in order to emit a proposal candidate update event from this contract. uint256 public updateCandidateCost; /// @notice The state of which (proposer,slug) pairs have been used to create a proposal candidate. mapping(address => mapping(bytes32 => bool)) public propCandidates; /// @notice The account to send ETH fees to. address payable public feeRecipient; constructor(address nounsToken_, address nounsDao_) initializer { nounsToken = NounsTokenLike(nounsToken_); nounsDao = nounsDao_; } /** * @notice Initialize this data availability contract. * @param admin the account that can set config state like `createCandidateCost` and `updateCandidateCost` * @param createCandidateCost_ the cost non-Nouners must pay in ETH in order to emit a new proposal candidate event from this contract. * @param updateCandidateCost_ the cost non-Nouners must pay in ETH in order to emit a proposal candidate update event from this contract. */ function initialize( address admin, uint256 createCandidateCost_, uint256 updateCandidateCost_, address payable feeRecipient_ ) external initializer { _transferOwnership(admin); createCandidateCost = createCandidateCost_; updateCandidateCost = updateCandidateCost_; feeRecipient = feeRecipient_; } /** * ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ * PUBLIC/EXTERNAL * ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ */ /** * @notice Create a new proposal candidate by emitting an event. Nouners can post for free, while non-Nouners must pay `createCandidateCost` in ETH. * When used to update a proposal created by signatures, `proposalIdToUpdate` should be the ID of the proposal to update, * and no fee is required. * Also in this case, the following conditions must be met: * 1. The proposal must be in the Updatable state. * 2. `msg.sender` must be the same as the proposer of the proposal to update. * 3. The proposal must have at least one signer. * @dev Reverts if the proposer (msg.sender) has already created a candidate with the same slug. * @param targets the candidate proposal targets. * @param values the candidate proposal values. * @param signatures the candidate proposal signatures. * @param calldatas the candidate proposal calldatas. * @param description the candidate proposal description. * @param slug the candidate proposal slug string, used alognside the proposer to uniquely identify candidates. * @param proposalIdToUpdate if this is an update to an existing proposal, the ID of the proposal to update, otherwise 0. */ function createProposalCandidate( address[] memory targets, uint256[] memory values, string[] memory signatures, bytes[] memory calldatas, string memory description, string memory slug, uint256 proposalIdToUpdate ) external payable { if (proposalIdToUpdate > 0) { INounsDAO dao = INounsDAO(nounsDao); NounsDAOStorageV3.ProposalCondensed memory propInfo = dao.proposalsV3(proposalIdToUpdate); if (block.number > propInfo.updatePeriodEndBlock) revert ProposalToUpdateMustBeUpdatable(); if (propInfo.proposer != msg.sender) revert OnlyProposerCanCreateUpdateCandidate(); if (propInfo.signers.length == 0) revert UpdateProposalCandidatesOnlyWorkWithProposalsBySigs(); } else { if (!isNouner(msg.sender) && msg.value < createCandidateCost) revert MustBeNounerOrPaySufficientFee(); } if (propCandidates[msg.sender][keccak256(bytes(slug))]) revert SlugAlreadyUsed(); NounsDAOV3Proposals.checkProposalTxs(NounsDAOV3Proposals.ProposalTxs(targets, values, signatures, calldatas)); propCandidates[msg.sender][keccak256(bytes(slug))] = true; bytes memory encodedProp = NounsDAOV3Proposals.calcProposalEncodeData( msg.sender, NounsDAOV3Proposals.ProposalTxs(targets, values, signatures, calldatas), description ); if (proposalIdToUpdate > 0) { encodedProp = abi.encodePacked(proposalIdToUpdate, encodedProp); } sendValueToRecipient(); emit ProposalCandidateCreated( msg.sender, targets, values, signatures, calldatas, description, slug, proposalIdToUpdate, keccak256(encodedProp) ); } /** * @notice Update a proposal candidate by emitting an event. Nouners can update for free, while non-Nouners must pay `updateCandidateCost` in ETH. * @dev Reverts if the proposer (msg.sender) has not already created a candidate with the same slug. * @param targets the candidate proposal targets. * @param values the candidate proposal values. * @param signatures the candidate proposal signatures. * @param calldatas the candidate proposal calldatas. * @param description the candidate proposal description. * @param slug the candidate proposal slug string, used alognside the proposer to uniquely identify candidates. * @param proposalIdToUpdate if this is an update to an existing proposal, the ID of the proposal to update, otherwise 0. * @param reason the free text reason and context for the update. */ function updateProposalCandidate( address[] memory targets, uint256[] memory values, string[] memory signatures, bytes[] memory calldatas, string memory description, string memory slug, uint256 proposalIdToUpdate, string memory reason ) external payable { if (!isNouner(msg.sender) && msg.value < updateCandidateCost) revert MustBeNounerOrPaySufficientFee(); if (!propCandidates[msg.sender][keccak256(bytes(slug))]) revert SlugDoesNotExist(); NounsDAOV3Proposals.checkProposalTxs(NounsDAOV3Proposals.ProposalTxs(targets, values, signatures, calldatas)); bytes memory encodedProp = NounsDAOV3Proposals.calcProposalEncodeData( msg.sender, NounsDAOV3Proposals.ProposalTxs(targets, values, signatures, calldatas), description ); if (proposalIdToUpdate > 0) { encodedProp = abi.encodePacked(proposalIdToUpdate, encodedProp); } sendValueToRecipient(); emit ProposalCandidateUpdated( msg.sender, targets, values, signatures, calldatas, description, slug, proposalIdToUpdate, keccak256(encodedProp), reason ); } /** * @notice Cancel a proposal candidate by emitting an event. * @dev Reverts if the proposer (msg.sender) has not already created a candidate with the same slug. * @param slug the candidate proposal slug string, used alognside the proposer to uniquely identify candidates. */ function cancelProposalCandidate(string memory slug) external { if (!propCandidates[msg.sender][keccak256(bytes(slug))]) revert SlugDoesNotExist(); emit ProposalCandidateCanceled(msg.sender, slug); } /** * @notice Add a signature supporting a new candidate to be proposed to the DAO using `proposeBySigs`, by emitting an event with the signature data. * Only lets the signer account submit their signature, to minimize potential spam. * @param sig the signature bytes. * @param expirationTimestamp the signature's expiration timestamp. * @param proposer the proposer account that posted the candidate proposal with the provided slug. * @param slug the slug of the proposal candidate signer signed on. * @param proposalIdToUpdate if this is an update to an existing proposal, the ID of the proposal to update, otherwise 0. * @param encodedProp the abi encoding of the candidate version signed; should be identical to the output of * the `NounsDAOV3Proposals.calcProposalEncodeData` function. * @param reason signer's reason free text. */ function addSignature( bytes memory sig, uint256 expirationTimestamp, address proposer, string memory slug, uint256 proposalIdToUpdate, bytes memory encodedProp, string memory reason ) external { if (!propCandidates[proposer][keccak256(bytes(slug))]) revert SlugDoesNotExist(); bytes32 typeHash = proposalIdToUpdate == 0 ? NounsDAOV3Proposals.PROPOSAL_TYPEHASH : NounsDAOV3Proposals.UPDATE_PROPOSAL_TYPEHASH; bytes32 sigDigest = NounsDAOV3Proposals.sigDigest(typeHash, encodedProp, expirationTimestamp, nounsDao); if (!SignatureChecker.isValidSignatureNow(msg.sender, sigDigest, sig)) revert InvalidSignature(); emit SignatureAdded( msg.sender, sig, expirationTimestamp, proposer, slug, proposalIdToUpdate, keccak256(encodedProp), sigDigest, reason ); } /** * @notice Send feedback on a proposal. Meant to be used during a proposal's Updatable period, to help proposers receive * valuable feedback and update their proposal in time. * @param proposalId the ID of the proposal. * @param support msg.sender's vote-like feedback: 0 is against, 1 is for, 2 is abstain. * @param reason their free text feedback. */ function sendFeedback( uint256 proposalId, uint8 support, string memory reason ) external { if (support > 2) revert InvalidSupportValue(); emit FeedbackSent(msg.sender, proposalId, support, reason); } /** * @notice Send feedback on a proposal candidate. Meant to be used prior to submitting the candidate as a proposal, * to help proposers refine their candidate. * @param proposer the proposer of the candidate. * @param slug the slug of the candidate. * @param support msg.sender's vote-like feedback: 0 is against, 1 is for, 2 is abstain. * @param reason their free text feedback. */ function sendCandidateFeedback( address proposer, string memory slug, uint8 support, string memory reason ) external { if (!propCandidates[proposer][keccak256(bytes(slug))]) revert SlugDoesNotExist(); if (support > 2) revert InvalidSupportValue(); emit CandidateFeedbackSent(msg.sender, proposer, slug, support, reason); } /** * ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ * ADMIN (OWNER) FUNCTIONS * ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ */ function setCreateCandidateCost(uint256 newCreateCandidateCost) external onlyOwner { uint256 oldCreateCandidateCost = createCandidateCost; createCandidateCost = newCreateCandidateCost; emit CreateCandidateCostSet(oldCreateCandidateCost, newCreateCandidateCost); } function setUpdateCandidateCost(uint256 newUpdateCandidateCost) external onlyOwner { uint256 oldUpdateCandidateCost = updateCandidateCost; updateCandidateCost = newUpdateCandidateCost; emit UpdateCandidateCostSet(oldUpdateCandidateCost, newUpdateCandidateCost); } function setFeeRecipient(address payable newFeeRecipient) external onlyOwner { address oldFeeRecipient = feeRecipient; feeRecipient = newFeeRecipient; emit FeeRecipientSet(oldFeeRecipient, newFeeRecipient); } /** * @notice Withdraw ETH from this contract's balance. Only owner can call this function. * @param to the recipient. * @param amount the ETH amount to send. */ function withdrawETH(address to, uint256 amount) external onlyOwner { if (amount > address(this).balance) revert AmountExceedsBalance(); (bool sent, bytes memory data) = to.call{ value: amount }(''); if (!sent) { revert FailedWithdrawingETH(data); } emit ETHWithdrawn(to, amount); } /** * ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ * INTERNAL * ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ */ function sendValueToRecipient() internal { address feeRecipient_ = feeRecipient; if (msg.value > 0 && feeRecipient_ != address(0)) { // choosing to not revert upon failure here because owner can always use // the withdraw function instead. feeRecipient_.call{ value: msg.value }(''); } } function isNouner(address account) internal view returns (bool) { return nounsToken.getPriorVotes(account, block.number - PRIOR_VOTES_BLOCKS_AGO) > 0; } /** * @dev Function that should revert when `msg.sender` is not authorized to upgrade the contract. Called by * {upgradeTo} and {upgradeToAndCall}. * * Normally, this function will use an xref:access.adoc[access control] modifier such as {Ownable-onlyOwner}. * * ```solidity * function _authorizeUpgrade(address) internal override onlyOwner {} * ``` */ function _authorizeUpgrade(address) internal view override onlyOwner {} }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.0 (access/Ownable.sol) pragma solidity ^0.8.0; import "../utils/ContextUpgradeable.sol"; import "../proxy/utils/Initializable.sol"; /** * @dev Contract module which provides a basic access control mechanism, where * there is an account (an owner) that can be granted exclusive access to * specific functions. * * By default, the owner account will be the one that deploys the contract. This * can later be changed with {transferOwnership}. * * This module is used through inheritance. It will make available the modifier * `onlyOwner`, which can be applied to your functions to restrict their use to * the owner. */ abstract contract OwnableUpgradeable is Initializable, ContextUpgradeable { address private _owner; event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); /** * @dev Initializes the contract setting the deployer as the initial owner. */ function __Ownable_init() internal initializer { __Context_init_unchained(); __Ownable_init_unchained(); } function __Ownable_init_unchained() internal initializer { _transferOwnership(_msgSender()); } /** * @dev Returns the address of the current owner. */ function owner() public view virtual returns (address) { return _owner; } /** * @dev Throws if called by any account other than the owner. */ modifier onlyOwner() { require(owner() == _msgSender(), "Ownable: caller is not the owner"); _; } /** * @dev Leaves the contract without owner. It will not be possible to call * `onlyOwner` functions anymore. Can only be called by the current owner. * * NOTE: Renouncing ownership will leave the contract without an owner, * thereby removing any functionality that is only available to the owner. */ function renounceOwnership() public virtual onlyOwner { _transferOwnership(address(0)); } /** * @dev Transfers ownership of the contract to a new account (`newOwner`). * Can only be called by the current owner. */ function transferOwnership(address newOwner) public virtual onlyOwner { require(newOwner != address(0), "Ownable: new owner is the zero address"); _transferOwnership(newOwner); } /** * @dev Transfers ownership of the contract to a new account (`newOwner`). * Internal function without access restriction. */ function _transferOwnership(address newOwner) internal virtual { address oldOwner = _owner; _owner = newOwner; emit OwnershipTransferred(oldOwner, newOwner); } uint256[49] private __gap; }
// SPDX-License-Identifier: GPL-3.0 /// @title Library for NounsDAOLogicV3 contract containing the proposal lifecycle code /********************************* * ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ * * ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ * * ░░░░░░█████████░░█████████░░░ * * ░░░░░░██░░░████░░██░░░████░░░ * * ░░██████░░░████████░░░████░░░ * * ░░██░░██░░░████░░██░░░████░░░ * * ░░██░░██░░░████░░██░░░████░░░ * * ░░░░░░█████████░░█████████░░░ * * ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ * * ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ * *********************************/ pragma solidity ^0.8.19; import './NounsDAOInterfaces.sol'; import { NounsDAOV3DynamicQuorum } from './NounsDAOV3DynamicQuorum.sol'; import { NounsDAOV3Fork } from './fork/NounsDAOV3Fork.sol'; import { SignatureChecker } from '../external/openzeppelin/SignatureChecker.sol'; import { ECDSA } from '../external/openzeppelin/ECDSA.sol'; import { SafeCast } from '@openzeppelin/contracts/utils/math/SafeCast.sol'; library NounsDAOV3Proposals { using NounsDAOV3DynamicQuorum for NounsDAOStorageV3.StorageV3; using NounsDAOV3Fork for NounsDAOStorageV3.StorageV3; error CantCancelProposalAtFinalState(); error ProposalInfoArityMismatch(); error MustProvideActions(); error TooManyActions(); error ProposerAlreadyHasALiveProposal(); error InvalidSignature(); error SignatureExpired(); error CanOnlyEditUpdatableProposals(); error OnlyProposerCanEdit(); error SignerCountMismtach(); error ProposerCannotUpdateProposalWithSigners(); error MustProvideSignatures(); error SignatureIsCancelled(); error CannotExecuteDuringForkingPeriod(); error VetoerBurned(); error VetoerOnly(); error CantVetoExecutedProposal(); error VotesBelowProposalThreshold(); /// @notice An event emitted when a proposal has been vetoed by vetoAddress event ProposalVetoed(uint256 id); /// @notice An event emitted when a new proposal is created event ProposalCreated( uint256 id, address proposer, address[] targets, uint256[] values, string[] signatures, bytes[] calldatas, uint256 startBlock, uint256 endBlock, string description ); /// @notice An event emitted when a new proposal is created, which includes additional information /// @dev V3 adds `signers`, `updatePeriodEndBlock` compared to the V1/V2 event. event ProposalCreatedWithRequirements( uint256 id, address proposer, address[] signers, address[] targets, uint256[] values, string[] signatures, bytes[] calldatas, uint256 startBlock, uint256 endBlock, uint256 updatePeriodEndBlock, uint256 proposalThreshold, uint256 quorumVotes, string description ); /// @notice Emitted when a proposal is created to be executed on timelockV1 event ProposalCreatedOnTimelockV1(uint256 id); /// @notice Emitted when a proposal is updated event ProposalUpdated( uint256 indexed id, address indexed proposer, address[] targets, uint256[] values, string[] signatures, bytes[] calldatas, string description, string updateMessage ); /// @notice Emitted when a proposal's transactions are updated event ProposalTransactionsUpdated( uint256 indexed id, address indexed proposer, address[] targets, uint256[] values, string[] signatures, bytes[] calldatas, string updateMessage ); /// @notice Emitted when a proposal's description is updated event ProposalDescriptionUpdated( uint256 indexed id, address indexed proposer, string description, string updateMessage ); /// @notice An event emitted when a proposal has been queued in the NounsDAOExecutor event ProposalQueued(uint256 id, uint256 eta); /// @notice An event emitted when a proposal has been executed in the NounsDAOExecutor event ProposalExecuted(uint256 id); /// @notice An event emitted when a proposal has been canceled event ProposalCanceled(uint256 id); /// @notice Emitted when someone cancels a signature event SignatureCancelled(address indexed signer, bytes sig); // Created to solve stack-too-deep errors struct ProposalTxs { address[] targets; uint256[] values; string[] signatures; bytes[] calldatas; } /// @notice The maximum number of actions that can be included in a proposal uint256 public constant PROPOSAL_MAX_OPERATIONS = 10; // 10 actions bytes32 public constant DOMAIN_TYPEHASH = keccak256('EIP712Domain(string name,uint256 chainId,address verifyingContract)'); bytes32 public constant PROPOSAL_TYPEHASH = keccak256( 'Proposal(address proposer,address[] targets,uint256[] values,string[] signatures,bytes[] calldatas,string description,uint256 expiry)' ); bytes32 public constant UPDATE_PROPOSAL_TYPEHASH = keccak256( 'UpdateProposal(uint256 proposalId,address proposer,address[] targets,uint256[] values,string[] signatures,bytes[] calldatas,string description,uint256 expiry)' ); /** * @notice Function used to propose a new proposal. Sender must have delegates above the proposal threshold * @param txs Target addresses, eth values, function signatures and calldatas for proposal calls * @param description String description of the proposal * @return Proposal id of new proposal */ function propose( NounsDAOStorageV3.StorageV3 storage ds, ProposalTxs memory txs, string memory description ) internal returns (uint256) { uint256 adjustedTotalSupply = ds.adjustedTotalSupply(); uint256 proposalThreshold_ = checkPropThreshold( ds, ds.nouns.getPriorVotes(msg.sender, block.number - 1), adjustedTotalSupply ); checkProposalTxs(txs); checkNoActiveProp(ds, msg.sender); uint256 proposalId = ds.proposalCount = ds.proposalCount + 1; NounsDAOStorageV3.Proposal storage newProposal = createNewProposal( ds, proposalId, proposalThreshold_, adjustedTotalSupply, txs ); ds.latestProposalIds[msg.sender] = proposalId; emitNewPropEvents(newProposal, new address[](0), ds.minQuorumVotes(adjustedTotalSupply), txs, description); return proposalId; } /** * @notice Function used to propose a new proposal. Sender must have delegates above the proposal threshold. * This proposal would be executed via the timelockV1 contract. This is meant to be used in case timelockV1 * is still holding funds or has special permissions to execute on certain contracts. * @param txs Target addresses, eth values, function signatures and calldatas for proposal calls * @param description String description of the proposal * @return uint256 Proposal id of new proposal */ function proposeOnTimelockV1( NounsDAOStorageV3.StorageV3 storage ds, ProposalTxs memory txs, string memory description ) internal returns (uint256) { uint256 newProposalId = propose(ds, txs, description); NounsDAOStorageV3.Proposal storage newProposal = ds._proposals[newProposalId]; newProposal.executeOnTimelockV1 = true; emit ProposalCreatedOnTimelockV1(newProposalId); return newProposalId; } /** * @notice Function used to propose a new proposal. Sender and signers must have delegates above the proposal threshold * @param proposerSignatures Array of signers who have signed the proposal and their signatures. * @dev The signatures follow EIP-712. See `PROPOSAL_TYPEHASH` in NounsDAOV3Proposals.sol * @param txs Target addresses, eth values, function signatures and calldatas for proposal calls * @param description String description of the proposal * @return uint256 Proposal id of new proposal */ function proposeBySigs( NounsDAOStorageV3.StorageV3 storage ds, NounsDAOStorageV3.ProposerSignature[] memory proposerSignatures, ProposalTxs memory txs, string memory description ) external returns (uint256) { if (proposerSignatures.length == 0) revert MustProvideSignatures(); checkProposalTxs(txs); uint256 proposalId = ds.proposalCount = ds.proposalCount + 1; uint256 adjustedTotalSupply = ds.adjustedTotalSupply(); uint256 propThreshold = proposalThreshold(ds, adjustedTotalSupply); NounsDAOStorageV3.Proposal storage newProposal = createNewProposal( ds, proposalId, propThreshold, adjustedTotalSupply, txs ); // important that the proposal is created before the verification call in order to ensure // the same signer is not trying to sign this proposal more than once (uint256 votes, address[] memory signers) = verifySignersCanBackThisProposalAndCountTheirVotes( ds, proposerSignatures, txs, description, proposalId ); if (signers.length == 0) revert MustProvideSignatures(); if (votes <= propThreshold) revert VotesBelowProposalThreshold(); newProposal.signers = signers; emitNewPropEvents(newProposal, signers, ds.minQuorumVotes(adjustedTotalSupply), txs, description); return proposalId; } /** * @notice Invalidates a signature that may be used for signing a proposal. * Once a signature is canceled, the sender can no longer use it again. * If the sender changes their mind and want to sign the proposal, they can change the expiry timestamp * in order to produce a new signature. * The signature will only be invalidated when used by the sender. If used by a different account, it will * not be invalidated. * @param sig The signature to cancel */ function cancelSig(NounsDAOStorageV3.StorageV3 storage ds, bytes calldata sig) external { bytes32 sigHash = keccak256(sig); ds.cancelledSigs[msg.sender][sigHash] = true; emit SignatureCancelled(msg.sender, sig); } /** * @notice Update a proposal transactions and description. * Only the proposer can update it, and only during the updateable period. * @param proposalId Proposal's id * @param targets Updated target addresses for proposal calls * @param values Updated eth values for proposal calls * @param signatures Updated function signatures for proposal calls * @param calldatas Updated calldatas for proposal calls * @param description Updated description of the proposal * @param updateMessage Short message to explain the update */ function updateProposal( NounsDAOStorageV3.StorageV3 storage ds, uint256 proposalId, address[] memory targets, uint256[] memory values, string[] memory signatures, bytes[] memory calldatas, string memory description, string memory updateMessage ) external { updateProposalTransactionsInternal(ds, proposalId, targets, values, signatures, calldatas); emit ProposalUpdated( proposalId, msg.sender, targets, values, signatures, calldatas, description, updateMessage ); } /** * @notice Updates the proposal's transactions. Only the proposer can update it, and only during the updateable period. * @param proposalId Proposal's id * @param targets Updated target addresses for proposal calls * @param values Updated eth values for proposal calls * @param signatures Updated function signatures for proposal calls * @param calldatas Updated calldatas for proposal calls * @param updateMessage Short message to explain the update */ function updateProposalTransactions( NounsDAOStorageV3.StorageV3 storage ds, uint256 proposalId, address[] memory targets, uint256[] memory values, string[] memory signatures, bytes[] memory calldatas, string memory updateMessage ) external { updateProposalTransactionsInternal(ds, proposalId, targets, values, signatures, calldatas); emit ProposalTransactionsUpdated(proposalId, msg.sender, targets, values, signatures, calldatas, updateMessage); } function updateProposalTransactionsInternal( NounsDAOStorageV3.StorageV3 storage ds, uint256 proposalId, address[] memory targets, uint256[] memory values, string[] memory signatures, bytes[] memory calldatas ) internal { checkProposalTxs(ProposalTxs(targets, values, signatures, calldatas)); NounsDAOStorageV3.Proposal storage proposal = ds._proposals[proposalId]; checkProposalUpdatable(ds, proposalId, proposal); proposal.targets = targets; proposal.values = values; proposal.signatures = signatures; proposal.calldatas = calldatas; } /** * @notice Updates the proposal's description. Only the proposer can update it, and only during the updateable period. * @param proposalId Proposal's id * @param description Updated description of the proposal * @param updateMessage Short message to explain the update */ function updateProposalDescription( NounsDAOStorageV3.StorageV3 storage ds, uint256 proposalId, string calldata description, string calldata updateMessage ) external { NounsDAOStorageV3.Proposal storage proposal = ds._proposals[proposalId]; checkProposalUpdatable(ds, proposalId, proposal); emit ProposalDescriptionUpdated(proposalId, msg.sender, description, updateMessage); } /** * @notice Update a proposal's transactions and description that was created with proposeBySigs. * Only the proposer can update it, during the updateable period. * Requires the original signers to sign the update. * @param proposalId Proposal's id * @param proposerSignatures Array of signers who have signed the proposal and their signatures. * @dev The signatures follow EIP-712. See `UPDATE_PROPOSAL_TYPEHASH` in NounsDAOV3Proposals.sol * @param txs Updated transactions for the proposal * @param description Updated description of the proposal * @param updateMessage Short message to explain the update */ function updateProposalBySigs( NounsDAOStorageV3.StorageV3 storage ds, uint256 proposalId, NounsDAOStorageV3.ProposerSignature[] memory proposerSignatures, ProposalTxs memory txs, string memory description, string memory updateMessage ) external { checkProposalTxs(txs); // without this check it's possible to run through this function and update a proposal without signatures // this problem doesn't exist in the propose function because we check for prop threshold there if (proposerSignatures.length == 0) revert MustProvideSignatures(); NounsDAOStorageV3.Proposal storage proposal = ds._proposals[proposalId]; if (stateInternal(ds, proposalId) != NounsDAOStorageV3.ProposalState.Updatable) revert CanOnlyEditUpdatableProposals(); if (msg.sender != proposal.proposer) revert OnlyProposerCanEdit(); address[] memory signers = proposal.signers; if (proposerSignatures.length != signers.length) revert SignerCountMismtach(); bytes memory proposalEncodeData = abi.encodePacked( proposalId, calcProposalEncodeData(msg.sender, txs, description) ); for (uint256 i = 0; i < proposerSignatures.length; ++i) { verifyProposalSignature(ds, proposalEncodeData, proposerSignatures[i], UPDATE_PROPOSAL_TYPEHASH); // To avoid the gas cost of having to search signers in proposal.signers, we're assuming the sigs we get // use the same amount of signers and the same order. if (signers[i] != proposerSignatures[i].signer) revert OnlyProposerCanEdit(); } proposal.targets = txs.targets; proposal.values = txs.values; proposal.signatures = txs.signatures; proposal.calldatas = txs.calldatas; emit ProposalUpdated( proposalId, msg.sender, txs.targets, txs.values, txs.signatures, txs.calldatas, description, updateMessage ); } /** * @notice Queues a proposal of state succeeded * @param proposalId The id of the proposal to queue */ function queue(NounsDAOStorageV3.StorageV3 storage ds, uint256 proposalId) external { require( stateInternal(ds, proposalId) == NounsDAOStorageV3.ProposalState.Succeeded, 'NounsDAO::queue: proposal can only be queued if it is succeeded' ); NounsDAOStorageV3.Proposal storage proposal = ds._proposals[proposalId]; INounsDAOExecutor timelock = getProposalTimelock(ds, proposal); uint256 eta = block.timestamp + timelock.delay(); for (uint256 i = 0; i < proposal.targets.length; i++) { queueOrRevertInternal( timelock, proposal.targets[i], proposal.values[i], proposal.signatures[i], proposal.calldatas[i], eta ); } proposal.eta = eta; emit ProposalQueued(proposalId, eta); } function queueOrRevertInternal( INounsDAOExecutor timelock, address target, uint256 value, string memory signature, bytes memory data, uint256 eta ) internal { require( !timelock.queuedTransactions(keccak256(abi.encode(target, value, signature, data, eta))), 'NounsDAO::queueOrRevertInternal: identical proposal action already queued at eta' ); timelock.queueTransaction(target, value, signature, data, eta); } /** * @notice Executes a queued proposal if eta has passed * @param proposalId The id of the proposal to execute */ function execute(NounsDAOStorageV3.StorageV3 storage ds, uint256 proposalId) external { NounsDAOStorageV3.Proposal storage proposal = ds._proposals[proposalId]; INounsDAOExecutor timelock = getProposalTimelock(ds, proposal); executeInternal(ds, proposal, timelock); } /** * @notice Executes a queued proposal on timelockV1 if eta has passed * This is only required for proposal that were queued on timelockV1, but before the upgrade to DAO V3. * These proposals will not have the `executeOnTimelockV1` bool turned on. */ function executeOnTimelockV1(NounsDAOStorageV3.StorageV3 storage ds, uint256 proposalId) external { NounsDAOStorageV3.Proposal storage proposal = ds._proposals[proposalId]; executeInternal(ds, proposal, ds.timelockV1); } function executeInternal( NounsDAOStorageV3.StorageV3 storage ds, NounsDAOStorageV3.Proposal storage proposal, INounsDAOExecutor timelock ) internal { require( stateInternal(ds, proposal.id) == NounsDAOStorageV3.ProposalState.Queued, 'NounsDAO::execute: proposal can only be executed if it is queued' ); if (ds.isForkPeriodActive()) revert CannotExecuteDuringForkingPeriod(); proposal.executed = true; for (uint256 i = 0; i < proposal.targets.length; i++) { timelock.executeTransaction( proposal.targets[i], proposal.values[i], proposal.signatures[i], proposal.calldatas[i], proposal.eta ); } emit ProposalExecuted(proposal.id); } function getProposalTimelock(NounsDAOStorageV3.StorageV3 storage ds, NounsDAOStorageV3.Proposal storage proposal) internal view returns (INounsDAOExecutor) { if (proposal.executeOnTimelockV1) { return ds.timelockV1; } else { return ds.timelock; } } /** * @notice Vetoes a proposal only if sender is the vetoer and the proposal has not been executed. * @param proposalId The id of the proposal to veto */ function veto(NounsDAOStorageV3.StorageV3 storage ds, uint256 proposalId) external { if (ds.vetoer == address(0)) { revert VetoerBurned(); } if (msg.sender != ds.vetoer) { revert VetoerOnly(); } if (stateInternal(ds, proposalId) == NounsDAOStorageV3.ProposalState.Executed) { revert CantVetoExecutedProposal(); } NounsDAOStorageV3.Proposal storage proposal = ds._proposals[proposalId]; proposal.vetoed = true; INounsDAOExecutor timelock = getProposalTimelock(ds, proposal); for (uint256 i = 0; i < proposal.targets.length; i++) { timelock.cancelTransaction( proposal.targets[i], proposal.values[i], proposal.signatures[i], proposal.calldatas[i], proposal.eta ); } emit ProposalVetoed(proposalId); } /** * @notice Cancels a proposal only if sender is the proposer or a signer, or proposer & signers voting power * dropped below proposal threshold * @param proposalId The id of the proposal to cancel */ function cancel(NounsDAOStorageV3.StorageV3 storage ds, uint256 proposalId) external { NounsDAOStorageV3.ProposalState proposalState = stateInternal(ds, proposalId); if ( proposalState == NounsDAOStorageV3.ProposalState.Canceled || proposalState == NounsDAOStorageV3.ProposalState.Defeated || proposalState == NounsDAOStorageV3.ProposalState.Expired || proposalState == NounsDAOStorageV3.ProposalState.Executed || proposalState == NounsDAOStorageV3.ProposalState.Vetoed ) { revert CantCancelProposalAtFinalState(); } NounsDAOStorageV3.Proposal storage proposal = ds._proposals[proposalId]; address proposer = proposal.proposer; NounsTokenLike nouns = ds.nouns; uint256 votes = nouns.getPriorVotes(proposer, block.number - 1); bool msgSenderIsProposer = proposer == msg.sender; address[] memory signers = proposal.signers; for (uint256 i = 0; i < signers.length; ++i) { msgSenderIsProposer = msgSenderIsProposer || msg.sender == signers[i]; votes += nouns.getPriorVotes(signers[i], block.number - 1); } require( msgSenderIsProposer || votes <= proposal.proposalThreshold, 'NounsDAO::cancel: proposer above threshold' ); proposal.canceled = true; INounsDAOExecutor timelock = getProposalTimelock(ds, proposal); for (uint256 i = 0; i < proposal.targets.length; i++) { timelock.cancelTransaction( proposal.targets[i], proposal.values[i], proposal.signatures[i], proposal.calldatas[i], proposal.eta ); } emit ProposalCanceled(proposalId); } /** * @notice Gets the state of a proposal * @param ds the DAO's state struct * @param proposalId The id of the proposal * @return Proposal state */ function state(NounsDAOStorageV3.StorageV3 storage ds, uint256 proposalId) public view returns (NounsDAOStorageV3.ProposalState) { return stateInternal(ds, proposalId); } /** * @notice Gets the state of a proposal * @dev This internal function is used by other libraries to embed in compile time and save the runtime gas cost of a delegate call * @param ds the DAO's state struct * @param proposalId The id of the proposal * @return Proposal state */ function stateInternal(NounsDAOStorageV3.StorageV3 storage ds, uint256 proposalId) internal view returns (NounsDAOStorageV3.ProposalState) { require(ds.proposalCount >= proposalId, 'NounsDAO::state: invalid proposal id'); NounsDAOStorageV3.Proposal storage proposal = ds._proposals[proposalId]; if (proposal.vetoed) { return NounsDAOStorageV3.ProposalState.Vetoed; } else if (proposal.canceled) { return NounsDAOStorageV3.ProposalState.Canceled; } else if (block.number <= proposal.updatePeriodEndBlock) { return NounsDAOStorageV3.ProposalState.Updatable; } else if (block.number <= proposal.startBlock) { return NounsDAOStorageV3.ProposalState.Pending; } else if (block.number <= proposal.endBlock) { return NounsDAOStorageV3.ProposalState.Active; } else if (block.number <= proposal.objectionPeriodEndBlock) { return NounsDAOStorageV3.ProposalState.ObjectionPeriod; } else if (isDefeated(ds, proposal)) { return NounsDAOStorageV3.ProposalState.Defeated; } else if (proposal.eta == 0) { return NounsDAOStorageV3.ProposalState.Succeeded; } else if (proposal.executed) { return NounsDAOStorageV3.ProposalState.Executed; } else if (block.timestamp >= proposal.eta + getProposalTimelock(ds, proposal).GRACE_PERIOD()) { return NounsDAOStorageV3.ProposalState.Expired; } else { return NounsDAOStorageV3.ProposalState.Queued; } } /** * @notice Gets actions of a proposal * @param proposalId the id of the proposal * @return targets * @return values * @return signatures * @return calldatas */ function getActions(NounsDAOStorageV3.StorageV3 storage ds, uint256 proposalId) internal view returns ( address[] memory targets, uint256[] memory values, string[] memory signatures, bytes[] memory calldatas ) { NounsDAOStorageV3.Proposal storage p = ds._proposals[proposalId]; return (p.targets, p.values, p.signatures, p.calldatas); } /** * @notice Gets the receipt for a voter on a given proposal * @param proposalId the id of proposal * @param voter The address of the voter * @return The voting receipt */ function getReceipt( NounsDAOStorageV3.StorageV3 storage ds, uint256 proposalId, address voter ) internal view returns (NounsDAOStorageV3.Receipt memory) { return ds._proposals[proposalId].receipts[voter]; } /** * @notice Returns the proposal details given a proposal id. * The `quorumVotes` member holds the *current* quorum, given the current votes. * @param proposalId the proposal id to get the data for * @return A `ProposalCondensed` struct with the proposal data */ function proposals(NounsDAOStorageV3.StorageV3 storage ds, uint256 proposalId) external view returns (NounsDAOStorageV2.ProposalCondensed memory) { NounsDAOStorageV3.Proposal storage proposal = ds._proposals[proposalId]; return NounsDAOStorageV2.ProposalCondensed({ id: proposal.id, proposer: proposal.proposer, proposalThreshold: proposal.proposalThreshold, quorumVotes: ds.quorumVotes(proposal.id), eta: proposal.eta, startBlock: proposal.startBlock, endBlock: proposal.endBlock, forVotes: proposal.forVotes, againstVotes: proposal.againstVotes, abstainVotes: proposal.abstainVotes, canceled: proposal.canceled, vetoed: proposal.vetoed, executed: proposal.executed, totalSupply: proposal.totalSupply, creationBlock: proposal.creationBlock }); } /** * @notice Returns the proposal details given a proposal id. * The `quorumVotes` member holds the *current* quorum, given the current votes. * @param proposalId the proposal id to get the data for * @return A `ProposalCondensed` struct with the proposal data */ function proposalsV3(NounsDAOStorageV3.StorageV3 storage ds, uint256 proposalId) external view returns (NounsDAOStorageV3.ProposalCondensed memory) { NounsDAOStorageV3.Proposal storage proposal = ds._proposals[proposalId]; return NounsDAOStorageV3.ProposalCondensed({ id: proposal.id, proposer: proposal.proposer, proposalThreshold: proposal.proposalThreshold, quorumVotes: ds.quorumVotes(proposal.id), eta: proposal.eta, startBlock: proposal.startBlock, endBlock: proposal.endBlock, forVotes: proposal.forVotes, againstVotes: proposal.againstVotes, abstainVotes: proposal.abstainVotes, canceled: proposal.canceled, vetoed: proposal.vetoed, executed: proposal.executed, totalSupply: proposal.totalSupply, creationBlock: proposal.creationBlock, signers: proposal.signers, updatePeriodEndBlock: proposal.updatePeriodEndBlock, objectionPeriodEndBlock: proposal.objectionPeriodEndBlock, executeOnTimelockV1: proposal.executeOnTimelockV1 }); } /** * @notice Current proposal threshold using Noun Total Supply * Differs from `GovernerBravo` which uses fixed amount */ function proposalThreshold(NounsDAOStorageV3.StorageV3 storage ds, uint256 adjustedTotalSupply) internal view returns (uint256) { return bps2Uint(ds.proposalThresholdBPS, adjustedTotalSupply); } function isDefeated(NounsDAOStorageV3.StorageV3 storage ds, NounsDAOStorageV3.Proposal storage proposal) internal view returns (bool) { uint256 forVotes = proposal.forVotes; return forVotes <= proposal.againstVotes || forVotes < ds.quorumVotes(proposal.id); } /** * @notice reverts if `proposer` is the proposer or signer of an active proposal. * This is a spam protection mechanism to limit the number of proposals each noun can back. */ function checkNoActiveProp(NounsDAOStorageV3.StorageV3 storage ds, address proposer) internal view { uint256 latestProposalId = ds.latestProposalIds[proposer]; if (latestProposalId != 0) { NounsDAOStorageV3.ProposalState proposersLatestProposalState = stateInternal(ds, latestProposalId); if ( proposersLatestProposalState == NounsDAOStorageV3.ProposalState.ObjectionPeriod || proposersLatestProposalState == NounsDAOStorageV3.ProposalState.Active || proposersLatestProposalState == NounsDAOStorageV3.ProposalState.Pending || proposersLatestProposalState == NounsDAOStorageV3.ProposalState.Updatable ) revert ProposerAlreadyHasALiveProposal(); } } /** * @dev Extracted this function to fix the `Stack too deep` error `proposeBySigs` hit. */ function verifySignersCanBackThisProposalAndCountTheirVotes( NounsDAOStorageV3.StorageV3 storage ds, NounsDAOStorageV3.ProposerSignature[] memory proposerSignatures, ProposalTxs memory txs, string memory description, uint256 proposalId ) internal returns (uint256 votes, address[] memory signers) { NounsTokenLike nouns = ds.nouns; bytes memory proposalEncodeData = calcProposalEncodeData(msg.sender, txs, description); signers = new address[](proposerSignatures.length); uint256 numSigners = 0; for (uint256 i = 0; i < proposerSignatures.length; ++i) { verifyProposalSignature(ds, proposalEncodeData, proposerSignatures[i], PROPOSAL_TYPEHASH); address signer = proposerSignatures[i].signer; checkNoActiveProp(ds, signer); uint256 signerVotes = nouns.getPriorVotes(signer, block.number - 1); if (signerVotes == 0) { continue; } signers[numSigners++] = signer; ds.latestProposalIds[signer] = proposalId; votes += signerVotes; } if (numSigners < proposerSignatures.length) { // this assembly trims the signer array, getting rid of unused cells assembly { mstore(signers, numSigners) } } checkNoActiveProp(ds, msg.sender); ds.latestProposalIds[msg.sender] = proposalId; votes += nouns.getPriorVotes(msg.sender, block.number - 1); } function calcProposalEncodeData( address proposer, ProposalTxs memory txs, string memory description ) internal pure returns (bytes memory) { bytes32[] memory signatureHashes = new bytes32[](txs.signatures.length); for (uint256 i = 0; i < txs.signatures.length; ++i) { signatureHashes[i] = keccak256(bytes(txs.signatures[i])); } bytes32[] memory calldatasHashes = new bytes32[](txs.calldatas.length); for (uint256 i = 0; i < txs.calldatas.length; ++i) { calldatasHashes[i] = keccak256(txs.calldatas[i]); } return abi.encode( proposer, keccak256(abi.encodePacked(txs.targets)), keccak256(abi.encodePacked(txs.values)), keccak256(abi.encodePacked(signatureHashes)), keccak256(abi.encodePacked(calldatasHashes)), keccak256(bytes(description)) ); } function checkProposalUpdatable( NounsDAOStorageV3.StorageV3 storage ds, uint256 proposalId, NounsDAOStorageV3.Proposal storage proposal ) internal view { if (stateInternal(ds, proposalId) != NounsDAOStorageV3.ProposalState.Updatable) revert CanOnlyEditUpdatableProposals(); if (msg.sender != proposal.proposer) revert OnlyProposerCanEdit(); if (proposal.signers.length > 0) revert ProposerCannotUpdateProposalWithSigners(); } function createNewProposal( NounsDAOStorageV3.StorageV3 storage ds, uint256 proposalId, uint256 proposalThreshold_, uint256 adjustedTotalSupply, ProposalTxs memory txs ) internal returns (NounsDAOStorageV3.Proposal storage newProposal) { uint64 updatePeriodEndBlock = SafeCast.toUint64(block.number + ds.proposalUpdatablePeriodInBlocks); uint256 startBlock = updatePeriodEndBlock + ds.votingDelay; uint256 endBlock = startBlock + ds.votingPeriod; newProposal = ds._proposals[proposalId]; newProposal.id = proposalId; newProposal.proposer = msg.sender; newProposal.proposalThreshold = proposalThreshold_; newProposal.targets = txs.targets; newProposal.values = txs.values; newProposal.signatures = txs.signatures; newProposal.calldatas = txs.calldatas; newProposal.startBlock = startBlock; newProposal.endBlock = endBlock; newProposal.totalSupply = adjustedTotalSupply; newProposal.creationBlock = SafeCast.toUint64(block.number); newProposal.updatePeriodEndBlock = updatePeriodEndBlock; } function emitNewPropEvents( NounsDAOStorageV3.Proposal storage newProposal, address[] memory signers, uint256 minQuorumVotes, ProposalTxs memory txs, string memory description ) internal { /// @notice Maintains backwards compatibility with GovernorBravo events emit ProposalCreated( newProposal.id, msg.sender, txs.targets, txs.values, txs.signatures, txs.calldatas, newProposal.startBlock, newProposal.endBlock, description ); /// @notice V1: Updated event with `proposalThreshold` and `quorumVotes` `minQuorumVotes` /// @notice V2: `quorumVotes` changed to `minQuorumVotes` /// @notice V3: Added signers and updatePeriodEndBlock emit ProposalCreatedWithRequirements( newProposal.id, msg.sender, signers, txs.targets, txs.values, txs.signatures, txs.calldatas, newProposal.startBlock, newProposal.endBlock, newProposal.updatePeriodEndBlock, newProposal.proposalThreshold, minQuorumVotes, description ); } function checkPropThreshold( NounsDAOStorageV3.StorageV3 storage ds, uint256 votes, uint256 adjustedTotalSupply ) internal view returns (uint256 propThreshold) { propThreshold = proposalThreshold(ds, adjustedTotalSupply); if (votes <= propThreshold) revert VotesBelowProposalThreshold(); } function checkProposalTxs(ProposalTxs memory txs) internal pure { if ( txs.targets.length != txs.values.length || txs.targets.length != txs.signatures.length || txs.targets.length != txs.calldatas.length ) revert ProposalInfoArityMismatch(); if (txs.targets.length == 0) revert MustProvideActions(); if (txs.targets.length > PROPOSAL_MAX_OPERATIONS) revert TooManyActions(); } function verifyProposalSignature( NounsDAOStorageV3.StorageV3 storage ds, bytes memory proposalEncodeData, NounsDAOStorageV3.ProposerSignature memory proposerSignature, bytes32 typehash ) internal view { bytes32 sigHash = keccak256(proposerSignature.sig); if (ds.cancelledSigs[proposerSignature.signer][sigHash]) revert SignatureIsCancelled(); bytes32 digest = sigDigest(typehash, proposalEncodeData, proposerSignature.expirationTimestamp, address(this)); if (!SignatureChecker.isValidSignatureNow(proposerSignature.signer, digest, proposerSignature.sig)) revert InvalidSignature(); if (block.timestamp > proposerSignature.expirationTimestamp) revert SignatureExpired(); } /** * @notice Generate the digest (hash) used to verify proposal signatures. * @param typehash the EIP 712 type hash of the signed message, e.g. `PROPOSAL_TYPEHASH` or `UPDATE_PROPOSAL_TYPEHASH`. * @param proposalEncodeData the abi encoded proposal data, identical to the output of `calcProposalEncodeData`. * @param expirationTimestamp the signature's expiration timestamp. * @param verifyingContract the contract verifying the signature, e.g. the DAO proxy by default. * @return bytes32 the signature's typed data hash. */ function sigDigest( bytes32 typehash, bytes memory proposalEncodeData, uint256 expirationTimestamp, address verifyingContract ) internal view returns (bytes32) { bytes32 structHash = keccak256(abi.encodePacked(typehash, proposalEncodeData, expirationTimestamp)); bytes32 domainSeparator = keccak256( abi.encode(DOMAIN_TYPEHASH, keccak256(bytes('Nouns DAO')), block.chainid, verifyingContract) ); return ECDSA.toTypedDataHash(domainSeparator, structHash); } function bps2Uint(uint256 bps, uint256 number) internal pure returns (uint256) { return (number * bps) / 10000; } }
// SPDX-License-Identifier: BSD-3-Clause /// @title Nouns DAO Logic interfaces and events /********************************* * ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ * * ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ * * ░░░░░░█████████░░█████████░░░ * * ░░░░░░██░░░████░░██░░░████░░░ * * ░░██████░░░████████░░░████░░░ * * ░░██░░██░░░████░░██░░░████░░░ * * ░░██░░██░░░████░░██░░░████░░░ * * ░░░░░░█████████░░█████████░░░ * * ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ * * ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ * *********************************/ // LICENSE // NounsDAOInterfaces.sol is a modified version of Compound Lab's GovernorBravoInterfaces.sol: // https://github.com/compound-finance/compound-protocol/blob/b9b14038612d846b83f8a009a82c38974ff2dcfe/contracts/Governance/GovernorBravoInterfaces.sol // // GovernorBravoInterfaces.sol source code Copyright 2020 Compound Labs, Inc. licensed under the BSD-3-Clause license. // With modifications by Nounders DAO. // // Additional conditions of BSD-3-Clause can be found here: https://opensource.org/licenses/BSD-3-Clause // // MODIFICATIONS // NounsDAOEvents, NounsDAOProxyStorage, NounsDAOStorageV1 add support for changes made by Nouns DAO to GovernorBravo.sol // See NounsDAOLogicV1.sol for more details. // NounsDAOStorageV1Adjusted and NounsDAOStorageV2 add support for a dynamic vote quorum. // See NounsDAOLogicV2.sol for more details. // NounsDAOStorageV3 // See NounsDAOLogicV3.sol for more details. pragma solidity ^0.8.6; contract NounsDAOEvents { /// @notice An event emitted when a new proposal is created event ProposalCreated( uint256 id, address proposer, address[] targets, uint256[] values, string[] signatures, bytes[] calldatas, uint256 startBlock, uint256 endBlock, string description ); /// @notice An event emitted when a new proposal is created, which includes additional information event ProposalCreatedWithRequirements( uint256 id, address proposer, address[] targets, uint256[] values, string[] signatures, bytes[] calldatas, uint256 startBlock, uint256 endBlock, uint256 proposalThreshold, uint256 quorumVotes, string description ); /// @notice An event emitted when a vote has been cast on a proposal /// @param voter The address which casted a vote /// @param proposalId The proposal id which was voted on /// @param support Support value for the vote. 0=against, 1=for, 2=abstain /// @param votes Number of votes which were cast by the voter /// @param reason The reason given for the vote by the voter event VoteCast(address indexed voter, uint256 proposalId, uint8 support, uint256 votes, string reason); /// @notice An event emitted when a proposal has been canceled event ProposalCanceled(uint256 id); /// @notice An event emitted when a proposal has been queued in the NounsDAOExecutor event ProposalQueued(uint256 id, uint256 eta); /// @notice An event emitted when a proposal has been executed in the NounsDAOExecutor event ProposalExecuted(uint256 id); /// @notice An event emitted when a proposal has been vetoed by vetoAddress event ProposalVetoed(uint256 id); /// @notice An event emitted when the voting delay is set event VotingDelaySet(uint256 oldVotingDelay, uint256 newVotingDelay); /// @notice An event emitted when the voting period is set event VotingPeriodSet(uint256 oldVotingPeriod, uint256 newVotingPeriod); /// @notice Emitted when implementation is changed event NewImplementation(address oldImplementation, address newImplementation); /// @notice Emitted when proposal threshold basis points is set event ProposalThresholdBPSSet(uint256 oldProposalThresholdBPS, uint256 newProposalThresholdBPS); /// @notice Emitted when quorum votes basis points is set event QuorumVotesBPSSet(uint256 oldQuorumVotesBPS, uint256 newQuorumVotesBPS); /// @notice Emitted when pendingAdmin is changed event NewPendingAdmin(address oldPendingAdmin, address newPendingAdmin); /// @notice Emitted when pendingAdmin is accepted, which means admin is updated event NewAdmin(address oldAdmin, address newAdmin); /// @notice Emitted when vetoer is changed event NewVetoer(address oldVetoer, address newVetoer); } contract NounsDAOEventsV2 is NounsDAOEvents { /// @notice Emitted when minQuorumVotesBPS is set event MinQuorumVotesBPSSet(uint16 oldMinQuorumVotesBPS, uint16 newMinQuorumVotesBPS); /// @notice Emitted when maxQuorumVotesBPS is set event MaxQuorumVotesBPSSet(uint16 oldMaxQuorumVotesBPS, uint16 newMaxQuorumVotesBPS); /// @notice Emitted when quorumCoefficient is set event QuorumCoefficientSet(uint32 oldQuorumCoefficient, uint32 newQuorumCoefficient); /// @notice Emitted when a voter cast a vote requesting a gas refund. event RefundableVote(address indexed voter, uint256 refundAmount, bool refundSent); /// @notice Emitted when admin withdraws the DAO's balance. event Withdraw(uint256 amount, bool sent); /// @notice Emitted when pendingVetoer is changed event NewPendingVetoer(address oldPendingVetoer, address newPendingVetoer); } contract NounsDAOEventsV3 is NounsDAOEventsV2 { /// @notice An event emitted when a new proposal is created, which includes additional information /// @dev V3 adds `signers`, `updatePeriodEndBlock` compared to the V1/V2 event. event ProposalCreatedWithRequirements( uint256 id, address proposer, address[] signers, address[] targets, uint256[] values, string[] signatures, bytes[] calldatas, uint256 startBlock, uint256 endBlock, uint256 updatePeriodEndBlock, uint256 proposalThreshold, uint256 quorumVotes, string description ); /// @notice Emitted when a proposal is created to be executed on timelockV1 event ProposalCreatedOnTimelockV1(uint256 id); /// @notice Emitted when a proposal is updated event ProposalUpdated( uint256 indexed id, address indexed proposer, address[] targets, uint256[] values, string[] signatures, bytes[] calldatas, string description, string updateMessage ); /// @notice Emitted when a proposal's transactions are updated event ProposalTransactionsUpdated( uint256 indexed id, address indexed proposer, address[] targets, uint256[] values, string[] signatures, bytes[] calldatas, string updateMessage ); /// @notice Emitted when a proposal's description is updated event ProposalDescriptionUpdated( uint256 indexed id, address indexed proposer, string description, string updateMessage ); /// @notice Emitted when a proposal is set to have an objection period event ProposalObjectionPeriodSet(uint256 indexed id, uint256 objectionPeriodEndBlock); /// @notice Emitted when someone cancels a signature event SignatureCancelled(address indexed signer, bytes sig); /// @notice An event emitted when the objection period duration is set event ObjectionPeriodDurationSet( uint32 oldObjectionPeriodDurationInBlocks, uint32 newObjectionPeriodDurationInBlocks ); /// @notice An event emitted when the objection period last minute window is set event LastMinuteWindowSet(uint32 oldLastMinuteWindowInBlocks, uint32 newLastMinuteWindowInBlocks); /// @notice An event emitted when the proposal updatable period is set event ProposalUpdatablePeriodSet( uint32 oldProposalUpdatablePeriodInBlocks, uint32 newProposalUpdatablePeriodInBlocks ); /// @notice Emitted when the proposal id at which vote snapshot block changes is set event VoteSnapshotBlockSwitchProposalIdSet( uint256 oldVoteSnapshotBlockSwitchProposalId, uint256 newVoteSnapshotBlockSwitchProposalId ); /// @notice Emitted when the erc20 tokens to include in a fork are set event ERC20TokensToIncludeInForkSet(address[] oldErc20Tokens, address[] newErc20tokens); /// @notice Emitted when the fork DAO deployer is set event ForkDAODeployerSet(address oldForkDAODeployer, address newForkDAODeployer); /// @notice Emitted when the during of the forking period is set event ForkPeriodSet(uint256 oldForkPeriod, uint256 newForkPeriod); /// @notice Emitted when the threhsold for forking is set event ForkThresholdSet(uint256 oldForkThreshold, uint256 newForkThreshold); /// @notice Emitted when the main timelock, timelockV1 and admin are set event TimelocksAndAdminSet(address timelock, address timelockV1, address admin); /// @notice Emitted when someones adds nouns to the fork escrow event EscrowedToFork( uint32 indexed forkId, address indexed owner, uint256[] tokenIds, uint256[] proposalIds, string reason ); /// @notice Emitted when the owner withdraws their nouns from the fork escrow event WithdrawFromForkEscrow(uint32 indexed forkId, address indexed owner, uint256[] tokenIds); /// @notice Emitted when the fork is executed and the forking period begins event ExecuteFork( uint32 indexed forkId, address forkTreasury, address forkToken, uint256 forkEndTimestamp, uint256 tokensInEscrow ); /// @notice Emitted when someone joins a fork during the forking period event JoinFork( uint32 indexed forkId, address indexed owner, uint256[] tokenIds, uint256[] proposalIds, string reason ); /// @notice Emitted when the DAO withdraws nouns from the fork escrow after a fork has been executed event DAOWithdrawNounsFromEscrow(uint256[] tokenIds, address to); /// @notice Emitted when withdrawing nouns from escrow increases adjusted total supply event DAONounsSupplyIncreasedFromEscrow(uint256 numTokens, address to); } contract NounsDAOProxyStorage { /// @notice Administrator for this contract address public admin; /// @notice Pending administrator for this contract address public pendingAdmin; /// @notice Active brains of Governor address public implementation; } /** * @title Storage for Governor Bravo Delegate * @notice For future upgrades, do not change NounsDAOStorageV1. Create a new * contract which implements NounsDAOStorageV1 and following the naming convention * NounsDAOStorageVX. */ contract NounsDAOStorageV1 is NounsDAOProxyStorage { /// @notice Vetoer who has the ability to veto any proposal address public vetoer; /// @notice The delay before voting on a proposal may take place, once proposed, in blocks uint256 public votingDelay; /// @notice The duration of voting on a proposal, in blocks uint256 public votingPeriod; /// @notice The basis point number of votes required in order for a voter to become a proposer. *DIFFERS from GovernerBravo uint256 public proposalThresholdBPS; /// @notice The basis point number of votes in support of a proposal required in order for a quorum to be reached and for a vote to succeed. *DIFFERS from GovernerBravo uint256 public quorumVotesBPS; /// @notice The total number of proposals uint256 public proposalCount; /// @notice The address of the Nouns DAO Executor NounsDAOExecutor INounsDAOExecutor public timelock; /// @notice The address of the Nouns tokens NounsTokenLike public nouns; /// @notice The official record of all proposals ever proposed mapping(uint256 => Proposal) public proposals; /// @notice The latest proposal for each proposer mapping(address => uint256) public latestProposalIds; struct Proposal { /// @notice Unique id for looking up a proposal uint256 id; /// @notice Creator of the proposal address proposer; /// @notice The number of votes needed to create a proposal at the time of proposal creation. *DIFFERS from GovernerBravo uint256 proposalThreshold; /// @notice The number of votes in support of a proposal required in order for a quorum to be reached and for a vote to succeed at the time of proposal creation. *DIFFERS from GovernerBravo uint256 quorumVotes; /// @notice The timestamp that the proposal will be available for execution, set once the vote succeeds uint256 eta; /// @notice the ordered list of target addresses for calls to be made address[] targets; /// @notice The ordered list of values (i.e. msg.value) to be passed to the calls to be made uint256[] values; /// @notice The ordered list of function signatures to be called string[] signatures; /// @notice The ordered list of calldata to be passed to each call bytes[] calldatas; /// @notice The block at which voting begins: holders must delegate their votes prior to this block uint256 startBlock; /// @notice The block at which voting ends: votes must be cast prior to this block uint256 endBlock; /// @notice Current number of votes in favor of this proposal uint256 forVotes; /// @notice Current number of votes in opposition to this proposal uint256 againstVotes; /// @notice Current number of votes for abstaining for this proposal uint256 abstainVotes; /// @notice Flag marking whether the proposal has been canceled bool canceled; /// @notice Flag marking whether the proposal has been vetoed bool vetoed; /// @notice Flag marking whether the proposal has been executed bool executed; /// @notice Receipts of ballots for the entire set of voters mapping(address => Receipt) receipts; } /// @notice Ballot receipt record for a voter struct Receipt { /// @notice Whether or not a vote has been cast bool hasVoted; /// @notice Whether or not the voter supports the proposal or abstains uint8 support; /// @notice The number of votes the voter had, which were cast uint96 votes; } /// @notice Possible states that a proposal may be in enum ProposalState { Pending, Active, Canceled, Defeated, Succeeded, Queued, Expired, Executed, Vetoed } } /** * @title Extra fields added to the `Proposal` struct from NounsDAOStorageV1 * @notice The following fields were added to the `Proposal` struct: * - `Proposal.totalSupply` * - `Proposal.creationBlock` */ contract NounsDAOStorageV1Adjusted is NounsDAOProxyStorage { /// @notice Vetoer who has the ability to veto any proposal address public vetoer; /// @notice The delay before voting on a proposal may take place, once proposed, in blocks uint256 public votingDelay; /// @notice The duration of voting on a proposal, in blocks uint256 public votingPeriod; /// @notice The basis point number of votes required in order for a voter to become a proposer. *DIFFERS from GovernerBravo uint256 public proposalThresholdBPS; /// @notice The basis point number of votes in support of a proposal required in order for a quorum to be reached and for a vote to succeed. *DIFFERS from GovernerBravo uint256 public quorumVotesBPS; /// @notice The total number of proposals uint256 public proposalCount; /// @notice The address of the Nouns DAO Executor NounsDAOExecutor INounsDAOExecutor public timelock; /// @notice The address of the Nouns tokens NounsTokenLike public nouns; /// @notice The official record of all proposals ever proposed mapping(uint256 => Proposal) internal _proposals; /// @notice The latest proposal for each proposer mapping(address => uint256) public latestProposalIds; struct Proposal { /// @notice Unique id for looking up a proposal uint256 id; /// @notice Creator of the proposal address proposer; /// @notice The number of votes needed to create a proposal at the time of proposal creation. *DIFFERS from GovernerBravo uint256 proposalThreshold; /// @notice The number of votes in support of a proposal required in order for a quorum to be reached and for a vote to succeed at the time of proposal creation. *DIFFERS from GovernerBravo uint256 quorumVotes; /// @notice The timestamp that the proposal will be available for execution, set once the vote succeeds uint256 eta; /// @notice the ordered list of target addresses for calls to be made address[] targets; /// @notice The ordered list of values (i.e. msg.value) to be passed to the calls to be made uint256[] values; /// @notice The ordered list of function signatures to be called string[] signatures; /// @notice The ordered list of calldata to be passed to each call bytes[] calldatas; /// @notice The block at which voting begins: holders must delegate their votes prior to this block uint256 startBlock; /// @notice The block at which voting ends: votes must be cast prior to this block uint256 endBlock; /// @notice Current number of votes in favor of this proposal uint256 forVotes; /// @notice Current number of votes in opposition to this proposal uint256 againstVotes; /// @notice Current number of votes for abstaining for this proposal uint256 abstainVotes; /// @notice Flag marking whether the proposal has been canceled bool canceled; /// @notice Flag marking whether the proposal has been vetoed bool vetoed; /// @notice Flag marking whether the proposal has been executed bool executed; /// @notice Receipts of ballots for the entire set of voters mapping(address => Receipt) receipts; /// @notice The total supply at the time of proposal creation uint256 totalSupply; /// @notice The block at which this proposal was created uint256 creationBlock; } /// @notice Ballot receipt record for a voter struct Receipt { /// @notice Whether or not a vote has been cast bool hasVoted; /// @notice Whether or not the voter supports the proposal or abstains uint8 support; /// @notice The number of votes the voter had, which were cast uint96 votes; } /// @notice Possible states that a proposal may be in enum ProposalState { Pending, Active, Canceled, Defeated, Succeeded, Queued, Expired, Executed, Vetoed } } /** * @title Storage for Governor Bravo Delegate * @notice For future upgrades, do not change NounsDAOStorageV2. Create a new * contract which implements NounsDAOStorageV2 and following the naming convention * NounsDAOStorageVX. */ contract NounsDAOStorageV2 is NounsDAOStorageV1Adjusted { DynamicQuorumParamsCheckpoint[] public quorumParamsCheckpoints; /// @notice Pending new vetoer address public pendingVetoer; struct DynamicQuorumParams { /// @notice The minimum basis point number of votes in support of a proposal required in order for a quorum to be reached and for a vote to succeed. uint16 minQuorumVotesBPS; /// @notice The maximum basis point number of votes in support of a proposal required in order for a quorum to be reached and for a vote to succeed. uint16 maxQuorumVotesBPS; /// @notice The dynamic quorum coefficient /// @dev Assumed to be fixed point integer with 6 decimals, i.e 0.2 is represented as 0.2 * 1e6 = 200000 uint32 quorumCoefficient; } /// @notice A checkpoint for storing dynamic quorum params from a given block struct DynamicQuorumParamsCheckpoint { /// @notice The block at which the new values were set uint32 fromBlock; /// @notice The parameter values of this checkpoint DynamicQuorumParams params; } struct ProposalCondensed { /// @notice Unique id for looking up a proposal uint256 id; /// @notice Creator of the proposal address proposer; /// @notice The number of votes needed to create a proposal at the time of proposal creation. *DIFFERS from GovernerBravo uint256 proposalThreshold; /// @notice The minimum number of votes in support of a proposal required in order for a quorum to be reached and for a vote to succeed at the time of proposal creation. *DIFFERS from GovernerBravo uint256 quorumVotes; /// @notice The timestamp that the proposal will be available for execution, set once the vote succeeds uint256 eta; /// @notice The block at which voting begins: holders must delegate their votes prior to this block uint256 startBlock; /// @notice The block at which voting ends: votes must be cast prior to this block uint256 endBlock; /// @notice Current number of votes in favor of this proposal uint256 forVotes; /// @notice Current number of votes in opposition to this proposal uint256 againstVotes; /// @notice Current number of votes for abstaining for this proposal uint256 abstainVotes; /// @notice Flag marking whether the proposal has been canceled bool canceled; /// @notice Flag marking whether the proposal has been vetoed bool vetoed; /// @notice Flag marking whether the proposal has been executed bool executed; /// @notice The total supply at the time of proposal creation uint256 totalSupply; /// @notice The block at which this proposal was created uint256 creationBlock; } } interface INounsDAOExecutor { function delay() external view returns (uint256); function GRACE_PERIOD() external view returns (uint256); function acceptAdmin() external; function queuedTransactions(bytes32 hash) external view returns (bool); function queueTransaction( address target, uint256 value, string calldata signature, bytes calldata data, uint256 eta ) external returns (bytes32); function cancelTransaction( address target, uint256 value, string calldata signature, bytes calldata data, uint256 eta ) external; function executeTransaction( address target, uint256 value, string calldata signature, bytes calldata data, uint256 eta ) external payable returns (bytes memory); } interface NounsTokenLike { function getPriorVotes(address account, uint256 blockNumber) external view returns (uint96); function totalSupply() external view returns (uint256); function transferFrom( address from, address to, uint256 tokenId ) external; function safeTransferFrom( address from, address to, uint256 tokenId ) external; function balanceOf(address owner) external view returns (uint256 balance); function ownerOf(uint256 tokenId) external view returns (address owner); function minter() external view returns (address); function mint() external returns (uint256); function setApprovalForAll(address operator, bool approved) external; } interface IForkDAODeployer { function deployForkDAO(uint256 forkingPeriodEndTimestamp, INounsDAOForkEscrow forkEscrowAddress) external returns (address treasury, address token); function tokenImpl() external view returns (address); function auctionImpl() external view returns (address); function governorImpl() external view returns (address); function treasuryImpl() external view returns (address); } interface INounsDAOExecutorV2 is INounsDAOExecutor { function sendETH(address recipient, uint256 ethToSend) external; function sendERC20( address recipient, address erc20Token, uint256 tokensToSend ) external; } interface INounsDAOForkEscrow { function markOwner(address owner, uint256[] calldata tokenIds) external; function returnTokensToOwner(address owner, uint256[] calldata tokenIds) external; function closeEscrow() external returns (uint32); function numTokensInEscrow() external view returns (uint256); function numTokensOwnedByDAO() external view returns (uint256); function withdrawTokens(uint256[] calldata tokenIds, address to) external; function forkId() external view returns (uint32); function nounsToken() external view returns (NounsTokenLike); function dao() external view returns (address); function ownerOfEscrowedToken(uint32 forkId_, uint256 tokenId) external view returns (address); } contract NounsDAOStorageV3 { StorageV3 ds; struct StorageV3 { // ================ PROXY ================ // /// @notice Administrator for this contract address admin; /// @notice Pending administrator for this contract address pendingAdmin; /// @notice Active brains of Governor address implementation; // ================ V1 ================ // /// @notice Vetoer who has the ability to veto any proposal address vetoer; /// @notice The delay before voting on a proposal may take place, once proposed, in blocks uint256 votingDelay; /// @notice The duration of voting on a proposal, in blocks uint256 votingPeriod; /// @notice The basis point number of votes required in order for a voter to become a proposer. *DIFFERS from GovernerBravo uint256 proposalThresholdBPS; /// @notice The basis point number of votes in support of a proposal required in order for a quorum to be reached and for a vote to succeed. *DIFFERS from GovernerBravo uint256 quorumVotesBPS; /// @notice The total number of proposals uint256 proposalCount; /// @notice The address of the Nouns DAO Executor NounsDAOExecutor INounsDAOExecutorV2 timelock; /// @notice The address of the Nouns tokens NounsTokenLike nouns; /// @notice The official record of all proposals ever proposed mapping(uint256 => Proposal) _proposals; /// @notice The latest proposal for each proposer mapping(address => uint256) latestProposalIds; // ================ V2 ================ // DynamicQuorumParamsCheckpoint[] quorumParamsCheckpoints; /// @notice Pending new vetoer address pendingVetoer; // ================ V3 ================ // /// @notice user => sig => isCancelled: signatures that have been cancelled by the signer and are no longer valid mapping(address => mapping(bytes32 => bool)) cancelledSigs; /// @notice The number of blocks before voting ends during which the objection period can be initiated uint32 lastMinuteWindowInBlocks; /// @notice Length of the objection period in blocks uint32 objectionPeriodDurationInBlocks; /// @notice Length of proposal updatable period in block uint32 proposalUpdatablePeriodInBlocks; /// @notice address of the DAO's fork escrow contract INounsDAOForkEscrow forkEscrow; /// @notice address of the DAO's fork deployer contract IForkDAODeployer forkDAODeployer; /// @notice ERC20 tokens to include when sending funds to a deployed fork address[] erc20TokensToIncludeInFork; /// @notice The treasury contract of the last deployed fork address forkDAOTreasury; /// @notice The token contract of the last deployed fork address forkDAOToken; /// @notice Timestamp at which the last fork period ends uint256 forkEndTimestamp; /// @notice Fork period in seconds uint256 forkPeriod; /// @notice Threshold defined in basis points (10,000 = 100%) required for forking uint256 forkThresholdBPS; /// @notice Address of the original timelock INounsDAOExecutor timelockV1; /// @notice The proposal at which to start using `startBlock` instead of `creationBlock` for vote snapshots /// @dev Make sure this stays the last variable in this struct, so we can delete it in the next version /// @dev To be zeroed-out and removed in a V3.1 fix version once the switch takes place uint256 voteSnapshotBlockSwitchProposalId; } struct Proposal { /// @notice Unique id for looking up a proposal uint256 id; /// @notice Creator of the proposal address proposer; /// @notice The number of votes needed to create a proposal at the time of proposal creation. *DIFFERS from GovernerBravo uint256 proposalThreshold; /// @notice The number of votes in support of a proposal required in order for a quorum to be reached and for a vote to succeed at the time of proposal creation. *DIFFERS from GovernerBravo uint256 quorumVotes; /// @notice The timestamp that the proposal will be available for execution, set once the vote succeeds uint256 eta; /// @notice the ordered list of target addresses for calls to be made address[] targets; /// @notice The ordered list of values (i.e. msg.value) to be passed to the calls to be made uint256[] values; /// @notice The ordered list of function signatures to be called string[] signatures; /// @notice The ordered list of calldata to be passed to each call bytes[] calldatas; /// @notice The block at which voting begins: holders must delegate their votes prior to this block uint256 startBlock; /// @notice The block at which voting ends: votes must be cast prior to this block uint256 endBlock; /// @notice Current number of votes in favor of this proposal uint256 forVotes; /// @notice Current number of votes in opposition to this proposal uint256 againstVotes; /// @notice Current number of votes for abstaining for this proposal uint256 abstainVotes; /// @notice Flag marking whether the proposal has been canceled bool canceled; /// @notice Flag marking whether the proposal has been vetoed bool vetoed; /// @notice Flag marking whether the proposal has been executed bool executed; /// @notice Receipts of ballots for the entire set of voters mapping(address => Receipt) receipts; /// @notice The total supply at the time of proposal creation uint256 totalSupply; /// @notice The block at which this proposal was created uint64 creationBlock; /// @notice The last block which allows updating a proposal's description and transactions uint64 updatePeriodEndBlock; /// @notice Starts at 0 and is set to the block at which the objection period ends when the objection period is initiated uint64 objectionPeriodEndBlock; /// @dev unused for now uint64 placeholder; /// @notice The signers of a proposal, when using proposeBySigs address[] signers; /// @notice When true, a proposal would be executed on timelockV1 instead of the current timelock bool executeOnTimelockV1; } /// @notice Ballot receipt record for a voter struct Receipt { /// @notice Whether or not a vote has been cast bool hasVoted; /// @notice Whether or not the voter supports the proposal or abstains uint8 support; /// @notice The number of votes the voter had, which were cast uint96 votes; } struct ProposerSignature { /// @notice Signature of a proposal bytes sig; /// @notice The address of the signer address signer; /// @notice The timestamp until which the signature is valid uint256 expirationTimestamp; } struct ProposalCondensed { /// @notice Unique id for looking up a proposal uint256 id; /// @notice Creator of the proposal address proposer; /// @notice The number of votes needed to create a proposal at the time of proposal creation. *DIFFERS from GovernerBravo uint256 proposalThreshold; /// @notice The minimum number of votes in support of a proposal required in order for a quorum to be reached and for a vote to succeed at the time of proposal creation. *DIFFERS from GovernerBravo uint256 quorumVotes; /// @notice The timestamp that the proposal will be available for execution, set once the vote succeeds uint256 eta; /// @notice The block at which voting begins: holders must delegate their votes prior to this block uint256 startBlock; /// @notice The block at which voting ends: votes must be cast prior to this block uint256 endBlock; /// @notice Current number of votes in favor of this proposal uint256 forVotes; /// @notice Current number of votes in opposition to this proposal uint256 againstVotes; /// @notice Current number of votes for abstaining for this proposal uint256 abstainVotes; /// @notice Flag marking whether the proposal has been canceled bool canceled; /// @notice Flag marking whether the proposal has been vetoed bool vetoed; /// @notice Flag marking whether the proposal has been executed bool executed; /// @notice The total supply at the time of proposal creation uint256 totalSupply; /// @notice The block at which this proposal was created uint256 creationBlock; /// @notice The signers of a proposal, when using proposeBySigs address[] signers; /// @notice The last block which allows updating a proposal's description and transactions uint256 updatePeriodEndBlock; /// @notice Starts at 0 and is set to the block at which the objection period ends when the objection period is initiated uint256 objectionPeriodEndBlock; /// @notice When true, a proposal would be executed on timelockV1 instead of the current timelock bool executeOnTimelockV1; } struct DynamicQuorumParams { /// @notice The minimum basis point number of votes in support of a proposal required in order for a quorum to be reached and for a vote to succeed. uint16 minQuorumVotesBPS; /// @notice The maximum basis point number of votes in support of a proposal required in order for a quorum to be reached and for a vote to succeed. uint16 maxQuorumVotesBPS; /// @notice The dynamic quorum coefficient /// @dev Assumed to be fixed point integer with 6 decimals, i.e 0.2 is represented as 0.2 * 1e6 = 200000 uint32 quorumCoefficient; } struct NounsDAOParams { uint256 votingPeriod; uint256 votingDelay; uint256 proposalThresholdBPS; uint32 lastMinuteWindowInBlocks; uint32 objectionPeriodDurationInBlocks; uint32 proposalUpdatablePeriodInBlocks; } /// @notice A checkpoint for storing dynamic quorum params from a given block struct DynamicQuorumParamsCheckpoint { /// @notice The block at which the new values were set uint32 fromBlock; /// @notice The parameter values of this checkpoint DynamicQuorumParams params; } /// @notice Possible states that a proposal may be in enum ProposalState { Pending, Active, Canceled, Defeated, Succeeded, Queued, Expired, Executed, Vetoed, ObjectionPeriod, Updatable } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.9.0) (utils/cryptography/SignatureChecker.sol) pragma solidity ^0.8.0; import './ECDSA.sol'; import '@openzeppelin/contracts/interfaces/IERC1271.sol'; /** * @dev Signature verification helper that can be used instead of `ECDSA.recover` to seamlessly support both ECDSA * signatures from externally owned accounts (EOAs) as well as ERC1271 signatures from smart contract wallets like * Argent and Gnosis Safe. * * _Available since v4.1._ */ library SignatureChecker { /** * @dev Checks if a signature is valid for a given signer and data hash. If the signer is a smart contract, the * signature is validated against that smart contract using ERC1271, otherwise it's validated using `ECDSA.recover`. * * NOTE: Unlike ECDSA signatures, contract signatures are revocable, and the outcome of this function can thus * change through time. It could return true at block N and false at block N+1 (or the opposite). */ function isValidSignatureNow( address signer, bytes32 hash, bytes memory signature ) internal view returns (bool) { (address recovered, ECDSA.RecoverError error) = ECDSA.tryRecover(hash, signature); return (error == ECDSA.RecoverError.NoError && recovered == signer) || isValidERC1271SignatureNow(signer, hash, signature); } /** * @dev Checks if a signature is valid for a given signer and data hash. The signature is validated * against the signer smart contract using ERC1271. * * NOTE: Unlike ECDSA signatures, contract signatures are revocable, and the outcome of this function can thus * change through time. It could return true at block N and false at block N+1 (or the opposite). */ function isValidERC1271SignatureNow( address signer, bytes32 hash, bytes memory signature ) internal view returns (bool) { (bool success, bytes memory result) = signer.staticcall( abi.encodeWithSelector(IERC1271.isValidSignature.selector, hash, signature) ); return (success && result.length >= 32 && abi.decode(result, (bytes32)) == bytes32(IERC1271.isValidSignature.selector)); } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.0 (proxy/utils/UUPSUpgradeable.sol) pragma solidity ^0.8.0; import "../ERC1967/ERC1967Upgrade.sol"; /** * @dev An upgradeability mechanism designed for UUPS proxies. The functions included here can perform an upgrade of an * {ERC1967Proxy}, when this contract is set as the implementation behind such a proxy. * * A security mechanism ensures that an upgrade does not turn off upgradeability accidentally, although this risk is * reinstated if the upgrade retains upgradeability but removes the security mechanism, e.g. by replacing * `UUPSUpgradeable` with a custom implementation of upgrades. * * The {_authorizeUpgrade} function must be overridden to include access restriction to the upgrade mechanism. * * _Available since v4.1._ */ abstract contract UUPSUpgradeable is ERC1967Upgrade { /// @custom:oz-upgrades-unsafe-allow state-variable-immutable state-variable-assignment address private immutable __self = address(this); /** * @dev Check that the execution is being performed through a delegatecall call and that the execution context is * a proxy contract with an implementation (as defined in ERC1967) pointing to self. This should only be the case * for UUPS and transparent proxies that are using the current contract as their implementation. Execution of a * function through ERC1167 minimal proxies (clones) would not normally pass this test, but is not guaranteed to * fail. */ modifier onlyProxy() { require(address(this) != __self, "Function must be called through delegatecall"); require(_getImplementation() == __self, "Function must be called through active proxy"); _; } /** * @dev Upgrade the implementation of the proxy to `newImplementation`. * * Calls {_authorizeUpgrade}. * * Emits an {Upgraded} event. */ function upgradeTo(address newImplementation) external virtual onlyProxy { _authorizeUpgrade(newImplementation); _upgradeToAndCallSecure(newImplementation, new bytes(0), false); } /** * @dev Upgrade the implementation of the proxy to `newImplementation`, and subsequently execute the function call * encoded in `data`. * * Calls {_authorizeUpgrade}. * * Emits an {Upgraded} event. */ function upgradeToAndCall(address newImplementation, bytes memory data) external payable virtual onlyProxy { _authorizeUpgrade(newImplementation); _upgradeToAndCallSecure(newImplementation, data, true); } /** * @dev Function that should revert when `msg.sender` is not authorized to upgrade the contract. Called by * {upgradeTo} and {upgradeToAndCall}. * * Normally, this function will use an xref:access.adoc[access control] modifier such as {Ownable-onlyOwner}. * * ```solidity * function _authorizeUpgrade(address) internal override onlyOwner {} * ``` */ function _authorizeUpgrade(address newImplementation) internal virtual; }
// SPDX-License-Identifier: GPL-3.0 /// @title Nouns DAO Data Events /********************************* * ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ * * ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ * * ░░░░░░█████████░░█████████░░░ * * ░░░░░░██░░░████░░██░░░████░░░ * * ░░██████░░░████████░░░████░░░ * * ░░██░░██░░░████░░██░░░████░░░ * * ░░██░░██░░░████░░██░░░████░░░ * * ░░░░░░█████████░░█████████░░░ * * ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ * * ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ * *********************************/ pragma solidity ^0.8.19; contract NounsDAODataEvents { event ProposalCandidateCreated( address indexed msgSender, address[] targets, uint256[] values, string[] signatures, bytes[] calldatas, string description, string slug, uint256 proposalIdToUpdate, bytes32 encodedProposalHash ); event ProposalCandidateUpdated( address indexed msgSender, address[] targets, uint256[] values, string[] signatures, bytes[] calldatas, string description, string slug, uint256 proposalIdToUpdate, bytes32 encodedProposalHash, string reason ); event ProposalCandidateCanceled(address indexed msgSender, string slug); event SignatureAdded( address indexed signer, bytes sig, uint256 expirationTimestamp, address proposer, string slug, uint256 proposalIdToUpdate, bytes32 encodedPropHash, bytes32 sigDigest, string reason ); event FeedbackSent(address indexed msgSender, uint256 proposalId, uint8 support, string reason); event CandidateFeedbackSent( address indexed msgSender, address indexed proposer, string slug, uint8 support, string reason ); event CreateCandidateCostSet(uint256 oldCreateCandidateCost, uint256 newCreateCandidateCost); event UpdateCandidateCostSet(uint256 oldUpdateCandidateCost, uint256 newUpdateCandidateCost); event ETHWithdrawn(address indexed to, uint256 amount); event FeeRecipientSet(address indexed oldFeeRecipient, address indexed newFeeRecipient); }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.0 (utils/Context.sol) pragma solidity ^0.8.0; import "../proxy/utils/Initializable.sol"; /** * @dev Provides information about the current execution context, including the * sender of the transaction and its data. While these are generally available * via msg.sender and msg.data, they should not be accessed in such a direct * manner, since when dealing with meta-transactions the account sending and * paying for execution may not be the actual sender (as far as an application * is concerned). * * This contract is only required for intermediate, library-like contracts. */ abstract contract ContextUpgradeable is Initializable { function __Context_init() internal initializer { __Context_init_unchained(); } function __Context_init_unchained() internal initializer { } function _msgSender() internal view virtual returns (address) { return msg.sender; } function _msgData() internal view virtual returns (bytes calldata) { return msg.data; } uint256[50] private __gap; }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.0 (proxy/utils/Initializable.sol) pragma solidity ^0.8.0; /** * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed * behind a proxy. Since a proxied contract can't have a constructor, it's common to move constructor logic to an * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect. * * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as * possible by providing the encoded function call as the `_data` argument to {ERC1967Proxy-constructor}. * * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity. * * [CAUTION] * ==== * Avoid leaving a contract uninitialized. * * An uninitialized contract can be taken over by an attacker. This applies to both a proxy and its implementation * contract, which may impact the proxy. To initialize the implementation contract, you can either invoke the * initializer manually, or you can include a constructor to automatically mark it as initialized when it is deployed: * * [.hljs-theme-light.nopadding] * ``` * /// @custom:oz-upgrades-unsafe-allow constructor * constructor() initializer {} * ``` * ==== */ abstract contract Initializable { /** * @dev Indicates that the contract has been initialized. */ bool private _initialized; /** * @dev Indicates that the contract is in the process of being initialized. */ bool private _initializing; /** * @dev Modifier to protect an initializer function from being invoked twice. */ modifier initializer() { require(_initializing || !_initialized, "Initializable: contract is already initialized"); bool isTopLevelCall = !_initializing; if (isTopLevelCall) { _initializing = true; _initialized = true; } _; if (isTopLevelCall) { _initializing = false; } } }
// SPDX-License-Identifier: GPL-3.0 /// @title Library for NounsDAOLogicV3 contract containing functions related to quorum calculations /********************************* * ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ * * ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ * * ░░░░░░█████████░░█████████░░░ * * ░░░░░░██░░░████░░██░░░████░░░ * * ░░██████░░░████████░░░████░░░ * * ░░██░░██░░░████░░██░░░████░░░ * * ░░██░░██░░░████░░██░░░████░░░ * * ░░░░░░█████████░░█████████░░░ * * ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ * * ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ * *********************************/ pragma solidity ^0.8.19; import './NounsDAOInterfaces.sol'; import { NounsDAOV3Fork } from './fork/NounsDAOV3Fork.sol'; library NounsDAOV3DynamicQuorum { using NounsDAOV3Fork for NounsDAOStorageV3.StorageV3; error UnsafeUint16Cast(); /** * @notice Quorum votes required for a specific proposal to succeed * Differs from `GovernerBravo` which uses fixed amount */ function quorumVotes(NounsDAOStorageV3.StorageV3 storage ds, uint256 proposalId) internal view returns (uint256) { NounsDAOStorageV3.Proposal storage proposal = ds._proposals[proposalId]; if (proposal.totalSupply == 0) { return proposal.quorumVotes; } return dynamicQuorumVotes( proposal.againstVotes, proposal.totalSupply, getDynamicQuorumParamsAt(ds, proposal.creationBlock) ); } /** * @notice Calculates the required quorum of for-votes based on the amount of against-votes * The more against-votes there are for a proposal, the higher the required quorum is. * The quorum BPS is between `params.minQuorumVotesBPS` and params.maxQuorumVotesBPS. * The additional quorum is calculated as: * quorumCoefficient * againstVotesBPS * @dev Note the coefficient is a fixed point integer with 6 decimals * @param againstVotes Number of against-votes in the proposal * @param totalSupply The total supply of Nouns at the time of proposal creation * @param params Configurable parameters for calculating the quorum based on againstVotes. See `DynamicQuorumParams` definition for additional details. * @return quorumVotes The required quorum */ function dynamicQuorumVotes( uint256 againstVotes, uint256 totalSupply, NounsDAOStorageV3.DynamicQuorumParams memory params ) public pure returns (uint256) { uint256 againstVotesBPS = (10000 * againstVotes) / totalSupply; uint256 quorumAdjustmentBPS = (params.quorumCoefficient * againstVotesBPS) / 1e6; uint256 adjustedQuorumBPS = params.minQuorumVotesBPS + quorumAdjustmentBPS; uint256 quorumBPS = min(params.maxQuorumVotesBPS, adjustedQuorumBPS); return bps2Uint(quorumBPS, totalSupply); } /** * @notice returns the dynamic quorum parameters values at a certain block number * @dev The checkpoints array must not be empty, and the block number must be higher than or equal to * the block of the first checkpoint * @param blockNumber_ the block number to get the params at * @return The dynamic quorum parameters that were set at the given block number */ function getDynamicQuorumParamsAt(NounsDAOStorageV3.StorageV3 storage ds, uint256 blockNumber_) internal view returns (NounsDAOStorageV3.DynamicQuorumParams memory) { uint32 blockNumber = safe32(blockNumber_, 'NounsDAO::getDynamicQuorumParamsAt: block number exceeds 32 bits'); uint256 len = ds.quorumParamsCheckpoints.length; if (len == 0) { return NounsDAOStorageV3.DynamicQuorumParams({ minQuorumVotesBPS: safe16(ds.quorumVotesBPS), maxQuorumVotesBPS: safe16(ds.quorumVotesBPS), quorumCoefficient: 0 }); } if (ds.quorumParamsCheckpoints[len - 1].fromBlock <= blockNumber) { return ds.quorumParamsCheckpoints[len - 1].params; } if (ds.quorumParamsCheckpoints[0].fromBlock > blockNumber) { return NounsDAOStorageV3.DynamicQuorumParams({ minQuorumVotesBPS: safe16(ds.quorumVotesBPS), maxQuorumVotesBPS: safe16(ds.quorumVotesBPS), quorumCoefficient: 0 }); } uint256 lower = 0; uint256 upper = len - 1; while (upper > lower) { uint256 center = upper - (upper - lower) / 2; NounsDAOStorageV3.DynamicQuorumParamsCheckpoint memory cp = ds.quorumParamsCheckpoints[center]; if (cp.fromBlock == blockNumber) { return cp.params; } else if (cp.fromBlock < blockNumber) { lower = center; } else { upper = center - 1; } } return ds.quorumParamsCheckpoints[lower].params; } /** * @notice Current min quorum votes using Nouns adjusted total supply */ function minQuorumVotes(NounsDAOStorageV3.StorageV3 storage ds, uint256 adjustedTotalSupply) internal view returns (uint256) { return bps2Uint(getDynamicQuorumParamsAt(ds, block.number).minQuorumVotesBPS, adjustedTotalSupply); } /** * @notice Current max quorum votes using Nouns adjusted total supply */ function maxQuorumVotes(NounsDAOStorageV3.StorageV3 storage ds, uint256 adjustedTotalSupply) internal view returns (uint256) { return bps2Uint(getDynamicQuorumParamsAt(ds, block.number).maxQuorumVotesBPS, adjustedTotalSupply); } function safe32(uint256 n, string memory errorMessage) internal pure returns (uint32) { require(n <= type(uint32).max, errorMessage); return uint32(n); } function safe16(uint256 n) internal pure returns (uint16) { if (n > type(uint16).max) { revert UnsafeUint16Cast(); } return uint16(n); } function min(uint256 a, uint256 b) internal pure returns (uint256) { return a < b ? a : b; } function bps2Uint(uint256 bps, uint256 number) internal pure returns (uint256) { return (number * bps) / 10000; } }
// SPDX-License-Identifier: GPL-3.0 /// @title Library for NounsDAOLogicV3 contract containing the dao fork logic /********************************* * ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ * * ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ * * ░░░░░░█████████░░█████████░░░ * * ░░░░░░██░░░████░░██░░░████░░░ * * ░░██████░░░████████░░░████░░░ * * ░░██░░██░░░████░░██░░░████░░░ * * ░░██░░██░░░████░░██░░░████░░░ * * ░░░░░░█████████░░█████████░░░ * * ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ * * ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ * *********************************/ pragma solidity ^0.8.19; import { NounsDAOStorageV3, INounsDAOForkEscrow, INounsDAOExecutorV2 } from '../NounsDAOInterfaces.sol'; import { IERC20 } from '@openzeppelin/contracts/token/ERC20/IERC20.sol'; import { NounsTokenFork } from './newdao/token/NounsTokenFork.sol'; library NounsDAOV3Fork { error ForkThresholdNotMet(); error ForkPeriodNotActive(); error ForkPeriodActive(); error AdminOnly(); error UseAlternativeWithdrawFunction(); /// @notice Emitted when someones adds nouns to the fork escrow event EscrowedToFork( uint32 indexed forkId, address indexed owner, uint256[] tokenIds, uint256[] proposalIds, string reason ); /// @notice Emitted when the owner withdraws their nouns from the fork escrow event WithdrawFromForkEscrow(uint32 indexed forkId, address indexed owner, uint256[] tokenIds); /// @notice Emitted when the fork is executed and the forking period begins event ExecuteFork( uint32 indexed forkId, address forkTreasury, address forkToken, uint256 forkEndTimestamp, uint256 tokensInEscrow ); /// @notice Emitted when someone joins a fork during the forking period event JoinFork( uint32 indexed forkId, address indexed owner, uint256[] tokenIds, uint256[] proposalIds, string reason ); /// @notice Emitted when the DAO withdraws nouns from the fork escrow after a fork has been executed event DAOWithdrawNounsFromEscrow(uint256[] tokenIds, address to); /// @notice Emitted when withdrawing nouns from escrow increases adjusted total supply event DAONounsSupplyIncreasedFromEscrow(uint256 numTokens, address to); /** * @notice Escrow Nouns to contribute to the fork threshold * @dev Requires approving the tokenIds or the entire noun token to the DAO contract * @param tokenIds the tokenIds to escrow. They will be sent to the DAO once the fork threshold is reached and the escrow is closed. * @param proposalIds array of proposal ids which are the reason for wanting to fork. This will only be used to emit event. * @param reason the reason for want to fork. This will only be used to emit event. */ function escrowToFork( NounsDAOStorageV3.StorageV3 storage ds, uint256[] calldata tokenIds, uint256[] calldata proposalIds, string calldata reason ) external { if (isForkPeriodActive(ds)) revert ForkPeriodActive(); INounsDAOForkEscrow forkEscrow = ds.forkEscrow; for (uint256 i = 0; i < tokenIds.length; i++) { ds.nouns.safeTransferFrom(msg.sender, address(forkEscrow), tokenIds[i]); } emit EscrowedToFork(forkEscrow.forkId(), msg.sender, tokenIds, proposalIds, reason); } /** * @notice Withdraw Nouns from the fork escrow. Only possible if the fork has not been executed. * Only allowed to withdraw tokens that the sender has escrowed. * @param tokenIds the tokenIds to withdraw */ function withdrawFromForkEscrow(NounsDAOStorageV3.StorageV3 storage ds, uint256[] calldata tokenIds) external { if (isForkPeriodActive(ds)) revert ForkPeriodActive(); INounsDAOForkEscrow forkEscrow = ds.forkEscrow; forkEscrow.returnTokensToOwner(msg.sender, tokenIds); emit WithdrawFromForkEscrow(forkEscrow.forkId(), msg.sender, tokenIds); } /** * @notice Execute the fork. Only possible if the fork threshold has been exceeded. * This will deploy a new DAO and send the prorated part of the treasury to the new DAO's treasury. * This will also close the active escrow and all nouns in the escrow will belong to the original DAO. * @return forkTreasury The address of the new DAO's treasury * @return forkToken The address of the new DAO's token */ function executeFork(NounsDAOStorageV3.StorageV3 storage ds) external returns (address forkTreasury, address forkToken) { if (isForkPeriodActive(ds)) revert ForkPeriodActive(); INounsDAOForkEscrow forkEscrow = ds.forkEscrow; uint256 tokensInEscrow = forkEscrow.numTokensInEscrow(); if (tokensInEscrow <= forkThreshold(ds)) revert ForkThresholdNotMet(); uint256 forkEndTimestamp = block.timestamp + ds.forkPeriod; (forkTreasury, forkToken) = ds.forkDAODeployer.deployForkDAO(forkEndTimestamp, forkEscrow); sendProRataTreasury(ds, forkTreasury, tokensInEscrow, adjustedTotalSupply(ds)); uint32 forkId = forkEscrow.closeEscrow(); ds.forkDAOTreasury = forkTreasury; ds.forkDAOToken = forkToken; ds.forkEndTimestamp = forkEndTimestamp; emit ExecuteFork(forkId, forkTreasury, forkToken, forkEndTimestamp, tokensInEscrow); } /** * @notice Joins a fork while a fork is active * Sends the tokens to the timelock contract. * Sends a prorated part of the treasury to the new fork DAO's treasury. * Mints new tokens in the new fork DAO with the same token ids. * @param tokenIds the tokenIds to send to the DAO in exchange for joining the fork */ function joinFork( NounsDAOStorageV3.StorageV3 storage ds, uint256[] calldata tokenIds, uint256[] calldata proposalIds, string calldata reason ) external { if (!isForkPeriodActive(ds)) revert ForkPeriodNotActive(); INounsDAOForkEscrow forkEscrow = ds.forkEscrow; address timelock = address(ds.timelock); sendProRataTreasury(ds, ds.forkDAOTreasury, tokenIds.length, adjustedTotalSupply(ds)); for (uint256 i = 0; i < tokenIds.length; i++) { ds.nouns.transferFrom(msg.sender, timelock, tokenIds[i]); } NounsTokenFork(ds.forkDAOToken).claimDuringForkPeriod(msg.sender, tokenIds); emit JoinFork(forkEscrow.forkId() - 1, msg.sender, tokenIds, proposalIds, reason); } /** * @notice Withdraws nouns from the fork escrow to the treasury after the fork has been executed * @dev Only the DAO can call this function * @param tokenIds the tokenIds to withdraw */ function withdrawDAONounsFromEscrowToTreasury(NounsDAOStorageV3.StorageV3 storage ds, uint256[] calldata tokenIds) external { withdrawDAONounsFromEscrow(ds, tokenIds, address(ds.timelock)); } /** * @notice Withdraws nouns from the fork escrow after the fork has been executed to an address other than the treasury * @dev Only the DAO can call this function * @param tokenIds the tokenIds to withdraw * @param to the address to send the nouns to */ function withdrawDAONounsFromEscrowIncreasingTotalSupply( NounsDAOStorageV3.StorageV3 storage ds, uint256[] calldata tokenIds, address to ) external { if (to == address(ds.timelock)) revert UseAlternativeWithdrawFunction(); withdrawDAONounsFromEscrow(ds, tokenIds, to); emit DAONounsSupplyIncreasedFromEscrow(tokenIds.length, to); } function withdrawDAONounsFromEscrow( NounsDAOStorageV3.StorageV3 storage ds, uint256[] calldata tokenIds, address to ) private { if (msg.sender != ds.admin) { revert AdminOnly(); } ds.forkEscrow.withdrawTokens(tokenIds, to); emit DAOWithdrawNounsFromEscrow(tokenIds, to); } /** * @notice Returns the required number of tokens to escrow to trigger a fork */ function forkThreshold(NounsDAOStorageV3.StorageV3 storage ds) public view returns (uint256) { return (adjustedTotalSupply(ds) * ds.forkThresholdBPS) / 10_000; } /** * @notice Returns the number of tokens currently in escrow, contributing to the fork threshold */ function numTokensInForkEscrow(NounsDAOStorageV3.StorageV3 storage ds) public view returns (uint256) { return ds.forkEscrow.numTokensInEscrow(); } /** * @notice Returns the number of nouns in supply minus nouns owned by the DAO, i.e. held in the treasury or in an * escrow after it has closed. * This is used when calculating proposal threshold, quorum, fork threshold & treasury split. */ function adjustedTotalSupply(NounsDAOStorageV3.StorageV3 storage ds) internal view returns (uint256) { return ds.nouns.totalSupply() - ds.nouns.balanceOf(address(ds.timelock)) - ds.forkEscrow.numTokensOwnedByDAO(); } /** * @notice Returns true if noun holders can currently join a fork */ function isForkPeriodActive(NounsDAOStorageV3.StorageV3 storage ds) internal view returns (bool) { return ds.forkEndTimestamp > block.timestamp; } /** * @notice Sends part of the DAO's treasury to the `newDAOTreasury` address. * The amount sent is proportional to the `tokenCount` out of `totalSupply`. * Sends ETH and ERC20 tokens listed in `ds.erc20TokensToIncludeInFork`. */ function sendProRataTreasury( NounsDAOStorageV3.StorageV3 storage ds, address newDAOTreasury, uint256 tokenCount, uint256 totalSupply ) internal { INounsDAOExecutorV2 timelock = ds.timelock; uint256 ethToSend = (address(timelock).balance * tokenCount) / totalSupply; timelock.sendETH(newDAOTreasury, ethToSend); uint256 erc20Count = ds.erc20TokensToIncludeInFork.length; for (uint256 i = 0; i < erc20Count; ++i) { IERC20 erc20token = IERC20(ds.erc20TokensToIncludeInFork[i]); uint256 tokensToSend = (erc20token.balanceOf(address(timelock)) * tokenCount) / totalSupply; if (tokensToSend > 0) { timelock.sendERC20(newDAOTreasury, address(erc20token), tokensToSend); } } } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.9.0) (utils/cryptography/ECDSA.sol) pragma solidity ^0.8.0; import { Strings } from '@openzeppelin/contracts/utils/Strings.sol'; /** * @dev Elliptic Curve Digital Signature Algorithm (ECDSA) operations. * * These functions can be used to verify that a message was signed by the holder * of the private keys of a given address. */ library ECDSA { enum RecoverError { NoError, InvalidSignature, InvalidSignatureLength, InvalidSignatureS, InvalidSignatureV // Deprecated in v4.8 } function _throwError(RecoverError error) private pure { if (error == RecoverError.NoError) { return; // no error: do nothing } else if (error == RecoverError.InvalidSignature) { revert('ECDSA: invalid signature'); } else if (error == RecoverError.InvalidSignatureLength) { revert('ECDSA: invalid signature length'); } else if (error == RecoverError.InvalidSignatureS) { revert("ECDSA: invalid signature 's' value"); } } /** * @dev Returns the address that signed a hashed message (`hash`) with * `signature` or error string. This address can then be used for verification purposes. * * The `ecrecover` EVM opcode allows for malleable (non-unique) signatures: * this function rejects them by requiring the `s` value to be in the lower * half order, and the `v` value to be either 27 or 28. * * IMPORTANT: `hash` _must_ be the result of a hash operation for the * verification to be secure: it is possible to craft signatures that * recover to arbitrary addresses for non-hashed data. A safe way to ensure * this is by receiving a hash of the original message (which may otherwise * be too long), and then calling {toEthSignedMessageHash} on it. * * Documentation for signature generation: * - with https://web3js.readthedocs.io/en/v1.3.4/web3-eth-accounts.html#sign[Web3.js] * - with https://docs.ethers.io/v5/api/signer/#Signer-signMessage[ethers] * * _Available since v4.3._ */ function tryRecover(bytes32 hash, bytes memory signature) internal pure returns (address, RecoverError) { if (signature.length == 65) { bytes32 r; bytes32 s; uint8 v; // ecrecover takes the signature parameters, and the only way to get them // currently is to use assembly. /// @solidity memory-safe-assembly assembly { r := mload(add(signature, 0x20)) s := mload(add(signature, 0x40)) v := byte(0, mload(add(signature, 0x60))) } return tryRecover(hash, v, r, s); } else { return (address(0), RecoverError.InvalidSignatureLength); } } /** * @dev Returns the address that signed a hashed message (`hash`) with * `signature`. This address can then be used for verification purposes. * * The `ecrecover` EVM opcode allows for malleable (non-unique) signatures: * this function rejects them by requiring the `s` value to be in the lower * half order, and the `v` value to be either 27 or 28. * * IMPORTANT: `hash` _must_ be the result of a hash operation for the * verification to be secure: it is possible to craft signatures that * recover to arbitrary addresses for non-hashed data. A safe way to ensure * this is by receiving a hash of the original message (which may otherwise * be too long), and then calling {toEthSignedMessageHash} on it. */ function recover(bytes32 hash, bytes memory signature) internal pure returns (address) { (address recovered, RecoverError error) = tryRecover(hash, signature); _throwError(error); return recovered; } /** * @dev Overload of {ECDSA-tryRecover} that receives the `r` and `vs` short-signature fields separately. * * See https://eips.ethereum.org/EIPS/eip-2098[EIP-2098 short signatures] * * _Available since v4.3._ */ function tryRecover( bytes32 hash, bytes32 r, bytes32 vs ) internal pure returns (address, RecoverError) { bytes32 s = vs & bytes32(0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff); uint8 v = uint8((uint256(vs) >> 255) + 27); return tryRecover(hash, v, r, s); } /** * @dev Overload of {ECDSA-recover} that receives the `r and `vs` short-signature fields separately. * * _Available since v4.2._ */ function recover( bytes32 hash, bytes32 r, bytes32 vs ) internal pure returns (address) { (address recovered, RecoverError error) = tryRecover(hash, r, vs); _throwError(error); return recovered; } /** * @dev Overload of {ECDSA-tryRecover} that receives the `v`, * `r` and `s` signature fields separately. * * _Available since v4.3._ */ function tryRecover( bytes32 hash, uint8 v, bytes32 r, bytes32 s ) internal pure returns (address, RecoverError) { // EIP-2 still allows signature malleability for ecrecover(). Remove this possibility and make the signature // unique. Appendix F in the Ethereum Yellow paper (https://ethereum.github.io/yellowpaper/paper.pdf), defines // the valid range for s in (301): 0 < s < secp256k1n ÷ 2 + 1, and for v in (302): v ∈ {27, 28}. Most // signatures from current libraries generate a unique signature with an s-value in the lower half order. // // If your library generates malleable signatures, such as s-values in the upper range, calculate a new s-value // with 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141 - s1 and flip v from 27 to 28 or // vice versa. If your library also generates signatures with 0/1 for v instead 27/28, add 27 to v to accept // these malleable signatures as well. if (uint256(s) > 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5D576E7357A4501DDFE92F46681B20A0) { return (address(0), RecoverError.InvalidSignatureS); } // If the signature is valid (and not malleable), return the signer address address signer = ecrecover(hash, v, r, s); if (signer == address(0)) { return (address(0), RecoverError.InvalidSignature); } return (signer, RecoverError.NoError); } /** * @dev Overload of {ECDSA-recover} that receives the `v`, * `r` and `s` signature fields separately. */ function recover( bytes32 hash, uint8 v, bytes32 r, bytes32 s ) internal pure returns (address) { (address recovered, RecoverError error) = tryRecover(hash, v, r, s); _throwError(error); return recovered; } /** * @dev Returns an Ethereum Signed Message, created from a `hash`. This * produces hash corresponding to the one signed with the * https://eth.wiki/json-rpc/API#eth_sign[`eth_sign`] * JSON-RPC method as part of EIP-191. * * See {recover}. */ function toEthSignedMessageHash(bytes32 hash) internal pure returns (bytes32 message) { // 32 is the length in bytes of hash, // enforced by the type signature above /// @solidity memory-safe-assembly assembly { mstore(0x00, '\x19Ethereum Signed Message:\n32') mstore(0x1c, hash) message := keccak256(0x00, 0x3c) } } /** * @dev Returns an Ethereum Signed Message, created from `s`. This * produces hash corresponding to the one signed with the * https://eth.wiki/json-rpc/API#eth_sign[`eth_sign`] * JSON-RPC method as part of EIP-191. * * See {recover}. */ function toEthSignedMessageHash(bytes memory s) internal pure returns (bytes32) { return keccak256(abi.encodePacked('\x19Ethereum Signed Message:\n', Strings.toString(s.length), s)); } /** * @dev Returns an Ethereum Signed Typed Data, created from a * `domainSeparator` and a `structHash`. This produces hash corresponding * to the one signed with the * https://eips.ethereum.org/EIPS/eip-712[`eth_signTypedData`] * JSON-RPC method as part of EIP-712. * * See {recover}. */ function toTypedDataHash(bytes32 domainSeparator, bytes32 structHash) internal pure returns (bytes32 data) { /// @solidity memory-safe-assembly assembly { let ptr := mload(0x40) mstore(ptr, '\x19\x01') mstore(add(ptr, 0x02), domainSeparator) mstore(add(ptr, 0x22), structHash) data := keccak256(ptr, 0x42) } } /** * @dev Returns an Ethereum Signed Data with intended validator, created from a * `validator` and `data` according to the version 0 of EIP-191. * * See {recover}. */ function toDataWithIntendedValidatorHash(address validator, bytes memory data) internal pure returns (bytes32) { return keccak256(abi.encodePacked('\x19\x00', validator, data)); } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.0 (utils/math/SafeCast.sol) pragma solidity ^0.8.0; /** * @dev Wrappers over Solidity's uintXX/intXX casting operators with added overflow * checks. * * Downcasting from uint256/int256 in Solidity does not revert on overflow. This can * easily result in undesired exploitation or bugs, since developers usually * assume that overflows raise errors. `SafeCast` restores this intuition by * reverting the transaction when such an operation overflows. * * Using this library instead of the unchecked operations eliminates an entire * class of bugs, so it's recommended to use it always. * * Can be combined with {SafeMath} and {SignedSafeMath} to extend it to smaller types, by performing * all math on `uint256` and `int256` and then downcasting. */ library SafeCast { /** * @dev Returns the downcasted uint224 from uint256, reverting on * overflow (when the input is greater than largest uint224). * * Counterpart to Solidity's `uint224` operator. * * Requirements: * * - input must fit into 224 bits */ function toUint224(uint256 value) internal pure returns (uint224) { require(value <= type(uint224).max, "SafeCast: value doesn't fit in 224 bits"); return uint224(value); } /** * @dev Returns the downcasted uint128 from uint256, reverting on * overflow (when the input is greater than largest uint128). * * Counterpart to Solidity's `uint128` operator. * * Requirements: * * - input must fit into 128 bits */ function toUint128(uint256 value) internal pure returns (uint128) { require(value <= type(uint128).max, "SafeCast: value doesn't fit in 128 bits"); return uint128(value); } /** * @dev Returns the downcasted uint96 from uint256, reverting on * overflow (when the input is greater than largest uint96). * * Counterpart to Solidity's `uint96` operator. * * Requirements: * * - input must fit into 96 bits */ function toUint96(uint256 value) internal pure returns (uint96) { require(value <= type(uint96).max, "SafeCast: value doesn't fit in 96 bits"); return uint96(value); } /** * @dev Returns the downcasted uint64 from uint256, reverting on * overflow (when the input is greater than largest uint64). * * Counterpart to Solidity's `uint64` operator. * * Requirements: * * - input must fit into 64 bits */ function toUint64(uint256 value) internal pure returns (uint64) { require(value <= type(uint64).max, "SafeCast: value doesn't fit in 64 bits"); return uint64(value); } /** * @dev Returns the downcasted uint32 from uint256, reverting on * overflow (when the input is greater than largest uint32). * * Counterpart to Solidity's `uint32` operator. * * Requirements: * * - input must fit into 32 bits */ function toUint32(uint256 value) internal pure returns (uint32) { require(value <= type(uint32).max, "SafeCast: value doesn't fit in 32 bits"); return uint32(value); } /** * @dev Returns the downcasted uint16 from uint256, reverting on * overflow (when the input is greater than largest uint16). * * Counterpart to Solidity's `uint16` operator. * * Requirements: * * - input must fit into 16 bits */ function toUint16(uint256 value) internal pure returns (uint16) { require(value <= type(uint16).max, "SafeCast: value doesn't fit in 16 bits"); return uint16(value); } /** * @dev Returns the downcasted uint8 from uint256, reverting on * overflow (when the input is greater than largest uint8). * * Counterpart to Solidity's `uint8` operator. * * Requirements: * * - input must fit into 8 bits. */ function toUint8(uint256 value) internal pure returns (uint8) { require(value <= type(uint8).max, "SafeCast: value doesn't fit in 8 bits"); return uint8(value); } /** * @dev Converts a signed int256 into an unsigned uint256. * * Requirements: * * - input must be greater than or equal to 0. */ function toUint256(int256 value) internal pure returns (uint256) { require(value >= 0, "SafeCast: value must be positive"); return uint256(value); } /** * @dev Returns the downcasted int128 from int256, reverting on * overflow (when the input is less than smallest int128 or * greater than largest int128). * * Counterpart to Solidity's `int128` operator. * * Requirements: * * - input must fit into 128 bits * * _Available since v3.1._ */ function toInt128(int256 value) internal pure returns (int128) { require(value >= type(int128).min && value <= type(int128).max, "SafeCast: value doesn't fit in 128 bits"); return int128(value); } /** * @dev Returns the downcasted int64 from int256, reverting on * overflow (when the input is less than smallest int64 or * greater than largest int64). * * Counterpart to Solidity's `int64` operator. * * Requirements: * * - input must fit into 64 bits * * _Available since v3.1._ */ function toInt64(int256 value) internal pure returns (int64) { require(value >= type(int64).min && value <= type(int64).max, "SafeCast: value doesn't fit in 64 bits"); return int64(value); } /** * @dev Returns the downcasted int32 from int256, reverting on * overflow (when the input is less than smallest int32 or * greater than largest int32). * * Counterpart to Solidity's `int32` operator. * * Requirements: * * - input must fit into 32 bits * * _Available since v3.1._ */ function toInt32(int256 value) internal pure returns (int32) { require(value >= type(int32).min && value <= type(int32).max, "SafeCast: value doesn't fit in 32 bits"); return int32(value); } /** * @dev Returns the downcasted int16 from int256, reverting on * overflow (when the input is less than smallest int16 or * greater than largest int16). * * Counterpart to Solidity's `int16` operator. * * Requirements: * * - input must fit into 16 bits * * _Available since v3.1._ */ function toInt16(int256 value) internal pure returns (int16) { require(value >= type(int16).min && value <= type(int16).max, "SafeCast: value doesn't fit in 16 bits"); return int16(value); } /** * @dev Returns the downcasted int8 from int256, reverting on * overflow (when the input is less than smallest int8 or * greater than largest int8). * * Counterpart to Solidity's `int8` operator. * * Requirements: * * - input must fit into 8 bits. * * _Available since v3.1._ */ function toInt8(int256 value) internal pure returns (int8) { require(value >= type(int8).min && value <= type(int8).max, "SafeCast: value doesn't fit in 8 bits"); return int8(value); } /** * @dev Converts an unsigned uint256 into a signed int256. * * Requirements: * * - input must be less than or equal to maxInt256. */ function toInt256(uint256 value) internal pure returns (int256) { // Note: Unsafe cast below is okay because `type(int256).max` is guaranteed to be positive require(value <= uint256(type(int256).max), "SafeCast: value doesn't fit in an int256"); return int256(value); } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.0 (interfaces/IERC1271.sol) pragma solidity ^0.8.0; /** * @dev Interface of the ERC1271 standard signature validation method for * contracts as defined in https://eips.ethereum.org/EIPS/eip-1271[ERC-1271]. * * _Available since v4.1._ */ interface IERC1271 { /** * @dev Should return whether the signature provided is valid for the provided data * @param hash Hash of the data to be signed * @param signature Signature byte array associated with _data */ function isValidSignature(bytes32 hash, bytes memory signature) external view returns (bytes4 magicValue); }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.0 (proxy/ERC1967/ERC1967Upgrade.sol) pragma solidity ^0.8.2; import "../beacon/IBeacon.sol"; import "../../utils/Address.sol"; import "../../utils/StorageSlot.sol"; /** * @dev This abstract contract provides getters and event emitting update functions for * https://eips.ethereum.org/EIPS/eip-1967[EIP1967] slots. * * _Available since v4.1._ * * @custom:oz-upgrades-unsafe-allow delegatecall */ abstract contract ERC1967Upgrade { // This is the keccak-256 hash of "eip1967.proxy.rollback" subtracted by 1 bytes32 private constant _ROLLBACK_SLOT = 0x4910fdfa16fed3260ed0e7147f7cc6da11a60208b5b9406d12a635614ffd9143; /** * @dev Storage slot with the address of the current implementation. * This is the keccak-256 hash of "eip1967.proxy.implementation" subtracted by 1, and is * validated in the constructor. */ bytes32 internal constant _IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc; /** * @dev Emitted when the implementation is upgraded. */ event Upgraded(address indexed implementation); /** * @dev Returns the current implementation address. */ function _getImplementation() internal view returns (address) { return StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value; } /** * @dev Stores a new address in the EIP1967 implementation slot. */ function _setImplementation(address newImplementation) private { require(Address.isContract(newImplementation), "ERC1967: new implementation is not a contract"); StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value = newImplementation; } /** * @dev Perform implementation upgrade * * Emits an {Upgraded} event. */ function _upgradeTo(address newImplementation) internal { _setImplementation(newImplementation); emit Upgraded(newImplementation); } /** * @dev Perform implementation upgrade with additional setup call. * * Emits an {Upgraded} event. */ function _upgradeToAndCall( address newImplementation, bytes memory data, bool forceCall ) internal { _upgradeTo(newImplementation); if (data.length > 0 || forceCall) { Address.functionDelegateCall(newImplementation, data); } } /** * @dev Perform implementation upgrade with security checks for UUPS proxies, and additional setup call. * * Emits an {Upgraded} event. */ function _upgradeToAndCallSecure( address newImplementation, bytes memory data, bool forceCall ) internal { address oldImplementation = _getImplementation(); // Initial upgrade and setup call _setImplementation(newImplementation); if (data.length > 0 || forceCall) { Address.functionDelegateCall(newImplementation, data); } // Perform rollback test if not already in progress StorageSlot.BooleanSlot storage rollbackTesting = StorageSlot.getBooleanSlot(_ROLLBACK_SLOT); if (!rollbackTesting.value) { // Trigger rollback using upgradeTo from the new implementation rollbackTesting.value = true; Address.functionDelegateCall( newImplementation, abi.encodeWithSignature("upgradeTo(address)", oldImplementation) ); rollbackTesting.value = false; // Check rollback was effective require(oldImplementation == _getImplementation(), "ERC1967Upgrade: upgrade breaks further upgrades"); // Finally reset to the new implementation and log the upgrade _upgradeTo(newImplementation); } } /** * @dev Storage slot with the admin of the contract. * This is the keccak-256 hash of "eip1967.proxy.admin" subtracted by 1, and is * validated in the constructor. */ bytes32 internal constant _ADMIN_SLOT = 0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103; /** * @dev Emitted when the admin account has changed. */ event AdminChanged(address previousAdmin, address newAdmin); /** * @dev Returns the current admin. */ function _getAdmin() internal view returns (address) { return StorageSlot.getAddressSlot(_ADMIN_SLOT).value; } /** * @dev Stores a new address in the EIP1967 admin slot. */ function _setAdmin(address newAdmin) private { require(newAdmin != address(0), "ERC1967: new admin is the zero address"); StorageSlot.getAddressSlot(_ADMIN_SLOT).value = newAdmin; } /** * @dev Changes the admin of the proxy. * * Emits an {AdminChanged} event. */ function _changeAdmin(address newAdmin) internal { emit AdminChanged(_getAdmin(), newAdmin); _setAdmin(newAdmin); } /** * @dev The storage slot of the UpgradeableBeacon contract which defines the implementation for this proxy. * This is bytes32(uint256(keccak256('eip1967.proxy.beacon')) - 1)) and is validated in the constructor. */ bytes32 internal constant _BEACON_SLOT = 0xa3f0ad74e5423aebfd80d3ef4346578335a9a72aeaee59ff6cb3582b35133d50; /** * @dev Emitted when the beacon is upgraded. */ event BeaconUpgraded(address indexed beacon); /** * @dev Returns the current beacon. */ function _getBeacon() internal view returns (address) { return StorageSlot.getAddressSlot(_BEACON_SLOT).value; } /** * @dev Stores a new beacon in the EIP1967 beacon slot. */ function _setBeacon(address newBeacon) private { require(Address.isContract(newBeacon), "ERC1967: new beacon is not a contract"); require( Address.isContract(IBeacon(newBeacon).implementation()), "ERC1967: beacon implementation is not a contract" ); StorageSlot.getAddressSlot(_BEACON_SLOT).value = newBeacon; } /** * @dev Perform beacon upgrade with additional setup call. Note: This upgrades the address of the beacon, it does * not upgrade the implementation contained in the beacon (see {UpgradeableBeacon-_setImplementation} for that). * * Emits a {BeaconUpgraded} event. */ function _upgradeBeaconToAndCall( address newBeacon, bytes memory data, bool forceCall ) internal { _setBeacon(newBeacon); emit BeaconUpgraded(newBeacon); if (data.length > 0 || forceCall) { Address.functionDelegateCall(IBeacon(newBeacon).implementation(), data); } } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.0 (token/ERC20/IERC20.sol) pragma solidity ^0.8.0; /** * @dev Interface of the ERC20 standard as defined in the EIP. */ interface IERC20 { /** * @dev Returns the amount of tokens in existence. */ function totalSupply() external view returns (uint256); /** * @dev Returns the amount of tokens owned by `account`. */ function balanceOf(address account) external view returns (uint256); /** * @dev Moves `amount` tokens from the caller's account to `recipient`. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transfer(address recipient, uint256 amount) external returns (bool); /** * @dev Returns the remaining number of tokens that `spender` will be * allowed to spend on behalf of `owner` through {transferFrom}. This is * zero by default. * * This value changes when {approve} or {transferFrom} are called. */ function allowance(address owner, address spender) external view returns (uint256); /** * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. * * Returns a boolean value indicating whether the operation succeeded. * * IMPORTANT: Beware that changing an allowance with this method brings the risk * that someone may use both the old and the new allowance by unfortunate * transaction ordering. One possible solution to mitigate this race * condition is to first reduce the spender's allowance to 0 and set the * desired value afterwards: * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 * * Emits an {Approval} event. */ function approve(address spender, uint256 amount) external returns (bool); /** * @dev Moves `amount` tokens from `sender` to `recipient` using the * allowance mechanism. `amount` is then deducted from the caller's * allowance. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transferFrom( address sender, address recipient, uint256 amount ) external returns (bool); /** * @dev Emitted when `value` tokens are moved from one account (`from`) to * another (`to`). * * Note that `value` may be zero. */ event Transfer(address indexed from, address indexed to, uint256 value); /** * @dev Emitted when the allowance of a `spender` for an `owner` is set by * a call to {approve}. `value` is the new allowance. */ event Approval(address indexed owner, address indexed spender, uint256 value); }
// SPDX-License-Identifier: GPL-3.0 /// @title The Nouns ERC-721 token, adjusted for forks /********************************* * ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ * * ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ * * ░░░░░░█████████░░█████████░░░ * * ░░░░░░██░░░████░░██░░░████░░░ * * ░░██████░░░████████░░░████░░░ * * ░░██░░██░░░████░░██░░░████░░░ * * ░░██░░██░░░████░░██░░░████░░░ * * ░░░░░░█████████░░█████████░░░ * * ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ * * ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ * *********************************/ pragma solidity ^0.8.19; import { OwnableUpgradeable } from '@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol'; import { ERC721CheckpointableUpgradeable } from './base/ERC721CheckpointableUpgradeable.sol'; import { INounsDescriptorMinimal } from '../../../../interfaces/INounsDescriptorMinimal.sol'; import { INounsSeeder } from '../../../../interfaces/INounsSeeder.sol'; import { INounsTokenFork } from './INounsTokenFork.sol'; import { IERC721 } from '@openzeppelin/contracts/token/ERC721/IERC721.sol'; import { UUPSUpgradeable } from '@openzeppelin/contracts/proxy/utils/UUPSUpgradeable.sol'; import { INounsDAOForkEscrow } from '../../../NounsDAOInterfaces.sol'; /** * @dev This contract is a fork of NounsToken, with the following changes: * - Added upgradeablity via UUPSUpgradeable. * - Inheriting from an unmodified ERC721, so that the double Transfer event emission that * NounsToken performs is gone, in favor of the standard single event. * - Added functions to claim tokens from a Nouns Fork escrow, or during the forking period. * - Removed the proxyRegistry feature that whitelisted OpenSea. * - Removed `noundersDAO` and the founder reward every 10 mints. * For additional context see `ERC721CheckpointableUpgradeable`. */ contract NounsTokenFork is INounsTokenFork, OwnableUpgradeable, ERC721CheckpointableUpgradeable, UUPSUpgradeable { error OnlyOwner(); error OnlyTokenOwnerCanClaim(); error OnlyOriginalDAO(); error NoundersCannotBeAddressZero(); error OnlyDuringForkingPeriod(); string public constant NAME = 'NounsTokenFork'; /// @notice An address who has permissions to mint Nouns address public minter; /// @notice The Nouns token URI descriptor INounsDescriptorMinimal public descriptor; /// @notice The Nouns token seeder INounsSeeder public seeder; /// @notice The escrow contract used to verify ownership of the original Nouns in the post-fork claiming process INounsDAOForkEscrow public escrow; /// @notice The fork ID, used when querying the escrow for token ownership uint32 public forkId; /// @notice How many tokens are still available to be claimed by Nouners who put their original Nouns in escrow uint256 public remainingTokensToClaim; /// @notice The forking period expiration timestamp, after which new tokens cannot be claimed by the original DAO uint256 public forkingPeriodEndTimestamp; /// @notice Whether the minter can be updated bool public isMinterLocked; /// @notice Whether the descriptor can be updated bool public isDescriptorLocked; /// @notice Whether the seeder can be updated bool public isSeederLocked; /// @notice The noun seeds mapping(uint256 => INounsSeeder.Seed) public seeds; /// @notice The internal noun ID tracker uint256 private _currentNounId; /// @notice IPFS content hash of contract-level metadata string private _contractURIHash = 'QmZi1n79FqWt2tTLwCqiy6nLM6xLGRsEPQ5JmReJQKNNzX'; /** * @notice Require that the minter has not been locked. */ modifier whenMinterNotLocked() { require(!isMinterLocked, 'Minter is locked'); _; } /** * @notice Require that the descriptor has not been locked. */ modifier whenDescriptorNotLocked() { require(!isDescriptorLocked, 'Descriptor is locked'); _; } /** * @notice Require that the seeder has not been locked. */ modifier whenSeederNotLocked() { require(!isSeederLocked, 'Seeder is locked'); _; } /** * @notice Require that the sender is the minter. */ modifier onlyMinter() { require(msg.sender == minter, 'Sender is not the minter'); _; } constructor() initializer {} function initialize( address _owner, address _minter, INounsDAOForkEscrow _escrow, uint32 _forkId, uint256 startNounId, uint256 tokensToClaim, uint256 _forkingPeriodEndTimestamp ) external initializer { __ERC721_init('Nouns', 'NOUN'); _transferOwnership(_owner); minter = _minter; escrow = _escrow; forkId = _forkId; _currentNounId = startNounId; remainingTokensToClaim = tokensToClaim; forkingPeriodEndTimestamp = _forkingPeriodEndTimestamp; NounsTokenFork originalToken = NounsTokenFork(address(escrow.nounsToken())); descriptor = originalToken.descriptor(); seeder = originalToken.seeder(); } /** * @notice Claim new tokens if you escrowed original Nouns and forked into a new DAO governed by holders of this * token. * @dev Reverts if the sender is not the owner of the escrowed token. * @param tokenIds The token IDs to claim */ function claimFromEscrow(uint256[] calldata tokenIds) external { for (uint256 i = 0; i < tokenIds.length; i++) { uint256 nounId = tokenIds[i]; if (escrow.ownerOfEscrowedToken(forkId, nounId) != msg.sender) revert OnlyTokenOwnerCanClaim(); _mintWithOriginalSeed(msg.sender, nounId); } remainingTokensToClaim -= tokenIds.length; } /** * @notice The original DAO can claim tokens during the forking period, on behalf of Nouners who choose to join * a new fork DAO. Does not allow the original DAO to claim once the forking period has ended. * @dev Assumes the original DAO is honest during the forking period. * @param to The recipient of the tokens * @param tokenIds The token IDs to claim */ function claimDuringForkPeriod(address to, uint256[] calldata tokenIds) external { uint256 currentNounId = _currentNounId; uint256 maxNounId = 0; if (msg.sender != escrow.dao()) revert OnlyOriginalDAO(); if (block.timestamp >= forkingPeriodEndTimestamp) revert OnlyDuringForkingPeriod(); for (uint256 i = 0; i < tokenIds.length; i++) { uint256 nounId = tokenIds[i]; _mintWithOriginalSeed(to, nounId); if (tokenIds[i] > maxNounId) maxNounId = tokenIds[i]; } // This treats an important case: // During a forking period, people can buy new Nouns on auction, with a higher ID than the auction ID at forking // They can then join the fork with those IDs // If we don't increment currentNounId, unpausing the fork auction house would revert // Since it would attempt to mint a noun with an ID that already exists if (maxNounId >= currentNounId) _currentNounId = maxNounId + 1; } /** * @notice The IPFS URI of contract-level metadata. */ function contractURI() public view returns (string memory) { return string(abi.encodePacked('ipfs://', _contractURIHash)); } /** * @notice Set the _contractURIHash. * @dev Only callable by the owner. */ function setContractURIHash(string memory newContractURIHash) external onlyOwner { _contractURIHash = newContractURIHash; } /** * @notice Mint a Noun to the minter * @dev Call _mintTo with the to address(es). */ function mint() public override onlyMinter returns (uint256) { return _mintTo(minter, _currentNounId++); } /** * @notice Burn a noun. */ function burn(uint256 nounId) public override onlyMinter { _burn(nounId); emit NounBurned(nounId); } /** * @notice A distinct Uniform Resource Identifier (URI) for a given asset. * @dev See {IERC721Metadata-tokenURI}. */ function tokenURI(uint256 tokenId) public view override returns (string memory) { require(_exists(tokenId), 'NounsToken: URI query for nonexistent token'); return descriptor.tokenURI(tokenId, seeds[tokenId]); } /** * @notice Similar to `tokenURI`, but always serves a base64 encoded data URI * with the JSON contents directly inlined. */ function dataURI(uint256 tokenId) public view override returns (string memory) { require(_exists(tokenId), 'NounsToken: URI query for nonexistent token'); return descriptor.dataURI(tokenId, seeds[tokenId]); } /** * @notice Set the token minter. * @dev Only callable by the owner when not locked. */ function setMinter(address _minter) external override onlyOwner whenMinterNotLocked { minter = _minter; emit MinterUpdated(_minter); } /** * @notice Lock the minter. * @dev This cannot be reversed and is only callable by the owner when not locked. */ function lockMinter() external override onlyOwner whenMinterNotLocked { isMinterLocked = true; emit MinterLocked(); } /** * @notice Set the token URI descriptor. * @dev Only callable by the owner when not locked. */ function setDescriptor(INounsDescriptorMinimal _descriptor) external override onlyOwner whenDescriptorNotLocked { descriptor = _descriptor; emit DescriptorUpdated(_descriptor); } /** * @notice Lock the descriptor. * @dev This cannot be reversed and is only callable by the owner when not locked. */ function lockDescriptor() external override onlyOwner whenDescriptorNotLocked { isDescriptorLocked = true; emit DescriptorLocked(); } /** * @notice Set the token seeder. * @dev Only callable by the owner when not locked. */ function setSeeder(INounsSeeder _seeder) external override onlyOwner whenSeederNotLocked { seeder = _seeder; emit SeederUpdated(_seeder); } /** * @notice Lock the seeder. * @dev This cannot be reversed and is only callable by the owner when not locked. */ function lockSeeder() external override onlyOwner whenSeederNotLocked { isSeederLocked = true; emit SeederLocked(); } /** * @notice Mint a Noun with `nounId` to the provided `to` address. */ function _mintTo(address to, uint256 nounId) internal returns (uint256) { INounsSeeder.Seed memory seed = seeds[nounId] = seeder.generateSeed(nounId, descriptor); _mint(to, nounId); emit NounCreated(nounId, seed); return nounId; } /** * @notice Mint a new token using the original Nouns seed. */ function _mintWithOriginalSeed(address to, uint256 nounId) internal { (uint48 background, uint48 body, uint48 accessory, uint48 head, uint48 glasses) = NounsTokenFork( address(escrow.nounsToken()) ).seeds(nounId); INounsSeeder.Seed memory seed = INounsSeeder.Seed(background, body, accessory, head, glasses); seeds[nounId] = seed; _mint(to, nounId); emit NounCreated(nounId, seed); } /** * @dev Reverts when `msg.sender` is not the owner of this contract; in the case of Noun DAOs it should be the * DAO's treasury contract. */ function _authorizeUpgrade(address) internal view override onlyOwner {} }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.0 (utils/Strings.sol) pragma solidity ^0.8.0; /** * @dev String operations. */ library Strings { bytes16 private constant _HEX_SYMBOLS = "0123456789abcdef"; /** * @dev Converts a `uint256` to its ASCII `string` decimal representation. */ function toString(uint256 value) internal pure returns (string memory) { // Inspired by OraclizeAPI's implementation - MIT licence // https://github.com/oraclize/ethereum-api/blob/b42146b063c7d6ee1358846c198246239e9360e8/oraclizeAPI_0.4.25.sol if (value == 0) { return "0"; } uint256 temp = value; uint256 digits; while (temp != 0) { digits++; temp /= 10; } bytes memory buffer = new bytes(digits); while (value != 0) { digits -= 1; buffer[digits] = bytes1(uint8(48 + uint256(value % 10))); value /= 10; } return string(buffer); } /** * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation. */ function toHexString(uint256 value) internal pure returns (string memory) { if (value == 0) { return "0x00"; } uint256 temp = value; uint256 length = 0; while (temp != 0) { length++; temp >>= 8; } return toHexString(value, length); } /** * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length. */ function toHexString(uint256 value, uint256 length) internal pure returns (string memory) { bytes memory buffer = new bytes(2 * length + 2); buffer[0] = "0"; buffer[1] = "x"; for (uint256 i = 2 * length + 1; i > 1; --i) { buffer[i] = _HEX_SYMBOLS[value & 0xf]; value >>= 4; } require(value == 0, "Strings: hex length insufficient"); return string(buffer); } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.0 (proxy/beacon/IBeacon.sol) pragma solidity ^0.8.0; /** * @dev This is the interface that {BeaconProxy} expects of its beacon. */ interface IBeacon { /** * @dev Must return an address that can be used as a delegate call target. * * {BeaconProxy} will check that this address is a contract. */ function implementation() external view returns (address); }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.0 (utils/Address.sol) pragma solidity ^0.8.0; /** * @dev Collection of functions related to the address type */ library Address { /** * @dev Returns true if `account` is a contract. * * [IMPORTANT] * ==== * It is unsafe to assume that an address for which this function returns * false is an externally-owned account (EOA) and not a contract. * * Among others, `isContract` will return false for the following * types of addresses: * * - an externally-owned account * - a contract in construction * - an address where a contract will be created * - an address where a contract lived, but was destroyed * ==== */ function isContract(address account) internal view returns (bool) { // This method relies on extcodesize, which returns 0 for contracts in // construction, since the code is only stored at the end of the // constructor execution. uint256 size; assembly { size := extcodesize(account) } return size > 0; } /** * @dev Replacement for Solidity's `transfer`: sends `amount` wei to * `recipient`, forwarding all available gas and reverting on errors. * * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost * of certain opcodes, possibly making contracts go over the 2300 gas limit * imposed by `transfer`, making them unable to receive funds via * `transfer`. {sendValue} removes this limitation. * * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. * * IMPORTANT: because control is transferred to `recipient`, care must be * taken to not create reentrancy vulnerabilities. Consider using * {ReentrancyGuard} or the * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. */ function sendValue(address payable recipient, uint256 amount) internal { require(address(this).balance >= amount, "Address: insufficient balance"); (bool success, ) = recipient.call{value: amount}(""); require(success, "Address: unable to send value, recipient may have reverted"); } /** * @dev Performs a Solidity function call using a low level `call`. A * plain `call` is an unsafe replacement for a function call: use this * function instead. * * If `target` reverts with a revert reason, it is bubbled up by this * function (like regular Solidity function calls). * * Returns the raw returned data. To convert to the expected return value, * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. * * Requirements: * * - `target` must be a contract. * - calling `target` with `data` must not revert. * * _Available since v3.1._ */ function functionCall(address target, bytes memory data) internal returns (bytes memory) { return functionCall(target, data, "Address: low-level call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with * `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCall( address target, bytes memory data, string memory errorMessage ) internal returns (bytes memory) { return functionCallWithValue(target, data, 0, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but also transferring `value` wei to `target`. * * Requirements: * * - the calling contract must have an ETH balance of at least `value`. * - the called Solidity function must be `payable`. * * _Available since v3.1._ */ function functionCallWithValue( address target, bytes memory data, uint256 value ) internal returns (bytes memory) { return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); } /** * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but * with `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCallWithValue( address target, bytes memory data, uint256 value, string memory errorMessage ) internal returns (bytes memory) { require(address(this).balance >= value, "Address: insufficient balance for call"); require(isContract(target), "Address: call to non-contract"); (bool success, bytes memory returndata) = target.call{value: value}(data); return verifyCallResult(success, returndata, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but performing a static call. * * _Available since v3.3._ */ function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) { return functionStaticCall(target, data, "Address: low-level static call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`], * but performing a static call. * * _Available since v3.3._ */ function functionStaticCall( address target, bytes memory data, string memory errorMessage ) internal view returns (bytes memory) { require(isContract(target), "Address: static call to non-contract"); (bool success, bytes memory returndata) = target.staticcall(data); return verifyCallResult(success, returndata, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but performing a delegate call. * * _Available since v3.4._ */ function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) { return functionDelegateCall(target, data, "Address: low-level delegate call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`], * but performing a delegate call. * * _Available since v3.4._ */ function functionDelegateCall( address target, bytes memory data, string memory errorMessage ) internal returns (bytes memory) { require(isContract(target), "Address: delegate call to non-contract"); (bool success, bytes memory returndata) = target.delegatecall(data); return verifyCallResult(success, returndata, errorMessage); } /** * @dev Tool to verifies that a low level call was successful, and revert if it wasn't, either by bubbling the * revert reason using the provided one. * * _Available since v4.3._ */ function verifyCallResult( bool success, bytes memory returndata, string memory errorMessage ) internal pure returns (bytes memory) { if (success) { return returndata; } else { // Look for revert reason and bubble it up if present if (returndata.length > 0) { // The easiest way to bubble the revert reason is using memory via assembly assembly { let returndata_size := mload(returndata) revert(add(32, returndata), returndata_size) } } else { revert(errorMessage); } } } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.0 (utils/StorageSlot.sol) pragma solidity ^0.8.0; /** * @dev Library for reading and writing primitive types to specific storage slots. * * Storage slots are often used to avoid storage conflict when dealing with upgradeable contracts. * This library helps with reading and writing to such slots without the need for inline assembly. * * The functions in this library return Slot structs that contain a `value` member that can be used to read or write. * * Example usage to set ERC1967 implementation slot: * ``` * contract ERC1967 { * bytes32 internal constant _IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc; * * function _getImplementation() internal view returns (address) { * return StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value; * } * * function _setImplementation(address newImplementation) internal { * require(Address.isContract(newImplementation), "ERC1967: new implementation is not a contract"); * StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value = newImplementation; * } * } * ``` * * _Available since v4.1 for `address`, `bool`, `bytes32`, and `uint256`._ */ library StorageSlot { struct AddressSlot { address value; } struct BooleanSlot { bool value; } struct Bytes32Slot { bytes32 value; } struct Uint256Slot { uint256 value; } /** * @dev Returns an `AddressSlot` with member `value` located at `slot`. */ function getAddressSlot(bytes32 slot) internal pure returns (AddressSlot storage r) { assembly { r.slot := slot } } /** * @dev Returns an `BooleanSlot` with member `value` located at `slot`. */ function getBooleanSlot(bytes32 slot) internal pure returns (BooleanSlot storage r) { assembly { r.slot := slot } } /** * @dev Returns an `Bytes32Slot` with member `value` located at `slot`. */ function getBytes32Slot(bytes32 slot) internal pure returns (Bytes32Slot storage r) { assembly { r.slot := slot } } /** * @dev Returns an `Uint256Slot` with member `value` located at `slot`. */ function getUint256Slot(bytes32 slot) internal pure returns (Uint256Slot storage r) { assembly { r.slot := slot } } }
// SPDX-License-Identifier: BSD-3-Clause /// @title Vote checkpointing for an ERC-721 token /********************************* * ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ * * ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ * * ░░░░░░█████████░░█████████░░░ * * ░░░░░░██░░░████░░██░░░████░░░ * * ░░██████░░░████████░░░████░░░ * * ░░██░░██░░░████░░██░░░████░░░ * * ░░██░░██░░░████░░██░░░████░░░ * * ░░░░░░█████████░░█████████░░░ * * ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ * * ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ * *********************************/ // LICENSE // ERC721CheckpointableUpgradeable.sol is a modified version of ERC721Checkpointable.sol in this repository. // ERC721Checkpointable.sol uses and modifies part of Compound Lab's Comp.sol: // https://github.com/compound-finance/compound-protocol/blob/ae4388e780a8d596d97619d9704a931a2752c2bc/contracts/Governance/Comp.sol // // Comp.sol source code Copyright 2020 Compound Labs, Inc. licensed under the BSD-3-Clause license. // With modifications by Nounders DAO. // // Additional conditions of BSD-3-Clause can be found here: https://opensource.org/licenses/BSD-3-Clause // // ERC721CheckpointableUpgradeable.sol MODIFICATIONS: // - Inherits from OpenZeppelin's ERC721EnumerableUpgradeable.sol, removing the original modification Nouns made to // ERC721.sol, where for each mint two Transfer events were emitted; this modified implementation sticks with the // OpenZeppelin standard. // - More importantly, this inheritance change makes the token upgradable, which we deemed important in the context of // forks, in order to give new Nouns forks enough of a chance to modify their contracts to the new DAO's needs. // - Fixes a critical bug in `delegateBySig`, where the previous version allowed delegating to address zero, which then // reverts whenever that owner tries to delegate anew or transfer their tokens. The fix is simply to revert on any // attempt to delegate to address zero. // // ERC721Checkpointable.sol MODIFICATIONS: // Checkpointing logic from Comp.sol has been used with the following modifications: // - `delegates` is renamed to `_delegates` and is set to private // - `delegates` is a public function that uses the `_delegates` mapping look-up, but unlike // Comp.sol, returns the delegator's own address if there is no delegate. // This avoids the delegator needing to "delegate to self" with an additional transaction // - `_transferTokens()` is renamed `_beforeTokenTransfer()` and adapted to hook into OpenZeppelin's ERC721 hooks. pragma solidity ^0.8.19; import { ERC721EnumerableUpgradeable } from '@openzeppelin/contracts-upgradeable/token/ERC721/extensions/ERC721EnumerableUpgradeable.sol'; abstract contract ERC721CheckpointableUpgradeable is ERC721EnumerableUpgradeable { /// @notice Defines decimals as per ERC-20 convention to make integrations with 3rd party governance platforms easier uint8 public constant decimals = 0; /// @notice A record of each accounts delegate mapping(address => address) private _delegates; /// @notice A checkpoint for marking number of votes from a given block struct Checkpoint { uint32 fromBlock; uint96 votes; } /// @notice A record of votes checkpoints for each account, by index mapping(address => mapping(uint32 => Checkpoint)) public checkpoints; /// @notice The number of checkpoints for each account mapping(address => uint32) public numCheckpoints; /// @notice The EIP-712 typehash for the contract's domain bytes32 public constant DOMAIN_TYPEHASH = keccak256('EIP712Domain(string name,uint256 chainId,address verifyingContract)'); /// @notice The EIP-712 typehash for the delegation struct used by the contract bytes32 public constant DELEGATION_TYPEHASH = keccak256('Delegation(address delegatee,uint256 nonce,uint256 expiry)'); /// @notice A record of states for signing / validating signatures mapping(address => uint256) public nonces; /// @notice An event thats emitted when an account changes its delegate event DelegateChanged(address indexed delegator, address indexed fromDelegate, address indexed toDelegate); /// @notice An event thats emitted when a delegate account's vote balance changes event DelegateVotesChanged(address indexed delegate, uint256 previousBalance, uint256 newBalance); /** * @notice The votes a delegator can delegate, which is the current balance of the delegator. * @dev Used when calling `_delegate()` */ function votesToDelegate(address delegator) public view returns (uint96) { return safe96(balanceOf(delegator), 'ERC721Checkpointable::votesToDelegate: amount exceeds 96 bits'); } /** * @notice Overrides the standard `Comp.sol` delegates mapping to return * the delegator's own address if they haven't delegated. * This avoids having to delegate to oneself. */ function delegates(address delegator) public view returns (address) { address current = _delegates[delegator]; return current == address(0) ? delegator : current; } /** * @notice Adapted from `_transferTokens()` in `Comp.sol` to update delegate votes. * @dev hooks into OpenZeppelin's `ERC721._transfer` */ function _beforeTokenTransfer( address from, address to, uint256 tokenId ) internal override { super._beforeTokenTransfer(from, to, tokenId); /// @notice Differs from `_transferTokens()` to use `delegates` override method to simulate auto-delegation _moveDelegates(delegates(from), delegates(to), 1); } /** * @notice Delegate votes from `msg.sender` to `delegatee` * @param delegatee The address to delegate votes to */ function delegate(address delegatee) public { if (delegatee == address(0)) delegatee = msg.sender; return _delegate(msg.sender, delegatee); } /** * @notice Delegates votes from signatory to `delegatee` * @param delegatee The address to delegate votes to * @param nonce The contract state required to match the signature * @param expiry The time at which to expire the signature * @param v The recovery byte of the signature * @param r Half of the ECDSA signature pair * @param s Half of the ECDSA signature pair */ function delegateBySig( address delegatee, uint256 nonce, uint256 expiry, uint8 v, bytes32 r, bytes32 s ) public { require(delegatee != address(0), 'ERC721Checkpointable::delegateBySig: delegatee cannot be zero address'); bytes32 domainSeparator = keccak256( abi.encode(DOMAIN_TYPEHASH, keccak256(bytes(name())), block.chainid, address(this)) ); bytes32 structHash = keccak256(abi.encode(DELEGATION_TYPEHASH, delegatee, nonce, expiry)); bytes32 digest = keccak256(abi.encodePacked('\x19\x01', domainSeparator, structHash)); address signatory = ecrecover(digest, v, r, s); require(signatory != address(0), 'ERC721Checkpointable::delegateBySig: invalid signature'); require(nonce == nonces[signatory]++, 'ERC721Checkpointable::delegateBySig: invalid nonce'); require(block.timestamp <= expiry, 'ERC721Checkpointable::delegateBySig: signature expired'); return _delegate(signatory, delegatee); } /** * @notice Gets the current votes balance for `account` * @param account The address to get votes balance * @return The number of current votes for `account` */ function getCurrentVotes(address account) external view returns (uint96) { uint32 nCheckpoints = numCheckpoints[account]; return nCheckpoints > 0 ? checkpoints[account][nCheckpoints - 1].votes : 0; } /** * @notice Determine the prior number of votes for an account as of a block number * @dev Block number must be a finalized block or else this function will revert to prevent misinformation. * @param account The address of the account to check * @param blockNumber The block number to get the vote balance at * @return The number of votes the account had as of the given block */ function getPriorVotes(address account, uint256 blockNumber) public view returns (uint96) { require(blockNumber < block.number, 'ERC721Checkpointable::getPriorVotes: not yet determined'); uint32 nCheckpoints = numCheckpoints[account]; if (nCheckpoints == 0) { return 0; } // First check most recent balance if (checkpoints[account][nCheckpoints - 1].fromBlock <= blockNumber) { return checkpoints[account][nCheckpoints - 1].votes; } // Next check implicit zero balance if (checkpoints[account][0].fromBlock > blockNumber) { return 0; } uint32 lower = 0; uint32 upper = nCheckpoints - 1; while (upper > lower) { uint32 center = upper - (upper - lower) / 2; // ceil, avoiding overflow Checkpoint memory cp = checkpoints[account][center]; if (cp.fromBlock == blockNumber) { return cp.votes; } else if (cp.fromBlock < blockNumber) { lower = center; } else { upper = center - 1; } } return checkpoints[account][lower].votes; } function _delegate(address delegator, address delegatee) internal { /// @notice differs from `_delegate()` in `Comp.sol` to use `delegates` override method to simulate auto-delegation address currentDelegate = delegates(delegator); _delegates[delegator] = delegatee; emit DelegateChanged(delegator, currentDelegate, delegatee); uint96 amount = votesToDelegate(delegator); _moveDelegates(currentDelegate, delegatee, amount); } function _moveDelegates( address srcRep, address dstRep, uint96 amount ) internal { if (srcRep != dstRep && amount > 0) { if (srcRep != address(0)) { uint32 srcRepNum = numCheckpoints[srcRep]; uint96 srcRepOld = srcRepNum > 0 ? checkpoints[srcRep][srcRepNum - 1].votes : 0; uint96 srcRepNew = sub96(srcRepOld, amount, 'ERC721Checkpointable::_moveDelegates: amount underflows'); _writeCheckpoint(srcRep, srcRepNum, srcRepOld, srcRepNew); } if (dstRep != address(0)) { uint32 dstRepNum = numCheckpoints[dstRep]; uint96 dstRepOld = dstRepNum > 0 ? checkpoints[dstRep][dstRepNum - 1].votes : 0; uint96 dstRepNew = add96(dstRepOld, amount, 'ERC721Checkpointable::_moveDelegates: amount overflows'); _writeCheckpoint(dstRep, dstRepNum, dstRepOld, dstRepNew); } } } function _writeCheckpoint( address delegatee, uint32 nCheckpoints, uint96 oldVotes, uint96 newVotes ) internal { uint32 blockNumber = safe32( block.number, 'ERC721Checkpointable::_writeCheckpoint: block number exceeds 32 bits' ); if (nCheckpoints > 0 && checkpoints[delegatee][nCheckpoints - 1].fromBlock == blockNumber) { checkpoints[delegatee][nCheckpoints - 1].votes = newVotes; } else { checkpoints[delegatee][nCheckpoints] = Checkpoint(blockNumber, newVotes); numCheckpoints[delegatee] = nCheckpoints + 1; } emit DelegateVotesChanged(delegatee, oldVotes, newVotes); } function safe32(uint256 n, string memory errorMessage) internal pure returns (uint32) { require(n < 2**32, errorMessage); return uint32(n); } function safe96(uint256 n, string memory errorMessage) internal pure returns (uint96) { require(n < 2**96, errorMessage); return uint96(n); } function add96( uint96 a, uint96 b, string memory errorMessage ) internal pure returns (uint96) { uint96 c = a + b; require(c >= a, errorMessage); return c; } function sub96( uint96 a, uint96 b, string memory errorMessage ) internal pure returns (uint96) { require(b <= a, errorMessage); return a - b; } }
// SPDX-License-Identifier: GPL-3.0 /// @title Common interface for NounsDescriptor versions, as used by NounsToken and NounsSeeder. /********************************* * ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ * * ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ * * ░░░░░░█████████░░█████████░░░ * * ░░░░░░██░░░████░░██░░░████░░░ * * ░░██████░░░████████░░░████░░░ * * ░░██░░██░░░████░░██░░░████░░░ * * ░░██░░██░░░████░░██░░░████░░░ * * ░░░░░░█████████░░█████████░░░ * * ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ * * ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ * *********************************/ pragma solidity ^0.8.6; import { INounsSeeder } from './INounsSeeder.sol'; interface INounsDescriptorMinimal { /// /// USED BY TOKEN /// function tokenURI(uint256 tokenId, INounsSeeder.Seed memory seed) external view returns (string memory); function dataURI(uint256 tokenId, INounsSeeder.Seed memory seed) external view returns (string memory); /// /// USED BY SEEDER /// function backgroundCount() external view returns (uint256); function bodyCount() external view returns (uint256); function accessoryCount() external view returns (uint256); function headCount() external view returns (uint256); function glassesCount() external view returns (uint256); }
// SPDX-License-Identifier: GPL-3.0 /// @title Interface for NounsSeeder /********************************* * ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ * * ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ * * ░░░░░░█████████░░█████████░░░ * * ░░░░░░██░░░████░░██░░░████░░░ * * ░░██████░░░████████░░░████░░░ * * ░░██░░██░░░████░░██░░░████░░░ * * ░░██░░██░░░████░░██░░░████░░░ * * ░░░░░░█████████░░█████████░░░ * * ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ * * ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ * *********************************/ pragma solidity ^0.8.6; import { INounsDescriptorMinimal } from './INounsDescriptorMinimal.sol'; interface INounsSeeder { struct Seed { uint48 background; uint48 body; uint48 accessory; uint48 head; uint48 glasses; } function generateSeed(uint256 nounId, INounsDescriptorMinimal descriptor) external view returns (Seed memory); }
// SPDX-License-Identifier: GPL-3.0 /// @title Interface for NounsTokenFork /********************************* * ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ * * ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ * * ░░░░░░█████████░░█████████░░░ * * ░░░░░░██░░░████░░██░░░████░░░ * * ░░██████░░░████████░░░████░░░ * * ░░██░░██░░░████░░██░░░████░░░ * * ░░██░░██░░░████░░██░░░████░░░ * * ░░░░░░█████████░░█████████░░░ * * ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ * * ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ * *********************************/ pragma solidity ^0.8.19; import { IERC721Upgradeable } from '@openzeppelin/contracts-upgradeable/token/ERC721/IERC721Upgradeable.sol'; import { INounsDescriptorMinimal } from '../../../../interfaces/INounsDescriptorMinimal.sol'; import { INounsSeeder } from '../../../../interfaces/INounsSeeder.sol'; interface INounsTokenFork is IERC721Upgradeable { event NounCreated(uint256 indexed tokenId, INounsSeeder.Seed seed); event NounBurned(uint256 indexed tokenId); event MinterUpdated(address minter); event MinterLocked(); event DescriptorUpdated(INounsDescriptorMinimal descriptor); event DescriptorLocked(); event SeederUpdated(INounsSeeder seeder); event SeederLocked(); function mint() external returns (uint256); function burn(uint256 tokenId) external; function dataURI(uint256 tokenId) external returns (string memory); function setMinter(address minter) external; function lockMinter() external; function setDescriptor(INounsDescriptorMinimal descriptor) external; function lockDescriptor() external; function setSeeder(INounsSeeder seeder) external; function lockSeeder() external; }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.0 (token/ERC721/IERC721.sol) pragma solidity ^0.8.0; import "../../utils/introspection/IERC165.sol"; /** * @dev Required interface of an ERC721 compliant contract. */ interface IERC721 is IERC165 { /** * @dev Emitted when `tokenId` token is transferred from `from` to `to`. */ event Transfer(address indexed from, address indexed to, uint256 indexed tokenId); /** * @dev Emitted when `owner` enables `approved` to manage the `tokenId` token. */ event Approval(address indexed owner, address indexed approved, uint256 indexed tokenId); /** * @dev Emitted when `owner` enables or disables (`approved`) `operator` to manage all of its assets. */ event ApprovalForAll(address indexed owner, address indexed operator, bool approved); /** * @dev Returns the number of tokens in ``owner``'s account. */ function balanceOf(address owner) external view returns (uint256 balance); /** * @dev Returns the owner of the `tokenId` token. * * Requirements: * * - `tokenId` must exist. */ function ownerOf(uint256 tokenId) external view returns (address owner); /** * @dev Safely transfers `tokenId` token from `from` to `to`, checking first that contract recipients * are aware of the ERC721 protocol to prevent tokens from being forever locked. * * Requirements: * * - `from` cannot be the zero address. * - `to` cannot be the zero address. * - `tokenId` token must exist and be owned by `from`. * - If the caller is not `from`, it must be have been allowed to move this token by either {approve} or {setApprovalForAll}. * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer. * * Emits a {Transfer} event. */ function safeTransferFrom( address from, address to, uint256 tokenId ) external; /** * @dev Transfers `tokenId` token from `from` to `to`. * * WARNING: Usage of this method is discouraged, use {safeTransferFrom} whenever possible. * * Requirements: * * - `from` cannot be the zero address. * - `to` cannot be the zero address. * - `tokenId` token must be owned by `from`. * - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}. * * Emits a {Transfer} event. */ function transferFrom( address from, address to, uint256 tokenId ) external; /** * @dev Gives permission to `to` to transfer `tokenId` token to another account. * The approval is cleared when the token is transferred. * * Only a single account can be approved at a time, so approving the zero address clears previous approvals. * * Requirements: * * - The caller must own the token or be an approved operator. * - `tokenId` must exist. * * Emits an {Approval} event. */ function approve(address to, uint256 tokenId) external; /** * @dev Returns the account approved for `tokenId` token. * * Requirements: * * - `tokenId` must exist. */ function getApproved(uint256 tokenId) external view returns (address operator); /** * @dev Approve or remove `operator` as an operator for the caller. * Operators can call {transferFrom} or {safeTransferFrom} for any token owned by the caller. * * Requirements: * * - The `operator` cannot be the caller. * * Emits an {ApprovalForAll} event. */ function setApprovalForAll(address operator, bool _approved) external; /** * @dev Returns if the `operator` is allowed to manage all of the assets of `owner`. * * See {setApprovalForAll} */ function isApprovedForAll(address owner, address operator) external view returns (bool); /** * @dev Safely transfers `tokenId` token from `from` to `to`. * * Requirements: * * - `from` cannot be the zero address. * - `to` cannot be the zero address. * - `tokenId` token must exist and be owned by `from`. * - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}. * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer. * * Emits a {Transfer} event. */ function safeTransferFrom( address from, address to, uint256 tokenId, bytes calldata data ) external; }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.0 (token/ERC721/extensions/ERC721Enumerable.sol) pragma solidity ^0.8.0; import "../ERC721Upgradeable.sol"; import "./IERC721EnumerableUpgradeable.sol"; import "../../../proxy/utils/Initializable.sol"; /** * @dev This implements an optional extension of {ERC721} defined in the EIP that adds * enumerability of all the token ids in the contract as well as all token ids owned by each * account. */ abstract contract ERC721EnumerableUpgradeable is Initializable, ERC721Upgradeable, IERC721EnumerableUpgradeable { function __ERC721Enumerable_init() internal initializer { __Context_init_unchained(); __ERC165_init_unchained(); __ERC721Enumerable_init_unchained(); } function __ERC721Enumerable_init_unchained() internal initializer { } // Mapping from owner to list of owned token IDs mapping(address => mapping(uint256 => uint256)) private _ownedTokens; // Mapping from token ID to index of the owner tokens list mapping(uint256 => uint256) private _ownedTokensIndex; // Array with all token ids, used for enumeration uint256[] private _allTokens; // Mapping from token id to position in the allTokens array mapping(uint256 => uint256) private _allTokensIndex; /** * @dev See {IERC165-supportsInterface}. */ function supportsInterface(bytes4 interfaceId) public view virtual override(IERC165Upgradeable, ERC721Upgradeable) returns (bool) { return interfaceId == type(IERC721EnumerableUpgradeable).interfaceId || super.supportsInterface(interfaceId); } /** * @dev See {IERC721Enumerable-tokenOfOwnerByIndex}. */ function tokenOfOwnerByIndex(address owner, uint256 index) public view virtual override returns (uint256) { require(index < ERC721Upgradeable.balanceOf(owner), "ERC721Enumerable: owner index out of bounds"); return _ownedTokens[owner][index]; } /** * @dev See {IERC721Enumerable-totalSupply}. */ function totalSupply() public view virtual override returns (uint256) { return _allTokens.length; } /** * @dev See {IERC721Enumerable-tokenByIndex}. */ function tokenByIndex(uint256 index) public view virtual override returns (uint256) { require(index < ERC721EnumerableUpgradeable.totalSupply(), "ERC721Enumerable: global index out of bounds"); return _allTokens[index]; } /** * @dev Hook that is called before any token transfer. This includes minting * and burning. * * Calling conditions: * * - When `from` and `to` are both non-zero, ``from``'s `tokenId` will be * transferred to `to`. * - When `from` is zero, `tokenId` will be minted for `to`. * - When `to` is zero, ``from``'s `tokenId` will be burned. * - `from` cannot be the zero address. * - `to` cannot be the zero address. * * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. */ function _beforeTokenTransfer( address from, address to, uint256 tokenId ) internal virtual override { super._beforeTokenTransfer(from, to, tokenId); if (from == address(0)) { _addTokenToAllTokensEnumeration(tokenId); } else if (from != to) { _removeTokenFromOwnerEnumeration(from, tokenId); } if (to == address(0)) { _removeTokenFromAllTokensEnumeration(tokenId); } else if (to != from) { _addTokenToOwnerEnumeration(to, tokenId); } } /** * @dev Private function to add a token to this extension's ownership-tracking data structures. * @param to address representing the new owner of the given token ID * @param tokenId uint256 ID of the token to be added to the tokens list of the given address */ function _addTokenToOwnerEnumeration(address to, uint256 tokenId) private { uint256 length = ERC721Upgradeable.balanceOf(to); _ownedTokens[to][length] = tokenId; _ownedTokensIndex[tokenId] = length; } /** * @dev Private function to add a token to this extension's token tracking data structures. * @param tokenId uint256 ID of the token to be added to the tokens list */ function _addTokenToAllTokensEnumeration(uint256 tokenId) private { _allTokensIndex[tokenId] = _allTokens.length; _allTokens.push(tokenId); } /** * @dev Private function to remove a token from this extension's ownership-tracking data structures. Note that * while the token is not assigned a new owner, the `_ownedTokensIndex` mapping is _not_ updated: this allows for * gas optimizations e.g. when performing a transfer operation (avoiding double writes). * This has O(1) time complexity, but alters the order of the _ownedTokens array. * @param from address representing the previous owner of the given token ID * @param tokenId uint256 ID of the token to be removed from the tokens list of the given address */ function _removeTokenFromOwnerEnumeration(address from, uint256 tokenId) private { // To prevent a gap in from's tokens array, we store the last token in the index of the token to delete, and // then delete the last slot (swap and pop). uint256 lastTokenIndex = ERC721Upgradeable.balanceOf(from) - 1; uint256 tokenIndex = _ownedTokensIndex[tokenId]; // When the token to delete is the last token, the swap operation is unnecessary if (tokenIndex != lastTokenIndex) { uint256 lastTokenId = _ownedTokens[from][lastTokenIndex]; _ownedTokens[from][tokenIndex] = lastTokenId; // Move the last token to the slot of the to-delete token _ownedTokensIndex[lastTokenId] = tokenIndex; // Update the moved token's index } // This also deletes the contents at the last position of the array delete _ownedTokensIndex[tokenId]; delete _ownedTokens[from][lastTokenIndex]; } /** * @dev Private function to remove a token from this extension's token tracking data structures. * This has O(1) time complexity, but alters the order of the _allTokens array. * @param tokenId uint256 ID of the token to be removed from the tokens list */ function _removeTokenFromAllTokensEnumeration(uint256 tokenId) private { // To prevent a gap in the tokens array, we store the last token in the index of the token to delete, and // then delete the last slot (swap and pop). uint256 lastTokenIndex = _allTokens.length - 1; uint256 tokenIndex = _allTokensIndex[tokenId]; // When the token to delete is the last token, the swap operation is unnecessary. However, since this occurs so // rarely (when the last minted token is burnt) that we still do the swap here to avoid the gas cost of adding // an 'if' statement (like in _removeTokenFromOwnerEnumeration) uint256 lastTokenId = _allTokens[lastTokenIndex]; _allTokens[tokenIndex] = lastTokenId; // Move the last token to the slot of the to-delete token _allTokensIndex[lastTokenId] = tokenIndex; // Update the moved token's index // This also deletes the contents at the last position of the array delete _allTokensIndex[tokenId]; _allTokens.pop(); } uint256[46] private __gap; }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.0 (token/ERC721/IERC721.sol) pragma solidity ^0.8.0; import "../../utils/introspection/IERC165Upgradeable.sol"; /** * @dev Required interface of an ERC721 compliant contract. */ interface IERC721Upgradeable is IERC165Upgradeable { /** * @dev Emitted when `tokenId` token is transferred from `from` to `to`. */ event Transfer(address indexed from, address indexed to, uint256 indexed tokenId); /** * @dev Emitted when `owner` enables `approved` to manage the `tokenId` token. */ event Approval(address indexed owner, address indexed approved, uint256 indexed tokenId); /** * @dev Emitted when `owner` enables or disables (`approved`) `operator` to manage all of its assets. */ event ApprovalForAll(address indexed owner, address indexed operator, bool approved); /** * @dev Returns the number of tokens in ``owner``'s account. */ function balanceOf(address owner) external view returns (uint256 balance); /** * @dev Returns the owner of the `tokenId` token. * * Requirements: * * - `tokenId` must exist. */ function ownerOf(uint256 tokenId) external view returns (address owner); /** * @dev Safely transfers `tokenId` token from `from` to `to`, checking first that contract recipients * are aware of the ERC721 protocol to prevent tokens from being forever locked. * * Requirements: * * - `from` cannot be the zero address. * - `to` cannot be the zero address. * - `tokenId` token must exist and be owned by `from`. * - If the caller is not `from`, it must be have been allowed to move this token by either {approve} or {setApprovalForAll}. * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer. * * Emits a {Transfer} event. */ function safeTransferFrom( address from, address to, uint256 tokenId ) external; /** * @dev Transfers `tokenId` token from `from` to `to`. * * WARNING: Usage of this method is discouraged, use {safeTransferFrom} whenever possible. * * Requirements: * * - `from` cannot be the zero address. * - `to` cannot be the zero address. * - `tokenId` token must be owned by `from`. * - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}. * * Emits a {Transfer} event. */ function transferFrom( address from, address to, uint256 tokenId ) external; /** * @dev Gives permission to `to` to transfer `tokenId` token to another account. * The approval is cleared when the token is transferred. * * Only a single account can be approved at a time, so approving the zero address clears previous approvals. * * Requirements: * * - The caller must own the token or be an approved operator. * - `tokenId` must exist. * * Emits an {Approval} event. */ function approve(address to, uint256 tokenId) external; /** * @dev Returns the account approved for `tokenId` token. * * Requirements: * * - `tokenId` must exist. */ function getApproved(uint256 tokenId) external view returns (address operator); /** * @dev Approve or remove `operator` as an operator for the caller. * Operators can call {transferFrom} or {safeTransferFrom} for any token owned by the caller. * * Requirements: * * - The `operator` cannot be the caller. * * Emits an {ApprovalForAll} event. */ function setApprovalForAll(address operator, bool _approved) external; /** * @dev Returns if the `operator` is allowed to manage all of the assets of `owner`. * * See {setApprovalForAll} */ function isApprovedForAll(address owner, address operator) external view returns (bool); /** * @dev Safely transfers `tokenId` token from `from` to `to`. * * Requirements: * * - `from` cannot be the zero address. * - `to` cannot be the zero address. * - `tokenId` token must exist and be owned by `from`. * - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}. * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer. * * Emits a {Transfer} event. */ function safeTransferFrom( address from, address to, uint256 tokenId, bytes calldata data ) external; }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.0 (utils/introspection/IERC165.sol) pragma solidity ^0.8.0; /** * @dev Interface of the ERC165 standard, as defined in the * https://eips.ethereum.org/EIPS/eip-165[EIP]. * * Implementers can declare support of contract interfaces, which can then be * queried by others ({ERC165Checker}). * * For an implementation, see {ERC165}. */ interface IERC165 { /** * @dev Returns true if this contract implements the interface defined by * `interfaceId`. See the corresponding * https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section] * to learn more about how these ids are created. * * This function call must use less than 30 000 gas. */ function supportsInterface(bytes4 interfaceId) external view returns (bool); }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.0 (token/ERC721/ERC721.sol) pragma solidity ^0.8.0; import "./IERC721Upgradeable.sol"; import "./IERC721ReceiverUpgradeable.sol"; import "./extensions/IERC721MetadataUpgradeable.sol"; import "../../utils/AddressUpgradeable.sol"; import "../../utils/ContextUpgradeable.sol"; import "../../utils/StringsUpgradeable.sol"; import "../../utils/introspection/ERC165Upgradeable.sol"; import "../../proxy/utils/Initializable.sol"; /** * @dev Implementation of https://eips.ethereum.org/EIPS/eip-721[ERC721] Non-Fungible Token Standard, including * the Metadata extension, but not including the Enumerable extension, which is available separately as * {ERC721Enumerable}. */ contract ERC721Upgradeable is Initializable, ContextUpgradeable, ERC165Upgradeable, IERC721Upgradeable, IERC721MetadataUpgradeable { using AddressUpgradeable for address; using StringsUpgradeable for uint256; // Token name string private _name; // Token symbol string private _symbol; // Mapping from token ID to owner address mapping(uint256 => address) private _owners; // Mapping owner address to token count mapping(address => uint256) private _balances; // Mapping from token ID to approved address mapping(uint256 => address) private _tokenApprovals; // Mapping from owner to operator approvals mapping(address => mapping(address => bool)) private _operatorApprovals; /** * @dev Initializes the contract by setting a `name` and a `symbol` to the token collection. */ function __ERC721_init(string memory name_, string memory symbol_) internal initializer { __Context_init_unchained(); __ERC165_init_unchained(); __ERC721_init_unchained(name_, symbol_); } function __ERC721_init_unchained(string memory name_, string memory symbol_) internal initializer { _name = name_; _symbol = symbol_; } /** * @dev See {IERC165-supportsInterface}. */ function supportsInterface(bytes4 interfaceId) public view virtual override(ERC165Upgradeable, IERC165Upgradeable) returns (bool) { return interfaceId == type(IERC721Upgradeable).interfaceId || interfaceId == type(IERC721MetadataUpgradeable).interfaceId || super.supportsInterface(interfaceId); } /** * @dev See {IERC721-balanceOf}. */ function balanceOf(address owner) public view virtual override returns (uint256) { require(owner != address(0), "ERC721: balance query for the zero address"); return _balances[owner]; } /** * @dev See {IERC721-ownerOf}. */ function ownerOf(uint256 tokenId) public view virtual override returns (address) { address owner = _owners[tokenId]; require(owner != address(0), "ERC721: owner query for nonexistent token"); return owner; } /** * @dev See {IERC721Metadata-name}. */ function name() public view virtual override returns (string memory) { return _name; } /** * @dev See {IERC721Metadata-symbol}. */ function symbol() public view virtual override returns (string memory) { return _symbol; } /** * @dev See {IERC721Metadata-tokenURI}. */ function tokenURI(uint256 tokenId) public view virtual override returns (string memory) { require(_exists(tokenId), "ERC721Metadata: URI query for nonexistent token"); string memory baseURI = _baseURI(); return bytes(baseURI).length > 0 ? string(abi.encodePacked(baseURI, tokenId.toString())) : ""; } /** * @dev Base URI for computing {tokenURI}. If set, the resulting URI for each * token will be the concatenation of the `baseURI` and the `tokenId`. Empty * by default, can be overriden in child contracts. */ function _baseURI() internal view virtual returns (string memory) { return ""; } /** * @dev See {IERC721-approve}. */ function approve(address to, uint256 tokenId) public virtual override { address owner = ERC721Upgradeable.ownerOf(tokenId); require(to != owner, "ERC721: approval to current owner"); require( _msgSender() == owner || isApprovedForAll(owner, _msgSender()), "ERC721: approve caller is not owner nor approved for all" ); _approve(to, tokenId); } /** * @dev See {IERC721-getApproved}. */ function getApproved(uint256 tokenId) public view virtual override returns (address) { require(_exists(tokenId), "ERC721: approved query for nonexistent token"); return _tokenApprovals[tokenId]; } /** * @dev See {IERC721-setApprovalForAll}. */ function setApprovalForAll(address operator, bool approved) public virtual override { _setApprovalForAll(_msgSender(), operator, approved); } /** * @dev See {IERC721-isApprovedForAll}. */ function isApprovedForAll(address owner, address operator) public view virtual override returns (bool) { return _operatorApprovals[owner][operator]; } /** * @dev See {IERC721-transferFrom}. */ function transferFrom( address from, address to, uint256 tokenId ) public virtual override { //solhint-disable-next-line max-line-length require(_isApprovedOrOwner(_msgSender(), tokenId), "ERC721: transfer caller is not owner nor approved"); _transfer(from, to, tokenId); } /** * @dev See {IERC721-safeTransferFrom}. */ function safeTransferFrom( address from, address to, uint256 tokenId ) public virtual override { safeTransferFrom(from, to, tokenId, ""); } /** * @dev See {IERC721-safeTransferFrom}. */ function safeTransferFrom( address from, address to, uint256 tokenId, bytes memory _data ) public virtual override { require(_isApprovedOrOwner(_msgSender(), tokenId), "ERC721: transfer caller is not owner nor approved"); _safeTransfer(from, to, tokenId, _data); } /** * @dev Safely transfers `tokenId` token from `from` to `to`, checking first that contract recipients * are aware of the ERC721 protocol to prevent tokens from being forever locked. * * `_data` is additional data, it has no specified format and it is sent in call to `to`. * * This internal function is equivalent to {safeTransferFrom}, and can be used to e.g. * implement alternative mechanisms to perform token transfer, such as signature-based. * * Requirements: * * - `from` cannot be the zero address. * - `to` cannot be the zero address. * - `tokenId` token must exist and be owned by `from`. * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer. * * Emits a {Transfer} event. */ function _safeTransfer( address from, address to, uint256 tokenId, bytes memory _data ) internal virtual { _transfer(from, to, tokenId); require(_checkOnERC721Received(from, to, tokenId, _data), "ERC721: transfer to non ERC721Receiver implementer"); } /** * @dev Returns whether `tokenId` exists. * * Tokens can be managed by their owner or approved accounts via {approve} or {setApprovalForAll}. * * Tokens start existing when they are minted (`_mint`), * and stop existing when they are burned (`_burn`). */ function _exists(uint256 tokenId) internal view virtual returns (bool) { return _owners[tokenId] != address(0); } /** * @dev Returns whether `spender` is allowed to manage `tokenId`. * * Requirements: * * - `tokenId` must exist. */ function _isApprovedOrOwner(address spender, uint256 tokenId) internal view virtual returns (bool) { require(_exists(tokenId), "ERC721: operator query for nonexistent token"); address owner = ERC721Upgradeable.ownerOf(tokenId); return (spender == owner || getApproved(tokenId) == spender || isApprovedForAll(owner, spender)); } /** * @dev Safely mints `tokenId` and transfers it to `to`. * * Requirements: * * - `tokenId` must not exist. * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer. * * Emits a {Transfer} event. */ function _safeMint(address to, uint256 tokenId) internal virtual { _safeMint(to, tokenId, ""); } /** * @dev Same as {xref-ERC721-_safeMint-address-uint256-}[`_safeMint`], with an additional `data` parameter which is * forwarded in {IERC721Receiver-onERC721Received} to contract recipients. */ function _safeMint( address to, uint256 tokenId, bytes memory _data ) internal virtual { _mint(to, tokenId); require( _checkOnERC721Received(address(0), to, tokenId, _data), "ERC721: transfer to non ERC721Receiver implementer" ); } /** * @dev Mints `tokenId` and transfers it to `to`. * * WARNING: Usage of this method is discouraged, use {_safeMint} whenever possible * * Requirements: * * - `tokenId` must not exist. * - `to` cannot be the zero address. * * Emits a {Transfer} event. */ function _mint(address to, uint256 tokenId) internal virtual { require(to != address(0), "ERC721: mint to the zero address"); require(!_exists(tokenId), "ERC721: token already minted"); _beforeTokenTransfer(address(0), to, tokenId); _balances[to] += 1; _owners[tokenId] = to; emit Transfer(address(0), to, tokenId); } /** * @dev Destroys `tokenId`. * The approval is cleared when the token is burned. * * Requirements: * * - `tokenId` must exist. * * Emits a {Transfer} event. */ function _burn(uint256 tokenId) internal virtual { address owner = ERC721Upgradeable.ownerOf(tokenId); _beforeTokenTransfer(owner, address(0), tokenId); // Clear approvals _approve(address(0), tokenId); _balances[owner] -= 1; delete _owners[tokenId]; emit Transfer(owner, address(0), tokenId); } /** * @dev Transfers `tokenId` from `from` to `to`. * As opposed to {transferFrom}, this imposes no restrictions on msg.sender. * * Requirements: * * - `to` cannot be the zero address. * - `tokenId` token must be owned by `from`. * * Emits a {Transfer} event. */ function _transfer( address from, address to, uint256 tokenId ) internal virtual { require(ERC721Upgradeable.ownerOf(tokenId) == from, "ERC721: transfer of token that is not own"); require(to != address(0), "ERC721: transfer to the zero address"); _beforeTokenTransfer(from, to, tokenId); // Clear approvals from the previous owner _approve(address(0), tokenId); _balances[from] -= 1; _balances[to] += 1; _owners[tokenId] = to; emit Transfer(from, to, tokenId); } /** * @dev Approve `to` to operate on `tokenId` * * Emits a {Approval} event. */ function _approve(address to, uint256 tokenId) internal virtual { _tokenApprovals[tokenId] = to; emit Approval(ERC721Upgradeable.ownerOf(tokenId), to, tokenId); } /** * @dev Approve `operator` to operate on all of `owner` tokens * * Emits a {ApprovalForAll} event. */ function _setApprovalForAll( address owner, address operator, bool approved ) internal virtual { require(owner != operator, "ERC721: approve to caller"); _operatorApprovals[owner][operator] = approved; emit ApprovalForAll(owner, operator, approved); } /** * @dev Internal function to invoke {IERC721Receiver-onERC721Received} on a target address. * The call is not executed if the target address is not a contract. * * @param from address representing the previous owner of the given token ID * @param to target address that will receive the tokens * @param tokenId uint256 ID of the token to be transferred * @param _data bytes optional data to send along with the call * @return bool whether the call correctly returned the expected magic value */ function _checkOnERC721Received( address from, address to, uint256 tokenId, bytes memory _data ) private returns (bool) { if (to.isContract()) { try IERC721ReceiverUpgradeable(to).onERC721Received(_msgSender(), from, tokenId, _data) returns (bytes4 retval) { return retval == IERC721ReceiverUpgradeable.onERC721Received.selector; } catch (bytes memory reason) { if (reason.length == 0) { revert("ERC721: transfer to non ERC721Receiver implementer"); } else { assembly { revert(add(32, reason), mload(reason)) } } } } else { return true; } } /** * @dev Hook that is called before any token transfer. This includes minting * and burning. * * Calling conditions: * * - When `from` and `to` are both non-zero, ``from``'s `tokenId` will be * transferred to `to`. * - When `from` is zero, `tokenId` will be minted for `to`. * - When `to` is zero, ``from``'s `tokenId` will be burned. * - `from` and `to` are never both zero. * * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. */ function _beforeTokenTransfer( address from, address to, uint256 tokenId ) internal virtual {} uint256[44] private __gap; }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.0 (token/ERC721/extensions/IERC721Enumerable.sol) pragma solidity ^0.8.0; import "../IERC721Upgradeable.sol"; /** * @title ERC-721 Non-Fungible Token Standard, optional enumeration extension * @dev See https://eips.ethereum.org/EIPS/eip-721 */ interface IERC721EnumerableUpgradeable is IERC721Upgradeable { /** * @dev Returns the total amount of tokens stored by the contract. */ function totalSupply() external view returns (uint256); /** * @dev Returns a token ID owned by `owner` at a given `index` of its token list. * Use along with {balanceOf} to enumerate all of ``owner``'s tokens. */ function tokenOfOwnerByIndex(address owner, uint256 index) external view returns (uint256 tokenId); /** * @dev Returns a token ID at a given `index` of all the tokens stored by the contract. * Use along with {totalSupply} to enumerate all tokens. */ function tokenByIndex(uint256 index) external view returns (uint256); }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.0 (utils/introspection/IERC165.sol) pragma solidity ^0.8.0; /** * @dev Interface of the ERC165 standard, as defined in the * https://eips.ethereum.org/EIPS/eip-165[EIP]. * * Implementers can declare support of contract interfaces, which can then be * queried by others ({ERC165Checker}). * * For an implementation, see {ERC165}. */ interface IERC165Upgradeable { /** * @dev Returns true if this contract implements the interface defined by * `interfaceId`. See the corresponding * https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section] * to learn more about how these ids are created. * * This function call must use less than 30 000 gas. */ function supportsInterface(bytes4 interfaceId) external view returns (bool); }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.0 (token/ERC721/IERC721Receiver.sol) pragma solidity ^0.8.0; /** * @title ERC721 token receiver interface * @dev Interface for any contract that wants to support safeTransfers * from ERC721 asset contracts. */ interface IERC721ReceiverUpgradeable { /** * @dev Whenever an {IERC721} `tokenId` token is transferred to this contract via {IERC721-safeTransferFrom} * by `operator` from `from`, this function is called. * * It must return its Solidity selector to confirm the token transfer. * If any other value is returned or the interface is not implemented by the recipient, the transfer will be reverted. * * The selector can be obtained in Solidity with `IERC721.onERC721Received.selector`. */ function onERC721Received( address operator, address from, uint256 tokenId, bytes calldata data ) external returns (bytes4); }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.0 (token/ERC721/extensions/IERC721Metadata.sol) pragma solidity ^0.8.0; import "../IERC721Upgradeable.sol"; /** * @title ERC-721 Non-Fungible Token Standard, optional metadata extension * @dev See https://eips.ethereum.org/EIPS/eip-721 */ interface IERC721MetadataUpgradeable is IERC721Upgradeable { /** * @dev Returns the token collection name. */ function name() external view returns (string memory); /** * @dev Returns the token collection symbol. */ function symbol() external view returns (string memory); /** * @dev Returns the Uniform Resource Identifier (URI) for `tokenId` token. */ function tokenURI(uint256 tokenId) external view returns (string memory); }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.0 (utils/Address.sol) pragma solidity ^0.8.0; /** * @dev Collection of functions related to the address type */ library AddressUpgradeable { /** * @dev Returns true if `account` is a contract. * * [IMPORTANT] * ==== * It is unsafe to assume that an address for which this function returns * false is an externally-owned account (EOA) and not a contract. * * Among others, `isContract` will return false for the following * types of addresses: * * - an externally-owned account * - a contract in construction * - an address where a contract will be created * - an address where a contract lived, but was destroyed * ==== */ function isContract(address account) internal view returns (bool) { // This method relies on extcodesize, which returns 0 for contracts in // construction, since the code is only stored at the end of the // constructor execution. uint256 size; assembly { size := extcodesize(account) } return size > 0; } /** * @dev Replacement for Solidity's `transfer`: sends `amount` wei to * `recipient`, forwarding all available gas and reverting on errors. * * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost * of certain opcodes, possibly making contracts go over the 2300 gas limit * imposed by `transfer`, making them unable to receive funds via * `transfer`. {sendValue} removes this limitation. * * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. * * IMPORTANT: because control is transferred to `recipient`, care must be * taken to not create reentrancy vulnerabilities. Consider using * {ReentrancyGuard} or the * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. */ function sendValue(address payable recipient, uint256 amount) internal { require(address(this).balance >= amount, "Address: insufficient balance"); (bool success, ) = recipient.call{value: amount}(""); require(success, "Address: unable to send value, recipient may have reverted"); } /** * @dev Performs a Solidity function call using a low level `call`. A * plain `call` is an unsafe replacement for a function call: use this * function instead. * * If `target` reverts with a revert reason, it is bubbled up by this * function (like regular Solidity function calls). * * Returns the raw returned data. To convert to the expected return value, * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. * * Requirements: * * - `target` must be a contract. * - calling `target` with `data` must not revert. * * _Available since v3.1._ */ function functionCall(address target, bytes memory data) internal returns (bytes memory) { return functionCall(target, data, "Address: low-level call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with * `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCall( address target, bytes memory data, string memory errorMessage ) internal returns (bytes memory) { return functionCallWithValue(target, data, 0, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but also transferring `value` wei to `target`. * * Requirements: * * - the calling contract must have an ETH balance of at least `value`. * - the called Solidity function must be `payable`. * * _Available since v3.1._ */ function functionCallWithValue( address target, bytes memory data, uint256 value ) internal returns (bytes memory) { return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); } /** * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but * with `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCallWithValue( address target, bytes memory data, uint256 value, string memory errorMessage ) internal returns (bytes memory) { require(address(this).balance >= value, "Address: insufficient balance for call"); require(isContract(target), "Address: call to non-contract"); (bool success, bytes memory returndata) = target.call{value: value}(data); return verifyCallResult(success, returndata, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but performing a static call. * * _Available since v3.3._ */ function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) { return functionStaticCall(target, data, "Address: low-level static call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`], * but performing a static call. * * _Available since v3.3._ */ function functionStaticCall( address target, bytes memory data, string memory errorMessage ) internal view returns (bytes memory) { require(isContract(target), "Address: static call to non-contract"); (bool success, bytes memory returndata) = target.staticcall(data); return verifyCallResult(success, returndata, errorMessage); } /** * @dev Tool to verifies that a low level call was successful, and revert if it wasn't, either by bubbling the * revert reason using the provided one. * * _Available since v4.3._ */ function verifyCallResult( bool success, bytes memory returndata, string memory errorMessage ) internal pure returns (bytes memory) { if (success) { return returndata; } else { // Look for revert reason and bubble it up if present if (returndata.length > 0) { // The easiest way to bubble the revert reason is using memory via assembly assembly { let returndata_size := mload(returndata) revert(add(32, returndata), returndata_size) } } else { revert(errorMessage); } } } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.0 (utils/Strings.sol) pragma solidity ^0.8.0; /** * @dev String operations. */ library StringsUpgradeable { bytes16 private constant _HEX_SYMBOLS = "0123456789abcdef"; /** * @dev Converts a `uint256` to its ASCII `string` decimal representation. */ function toString(uint256 value) internal pure returns (string memory) { // Inspired by OraclizeAPI's implementation - MIT licence // https://github.com/oraclize/ethereum-api/blob/b42146b063c7d6ee1358846c198246239e9360e8/oraclizeAPI_0.4.25.sol if (value == 0) { return "0"; } uint256 temp = value; uint256 digits; while (temp != 0) { digits++; temp /= 10; } bytes memory buffer = new bytes(digits); while (value != 0) { digits -= 1; buffer[digits] = bytes1(uint8(48 + uint256(value % 10))); value /= 10; } return string(buffer); } /** * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation. */ function toHexString(uint256 value) internal pure returns (string memory) { if (value == 0) { return "0x00"; } uint256 temp = value; uint256 length = 0; while (temp != 0) { length++; temp >>= 8; } return toHexString(value, length); } /** * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length. */ function toHexString(uint256 value, uint256 length) internal pure returns (string memory) { bytes memory buffer = new bytes(2 * length + 2); buffer[0] = "0"; buffer[1] = "x"; for (uint256 i = 2 * length + 1; i > 1; --i) { buffer[i] = _HEX_SYMBOLS[value & 0xf]; value >>= 4; } require(value == 0, "Strings: hex length insufficient"); return string(buffer); } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.0 (utils/introspection/ERC165.sol) pragma solidity ^0.8.0; import "./IERC165Upgradeable.sol"; import "../../proxy/utils/Initializable.sol"; /** * @dev Implementation of the {IERC165} interface. * * Contracts that want to implement ERC165 should inherit from this contract and override {supportsInterface} to check * for the additional interface id that will be supported. For example: * * ```solidity * function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) { * return interfaceId == type(MyInterface).interfaceId || super.supportsInterface(interfaceId); * } * ``` * * Alternatively, {ERC165Storage} provides an easier to use but more expensive implementation. */ abstract contract ERC165Upgradeable is Initializable, IERC165Upgradeable { function __ERC165_init() internal initializer { __ERC165_init_unchained(); } function __ERC165_init_unchained() internal initializer { } /** * @dev See {IERC165-supportsInterface}. */ function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) { return interfaceId == type(IERC165Upgradeable).interfaceId; } uint256[50] private __gap; }
{ "remappings": [ "ds-test/=lib/forge-std/lib/ds-test/src/", "forge-std/=lib/forge-std/src/", "@ensdomains/=/Users/elad/code/nounsDAO/nouns-monorepo/node_modules/@ensdomains/", "@nouns/=/Users/elad/code/nounsDAO/nouns-monorepo/node_modules/@nouns/", "@openzeppelin/=/Users/elad/code/nounsDAO/nouns-monorepo/node_modules/@openzeppelin/", "base64-sol/=/Users/elad/code/nounsDAO/nouns-monorepo/node_modules/base64-sol/", "eth-gas-reporter/=/Users/elad/code/nounsDAO/nouns-monorepo/node_modules/eth-gas-reporter/", "hardhat/=/Users/elad/code/nounsDAO/nouns-monorepo/node_modules/hardhat/" ], "optimizer": { "enabled": true, "runs": 200 }, "metadata": { "useLiteralContent": false, "bytecodeHash": "ipfs", "appendCBOR": true }, "outputSelection": { "*": { "*": [ "evm.bytecode", "evm.deployedBytecode", "devdoc", "userdoc", "metadata", "abi" ] } }, "evmVersion": "paris", "libraries": {} }
Contract Security Audit
- No Contract Security Audit Submitted- Submit Audit Here
Contract ABI
API[{"inputs":[{"internalType":"address","name":"nounsToken_","type":"address"},{"internalType":"address","name":"nounsDao_","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[],"name":"AmountExceedsBalance","type":"error"},{"inputs":[{"internalType":"bytes","name":"data","type":"bytes"}],"name":"FailedWithdrawingETH","type":"error"},{"inputs":[],"name":"InvalidSignature","type":"error"},{"inputs":[],"name":"InvalidSupportValue","type":"error"},{"inputs":[],"name":"MustBeNounerOrPaySufficientFee","type":"error"},{"inputs":[],"name":"MustProvideActions","type":"error"},{"inputs":[],"name":"OnlyProposerCanCreateUpdateCandidate","type":"error"},{"inputs":[],"name":"ProposalInfoArityMismatch","type":"error"},{"inputs":[],"name":"ProposalToUpdateMustBeUpdatable","type":"error"},{"inputs":[],"name":"SlugAlreadyUsed","type":"error"},{"inputs":[],"name":"SlugDoesNotExist","type":"error"},{"inputs":[],"name":"TooManyActions","type":"error"},{"inputs":[],"name":"UpdateProposalCandidatesOnlyWorkWithProposalsBySigs","type":"error"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"previousAdmin","type":"address"},{"indexed":false,"internalType":"address","name":"newAdmin","type":"address"}],"name":"AdminChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"beacon","type":"address"}],"name":"BeaconUpgraded","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"msgSender","type":"address"},{"indexed":true,"internalType":"address","name":"proposer","type":"address"},{"indexed":false,"internalType":"string","name":"slug","type":"string"},{"indexed":false,"internalType":"uint8","name":"support","type":"uint8"},{"indexed":false,"internalType":"string","name":"reason","type":"string"}],"name":"CandidateFeedbackSent","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"oldCreateCandidateCost","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"newCreateCandidateCost","type":"uint256"}],"name":"CreateCandidateCostSet","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"to","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"ETHWithdrawn","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"oldFeeRecipient","type":"address"},{"indexed":true,"internalType":"address","name":"newFeeRecipient","type":"address"}],"name":"FeeRecipientSet","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"msgSender","type":"address"},{"indexed":false,"internalType":"uint256","name":"proposalId","type":"uint256"},{"indexed":false,"internalType":"uint8","name":"support","type":"uint8"},{"indexed":false,"internalType":"string","name":"reason","type":"string"}],"name":"FeedbackSent","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"msgSender","type":"address"},{"indexed":false,"internalType":"string","name":"slug","type":"string"}],"name":"ProposalCandidateCanceled","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"msgSender","type":"address"},{"indexed":false,"internalType":"address[]","name":"targets","type":"address[]"},{"indexed":false,"internalType":"uint256[]","name":"values","type":"uint256[]"},{"indexed":false,"internalType":"string[]","name":"signatures","type":"string[]"},{"indexed":false,"internalType":"bytes[]","name":"calldatas","type":"bytes[]"},{"indexed":false,"internalType":"string","name":"description","type":"string"},{"indexed":false,"internalType":"string","name":"slug","type":"string"},{"indexed":false,"internalType":"uint256","name":"proposalIdToUpdate","type":"uint256"},{"indexed":false,"internalType":"bytes32","name":"encodedProposalHash","type":"bytes32"}],"name":"ProposalCandidateCreated","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"msgSender","type":"address"},{"indexed":false,"internalType":"address[]","name":"targets","type":"address[]"},{"indexed":false,"internalType":"uint256[]","name":"values","type":"uint256[]"},{"indexed":false,"internalType":"string[]","name":"signatures","type":"string[]"},{"indexed":false,"internalType":"bytes[]","name":"calldatas","type":"bytes[]"},{"indexed":false,"internalType":"string","name":"description","type":"string"},{"indexed":false,"internalType":"string","name":"slug","type":"string"},{"indexed":false,"internalType":"uint256","name":"proposalIdToUpdate","type":"uint256"},{"indexed":false,"internalType":"bytes32","name":"encodedProposalHash","type":"bytes32"},{"indexed":false,"internalType":"string","name":"reason","type":"string"}],"name":"ProposalCandidateUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"signer","type":"address"},{"indexed":false,"internalType":"bytes","name":"sig","type":"bytes"},{"indexed":false,"internalType":"uint256","name":"expirationTimestamp","type":"uint256"},{"indexed":false,"internalType":"address","name":"proposer","type":"address"},{"indexed":false,"internalType":"string","name":"slug","type":"string"},{"indexed":false,"internalType":"uint256","name":"proposalIdToUpdate","type":"uint256"},{"indexed":false,"internalType":"bytes32","name":"encodedPropHash","type":"bytes32"},{"indexed":false,"internalType":"bytes32","name":"sigDigest","type":"bytes32"},{"indexed":false,"internalType":"string","name":"reason","type":"string"}],"name":"SignatureAdded","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"oldUpdateCandidateCost","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"newUpdateCandidateCost","type":"uint256"}],"name":"UpdateCandidateCostSet","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"implementation","type":"address"}],"name":"Upgraded","type":"event"},{"inputs":[],"name":"PRIOR_VOTES_BLOCKS_AGO","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes","name":"sig","type":"bytes"},{"internalType":"uint256","name":"expirationTimestamp","type":"uint256"},{"internalType":"address","name":"proposer","type":"address"},{"internalType":"string","name":"slug","type":"string"},{"internalType":"uint256","name":"proposalIdToUpdate","type":"uint256"},{"internalType":"bytes","name":"encodedProp","type":"bytes"},{"internalType":"string","name":"reason","type":"string"}],"name":"addSignature","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"string","name":"slug","type":"string"}],"name":"cancelProposalCandidate","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"createCandidateCost","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address[]","name":"targets","type":"address[]"},{"internalType":"uint256[]","name":"values","type":"uint256[]"},{"internalType":"string[]","name":"signatures","type":"string[]"},{"internalType":"bytes[]","name":"calldatas","type":"bytes[]"},{"internalType":"string","name":"description","type":"string"},{"internalType":"string","name":"slug","type":"string"},{"internalType":"uint256","name":"proposalIdToUpdate","type":"uint256"}],"name":"createProposalCandidate","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[],"name":"feeRecipient","outputs":[{"internalType":"address payable","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"admin","type":"address"},{"internalType":"uint256","name":"createCandidateCost_","type":"uint256"},{"internalType":"uint256","name":"updateCandidateCost_","type":"uint256"},{"internalType":"address payable","name":"feeRecipient_","type":"address"}],"name":"initialize","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"nounsDao","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"nounsToken","outputs":[{"internalType":"contract NounsTokenLike","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"},{"internalType":"bytes32","name":"","type":"bytes32"}],"name":"propCandidates","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"renounceOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"proposer","type":"address"},{"internalType":"string","name":"slug","type":"string"},{"internalType":"uint8","name":"support","type":"uint8"},{"internalType":"string","name":"reason","type":"string"}],"name":"sendCandidateFeedback","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"proposalId","type":"uint256"},{"internalType":"uint8","name":"support","type":"uint8"},{"internalType":"string","name":"reason","type":"string"}],"name":"sendFeedback","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"newCreateCandidateCost","type":"uint256"}],"name":"setCreateCandidateCost","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address payable","name":"newFeeRecipient","type":"address"}],"name":"setFeeRecipient","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"newUpdateCandidateCost","type":"uint256"}],"name":"setUpdateCandidateCost","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"updateCandidateCost","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address[]","name":"targets","type":"address[]"},{"internalType":"uint256[]","name":"values","type":"uint256[]"},{"internalType":"string[]","name":"signatures","type":"string[]"},{"internalType":"bytes[]","name":"calldatas","type":"bytes[]"},{"internalType":"string","name":"description","type":"string"},{"internalType":"string","name":"slug","type":"string"},{"internalType":"uint256","name":"proposalIdToUpdate","type":"uint256"},{"internalType":"string","name":"reason","type":"string"}],"name":"updateProposalCandidate","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address","name":"newImplementation","type":"address"}],"name":"upgradeTo","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newImplementation","type":"address"},{"internalType":"bytes","name":"data","type":"bytes"}],"name":"upgradeToAndCall","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"withdrawETH","outputs":[],"stateMutability":"nonpayable","type":"function"}]
Contract Creation Code
60e0604052306080523480156200001557600080fd5b5060405162002de938038062002de9833981016040819052620000389162000129565b600054610100900460ff168062000052575060005460ff16155b620000ba5760405162461bcd60e51b815260206004820152602e60248201527f496e697469616c697a61626c653a20636f6e747261637420697320616c72656160448201526d191e481a5b9a5d1a585b1a5e995960921b606482015260840160405180910390fd5b600054610100900460ff16158015620000dd576000805461ffff19166101011790555b6001600160a01b0380841660a052821660c052801562000103576000805461ff00191690555b50505062000161565b80516001600160a01b03811681146200012457600080fd5b919050565b600080604083850312156200013d57600080fd5b62000148836200010c565b915062000158602084016200010c565b90509250929050565b60805160a05160c051612c2e620001bb6000396000818161034b015281816109ac0152610a6e0152600081816103d001526113c70152600081816105c1015281816106010152818161085801526108980152612c2e6000f3fe6080604052600436106101405760003560e01c8063628ff474116100b65780638da5cb5b1161006f5780638da5cb5b146103805780639e3d87cd1461039e578063ced9481f146103be578063e74b981b146103f2578063f2fde38b14610412578063ff4ca1841461043257600080fd5b8063628ff474146102d55780636549df9f146102f95780637031ba591461030f578063715018a614610324578063841de94714610339578063848ea72f1461036d57600080fd5b806338e861a01161010857806338e861a01461021757806346904840146102375780634782f7791461026f5780634f1ef2861461028f578063614ef902146102a2578063615e4ef9146102c257600080fd5b806306b88d68146101455780631fdefaab146101675780632a03c079146101875780633659cfe6146101a757806338cbe0ca146101c7575b600080fd5b34801561015157600080fd5b50610165610160366004611c42565b610452565b005b34801561017357600080fd5b50610165610182366004611c42565b6104cb565b34801561019357600080fd5b506101656101a2366004611d39565b610533565b3480156101b357600080fd5b506101656101c2366004611d9a565b6105b7565b3480156101d357600080fd5b506102026101e2366004611db7565b606760209081526000928352604080842090915290825290205460ff1681565b60405190151581526020015b60405180910390f35b34801561022357600080fd5b50610165610232366004611df4565b61067f565b34801561024357600080fd5b50606854610257906001600160a01b031681565b6040516001600160a01b03909116815260200161020e565b34801561027b57600080fd5b5061016561028a366004611db7565b610742565b61016561029d366004611e7a565b61084e565b3480156102ae57600080fd5b506101656102bd366004611ec9565b610907565b6101656102d0366004612189565b610a52565b3480156102e157600080fd5b506102eb60655481565b60405190815260200161020e565b34801561030557600080fd5b506102eb60665481565b34801561031b57600080fd5b506102eb600181565b34801561033057600080fd5b50610165610ceb565b34801561034557600080fd5b506102577f000000000000000000000000000000000000000000000000000000000000000081565b61016561037b366004612288565b610d21565b34801561038c57600080fd5b506033546001600160a01b0316610257565b3480156103aa57600080fd5b506101656103b93660046123ac565b610e68565b3480156103ca57600080fd5b506102577f000000000000000000000000000000000000000000000000000000000000000081565b3480156103fe57600080fd5b5061016561040d366004611d9a565b610f4d565b34801561041e57600080fd5b5061016561042d366004611d9a565b610fc9565b34801561043e57600080fd5b5061016561044d3660046123f6565b611061565b6033546001600160a01b031633146104855760405162461bcd60e51b815260040161047c9061244c565b60405180910390fd5b606680549082905560408051828152602081018490527fa5ff6097ec99d1e07b3a63580670fae7f549bde33491de1bd1877250d26cc34b91015b60405180910390a15050565b6033546001600160a01b031633146104f55760405162461bcd60e51b815260040161047c9061244c565b606580549082905560408051828152602081018490527f3e09bd31378b9c85b14184aa5a8cdafd32b41315a2adf5579140ccfff0aefa4791016104bf565b336000908152606760209081526040808320845185840120845290915290205460ff1661057357604051636a76632960e11b815260040160405180910390fd5b336001600160a01b03167f535f3f195da71b37d09a686916267ef7ad39d15bef95c61e85224d35f8b8fbad826040516105ac91906124d1565b60405180910390a250565b6001600160a01b037f00000000000000000000000000000000000000000000000000000000000000001630036105ff5760405162461bcd60e51b815260040161047c906124e4565b7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03166106316110d0565b6001600160a01b0316146106575760405162461bcd60e51b815260040161047c90612530565b610660816110fe565b6040805160008082526020820190925261067c91839190611128565b50565b6001600160a01b0384166000908152606760209081526040808320865187840120845290915290205460ff166106c857604051636a76632960e11b815260040160405180910390fd5b60028260ff1611156106ed57604051634f81348960e11b815260040160405180910390fd5b836001600160a01b0316336001600160a01b03167f1e071c52ea06b433aac74cdba4ed70ff3e6635d5a6b344d654c04b4c762f054e8585856040516107349392919061257c565b60405180910390a350505050565b6033546001600160a01b0316331461076c5760405162461bcd60e51b815260040161047c9061244c565b4781111561078d576040516312d5633960e31b815260040160405180910390fd5b600080836001600160a01b03168360405160006040518083038185875af1925050503d80600081146107db576040519150601f19603f3d011682016040523d82523d6000602084013e6107e0565b606091505b5091509150816108055780604051636a30b5a560e01b815260040161047c91906124d1565b836001600160a01b03167f94b2de810873337ed265c5f8cf98c9cffefa06b8607f9a2f1fbaebdfbcfbef1c8460405161084091815260200190565b60405180910390a250505050565b6001600160a01b037f00000000000000000000000000000000000000000000000000000000000000001630036108965760405162461bcd60e51b815260040161047c906124e4565b7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03166108c86110d0565b6001600160a01b0316146108ee5760405162461bcd60e51b815260040161047c90612530565b6108f7826110fe565b61090382826001611128565b5050565b6001600160a01b0385166000908152606760209081526040808320875188840120845290915290205460ff1661095057604051636a76632960e11b815260040160405180910390fd5b6000831561097e577fe5a9e6d2702042f3612beac0f605312204baddec2d19d1338da7e37e6c67d6ee6109a0565b7fd4eafb6bc770edecb5da52765bc3f50af948bfe1b8344cf115f8ee7fefe55ec75b905060006109d082858a7f000000000000000000000000000000000000000000000000000000000000000061126c565b90506109dd33828b611357565b6109fa57604051638baa579f60e01b815260040160405180910390fd5b8351602085012060405133917f049e3f4ea065d6c7f5c163f55c25cff7a2e7a6f7da1379f9e2a0173618d1db6891610a3f918d918d918d918d918d918a908d906125b4565b60405180910390a2505050505050505050565b8015610b6d57604051631c4e85c360e31b8152600481018290527f0000000000000000000000000000000000000000000000000000000000000000906000906001600160a01b0383169063e2742e1890602401600060405180830381865afa158015610ac2573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f19168201604052610aea91908101906126a6565b9050806102000151431115610b1257604051630a03350360e31b815260040160405180910390fd5b60208101516001600160a01b03163314610b3f57604051636391d6c560e01b815260040160405180910390fd5b806101e0015151600003610b66576040516314f1d23560e21b815260040160405180910390fd5b5050610ba2565b610b76336113ba565b158015610b84575060655434105b15610ba2576040516339b4a7f160e11b815260040160405180910390fd5b336000908152606760209081526040808320855186840120845290915290205460ff1615610be3576040516323a5379b60e21b815260040160405180910390fd5b610c0c60405180608001604052808981526020018881526020018781526020018681525061147a565b33600081815260676020908152604080832086518784012084528252808320805460ff1916600117905580516080810182528b81529182018a90528101889052606081018790529091610c5f918661150e565b90508115610c8c578181604051602001610c7a9291906127fe565b60405160208183030381529060405290505b610c94611769565b8051602082012060405133917f092e72bcc568a2ad800b1d7bbd7cc3f305e4a7b596092c69d10da00e38d705e691610cd9918c918c918c918c918c918c918c916128ed565b60405180910390a25050505050505050565b6033546001600160a01b03163314610d155760405162461bcd60e51b815260040161047c9061244c565b610d1f60006117e5565b565b610d2a336113ba565b158015610d38575060665434105b15610d56576040516339b4a7f160e11b815260040160405180910390fd5b336000908152606760209081526040808320865187840120845290915290205460ff16610d9657604051636a76632960e11b815260040160405180910390fd5b610dbf60405180608001604052808a81526020018981526020018881526020018781525061147a565b6000610dec3360405180608001604052808c81526020018b81526020018a8152602001898152508761150e565b90508215610e19578281604051602001610e079291906127fe565b60405160208183030381529060405290505b610e21611769565b8051602082012060405133917f918063625a303d021375548c338d007d2857e576643789b387992dcfe04449cc91610a3f918d918d918d918d918d918d918d918d9061297d565b600054610100900460ff1680610e81575060005460ff16155b610ee45760405162461bcd60e51b815260206004820152602e60248201527f496e697469616c697a61626c653a20636f6e747261637420697320616c72656160448201526d191e481a5b9a5d1a585b1a5e995960921b606482015260840161047c565b600054610100900460ff16158015610f06576000805461ffff19166101011790555b610f0f856117e5565b60658490556066839055606880546001600160a01b0319166001600160a01b0384161790558015610f46576000805461ff00191690555b5050505050565b6033546001600160a01b03163314610f775760405162461bcd60e51b815260040161047c9061244c565b606880546001600160a01b038381166001600160a01b0319831681179093556040519116919082907f15d80a013f22151bc7246e3bc132e12828cde19de98870475e3fa7084015272190600090a35050565b6033546001600160a01b03163314610ff35760405162461bcd60e51b815260040161047c9061244c565b6001600160a01b0381166110585760405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201526564647265737360d01b606482015260840161047c565b61067c816117e5565b60028260ff16111561108657604051634f81348960e11b815260040160405180910390fd5b336001600160a01b03167f66777d398af2d3ad91be043f4ee15e0058fd64a2badd9977e29334dc608bbfa68484846040516110c393929190612a26565b60405180910390a2505050565b7f360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc546001600160a01b031690565b6033546001600160a01b0316331461067c5760405162461bcd60e51b815260040161047c9061244c565b60006111326110d0565b905061113d84611837565b60008351118061114a5750815b1561115b5761115984846118dc565b505b7f4910fdfa16fed3260ed0e7147f7cc6da11a60208b5b9406d12a635614ffd9143805460ff16610f4657805460ff191660011781556040516001600160a01b03831660248201526111da90869060440160408051601f198184030181529190526020810180516001600160e01b0316631b2ce7f360e11b1790526118dc565b50805460ff191681556111eb6110d0565b6001600160a01b0316826001600160a01b0316146112635760405162461bcd60e51b815260206004820152602f60248201527f45524331393637557067726164653a207570677261646520627265616b73206660448201526e75727468657220757067726164657360881b606482015260840161047c565b610f468561190a565b60008085858560405160200161128493929190612a51565b60408051808303601f190181528282528051602091820120838301835260098452684e6f756e732044414f60b81b9382019390935281517f8cad95687ba82c2ce50e74f7b754645e5117c3a5bec8151c0726d5857980a866818301527fe1dd93b3612547b4bb7c3d429f3df8508d84f5a4f63b5e2e44340b94698e6b3b818401524660608201526001600160a01b03969096166080808801919091528251808803909101815260a0870192839052805191012061190160f01b825260a286015260c2909401525050604290209392505050565b6000806000611366858561194a565b9092509050600081600481111561137f5761137f612a7e565b14801561139d5750856001600160a01b0316826001600160a01b0316145b806113ae57506113ae86868661198f565b925050505b9392505050565b6000806001600160a01b037f00000000000000000000000000000000000000000000000000000000000000001663782d6fe1846113f8600143612aaa565b6040516001600160e01b031960e085901b1681526001600160a01b0390921660048301526024820152604401602060405180830381865afa158015611441573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906114659190612abd565b6bffffffffffffffffffffffff161192915050565b602081015151815151141580611497575060408101515181515114155b806114a9575060608101515181515114155b156114c75760405163ccb0ce3f60e01b815260040160405180910390fd5b8051516000036114ea57604051630f24cd7360e01b815260040160405180910390fd5b805151600a101561067c576040516308e3b1eb60e11b815260040160405180910390fd5b606060008360400151516001600160401b0381111561152f5761152f611c5b565b604051908082528060200260200182016040528015611558578160200160208202803683370190505b50905060005b8460400151518110156115bd578460400151818151811061158157611581612aeb565b6020026020010151805190602001208282815181106115a2576115a2612aeb565b60209081029190910101526115b681612b01565b905061155e565b5060008460600151516001600160401b038111156115dd576115dd611c5b565b604051908082528060200260200182016040528015611606578160200160208202803683370190505b50905060005b85606001515181101561166b578560600151818151811061162f5761162f612aeb565b60200260200101518051906020012082828151811061165057611650612aeb565b602090810291909101015261166481612b01565b905061160c565b508451604051879161167f91602001612b1a565b6040516020818303038152906040528051906020012086602001516040516020016116aa9190612b59565b60405160208183030381529060405280519060200120846040516020016116d19190612b59565b60405160208183030381529060405280519060200120846040516020016116f89190612b59565b60408051601f1981840301815282825280516020918201208b518c8301206001600160a01b0390981691840191909152908201949094526060810192909252608082015260a081019190915260c081019190915260e001604051602081830303815290604052925050509392505050565b6068546001600160a01b0316341580159061178c57506001600160a01b03811615155b1561067c576040516001600160a01b038216903490600081818185875af1925050503d80600081146117da576040519150601f19603f3d011682016040523d82523d6000602084013e6117df565b606091505b50505050565b603380546001600160a01b038381166001600160a01b0319831681179093556040519116919082907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e090600090a35050565b803b61189b5760405162461bcd60e51b815260206004820152602d60248201527f455243313936373a206e657720696d706c656d656e746174696f6e206973206e60448201526c1bdd08184818dbdb9d1c9858dd609a1b606482015260840161047c565b7f360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc80546001600160a01b0319166001600160a01b0392909216919091179055565b60606119018383604051806060016040528060278152602001612bd260279139611a7b565b90505b92915050565b61191381611837565b6040516001600160a01b038216907fbc7cd75a20ee27fd9adebab32041f755214dbc6bffa90cc0225b39da2e5c2d3b90600090a250565b60008082516041036119805760208301516040840151606085015160001a61197487828585611b45565b94509450505050611988565b506000905060025b9250929050565b6000806000856001600160a01b0316631626ba7e60e01b86866040516024016119b9929190612b83565b60408051601f198184030181529181526020820180516001600160e01b03166001600160e01b03199094169390931790925290516119f79190612b9c565b600060405180830381855afa9150503d8060008114611a32576040519150601f19603f3d011682016040523d82523d6000602084013e611a37565b606091505b5091509150818015611a4b57506020815110155b80156113ae57508051630b135d3f60e11b90611a709083016020908101908401612bb8565b149695505050505050565b6060833b611ada5760405162461bcd60e51b815260206004820152602660248201527f416464726573733a2064656c65676174652063616c6c20746f206e6f6e2d636f6044820152651b9d1c9858dd60d21b606482015260840161047c565b600080856001600160a01b031685604051611af59190612b9c565b600060405180830381855af49150503d8060008114611b30576040519150601f19603f3d011682016040523d82523d6000602084013e611b35565b606091505b50915091506113ae828286611c09565b6000807f7fffffffffffffffffffffffffffffff5d576e7357a4501ddfe92f46681b20a0831115611b7c5750600090506003611c00565b6040805160008082526020820180845289905260ff881692820192909252606081018690526080810185905260019060a0016020604051602081039080840390855afa158015611bd0573d6000803e3d6000fd5b5050604051601f1901519150506001600160a01b038116611bf957600060019250925050611c00565b9150600090505b94509492505050565b60608315611c185750816113b3565b825115611c285782518084602001fd5b8160405162461bcd60e51b815260040161047c91906124d1565b600060208284031215611c5457600080fd5b5035919050565b634e487b7160e01b600052604160045260246000fd5b60405161026081016001600160401b0381118282101715611c9457611c94611c5b565b60405290565b604051601f8201601f191681016001600160401b0381118282101715611cc257611cc2611c5b565b604052919050565b600082601f830112611cdb57600080fd5b81356001600160401b03811115611cf457611cf4611c5b565b611d07601f8201601f1916602001611c9a565b818152846020838601011115611d1c57600080fd5b816020850160208301376000918101602001919091529392505050565b600060208284031215611d4b57600080fd5b81356001600160401b03811115611d6157600080fd5b611d6d84828501611cca565b949350505050565b6001600160a01b038116811461067c57600080fd5b8035611d9581611d75565b919050565b600060208284031215611dac57600080fd5b81356113b381611d75565b60008060408385031215611dca57600080fd5b8235611dd581611d75565b946020939093013593505050565b803560ff81168114611d9557600080fd5b60008060008060808587031215611e0a57600080fd5b8435611e1581611d75565b935060208501356001600160401b0380821115611e3157600080fd5b611e3d88838901611cca565b9450611e4b60408801611de3565b93506060870135915080821115611e6157600080fd5b50611e6e87828801611cca565b91505092959194509250565b60008060408385031215611e8d57600080fd5b8235611e9881611d75565b915060208301356001600160401b03811115611eb357600080fd5b611ebf85828601611cca565b9150509250929050565b600080600080600080600060e0888a031215611ee457600080fd5b87356001600160401b0380821115611efb57600080fd5b611f078b838c01611cca565b985060208a01359750611f1c60408b01611d8a565b965060608a0135915080821115611f3257600080fd5b611f3e8b838c01611cca565b955060808a0135945060a08a0135915080821115611f5b57600080fd5b611f678b838c01611cca565b935060c08a0135915080821115611f7d57600080fd5b50611f8a8a828b01611cca565b91505092959891949750929550565b60006001600160401b03821115611fb257611fb2611c5b565b5060051b60200190565b600082601f830112611fcd57600080fd5b81356020611fe2611fdd83611f99565b611c9a565b82815260059290921b8401810191818101908684111561200157600080fd5b8286015b8481101561202557803561201881611d75565b8352918301918301612005565b509695505050505050565b600082601f83011261204157600080fd5b81356020612051611fdd83611f99565b82815260059290921b8401810191818101908684111561207057600080fd5b8286015b848110156120255780358352918301918301612074565b600082601f83011261209c57600080fd5b813560206120ac611fdd83611f99565b82815260059290921b840181019181810190868411156120cb57600080fd5b8286015b848110156120255780356001600160401b038111156120ee5760008081fd5b6120fc8986838b0101611cca565b8452509183019183016120cf565b600082601f83011261211b57600080fd5b8135602061212b611fdd83611f99565b82815260059290921b8401810191818101908684111561214a57600080fd5b8286015b848110156120255780356001600160401b0381111561216d5760008081fd5b61217b8986838b0101611cca565b84525091830191830161214e565b600080600080600080600060e0888a0312156121a457600080fd5b87356001600160401b03808211156121bb57600080fd5b6121c78b838c01611fbc565b985060208a01359150808211156121dd57600080fd5b6121e98b838c01612030565b975060408a01359150808211156121ff57600080fd5b61220b8b838c0161208b565b965060608a013591508082111561222157600080fd5b61222d8b838c0161210a565b955060808a013591508082111561224357600080fd5b61224f8b838c01611cca565b945060a08a013591508082111561226557600080fd5b506122728a828b01611cca565b92505060c0880135905092959891949750929550565b600080600080600080600080610100898b0312156122a557600080fd5b88356001600160401b03808211156122bc57600080fd5b6122c88c838d01611fbc565b995060208b01359150808211156122de57600080fd5b6122ea8c838d01612030565b985060408b013591508082111561230057600080fd5b61230c8c838d0161208b565b975060608b013591508082111561232257600080fd5b61232e8c838d0161210a565b965060808b013591508082111561234457600080fd5b6123508c838d01611cca565b955060a08b013591508082111561236657600080fd5b6123728c838d01611cca565b945060c08b0135935060e08b013591508082111561238f57600080fd5b5061239c8b828c01611cca565b9150509295985092959890939650565b600080600080608085870312156123c257600080fd5b84356123cd81611d75565b9350602085013592506040850135915060608501356123eb81611d75565b939692955090935050565b60008060006060848603121561240b57600080fd5b8335925061241b60208501611de3565b915060408401356001600160401b0381111561243657600080fd5b61244286828701611cca565b9150509250925092565b6020808252818101527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604082015260600190565b60005b8381101561249c578181015183820152602001612484565b50506000910152565b600081518084526124bd816020860160208601612481565b601f01601f19169290920160200192915050565b60208152600061190160208301846124a5565b6020808252602c908201527f46756e6374696f6e206d7573742062652063616c6c6564207468726f7567682060408201526b19195b1959d85d1958d85b1b60a21b606082015260800190565b6020808252602c908201527f46756e6374696f6e206d7573742062652063616c6c6564207468726f7567682060408201526b6163746976652070726f787960a01b606082015260800190565b60608152600061258f60608301866124a5565b60ff8516602084015282810360408401526125aa81856124a5565b9695505050505050565b60006101008083526125c88184018c6124a5565b602084018b90526001600160a01b038a166040850152838103606085015290506125f281896124a5565b90508660808401528560a08401528460c084015282810360e084015261261881856124a5565b9b9a5050505050505050505050565b8051611d9581611d75565b80518015158114611d9557600080fd5b600082601f83011261265357600080fd5b81516020612663611fdd83611f99565b82815260059290921b8401810191818101908684111561268257600080fd5b8286015b8481101561202557805161269981611d75565b8352918301918301612686565b6000602082840312156126b857600080fd5b81516001600160401b03808211156126cf57600080fd5b9083019061026082860312156126e457600080fd5b6126ec611c71565b825181526126fc60208401612627565b602082015260408301516040820152606083015160608201526080830151608082015260a083015160a082015260c083015160c082015260e083015160e0820152610100808401518183015250610120808401518183015250610140612763818501612632565b90820152610160612775848201612632565b90820152610180612787848201612632565b908201526101a083810151908201526101c080840151908201526101e080840151838111156127b557600080fd5b6127c188828701612642565b91830191909152506102008381015190820152610220808401519082015261024091506127ef828401612632565b91810191909152949350505050565b82815260008251612816816020850160208701612481565b919091016020019392505050565b600081518084526020808501945080840160005b8381101561285d5781516001600160a01b031687529582019590820190600101612838565b509495945050505050565b600081518084526020808501945080840160005b8381101561285d5781518752958201959082019060010161287c565b600081518084526020808501808196508360051b8101915082860160005b858110156128e05782840389526128ce8483516124a5565b988501989350908401906001016128b6565b5091979650505050505050565b60006101008083526129018184018c612824565b90508281036020840152612915818b612868565b90508281036040840152612929818a612898565b9050828103606084015261293d8189612898565b9050828103608084015261295181886124a5565b905082810360a084015261296581876124a5565b60c0840195909552505060e001529695505050505050565b60006101208083526129918184018d612824565b905082810360208401526129a5818c612868565b905082810360408401526129b9818b612898565b905082810360608401526129cd818a612898565b905082810360808401526129e181896124a5565b905082810360a08401526129f581886124a5565b90508560c08401528460e0840152828103610100840152612a1681856124a5565b9c9b505050505050505050505050565b83815260ff83166020820152606060408201526000612a4860608301846124a5565b95945050505050565b83815260008351612a69816020850160208801612481565b60209201918201929092526040019392505050565b634e487b7160e01b600052602160045260246000fd5b634e487b7160e01b600052601160045260246000fd5b8181038181111561190457611904612a94565b600060208284031215612acf57600080fd5b81516bffffffffffffffffffffffff811681146113b357600080fd5b634e487b7160e01b600052603260045260246000fd5b600060018201612b1357612b13612a94565b5060010190565b815160009082906020808601845b83811015612b4d5781516001600160a01b031685529382019390820190600101612b28565b50929695505050505050565b815160009082906020808601845b83811015612b4d57815185529382019390820190600101612b67565b828152604060208201526000611d6d60408301846124a5565b60008251612bae818460208701612481565b9190910192915050565b600060208284031215612bca57600080fd5b505191905056fe416464726573733a206c6f772d6c6576656c2064656c65676174652063616c6c206661696c6564a2646970667358221220dab756ecdf5f8514a12011b2bb45591891a562bc69453a45f2dca2811d6e09fe64736f6c634300081300330000000000000000000000009c8ff314c9bc7f6e59a9d9225fb22946427edc030000000000000000000000006f3e6272a167e8accb32072d08e0957f9c79223d
Deployed Bytecode
0x6080604052600436106101405760003560e01c8063628ff474116100b65780638da5cb5b1161006f5780638da5cb5b146103805780639e3d87cd1461039e578063ced9481f146103be578063e74b981b146103f2578063f2fde38b14610412578063ff4ca1841461043257600080fd5b8063628ff474146102d55780636549df9f146102f95780637031ba591461030f578063715018a614610324578063841de94714610339578063848ea72f1461036d57600080fd5b806338e861a01161010857806338e861a01461021757806346904840146102375780634782f7791461026f5780634f1ef2861461028f578063614ef902146102a2578063615e4ef9146102c257600080fd5b806306b88d68146101455780631fdefaab146101675780632a03c079146101875780633659cfe6146101a757806338cbe0ca146101c7575b600080fd5b34801561015157600080fd5b50610165610160366004611c42565b610452565b005b34801561017357600080fd5b50610165610182366004611c42565b6104cb565b34801561019357600080fd5b506101656101a2366004611d39565b610533565b3480156101b357600080fd5b506101656101c2366004611d9a565b6105b7565b3480156101d357600080fd5b506102026101e2366004611db7565b606760209081526000928352604080842090915290825290205460ff1681565b60405190151581526020015b60405180910390f35b34801561022357600080fd5b50610165610232366004611df4565b61067f565b34801561024357600080fd5b50606854610257906001600160a01b031681565b6040516001600160a01b03909116815260200161020e565b34801561027b57600080fd5b5061016561028a366004611db7565b610742565b61016561029d366004611e7a565b61084e565b3480156102ae57600080fd5b506101656102bd366004611ec9565b610907565b6101656102d0366004612189565b610a52565b3480156102e157600080fd5b506102eb60655481565b60405190815260200161020e565b34801561030557600080fd5b506102eb60665481565b34801561031b57600080fd5b506102eb600181565b34801561033057600080fd5b50610165610ceb565b34801561034557600080fd5b506102577f0000000000000000000000006f3e6272a167e8accb32072d08e0957f9c79223d81565b61016561037b366004612288565b610d21565b34801561038c57600080fd5b506033546001600160a01b0316610257565b3480156103aa57600080fd5b506101656103b93660046123ac565b610e68565b3480156103ca57600080fd5b506102577f0000000000000000000000009c8ff314c9bc7f6e59a9d9225fb22946427edc0381565b3480156103fe57600080fd5b5061016561040d366004611d9a565b610f4d565b34801561041e57600080fd5b5061016561042d366004611d9a565b610fc9565b34801561043e57600080fd5b5061016561044d3660046123f6565b611061565b6033546001600160a01b031633146104855760405162461bcd60e51b815260040161047c9061244c565b60405180910390fd5b606680549082905560408051828152602081018490527fa5ff6097ec99d1e07b3a63580670fae7f549bde33491de1bd1877250d26cc34b91015b60405180910390a15050565b6033546001600160a01b031633146104f55760405162461bcd60e51b815260040161047c9061244c565b606580549082905560408051828152602081018490527f3e09bd31378b9c85b14184aa5a8cdafd32b41315a2adf5579140ccfff0aefa4791016104bf565b336000908152606760209081526040808320845185840120845290915290205460ff1661057357604051636a76632960e11b815260040160405180910390fd5b336001600160a01b03167f535f3f195da71b37d09a686916267ef7ad39d15bef95c61e85224d35f8b8fbad826040516105ac91906124d1565b60405180910390a250565b6001600160a01b037f000000000000000000000000624efaba6e7df177ad8ca5bee3bd62f78b304b6e1630036105ff5760405162461bcd60e51b815260040161047c906124e4565b7f000000000000000000000000624efaba6e7df177ad8ca5bee3bd62f78b304b6e6001600160a01b03166106316110d0565b6001600160a01b0316146106575760405162461bcd60e51b815260040161047c90612530565b610660816110fe565b6040805160008082526020820190925261067c91839190611128565b50565b6001600160a01b0384166000908152606760209081526040808320865187840120845290915290205460ff166106c857604051636a76632960e11b815260040160405180910390fd5b60028260ff1611156106ed57604051634f81348960e11b815260040160405180910390fd5b836001600160a01b0316336001600160a01b03167f1e071c52ea06b433aac74cdba4ed70ff3e6635d5a6b344d654c04b4c762f054e8585856040516107349392919061257c565b60405180910390a350505050565b6033546001600160a01b0316331461076c5760405162461bcd60e51b815260040161047c9061244c565b4781111561078d576040516312d5633960e31b815260040160405180910390fd5b600080836001600160a01b03168360405160006040518083038185875af1925050503d80600081146107db576040519150601f19603f3d011682016040523d82523d6000602084013e6107e0565b606091505b5091509150816108055780604051636a30b5a560e01b815260040161047c91906124d1565b836001600160a01b03167f94b2de810873337ed265c5f8cf98c9cffefa06b8607f9a2f1fbaebdfbcfbef1c8460405161084091815260200190565b60405180910390a250505050565b6001600160a01b037f000000000000000000000000624efaba6e7df177ad8ca5bee3bd62f78b304b6e1630036108965760405162461bcd60e51b815260040161047c906124e4565b7f000000000000000000000000624efaba6e7df177ad8ca5bee3bd62f78b304b6e6001600160a01b03166108c86110d0565b6001600160a01b0316146108ee5760405162461bcd60e51b815260040161047c90612530565b6108f7826110fe565b61090382826001611128565b5050565b6001600160a01b0385166000908152606760209081526040808320875188840120845290915290205460ff1661095057604051636a76632960e11b815260040160405180910390fd5b6000831561097e577fe5a9e6d2702042f3612beac0f605312204baddec2d19d1338da7e37e6c67d6ee6109a0565b7fd4eafb6bc770edecb5da52765bc3f50af948bfe1b8344cf115f8ee7fefe55ec75b905060006109d082858a7f0000000000000000000000006f3e6272a167e8accb32072d08e0957f9c79223d61126c565b90506109dd33828b611357565b6109fa57604051638baa579f60e01b815260040160405180910390fd5b8351602085012060405133917f049e3f4ea065d6c7f5c163f55c25cff7a2e7a6f7da1379f9e2a0173618d1db6891610a3f918d918d918d918d918d918a908d906125b4565b60405180910390a2505050505050505050565b8015610b6d57604051631c4e85c360e31b8152600481018290527f0000000000000000000000006f3e6272a167e8accb32072d08e0957f9c79223d906000906001600160a01b0383169063e2742e1890602401600060405180830381865afa158015610ac2573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f19168201604052610aea91908101906126a6565b9050806102000151431115610b1257604051630a03350360e31b815260040160405180910390fd5b60208101516001600160a01b03163314610b3f57604051636391d6c560e01b815260040160405180910390fd5b806101e0015151600003610b66576040516314f1d23560e21b815260040160405180910390fd5b5050610ba2565b610b76336113ba565b158015610b84575060655434105b15610ba2576040516339b4a7f160e11b815260040160405180910390fd5b336000908152606760209081526040808320855186840120845290915290205460ff1615610be3576040516323a5379b60e21b815260040160405180910390fd5b610c0c60405180608001604052808981526020018881526020018781526020018681525061147a565b33600081815260676020908152604080832086518784012084528252808320805460ff1916600117905580516080810182528b81529182018a90528101889052606081018790529091610c5f918661150e565b90508115610c8c578181604051602001610c7a9291906127fe565b60405160208183030381529060405290505b610c94611769565b8051602082012060405133917f092e72bcc568a2ad800b1d7bbd7cc3f305e4a7b596092c69d10da00e38d705e691610cd9918c918c918c918c918c918c918c916128ed565b60405180910390a25050505050505050565b6033546001600160a01b03163314610d155760405162461bcd60e51b815260040161047c9061244c565b610d1f60006117e5565b565b610d2a336113ba565b158015610d38575060665434105b15610d56576040516339b4a7f160e11b815260040160405180910390fd5b336000908152606760209081526040808320865187840120845290915290205460ff16610d9657604051636a76632960e11b815260040160405180910390fd5b610dbf60405180608001604052808a81526020018981526020018881526020018781525061147a565b6000610dec3360405180608001604052808c81526020018b81526020018a8152602001898152508761150e565b90508215610e19578281604051602001610e079291906127fe565b60405160208183030381529060405290505b610e21611769565b8051602082012060405133917f918063625a303d021375548c338d007d2857e576643789b387992dcfe04449cc91610a3f918d918d918d918d918d918d918d918d9061297d565b600054610100900460ff1680610e81575060005460ff16155b610ee45760405162461bcd60e51b815260206004820152602e60248201527f496e697469616c697a61626c653a20636f6e747261637420697320616c72656160448201526d191e481a5b9a5d1a585b1a5e995960921b606482015260840161047c565b600054610100900460ff16158015610f06576000805461ffff19166101011790555b610f0f856117e5565b60658490556066839055606880546001600160a01b0319166001600160a01b0384161790558015610f46576000805461ff00191690555b5050505050565b6033546001600160a01b03163314610f775760405162461bcd60e51b815260040161047c9061244c565b606880546001600160a01b038381166001600160a01b0319831681179093556040519116919082907f15d80a013f22151bc7246e3bc132e12828cde19de98870475e3fa7084015272190600090a35050565b6033546001600160a01b03163314610ff35760405162461bcd60e51b815260040161047c9061244c565b6001600160a01b0381166110585760405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201526564647265737360d01b606482015260840161047c565b61067c816117e5565b60028260ff16111561108657604051634f81348960e11b815260040160405180910390fd5b336001600160a01b03167f66777d398af2d3ad91be043f4ee15e0058fd64a2badd9977e29334dc608bbfa68484846040516110c393929190612a26565b60405180910390a2505050565b7f360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc546001600160a01b031690565b6033546001600160a01b0316331461067c5760405162461bcd60e51b815260040161047c9061244c565b60006111326110d0565b905061113d84611837565b60008351118061114a5750815b1561115b5761115984846118dc565b505b7f4910fdfa16fed3260ed0e7147f7cc6da11a60208b5b9406d12a635614ffd9143805460ff16610f4657805460ff191660011781556040516001600160a01b03831660248201526111da90869060440160408051601f198184030181529190526020810180516001600160e01b0316631b2ce7f360e11b1790526118dc565b50805460ff191681556111eb6110d0565b6001600160a01b0316826001600160a01b0316146112635760405162461bcd60e51b815260206004820152602f60248201527f45524331393637557067726164653a207570677261646520627265616b73206660448201526e75727468657220757067726164657360881b606482015260840161047c565b610f468561190a565b60008085858560405160200161128493929190612a51565b60408051808303601f190181528282528051602091820120838301835260098452684e6f756e732044414f60b81b9382019390935281517f8cad95687ba82c2ce50e74f7b754645e5117c3a5bec8151c0726d5857980a866818301527fe1dd93b3612547b4bb7c3d429f3df8508d84f5a4f63b5e2e44340b94698e6b3b818401524660608201526001600160a01b03969096166080808801919091528251808803909101815260a0870192839052805191012061190160f01b825260a286015260c2909401525050604290209392505050565b6000806000611366858561194a565b9092509050600081600481111561137f5761137f612a7e565b14801561139d5750856001600160a01b0316826001600160a01b0316145b806113ae57506113ae86868661198f565b925050505b9392505050565b6000806001600160a01b037f0000000000000000000000009c8ff314c9bc7f6e59a9d9225fb22946427edc031663782d6fe1846113f8600143612aaa565b6040516001600160e01b031960e085901b1681526001600160a01b0390921660048301526024820152604401602060405180830381865afa158015611441573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906114659190612abd565b6bffffffffffffffffffffffff161192915050565b602081015151815151141580611497575060408101515181515114155b806114a9575060608101515181515114155b156114c75760405163ccb0ce3f60e01b815260040160405180910390fd5b8051516000036114ea57604051630f24cd7360e01b815260040160405180910390fd5b805151600a101561067c576040516308e3b1eb60e11b815260040160405180910390fd5b606060008360400151516001600160401b0381111561152f5761152f611c5b565b604051908082528060200260200182016040528015611558578160200160208202803683370190505b50905060005b8460400151518110156115bd578460400151818151811061158157611581612aeb565b6020026020010151805190602001208282815181106115a2576115a2612aeb565b60209081029190910101526115b681612b01565b905061155e565b5060008460600151516001600160401b038111156115dd576115dd611c5b565b604051908082528060200260200182016040528015611606578160200160208202803683370190505b50905060005b85606001515181101561166b578560600151818151811061162f5761162f612aeb565b60200260200101518051906020012082828151811061165057611650612aeb565b602090810291909101015261166481612b01565b905061160c565b508451604051879161167f91602001612b1a565b6040516020818303038152906040528051906020012086602001516040516020016116aa9190612b59565b60405160208183030381529060405280519060200120846040516020016116d19190612b59565b60405160208183030381529060405280519060200120846040516020016116f89190612b59565b60408051601f1981840301815282825280516020918201208b518c8301206001600160a01b0390981691840191909152908201949094526060810192909252608082015260a081019190915260c081019190915260e001604051602081830303815290604052925050509392505050565b6068546001600160a01b0316341580159061178c57506001600160a01b03811615155b1561067c576040516001600160a01b038216903490600081818185875af1925050503d80600081146117da576040519150601f19603f3d011682016040523d82523d6000602084013e6117df565b606091505b50505050565b603380546001600160a01b038381166001600160a01b0319831681179093556040519116919082907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e090600090a35050565b803b61189b5760405162461bcd60e51b815260206004820152602d60248201527f455243313936373a206e657720696d706c656d656e746174696f6e206973206e60448201526c1bdd08184818dbdb9d1c9858dd609a1b606482015260840161047c565b7f360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc80546001600160a01b0319166001600160a01b0392909216919091179055565b60606119018383604051806060016040528060278152602001612bd260279139611a7b565b90505b92915050565b61191381611837565b6040516001600160a01b038216907fbc7cd75a20ee27fd9adebab32041f755214dbc6bffa90cc0225b39da2e5c2d3b90600090a250565b60008082516041036119805760208301516040840151606085015160001a61197487828585611b45565b94509450505050611988565b506000905060025b9250929050565b6000806000856001600160a01b0316631626ba7e60e01b86866040516024016119b9929190612b83565b60408051601f198184030181529181526020820180516001600160e01b03166001600160e01b03199094169390931790925290516119f79190612b9c565b600060405180830381855afa9150503d8060008114611a32576040519150601f19603f3d011682016040523d82523d6000602084013e611a37565b606091505b5091509150818015611a4b57506020815110155b80156113ae57508051630b135d3f60e11b90611a709083016020908101908401612bb8565b149695505050505050565b6060833b611ada5760405162461bcd60e51b815260206004820152602660248201527f416464726573733a2064656c65676174652063616c6c20746f206e6f6e2d636f6044820152651b9d1c9858dd60d21b606482015260840161047c565b600080856001600160a01b031685604051611af59190612b9c565b600060405180830381855af49150503d8060008114611b30576040519150601f19603f3d011682016040523d82523d6000602084013e611b35565b606091505b50915091506113ae828286611c09565b6000807f7fffffffffffffffffffffffffffffff5d576e7357a4501ddfe92f46681b20a0831115611b7c5750600090506003611c00565b6040805160008082526020820180845289905260ff881692820192909252606081018690526080810185905260019060a0016020604051602081039080840390855afa158015611bd0573d6000803e3d6000fd5b5050604051601f1901519150506001600160a01b038116611bf957600060019250925050611c00565b9150600090505b94509492505050565b60608315611c185750816113b3565b825115611c285782518084602001fd5b8160405162461bcd60e51b815260040161047c91906124d1565b600060208284031215611c5457600080fd5b5035919050565b634e487b7160e01b600052604160045260246000fd5b60405161026081016001600160401b0381118282101715611c9457611c94611c5b565b60405290565b604051601f8201601f191681016001600160401b0381118282101715611cc257611cc2611c5b565b604052919050565b600082601f830112611cdb57600080fd5b81356001600160401b03811115611cf457611cf4611c5b565b611d07601f8201601f1916602001611c9a565b818152846020838601011115611d1c57600080fd5b816020850160208301376000918101602001919091529392505050565b600060208284031215611d4b57600080fd5b81356001600160401b03811115611d6157600080fd5b611d6d84828501611cca565b949350505050565b6001600160a01b038116811461067c57600080fd5b8035611d9581611d75565b919050565b600060208284031215611dac57600080fd5b81356113b381611d75565b60008060408385031215611dca57600080fd5b8235611dd581611d75565b946020939093013593505050565b803560ff81168114611d9557600080fd5b60008060008060808587031215611e0a57600080fd5b8435611e1581611d75565b935060208501356001600160401b0380821115611e3157600080fd5b611e3d88838901611cca565b9450611e4b60408801611de3565b93506060870135915080821115611e6157600080fd5b50611e6e87828801611cca565b91505092959194509250565b60008060408385031215611e8d57600080fd5b8235611e9881611d75565b915060208301356001600160401b03811115611eb357600080fd5b611ebf85828601611cca565b9150509250929050565b600080600080600080600060e0888a031215611ee457600080fd5b87356001600160401b0380821115611efb57600080fd5b611f078b838c01611cca565b985060208a01359750611f1c60408b01611d8a565b965060608a0135915080821115611f3257600080fd5b611f3e8b838c01611cca565b955060808a0135945060a08a0135915080821115611f5b57600080fd5b611f678b838c01611cca565b935060c08a0135915080821115611f7d57600080fd5b50611f8a8a828b01611cca565b91505092959891949750929550565b60006001600160401b03821115611fb257611fb2611c5b565b5060051b60200190565b600082601f830112611fcd57600080fd5b81356020611fe2611fdd83611f99565b611c9a565b82815260059290921b8401810191818101908684111561200157600080fd5b8286015b8481101561202557803561201881611d75565b8352918301918301612005565b509695505050505050565b600082601f83011261204157600080fd5b81356020612051611fdd83611f99565b82815260059290921b8401810191818101908684111561207057600080fd5b8286015b848110156120255780358352918301918301612074565b600082601f83011261209c57600080fd5b813560206120ac611fdd83611f99565b82815260059290921b840181019181810190868411156120cb57600080fd5b8286015b848110156120255780356001600160401b038111156120ee5760008081fd5b6120fc8986838b0101611cca565b8452509183019183016120cf565b600082601f83011261211b57600080fd5b8135602061212b611fdd83611f99565b82815260059290921b8401810191818101908684111561214a57600080fd5b8286015b848110156120255780356001600160401b0381111561216d5760008081fd5b61217b8986838b0101611cca565b84525091830191830161214e565b600080600080600080600060e0888a0312156121a457600080fd5b87356001600160401b03808211156121bb57600080fd5b6121c78b838c01611fbc565b985060208a01359150808211156121dd57600080fd5b6121e98b838c01612030565b975060408a01359150808211156121ff57600080fd5b61220b8b838c0161208b565b965060608a013591508082111561222157600080fd5b61222d8b838c0161210a565b955060808a013591508082111561224357600080fd5b61224f8b838c01611cca565b945060a08a013591508082111561226557600080fd5b506122728a828b01611cca565b92505060c0880135905092959891949750929550565b600080600080600080600080610100898b0312156122a557600080fd5b88356001600160401b03808211156122bc57600080fd5b6122c88c838d01611fbc565b995060208b01359150808211156122de57600080fd5b6122ea8c838d01612030565b985060408b013591508082111561230057600080fd5b61230c8c838d0161208b565b975060608b013591508082111561232257600080fd5b61232e8c838d0161210a565b965060808b013591508082111561234457600080fd5b6123508c838d01611cca565b955060a08b013591508082111561236657600080fd5b6123728c838d01611cca565b945060c08b0135935060e08b013591508082111561238f57600080fd5b5061239c8b828c01611cca565b9150509295985092959890939650565b600080600080608085870312156123c257600080fd5b84356123cd81611d75565b9350602085013592506040850135915060608501356123eb81611d75565b939692955090935050565b60008060006060848603121561240b57600080fd5b8335925061241b60208501611de3565b915060408401356001600160401b0381111561243657600080fd5b61244286828701611cca565b9150509250925092565b6020808252818101527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604082015260600190565b60005b8381101561249c578181015183820152602001612484565b50506000910152565b600081518084526124bd816020860160208601612481565b601f01601f19169290920160200192915050565b60208152600061190160208301846124a5565b6020808252602c908201527f46756e6374696f6e206d7573742062652063616c6c6564207468726f7567682060408201526b19195b1959d85d1958d85b1b60a21b606082015260800190565b6020808252602c908201527f46756e6374696f6e206d7573742062652063616c6c6564207468726f7567682060408201526b6163746976652070726f787960a01b606082015260800190565b60608152600061258f60608301866124a5565b60ff8516602084015282810360408401526125aa81856124a5565b9695505050505050565b60006101008083526125c88184018c6124a5565b602084018b90526001600160a01b038a166040850152838103606085015290506125f281896124a5565b90508660808401528560a08401528460c084015282810360e084015261261881856124a5565b9b9a5050505050505050505050565b8051611d9581611d75565b80518015158114611d9557600080fd5b600082601f83011261265357600080fd5b81516020612663611fdd83611f99565b82815260059290921b8401810191818101908684111561268257600080fd5b8286015b8481101561202557805161269981611d75565b8352918301918301612686565b6000602082840312156126b857600080fd5b81516001600160401b03808211156126cf57600080fd5b9083019061026082860312156126e457600080fd5b6126ec611c71565b825181526126fc60208401612627565b602082015260408301516040820152606083015160608201526080830151608082015260a083015160a082015260c083015160c082015260e083015160e0820152610100808401518183015250610120808401518183015250610140612763818501612632565b90820152610160612775848201612632565b90820152610180612787848201612632565b908201526101a083810151908201526101c080840151908201526101e080840151838111156127b557600080fd5b6127c188828701612642565b91830191909152506102008381015190820152610220808401519082015261024091506127ef828401612632565b91810191909152949350505050565b82815260008251612816816020850160208701612481565b919091016020019392505050565b600081518084526020808501945080840160005b8381101561285d5781516001600160a01b031687529582019590820190600101612838565b509495945050505050565b600081518084526020808501945080840160005b8381101561285d5781518752958201959082019060010161287c565b600081518084526020808501808196508360051b8101915082860160005b858110156128e05782840389526128ce8483516124a5565b988501989350908401906001016128b6565b5091979650505050505050565b60006101008083526129018184018c612824565b90508281036020840152612915818b612868565b90508281036040840152612929818a612898565b9050828103606084015261293d8189612898565b9050828103608084015261295181886124a5565b905082810360a084015261296581876124a5565b60c0840195909552505060e001529695505050505050565b60006101208083526129918184018d612824565b905082810360208401526129a5818c612868565b905082810360408401526129b9818b612898565b905082810360608401526129cd818a612898565b905082810360808401526129e181896124a5565b905082810360a08401526129f581886124a5565b90508560c08401528460e0840152828103610100840152612a1681856124a5565b9c9b505050505050505050505050565b83815260ff83166020820152606060408201526000612a4860608301846124a5565b95945050505050565b83815260008351612a69816020850160208801612481565b60209201918201929092526040019392505050565b634e487b7160e01b600052602160045260246000fd5b634e487b7160e01b600052601160045260246000fd5b8181038181111561190457611904612a94565b600060208284031215612acf57600080fd5b81516bffffffffffffffffffffffff811681146113b357600080fd5b634e487b7160e01b600052603260045260246000fd5b600060018201612b1357612b13612a94565b5060010190565b815160009082906020808601845b83811015612b4d5781516001600160a01b031685529382019390820190600101612b28565b50929695505050505050565b815160009082906020808601845b83811015612b4d57815185529382019390820190600101612b67565b828152604060208201526000611d6d60408301846124a5565b60008251612bae818460208701612481565b9190910192915050565b600060208284031215612bca57600080fd5b505191905056fe416464726573733a206c6f772d6c6576656c2064656c65676174652063616c6c206661696c6564a2646970667358221220dab756ecdf5f8514a12011b2bb45591891a562bc69453a45f2dca2811d6e09fe64736f6c63430008130033
Constructor Arguments (ABI-Encoded and is the last bytes of the Contract Creation Code above)
0000000000000000000000009c8ff314c9bc7f6e59a9d9225fb22946427edc030000000000000000000000006f3e6272a167e8accb32072d08e0957f9c79223d
-----Decoded View---------------
Arg [0] : nounsToken_ (address): 0x9C8fF314C9Bc7F6e59A9d9225Fb22946427eDC03
Arg [1] : nounsDao_ (address): 0x6f3E6272A167e8AcCb32072d08E0957F9c79223d
-----Encoded View---------------
2 Constructor Arguments found :
Arg [0] : 0000000000000000000000009c8ff314c9bc7f6e59a9d9225fb22946427edc03
Arg [1] : 0000000000000000000000006f3e6272a167e8accb32072d08e0957f9c79223d
Loading...
Loading
Loading...
Loading
Multichain Portfolio | 35 Chains
Chain | Token | Portfolio % | Price | Amount | Value |
---|
Loading...
Loading
Loading...
Loading
Loading...
Loading
A contract address hosts a smart contract, which is a set of code stored on the blockchain that runs when predetermined conditions are met. Learn more about addresses in our Knowledge Base.