Overview
ETH Balance
0 ETH
Eth Value
$0.00More Info
Private Name Tags
ContractCreator
Transaction Hash |
Method
|
Block
|
From
|
To
|
|||||
---|---|---|---|---|---|---|---|---|---|
Latest 12 internal transactions
Advanced mode:
Parent Transaction Hash | Block |
From
|
To
|
|||
---|---|---|---|---|---|---|
18587497 | 406 days ago | Contract Creation | 0 ETH | |||
18587497 | 406 days ago | Contract Creation | 0 ETH | |||
18587497 | 406 days ago | Contract Creation | 0 ETH | |||
18587497 | 406 days ago | Contract Creation | 0 ETH | |||
18302029 | 446 days ago | Contract Creation | 0 ETH | |||
18302029 | 446 days ago | Contract Creation | 0 ETH | |||
18302029 | 446 days ago | Contract Creation | 0 ETH | |||
18302029 | 446 days ago | Contract Creation | 0 ETH | |||
18094362 | 475 days ago | Contract Creation | 0 ETH | |||
18094362 | 475 days ago | Contract Creation | 0 ETH | |||
18094362 | 475 days ago | Contract Creation | 0 ETH | |||
18094362 | 475 days ago | Contract Creation | 0 ETH |
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:
ForkDAODeployer
Compiler Version
v0.8.19+commit.7dd6d404
Optimization Enabled:
Yes with 200 runs
Other Settings:
default evmVersion
Contract Source Code (Solidity Standard Json-Input format)
// SPDX-License-Identifier: GPL-3.0 /// @title The deployer of new Nouns DAO forks /********************************* * ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ * * ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ * * ░░░░░░█████████░░█████████░░░ * * ░░░░░░██░░░████░░██░░░████░░░ * * ░░██████░░░████████░░░████░░░ * * ░░██░░██░░░████░░██░░░████░░░ * * ░░██░░██░░░████░░██░░░████░░░ * * ░░░░░░█████████░░█████████░░░ * * ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ * * ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ * *********************************/ pragma solidity ^0.8.19; import { ERC1967Proxy } from '@openzeppelin/contracts/proxy/ERC1967/ERC1967Proxy.sol'; import { IForkDAODeployer, INounsDAOForkEscrow, NounsDAOStorageV3 } from '../NounsDAOInterfaces.sol'; import { NounsTokenFork } from './newdao/token/NounsTokenFork.sol'; import { NounsAuctionHouseFork } from './newdao/NounsAuctionHouseFork.sol'; import { NounsDAOExecutorV2 } from '../NounsDAOExecutorV2.sol'; import { NounsDAOProxy } from '../NounsDAOProxy.sol'; import { NounsDAOLogicV3 } from '../NounsDAOLogicV3.sol'; import { NounsDAOLogicV1Fork } from './newdao/governance/NounsDAOLogicV1Fork.sol'; import { NounsToken } from '../../NounsToken.sol'; import { NounsAuctionHouse } from '../../NounsAuctionHouse.sol'; contract ForkDAODeployer is IForkDAODeployer { event DAODeployed(address token, address auction, address governor, address treasury); /// @notice The token implementation address address public immutable tokenImpl; /// @notice The auction house implementation address address public immutable auctionImpl; /// @notice The treasury implementation address address public immutable treasuryImpl; /// @notice The governor implementation address address public immutable governorImpl; /// @notice The maximum duration of the governance delay in new DAOs uint256 public immutable delayedGovernanceMaxDuration; /// @notice The initial voting period in new DAOs, in blocks uint256 public immutable initialVotingPeriod; /// @notice The initial voting delay in new DAOs, in blocks uint256 public immutable initialVotingDelay; /// @notice The initial proposal threshold in new DAOs, in BPS uint256 public immutable initialProposalThresholdBPS; /// @notice The initial quorum votes in new DAOs, in BPS uint256 public immutable initialQuorumVotesBPS; constructor( address tokenImpl_, address auctionImpl_, address governorImpl_, address treasuryImpl_, uint256 delayedGovernanceMaxDuration_, uint256 initialVotingPeriod_, uint256 initialVotingDelay_, uint256 initialProposalThresholdBPS_, uint256 initialQuorumVotesBPS_ ) { tokenImpl = tokenImpl_; auctionImpl = auctionImpl_; governorImpl = governorImpl_; treasuryImpl = treasuryImpl_; delayedGovernanceMaxDuration = delayedGovernanceMaxDuration_; initialVotingPeriod = initialVotingPeriod_; initialVotingDelay = initialVotingDelay_; initialProposalThresholdBPS = initialProposalThresholdBPS_; initialQuorumVotesBPS = initialQuorumVotesBPS_; } /** * @notice Deploys a new Nouns DAO fork, including a new token, auction house, governor, and treasury. * All contracts are upgradable, and are almost entirely initialized with the same parameters as the original DAO. * @param forkingPeriodEndTimestamp The timestamp at which the forking period ends * @param forkEscrow The address of the fork escrow contract, used for claiming tokens that were escrowed in the original DAO * and to get references to the original DAO's auction house and timelock * @return treasury The address of the fork DAO treasury * @return token The address of the fork DAO token */ function deployForkDAO(uint256 forkingPeriodEndTimestamp, INounsDAOForkEscrow forkEscrow) external returns (address treasury, address token) { token = address(new ERC1967Proxy(tokenImpl, '')); address auction = address(new ERC1967Proxy(auctionImpl, '')); address governor = address(new ERC1967Proxy(governorImpl, '')); treasury = address(new ERC1967Proxy(treasuryImpl, '')); NounsAuctionHouse originalAuction = getOriginalAuction(forkEscrow); NounsDAOExecutorV2 originalTimelock = getOriginalTimelock(forkEscrow); NounsTokenFork(token).initialize( treasury, auction, forkEscrow, forkEscrow.forkId(), getStartNounId(originalAuction), forkEscrow.numTokensInEscrow(), forkingPeriodEndTimestamp ); NounsAuctionHouseFork(auction).initialize( treasury, NounsToken(token), originalAuction.weth(), originalAuction.timeBuffer(), originalAuction.reservePrice(), originalAuction.minBidIncrementPercentage(), originalAuction.duration() ); initDAO(governor, treasury, token, originalTimelock); NounsDAOExecutorV2(payable(treasury)).initialize(governor, originalTimelock.delay()); emit DAODeployed(token, auction, governor, treasury); } /** * @dev Used to prevent the 'Stack too deep' error in the main deploy function. */ function initDAO( address governor, address treasury, address token, NounsDAOExecutorV2 originalTimelock ) internal { NounsDAOLogicV3 originalDAO = NounsDAOLogicV3(payable(originalTimelock.admin())); NounsDAOLogicV1Fork(governor).initialize( treasury, token, initialVotingPeriod, initialVotingDelay, initialProposalThresholdBPS, initialQuorumVotesBPS, originalDAO.erc20TokensToIncludeInFork(), block.timestamp + delayedGovernanceMaxDuration ); } /** * @dev Used to prevent the 'Stack too deep' error in the main deploy function. */ function getOriginalTimelock(INounsDAOForkEscrow forkEscrow) internal view returns (NounsDAOExecutorV2) { NounsToken originalToken = NounsToken(address(forkEscrow.nounsToken())); return NounsDAOExecutorV2(payable(originalToken.owner())); } /** * @dev Used to prevent the 'Stack too deep' error in the main deploy function. */ function getOriginalAuction(INounsDAOForkEscrow forkEscrow) internal view returns (NounsAuctionHouse) { NounsToken originalToken = NounsToken(address(forkEscrow.nounsToken())); return NounsAuctionHouse(originalToken.minter()); } function getStartNounId(NounsAuctionHouse originalAuction) internal view returns (uint256) { (uint256 nounId, , , , , ) = originalAuction.auction(); return nounId; } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.0 (proxy/ERC1967/ERC1967Proxy.sol) pragma solidity ^0.8.0; import "../Proxy.sol"; import "./ERC1967Upgrade.sol"; /** * @dev This contract implements an upgradeable proxy. It is upgradeable because calls are delegated to an * implementation address that can be changed. This address is stored in storage in the location specified by * https://eips.ethereum.org/EIPS/eip-1967[EIP1967], so that it doesn't conflict with the storage layout of the * implementation behind the proxy. */ contract ERC1967Proxy is Proxy, ERC1967Upgrade { /** * @dev Initializes the upgradeable proxy with an initial implementation specified by `_logic`. * * If `_data` is nonempty, it's used as data in a delegate call to `_logic`. This will typically be an encoded * function call, and allows initializating the storage of the proxy like a Solidity constructor. */ constructor(address _logic, bytes memory _data) payable { assert(_IMPLEMENTATION_SLOT == bytes32(uint256(keccak256("eip1967.proxy.implementation")) - 1)); _upgradeToAndCall(_logic, _data, false); } /** * @dev Returns the current implementation address. */ function _implementation() internal view virtual override returns (address impl) { return ERC1967Upgrade._getImplementation(); } }
// 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: 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: GPL-3.0 /// @title The Nouns DAO auction house, supporting UUPS upgrades /********************************* * ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ * * ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ * * ░░░░░░█████████░░█████████░░░ * * ░░░░░░██░░░████░░██░░░████░░░ * * ░░██████░░░████████░░░████░░░ * * ░░██░░██░░░████░░██░░░████░░░ * * ░░██░░██░░░████░░██░░░████░░░ * * ░░░░░░█████████░░█████████░░░ * * ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ * * ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ * *********************************/ // LICENSE // NounsAuctionHouseFork.sol is a modified version of NounsAuctionHouse.sol. // NounsAuctionHouse.sol is a modified version of Zora's AuctionHouse.sol: // https://github.com/ourzora/auction-house/blob/54a12ec1a6cf562e49f0a4917990474b11350a2d/contracts/AuctionHouse.sol // // AuctionHouse.sol source code Copyright Zora licensed under the GPL-3.0 license. // With modifications by Nounders DAO. // // NounsAuctionHouseFork.sol Modifications: // - Proxy pattern changed from Transparent to UUPS. // - Owner is set in the initialize function, instead of in a follow-up transaction. pragma solidity ^0.8.19; import { PausableUpgradeable } from '@openzeppelin/contracts-upgradeable/security/PausableUpgradeable.sol'; import { ReentrancyGuardUpgradeable } from '@openzeppelin/contracts-upgradeable/security/ReentrancyGuardUpgradeable.sol'; import { OwnableUpgradeable } from '@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol'; import { IERC20 } from '@openzeppelin/contracts/token/ERC20/IERC20.sol'; import { INounsAuctionHouse } from '../../../interfaces/INounsAuctionHouse.sol'; import { INounsToken } from '../../../interfaces/INounsToken.sol'; import { IWETH } from '../../../interfaces/IWETH.sol'; import { UUPSUpgradeable } from '@openzeppelin/contracts/proxy/utils/UUPSUpgradeable.sol'; contract NounsAuctionHouseFork is INounsAuctionHouse, PausableUpgradeable, ReentrancyGuardUpgradeable, OwnableUpgradeable, UUPSUpgradeable { string public constant NAME = 'NounsAuctionHouseFork'; // The Nouns ERC721 token contract INounsToken public nouns; // The address of the WETH contract address public weth; // The minimum amount of time left in an auction after a new bid is created uint256 public timeBuffer; // The minimum price accepted in an auction uint256 public reservePrice; // The minimum percentage difference between the last bid amount and the current bid uint8 public minBidIncrementPercentage; // The duration of a single auction uint256 public duration; // The active auction INounsAuctionHouse.Auction public auction; constructor() initializer {} /** * @notice Initialize the auction house and base contracts, * populate configuration values, and pause the contract. * @dev This function can only be called once. */ function initialize( address _owner, INounsToken _nouns, address _weth, uint256 _timeBuffer, uint256 _reservePrice, uint8 _minBidIncrementPercentage, uint256 _duration ) external initializer { __Pausable_init(); __ReentrancyGuard_init(); _transferOwnership(_owner); _pause(); nouns = _nouns; weth = _weth; timeBuffer = _timeBuffer; reservePrice = _reservePrice; minBidIncrementPercentage = _minBidIncrementPercentage; duration = _duration; } /** * @notice Settle the current auction, mint a new Noun, and put it up for auction. */ function settleCurrentAndCreateNewAuction() external override nonReentrant whenNotPaused { _settleAuction(); _createAuction(); } /** * @notice Settle the current auction. * @dev This function can only be called when the contract is paused. */ function settleAuction() external override whenPaused nonReentrant { _settleAuction(); } /** * @notice Create a bid for a Noun, with a given amount. * @dev This contract only accepts payment in ETH. */ function createBid(uint256 nounId) external payable override nonReentrant { INounsAuctionHouse.Auction memory _auction = auction; require(_auction.nounId == nounId, 'Noun not up for auction'); require(block.timestamp < _auction.endTime, 'Auction expired'); require(msg.value >= reservePrice, 'Must send at least reservePrice'); require( msg.value >= _auction.amount + ((_auction.amount * minBidIncrementPercentage) / 100), 'Must send more than last bid by minBidIncrementPercentage amount' ); address payable lastBidder = _auction.bidder; // Refund the last bidder, if applicable if (lastBidder != address(0)) { _safeTransferETHWithFallback(lastBidder, _auction.amount); } auction.amount = msg.value; auction.bidder = payable(msg.sender); // Extend the auction if the bid was received within `timeBuffer` of the auction end time bool extended = _auction.endTime - block.timestamp < timeBuffer; if (extended) { auction.endTime = _auction.endTime = block.timestamp + timeBuffer; } emit AuctionBid(_auction.nounId, msg.sender, msg.value, extended); if (extended) { emit AuctionExtended(_auction.nounId, _auction.endTime); } } /** * @notice Pause the Nouns auction house. * @dev This function can only be called by the owner when the * contract is unpaused. While no new auctions can be started when paused, * anyone can settle an ongoing auction. */ function pause() external override onlyOwner { _pause(); } /** * @notice Unpause the Nouns auction house. * @dev This function can only be called by the owner when the * contract is paused. If required, this function will start a new auction. */ function unpause() external override onlyOwner { _unpause(); if (auction.startTime == 0 || auction.settled) { _createAuction(); } } /** * @notice Set the auction time buffer. * @dev Only callable by the owner. */ function setTimeBuffer(uint256 _timeBuffer) external override onlyOwner { timeBuffer = _timeBuffer; emit AuctionTimeBufferUpdated(_timeBuffer); } /** * @notice Set the auction reserve price. * @dev Only callable by the owner. */ function setReservePrice(uint256 _reservePrice) external override onlyOwner { reservePrice = _reservePrice; emit AuctionReservePriceUpdated(_reservePrice); } /** * @notice Set the auction minimum bid increment percentage. * @dev Only callable by the owner. */ function setMinBidIncrementPercentage(uint8 _minBidIncrementPercentage) external override onlyOwner { minBidIncrementPercentage = _minBidIncrementPercentage; emit AuctionMinBidIncrementPercentageUpdated(_minBidIncrementPercentage); } /** * @notice Create an auction. * @dev Store the auction details in the `auction` state variable and emit an AuctionCreated event. * If the mint reverts, the minter was updated without pausing this contract first. To remedy this, * catch the revert and pause this contract. */ function _createAuction() internal { try nouns.mint() returns (uint256 nounId) { uint256 startTime = block.timestamp; uint256 endTime = startTime + duration; auction = Auction({ nounId: nounId, amount: 0, startTime: startTime, endTime: endTime, bidder: payable(0), settled: false }); emit AuctionCreated(nounId, startTime, endTime); } catch Error(string memory) { _pause(); } } /** * @notice Settle an auction, finalizing the bid and paying out to the owner. * @dev If there are no bids, the Noun is burned. */ function _settleAuction() internal { INounsAuctionHouse.Auction memory _auction = auction; require(_auction.startTime != 0, "Auction hasn't begun"); require(!_auction.settled, 'Auction has already been settled'); require(block.timestamp >= _auction.endTime, "Auction hasn't completed"); auction.settled = true; if (_auction.bidder == address(0)) { nouns.burn(_auction.nounId); } else { nouns.transferFrom(address(this), _auction.bidder, _auction.nounId); } if (_auction.amount > 0) { _safeTransferETHWithFallback(owner(), _auction.amount); } emit AuctionSettled(_auction.nounId, _auction.bidder, _auction.amount); } /** * @notice Transfer ETH. If the ETH transfer fails, wrap the ETH and try send it as WETH. */ function _safeTransferETHWithFallback(address to, uint256 amount) internal { if (!_safeTransferETH(to, amount)) { IWETH(weth).deposit{ value: amount }(); IERC20(weth).transfer(to, amount); } } /** * @notice Transfer ETH and return the success status. * @dev This function only forwards 30,000 gas to the callee. */ function _safeTransferETH(address to, uint256 value) internal returns (bool) { (bool success, ) = to.call{ value: value, gas: 30_000 }(new bytes(0)); return success; } /** * @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: BSD-3-Clause /// @title The Nouns DAO executor and treasury, supporting DAO fork /********************************* * ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ * * ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ * * ░░░░░░█████████░░█████████░░░ * * ░░░░░░██░░░████░░██░░░████░░░ * * ░░██████░░░████████░░░████░░░ * * ░░██░░██░░░████░░██░░░████░░░ * * ░░██░░██░░░████░░██░░░████░░░ * * ░░░░░░█████████░░█████████░░░ * * ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ * * ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ * *********************************/ // LICENSE // NounsDAOExecutor2.sol is a modified version of Compound Lab's Timelock.sol: // https://github.com/compound-finance/compound-protocol/blob/20abad28055a2f91df48a90f8bb6009279a4cb35/contracts/Timelock.sol // // Timelock.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 // NounsDAOExecutor2.sol is a modified version of NounsDAOExecutor.sol // // NounsDAOExecutor.sol modifications: // NounsDAOExecutor.sol modifies Timelock to use Solidity 0.8.x receive(), fallback(), and built-in over/underflow protection // This contract acts as executor of Nouns DAO governance and its treasury, so it has been modified to accept ETH. // // // NounsDAOExecutor2.sol modifications: // - `sendETH` and `sendERC20` functions used for DAO forks // - is upgradable via UUPSUpgradeable. uses intializer instead of constructor. // - `GRACE_PERIOD` has been increased from 14 days to 21 days to allow more time in case of a forking period pragma solidity ^0.8.19; import { IERC20 } from '@openzeppelin/contracts/token/ERC20/IERC20.sol'; import { SafeERC20 } from '@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol'; import { Initializable } from '@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol'; import { UUPSUpgradeable } from '@openzeppelin/contracts/proxy/utils/UUPSUpgradeable.sol'; import { Address } from '@openzeppelin/contracts/utils/Address.sol'; contract NounsDAOExecutorV2 is UUPSUpgradeable, Initializable { using SafeERC20 for IERC20; using Address for address payable; event NewAdmin(address indexed newAdmin); event NewPendingAdmin(address indexed newPendingAdmin); event NewDelay(uint256 indexed newDelay); event CancelTransaction( bytes32 indexed txHash, address indexed target, uint256 value, string signature, bytes data, uint256 eta ); event ExecuteTransaction( bytes32 indexed txHash, address indexed target, uint256 value, string signature, bytes data, uint256 eta ); event QueueTransaction( bytes32 indexed txHash, address indexed target, uint256 value, string signature, bytes data, uint256 eta ); event ETHSent(address indexed to, uint256 amount); event ERC20Sent(address indexed to, address indexed erc20Token, uint256 amount); string public constant NAME = 'NounsDAOExecutorV2'; /// @dev increased grace period from 14 days to 21 days to allow more time in case of a forking period uint256 public constant GRACE_PERIOD = 21 days; uint256 public constant MINIMUM_DELAY = 2 days; uint256 public constant MAXIMUM_DELAY = 30 days; address public admin; address public pendingAdmin; uint256 public delay; mapping(bytes32 => bool) public queuedTransactions; constructor() initializer {} function initialize(address admin_, uint256 delay_) public virtual initializer { require(delay_ >= MINIMUM_DELAY, 'NounsDAOExecutor::constructor: Delay must exceed minimum delay.'); require(delay_ <= MAXIMUM_DELAY, 'NounsDAOExecutor::setDelay: Delay must not exceed maximum delay.'); admin = admin_; delay = delay_; } function setDelay(uint256 delay_) public { require(msg.sender == address(this), 'NounsDAOExecutor::setDelay: Call must come from NounsDAOExecutor.'); require(delay_ >= MINIMUM_DELAY, 'NounsDAOExecutor::setDelay: Delay must exceed minimum delay.'); require(delay_ <= MAXIMUM_DELAY, 'NounsDAOExecutor::setDelay: Delay must not exceed maximum delay.'); delay = delay_; emit NewDelay(delay_); } function acceptAdmin() public { require(msg.sender == pendingAdmin, 'NounsDAOExecutor::acceptAdmin: Call must come from pendingAdmin.'); admin = msg.sender; pendingAdmin = address(0); emit NewAdmin(msg.sender); } function setPendingAdmin(address pendingAdmin_) public { require( msg.sender == address(this), 'NounsDAOExecutor::setPendingAdmin: Call must come from NounsDAOExecutor.' ); pendingAdmin = pendingAdmin_; emit NewPendingAdmin(pendingAdmin_); } function queueTransaction( address target, uint256 value, string memory signature, bytes memory data, uint256 eta ) public returns (bytes32) { require(msg.sender == admin, 'NounsDAOExecutor::queueTransaction: Call must come from admin.'); require( eta >= getBlockTimestamp() + delay, 'NounsDAOExecutor::queueTransaction: Estimated execution block must satisfy delay.' ); bytes32 txHash = keccak256(abi.encode(target, value, signature, data, eta)); queuedTransactions[txHash] = true; emit QueueTransaction(txHash, target, value, signature, data, eta); return txHash; } function cancelTransaction( address target, uint256 value, string memory signature, bytes memory data, uint256 eta ) public { require(msg.sender == admin, 'NounsDAOExecutor::cancelTransaction: Call must come from admin.'); bytes32 txHash = keccak256(abi.encode(target, value, signature, data, eta)); queuedTransactions[txHash] = false; emit CancelTransaction(txHash, target, value, signature, data, eta); } function executeTransaction( address target, uint256 value, string memory signature, bytes memory data, uint256 eta ) public returns (bytes memory) { require(msg.sender == admin, 'NounsDAOExecutor::executeTransaction: Call must come from admin.'); bytes32 txHash = keccak256(abi.encode(target, value, signature, data, eta)); require(queuedTransactions[txHash], "NounsDAOExecutor::executeTransaction: Transaction hasn't been queued."); require( getBlockTimestamp() >= eta, "NounsDAOExecutor::executeTransaction: Transaction hasn't surpassed time lock." ); require( getBlockTimestamp() <= eta + GRACE_PERIOD, 'NounsDAOExecutor::executeTransaction: Transaction is stale.' ); queuedTransactions[txHash] = false; bytes memory callData; if (bytes(signature).length == 0) { callData = data; } else { callData = abi.encodePacked(bytes4(keccak256(bytes(signature))), data); } // solium-disable-next-line security/no-call-value (bool success, bytes memory returnData) = target.call{ value: value }(callData); require(success, 'NounsDAOExecutor::executeTransaction: Transaction execution reverted.'); emit ExecuteTransaction(txHash, target, value, signature, data, eta); return returnData; } function getBlockTimestamp() internal view returns (uint256) { // solium-disable-next-line security/no-block-members return block.timestamp; } receive() external payable {} fallback() external payable {} function sendETH(address payable recipient, uint256 ethToSend) external { require(msg.sender == admin, 'NounsDAOExecutor::sendETH: Call must come from admin.'); recipient.sendValue(ethToSend); emit ETHSent(recipient, ethToSend); } function sendERC20( address recipient, address erc20Token, uint256 tokensToSend ) external { require(msg.sender == admin, 'NounsDAOExecutor::sendERC20: Call must come from admin.'); IERC20(erc20Token).safeTransfer(recipient, tokensToSend); emit ERC20Sent(recipient, erc20Token, tokensToSend); } /** * @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 { require( msg.sender == address(this), 'NounsDAOExecutor::_authorizeUpgrade: Call must come from NounsDAOExecutor.' ); } }
// SPDX-License-Identifier: BSD-3-Clause /// @title The Nouns DAO proxy contract /********************************* * ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ * * ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ * * ░░░░░░█████████░░█████████░░░ * * ░░░░░░██░░░████░░██░░░████░░░ * * ░░██████░░░████████░░░████░░░ * * ░░██░░██░░░████░░██░░░████░░░ * * ░░██░░██░░░████░░██░░░████░░░ * * ░░░░░░█████████░░█████████░░░ * * ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ * * ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ * *********************************/ // LICENSE // NounsDAOProxy.sol is a modified version of Compound Lab's GovernorBravoDelegator.sol: // https://github.com/compound-finance/compound-protocol/blob/b9b14038612d846b83f8a009a82c38974ff2dcfe/contracts/Governance/GovernorBravoDelegator.sol // // GovernorBravoDelegator.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 // // // NounsDAOProxy.sol uses parts of Open Zeppelin's Proxy.sol: // https://github.com/OpenZeppelin/openzeppelin-contracts/blob/5c8746f56b4bed8cc9e0e044f5f69ab2f9428ce1/contracts/proxy/Proxy.sol // // Proxy.sol source code licensed under MIT License. // // MODIFICATIONS // The fallback() and receive() functions of Proxy.sol have been used to allow Solidity > 0.6.0 compatibility pragma solidity ^0.8.6; import './NounsDAOInterfaces.sol'; contract NounsDAOProxy is NounsDAOProxyStorage, NounsDAOEvents { constructor( address timelock_, address nouns_, address vetoer_, address admin_, address implementation_, uint256 votingPeriod_, uint256 votingDelay_, uint256 proposalThresholdBPS_, uint256 quorumVotesBPS_ ) { // Admin set to msg.sender for initialization admin = msg.sender; delegateTo( implementation_, abi.encodeWithSignature( 'initialize(address,address,address,uint256,uint256,uint256,uint256)', timelock_, nouns_, vetoer_, votingPeriod_, votingDelay_, proposalThresholdBPS_, quorumVotesBPS_ ) ); _setImplementation(implementation_); admin = admin_; } /** * @notice Called by the admin to update the implementation of the delegator * @param implementation_ The address of the new implementation for delegation */ function _setImplementation(address implementation_) public { require(msg.sender == admin, 'NounsDAOProxy::_setImplementation: admin only'); require(implementation_ != address(0), 'NounsDAOProxy::_setImplementation: invalid implementation address'); address oldImplementation = implementation; implementation = implementation_; emit NewImplementation(oldImplementation, implementation); } /** * @notice Internal method to delegate execution to another contract * @dev It returns to the external caller whatever the implementation returns or forwards reverts * @param callee The contract to delegatecall * @param data The raw data to delegatecall */ function delegateTo(address callee, bytes memory data) internal { (bool success, bytes memory returnData) = callee.delegatecall(data); assembly { if eq(success, 0) { revert(add(returnData, 0x20), returndatasize()) } } } /** * @dev Delegates execution to an implementation contract. * It returns to the external caller whatever the implementation returns * or forwards reverts. */ function _fallback() internal { // delegate all other functions to current implementation (bool success, ) = implementation.delegatecall(msg.data); assembly { let free_mem_ptr := mload(0x40) returndatacopy(free_mem_ptr, 0, returndatasize()) switch success case 0 { revert(free_mem_ptr, returndatasize()) } default { return(free_mem_ptr, returndatasize()) } } } /** * @dev Fallback function that delegates calls to the `implementation`. Will run if no other * function in the contract matches the call data. */ fallback() external payable { _fallback(); } /** * @dev Fallback function that delegates calls to `implementation`. Will run if call data * is empty. */ receive() external payable { _fallback(); } }
// SPDX-License-Identifier: BSD-3-Clause /// @title The Nouns DAO logic version 3 /********************************* * ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ * * ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ * * ░░░░░░█████████░░█████████░░░ * * ░░░░░░██░░░████░░██░░░████░░░ * * ░░██████░░░████████░░░████░░░ * * ░░██░░██░░░████░░██░░░████░░░ * * ░░██░░██░░░████░░██░░░████░░░ * * ░░░░░░█████████░░█████████░░░ * * ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ * * ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ * *********************************/ // LICENSE // NounsDAOLogicV2.sol is a modified version of Compound Lab's GovernorBravoDelegate.sol: // https://github.com/compound-finance/compound-protocol/blob/b9b14038612d846b83f8a009a82c38974ff2dcfe/contracts/Governance/GovernorBravoDelegate.sol // // GovernorBravoDelegate.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 // See NounsDAOLogicV1 for initial GovernorBravoDelegate modifications. // See NounsDAOLogicV2 for additional modifications // // NounsDAOLogicV3 adds: // - Contract has been broken down to use libraries because of contract size limitations // - Proposal editing: allowing proposers to update their proposal’s transactions and text description, // during the Updatable period only, which is the state upon proposal creation. Editing also works with signatures, // assuming the proposer is able to accumulate signatures from the same signers. // - Propose by signature: allowing Nouners and delegates to pool their voting power towards submitting a proposal, // by submitting their signature, instead of the current approach where sponsors must delegate their votes to help // a proposer achieve threshold. // - Objection-only Period: a conditional voting period that gets activated upon a last-minute proposal swing // from defeated to successful, affording against voters more reaction time. // Only against votes are possible during the objection period. // - Votes snapshot after voting delay: moving votes snapshot up, to provide Nouners with reaction time per proposal, // to get their votes ready (e.g. some might want to move their delegations around). // In NounsDAOLogicV2 the vote snapshot block is the proposal creation block. // - Nouns fork: any token holder can signal to fork (exit) in response to a governance proposal. // If a quorum of a configured threshold amount of tokens signals to exit, the fork will succeed. // This will deploy a new DAO and send part of the treasury to the new DAO. // // 2 new states have been added to the proposal state machine: Updatable, ObjectionPeriod // // Updated state machine: // Updatable -> Pending -> Active -> ObjectionPeriod (conditional) -> Succeeded -> Queued -> Executed // ┖> Defeated // pragma solidity ^0.8.19; import './NounsDAOInterfaces.sol'; import { NounsDAOV3Admin } from './NounsDAOV3Admin.sol'; import { NounsDAOV3DynamicQuorum } from './NounsDAOV3DynamicQuorum.sol'; import { NounsDAOV3Votes } from './NounsDAOV3Votes.sol'; import { NounsDAOV3Proposals } from './NounsDAOV3Proposals.sol'; import { NounsDAOV3Fork } from './fork/NounsDAOV3Fork.sol'; contract NounsDAOLogicV3 is NounsDAOStorageV3, NounsDAOEventsV3 { using NounsDAOV3Admin for StorageV3; using NounsDAOV3DynamicQuorum for StorageV3; using NounsDAOV3Votes for StorageV3; using NounsDAOV3Proposals for StorageV3; using NounsDAOV3Fork for StorageV3; /** * ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ * CONSTANTS * ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ */ /// @notice The minimum setable proposal threshold function MIN_PROPOSAL_THRESHOLD_BPS() public pure returns (uint256) { return NounsDAOV3Admin.MIN_PROPOSAL_THRESHOLD_BPS; } /// @notice The maximum setable proposal threshold function MAX_PROPOSAL_THRESHOLD_BPS() public pure returns (uint256) { return NounsDAOV3Admin.MAX_PROPOSAL_THRESHOLD_BPS; } /// @notice The minimum setable voting period in blocks function MIN_VOTING_PERIOD() public pure returns (uint256) { return NounsDAOV3Admin.MIN_VOTING_PERIOD_BLOCKS; } /// @notice The max setable voting period in blocks function MAX_VOTING_PERIOD() public pure returns (uint256) { return NounsDAOV3Admin.MAX_VOTING_PERIOD_BLOCKS; } /// @notice The min setable voting delay in blocks function MIN_VOTING_DELAY() public pure returns (uint256) { return NounsDAOV3Admin.MIN_VOTING_DELAY_BLOCKS; } /// @notice The max setable voting delay in blocks function MAX_VOTING_DELAY() public pure returns (uint256) { return NounsDAOV3Admin.MAX_VOTING_DELAY_BLOCKS; } /// @notice The maximum number of actions that can be included in a proposal function proposalMaxOperations() public pure returns (uint256) { return NounsDAOV3Proposals.PROPOSAL_MAX_OPERATIONS; } /** * ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ * ERRORS * ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ */ error AdminOnly(); error CanOnlyInitializeOnce(); error InvalidTimelockAddress(); error InvalidNounsAddress(); /** * ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ * INITIALIZER * ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ */ /** * @notice Used to initialize the contract during delegator contructor * @dev This will only be called for a newly deployed DAO, not as part of an upgrade from V2 to V3 * @param timelock_ The address of the NounsDAOExecutor * @param nouns_ The address of the NOUN tokens * @param forkEscrow_ The escrow contract used for creating forks * @param forkDAODeployer_ The contract used to deploy new forked DAOs * @param vetoer_ The address allowed to unilaterally veto proposals * @param daoParams_ Initial DAO parameters * @param dynamicQuorumParams_ The initial dynamic quorum parameters */ function initialize( address timelock_, address nouns_, address forkEscrow_, address forkDAODeployer_, address vetoer_, NounsDAOParams calldata daoParams_, DynamicQuorumParams calldata dynamicQuorumParams_ ) public virtual { if (address(ds.timelock) != address(0)) revert CanOnlyInitializeOnce(); if (msg.sender != ds.admin) revert AdminOnly(); if (timelock_ == address(0)) revert InvalidTimelockAddress(); if (nouns_ == address(0)) revert InvalidNounsAddress(); ds._setVotingPeriod(daoParams_.votingPeriod); ds._setVotingDelay(daoParams_.votingDelay); ds._setProposalThresholdBPS(daoParams_.proposalThresholdBPS); ds.timelock = INounsDAOExecutorV2(timelock_); ds.nouns = NounsTokenLike(nouns_); ds.forkEscrow = INounsDAOForkEscrow(forkEscrow_); ds.forkDAODeployer = IForkDAODeployer(forkDAODeployer_); ds.vetoer = vetoer_; _setDynamicQuorumParams( dynamicQuorumParams_.minQuorumVotesBPS, dynamicQuorumParams_.maxQuorumVotesBPS, dynamicQuorumParams_.quorumCoefficient ); ds._setLastMinuteWindowInBlocks(daoParams_.lastMinuteWindowInBlocks); ds._setObjectionPeriodDurationInBlocks(daoParams_.objectionPeriodDurationInBlocks); ds._setProposalUpdatablePeriodInBlocks(daoParams_.proposalUpdatablePeriodInBlocks); } /** * ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ * PROPOSALS * ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ */ /** * @notice Function used to propose a new proposal. Sender must have delegates above the proposal threshold * @param targets Target addresses for proposal calls * @param values Eth values for proposal calls * @param signatures Function signatures for proposal calls * @param calldatas Calldatas for proposal calls * @param description String description of the proposal * @return uint256 Proposal id of new proposal */ function propose( address[] memory targets, uint256[] memory values, string[] memory signatures, bytes[] memory calldatas, string memory description ) public returns (uint256) { return ds.propose(NounsDAOV3Proposals.ProposalTxs(targets, values, signatures, calldatas), description); } /** * @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 targets Target addresses for proposal calls * @param values Eth values for proposal calls * @param signatures Function signatures for proposal calls * @param calldatas Calldatas for proposal calls * @param description String description of the proposal * @return uint256 Proposal id of new proposal */ function proposeOnTimelockV1( address[] memory targets, uint256[] memory values, string[] memory signatures, bytes[] memory calldatas, string memory description ) public returns (uint256) { return ds.proposeOnTimelockV1( NounsDAOV3Proposals.ProposalTxs(targets, values, signatures, calldatas), description ); } /** * @notice Function used to propose a new proposal. Sender and signers must have delegates above the proposal threshold * Signers are regarded as co-proposers, and therefore have the ability to cancel the proposal at any time. * @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 targets Target addresses for proposal calls * @param values Eth values for proposal calls * @param signatures Function signatures for proposal calls * @param calldatas Calldatas for proposal calls * @param description String description of the proposal * @return uint256 Proposal id of new proposal */ function proposeBySigs( ProposerSignature[] memory proposerSignatures, address[] memory targets, uint256[] memory values, string[] memory signatures, bytes[] memory calldatas, string memory description ) external returns (uint256) { return ds.proposeBySigs( proposerSignatures, NounsDAOV3Proposals.ProposalTxs(targets, values, signatures, calldatas), description ); } /** * @notice Invalidates a signature that may be used for signing a new 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. * Cancelling a signature for an existing proposal will have no effect. Signers have the ability to cancel * a proposal they signed if necessary. * @param sig The signature to cancel */ function cancelSig(bytes calldata sig) external { ds.cancelSig(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( uint256 proposalId, address[] memory targets, uint256[] memory values, string[] memory signatures, bytes[] memory calldatas, string memory description, string memory updateMessage ) external { ds.updateProposal(proposalId, targets, values, signatures, calldatas, description, updateMessage); } /** * @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( uint256 proposalId, string calldata description, string calldata updateMessage ) external { ds.updateProposalDescription(proposalId, 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( uint256 proposalId, address[] memory targets, uint256[] memory values, string[] memory signatures, bytes[] memory calldatas, string memory updateMessage ) external { ds.updateProposalTransactions(proposalId, targets, values, signatures, calldatas, 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 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 updateProposalBySigs( uint256 proposalId, ProposerSignature[] memory proposerSignatures, address[] memory targets, uint256[] memory values, string[] memory signatures, bytes[] memory calldatas, string memory description, string memory updateMessage ) external { ds.updateProposalBySigs( proposalId, proposerSignatures, NounsDAOV3Proposals.ProposalTxs(targets, values, signatures, calldatas), description, updateMessage ); } /** * @notice Queues a proposal of state succeeded * @param proposalId The id of the proposal to queue */ function queue(uint256 proposalId) external { ds.queue(proposalId); } /** * @notice Executes a queued proposal if eta has passed * @param proposalId The id of the proposal to execute */ function execute(uint256 proposalId) external { ds.execute(proposalId); } /** * @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(uint256 proposalId) external { ds.executeOnTimelockV1(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(uint256 proposalId) external { ds.cancel(proposalId); } /** * @notice Gets the state of a proposal * @param proposalId The id of the proposal * @return Proposal state */ function state(uint256 proposalId) public view returns (ProposalState) { return ds.state(proposalId); } /** * @notice Gets actions of a proposal * @param proposalId the id of the proposal * @return targets * @return values * @return signatures * @return calldatas */ function getActions(uint256 proposalId) external view returns ( address[] memory targets, uint256[] memory values, string[] memory signatures, bytes[] memory calldatas ) { return ds.getActions(proposalId); } /** * @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(uint256 proposalId, address voter) external view returns (Receipt memory) { return ds.getReceipt(proposalId, 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, backwards compatible with V1 and V2 */ function proposals(uint256 proposalId) external view returns (NounsDAOStorageV2.ProposalCondensed memory) { return ds.proposals(proposalId); } /** * @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, not backwards compatible as it contains additional values * like `objectionPeriodEndBlock` and `signers` */ function proposalsV3(uint256 proposalId) external view returns (ProposalCondensed memory) { return ds.proposalsV3(proposalId); } /** * @notice Current proposal threshold using Noun Total Supply * Differs from `GovernerBravo` which uses fixed amount */ function proposalThreshold() public view returns (uint256) { return ds.proposalThreshold(ds.adjustedTotalSupply()); } /** * ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ * DAO FORK * ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ */ /** * @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( uint256[] calldata tokenIds, uint256[] calldata proposalIds, string calldata reason ) external { ds.escrowToFork(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(uint256[] calldata tokenIds) external { ds.withdrawFromForkEscrow(tokenIds); } /** * @notice Execute the fork. Only possible if the fork threshold has been met. * This will deploy a new DAO and send part of the treasury to the new DAO's treasury. * This will also close the active escrow and all nouns in the escrow 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() external returns (address forkTreasury, address forkToken) { return ds.executeFork(); } /** * @notice Joins a fork while a fork is active * @param tokenIds the tokenIds to send to the DAO in exchange for joining the fork * @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 joinFork( uint256[] calldata tokenIds, uint256[] calldata proposalIds, string calldata reason ) external { ds.joinFork(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(uint256[] calldata tokenIds) external { ds.withdrawDAONounsFromEscrowToTreasury(tokenIds); } /** * @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(uint256[] calldata tokenIds, address to) external { ds.withdrawDAONounsFromEscrowIncreasingTotalSupply(tokenIds, to); } /** * @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() external view returns (uint256) { return ds.adjustedTotalSupply(); } /** * @notice returns the required number of tokens to escrow to trigger a fork */ function forkThreshold() external view returns (uint256) { return ds.forkThreshold(); } /** * @notice Returns the number of tokens currently in escrow, contributing to the fork threshold */ function numTokensInForkEscrow() external view returns (uint256) { return ds.numTokensInForkEscrow(); } /** * ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ * VOTES * ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ */ /** * @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(uint256 proposalId) external { ds.veto(proposalId); } /** * @notice Cast a vote for a proposal * @param proposalId The id of the proposal to vote on * @param support The support value for the vote. 0=against, 1=for, 2=abstain */ function castVote(uint256 proposalId, uint8 support) external { ds.castVote(proposalId, support); } /** * @notice Cast a vote for a proposal, asking the DAO to refund gas costs. * Users with > 0 votes receive refunds. Refunds are partial when using a gas priority fee higher than the DAO's cap. * Refunds are partial when the DAO's balance is insufficient. * No refund is sent when the DAO's balance is empty. No refund is sent to users with no votes. * Voting takes place regardless of refund success. * @param proposalId The id of the proposal to vote on * @param support The support value for the vote. 0=against, 1=for, 2=abstain * @dev Reentrancy is defended against in `castVoteInternal` at the `receipt.hasVoted == false` require statement. */ function castRefundableVote(uint256 proposalId, uint8 support) external { ds.castRefundableVote(proposalId, support); } /** * @notice Cast a vote for a proposal, asking the DAO to refund gas costs. * Users with > 0 votes receive refunds. Refunds are partial when using a gas priority fee higher than the DAO's cap. * Refunds are partial when the DAO's balance is insufficient. * No refund is sent when the DAO's balance is empty. No refund is sent to users with no votes. * Voting takes place regardless of refund success. * @param proposalId The id of the proposal to vote on * @param support The support value for the vote. 0=against, 1=for, 2=abstain * @param reason The reason given for the vote by the voter * @dev Reentrancy is defended against in `castVoteInternal` at the `receipt.hasVoted == false` require statement. */ function castRefundableVoteWithReason( uint256 proposalId, uint8 support, string calldata reason ) external { ds.castRefundableVoteWithReason(proposalId, support, reason); } /** * @notice Cast a vote for a proposal with a reason * @param proposalId The id of the proposal to vote on * @param support The support value for the vote. 0=against, 1=for, 2=abstain * @param reason The reason given for the vote by the voter */ function castVoteWithReason( uint256 proposalId, uint8 support, string calldata reason ) external { ds.castVoteWithReason(proposalId, support, reason); } /** * @notice Cast a vote for a proposal by signature * @dev External function that accepts EIP-712 signatures for voting on proposals. */ function castVoteBySig( uint256 proposalId, uint8 support, uint8 v, bytes32 r, bytes32 s ) external { ds.castVoteBySig(proposalId, support, v, r, s); } /** * ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ * ADMIN * ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ */ /** * @notice Admin function for setting the voting delay. Best to set voting delay to at least a few days, to give * voters time to make sense of proposals, e.g. 21,600 blocks which should be at least 3 days. * @param newVotingDelay new voting delay, in blocks */ function _setVotingDelay(uint256 newVotingDelay) external { ds._setVotingDelay(newVotingDelay); } /** * @notice Admin function for setting the voting period * @param newVotingPeriod new voting period, in blocks */ function _setVotingPeriod(uint256 newVotingPeriod) external { ds._setVotingPeriod(newVotingPeriod); } /** * @notice Admin function for setting the proposal threshold basis points * @dev newProposalThresholdBPS must be in [`MIN_PROPOSAL_THRESHOLD_BPS`,`MAX_PROPOSAL_THRESHOLD_BPS`] * @param newProposalThresholdBPS new proposal threshold */ function _setProposalThresholdBPS(uint256 newProposalThresholdBPS) external { ds._setProposalThresholdBPS(newProposalThresholdBPS); } /** * @notice Admin function for setting the objection period duration * @param newObjectionPeriodDurationInBlocks new objection period duration, in blocks */ function _setObjectionPeriodDurationInBlocks(uint32 newObjectionPeriodDurationInBlocks) external { ds._setObjectionPeriodDurationInBlocks(newObjectionPeriodDurationInBlocks); } /** * @notice Admin function for setting the objection period last minute window * @param newLastMinuteWindowInBlocks new objection period last minute window, in blocks */ function _setLastMinuteWindowInBlocks(uint32 newLastMinuteWindowInBlocks) external { ds._setLastMinuteWindowInBlocks(newLastMinuteWindowInBlocks); } /** * @notice Admin function for setting the proposal updatable period * @param newProposalUpdatablePeriodInBlocks the new proposal updatable period, in blocks */ function _setProposalUpdatablePeriodInBlocks(uint32 newProposalUpdatablePeriodInBlocks) external { ds._setProposalUpdatablePeriodInBlocks(newProposalUpdatablePeriodInBlocks); } /** * @notice Begins transfer of admin rights. The newPendingAdmin must call `_acceptAdmin` to finalize the transfer. * @dev Admin function to begin change of admin. The newPendingAdmin must call `_acceptAdmin` to finalize the transfer. * @param newPendingAdmin New pending admin. */ function _setPendingAdmin(address newPendingAdmin) external { ds._setPendingAdmin(newPendingAdmin); } /** * @notice Accepts transfer of admin rights. msg.sender must be pendingAdmin * @dev Admin function for pending admin to accept role and update admin */ function _acceptAdmin() external { ds._acceptAdmin(); } /** * @notice Begins transition of vetoer. The newPendingVetoer must call _acceptVetoer to finalize the transfer. * @param newPendingVetoer New Pending Vetoer */ function _setPendingVetoer(address newPendingVetoer) public { ds._setPendingVetoer(newPendingVetoer); } /** * @notice Called by the pendingVetoer to accept role and update vetoer */ function _acceptVetoer() external { ds._acceptVetoer(); } /** * @notice Burns veto priviledges * @dev Vetoer function destroying veto power forever */ function _burnVetoPower() public { ds._burnVetoPower(); } /** * @notice Admin function for setting the minimum quorum votes bps * @param newMinQuorumVotesBPS minimum quorum votes bps * Must be between `MIN_QUORUM_VOTES_BPS_LOWER_BOUND` and `MIN_QUORUM_VOTES_BPS_UPPER_BOUND` * Must be lower than or equal to maxQuorumVotesBPS */ function _setMinQuorumVotesBPS(uint16 newMinQuorumVotesBPS) external { ds._setMinQuorumVotesBPS(newMinQuorumVotesBPS); } /** * @notice Admin function for setting the maximum quorum votes bps * @param newMaxQuorumVotesBPS maximum quorum votes bps * Must be lower than `MAX_QUORUM_VOTES_BPS_UPPER_BOUND` * Must be higher than or equal to minQuorumVotesBPS */ function _setMaxQuorumVotesBPS(uint16 newMaxQuorumVotesBPS) external { ds._setMaxQuorumVotesBPS(newMaxQuorumVotesBPS); } /** * @notice Admin function for setting the dynamic quorum coefficient * @param newQuorumCoefficient the new coefficient, as a fixed point integer with 6 decimals */ function _setQuorumCoefficient(uint32 newQuorumCoefficient) external { ds._setQuorumCoefficient(newQuorumCoefficient); } /** * @notice Admin function for setting all the dynamic quorum parameters * @param newMinQuorumVotesBPS minimum quorum votes bps * Must be between `MIN_QUORUM_VOTES_BPS_LOWER_BOUND` and `MIN_QUORUM_VOTES_BPS_UPPER_BOUND` * Must be lower than or equal to maxQuorumVotesBPS * @param newMaxQuorumVotesBPS maximum quorum votes bps * Must be lower than `MAX_QUORUM_VOTES_BPS_UPPER_BOUND` * Must be higher than or equal to minQuorumVotesBPS * @param newQuorumCoefficient the new coefficient, as a fixed point integer with 6 decimals */ function _setDynamicQuorumParams( uint16 newMinQuorumVotesBPS, uint16 newMaxQuorumVotesBPS, uint32 newQuorumCoefficient ) public { ds._setDynamicQuorumParams(newMinQuorumVotesBPS, newMaxQuorumVotesBPS, newQuorumCoefficient); } /** * @notice Withdraws all the ETH in the contract. This is callable only by the admin (timelock). */ function _withdraw() external returns (uint256, bool) { return ds._withdraw(); } /** * @notice Admin function for setting the fork period * @param newForkPeriod the new fork proposal period, in seconds */ function _setForkPeriod(uint256 newForkPeriod) external { ds._setForkPeriod(newForkPeriod); } /** * @notice Admin function for setting the fork threshold * @param newForkThresholdBPS the new fork proposal threshold, in basis points */ function _setForkThresholdBPS(uint256 newForkThresholdBPS) external { ds._setForkThresholdBPS(newForkThresholdBPS); } /** * @notice Admin function for setting the proposal id at which vote snapshots start using the voting start block * instead of the proposal creation block. * Sets it to the next proposal id. */ function _setVoteSnapshotBlockSwitchProposalId() external { ds._setVoteSnapshotBlockSwitchProposalId(); } /** * @notice Admin function for setting the fork DAO deployer contract */ function _setForkDAODeployer(address newForkDAODeployer) external { ds._setForkDAODeployer(newForkDAODeployer); } /** * @notice Admin function for setting the ERC20 tokens that are used when splitting funds to a fork */ function _setErc20TokensToIncludeInFork(address[] calldata erc20tokens) external { ds._setErc20TokensToIncludeInFork(erc20tokens); } /** * @notice Admin function for setting the fork escrow contract */ function _setForkEscrow(address newForkEscrow) external { ds._setForkEscrow(newForkEscrow); } /** * @notice Admin function for setting the fork related parameters * @param forkEscrow_ the fork escrow contract * @param forkDAODeployer_ the fork dao deployer contract * @param erc20TokensToIncludeInFork_ the ERC20 tokens used when splitting funds to a fork * @param forkPeriod_ the period during which it's possible to join a fork after exeuction * @param forkThresholdBPS_ the threshold required of escrowed nouns in order to execute a fork */ function _setForkParams( address forkEscrow_, address forkDAODeployer_, address[] calldata erc20TokensToIncludeInFork_, uint256 forkPeriod_, uint256 forkThresholdBPS_ ) external { ds._setForkEscrow(forkEscrow_); ds._setForkDAODeployer(forkDAODeployer_); ds._setErc20TokensToIncludeInFork(erc20TokensToIncludeInFork_); ds._setForkPeriod(forkPeriod_); ds._setForkThresholdBPS(forkThresholdBPS_); } /** * @notice Admin function for setting the timelocks and admin * @param newTimelock the new timelock contract * @param newTimelockV1 the new timelockV1 contract * @param newAdmin the new admin address */ function _setTimelocksAndAdmin( address newTimelock, address newTimelockV1, address newAdmin ) external { ds._setTimelocksAndAdmin(newTimelock, newTimelockV1, newAdmin); } /** * ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ * DYNAMIC QUORUM * ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ */ /** * @notice Quorum votes required for a specific proposal to succeed * Differs from `GovernerBravo` which uses fixed amount */ function quorumVotes(uint256 proposalId) public view returns (uint256) { return ds.quorumVotes(proposalId); } /** * @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 adjustedTotalSupply_ The adjusted 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 adjustedTotalSupply_, DynamicQuorumParams memory params ) public pure returns (uint256) { return NounsDAOV3DynamicQuorum.dynamicQuorumVotes(againstVotes, adjustedTotalSupply_, params); } /** * @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(uint256 blockNumber_) public view returns (DynamicQuorumParams memory) { return ds.getDynamicQuorumParamsAt(blockNumber_); } /** * @notice Current min quorum votes using Nouns adjusted total supply */ function minQuorumVotes() public view returns (uint256) { return ds.minQuorumVotes(ds.adjustedTotalSupply()); } /** * @notice Current max quorum votes using Nouns adjusted total supply */ function maxQuorumVotes() public view returns (uint256) { return ds.maxQuorumVotes(ds.adjustedTotalSupply()); } /** * @notice Get all quorum params checkpoints */ function quorumParamsCheckpoints() public view returns (DynamicQuorumParamsCheckpoint[] memory) { return ds.quorumParamsCheckpoints; } /** * @notice Get a quorum params checkpoint by its index */ function quorumParamsCheckpoints(uint256 index) public view returns (DynamicQuorumParamsCheckpoint memory) { return ds.quorumParamsCheckpoints[index]; } /** * ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ * STATE VARIABLE GETTERS * ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ */ function vetoer() public view returns (address) { return ds.vetoer; } function pendingVetoer() public view returns (address) { return ds.pendingVetoer; } function votingDelay() public view returns (uint256) { return ds.votingDelay; } function votingPeriod() public view returns (uint256) { return ds.votingPeriod; } function proposalThresholdBPS() public view returns (uint256) { return ds.proposalThresholdBPS; } function quorumVotesBPS() public view returns (uint256) { return ds.quorumVotesBPS; } function proposalCount() public view returns (uint256) { return ds.proposalCount; } function timelock() public view returns (INounsDAOExecutor) { return ds.timelock; } function nouns() public view returns (NounsTokenLike) { return ds.nouns; } function latestProposalIds(address account) public view returns (uint256) { return ds.latestProposalIds[account]; } function lastMinuteWindowInBlocks() public view returns (uint256) { return ds.lastMinuteWindowInBlocks; } function objectionPeriodDurationInBlocks() public view returns (uint256) { return ds.objectionPeriodDurationInBlocks; } function erc20TokensToIncludeInFork() public view returns (address[] memory) { return ds.erc20TokensToIncludeInFork; } function forkEscrow() public view returns (INounsDAOForkEscrow) { return ds.forkEscrow; } function forkDAODeployer() public view returns (IForkDAODeployer) { return ds.forkDAODeployer; } function forkEndTimestamp() public view returns (uint256) { return ds.forkEndTimestamp; } function forkPeriod() public view returns (uint256) { return ds.forkPeriod; } function forkThresholdBPS() public view returns (uint256) { return ds.forkThresholdBPS; } function proposalUpdatablePeriodInBlocks() public view returns (uint256) { return ds.proposalUpdatablePeriodInBlocks; } function timelockV1() public view returns (address) { return address(ds.timelockV1); } function voteSnapshotBlockSwitchProposalId() public view returns (uint256) { return ds.voteSnapshotBlockSwitchProposalId; } receive() external payable {} }
// SPDX-License-Identifier: BSD-3-Clause /// @title The Nouns DAO logic version 1 /********************************* * ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ * * ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ * * ░░░░░░█████████░░█████████░░░ * * ░░░░░░██░░░████░░██░░░████░░░ * * ░░██████░░░████████░░░████░░░ * * ░░██░░██░░░████░░██░░░████░░░ * * ░░██░░██░░░████░░██░░░████░░░ * * ░░░░░░█████████░░█████████░░░ * * ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ * * ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ * *********************************/ // LICENSE // NounsDAOLogicV1Fork.sol is a modified version of NounsDAOLogicV1.sol. // NounsDAOLogicV1.sol is a modified version of Compound Lab's GovernorBravoDelegate.sol: // https://github.com/compound-finance/compound-protocol/blob/b9b14038612d846b83f8a009a82c38974ff2dcfe/contracts/Governance/GovernorBravoDelegate.sol // // GovernorBravoDelegate.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 // NounsDAOLogicV1Fork adds: // - `quit(tokenIds)`, a function that allows token holders to quit the DAO, taking their pro rata funds, // and sending their tokens to the DAO treasury. // // - `adjustedTotalSupply`, the total supply calculation used in DAO functions like quorum and proposal threshold, in // which the DAO exludes tokens held by the treasury, such that tokens used to quit the DAO are not counted. // // - A function for the DAO to set which ERC20s are transferred pro rata in the `quit` function. // // - A new proposals getter function, since adding new fields to Proposal results in the default getter hitting a // `Stack too deep` error. // // - A new Proposal field: `creationBlock`, used to resolve the `votingDelay` bug, in which editing `votingDelay` would // change the votes snapshot block for proposals in-progress. // // NounsDAOLogicV1Fork modifies: // - The proxy pattern from Compound's old Transparent-like proxy, to OpenZeppelin's recommended UUPS pattern. // // - `propose` // - uses `adjustedTotalSupply` // - includes a new 'delayed governance' feature which gives forkers from the original DAO time to claim their tokens // with this new DAO; proposals are not allowed until all tokens are claimed, or until the delay expiration // timestamp is reached. // // - `cancel` bugfix, allowing proposals to be canceled by anyone if the proposer's vote balance is equal to proposal // threshold. // // - Removes the vetoer role and logic related to it. The quit function provides minority protection instead of the // vetoer, and fork DAOs can upgrade their governor to include the vetoer feature if it's needed. // // - Modified MIN_VOTING_PERIOD, MAX_VOTING_PERIOD to correct block numbers assuming 12 second blocks // - Modified MAX_VOTING_DELAY to be 2 weeks // // NounsDAOLogicV1 adds: // - Proposal Threshold basis points instead of fixed number // due to the Noun token's increasing supply // // - Quorum Votes basis points instead of fixed number // due to the Noun token's increasing supply // // - Per proposal storing of fixed `proposalThreshold` // and `quorumVotes` calculated using the Noun token's total supply // at the block the proposal was created and the basis point parameters // // - `ProposalCreatedWithRequirements` event that emits `ProposalCreated` parameters with // the addition of `proposalThreshold` and `quorumVotes` // // - Votes are counted from the block a proposal is created instead of // the proposal's voting start block to align with the parameters // stored with the proposal // // - Veto ability which allows `vetoer` to halt any proposal at any stage unless // the proposal is executed. // The `veto(uint proposalId)` logic is a modified version of `cancel(uint proposalId)` // A `vetoed` flag was added to the `Proposal` struct to support this. // // NounsDAOLogicV1 removes: // - `initialProposalId` and `_initiate()` due to this being the // first instance of the governance contract unlike // GovernorBravo which upgrades GovernorAlpha // // - Value passed along using `timelock.executeTransaction{value: proposal.value}` // in `execute(uint proposalId)`. This contract should not hold funds and does not // implement `receive()` or `fallback()` functions. // pragma solidity ^0.8.19; import { UUPSUpgradeable } from '@openzeppelin/contracts/proxy/utils/UUPSUpgradeable.sol'; import { NounsDAOEventsFork } from './NounsDAOEventsFork.sol'; import { NounsDAOStorageV1Fork } from './NounsDAOStorageV1Fork.sol'; import { NounsDAOExecutorV2 } from '../../../NounsDAOExecutorV2.sol'; import { INounsTokenForkLike } from './INounsTokenForkLike.sol'; import { IERC20 } from '@openzeppelin/contracts/token/ERC20/IERC20.sol'; import { ReentrancyGuardUpgradeable } from '@openzeppelin/contracts-upgradeable/security/ReentrancyGuardUpgradeable.sol'; contract NounsDAOLogicV1Fork is UUPSUpgradeable, ReentrancyGuardUpgradeable, NounsDAOStorageV1Fork, NounsDAOEventsFork { error AdminOnly(); error WaitingForTokensToClaimOrExpiration(); error TokensMustBeASubsetOfWhitelistedTokens(); error GovernanceBlockedDuringForkingPeriod(); error DuplicateTokenAddress(); event ERC20TokensToIncludeInQuitSet(address[] oldErc20Tokens, address[] newErc20tokens); event Quit(address indexed msgSender, uint256[] tokenIds); /// @notice The name of this contract string public constant name = 'Nouns DAO'; /// @notice The minimum setable proposal threshold uint256 public constant MIN_PROPOSAL_THRESHOLD_BPS = 1; // 1 basis point or 0.01% /// @notice The maximum setable proposal threshold uint256 public constant MAX_PROPOSAL_THRESHOLD_BPS = 1_000; // 1,000 basis points or 10% /// @notice The minimum setable voting period uint256 public constant MIN_VOTING_PERIOD = 7_200; // 24 hours /// @notice The max setable voting period uint256 public constant MAX_VOTING_PERIOD = 100_800; // 2 weeks /// @notice The min setable voting delay uint256 public constant MIN_VOTING_DELAY = 1; /// @notice The max setable voting delay uint256 public constant MAX_VOTING_DELAY = 100_800; // 2 weeks /// @notice The minimum setable quorum votes basis points uint256 public constant MIN_QUORUM_VOTES_BPS = 200; // 200 basis points or 2% /// @notice The maximum setable quorum votes basis points uint256 public constant MAX_QUORUM_VOTES_BPS = 2_000; // 2,000 basis points or 20% /// @notice The maximum number of actions that can be included in a proposal uint256 public constant proposalMaxOperations = 10; // 10 actions /// @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 ballot struct used by the contract bytes32 public constant BALLOT_TYPEHASH = keccak256('Ballot(uint256 proposalId,uint8 support)'); constructor() initializer {} /** * @notice Used to initialize the contract during delegator contructor * @dev Not asserting that param values are within the hard-coded bounds in order to make it easier to run * manual tests; seems a safe decision since we assume fork DAOs are initialized by `ForkDAODeployer` * @param timelock_ The address of the NounsDAOExecutor * @param nouns_ The address of the NOUN tokens * @param votingPeriod_ The initial voting period * @param votingDelay_ The initial voting delay * @param proposalThresholdBPS_ The initial proposal threshold in basis points * @param quorumVotesBPS_ The initial quorum votes threshold in basis points * @param erc20TokensToIncludeInQuit_ The initial list of ERC20 tokens to include when quitting * @param delayedGovernanceExpirationTimestamp_ The delayed governance expiration timestamp */ function initialize( address timelock_, address nouns_, uint256 votingPeriod_, uint256 votingDelay_, uint256 proposalThresholdBPS_, uint256 quorumVotesBPS_, address[] memory erc20TokensToIncludeInQuit_, uint256 delayedGovernanceExpirationTimestamp_ ) public virtual { __ReentrancyGuard_init_unchained(); require(address(timelock) == address(0), 'NounsDAO::initialize: can only initialize once'); require(timelock_ != address(0), 'NounsDAO::initialize: invalid timelock address'); require(nouns_ != address(0), 'NounsDAO::initialize: invalid nouns address'); emit VotingPeriodSet(votingPeriod, votingPeriod_); emit VotingDelaySet(votingDelay, votingDelay_); emit ProposalThresholdBPSSet(proposalThresholdBPS, proposalThresholdBPS_); emit QuorumVotesBPSSet(quorumVotesBPS, quorumVotesBPS_); admin = timelock_; timelock = NounsDAOExecutorV2(payable(timelock_)); nouns = INounsTokenForkLike(nouns_); votingPeriod = votingPeriod_; votingDelay = votingDelay_; proposalThresholdBPS = proposalThresholdBPS_; quorumVotesBPS = quorumVotesBPS_; erc20TokensToIncludeInQuit = erc20TokensToIncludeInQuit_; delayedGovernanceExpirationTimestamp = delayedGovernanceExpirationTimestamp_; } /** * @notice A function that allows token holders to quit the DAO, taking their pro rata funds, * and sending their tokens to the DAO treasury. * Will revert as long as not all tokens were claimed, and as long as the delayed governance has not expired. * @param tokenIds The token ids to quit with */ function quit(uint256[] calldata tokenIds) external nonReentrant { quitInternal(tokenIds, erc20TokensToIncludeInQuit); } function quit(uint256[] calldata tokenIds, address[] calldata erc20TokensToInclude) external nonReentrant { checkForDuplicates(erc20TokensToInclude); // check that erc20TokensToInclude is a subset of `erc20TokensToIncludeInQuit` address[] memory erc20TokensToIncludeInQuit_ = erc20TokensToIncludeInQuit; for (uint256 i = 0; i < erc20TokensToInclude.length; i++) { if (!isAddressIn(erc20TokensToInclude[i], erc20TokensToIncludeInQuit_)) { revert TokensMustBeASubsetOfWhitelistedTokens(); } } quitInternal(tokenIds, erc20TokensToInclude); } function quitInternal(uint256[] calldata tokenIds, address[] memory erc20TokensToInclude) internal { checkGovernanceActive(); uint256 totalSupply = adjustedTotalSupply(); for (uint256 i = 0; i < tokenIds.length; i++) { nouns.transferFrom(msg.sender, address(timelock), tokenIds[i]); } uint256[] memory balancesToSend = new uint256[](erc20TokensToInclude.length); // Capture balances to send before actually sending them, to avoid the risk of external calls changing balances. uint256 ethToSend = (address(timelock).balance * tokenIds.length) / totalSupply; for (uint256 i = 0; i < erc20TokensToInclude.length; i++) { IERC20 erc20token = IERC20(erc20TokensToInclude[i]); balancesToSend[i] = (erc20token.balanceOf(address(timelock)) * tokenIds.length) / totalSupply; } // Send ETH and ERC20 tokens timelock.sendETH(payable(msg.sender), ethToSend); for (uint256 i = 0; i < erc20TokensToInclude.length; i++) { if (balancesToSend[i] > 0) { timelock.sendERC20(msg.sender, erc20TokensToInclude[i], balancesToSend[i]); } } emit Quit(msg.sender, tokenIds); } function isAddressIn(address a, address[] memory addresses) internal pure returns (bool) { for (uint256 i = 0; i < addresses.length; i++) { if (addresses[i] == a) return true; } return false; } struct ProposalTemp { uint256 totalSupply; uint256 proposalThreshold; uint256 latestProposalId; uint256 startBlock; uint256 endBlock; } /** * @notice Function used to propose a new proposal. Sender must have delegates above the proposal threshold * Will revert as long as not all tokens were claimed, and as long as the delayed governance has not expired. * @param targets Target addresses for proposal calls * @param values Eth values for proposal calls * @param signatures Function signatures for proposal calls * @param calldatas Calldatas for proposal calls * @param description String description of the proposal * @return Proposal id of new proposal */ function propose( address[] memory targets, uint256[] memory values, string[] memory signatures, bytes[] memory calldatas, string memory description ) public returns (uint256) { checkGovernanceActive(); ProposalTemp memory temp; temp.totalSupply = adjustedTotalSupply(); temp.proposalThreshold = bps2Uint(proposalThresholdBPS, temp.totalSupply); require( nouns.getPriorVotes(msg.sender, block.number - 1) > temp.proposalThreshold, 'NounsDAO::propose: proposer votes below proposal threshold' ); require( targets.length == values.length && targets.length == signatures.length && targets.length == calldatas.length, 'NounsDAO::propose: proposal function information arity mismatch' ); require(targets.length != 0, 'NounsDAO::propose: must provide actions'); require(targets.length <= proposalMaxOperations, 'NounsDAO::propose: too many actions'); temp.latestProposalId = latestProposalIds[msg.sender]; if (temp.latestProposalId != 0) { ProposalState proposersLatestProposalState = state(temp.latestProposalId); require( proposersLatestProposalState != ProposalState.Active, 'NounsDAO::propose: one live proposal per proposer, found an already active proposal' ); require( proposersLatestProposalState != ProposalState.Pending, 'NounsDAO::propose: one live proposal per proposer, found an already pending proposal' ); } temp.startBlock = block.number + votingDelay; temp.endBlock = temp.startBlock + votingPeriod; proposalCount++; Proposal storage newProposal = _proposals[proposalCount]; newProposal.id = proposalCount; newProposal.proposer = msg.sender; newProposal.proposalThreshold = temp.proposalThreshold; newProposal.quorumVotes = bps2Uint(quorumVotesBPS, temp.totalSupply); newProposal.eta = 0; newProposal.targets = targets; newProposal.values = values; newProposal.signatures = signatures; newProposal.calldatas = calldatas; newProposal.startBlock = temp.startBlock; newProposal.endBlock = temp.endBlock; newProposal.forVotes = 0; newProposal.againstVotes = 0; newProposal.abstainVotes = 0; newProposal.canceled = false; newProposal.executed = false; newProposal.creationBlock = block.number; latestProposalIds[newProposal.proposer] = newProposal.id; /// @notice Maintains backwards compatibility with GovernorBravo events emit ProposalCreated( newProposal.id, msg.sender, targets, values, signatures, calldatas, newProposal.startBlock, newProposal.endBlock, description ); /// @notice Updated event with `proposalThreshold` and `quorumVotes` emit ProposalCreatedWithRequirements( newProposal.id, msg.sender, targets, values, signatures, calldatas, newProposal.startBlock, newProposal.endBlock, newProposal.proposalThreshold, newProposal.quorumVotes, description ); return newProposal.id; } /** * @notice Internal function that reverts if the governance is not active yet. Governance becomes active as soon as * the forking period ended and one of these conditions is met: * 1. All tokens are claimed * 2. The delayed governance expiration timestamp is reached */ function checkGovernanceActive() internal view { if (block.timestamp < nouns.forkingPeriodEndTimestamp()) { revert GovernanceBlockedDuringForkingPeriod(); } if (block.timestamp < delayedGovernanceExpirationTimestamp && nouns.remainingTokensToClaim() > 0) { revert WaitingForTokensToClaimOrExpiration(); } } /** * @notice Queues a proposal of state succeeded * @param proposalId The id of the proposal to queue */ function queue(uint256 proposalId) external { require( state(proposalId) == ProposalState.Succeeded, 'NounsDAO::queue: proposal can only be queued if it is succeeded' ); Proposal storage proposal = _proposals[proposalId]; uint256 eta = block.timestamp + timelock.delay(); for (uint256 i = 0; i < proposal.targets.length; i++) { queueOrRevertInternal( proposal.targets[i], proposal.values[i], proposal.signatures[i], proposal.calldatas[i], eta ); } proposal.eta = eta; emit ProposalQueued(proposalId, eta); } function queueOrRevertInternal( 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(uint256 proposalId) external { require( state(proposalId) == ProposalState.Queued, 'NounsDAO::execute: proposal can only be executed if it is queued' ); Proposal storage proposal = _proposals[proposalId]; 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(proposalId); } /** * @notice Cancels a proposal only if sender is the proposer, or proposer delegates dropped below proposal threshold * @param proposalId The id of the proposal to cancel */ function cancel(uint256 proposalId) external { require(state(proposalId) != ProposalState.Executed, 'NounsDAO::cancel: cannot cancel executed proposal'); Proposal storage proposal = _proposals[proposalId]; require( msg.sender == proposal.proposer || nouns.getPriorVotes(proposal.proposer, block.number - 1) <= proposal.proposalThreshold, 'NounsDAO::cancel: proposer above threshold' ); proposal.canceled = true; 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 actions of a proposal * @param proposalId the id of the proposal * @return targets * @return values * @return signatures * @return calldatas */ function getActions(uint256 proposalId) external view returns ( address[] memory targets, uint256[] memory values, string[] memory signatures, bytes[] memory calldatas ) { Proposal storage p = _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(uint256 proposalId, address voter) external view returns (Receipt memory) { return _proposals[proposalId].receipts[voter]; } /** * @notice Gets the state of a proposal * @param proposalId The id of the proposal * @return Proposal state */ function state(uint256 proposalId) public view returns (ProposalState) { require(proposalCount >= proposalId, 'NounsDAO::state: invalid proposal id'); Proposal storage proposal = _proposals[proposalId]; if (proposal.canceled) { return ProposalState.Canceled; } else if (block.number <= proposal.startBlock) { return ProposalState.Pending; } else if (block.number <= proposal.endBlock) { return ProposalState.Active; } else if (proposal.forVotes <= proposal.againstVotes || proposal.forVotes < proposal.quorumVotes) { return ProposalState.Defeated; } else if (proposal.eta == 0) { return ProposalState.Succeeded; } else if (proposal.executed) { return ProposalState.Executed; } else if (block.timestamp >= proposal.eta + timelock.GRACE_PERIOD()) { return ProposalState.Expired; } else { return ProposalState.Queued; } } /** * @notice Returns the proposal details given a proposal id. * @dev this explicit getter solves the `Stack too deep` problem that arose after * adding a new field to the Proposal struct. * @param proposalId the proposal id to get the data for * @return A `ProposalCondensed` struct with the proposal data */ function proposals(uint256 proposalId) external view returns (ProposalCondensed memory) { Proposal storage proposal = _proposals[proposalId]; return ProposalCondensed({ id: proposal.id, proposer: proposal.proposer, proposalThreshold: proposal.proposalThreshold, quorumVotes: proposal.quorumVotes, eta: proposal.eta, startBlock: proposal.startBlock, endBlock: proposal.endBlock, forVotes: proposal.forVotes, againstVotes: proposal.againstVotes, abstainVotes: proposal.abstainVotes, canceled: proposal.canceled, executed: proposal.executed, creationBlock: proposal.creationBlock }); } /** * @notice Cast a vote for a proposal * @param proposalId The id of the proposal to vote on * @param support The support value for the vote. 0=against, 1=for, 2=abstain */ function castVote(uint256 proposalId, uint8 support) external { emit VoteCast(msg.sender, proposalId, support, castVoteInternal(msg.sender, proposalId, support), ''); } /** * @notice Cast a vote for a proposal with a reason * @param proposalId The id of the proposal to vote on * @param support The support value for the vote. 0=against, 1=for, 2=abstain * @param reason The reason given for the vote by the voter */ function castVoteWithReason( uint256 proposalId, uint8 support, string calldata reason ) external { emit VoteCast(msg.sender, proposalId, support, castVoteInternal(msg.sender, proposalId, support), reason); } /** * @notice Cast a vote for a proposal by signature * @dev External function that accepts EIP-712 signatures for voting on proposals. */ function castVoteBySig( uint256 proposalId, uint8 support, uint8 v, bytes32 r, bytes32 s ) external { bytes32 domainSeparator = keccak256( abi.encode(DOMAIN_TYPEHASH, keccak256(bytes(name)), block.chainid, address(this)) ); bytes32 structHash = keccak256(abi.encode(BALLOT_TYPEHASH, proposalId, support)); bytes32 digest = keccak256(abi.encodePacked('\x19\x01', domainSeparator, structHash)); address signatory = ecrecover(digest, v, r, s); require(signatory != address(0), 'NounsDAO::castVoteBySig: invalid signature'); emit VoteCast(signatory, proposalId, support, castVoteInternal(signatory, proposalId, support), ''); } /** * @notice Internal function that caries out voting logic * @param voter The voter that is casting their vote * @param proposalId The id of the proposal to vote on * @param support The support value for the vote. 0=against, 1=for, 2=abstain * @return The number of votes cast */ function castVoteInternal( address voter, uint256 proposalId, uint8 support ) internal returns (uint96) { require(state(proposalId) == ProposalState.Active, 'NounsDAO::castVoteInternal: voting is closed'); require(support <= 2, 'NounsDAO::castVoteInternal: invalid vote type'); Proposal storage proposal = _proposals[proposalId]; Receipt storage receipt = proposal.receipts[voter]; require(receipt.hasVoted == false, 'NounsDAO::castVoteInternal: voter already voted'); /// @notice: Unlike GovernerBravo, votes are considered from the block the proposal was created in order to normalize quorumVotes and proposalThreshold metrics uint96 votes = nouns.getPriorVotes(voter, proposal.creationBlock); if (support == 0) { proposal.againstVotes = proposal.againstVotes + votes; } else if (support == 1) { proposal.forVotes = proposal.forVotes + votes; } else if (support == 2) { proposal.abstainVotes = proposal.abstainVotes + votes; } receipt.hasVoted = true; receipt.support = support; receipt.votes = votes; return votes; } /** * @notice Admin function for setting the voting delay * @param newVotingDelay new voting delay, in blocks */ function _setVotingDelay(uint256 newVotingDelay) external { require(msg.sender == admin, 'NounsDAO::_setVotingDelay: admin only'); require( newVotingDelay >= MIN_VOTING_DELAY && newVotingDelay <= MAX_VOTING_DELAY, 'NounsDAO::_setVotingDelay: invalid voting delay' ); uint256 oldVotingDelay = votingDelay; votingDelay = newVotingDelay; emit VotingDelaySet(oldVotingDelay, newVotingDelay); } /** * @notice Admin function for setting the voting period * @param newVotingPeriod new voting period, in blocks */ function _setVotingPeriod(uint256 newVotingPeriod) external { require(msg.sender == admin, 'NounsDAO::_setVotingPeriod: admin only'); require( newVotingPeriod >= MIN_VOTING_PERIOD && newVotingPeriod <= MAX_VOTING_PERIOD, 'NounsDAO::_setVotingPeriod: invalid voting period' ); uint256 oldVotingPeriod = votingPeriod; votingPeriod = newVotingPeriod; emit VotingPeriodSet(oldVotingPeriod, newVotingPeriod); } /** * @notice Admin function for setting the proposal threshold basis points * @dev newProposalThresholdBPS must be greater than the hardcoded min * @param newProposalThresholdBPS new proposal threshold */ function _setProposalThresholdBPS(uint256 newProposalThresholdBPS) external { require(msg.sender == admin, 'NounsDAO::_setProposalThresholdBPS: admin only'); require( newProposalThresholdBPS >= MIN_PROPOSAL_THRESHOLD_BPS && newProposalThresholdBPS <= MAX_PROPOSAL_THRESHOLD_BPS, 'NounsDAO::_setProposalThreshold: invalid proposal threshold' ); uint256 oldProposalThresholdBPS = proposalThresholdBPS; proposalThresholdBPS = newProposalThresholdBPS; emit ProposalThresholdBPSSet(oldProposalThresholdBPS, newProposalThresholdBPS); } /** * @notice Admin function for setting the quorum votes basis points * @dev newQuorumVotesBPS must be greater than the hardcoded min * @param newQuorumVotesBPS new proposal threshold */ function _setQuorumVotesBPS(uint256 newQuorumVotesBPS) external { require(msg.sender == admin, 'NounsDAO::_setQuorumVotesBPS: admin only'); require( newQuorumVotesBPS >= MIN_QUORUM_VOTES_BPS && newQuorumVotesBPS <= MAX_QUORUM_VOTES_BPS, 'NounsDAO::_setQuorumVotesBPS: invalid quorum votes basis points' ); uint256 oldQuorumVotesBPS = quorumVotesBPS; quorumVotesBPS = newQuorumVotesBPS; emit QuorumVotesBPSSet(oldQuorumVotesBPS, newQuorumVotesBPS); } /** * @notice Begins transfer of admin rights. The newPendingAdmin must call `_acceptAdmin` to finalize the transfer. * @dev Admin function to begin change of admin. The newPendingAdmin must call `_acceptAdmin` to finalize the transfer. * @param newPendingAdmin New pending admin. */ function _setPendingAdmin(address newPendingAdmin) external { // Check caller = admin require(msg.sender == admin, 'NounsDAO::_setPendingAdmin: admin only'); // Save current value, if any, for inclusion in log address oldPendingAdmin = pendingAdmin; // Store pendingAdmin with value newPendingAdmin pendingAdmin = newPendingAdmin; // Emit NewPendingAdmin(oldPendingAdmin, newPendingAdmin) emit NewPendingAdmin(oldPendingAdmin, newPendingAdmin); } /** * @notice Accepts transfer of admin rights. msg.sender must be pendingAdmin * @dev Admin function for pending admin to accept role and update admin */ function _acceptAdmin() external { // Check caller is pendingAdmin and pendingAdmin ≠ address(0) require(msg.sender == pendingAdmin && msg.sender != address(0), 'NounsDAO::_acceptAdmin: pending admin only'); // Save current values for inclusion in log address oldAdmin = admin; address oldPendingAdmin = pendingAdmin; // Store admin with value pendingAdmin admin = pendingAdmin; // Clear the pending value pendingAdmin = address(0); emit NewAdmin(oldAdmin, admin); emit NewPendingAdmin(oldPendingAdmin, pendingAdmin); } /** * @notice Admin function for setting the list of ERC20 tokens to transfer on `quit`. */ function _setErc20TokensToIncludeInQuit(address[] calldata erc20tokens) external { if (msg.sender != admin) revert AdminOnly(); checkForDuplicates(erc20tokens); emit ERC20TokensToIncludeInQuitSet(erc20TokensToIncludeInQuit, erc20tokens); erc20TokensToIncludeInQuit = erc20tokens; } /** * @notice Current proposal threshold using Noun Total Supply * Differs from `GovernerBravo` which uses fixed amount */ function proposalThreshold() public view returns (uint256) { return bps2Uint(proposalThresholdBPS, adjustedTotalSupply()); } /** * @notice Current quorum votes using Noun Total Supply * Differs from `GovernerBravo` which uses fixed amount */ function quorumVotes() public view returns (uint256) { return bps2Uint(quorumVotesBPS, adjustedTotalSupply()); } function adjustedTotalSupply() public view returns (uint256) { return nouns.totalSupply() - nouns.balanceOf(address(timelock)) + nouns.remainingTokensToClaim(); } function erc20TokensToIncludeInQuitArray() public view returns (address[] memory) { return erc20TokensToIncludeInQuit; } function bps2Uint(uint256 bps, uint256 number) internal pure returns (uint256) { return (number * bps) / 10000; } function _authorizeUpgrade(address) internal view override { require(msg.sender == admin, 'NounsDAO::_authorizeUpgrade: admin only'); } function checkForDuplicates(address[] calldata erc20tokens) internal pure { if (erc20tokens.length == 0) return; for (uint256 i = 0; i < erc20tokens.length - 1; i++) { for (uint256 j = i + 1; j < erc20tokens.length; j++) { if (erc20tokens[i] == erc20tokens[j]) revert DuplicateTokenAddress(); } } } }
// SPDX-License-Identifier: GPL-3.0 /// @title The Nouns ERC-721 token /********************************* * ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ * * ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ * * ░░░░░░█████████░░█████████░░░ * * ░░░░░░██░░░████░░██░░░████░░░ * * ░░██████░░░████████░░░████░░░ * * ░░██░░██░░░████░░██░░░████░░░ * * ░░██░░██░░░████░░██░░░████░░░ * * ░░░░░░█████████░░█████████░░░ * * ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ * * ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ * *********************************/ pragma solidity ^0.8.6; import { Ownable } from '@openzeppelin/contracts/access/Ownable.sol'; import { ERC721Checkpointable } from './base/ERC721Checkpointable.sol'; import { INounsDescriptorMinimal } from './interfaces/INounsDescriptorMinimal.sol'; import { INounsSeeder } from './interfaces/INounsSeeder.sol'; import { INounsToken } from './interfaces/INounsToken.sol'; import { ERC721 } from './base/ERC721.sol'; import { IERC721 } from '@openzeppelin/contracts/token/ERC721/IERC721.sol'; import { IProxyRegistry } from './external/opensea/IProxyRegistry.sol'; contract NounsToken is INounsToken, Ownable, ERC721Checkpointable { // The nounders DAO address (creators org) address public noundersDAO; // An address who has permissions to mint Nouns address public minter; // The Nouns token URI descriptor INounsDescriptorMinimal public descriptor; // The Nouns token seeder INounsSeeder public seeder; // Whether the minter can be updated bool public isMinterLocked; // Whether the descriptor can be updated bool public isDescriptorLocked; // Whether the seeder can be updated bool public isSeederLocked; // The noun seeds mapping(uint256 => INounsSeeder.Seed) public seeds; // The internal noun ID tracker uint256 private _currentNounId; // IPFS content hash of contract-level metadata string private _contractURIHash = 'QmZi1n79FqWt2tTLwCqiy6nLM6xLGRsEPQ5JmReJQKNNzX'; // OpenSea's Proxy Registry IProxyRegistry public immutable proxyRegistry; /** * @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 nounders DAO. */ modifier onlyNoundersDAO() { require(msg.sender == noundersDAO, 'Sender is not the nounders DAO'); _; } /** * @notice Require that the sender is the minter. */ modifier onlyMinter() { require(msg.sender == minter, 'Sender is not the minter'); _; } constructor( address _noundersDAO, address _minter, INounsDescriptorMinimal _descriptor, INounsSeeder _seeder, IProxyRegistry _proxyRegistry ) ERC721('Nouns', 'NOUN') { noundersDAO = _noundersDAO; minter = _minter; descriptor = _descriptor; seeder = _seeder; proxyRegistry = _proxyRegistry; } /** * @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 Override isApprovedForAll to whitelist user's OpenSea proxy accounts to enable gas-less listings. */ function isApprovedForAll(address owner, address operator) public view override(IERC721, ERC721) returns (bool) { // Whitelist OpenSea proxy contract for easy trading. if (proxyRegistry.proxies(owner) == operator) { return true; } return super.isApprovedForAll(owner, operator); } /** * @notice Mint a Noun to the minter, along with a possible nounders reward * Noun. Nounders reward Nouns are minted every 10 Nouns, starting at 0, * until 183 nounder Nouns have been minted (5 years w/ 24 hour auctions). * @dev Call _mintTo with the to address(es). */ function mint() public override onlyMinter returns (uint256) { if (_currentNounId <= 1820 && _currentNounId % 10 == 0) { _mintTo(noundersDAO, _currentNounId++); } 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 nounders DAO. * @dev Only callable by the nounders DAO when not locked. */ function setNoundersDAO(address _noundersDAO) external onlyNoundersDAO { noundersDAO = _noundersDAO; emit NoundersDAOUpdated(_noundersDAO); } /** * @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(owner(), to, nounId); emit NounCreated(nounId, seed); return nounId; } }
// SPDX-License-Identifier: GPL-3.0 /// @title The Nouns DAO auction house /********************************* * ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ * * ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ * * ░░░░░░█████████░░█████████░░░ * * ░░░░░░██░░░████░░██░░░████░░░ * * ░░██████░░░████████░░░████░░░ * * ░░██░░██░░░████░░██░░░████░░░ * * ░░██░░██░░░████░░██░░░████░░░ * * ░░░░░░█████████░░█████████░░░ * * ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ * * ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ * *********************************/ // LICENSE // NounsAuctionHouse.sol is a modified version of Zora's AuctionHouse.sol: // https://github.com/ourzora/auction-house/blob/54a12ec1a6cf562e49f0a4917990474b11350a2d/contracts/AuctionHouse.sol // // AuctionHouse.sol source code Copyright Zora licensed under the GPL-3.0 license. // With modifications by Nounders DAO. pragma solidity ^0.8.6; import { PausableUpgradeable } from '@openzeppelin/contracts-upgradeable/security/PausableUpgradeable.sol'; import { ReentrancyGuardUpgradeable } from '@openzeppelin/contracts-upgradeable/security/ReentrancyGuardUpgradeable.sol'; import { OwnableUpgradeable } from '@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol'; import { IERC20 } from '@openzeppelin/contracts/token/ERC20/IERC20.sol'; import { INounsAuctionHouse } from './interfaces/INounsAuctionHouse.sol'; import { INounsToken } from './interfaces/INounsToken.sol'; import { IWETH } from './interfaces/IWETH.sol'; contract NounsAuctionHouse is INounsAuctionHouse, PausableUpgradeable, ReentrancyGuardUpgradeable, OwnableUpgradeable { // The Nouns ERC721 token contract INounsToken public nouns; // The address of the WETH contract address public weth; // The minimum amount of time left in an auction after a new bid is created uint256 public timeBuffer; // The minimum price accepted in an auction uint256 public reservePrice; // The minimum percentage difference between the last bid amount and the current bid uint8 public minBidIncrementPercentage; // The duration of a single auction uint256 public duration; // The active auction INounsAuctionHouse.Auction public auction; /** * @notice Initialize the auction house and base contracts, * populate configuration values, and pause the contract. * @dev This function can only be called once. */ function initialize( INounsToken _nouns, address _weth, uint256 _timeBuffer, uint256 _reservePrice, uint8 _minBidIncrementPercentage, uint256 _duration ) external initializer { __Pausable_init(); __ReentrancyGuard_init(); __Ownable_init(); _pause(); nouns = _nouns; weth = _weth; timeBuffer = _timeBuffer; reservePrice = _reservePrice; minBidIncrementPercentage = _minBidIncrementPercentage; duration = _duration; } /** * @notice Settle the current auction, mint a new Noun, and put it up for auction. */ function settleCurrentAndCreateNewAuction() external override nonReentrant whenNotPaused { _settleAuction(); _createAuction(); } /** * @notice Settle the current auction. * @dev This function can only be called when the contract is paused. */ function settleAuction() external override whenPaused nonReentrant { _settleAuction(); } /** * @notice Create a bid for a Noun, with a given amount. * @dev This contract only accepts payment in ETH. */ function createBid(uint256 nounId) external payable override nonReentrant { INounsAuctionHouse.Auction memory _auction = auction; require(_auction.nounId == nounId, 'Noun not up for auction'); require(block.timestamp < _auction.endTime, 'Auction expired'); require(msg.value >= reservePrice, 'Must send at least reservePrice'); require( msg.value >= _auction.amount + ((_auction.amount * minBidIncrementPercentage) / 100), 'Must send more than last bid by minBidIncrementPercentage amount' ); address payable lastBidder = _auction.bidder; // Refund the last bidder, if applicable if (lastBidder != address(0)) { _safeTransferETHWithFallback(lastBidder, _auction.amount); } auction.amount = msg.value; auction.bidder = payable(msg.sender); // Extend the auction if the bid was received within `timeBuffer` of the auction end time bool extended = _auction.endTime - block.timestamp < timeBuffer; if (extended) { auction.endTime = _auction.endTime = block.timestamp + timeBuffer; } emit AuctionBid(_auction.nounId, msg.sender, msg.value, extended); if (extended) { emit AuctionExtended(_auction.nounId, _auction.endTime); } } /** * @notice Pause the Nouns auction house. * @dev This function can only be called by the owner when the * contract is unpaused. While no new auctions can be started when paused, * anyone can settle an ongoing auction. */ function pause() external override onlyOwner { _pause(); } /** * @notice Unpause the Nouns auction house. * @dev This function can only be called by the owner when the * contract is paused. If required, this function will start a new auction. */ function unpause() external override onlyOwner { _unpause(); if (auction.startTime == 0 || auction.settled) { _createAuction(); } } /** * @notice Set the auction time buffer. * @dev Only callable by the owner. */ function setTimeBuffer(uint256 _timeBuffer) external override onlyOwner { timeBuffer = _timeBuffer; emit AuctionTimeBufferUpdated(_timeBuffer); } /** * @notice Set the auction reserve price. * @dev Only callable by the owner. */ function setReservePrice(uint256 _reservePrice) external override onlyOwner { reservePrice = _reservePrice; emit AuctionReservePriceUpdated(_reservePrice); } /** * @notice Set the auction minimum bid increment percentage. * @dev Only callable by the owner. */ function setMinBidIncrementPercentage(uint8 _minBidIncrementPercentage) external override onlyOwner { minBidIncrementPercentage = _minBidIncrementPercentage; emit AuctionMinBidIncrementPercentageUpdated(_minBidIncrementPercentage); } /** * @notice Create an auction. * @dev Store the auction details in the `auction` state variable and emit an AuctionCreated event. * If the mint reverts, the minter was updated without pausing this contract first. To remedy this, * catch the revert and pause this contract. */ function _createAuction() internal { try nouns.mint() returns (uint256 nounId) { uint256 startTime = block.timestamp; uint256 endTime = startTime + duration; auction = Auction({ nounId: nounId, amount: 0, startTime: startTime, endTime: endTime, bidder: payable(0), settled: false }); emit AuctionCreated(nounId, startTime, endTime); } catch Error(string memory) { _pause(); } } /** * @notice Settle an auction, finalizing the bid and paying out to the owner. * @dev If there are no bids, the Noun is burned. */ function _settleAuction() internal { INounsAuctionHouse.Auction memory _auction = auction; require(_auction.startTime != 0, "Auction hasn't begun"); require(!_auction.settled, 'Auction has already been settled'); require(block.timestamp >= _auction.endTime, "Auction hasn't completed"); auction.settled = true; if (_auction.bidder == address(0)) { nouns.burn(_auction.nounId); } else { nouns.transferFrom(address(this), _auction.bidder, _auction.nounId); } if (_auction.amount > 0) { _safeTransferETHWithFallback(owner(), _auction.amount); } emit AuctionSettled(_auction.nounId, _auction.bidder, _auction.amount); } /** * @notice Transfer ETH. If the ETH transfer fails, wrap the ETH and try send it as WETH. */ function _safeTransferETHWithFallback(address to, uint256 amount) internal { if (!_safeTransferETH(to, amount)) { IWETH(weth).deposit{ value: amount }(); IERC20(weth).transfer(to, amount); } } /** * @notice Transfer ETH and return the success status. * @dev This function only forwards 30,000 gas to the callee. */ function _safeTransferETH(address to, uint256 value) internal returns (bool) { (bool success, ) = to.call{ value: value, gas: 30_000 }(new bytes(0)); return success; } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.0 (proxy/Proxy.sol) pragma solidity ^0.8.0; /** * @dev This abstract contract provides a fallback function that delegates all calls to another contract using the EVM * instruction `delegatecall`. We refer to the second contract as the _implementation_ behind the proxy, and it has to * be specified by overriding the virtual {_implementation} function. * * Additionally, delegation to the implementation can be triggered manually through the {_fallback} function, or to a * different contract through the {_delegate} function. * * The success and return data of the delegated call will be returned back to the caller of the proxy. */ abstract contract Proxy { /** * @dev Delegates the current call to `implementation`. * * This function does not return to its internall call site, it will return directly to the external caller. */ function _delegate(address implementation) internal virtual { assembly { // Copy msg.data. We take full control of memory in this inline assembly // block because it will not return to Solidity code. We overwrite the // Solidity scratch pad at memory position 0. calldatacopy(0, 0, calldatasize()) // Call the implementation. // out and outsize are 0 because we don't know the size yet. let result := delegatecall(gas(), implementation, 0, calldatasize(), 0, 0) // Copy the returned data. returndatacopy(0, 0, returndatasize()) switch result // delegatecall returns 0 on error. case 0 { revert(0, returndatasize()) } default { return(0, returndatasize()) } } } /** * @dev This is a virtual function that should be overriden so it returns the address to which the fallback function * and {_fallback} should delegate. */ function _implementation() internal view virtual returns (address); /** * @dev Delegates the current call to the address returned by `_implementation()`. * * This function does not return to its internall call site, it will return directly to the external caller. */ function _fallback() internal virtual { _beforeFallback(); _delegate(_implementation()); } /** * @dev Fallback function that delegates calls to the address returned by `_implementation()`. Will run if no other * function in the contract matches the call data. */ fallback() external payable virtual { _fallback(); } /** * @dev Fallback function that delegates calls to the address returned by `_implementation()`. Will run if call data * is empty. */ receive() external payable virtual { _fallback(); } /** * @dev Hook that is called before falling back to the implementation. Can happen as part of a manual `_fallback` * call, or as part of the Solidity `fallback` or `receive` functions. * * If overriden should call `super._beforeFallback()`. */ function _beforeFallback() internal virtual {} }
// 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 (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: 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 (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: MIT // OpenZeppelin Contracts v4.4.0 (security/Pausable.sol) pragma solidity ^0.8.0; import "../utils/ContextUpgradeable.sol"; import "../proxy/utils/Initializable.sol"; /** * @dev Contract module which allows children to implement an emergency stop * mechanism that can be triggered by an authorized account. * * This module is used through inheritance. It will make available the * modifiers `whenNotPaused` and `whenPaused`, which can be applied to * the functions of your contract. Note that they will not be pausable by * simply including this module, only once the modifiers are put in place. */ abstract contract PausableUpgradeable is Initializable, ContextUpgradeable { /** * @dev Emitted when the pause is triggered by `account`. */ event Paused(address account); /** * @dev Emitted when the pause is lifted by `account`. */ event Unpaused(address account); bool private _paused; /** * @dev Initializes the contract in unpaused state. */ function __Pausable_init() internal initializer { __Context_init_unchained(); __Pausable_init_unchained(); } function __Pausable_init_unchained() internal initializer { _paused = false; } /** * @dev Returns true if the contract is paused, and false otherwise. */ function paused() public view virtual returns (bool) { return _paused; } /** * @dev Modifier to make a function callable only when the contract is not paused. * * Requirements: * * - The contract must not be paused. */ modifier whenNotPaused() { require(!paused(), "Pausable: paused"); _; } /** * @dev Modifier to make a function callable only when the contract is paused. * * Requirements: * * - The contract must be paused. */ modifier whenPaused() { require(paused(), "Pausable: not paused"); _; } /** * @dev Triggers stopped state. * * Requirements: * * - The contract must not be paused. */ function _pause() internal virtual whenNotPaused { _paused = true; emit Paused(_msgSender()); } /** * @dev Returns to normal state. * * Requirements: * * - The contract must be paused. */ function _unpause() internal virtual whenPaused { _paused = false; emit Unpaused(_msgSender()); } uint256[49] private __gap; }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.0 (security/ReentrancyGuard.sol) pragma solidity ^0.8.0; import "../proxy/utils/Initializable.sol"; /** * @dev Contract module that helps prevent reentrant calls to a function. * * Inheriting from `ReentrancyGuard` will make the {nonReentrant} modifier * available, which can be applied to functions to make sure there are no nested * (reentrant) calls to them. * * Note that because there is a single `nonReentrant` guard, functions marked as * `nonReentrant` may not call one another. This can be worked around by making * those functions `private`, and then adding `external` `nonReentrant` entry * points to them. * * TIP: If you would like to learn more about reentrancy and alternative ways * to protect against it, check out our blog post * https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul]. */ abstract contract ReentrancyGuardUpgradeable is Initializable { // Booleans are more expensive than uint256 or any type that takes up a full // word because each write operation emits an extra SLOAD to first read the // slot's contents, replace the bits taken up by the boolean, and then write // back. This is the compiler's defense against contract upgrades and // pointer aliasing, and it cannot be disabled. // The values being non-zero value makes deployment a bit more expensive, // but in exchange the refund on every call to nonReentrant will be lower in // amount. Since refunds are capped to a percentage of the total // transaction's gas, it is best to keep them low in cases like this one, to // increase the likelihood of the full refund coming into effect. uint256 private constant _NOT_ENTERED = 1; uint256 private constant _ENTERED = 2; uint256 private _status; function __ReentrancyGuard_init() internal initializer { __ReentrancyGuard_init_unchained(); } function __ReentrancyGuard_init_unchained() internal initializer { _status = _NOT_ENTERED; } /** * @dev Prevents a contract from calling itself, directly or indirectly. * Calling a `nonReentrant` function from another `nonReentrant` * function is not supported. It is possible to prevent this from happening * by making the `nonReentrant` function external, and making it call a * `private` function that does the actual work. */ modifier nonReentrant() { // On the first call to nonReentrant, _notEntered will be true require(_status != _ENTERED, "ReentrancyGuard: reentrant call"); // Any calls to nonReentrant after this point will fail _status = _ENTERED; _; // By storing the original value once again, a refund is triggered (see // https://eips.ethereum.org/EIPS/eip-2200) _status = _NOT_ENTERED; } uint256[49] private __gap; }
// 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 Interface for Noun Auction Houses /********************************* * ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ * * ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ * * ░░░░░░█████████░░█████████░░░ * * ░░░░░░██░░░████░░██░░░████░░░ * * ░░██████░░░████████░░░████░░░ * * ░░██░░██░░░████░░██░░░████░░░ * * ░░██░░██░░░████░░██░░░████░░░ * * ░░░░░░█████████░░█████████░░░ * * ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ * * ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ * *********************************/ pragma solidity ^0.8.6; interface INounsAuctionHouse { struct Auction { // ID for the Noun (ERC721 token ID) uint256 nounId; // The current highest bid amount uint256 amount; // The time that the auction started uint256 startTime; // The time that the auction is scheduled to end uint256 endTime; // The address of the current highest bid address payable bidder; // Whether or not the auction has been settled bool settled; } event AuctionCreated(uint256 indexed nounId, uint256 startTime, uint256 endTime); event AuctionBid(uint256 indexed nounId, address sender, uint256 value, bool extended); event AuctionExtended(uint256 indexed nounId, uint256 endTime); event AuctionSettled(uint256 indexed nounId, address winner, uint256 amount); event AuctionTimeBufferUpdated(uint256 timeBuffer); event AuctionReservePriceUpdated(uint256 reservePrice); event AuctionMinBidIncrementPercentageUpdated(uint256 minBidIncrementPercentage); function settleAuction() external; function settleCurrentAndCreateNewAuction() external; function createBid(uint256 nounId) external payable; function pause() external; function unpause() external; function setTimeBuffer(uint256 timeBuffer) external; function setReservePrice(uint256 reservePrice) external; function setMinBidIncrementPercentage(uint8 minBidIncrementPercentage) external; }
// SPDX-License-Identifier: GPL-3.0 /// @title Interface for NounsToken /********************************* * ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ * * ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ * * ░░░░░░█████████░░█████████░░░ * * ░░░░░░██░░░████░░██░░░████░░░ * * ░░██████░░░████████░░░████░░░ * * ░░██░░██░░░████░░██░░░████░░░ * * ░░██░░██░░░████░░██░░░████░░░ * * ░░░░░░█████████░░█████████░░░ * * ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ * * ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ * *********************************/ pragma solidity ^0.8.6; import { IERC721 } from '@openzeppelin/contracts/token/ERC721/IERC721.sol'; import { INounsDescriptorMinimal } from './INounsDescriptorMinimal.sol'; import { INounsSeeder } from './INounsSeeder.sol'; interface INounsToken is IERC721 { event NounCreated(uint256 indexed tokenId, INounsSeeder.Seed seed); event NounBurned(uint256 indexed tokenId); event NoundersDAOUpdated(address noundersDAO); 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: GPL-3.0 pragma solidity ^0.8.6; interface IWETH { function deposit() external payable; function withdraw(uint256 wad) external; function transfer(address to, uint256 value) external returns (bool); }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.0 (token/ERC20/utils/SafeERC20.sol) pragma solidity ^0.8.0; import "../IERC20.sol"; import "../../../utils/Address.sol"; /** * @title SafeERC20 * @dev Wrappers around ERC20 operations that throw on failure (when the token * contract returns false). Tokens that return no value (and instead revert or * throw on failure) are also supported, non-reverting calls are assumed to be * successful. * To use this library you can add a `using SafeERC20 for IERC20;` statement to your contract, * which allows you to call the safe operations as `token.safeTransfer(...)`, etc. */ library SafeERC20 { using Address for address; function safeTransfer( IERC20 token, address to, uint256 value ) internal { _callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value)); } function safeTransferFrom( IERC20 token, address from, address to, uint256 value ) internal { _callOptionalReturn(token, abi.encodeWithSelector(token.transferFrom.selector, from, to, value)); } /** * @dev Deprecated. This function has issues similar to the ones found in * {IERC20-approve}, and its usage is discouraged. * * Whenever possible, use {safeIncreaseAllowance} and * {safeDecreaseAllowance} instead. */ function safeApprove( IERC20 token, address spender, uint256 value ) internal { // safeApprove should only be called when setting an initial allowance, // or when resetting it to zero. To increase and decrease it, use // 'safeIncreaseAllowance' and 'safeDecreaseAllowance' require( (value == 0) || (token.allowance(address(this), spender) == 0), "SafeERC20: approve from non-zero to non-zero allowance" ); _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, value)); } function safeIncreaseAllowance( IERC20 token, address spender, uint256 value ) internal { uint256 newAllowance = token.allowance(address(this), spender) + value; _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance)); } function safeDecreaseAllowance( IERC20 token, address spender, uint256 value ) internal { unchecked { uint256 oldAllowance = token.allowance(address(this), spender); require(oldAllowance >= value, "SafeERC20: decreased allowance below zero"); uint256 newAllowance = oldAllowance - value; _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance)); } } /** * @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement * on the return value: the return value is optional (but if data is returned, it must not be false). * @param token The token targeted by the call. * @param data The call data (encoded using abi.encode or one of its variants). */ function _callOptionalReturn(IERC20 token, bytes memory data) private { // We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since // we're implementing it ourselves. We use {Address.functionCall} to perform this call, which verifies that // the target address contains contract code and also asserts for success in the low-level call. bytes memory returndata = address(token).functionCall(data, "SafeERC20: low-level call failed"); if (returndata.length > 0) { // Return data is optional require(abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation did not succeed"); } } }
// 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: 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: GPL-3.0 /// @title Library for NounsDAOLogicV3 contract containing admin related functions /********************************* * ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ * * ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ * * ░░░░░░█████████░░█████████░░░ * * ░░░░░░██░░░████░░██░░░████░░░ * * ░░██████░░░████████░░░████░░░ * * ░░██░░██░░░████░░██░░░████░░░ * * ░░██░░██░░░████░░██░░░████░░░ * * ░░░░░░█████████░░█████████░░░ * * ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ * * ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ * *********************************/ pragma solidity ^0.8.19; import './NounsDAOInterfaces.sol'; import { NounsDAOV3DynamicQuorum } from './NounsDAOV3DynamicQuorum.sol'; library NounsDAOV3Admin { using NounsDAOV3DynamicQuorum for NounsDAOStorageV3.StorageV3; error AdminOnly(); error VetoerOnly(); error PendingVetoerOnly(); error InvalidMinQuorumVotesBPS(); error InvalidMaxQuorumVotesBPS(); error MinQuorumBPSGreaterThanMaxQuorumBPS(); error ForkPeriodTooLong(); error ForkPeriodTooShort(); error InvalidObjectionPeriodDurationInBlocks(); error InvalidProposalUpdatablePeriodInBlocks(); error VoteSnapshotSwitchAlreadySet(); error DuplicateTokenAddress(); /// @notice Emitted when proposal threshold basis points is set event ProposalThresholdBPSSet(uint256 oldProposalThresholdBPS, uint256 newProposalThresholdBPS); /// @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 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 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 pendingVetoer is changed event NewPendingVetoer(address oldPendingVetoer, address newPendingVetoer); /// @notice Emitted when vetoer is changed event NewVetoer(address oldVetoer, address newVetoer); /// @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 admin withdraws the DAO's balance. event Withdraw(uint256 amount, bool sent); /// @notice Emitted when the proposal id at which vote snapshot block changes is set event VoteSnapshotBlockSwitchProposalIdSet( uint256 oldVoteSnapshotBlockSwitchProposalId, uint256 newVoteSnapshotBlockSwitchProposalId ); /// @notice Emitted when the fork DAO deployer is set event ForkDAODeployerSet(address oldForkDAODeployer, address newForkDAODeployer); /// @notice Emitted when the erc20 tokens to include in a fork are set event ERC20TokensToIncludeInForkSet(address[] oldErc20Tokens, address[] newErc20tokens); /// @notice Emitted when the fork escrow contract address is set event ForkEscrowSet(address oldForkEscrow, address newForkEscrow); /// @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 The minimum setable proposal threshold uint256 public constant MIN_PROPOSAL_THRESHOLD_BPS = 1; // 1 basis point or 0.01% /// @notice The maximum setable proposal threshold uint256 public constant MAX_PROPOSAL_THRESHOLD_BPS = 1_000; // 1,000 basis points or 10% /// @notice The minimum setable voting period in blocks uint256 public constant MIN_VOTING_PERIOD_BLOCKS = 1 days / 12; /// @notice The max setable voting period in blocks uint256 public constant MAX_VOTING_PERIOD_BLOCKS = 2 weeks / 12; /// @notice The min setable voting delay in blocks uint256 public constant MIN_VOTING_DELAY_BLOCKS = 1; /// @notice The max setable voting delay in blocks uint256 public constant MAX_VOTING_DELAY_BLOCKS = 2 weeks / 12; /// @notice The lower bound of minimum quorum votes basis points uint256 public constant MIN_QUORUM_VOTES_BPS_LOWER_BOUND = 200; // 200 basis points or 2% /// @notice The upper bound of minimum quorum votes basis points uint256 public constant MIN_QUORUM_VOTES_BPS_UPPER_BOUND = 2_000; // 2,000 basis points or 20% /// @notice The upper bound of maximum quorum votes basis points uint256 public constant MAX_QUORUM_VOTES_BPS_UPPER_BOUND = 6_000; // 6,000 basis points or 60% /// @notice Upper bound for forking period. If forking period is too high it can block proposals for too long. uint256 public constant MAX_FORK_PERIOD = 14 days; /// @notice Lower bound for forking period uint256 public constant MIN_FORK_PERIOD = 2 days; /// @notice Upper bound for objection period duration in blocks. uint256 public constant MAX_OBJECTION_PERIOD_BLOCKS = 7 days / 12; /// @notice Upper bound for proposal updatable period duration in blocks. uint256 public constant MAX_UPDATABLE_PERIOD_BLOCKS = 7 days / 12; modifier onlyAdmin(NounsDAOStorageV3.StorageV3 storage ds) { if (msg.sender != ds.admin) { revert AdminOnly(); } _; } /** * @notice Admin function for setting the voting delay. Best to set voting delay to at least a few days, to give * voters time to make sense of proposals, e.g. 21,600 blocks which should be at least 3 days. * @param newVotingDelay new voting delay, in blocks */ function _setVotingDelay(NounsDAOStorageV3.StorageV3 storage ds, uint256 newVotingDelay) external onlyAdmin(ds) { require( newVotingDelay >= MIN_VOTING_DELAY_BLOCKS && newVotingDelay <= MAX_VOTING_DELAY_BLOCKS, 'NounsDAO::_setVotingDelay: invalid voting delay' ); uint256 oldVotingDelay = ds.votingDelay; ds.votingDelay = newVotingDelay; emit VotingDelaySet(oldVotingDelay, newVotingDelay); } /** * @notice Admin function for setting the voting period * @param newVotingPeriod new voting period, in blocks */ function _setVotingPeriod(NounsDAOStorageV3.StorageV3 storage ds, uint256 newVotingPeriod) external onlyAdmin(ds) { require( newVotingPeriod >= MIN_VOTING_PERIOD_BLOCKS && newVotingPeriod <= MAX_VOTING_PERIOD_BLOCKS, 'NounsDAO::_setVotingPeriod: invalid voting period' ); uint256 oldVotingPeriod = ds.votingPeriod; ds.votingPeriod = newVotingPeriod; emit VotingPeriodSet(oldVotingPeriod, newVotingPeriod); } /** * @notice Admin function for setting the proposal threshold basis points * @dev newProposalThresholdBPS must be in [`MIN_PROPOSAL_THRESHOLD_BPS`,`MAX_PROPOSAL_THRESHOLD_BPS`] * @param newProposalThresholdBPS new proposal threshold */ function _setProposalThresholdBPS(NounsDAOStorageV3.StorageV3 storage ds, uint256 newProposalThresholdBPS) external onlyAdmin(ds) { require( newProposalThresholdBPS >= MIN_PROPOSAL_THRESHOLD_BPS && newProposalThresholdBPS <= MAX_PROPOSAL_THRESHOLD_BPS, 'NounsDAO::_setProposalThreshold: invalid proposal threshold bps' ); uint256 oldProposalThresholdBPS = ds.proposalThresholdBPS; ds.proposalThresholdBPS = newProposalThresholdBPS; emit ProposalThresholdBPSSet(oldProposalThresholdBPS, newProposalThresholdBPS); } /** * @notice Admin function for setting the objection period duration * @param newObjectionPeriodDurationInBlocks new objection period duration, in blocks */ function _setObjectionPeriodDurationInBlocks( NounsDAOStorageV3.StorageV3 storage ds, uint32 newObjectionPeriodDurationInBlocks ) external onlyAdmin(ds) { if (newObjectionPeriodDurationInBlocks > MAX_OBJECTION_PERIOD_BLOCKS) revert InvalidObjectionPeriodDurationInBlocks(); uint32 oldObjectionPeriodDurationInBlocks = ds.objectionPeriodDurationInBlocks; ds.objectionPeriodDurationInBlocks = newObjectionPeriodDurationInBlocks; emit ObjectionPeriodDurationSet(oldObjectionPeriodDurationInBlocks, newObjectionPeriodDurationInBlocks); } /** * @notice Admin function for setting the objection period last minute window * @param newLastMinuteWindowInBlocks new objection period last minute window, in blocks */ function _setLastMinuteWindowInBlocks(NounsDAOStorageV3.StorageV3 storage ds, uint32 newLastMinuteWindowInBlocks) external onlyAdmin(ds) { uint32 oldLastMinuteWindowInBlocks = ds.lastMinuteWindowInBlocks; ds.lastMinuteWindowInBlocks = newLastMinuteWindowInBlocks; emit LastMinuteWindowSet(oldLastMinuteWindowInBlocks, newLastMinuteWindowInBlocks); } /** * @notice Admin function for setting the proposal updatable period * @param newProposalUpdatablePeriodInBlocks the new proposal updatable period, in blocks */ function _setProposalUpdatablePeriodInBlocks( NounsDAOStorageV3.StorageV3 storage ds, uint32 newProposalUpdatablePeriodInBlocks ) external onlyAdmin(ds) { if (newProposalUpdatablePeriodInBlocks > MAX_UPDATABLE_PERIOD_BLOCKS) revert InvalidProposalUpdatablePeriodInBlocks(); uint32 oldProposalUpdatablePeriodInBlocks = ds.proposalUpdatablePeriodInBlocks; ds.proposalUpdatablePeriodInBlocks = newProposalUpdatablePeriodInBlocks; emit ProposalUpdatablePeriodSet(oldProposalUpdatablePeriodInBlocks, newProposalUpdatablePeriodInBlocks); } /** * @notice Begins transfer of admin rights. The newPendingAdmin must call `_acceptAdmin` to finalize the transfer. * @dev Admin function to begin change of admin. The newPendingAdmin must call `_acceptAdmin` to finalize the transfer. * @param newPendingAdmin New pending admin. */ function _setPendingAdmin(NounsDAOStorageV3.StorageV3 storage ds, address newPendingAdmin) external onlyAdmin(ds) { // Save current value, if any, for inclusion in log address oldPendingAdmin = ds.pendingAdmin; // Store pendingAdmin with value newPendingAdmin ds.pendingAdmin = newPendingAdmin; // Emit NewPendingAdmin(oldPendingAdmin, newPendingAdmin) emit NewPendingAdmin(oldPendingAdmin, newPendingAdmin); } /** * @notice Accepts transfer of admin rights. msg.sender must be pendingAdmin * @dev Admin function for pending admin to accept role and update admin */ function _acceptAdmin(NounsDAOStorageV3.StorageV3 storage ds) external { // Check caller is pendingAdmin and pendingAdmin ≠ address(0) require( msg.sender == ds.pendingAdmin && msg.sender != address(0), 'NounsDAO::_acceptAdmin: pending admin only' ); // Save current values for inclusion in log address oldAdmin = ds.admin; address oldPendingAdmin = ds.pendingAdmin; // Store admin with value pendingAdmin ds.admin = ds.pendingAdmin; // Clear the pending value ds.pendingAdmin = address(0); emit NewAdmin(oldAdmin, ds.admin); emit NewPendingAdmin(oldPendingAdmin, address(0)); } /** * @notice Begins transition of vetoer. The newPendingVetoer must call _acceptVetoer to finalize the transfer. * @param newPendingVetoer New Pending Vetoer */ function _setPendingVetoer(NounsDAOStorageV3.StorageV3 storage ds, address newPendingVetoer) public { if (msg.sender != ds.vetoer) { revert VetoerOnly(); } emit NewPendingVetoer(ds.pendingVetoer, newPendingVetoer); ds.pendingVetoer = newPendingVetoer; } /** * @notice Called by the pendingVetoer to accept role and update vetoer */ function _acceptVetoer(NounsDAOStorageV3.StorageV3 storage ds) external { if (msg.sender != ds.pendingVetoer) { revert PendingVetoerOnly(); } // Update vetoer emit NewVetoer(ds.vetoer, ds.pendingVetoer); ds.vetoer = ds.pendingVetoer; // Clear the pending value emit NewPendingVetoer(ds.pendingVetoer, address(0)); ds.pendingVetoer = address(0); } /** * @notice Burns veto priviledges * @dev Vetoer function destroying veto power forever */ function _burnVetoPower(NounsDAOStorageV3.StorageV3 storage ds) public { // Check caller is vetoer require(msg.sender == ds.vetoer, 'NounsDAO::_burnVetoPower: vetoer only'); // Update vetoer to 0x0 emit NewVetoer(ds.vetoer, address(0)); ds.vetoer = address(0); // Clear the pending value emit NewPendingVetoer(ds.pendingVetoer, address(0)); ds.pendingVetoer = address(0); } /** * @notice Admin function for setting the minimum quorum votes bps * @param newMinQuorumVotesBPS minimum quorum votes bps * Must be between `MIN_QUORUM_VOTES_BPS_LOWER_BOUND` and `MIN_QUORUM_VOTES_BPS_UPPER_BOUND` * Must be lower than or equal to maxQuorumVotesBPS */ function _setMinQuorumVotesBPS(NounsDAOStorageV3.StorageV3 storage ds, uint16 newMinQuorumVotesBPS) external onlyAdmin(ds) { NounsDAOStorageV3.DynamicQuorumParams memory params = ds.getDynamicQuorumParamsAt(block.number); require( newMinQuorumVotesBPS >= MIN_QUORUM_VOTES_BPS_LOWER_BOUND && newMinQuorumVotesBPS <= MIN_QUORUM_VOTES_BPS_UPPER_BOUND, 'NounsDAO::_setMinQuorumVotesBPS: invalid min quorum votes bps' ); require( newMinQuorumVotesBPS <= params.maxQuorumVotesBPS, 'NounsDAO::_setMinQuorumVotesBPS: min quorum votes bps greater than max' ); uint16 oldMinQuorumVotesBPS = params.minQuorumVotesBPS; params.minQuorumVotesBPS = newMinQuorumVotesBPS; _writeQuorumParamsCheckpoint(ds, params); emit MinQuorumVotesBPSSet(oldMinQuorumVotesBPS, newMinQuorumVotesBPS); } /** * @notice Admin function for setting the maximum quorum votes bps * @param newMaxQuorumVotesBPS maximum quorum votes bps * Must be lower than `MAX_QUORUM_VOTES_BPS_UPPER_BOUND` * Must be higher than or equal to minQuorumVotesBPS */ function _setMaxQuorumVotesBPS(NounsDAOStorageV3.StorageV3 storage ds, uint16 newMaxQuorumVotesBPS) external onlyAdmin(ds) { NounsDAOStorageV3.DynamicQuorumParams memory params = ds.getDynamicQuorumParamsAt(block.number); require( newMaxQuorumVotesBPS <= MAX_QUORUM_VOTES_BPS_UPPER_BOUND, 'NounsDAO::_setMaxQuorumVotesBPS: invalid max quorum votes bps' ); require( params.minQuorumVotesBPS <= newMaxQuorumVotesBPS, 'NounsDAO::_setMaxQuorumVotesBPS: min quorum votes bps greater than max' ); uint16 oldMaxQuorumVotesBPS = params.maxQuorumVotesBPS; params.maxQuorumVotesBPS = newMaxQuorumVotesBPS; _writeQuorumParamsCheckpoint(ds, params); emit MaxQuorumVotesBPSSet(oldMaxQuorumVotesBPS, newMaxQuorumVotesBPS); } /** * @notice Admin function for setting the dynamic quorum coefficient * @param newQuorumCoefficient the new coefficient, as a fixed point integer with 6 decimals */ function _setQuorumCoefficient(NounsDAOStorageV3.StorageV3 storage ds, uint32 newQuorumCoefficient) external onlyAdmin(ds) { NounsDAOStorageV3.DynamicQuorumParams memory params = ds.getDynamicQuorumParamsAt(block.number); uint32 oldQuorumCoefficient = params.quorumCoefficient; params.quorumCoefficient = newQuorumCoefficient; _writeQuorumParamsCheckpoint(ds, params); emit QuorumCoefficientSet(oldQuorumCoefficient, newQuorumCoefficient); } /** * @notice Admin function for setting all the dynamic quorum parameters * @param newMinQuorumVotesBPS minimum quorum votes bps * Must be between `MIN_QUORUM_VOTES_BPS_LOWER_BOUND` and `MIN_QUORUM_VOTES_BPS_UPPER_BOUND` * Must be lower than or equal to maxQuorumVotesBPS * @param newMaxQuorumVotesBPS maximum quorum votes bps * Must be lower than `MAX_QUORUM_VOTES_BPS_UPPER_BOUND` * Must be higher than or equal to minQuorumVotesBPS * @param newQuorumCoefficient the new coefficient, as a fixed point integer with 6 decimals */ function _setDynamicQuorumParams( NounsDAOStorageV3.StorageV3 storage ds, uint16 newMinQuorumVotesBPS, uint16 newMaxQuorumVotesBPS, uint32 newQuorumCoefficient ) public onlyAdmin(ds) { if ( newMinQuorumVotesBPS < MIN_QUORUM_VOTES_BPS_LOWER_BOUND || newMinQuorumVotesBPS > MIN_QUORUM_VOTES_BPS_UPPER_BOUND ) { revert InvalidMinQuorumVotesBPS(); } if (newMaxQuorumVotesBPS > MAX_QUORUM_VOTES_BPS_UPPER_BOUND) { revert InvalidMaxQuorumVotesBPS(); } if (newMinQuorumVotesBPS > newMaxQuorumVotesBPS) { revert MinQuorumBPSGreaterThanMaxQuorumBPS(); } NounsDAOStorageV3.DynamicQuorumParams memory oldParams = ds.getDynamicQuorumParamsAt(block.number); NounsDAOStorageV3.DynamicQuorumParams memory params = NounsDAOStorageV3.DynamicQuorumParams({ minQuorumVotesBPS: newMinQuorumVotesBPS, maxQuorumVotesBPS: newMaxQuorumVotesBPS, quorumCoefficient: newQuorumCoefficient }); _writeQuorumParamsCheckpoint(ds, params); emit MinQuorumVotesBPSSet(oldParams.minQuorumVotesBPS, params.minQuorumVotesBPS); emit MaxQuorumVotesBPSSet(oldParams.maxQuorumVotesBPS, params.maxQuorumVotesBPS); emit QuorumCoefficientSet(oldParams.quorumCoefficient, params.quorumCoefficient); } /** * @notice Withdraws all the ETH in the contract. This is callable only by the admin (timelock). */ function _withdraw(NounsDAOStorageV3.StorageV3 storage ds) external onlyAdmin(ds) returns (uint256, bool) { uint256 amount = address(this).balance; (bool sent, ) = msg.sender.call{ value: amount }(''); emit Withdraw(amount, sent); return (amount, sent); } /** * @notice Admin function for setting the proposal id at which vote snapshots start using the voting start block * instead of the proposal creation block. * Sets it to the next proposal id. */ function _setVoteSnapshotBlockSwitchProposalId(NounsDAOStorageV3.StorageV3 storage ds) external onlyAdmin(ds) { uint256 oldVoteSnapshotBlockSwitchProposalId = ds.voteSnapshotBlockSwitchProposalId; if (oldVoteSnapshotBlockSwitchProposalId > 0) { revert VoteSnapshotSwitchAlreadySet(); } uint256 newVoteSnapshotBlockSwitchProposalId = ds.proposalCount + 1; ds.voteSnapshotBlockSwitchProposalId = newVoteSnapshotBlockSwitchProposalId; emit VoteSnapshotBlockSwitchProposalIdSet( oldVoteSnapshotBlockSwitchProposalId, newVoteSnapshotBlockSwitchProposalId ); } /** * @notice Admin function for setting the fork DAO deployer contract */ function _setForkDAODeployer(NounsDAOStorageV3.StorageV3 storage ds, address newForkDAODeployer) external onlyAdmin(ds) { address oldForkDAODeployer = address(ds.forkDAODeployer); ds.forkDAODeployer = IForkDAODeployer(newForkDAODeployer); emit ForkDAODeployerSet(oldForkDAODeployer, newForkDAODeployer); } /** * @notice Admin function for setting the ERC20 tokens that are used when splitting funds to a fork */ function _setErc20TokensToIncludeInFork(NounsDAOStorageV3.StorageV3 storage ds, address[] calldata erc20tokens) external onlyAdmin(ds) { checkForDuplicates(erc20tokens); emit ERC20TokensToIncludeInForkSet(ds.erc20TokensToIncludeInFork, erc20tokens); ds.erc20TokensToIncludeInFork = erc20tokens; } /** * @notice Admin function for setting the fork escrow contract */ function _setForkEscrow(NounsDAOStorageV3.StorageV3 storage ds, address newForkEscrow) external onlyAdmin(ds) { emit ForkEscrowSet(address(ds.forkEscrow), newForkEscrow); ds.forkEscrow = INounsDAOForkEscrow(newForkEscrow); } function _setForkPeriod(NounsDAOStorageV3.StorageV3 storage ds, uint256 newForkPeriod) external onlyAdmin(ds) { if (newForkPeriod > MAX_FORK_PERIOD) { revert ForkPeriodTooLong(); } if (newForkPeriod < MIN_FORK_PERIOD) { revert ForkPeriodTooShort(); } emit ForkPeriodSet(ds.forkPeriod, newForkPeriod); ds.forkPeriod = newForkPeriod; } /** * @notice Admin function for setting the fork threshold * @param newForkThresholdBPS the new fork proposal threshold, in basis points */ function _setForkThresholdBPS(NounsDAOStorageV3.StorageV3 storage ds, uint256 newForkThresholdBPS) external onlyAdmin(ds) { emit ForkThresholdSet(ds.forkThresholdBPS, newForkThresholdBPS); ds.forkThresholdBPS = newForkThresholdBPS; } /** * @notice Admin function for setting the timelocks and admin * @param timelock the new timelock contract * @param timelockV1 the new timelockV1 contract * @param admin the new admin address */ function _setTimelocksAndAdmin( NounsDAOStorageV3.StorageV3 storage ds, address timelock, address timelockV1, address admin ) external onlyAdmin(ds) { ds.timelock = INounsDAOExecutorV2(timelock); ds.timelockV1 = INounsDAOExecutor(timelockV1); ds.admin = admin; emit TimelocksAndAdminSet(timelock, timelockV1, admin); } function _writeQuorumParamsCheckpoint( NounsDAOStorageV3.StorageV3 storage ds, NounsDAOStorageV3.DynamicQuorumParams memory params ) internal { uint32 blockNumber = safe32(block.number, 'block number exceeds 32 bits'); uint256 pos = ds.quorumParamsCheckpoints.length; if (pos > 0 && ds.quorumParamsCheckpoints[pos - 1].fromBlock == blockNumber) { ds.quorumParamsCheckpoints[pos - 1].params = params; } else { ds.quorumParamsCheckpoints.push( NounsDAOStorageV3.DynamicQuorumParamsCheckpoint({ fromBlock: blockNumber, params: params }) ); } } function safe32(uint256 n, string memory errorMessage) internal pure returns (uint32) { require(n <= type(uint32).max, errorMessage); return uint32(n); } function checkForDuplicates(address[] calldata erc20tokens) internal pure { if (erc20tokens.length == 0) return; for (uint256 i = 0; i < erc20tokens.length - 1; i++) { for (uint256 j = i + 1; j < erc20tokens.length; j++) { if (erc20tokens[i] == erc20tokens[j]) revert DuplicateTokenAddress(); } } } }
// 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 all the voting related code /********************************* * ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ * * ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ * * ░░░░░░█████████░░█████████░░░ * * ░░░░░░██░░░████░░██░░░████░░░ * * ░░██████░░░████████░░░████░░░ * * ░░██░░██░░░████░░██░░░████░░░ * * ░░██░░██░░░████░░██░░░████░░░ * * ░░░░░░█████████░░█████████░░░ * * ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ * * ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ * *********************************/ pragma solidity ^0.8.19; import './NounsDAOInterfaces.sol'; import { NounsDAOV3Proposals } from './NounsDAOV3Proposals.sol'; import { SafeCast } from '@openzeppelin/contracts/utils/math/SafeCast.sol'; library NounsDAOV3Votes { using NounsDAOV3Proposals for NounsDAOStorageV3.StorageV3; error CanOnlyVoteAgainstDuringObjectionPeriod(); /// @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 Emitted when a voter cast a vote requesting a gas refund. event RefundableVote(address indexed voter, uint256 refundAmount, bool refundSent); /// @notice Emitted when a proposal is set to have an objection period event ProposalObjectionPeriodSet(uint256 indexed id, uint256 objectionPeriodEndBlock); /// @notice The name of this contract string public constant name = 'Nouns DAO'; /// @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 ballot struct used by the contract bytes32 public constant BALLOT_TYPEHASH = keccak256('Ballot(uint256 proposalId,uint8 support)'); /// @notice The maximum priority fee used to cap gas refunds in `castRefundableVote` uint256 public constant MAX_REFUND_PRIORITY_FEE = 2 gwei; /// @notice The vote refund gas overhead, including 7K for ETH transfer and 29K for general transaction overhead uint256 public constant REFUND_BASE_GAS = 36000; /// @notice The maximum gas units the DAO will refund voters on; supports about 9,190 characters uint256 public constant MAX_REFUND_GAS_USED = 200_000; /// @notice The maximum basefee the DAO will refund voters on uint256 public constant MAX_REFUND_BASE_FEE = 200 gwei; /** * @notice Cast a vote for a proposal * @param proposalId The id of the proposal to vote on * @param support The support value for the vote. 0=against, 1=for, 2=abstain */ function castVote( NounsDAOStorageV3.StorageV3 storage ds, uint256 proposalId, uint8 support ) external { emit VoteCast(msg.sender, proposalId, support, castVoteInternal(ds, msg.sender, proposalId, support), ''); } /** * @notice Cast a vote for a proposal, asking the DAO to refund gas costs. * Users with > 0 votes receive refunds. Refunds are partial when using a gas priority fee higher than the DAO's cap. * Refunds are partial when the DAO's balance is insufficient. * No refund is sent when the DAO's balance is empty. No refund is sent to users with no votes. * Voting takes place regardless of refund success. * @param proposalId The id of the proposal to vote on * @param support The support value for the vote. 0=against, 1=for, 2=abstain * @dev Reentrancy is defended against in `castVoteInternal` at the `receipt.hasVoted == false` require statement. */ function castRefundableVote( NounsDAOStorageV3.StorageV3 storage ds, uint256 proposalId, uint8 support ) external { castRefundableVoteInternal(ds, proposalId, support, ''); } /** * @notice Cast a vote for a proposal, asking the DAO to refund gas costs. * Users with > 0 votes receive refunds. Refunds are partial when using a gas priority fee higher than the DAO's cap. * Refunds are partial when the DAO's balance is insufficient. * No refund is sent when the DAO's balance is empty. No refund is sent to users with no votes. * Voting takes place regardless of refund success. * @param proposalId The id of the proposal to vote on * @param support The support value for the vote. 0=against, 1=for, 2=abstain * @param reason The reason given for the vote by the voter * @dev Reentrancy is defended against in `castVoteInternal` at the `receipt.hasVoted == false` require statement. */ function castRefundableVoteWithReason( NounsDAOStorageV3.StorageV3 storage ds, uint256 proposalId, uint8 support, string calldata reason ) external { castRefundableVoteInternal(ds, proposalId, support, reason); } /** * @notice Internal function that carries out refundable voting logic * @param proposalId The id of the proposal to vote on * @param support The support value for the vote. 0=against, 1=for, 2=abstain * @param reason The reason given for the vote by the voter * @dev Reentrancy is defended against in `castVoteInternal` at the `receipt.hasVoted == false` require statement. */ function castRefundableVoteInternal( NounsDAOStorageV3.StorageV3 storage ds, uint256 proposalId, uint8 support, string memory reason ) internal { uint256 startGas = gasleft(); uint96 votes = castVoteInternal(ds, msg.sender, proposalId, support); emit VoteCast(msg.sender, proposalId, support, votes, reason); if (votes > 0) { _refundGas(startGas); } } /** * @notice Cast a vote for a proposal with a reason * @param proposalId The id of the proposal to vote on * @param support The support value for the vote. 0=against, 1=for, 2=abstain * @param reason The reason given for the vote by the voter */ function castVoteWithReason( NounsDAOStorageV3.StorageV3 storage ds, uint256 proposalId, uint8 support, string calldata reason ) external { emit VoteCast(msg.sender, proposalId, support, castVoteInternal(ds, msg.sender, proposalId, support), reason); } /** * @notice Cast a vote for a proposal by signature * @dev External function that accepts EIP-712 signatures for voting on proposals. */ function castVoteBySig( NounsDAOStorageV3.StorageV3 storage ds, uint256 proposalId, uint8 support, uint8 v, bytes32 r, bytes32 s ) external { bytes32 domainSeparator = keccak256( abi.encode(DOMAIN_TYPEHASH, keccak256(bytes(name)), block.chainid, address(this)) ); bytes32 structHash = keccak256(abi.encode(BALLOT_TYPEHASH, proposalId, support)); bytes32 digest = keccak256(abi.encodePacked('\x19\x01', domainSeparator, structHash)); address signatory = ecrecover(digest, v, r, s); require(signatory != address(0), 'NounsDAO::castVoteBySig: invalid signature'); emit VoteCast(signatory, proposalId, support, castVoteInternal(ds, signatory, proposalId, support), ''); } /** * @notice Internal function that caries out voting logic * In case of a vote during the 'last minute window', which changes the proposal outcome from being defeated to * passing, and objection period is adding to the proposal's voting period. * During the objection period, only votes against a proposal can be cast. * @param voter The voter that is casting their vote * @param proposalId The id of the proposal to vote on * @param support The support value for the vote. 0=against, 1=for, 2=abstain * @return The number of votes cast */ function castVoteInternal( NounsDAOStorageV3.StorageV3 storage ds, address voter, uint256 proposalId, uint8 support ) internal returns (uint96) { NounsDAOStorageV3.ProposalState proposalState = ds.stateInternal(proposalId); if (proposalState == NounsDAOStorageV3.ProposalState.Active) { return castVoteDuringVotingPeriodInternal(ds, proposalId, voter, support); } else if (proposalState == NounsDAOStorageV3.ProposalState.ObjectionPeriod) { if (support != 0) revert CanOnlyVoteAgainstDuringObjectionPeriod(); return castObjectionInternal(ds, proposalId, voter); } revert('NounsDAO::castVoteInternal: voting is closed'); } /** * @notice Internal function that handles voting logic during the voting period. * @dev Assumes it's only called by `castVoteInternal` which ensures the proposal is active. * @param proposalId The id of the proposal being voted on * @param voter The address of the voter * @param support The support value for the vote. 0=against, 1=for, 2=abstain * @return The number of votes cast */ function castVoteDuringVotingPeriodInternal( NounsDAOStorageV3.StorageV3 storage ds, uint256 proposalId, address voter, uint8 support ) internal returns (uint96) { require(support <= 2, 'NounsDAO::castVoteDuringVotingPeriodInternal: invalid vote type'); NounsDAOStorageV3.Proposal storage proposal = ds._proposals[proposalId]; NounsDAOStorageV3.Receipt storage receipt = proposal.receipts[voter]; require(receipt.hasVoted == false, 'NounsDAO::castVoteDuringVotingPeriodInternal: voter already voted'); /// @notice: Unlike GovernerBravo, votes are considered from the block the proposal was created in order to normalize quorumVotes and proposalThreshold metrics uint96 votes = ds.nouns.getPriorVotes(voter, proposalVoteSnapshotBlock(ds, proposalId, proposal)); bool isForVoteInLastMinuteWindow = false; if (support == 1) { isForVoteInLastMinuteWindow = (proposal.endBlock - block.number < ds.lastMinuteWindowInBlocks); } bool isDefeatedBefore = false; if (isForVoteInLastMinuteWindow) isDefeatedBefore = ds.isDefeated(proposal); if (support == 0) { proposal.againstVotes = proposal.againstVotes + votes; } else if (support == 1) { proposal.forVotes = proposal.forVotes + votes; } else if (support == 2) { proposal.abstainVotes = proposal.abstainVotes + votes; } if ( // only for votes can trigger an objection period // we're in the last minute window isForVoteInLastMinuteWindow && // first part of the vote flip check // separated from the second part to optimize gas isDefeatedBefore && // haven't turn on objection yet proposal.objectionPeriodEndBlock == 0 && // second part of the vote flip check !ds.isDefeated(proposal) ) { proposal.objectionPeriodEndBlock = SafeCast.toUint64( proposal.endBlock + ds.objectionPeriodDurationInBlocks ); emit ProposalObjectionPeriodSet(proposal.id, proposal.objectionPeriodEndBlock); } receipt.hasVoted = true; receipt.support = support; receipt.votes = votes; return votes; } /** * @notice Internal function that handles against votes during an objection period. * @dev Assumes it's being called by `castVoteInternal` which ensures: * 1. The proposal is in the objection period state. * 2. The vote is an against vote. * @param proposalId The id of the proposal being voted on * @param voter The address of the voter * @return The number of votes cast */ function castObjectionInternal( NounsDAOStorageV3.StorageV3 storage ds, uint256 proposalId, address voter ) internal returns (uint96) { NounsDAOStorageV3.Proposal storage proposal = ds._proposals[proposalId]; NounsDAOStorageV3.Receipt storage receipt = proposal.receipts[voter]; require(receipt.hasVoted == false, 'NounsDAO::castVoteInternal: voter already voted'); uint96 votes = receipt.votes = ds.nouns.getPriorVotes( voter, proposalVoteSnapshotBlock(ds, proposalId, proposal) ); receipt.hasVoted = true; receipt.support = 0; proposal.againstVotes = proposal.againstVotes + votes; return votes; } function _refundGas(uint256 startGas) internal { unchecked { uint256 balance = address(this).balance; if (balance == 0) { return; } uint256 basefee = min(block.basefee, MAX_REFUND_BASE_FEE); uint256 gasPrice = min(tx.gasprice, basefee + MAX_REFUND_PRIORITY_FEE); uint256 gasUsed = min(startGas - gasleft() + REFUND_BASE_GAS, MAX_REFUND_GAS_USED); uint256 refundAmount = min(gasPrice * gasUsed, balance); (bool refundSent, ) = msg.sender.call{ value: refundAmount }(''); emit RefundableVote(msg.sender, refundAmount, refundSent); } } /** * @notice Internal function that returns the snapshot block number to use given a proposalId. The choice is * between the proposal's creation block and the proposal's voting start block, to allow a smooth migration from * creation block to start block. * @param proposalId The id of the proposal being voted on * @param proposal The proposal storage reference, used to read `creationBlock` and `startBlock` */ function proposalVoteSnapshotBlock( NounsDAOStorageV3.StorageV3 storage ds, uint256 proposalId, NounsDAOStorageV3.Proposal storage proposal ) internal view returns (uint256) { // The idea is to temporarily use this code that would still use `creationBlock` until all proposals are using // `startBlock`, then we can deploy a quick DAO fix that removes this line and only uses `startBlock`. // In that version upgrade we can also zero-out and remove this storage variable for max cleanup. uint256 voteSnapshotBlockSwitchProposalId = ds.voteSnapshotBlockSwitchProposalId; if (proposalId < voteSnapshotBlockSwitchProposalId || voteSnapshotBlockSwitchProposalId == 0) { return proposal.creationBlock; } return proposal.startBlock; } function min(uint256 a, uint256 b) internal pure returns (uint256) { return a < b ? a : b; } }
// 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: 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: BSD-3-Clause pragma solidity ^0.8.19; contract NounsDAOEventsFork { /// @notice An event emitted when a new proposal is created event ProposalCreated( uint256 indexed id, address indexed 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 indexed id, address indexed 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 indexed proposalId, uint8 support, uint256 votes, string reason); /// @notice An event emitted when a proposal has been canceled event ProposalCanceled(uint256 indexed id); /// @notice An event emitted when a proposal has been queued in the NounsDAOExecutor event ProposalQueued(uint256 indexed id, uint256 eta); /// @notice An event emitted when a proposal has been executed in the NounsDAOExecutor event ProposalExecuted(uint256 indexed 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 indexed oldPendingAdmin, address indexed newPendingAdmin); /// @notice Emitted when pendingAdmin is accepted, which means admin is updated event NewAdmin(address indexed oldAdmin, address indexed newAdmin); }
// SPDX-License-Identifier: BSD-3-Clause pragma solidity ^0.8.19; import { NounsDAOExecutorV2 } from '../../../NounsDAOExecutorV2.sol'; import { INounsTokenForkLike } from './INounsTokenForkLike.sol'; /** * @title Storage for `NounsDAOLogicV1Fork`. * @dev Based on NounsDAOStorageV1, with the following changes: * - vetoer is removed. * - Vetoed proposal state removed. * - implementation is removed, instead it's stored in the ERC-1967 storage slot. * - proposals renamed to _proposals to enable the explicit getter, which solves the stack too deep issue with the * default getter. * - creationBlock added to Proposal struct, similar to V2, to solve the votingDelay editing bug. * @notice For future upgrades, do not change NounsDAOStorageV1Fork. Create a new * contract which implements NounsDAOStorageV1Fork. */ contract NounsDAOStorageV1Fork { /// @notice Administrator for this contract address public admin; /// @notice Pending administrator for this contract address public pendingAdmin; /// @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 to exceed 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 NounsDAOExecutorV2 public timelock; /// @notice The address of the Nouns tokens INounsTokenForkLike 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; uint256 public delayedGovernanceExpirationTimestamp; address[] public erc20TokensToIncludeInQuit; 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 executed bool executed; /// @notice Receipts of ballots for the entire set of voters mapping(address => Receipt) receipts; /// @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 } 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 executed bool executed; /// @notice The block at which this proposal was created uint256 creationBlock; } }
// SPDX-License-Identifier: BSD-3-Clause pragma solidity ^0.8.19; interface INounsTokenForkLike { 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 balanceOf(address owner) external view returns (uint256 balance); function ownerOf(uint256 tokenId) external view returns (address owner); function remainingTokensToClaim() external view returns (uint256); function forkingPeriodEndTimestamp() external view returns (uint256); }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.0 (access/Ownable.sol) pragma solidity ^0.8.0; import "../utils/Context.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 Ownable is Context { address private _owner; event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); /** * @dev Initializes the contract setting the deployer as the initial owner. */ constructor() { _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); } }
// SPDX-License-Identifier: BSD-3-Clause /// @title Vote checkpointing for an ERC-721 token /********************************* * ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ * * ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ * * ░░░░░░█████████░░█████████░░░ * * ░░░░░░██░░░████░░██░░░████░░░ * * ░░██████░░░████████░░░████░░░ * * ░░██░░██░░░████░░██░░░████░░░ * * ░░██░░██░░░████░░██░░░████░░░ * * ░░░░░░█████████░░█████████░░░ * * ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ * * ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ * *********************************/ // LICENSE // 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 // // 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.6; import './ERC721Enumerable.sol'; abstract contract ERC721Checkpointable is ERC721Enumerable { /// @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 { bytes32 domainSeparator = keccak256( abi.encode(DOMAIN_TYPEHASH, keccak256(bytes(name())), getChainId(), 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; } function getChainId() internal view returns (uint256) { uint256 chainId; assembly { chainId := chainid() } return chainId; } }
// SPDX-License-Identifier: MIT /// @title ERC721 Token Implementation /********************************* * ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ * * ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ * * ░░░░░░█████████░░█████████░░░ * * ░░░░░░██░░░████░░██░░░████░░░ * * ░░██████░░░████████░░░████░░░ * * ░░██░░██░░░████░░██░░░████░░░ * * ░░██░░██░░░████░░██░░░████░░░ * * ░░░░░░█████████░░█████████░░░ * * ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ * * ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ * *********************************/ // LICENSE // ERC721.sol modifies OpenZeppelin's ERC721.sol: // https://github.com/OpenZeppelin/openzeppelin-contracts/blob/6618f9f18424ade44116d0221719f4c93be6a078/contracts/token/ERC721/ERC721.sol // // ERC721.sol source code copyright OpenZeppelin licensed under the MIT License. // With modifications by Nounders DAO. // // // MODIFICATIONS: // `_safeMint` and `_mint` contain an additional `creator` argument and // emit two `Transfer` logs, rather than one. The first log displays the // transfer (mint) from `address(0)` to the `creator`. The second displays the // transfer from the `creator` to the `to` address. This enables correct // attribution on various NFT marketplaces. pragma solidity ^0.8.6; import '@openzeppelin/contracts/token/ERC721/IERC721.sol'; import '@openzeppelin/contracts/token/ERC721/IERC721Receiver.sol'; import '@openzeppelin/contracts/token/ERC721/extensions/IERC721Metadata.sol'; import '@openzeppelin/contracts/utils/Address.sol'; import '@openzeppelin/contracts/utils/Context.sol'; import '@openzeppelin/contracts/utils/Strings.sol'; import '@openzeppelin/contracts/utils/introspection/ERC165.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 ERC721 is Context, ERC165, IERC721, IERC721Metadata { using Address for address; using Strings 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. */ constructor(string memory name_, string memory symbol_) { _name = name_; _symbol = symbol_; } /** * @dev See {IERC165-supportsInterface}. */ function supportsInterface(bytes4 interfaceId) public view virtual override(ERC165, IERC165) returns (bool) { return interfaceId == type(IERC721).interfaceId || interfaceId == type(IERC721Metadata).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 = ERC721.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 { require(operator != _msgSender(), 'ERC721: approve to caller'); _operatorApprovals[_msgSender()][operator] = approved; emit ApprovalForAll(_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 = ERC721.ownerOf(tokenId); return (spender == owner || getApproved(tokenId) == spender || isApprovedForAll(owner, spender)); } /** * @dev Safely mints `tokenId`, transfers it to `to`, and emits two log events - * 1. Credits the `minter` with the mint. * 2. Shows transfer from the `minter` 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 creator, address to, uint256 tokenId ) internal virtual { _safeMint(creator, 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 creator, address to, uint256 tokenId, bytes memory _data ) internal virtual { _mint(creator, to, tokenId); require( _checkOnERC721Received(address(0), to, tokenId, _data), 'ERC721: transfer to non ERC721Receiver implementer' ); } /** * @dev Mints `tokenId`, transfers it to `to`, and emits two log events - * 1. Credits the `creator` with the mint. * 2. Shows transfer from the `creator` 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 creator, 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), creator, tokenId); emit Transfer(creator, 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 = ERC721.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(ERC721.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(ERC721.ownerOf(tokenId), to, tokenId); } /** * @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 IERC721Receiver(to).onERC721Received(_msgSender(), from, tokenId, _data) returns (bytes4 retval) { return retval == IERC721Receiver(to).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 {} }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.6; interface IProxyRegistry { function proxies(address) external view returns (address); }
// 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/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: 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 (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 (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 (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 (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/Context.sol) pragma solidity ^0.8.0; /** * @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 Context { function _msgSender() internal view virtual returns (address) { return msg.sender; } function _msgData() internal view virtual returns (bytes calldata) { return msg.data; } }
// SPDX-License-Identifier: MIT /// @title ERC721 Enumerable Extension /********************************* * ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ * * ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ * * ░░░░░░█████████░░█████████░░░ * * ░░░░░░██░░░████░░██░░░████░░░ * * ░░██████░░░████████░░░████░░░ * * ░░██░░██░░░████░░██░░░████░░░ * * ░░██░░██░░░████░░██░░░████░░░ * * ░░░░░░█████████░░█████████░░░ * * ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ * * ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ * *********************************/ // LICENSE // ERC721.sol modifies OpenZeppelin's ERC721Enumerable.sol: // https://github.com/OpenZeppelin/openzeppelin-contracts/blob/6618f9f18424ade44116d0221719f4c93be6a078/contracts/token/ERC721/extensions/ERC721Enumerable.sol // // ERC721Enumerable.sol source code copyright OpenZeppelin licensed under the MIT License. // With modifications by Nounders DAO. // // MODIFICATIONS: // Consumes modified `ERC721` contract. See notes in `ERC721.sol`. pragma solidity ^0.8.0; import './ERC721.sol'; import '@openzeppelin/contracts/token/ERC721/extensions/IERC721Enumerable.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 ERC721Enumerable is ERC721, IERC721Enumerable { // 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(IERC165, ERC721) returns (bool) { return interfaceId == type(IERC721Enumerable).interfaceId || super.supportsInterface(interfaceId); } /** * @dev See {IERC721Enumerable-tokenOfOwnerByIndex}. */ function tokenOfOwnerByIndex(address owner, uint256 index) public view virtual override returns (uint256) { require(index < ERC721.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 < ERC721Enumerable.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 = ERC721.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 = ERC721.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(); } }
// 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 IERC721Receiver { /** * @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 "../IERC721.sol"; /** * @title ERC-721 Non-Fungible Token Standard, optional metadata extension * @dev See https://eips.ethereum.org/EIPS/eip-721 */ interface IERC721Metadata is IERC721 { /** * @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/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 (utils/introspection/ERC165.sol) pragma solidity ^0.8.0; import "./IERC165.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 ERC165 is IERC165 { /** * @dev See {IERC165-supportsInterface}. */ function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) { return interfaceId == type(IERC165).interfaceId; } }
// 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 (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 (token/ERC721/extensions/IERC721Enumerable.sol) pragma solidity ^0.8.0; import "../IERC721.sol"; /** * @title ERC-721 Non-Fungible Token Standard, optional enumeration extension * @dev See https://eips.ethereum.org/EIPS/eip-721 */ interface IERC721Enumerable is IERC721 { /** * @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 (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": [ "@ensdomains/=/Users/david/projects/crypto/nouns/dao-logic-v3/nouns-monorepo/node_modules/@ensdomains/", "@graphprotocol/=/Users/david/projects/crypto/nouns/dao-logic-v3/nouns-monorepo/node_modules/@graphprotocol/", "@nouns/=/Users/david/projects/crypto/nouns/dao-logic-v3/nouns-monorepo/node_modules/@nouns/", "@openzeppelin/=/Users/david/projects/crypto/nouns/dao-logic-v3/nouns-monorepo/node_modules/@openzeppelin/", "base64-sol/=/Users/david/projects/crypto/nouns/dao-logic-v3/nouns-monorepo/node_modules/base64-sol/", "ds-test/=lib/forge-std/lib/ds-test/src/", "eth-gas-reporter/=/Users/david/projects/crypto/nouns/dao-logic-v3/nouns-monorepo/node_modules/eth-gas-reporter/", "forge-std/=lib/forge-std/src/", "hardhat/=/Users/david/projects/crypto/nouns/dao-logic-v3/nouns-monorepo/node_modules/hardhat/", "truffle/=/Users/david/projects/crypto/nouns/dao-logic-v3/nouns-monorepo/node_modules/@graphprotocol/graph-cli/examples/basic-event-handlers/node_modules/truffle/", "lib/forge-std:ds-test/=lib/forge-std/lib/ds-test/src/" ], "optimizer": { "enabled": true, "runs": 200 }, "metadata": { "useLiteralContent": false, "bytecodeHash": "ipfs", "appendCBOR": true }, "outputSelection": { "*": { "*": [ "evm.bytecode", "evm.deployedBytecode", "devdoc", "userdoc", "metadata", "abi" ] } }, "evmVersion": "paris", "libraries": { "contracts/governance/NounsDAOV3Admin.sol": { "NounsDAOV3Admin": "0x3021e4a38e506546dc5dcf3bdb68cc5c049cd592" }, "contracts/governance/NounsDAOV3DynamicQuorum.sol": { "NounsDAOV3DynamicQuorum": "0x7e348c4288c7eaa1b0e63e1d0c055bfac04babbf" }, "contracts/governance/NounsDAOV3Proposals.sol": { "NounsDAOV3Proposals": "0x92b9adb33886f6cfcc0a763505a1bdf8708b96ed" }, "contracts/governance/NounsDAOV3Votes.sol": { "NounsDAOV3Votes": "0xe5bdc2badaf03a716c8559c8ef274c82df29d0f5" }, "contracts/governance/fork/NounsDAOV3Fork.sol": { "NounsDAOV3Fork": "0x34761eb1bda821ed7b30b51d7fbabbe18fd7574b" } } }
Contract Security Audit
- No Contract Security Audit Submitted- Submit Audit Here
[{"inputs":[{"internalType":"address","name":"tokenImpl_","type":"address"},{"internalType":"address","name":"auctionImpl_","type":"address"},{"internalType":"address","name":"governorImpl_","type":"address"},{"internalType":"address","name":"treasuryImpl_","type":"address"},{"internalType":"uint256","name":"delayedGovernanceMaxDuration_","type":"uint256"},{"internalType":"uint256","name":"initialVotingPeriod_","type":"uint256"},{"internalType":"uint256","name":"initialVotingDelay_","type":"uint256"},{"internalType":"uint256","name":"initialProposalThresholdBPS_","type":"uint256"},{"internalType":"uint256","name":"initialQuorumVotesBPS_","type":"uint256"}],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"token","type":"address"},{"indexed":false,"internalType":"address","name":"auction","type":"address"},{"indexed":false,"internalType":"address","name":"governor","type":"address"},{"indexed":false,"internalType":"address","name":"treasury","type":"address"}],"name":"DAODeployed","type":"event"},{"inputs":[],"name":"auctionImpl","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"delayedGovernanceMaxDuration","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"forkingPeriodEndTimestamp","type":"uint256"},{"internalType":"contract INounsDAOForkEscrow","name":"forkEscrow","type":"address"}],"name":"deployForkDAO","outputs":[{"internalType":"address","name":"treasury","type":"address"},{"internalType":"address","name":"token","type":"address"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"governorImpl","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"initialProposalThresholdBPS","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"initialQuorumVotesBPS","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"initialVotingDelay","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"initialVotingPeriod","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"tokenImpl","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"treasuryImpl","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"}]
Contract Creation Code
6101a060405234801561001157600080fd5b50604051620017a3380380620017a383398101604081905261003291610091565b6001600160a01b0398891660805296881660a05294871660e0529290951660c0526101005261012093909352610140929092526101609190915261018052610116565b80516001600160a01b038116811461008c57600080fd5b919050565b60008060008060008060008060006101208a8c0312156100b057600080fd5b6100b98a610075565b98506100c760208b01610075565b97506100d560408b01610075565b96506100e360608b01610075565b955060808a0151945060a08a0151935060c08a0151925060e08a015191506101008a015190509295985092959850929598565b60805160a05160c05160e05161010051610120516101405161016051610180516115df620001c46000396000818160fb0152610c270152600081816101aa0152610c060152600081816101d20152610be50152600081816101fa0152610bc401526000818161015a0152610cb501526000818160b6015261033b015260008181610182015261039601526000818161013201526102de01526000818161025a015261028101526115df6000f3fe60806040523480156200001157600080fd5b5060043610620000ab5760003560e01c80636291ada6116200006e5780636291ada614620001a4578063b478513914620001cc578063cdc409bc14620001f4578063fb146943146200021c578063ffc4992f146200025457600080fd5b8063264aa22a14620000b05780633baae2e014620000f5578063428eb538146200012c5780634d2fc98814620001545780634dfbbdaa146200017c575b600080fd5b620000d87f000000000000000000000000000000000000000000000000000000000000000081565b6040516001600160a01b0390911681526020015b60405180910390f35b6200011d7f000000000000000000000000000000000000000000000000000000000000000081565b604051908152602001620000ec565b620000d87f000000000000000000000000000000000000000000000000000000000000000081565b6200011d7f000000000000000000000000000000000000000000000000000000000000000081565b620000d87f000000000000000000000000000000000000000000000000000000000000000081565b6200011d7f000000000000000000000000000000000000000000000000000000000000000081565b6200011d7f000000000000000000000000000000000000000000000000000000000000000081565b6200011d7f000000000000000000000000000000000000000000000000000000000000000081565b620002336200022d36600462000d62565b6200027c565b604080516001600160a01b03938416815292909116602083015201620000ec565b620000d87f000000000000000000000000000000000000000000000000000000000000000081565b6000807f0000000000000000000000000000000000000000000000000000000000000000604051620002ae9062000d3b565b620002ba919062000d95565b604051809103906000f080158015620002d7573d6000803e3d6000fd5b50905060007f00000000000000000000000000000000000000000000000000000000000000006040516200030b9062000d3b565b62000317919062000d95565b604051809103906000f08015801562000334573d6000803e3d6000fd5b50905060007f0000000000000000000000000000000000000000000000000000000000000000604051620003689062000d3b565b62000374919062000d95565b604051809103906000f08015801562000391573d6000803e3d6000fd5b5090507f0000000000000000000000000000000000000000000000000000000000000000604051620003c39062000d3b565b620003cf919062000d95565b604051809103906000f080158015620003ec573d6000803e3d6000fd5b5093506000620003fc8662000954565b905060006200040b8762000a2a565b9050846001600160a01b031663d6e9fe4687868a8b6001600160a01b031663d7e53db06040518163ffffffff1660e01b8152600401602060405180830381865afa1580156200045e573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019062000484919062000db8565b6200048f8862000ad3565b8d6001600160a01b031663aa34213b6040518163ffffffff1660e01b8152600401602060405180830381865afa158015620004ce573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190620004f4919062000de0565b6040516001600160e01b031960e089901b1681526001600160a01b039687166004820152948616602486015294909216604484015263ffffffff166064830152608482015260a481019190915260c481018b905260e401600060405180830381600087803b1580156200056657600080fd5b505af11580156200057b573d6000803e3d6000fd5b50505050836001600160a01b03166360fca2598787856001600160a01b0316633fc8cef36040518163ffffffff1660e01b8152600401602060405180830381865afa158015620005cf573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190620005f5919062000e0c565b866001600160a01b031663ec91f2a46040518163ffffffff1660e01b8152600401602060405180830381865afa15801562000634573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906200065a919062000de0565b876001600160a01b031663db2e1eed6040518163ffffffff1660e01b8152600401602060405180830381865afa15801562000699573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190620006bf919062000de0565b886001600160a01b031663b296024d6040518163ffffffff1660e01b8152600401602060405180830381865afa158015620006fe573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019062000724919062000e2c565b896001600160a01b0316630fb5a6b46040518163ffffffff1660e01b8152600401602060405180830381865afa15801562000763573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019062000789919062000de0565b6040516001600160e01b031960e08a901b1681526001600160a01b03978816600482015295871660248701529590931660448501526064840191909152608483015260ff1660a482015260c481019190915260e401600060405180830381600087803b158015620007f957600080fd5b505af11580156200080e573d6000803e3d6000fd5b50505050620008208387878462000b48565b856001600160a01b031663cd6dc68784836001600160a01b0316636a42b8f86040518163ffffffff1660e01b8152600401602060405180830381865afa1580156200086f573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019062000895919062000de0565b6040516001600160e01b031960e085901b1681526001600160a01b0390921660048301526024820152604401600060405180830381600087803b158015620008dc57600080fd5b505af1158015620008f1573d6000803e3d6000fd5b5050604080516001600160a01b0389811682528881166020830152878116828401528a16606082015290517ff11e5aab072e2cc757196bc832963c0379cd33b72bc31255118228d22aaa76909350908190036080019150a1505050509250929050565b600080826001600160a01b031663ced9481f6040518163ffffffff1660e01b8152600401602060405180830381865afa15801562000996573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190620009bc919062000e0c565b9050806001600160a01b031663075461726040518163ffffffff1660e01b8152600401602060405180830381865afa158015620009fd573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019062000a23919062000e0c565b9392505050565b600080826001600160a01b031663ced9481f6040518163ffffffff1660e01b8152600401602060405180830381865afa15801562000a6c573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019062000a92919062000e0c565b9050806001600160a01b0316638da5cb5b6040518163ffffffff1660e01b8152600401602060405180830381865afa158015620009fd573d6000803e3d6000fd5b600080826001600160a01b0316637d9f6db56040518163ffffffff1660e01b815260040160c060405180830381865afa15801562000b15573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019062000b3b919062000e51565b5093979650505050505050565b6000816001600160a01b031663f851a4406040518163ffffffff1660e01b8152600401602060405180830381865afa15801562000b89573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019062000baf919062000e0c565b9050846001600160a01b031663f56ac09c85857f00000000000000000000000000000000000000000000000000000000000000007f00000000000000000000000000000000000000000000000000000000000000007f00000000000000000000000000000000000000000000000000000000000000007f0000000000000000000000000000000000000000000000000000000000000000886001600160a01b031663c37522d46040518163ffffffff1660e01b8152600401600060405180830381865afa15801562000c85573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f1916820160405262000caf919081019062000ecf565b62000cdb7f00000000000000000000000000000000000000000000000000000000000000004262000fa2565b6040518963ffffffff1660e01b815260040162000d0098979695949392919062000fca565b600060405180830381600087803b15801562000d1b57600080fd5b505af115801562000d30573d6000803e3d6000fd5b505050505050505050565b610552806200105883390190565b6001600160a01b038116811462000d5f57600080fd5b50565b6000806040838503121562000d7657600080fd5b82359150602083013562000d8a8162000d49565b809150509250929050565b6001600160a01b0391909116815260406020820181905260009082015260600190565b60006020828403121562000dcb57600080fd5b815163ffffffff8116811462000a2357600080fd5b60006020828403121562000df357600080fd5b5051919050565b805162000e078162000d49565b919050565b60006020828403121562000e1f57600080fd5b815162000a238162000d49565b60006020828403121562000e3f57600080fd5b815160ff8116811462000a2357600080fd5b60008060008060008060c0878903121562000e6b57600080fd5b86519550602087015194506040870151935060608701519250608087015162000e948162000d49565b60a0880151909250801515811462000eab57600080fd5b809150509295509295509295565b634e487b7160e01b600052604160045260246000fd5b6000602080838503121562000ee357600080fd5b825167ffffffffffffffff8082111562000efc57600080fd5b818501915085601f83011262000f1157600080fd5b81518181111562000f265762000f2662000eb9565b8060051b604051601f19603f8301168101818110858211171562000f4e5762000f4e62000eb9565b60405291825284820192508381018501918883111562000f6d57600080fd5b938501935b8285101562000f965762000f868562000dfa565b8452938501939285019262000f72565b98975050505050505050565b8082018082111562000fc457634e487b7160e01b600052601160045260246000fd5b92915050565b600061010080830160018060a01b03808d1685526020818d16818701528b60408701528a60608701528960808701528860a08701528360c0870152829350875180845261012087019450818901935060005b818110156200103c5784518416865294820194938201936001016200101c565b505050505060e092909201929092529897505050505050505056fe6080604052604051610552380380610552833981016040819052610022916102f8565b61004d60017f360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbd6103c6565b60008051602061050b83398151915214610069576100696103e7565b6100758282600061007c565b505061044c565b610085836100a8565b6000825111806100925750805b156100a3576100a183836100e8565b505b505050565b6100b181610116565b6040516001600160a01b038216907fbc7cd75a20ee27fd9adebab32041f755214dbc6bffa90cc0225b39da2e5c2d3b90600090a250565b606061010d838360405180606001604052806027815260200161052b602791396101ae565b90505b92915050565b803b61017f5760405162461bcd60e51b815260206004820152602d60248201527f455243313936373a206e657720696d706c656d656e746174696f6e206973206e60448201526c1bdd08184818dbdb9d1c9858dd609a1b60648201526084015b60405180910390fd5b60008051602061050b83398151915280546001600160a01b0319166001600160a01b0392909216919091179055565b6060833b61020d5760405162461bcd60e51b815260206004820152602660248201527f416464726573733a2064656c65676174652063616c6c20746f206e6f6e2d636f6044820152651b9d1c9858dd60d21b6064820152608401610176565b600080856001600160a01b03168560405161022891906103fd565b600060405180830381855af49150503d8060008114610263576040519150601f19603f3d011682016040523d82523d6000602084013e610268565b606091505b509092509050610279828286610285565b925050505b9392505050565b6060831561029457508161027e565b8251156102a45782518084602001fd5b8160405162461bcd60e51b81526004016101769190610419565b634e487b7160e01b600052604160045260246000fd5b60005b838110156102ef5781810151838201526020016102d7565b50506000910152565b6000806040838503121561030b57600080fd5b82516001600160a01b038116811461032257600080fd5b60208401519092506001600160401b038082111561033f57600080fd5b818501915085601f83011261035357600080fd5b815181811115610365576103656102be565b604051601f8201601f19908116603f0116810190838211818310171561038d5761038d6102be565b816040528281528860208487010111156103a657600080fd5b6103b78360208301602088016102d4565b80955050505050509250929050565b8181038181111561011057634e487b7160e01b600052601160045260246000fd5b634e487b7160e01b600052600160045260246000fd5b6000825161040f8184602087016102d4565b9190910192915050565b60208152600082518060208401526104388160408501602087016102d4565b601f01601f19169190910160400192915050565b60b18061045a6000396000f3fe608060405236601057600e6013565b005b600e5b601f601b6021565b6058565b565b600060537f360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc546001600160a01b031690565b905090565b3660008037600080366000845af43d6000803e8080156076573d6000f35b3d6000fdfea2646970667358221220d9d7907b53c6b009717389b1f8798be8d405eaefda31e63dde2ed39a8af9c94964736f6c63430008130033360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc416464726573733a206c6f772d6c6576656c2064656c65676174652063616c6c206661696c6564a26469706673582212207b98473acfde043371fbc944391bdcb1646fc3311a2057815c2623c93b2e8e6264736f6c63430008130033000000000000000000000000b78be3f66801a51df12a9b90289fa667af33fb81000000000000000000000000430b2fa7219631475df514c348284a6df60ed595000000000000000000000000c2fdade21b35c9e84b7cc6155b1a2774f622e5730000000000000000000000000fb7cf84f171154cbc3f553aa9df9b0e9076649d0000000000000000000000000000000000000000000000000000000000278d000000000000000000000000000000000000000000000000000000000000008ca00000000000000000000000000000000000000000000000000000000000008ca0000000000000000000000000000000000000000000000000000000000000001900000000000000000000000000000000000000000000000000000000000003e8
Deployed Bytecode
0x60806040523480156200001157600080fd5b5060043610620000ab5760003560e01c80636291ada6116200006e5780636291ada614620001a4578063b478513914620001cc578063cdc409bc14620001f4578063fb146943146200021c578063ffc4992f146200025457600080fd5b8063264aa22a14620000b05780633baae2e014620000f5578063428eb538146200012c5780634d2fc98814620001545780634dfbbdaa146200017c575b600080fd5b620000d87f000000000000000000000000c2fdade21b35c9e84b7cc6155b1a2774f622e57381565b6040516001600160a01b0390911681526020015b60405180910390f35b6200011d7f00000000000000000000000000000000000000000000000000000000000003e881565b604051908152602001620000ec565b620000d87f000000000000000000000000430b2fa7219631475df514c348284a6df60ed59581565b6200011d7f0000000000000000000000000000000000000000000000000000000000278d0081565b620000d87f0000000000000000000000000fb7cf84f171154cbc3f553aa9df9b0e9076649d81565b6200011d7f000000000000000000000000000000000000000000000000000000000000001981565b6200011d7f0000000000000000000000000000000000000000000000000000000000008ca081565b6200011d7f0000000000000000000000000000000000000000000000000000000000008ca081565b620002336200022d36600462000d62565b6200027c565b604080516001600160a01b03938416815292909116602083015201620000ec565b620000d87f000000000000000000000000b78be3f66801a51df12a9b90289fa667af33fb8181565b6000807f000000000000000000000000b78be3f66801a51df12a9b90289fa667af33fb81604051620002ae9062000d3b565b620002ba919062000d95565b604051809103906000f080158015620002d7573d6000803e3d6000fd5b50905060007f000000000000000000000000430b2fa7219631475df514c348284a6df60ed5956040516200030b9062000d3b565b62000317919062000d95565b604051809103906000f08015801562000334573d6000803e3d6000fd5b50905060007f000000000000000000000000c2fdade21b35c9e84b7cc6155b1a2774f622e573604051620003689062000d3b565b62000374919062000d95565b604051809103906000f08015801562000391573d6000803e3d6000fd5b5090507f0000000000000000000000000fb7cf84f171154cbc3f553aa9df9b0e9076649d604051620003c39062000d3b565b620003cf919062000d95565b604051809103906000f080158015620003ec573d6000803e3d6000fd5b5093506000620003fc8662000954565b905060006200040b8762000a2a565b9050846001600160a01b031663d6e9fe4687868a8b6001600160a01b031663d7e53db06040518163ffffffff1660e01b8152600401602060405180830381865afa1580156200045e573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019062000484919062000db8565b6200048f8862000ad3565b8d6001600160a01b031663aa34213b6040518163ffffffff1660e01b8152600401602060405180830381865afa158015620004ce573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190620004f4919062000de0565b6040516001600160e01b031960e089901b1681526001600160a01b039687166004820152948616602486015294909216604484015263ffffffff166064830152608482015260a481019190915260c481018b905260e401600060405180830381600087803b1580156200056657600080fd5b505af11580156200057b573d6000803e3d6000fd5b50505050836001600160a01b03166360fca2598787856001600160a01b0316633fc8cef36040518163ffffffff1660e01b8152600401602060405180830381865afa158015620005cf573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190620005f5919062000e0c565b866001600160a01b031663ec91f2a46040518163ffffffff1660e01b8152600401602060405180830381865afa15801562000634573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906200065a919062000de0565b876001600160a01b031663db2e1eed6040518163ffffffff1660e01b8152600401602060405180830381865afa15801562000699573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190620006bf919062000de0565b886001600160a01b031663b296024d6040518163ffffffff1660e01b8152600401602060405180830381865afa158015620006fe573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019062000724919062000e2c565b896001600160a01b0316630fb5a6b46040518163ffffffff1660e01b8152600401602060405180830381865afa15801562000763573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019062000789919062000de0565b6040516001600160e01b031960e08a901b1681526001600160a01b03978816600482015295871660248701529590931660448501526064840191909152608483015260ff1660a482015260c481019190915260e401600060405180830381600087803b158015620007f957600080fd5b505af11580156200080e573d6000803e3d6000fd5b50505050620008208387878462000b48565b856001600160a01b031663cd6dc68784836001600160a01b0316636a42b8f86040518163ffffffff1660e01b8152600401602060405180830381865afa1580156200086f573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019062000895919062000de0565b6040516001600160e01b031960e085901b1681526001600160a01b0390921660048301526024820152604401600060405180830381600087803b158015620008dc57600080fd5b505af1158015620008f1573d6000803e3d6000fd5b5050604080516001600160a01b0389811682528881166020830152878116828401528a16606082015290517ff11e5aab072e2cc757196bc832963c0379cd33b72bc31255118228d22aaa76909350908190036080019150a1505050509250929050565b600080826001600160a01b031663ced9481f6040518163ffffffff1660e01b8152600401602060405180830381865afa15801562000996573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190620009bc919062000e0c565b9050806001600160a01b031663075461726040518163ffffffff1660e01b8152600401602060405180830381865afa158015620009fd573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019062000a23919062000e0c565b9392505050565b600080826001600160a01b031663ced9481f6040518163ffffffff1660e01b8152600401602060405180830381865afa15801562000a6c573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019062000a92919062000e0c565b9050806001600160a01b0316638da5cb5b6040518163ffffffff1660e01b8152600401602060405180830381865afa158015620009fd573d6000803e3d6000fd5b600080826001600160a01b0316637d9f6db56040518163ffffffff1660e01b815260040160c060405180830381865afa15801562000b15573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019062000b3b919062000e51565b5093979650505050505050565b6000816001600160a01b031663f851a4406040518163ffffffff1660e01b8152600401602060405180830381865afa15801562000b89573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019062000baf919062000e0c565b9050846001600160a01b031663f56ac09c85857f0000000000000000000000000000000000000000000000000000000000008ca07f0000000000000000000000000000000000000000000000000000000000008ca07f00000000000000000000000000000000000000000000000000000000000000197f00000000000000000000000000000000000000000000000000000000000003e8886001600160a01b031663c37522d46040518163ffffffff1660e01b8152600401600060405180830381865afa15801562000c85573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f1916820160405262000caf919081019062000ecf565b62000cdb7f0000000000000000000000000000000000000000000000000000000000278d004262000fa2565b6040518963ffffffff1660e01b815260040162000d0098979695949392919062000fca565b600060405180830381600087803b15801562000d1b57600080fd5b505af115801562000d30573d6000803e3d6000fd5b505050505050505050565b610552806200105883390190565b6001600160a01b038116811462000d5f57600080fd5b50565b6000806040838503121562000d7657600080fd5b82359150602083013562000d8a8162000d49565b809150509250929050565b6001600160a01b0391909116815260406020820181905260009082015260600190565b60006020828403121562000dcb57600080fd5b815163ffffffff8116811462000a2357600080fd5b60006020828403121562000df357600080fd5b5051919050565b805162000e078162000d49565b919050565b60006020828403121562000e1f57600080fd5b815162000a238162000d49565b60006020828403121562000e3f57600080fd5b815160ff8116811462000a2357600080fd5b60008060008060008060c0878903121562000e6b57600080fd5b86519550602087015194506040870151935060608701519250608087015162000e948162000d49565b60a0880151909250801515811462000eab57600080fd5b809150509295509295509295565b634e487b7160e01b600052604160045260246000fd5b6000602080838503121562000ee357600080fd5b825167ffffffffffffffff8082111562000efc57600080fd5b818501915085601f83011262000f1157600080fd5b81518181111562000f265762000f2662000eb9565b8060051b604051601f19603f8301168101818110858211171562000f4e5762000f4e62000eb9565b60405291825284820192508381018501918883111562000f6d57600080fd5b938501935b8285101562000f965762000f868562000dfa565b8452938501939285019262000f72565b98975050505050505050565b8082018082111562000fc457634e487b7160e01b600052601160045260246000fd5b92915050565b600061010080830160018060a01b03808d1685526020818d16818701528b60408701528a60608701528960808701528860a08701528360c0870152829350875180845261012087019450818901935060005b818110156200103c5784518416865294820194938201936001016200101c565b505050505060e092909201929092529897505050505050505056fe6080604052604051610552380380610552833981016040819052610022916102f8565b61004d60017f360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbd6103c6565b60008051602061050b83398151915214610069576100696103e7565b6100758282600061007c565b505061044c565b610085836100a8565b6000825111806100925750805b156100a3576100a183836100e8565b505b505050565b6100b181610116565b6040516001600160a01b038216907fbc7cd75a20ee27fd9adebab32041f755214dbc6bffa90cc0225b39da2e5c2d3b90600090a250565b606061010d838360405180606001604052806027815260200161052b602791396101ae565b90505b92915050565b803b61017f5760405162461bcd60e51b815260206004820152602d60248201527f455243313936373a206e657720696d706c656d656e746174696f6e206973206e60448201526c1bdd08184818dbdb9d1c9858dd609a1b60648201526084015b60405180910390fd5b60008051602061050b83398151915280546001600160a01b0319166001600160a01b0392909216919091179055565b6060833b61020d5760405162461bcd60e51b815260206004820152602660248201527f416464726573733a2064656c65676174652063616c6c20746f206e6f6e2d636f6044820152651b9d1c9858dd60d21b6064820152608401610176565b600080856001600160a01b03168560405161022891906103fd565b600060405180830381855af49150503d8060008114610263576040519150601f19603f3d011682016040523d82523d6000602084013e610268565b606091505b509092509050610279828286610285565b925050505b9392505050565b6060831561029457508161027e565b8251156102a45782518084602001fd5b8160405162461bcd60e51b81526004016101769190610419565b634e487b7160e01b600052604160045260246000fd5b60005b838110156102ef5781810151838201526020016102d7565b50506000910152565b6000806040838503121561030b57600080fd5b82516001600160a01b038116811461032257600080fd5b60208401519092506001600160401b038082111561033f57600080fd5b818501915085601f83011261035357600080fd5b815181811115610365576103656102be565b604051601f8201601f19908116603f0116810190838211818310171561038d5761038d6102be565b816040528281528860208487010111156103a657600080fd5b6103b78360208301602088016102d4565b80955050505050509250929050565b8181038181111561011057634e487b7160e01b600052601160045260246000fd5b634e487b7160e01b600052600160045260246000fd5b6000825161040f8184602087016102d4565b9190910192915050565b60208152600082518060208401526104388160408501602087016102d4565b601f01601f19169190910160400192915050565b60b18061045a6000396000f3fe608060405236601057600e6013565b005b600e5b601f601b6021565b6058565b565b600060537f360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc546001600160a01b031690565b905090565b3660008037600080366000845af43d6000803e8080156076573d6000f35b3d6000fdfea2646970667358221220d9d7907b53c6b009717389b1f8798be8d405eaefda31e63dde2ed39a8af9c94964736f6c63430008130033360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc416464726573733a206c6f772d6c6576656c2064656c65676174652063616c6c206661696c6564a26469706673582212207b98473acfde043371fbc944391bdcb1646fc3311a2057815c2623c93b2e8e6264736f6c63430008130033
Constructor Arguments (ABI-Encoded and is the last bytes of the Contract Creation Code above)
000000000000000000000000b78be3f66801a51df12a9b90289fa667af33fb81000000000000000000000000430b2fa7219631475df514c348284a6df60ed595000000000000000000000000c2fdade21b35c9e84b7cc6155b1a2774f622e5730000000000000000000000000fb7cf84f171154cbc3f553aa9df9b0e9076649d0000000000000000000000000000000000000000000000000000000000278d000000000000000000000000000000000000000000000000000000000000008ca00000000000000000000000000000000000000000000000000000000000008ca0000000000000000000000000000000000000000000000000000000000000001900000000000000000000000000000000000000000000000000000000000003e8
-----Decoded View---------------
Arg [0] : tokenImpl_ (address): 0xb78bE3f66801A51df12a9b90289fA667AF33fB81
Arg [1] : auctionImpl_ (address): 0x430b2FA7219631475df514C348284a6Df60Ed595
Arg [2] : governorImpl_ (address): 0xc2fDaDe21b35C9E84B7Cc6155b1a2774f622e573
Arg [3] : treasuryImpl_ (address): 0x0FB7CF84F171154cBC3F553aA9Df9b0e9076649D
Arg [4] : delayedGovernanceMaxDuration_ (uint256): 2592000
Arg [5] : initialVotingPeriod_ (uint256): 36000
Arg [6] : initialVotingDelay_ (uint256): 36000
Arg [7] : initialProposalThresholdBPS_ (uint256): 25
Arg [8] : initialQuorumVotesBPS_ (uint256): 1000
-----Encoded View---------------
9 Constructor Arguments found :
Arg [0] : 000000000000000000000000b78be3f66801a51df12a9b90289fa667af33fb81
Arg [1] : 000000000000000000000000430b2fa7219631475df514c348284a6df60ed595
Arg [2] : 000000000000000000000000c2fdade21b35c9e84b7cc6155b1a2774f622e573
Arg [3] : 0000000000000000000000000fb7cf84f171154cbc3f553aa9df9b0e9076649d
Arg [4] : 0000000000000000000000000000000000000000000000000000000000278d00
Arg [5] : 0000000000000000000000000000000000000000000000000000000000008ca0
Arg [6] : 0000000000000000000000000000000000000000000000000000000000008ca0
Arg [7] : 0000000000000000000000000000000000000000000000000000000000000019
Arg [8] : 00000000000000000000000000000000000000000000000000000000000003e8
Loading...
Loading
Loading...
Loading
Multichain Portfolio | 30 Chains
Chain | Token | Portfolio % | Price | Amount | Value |
---|
Loading...
Loading
[ Download: CSV Export ]
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.