{
  "language": "Solidity",
  "sources": {
    "contracts/Governance/GovernorBravoDelegate.sol": {
      "content": "pragma solidity ^0.5.16;\npragma experimental ABIEncoderV2;\n\nimport \"./GovernorBravoInterfaces.sol\";\n\n/**\n * @title GovernorBravoDelegate\n * @notice Venus Governance latest on chain governance includes several new features including variable proposal routes and fine grained pause control.\n * Variable routes for proposals allows for governance paramaters such as voting threshold and timelocks to be customized based on the risk level and\n * impact of the proposal. Added granularity to the pause control mechanism allows governance to pause individual actions on specific markets,\n * which reduces impact on the protocol as a whole. This is particularly useful when applied to isolated pools.\n *\n * The goal of **Governance** is to increase governance efficiency, while mitigating and eliminating malicious or erroneous proposals.\n *\n * ## Details\n *\n * Governance has **3 main contracts**: **GovernanceBravoDelegate, XVSVault, XVS** token.\n *\n * - XVS token is the protocol token used for protocol users to cast their vote on submitted proposals.\n * - XVSVault is the main staking contract for XVS. Users first stake their XVS in the vault and receive voting power proportional to their staked\n * tokens that they can use to vote on proposals. Users also can choose to delegate their voting power to other users.\n *\n * # Governor Bravo\n *\n * `GovernanceBravoDelegate` is main Venus Governance contract. Users interact with it to:\n * - Submit new proposal\n * - Vote on a proposal\n * - Cancel a proposal\n * - Queue a proposal for execution with a timelock executor contract.\n * `GovernanceBravoDelegate` uses the XVSVault to get restrict certain actions based on a user's voting power. The governance rules it inforces are:\n * - A user's voting power must be greater than the `proposalThreshold` to submit a proposal\n * - If a user's voting power drops below certain amount, anyone can cancel the the proposal. The governance guardian and proposal creator can also\n * cancel a proposal at anytime before it is queued for execution.\n *\n * ## Venus Improvement Proposal\n *\n * Venus Governance allows for Venus Improvement Proposals (VIPs) to be categorized based on their impact and risk levels. This allows for optimizing proposals\n * execution to allow for things such as expediting interest rate changes and quickly updating risk parameters, while moving slower on other types of proposals\n * that can prevent a larger risk to the protocol and are not urgent. There are three different types of VIPs with different proposal paramters:\n *\n * - `NORMAL`\n * - `FASTTRACK`\n * - `CRITICAL`\n *\n * When initializing the `GovernorBravo` contract, the parameters for the three routes are set. The parameters are:\n *\n * - `votingDelay`: The delay in blocks between submitting a proposal and when voting begins\n * - `votingPeriod`: The number of blocks where voting will be open\n * - `proposalThreshold`: The number of votes required in order submit a proposal\n *\n * There is also a separate timelock executor contract for each route, which is used to dispatch the VIP for execution, giving even more control over the\n * flow of each type of VIP.\n *\n * ## Voting\n *\n * After a VIP is proposed, voting is opened after the `votingDelay` has passed. For example, if `votingDelay = 0`, then voting will begin in the next block\n * after the proposal has been submitted. After the delay, the proposal state is `ACTIVE` and users can cast their vote `for`, `against`, or `abstain`,\n * weighted by their total voting power (tokens + delegated voting power). Abstaining from a voting allows for a vote to be cast and optionally include a\n * comment, without the incrementing for or against vote count. The total voting power for the user is obtained by calling XVSVault's `getPriorVotes`.\n *\n * `GovernorBravoDelegate` also accepts [EIP-712](https://eips.ethereum.org/EIPS/eip-712) signatures for voting on proposals via the external function\n * `castVoteBySig`.\n *\n * ## Delegating\n *\n * A users voting power includes the amount of staked XVS the have staked as well as the votes delegate to them. Delegating is the process of a user loaning\n * their voting power to another, so that the latter has the combined voting power of both users. This is an important feature because it allows for a user\n * to let another user who they trust propose or vote in their place.\n *\n * The delegation of votes happens through the `XVSVault` contract by calling the `delegate` or `delegateBySig` functions. These same functions can revert\n * vote delegation by calling the same function with a value of `0`.\n */\ncontract GovernorBravoDelegate is GovernorBravoDelegateStorageV3, GovernorBravoEvents {\n    /// @notice The name of this contract\n    string public constant name = \"Venus Governor Bravo\";\n\n    /// @notice The minimum setable proposal threshold\n    uint public constant MIN_PROPOSAL_THRESHOLD = 150000e18; // 150,000 Xvs\n\n    /// @notice The maximum setable proposal threshold\n    uint public constant MAX_PROPOSAL_THRESHOLD = 300000e18; //300,000 Xvs\n\n    /// @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\n    uint public constant quorumVotes = 600000e18; // 600,000 = 2% of Xvs\n\n    /// @notice The EIP-712 typehash for the contract's domain\n    bytes32 public constant DOMAIN_TYPEHASH =\n        keccak256(\"EIP712Domain(string name,uint256 chainId,address verifyingContract)\");\n\n    /// @notice The EIP-712 typehash for the ballot struct used by the contract\n    bytes32 public constant BALLOT_TYPEHASH = keccak256(\"Ballot(uint256 proposalId,uint8 support)\");\n\n    /**\n     * @notice Used to initialize the contract during delegator contructor\n     * @param xvsVault_ The address of the XvsVault\n     * @param proposalConfigs_ Governance configs for each governance route\n     * @param timelocks Timelock addresses for each governance route\n     */\n    function initialize(\n        address xvsVault_,\n        ValidationParams memory validationParams_,\n        ProposalConfig[] memory proposalConfigs_,\n        TimelockInterface[] memory timelocks,\n        address guardian_\n    ) public {\n        require(address(proposalTimelocks[0]) == address(0), \"GovernorBravo::initialize: cannot initialize twice\");\n        require(msg.sender == admin, \"GovernorBravo::initialize: admin only\");\n        require(xvsVault_ != address(0), \"GovernorBravo::initialize: invalid xvs vault address\");\n        require(guardian_ != address(0), \"GovernorBravo::initialize: invalid guardian\");\n        require(\n            timelocks.length == getGovernanceRouteCount(),\n            \"GovernorBravo::initialize:number of timelocks should match number of governance routes\"\n        );\n        require(\n            proposalConfigs_.length == getGovernanceRouteCount(),\n            \"GovernorBravo::initialize:number of proposal configs should match number of governance routes\"\n        );\n\n        xvsVault = XvsVaultInterface(xvsVault_);\n        proposalMaxOperations = 10;\n        guardian = guardian_;\n\n        // Set parameters for each Governance Route\n        setValidationParams(validationParams_);\n        setProposalConfigs(proposalConfigs_);\n\n        uint256 arrLength = timelocks.length;\n        for (uint256 i; i < arrLength; ++i) {\n            require(address(timelocks[i]) != address(0), \"GovernorBravo::initialize:invalid timelock address\");\n            proposalTimelocks[i] = timelocks[i];\n        }\n    }\n\n    /**\n     ** @notice Sets the validation parameters for voting delay and voting period\n     ** @param newValidationParams Struct containing new minimum and maximum voting period and delay\n     */\n    function setValidationParams(ValidationParams memory newValidationParams) public {\n        require(msg.sender == admin, \"GovernorBravo::setValidationParams: admin only\");\n        require(\n            newValidationParams.minVotingPeriod > 0 &&\n                newValidationParams.minVotingDelay > 0 &&\n                newValidationParams.minVotingDelay < newValidationParams.maxVotingDelay &&\n                newValidationParams.minVotingPeriod < newValidationParams.maxVotingPeriod,\n            \"GovernorBravo::setValidationParams: invalid params\"\n        );\n        emit SetValidationParams(\n            validationParams.minVotingPeriod,\n            newValidationParams.minVotingPeriod,\n            validationParams.maxVotingPeriod,\n            newValidationParams.maxVotingPeriod,\n            validationParams.minVotingDelay,\n            newValidationParams.minVotingDelay,\n            validationParams.maxVotingDelay,\n            newValidationParams.maxVotingDelay\n        );\n        validationParams = newValidationParams;\n    }\n\n    /**\n     ** @notice Sets the configuration for different proposal types\n     ** @dev Requires validationParams to be configured before also it will set proposal config for all proposal types\n     ** @param proposalConfigs_ Array of proposal configuration structs to update\n     */\n    function setProposalConfigs(ProposalConfig[] memory proposalConfigs_) public {\n        require(msg.sender == admin, \"GovernorBravo::setProposalConfigs: admin only\");\n        require(\n            validationParams.minVotingPeriod > 0 &&\n                validationParams.maxVotingPeriod > 0 &&\n                validationParams.minVotingDelay > 0 &&\n                validationParams.maxVotingDelay > 0,\n            \"GovernorBravo::setProposalConfigs: validation params not configured yet\"\n        );\n        uint256 arrLength = proposalConfigs_.length;\n        require(\n            arrLength == getGovernanceRouteCount(),\n            \"GovernorBravo::setProposalConfigs: invalid proposal config length\"\n        );\n        for (uint256 i; i < arrLength; ++i) {\n            require(\n                proposalConfigs_[i].votingPeriod >= validationParams.minVotingPeriod,\n                \"GovernorBravo::setProposalConfigs: invalid min voting period\"\n            );\n            require(\n                proposalConfigs_[i].votingPeriod <= validationParams.maxVotingPeriod,\n                \"GovernorBravo::setProposalConfigs: invalid max voting period\"\n            );\n            require(\n                proposalConfigs_[i].votingDelay >= validationParams.minVotingDelay,\n                \"GovernorBravo::setProposalConfigs: invalid min voting delay\"\n            );\n            require(\n                proposalConfigs_[i].votingDelay <= validationParams.maxVotingDelay,\n                \"GovernorBravo::setProposalConfigs: invalid max voting delay\"\n            );\n            require(\n                proposalConfigs_[i].proposalThreshold >= MIN_PROPOSAL_THRESHOLD,\n                \"GovernorBravo::setProposalConfigs: invalid min proposal threshold\"\n            );\n            require(\n                proposalConfigs_[i].proposalThreshold <= MAX_PROPOSAL_THRESHOLD,\n                \"GovernorBravo::setProposalConfigs: invalid max proposal threshold\"\n            );\n\n            proposalConfigs[i] = proposalConfigs_[i];\n            emit SetProposalConfigs(\n                proposalConfigs_[i].votingPeriod,\n                proposalConfigs_[i].votingDelay,\n                proposalConfigs_[i].proposalThreshold\n            );\n        }\n    }\n\n    /**\n     * @notice Function used to propose a new proposal. Sender must have delegates above the proposal threshold.\n     * targets, values, signatures, and calldatas must be of equal length\n     * @dev NOTE: Proposals with duplicate set of actions can not be queued for execution. If the proposals consists\n     *  of duplicate actions, it's recommended to split those actions into separate proposals\n     * @param targets Target addresses for proposal calls\n     * @param values BNB values for proposal calls\n     * @param signatures Function signatures for proposal calls\n     * @param calldatas Calldatas for proposal calls\n     * @param description String description of the proposal\n     * @param proposalType the type of the proposal (e.g NORMAL, FASTTRACK, CRITICAL)\n     * @return Proposal id of new proposal\n     */\n    function propose(\n        address[] memory targets,\n        uint[] memory values,\n        string[] memory signatures,\n        bytes[] memory calldatas,\n        string memory description,\n        ProposalType proposalType\n    ) public returns (uint) {\n        // Reject proposals before initiating as Governor\n        require(initialProposalId != 0, \"GovernorBravo::propose: Governor Bravo not active\");\n        require(\n            xvsVault.getPriorVotes(msg.sender, sub256(block.number, 1)) >=\n                proposalConfigs[uint8(proposalType)].proposalThreshold,\n            \"GovernorBravo::propose: proposer votes below proposal threshold\"\n        );\n        require(\n            targets.length == values.length &&\n                targets.length == signatures.length &&\n                targets.length == calldatas.length,\n            \"GovernorBravo::propose: proposal function information arity mismatch\"\n        );\n        require(targets.length != 0, \"GovernorBravo::propose: must provide actions\");\n        require(targets.length <= proposalMaxOperations, \"GovernorBravo::propose: too many actions\");\n\n        uint latestProposalId = latestProposalIds[msg.sender];\n        if (latestProposalId != 0) {\n            ProposalState proposersLatestProposalState = state(latestProposalId);\n            require(\n                proposersLatestProposalState != ProposalState.Active,\n                \"GovernorBravo::propose: one live proposal per proposer, found an already active proposal\"\n            );\n            require(\n                proposersLatestProposalState != ProposalState.Pending,\n                \"GovernorBravo::propose: one live proposal per proposer, found an already pending proposal\"\n            );\n        }\n\n        uint startBlock = add256(block.number, proposalConfigs[uint8(proposalType)].votingDelay);\n        uint endBlock = add256(startBlock, proposalConfigs[uint8(proposalType)].votingPeriod);\n\n        proposalCount++;\n        Proposal memory newProposal = Proposal({\n            id: proposalCount,\n            proposer: msg.sender,\n            eta: 0,\n            targets: targets,\n            values: values,\n            signatures: signatures,\n            calldatas: calldatas,\n            startBlock: startBlock,\n            endBlock: endBlock,\n            forVotes: 0,\n            againstVotes: 0,\n            abstainVotes: 0,\n            canceled: false,\n            executed: false,\n            proposalType: uint8(proposalType)\n        });\n\n        proposals[newProposal.id] = newProposal;\n        latestProposalIds[newProposal.proposer] = newProposal.id;\n\n        emit ProposalCreated(\n            newProposal.id,\n            msg.sender,\n            targets,\n            values,\n            signatures,\n            calldatas,\n            startBlock,\n            endBlock,\n            description,\n            uint8(proposalType)\n        );\n        return newProposal.id;\n    }\n\n    /**\n     * @notice Queues a proposal of state succeeded\n     * @param proposalId The id of the proposal to queue\n     */\n    function queue(uint proposalId) external {\n        require(\n            state(proposalId) == ProposalState.Succeeded,\n            \"GovernorBravo::queue: proposal can only be queued if it is succeeded\"\n        );\n        Proposal storage proposal = proposals[proposalId];\n        uint eta = add256(block.timestamp, proposalTimelocks[uint8(proposal.proposalType)].delay());\n        for (uint i; i < proposal.targets.length; ++i) {\n            queueOrRevertInternal(\n                proposal.targets[i],\n                proposal.values[i],\n                proposal.signatures[i],\n                proposal.calldatas[i],\n                eta,\n                uint8(proposal.proposalType)\n            );\n        }\n        proposal.eta = eta;\n        emit ProposalQueued(proposalId, eta);\n    }\n\n    function queueOrRevertInternal(\n        address target,\n        uint value,\n        string memory signature,\n        bytes memory data,\n        uint eta,\n        uint8 proposalType\n    ) internal {\n        require(\n            !proposalTimelocks[proposalType].queuedTransactions(\n                keccak256(abi.encode(target, value, signature, data, eta))\n            ),\n            \"GovernorBravo::queueOrRevertInternal: identical proposal action already queued at eta\"\n        );\n        proposalTimelocks[proposalType].queueTransaction(target, value, signature, data, eta);\n    }\n\n    /**\n     * @notice Executes a queued proposal if eta has passed\n     * @param proposalId The id of the proposal to execute\n     */\n    function execute(uint proposalId) external {\n        require(\n            state(proposalId) == ProposalState.Queued,\n            \"GovernorBravo::execute: proposal can only be executed if it is queued\"\n        );\n        Proposal storage proposal = proposals[proposalId];\n        proposal.executed = true;\n        for (uint i; i < proposal.targets.length; ++i) {\n            proposalTimelocks[uint8(proposal.proposalType)].executeTransaction(\n                proposal.targets[i],\n                proposal.values[i],\n                proposal.signatures[i],\n                proposal.calldatas[i],\n                proposal.eta\n            );\n        }\n        emit ProposalExecuted(proposalId);\n    }\n\n    /**\n     * @notice Cancels a proposal only if sender is the proposer, or proposer delegates dropped below proposal threshold\n     * @param proposalId The id of the proposal to cancel\n     */\n    function cancel(uint proposalId) external {\n        require(state(proposalId) != ProposalState.Executed, \"GovernorBravo::cancel: cannot cancel executed proposal\");\n\n        Proposal storage proposal = proposals[proposalId];\n        require(\n            msg.sender == guardian ||\n                msg.sender == proposal.proposer ||\n                xvsVault.getPriorVotes(proposal.proposer, sub256(block.number, 1)) <\n                proposalConfigs[proposal.proposalType].proposalThreshold,\n            \"GovernorBravo::cancel: proposer above threshold\"\n        );\n\n        proposal.canceled = true;\n        for (uint i = 0; i < proposal.targets.length; i++) {\n            proposalTimelocks[proposal.proposalType].cancelTransaction(\n                proposal.targets[i],\n                proposal.values[i],\n                proposal.signatures[i],\n                proposal.calldatas[i],\n                proposal.eta\n            );\n        }\n\n        emit ProposalCanceled(proposalId);\n    }\n\n    /**\n     * @notice Gets actions of a proposal\n     * @param proposalId the id of the proposal\n     * @return targets, values, signatures, and calldatas of the proposal actions\n     */\n    function getActions(\n        uint proposalId\n    )\n        external\n        view\n        returns (address[] memory targets, uint[] memory values, string[] memory signatures, bytes[] memory calldatas)\n    {\n        Proposal storage p = proposals[proposalId];\n        return (p.targets, p.values, p.signatures, p.calldatas);\n    }\n\n    /**\n     * @notice Gets the receipt for a voter on a given proposal\n     * @param proposalId the id of proposal\n     * @param voter The address of the voter\n     * @return The voting receipt\n     */\n    function getReceipt(uint proposalId, address voter) external view returns (Receipt memory) {\n        return proposals[proposalId].receipts[voter];\n    }\n\n    /**\n     * @notice Gets the state of a proposal\n     * @param proposalId The id of the proposal\n     * @return Proposal state\n     */\n    function state(uint proposalId) public view returns (ProposalState) {\n        require(\n            proposalCount >= proposalId && proposalId > initialProposalId,\n            \"GovernorBravo::state: invalid proposal id\"\n        );\n        Proposal storage proposal = proposals[proposalId];\n        if (proposal.canceled) {\n            return ProposalState.Canceled;\n        } else if (block.number <= proposal.startBlock) {\n            return ProposalState.Pending;\n        } else if (block.number <= proposal.endBlock) {\n            return ProposalState.Active;\n        } else if (proposal.forVotes <= proposal.againstVotes || proposal.forVotes < quorumVotes) {\n            return ProposalState.Defeated;\n        } else if (proposal.eta == 0) {\n            return ProposalState.Succeeded;\n        } else if (proposal.executed) {\n            return ProposalState.Executed;\n        } else if (\n            block.timestamp >= add256(proposal.eta, proposalTimelocks[uint8(proposal.proposalType)].GRACE_PERIOD())\n        ) {\n            return ProposalState.Expired;\n        } else {\n            return ProposalState.Queued;\n        }\n    }\n\n    /**\n     * @notice Cast a vote for a proposal\n     * @param proposalId The id of the proposal to vote on\n     * @param support The support value for the vote. 0=against, 1=for, 2=abstain\n     */\n    function castVote(uint proposalId, uint8 support) external {\n        emit VoteCast(msg.sender, proposalId, support, castVoteInternal(msg.sender, proposalId, support), \"\");\n    }\n\n    /**\n     * @notice Cast a vote for a proposal with a reason\n     * @param proposalId The id of the proposal to vote on\n     * @param support The support value for the vote. 0=against, 1=for, 2=abstain\n     * @param reason The reason given for the vote by the voter\n     */\n    function castVoteWithReason(uint proposalId, uint8 support, string calldata reason) external {\n        emit VoteCast(msg.sender, proposalId, support, castVoteInternal(msg.sender, proposalId, support), reason);\n    }\n\n    /**\n     * @notice Cast a vote for a proposal by signature\n     * @dev External function that accepts EIP-712 signatures for voting on proposals.\n     * @param proposalId The id of the proposal to vote on\n     * @param support The support value for the vote. 0=against, 1=for, 2=abstain\n     * @param v recovery id of ECDSA signature\n     * @param r part of the ECDSA sig output\n     * @param s part of the ECDSA sig output\n     */\n    function castVoteBySig(uint proposalId, uint8 support, uint8 v, bytes32 r, bytes32 s) external {\n        bytes32 domainSeparator = keccak256(\n            abi.encode(DOMAIN_TYPEHASH, keccak256(bytes(name)), getChainIdInternal(), address(this))\n        );\n        bytes32 structHash = keccak256(abi.encode(BALLOT_TYPEHASH, proposalId, support));\n        bytes32 digest = keccak256(abi.encodePacked(\"\\x19\\x01\", domainSeparator, structHash));\n        address signatory = ecrecover(digest, v, r, s);\n        require(signatory != address(0), \"GovernorBravo::castVoteBySig: invalid signature\");\n        emit VoteCast(signatory, proposalId, support, castVoteInternal(signatory, proposalId, support), \"\");\n    }\n\n    /**\n     * @notice Internal function that caries out voting logic\n     * @param voter The voter that is casting their vote\n     * @param proposalId The id of the proposal to vote on\n     * @param support The support value for the vote. 0=against, 1=for, 2=abstain\n     * @return The number of votes cast\n     */\n    function castVoteInternal(address voter, uint proposalId, uint8 support) internal returns (uint96) {\n        require(state(proposalId) == ProposalState.Active, \"GovernorBravo::castVoteInternal: voting is closed\");\n        require(support <= 2, \"GovernorBravo::castVoteInternal: invalid vote type\");\n        Proposal storage proposal = proposals[proposalId];\n        Receipt storage receipt = proposal.receipts[voter];\n        require(receipt.hasVoted == false, \"GovernorBravo::castVoteInternal: voter already voted\");\n        uint96 votes = xvsVault.getPriorVotes(voter, proposal.startBlock);\n\n        if (support == 0) {\n            proposal.againstVotes = add256(proposal.againstVotes, votes);\n        } else if (support == 1) {\n            proposal.forVotes = add256(proposal.forVotes, votes);\n        } else if (support == 2) {\n            proposal.abstainVotes = add256(proposal.abstainVotes, votes);\n        }\n\n        receipt.hasVoted = true;\n        receipt.support = support;\n        receipt.votes = votes;\n\n        return votes;\n    }\n\n    /**\n     * @notice Sets the new governance guardian\n     * @param newGuardian the address of the new guardian\n     */\n    function _setGuardian(address newGuardian) external {\n        require(msg.sender == guardian || msg.sender == admin, \"GovernorBravo::_setGuardian: admin or guardian only\");\n        require(newGuardian != address(0), \"GovernorBravo::_setGuardian: cannot live without a guardian\");\n        address oldGuardian = guardian;\n        guardian = newGuardian;\n\n        emit NewGuardian(oldGuardian, newGuardian);\n    }\n\n    /**\n     * @notice Initiate the GovernorBravo contract\n     * @dev Admin only. Sets initial proposal id which initiates the contract, ensuring a continuous proposal id count\n     * @param governorAlpha The address for the Governor to continue the proposal id count from\n     */\n    function _initiate(address governorAlpha) external {\n        require(msg.sender == admin, \"GovernorBravo::_initiate: admin only\");\n        require(initialProposalId == 0, \"GovernorBravo::_initiate: can only initiate once\");\n        proposalCount = GovernorAlphaInterface(governorAlpha).proposalCount();\n        initialProposalId = proposalCount;\n        for (uint256 i; i < getGovernanceRouteCount(); ++i) {\n            proposalTimelocks[i].acceptAdmin();\n        }\n    }\n\n    /**\n     * @notice Set max proposal operations\n     * @dev Admin only.\n     * @param proposalMaxOperations_ Max proposal operations\n     */\n    function _setProposalMaxOperations(uint proposalMaxOperations_) external {\n        require(msg.sender == admin, \"GovernorBravo::_setProposalMaxOperations: admin only\");\n        uint oldProposalMaxOperations = proposalMaxOperations;\n        proposalMaxOperations = proposalMaxOperations_;\n\n        emit ProposalMaxOperationsUpdated(oldProposalMaxOperations, proposalMaxOperations_);\n    }\n\n    /**\n     * @notice Begins transfer of admin rights. The newPendingAdmin must call `_acceptAdmin` to finalize the transfer.\n     * @dev Admin function to begin change of admin. The newPendingAdmin must call `_acceptAdmin` to finalize the transfer.\n     * @param newPendingAdmin New pending admin.\n     */\n    function _setPendingAdmin(address newPendingAdmin) external {\n        // Check caller = admin\n        require(msg.sender == admin, \"GovernorBravo:_setPendingAdmin: admin only\");\n\n        // Save current value, if any, for inclusion in log\n        address oldPendingAdmin = pendingAdmin;\n\n        // Store pendingAdmin with value newPendingAdmin\n        pendingAdmin = newPendingAdmin;\n\n        // Emit NewPendingAdmin(oldPendingAdmin, newPendingAdmin)\n        emit NewPendingAdmin(oldPendingAdmin, newPendingAdmin);\n    }\n\n    /**\n     * @notice Accepts transfer of admin rights. msg.sender must be pendingAdmin\n     * @dev Admin function for pending admin to accept role and update admin\n     */\n    function _acceptAdmin() external {\n        // Check caller is pendingAdmin and pendingAdmin ≠ address(0)\n        require(\n            msg.sender == pendingAdmin && msg.sender != address(0),\n            \"GovernorBravo:_acceptAdmin: pending admin only\"\n        );\n\n        // Save current values for inclusion in log\n        address oldAdmin = admin;\n        address oldPendingAdmin = pendingAdmin;\n\n        // Store admin with value pendingAdmin\n        admin = pendingAdmin;\n\n        // Clear the pending value\n        pendingAdmin = address(0);\n\n        emit NewAdmin(oldAdmin, admin);\n        emit NewPendingAdmin(oldPendingAdmin, pendingAdmin);\n    }\n\n    function add256(uint256 a, uint256 b) internal pure returns (uint) {\n        uint c = a + b;\n        require(c >= a, \"addition overflow\");\n        return c;\n    }\n\n    function sub256(uint256 a, uint256 b) internal pure returns (uint) {\n        require(b <= a, \"subtraction underflow\");\n        return a - b;\n    }\n\n    function getChainIdInternal() internal pure returns (uint) {\n        uint chainId;\n        assembly {\n            chainId := chainid()\n        }\n        return chainId;\n    }\n\n    function getGovernanceRouteCount() internal pure returns (uint8) {\n        return uint8(ProposalType.CRITICAL) + 1;\n    }\n}\n"
    },
    "contracts/Governance/GovernorBravoDelegator.sol": {
      "content": "pragma solidity ^0.5.16;\npragma experimental ABIEncoderV2;\n\nimport \"./GovernorBravoInterfaces.sol\";\n\n/**\n * @title GovernorBravoDelegator\n * @author Venus\n * @notice The `GovernorBravoDelegator` contract.\n */\ncontract GovernorBravoDelegator is GovernorBravoDelegatorStorage, GovernorBravoEvents {\n    constructor(\n        address timelock_,\n        address xvsVault_,\n        address admin_,\n        address implementation_,\n        uint votingPeriod_,\n        uint votingDelay_,\n        uint proposalThreshold_,\n        address guardian_\n    ) public {\n        // Admin set to msg.sender for initialization\n        admin = msg.sender;\n\n        delegateTo(\n            implementation_,\n            abi.encodeWithSignature(\n                \"initialize(address,address,uint256,uint256,uint256,address)\",\n                timelock_,\n                xvsVault_,\n                votingPeriod_,\n                votingDelay_,\n                proposalThreshold_,\n                guardian_\n            )\n        );\n\n        _setImplementation(implementation_);\n\n        admin = admin_;\n    }\n\n    /**\n     * @notice Called by the admin to update the implementation of the delegator\n     * @param implementation_ The address of the new implementation for delegation\n     */\n    function _setImplementation(address implementation_) public {\n        require(msg.sender == admin, \"GovernorBravoDelegator::_setImplementation: admin only\");\n        require(\n            implementation_ != address(0),\n            \"GovernorBravoDelegator::_setImplementation: invalid implementation address\"\n        );\n\n        address oldImplementation = implementation;\n        implementation = implementation_;\n\n        emit NewImplementation(oldImplementation, implementation);\n    }\n\n    /**\n     * @notice Internal method to delegate execution to another contract\n     * @dev It returns to the external caller whatever the implementation returns or forwards reverts\n     * @param callee The contract to delegatecall\n     * @param data The raw data to delegatecall\n     */\n    function delegateTo(address callee, bytes memory data) internal {\n        (bool success, bytes memory returnData) = callee.delegatecall(data);\n        assembly {\n            if eq(success, 0) {\n                revert(add(returnData, 0x20), returndatasize)\n            }\n        }\n    }\n\n    /**\n     * @dev Delegates execution to an implementation contract.\n     * It returns to the external caller whatever the implementation returns\n     * or forwards reverts.\n     */\n    function() external payable {\n        // delegate all other functions to current implementation\n        (bool success, ) = implementation.delegatecall(msg.data);\n\n        assembly {\n            let free_mem_ptr := mload(0x40)\n            returndatacopy(free_mem_ptr, 0, returndatasize)\n\n            switch success\n            case 0 {\n                revert(free_mem_ptr, returndatasize)\n            }\n            default {\n                return(free_mem_ptr, returndatasize)\n            }\n        }\n    }\n}\n"
    },
    "contracts/Governance/GovernorBravoInterfaces.sol": {
      "content": "pragma solidity ^0.5.16;\npragma experimental ABIEncoderV2;\n\n/**\n * @title GovernorBravoEvents\n * @author Venus\n * @notice Set of events emitted by the GovernorBravo contracts.\n */\ncontract GovernorBravoEvents {\n    /// @notice An event emitted when a new proposal is created\n    event ProposalCreated(\n        uint id,\n        address proposer,\n        address[] targets,\n        uint[] values,\n        string[] signatures,\n        bytes[] calldatas,\n        uint startBlock,\n        uint endBlock,\n        string description,\n        uint8 proposalType\n    );\n\n    /// @notice An event emitted when a vote has been cast on a proposal\n    /// @param voter The address which casted a vote\n    /// @param proposalId The proposal id which was voted on\n    /// @param support Support value for the vote. 0=against, 1=for, 2=abstain\n    /// @param votes Number of votes which were cast by the voter\n    /// @param reason The reason given for the vote by the voter\n    event VoteCast(address indexed voter, uint proposalId, uint8 support, uint votes, string reason);\n\n    /// @notice An event emitted when a proposal has been canceled\n    event ProposalCanceled(uint id);\n\n    /// @notice An event emitted when a proposal has been queued in the Timelock\n    event ProposalQueued(uint id, uint eta);\n\n    /// @notice An event emitted when a proposal has been executed in the Timelock\n    event ProposalExecuted(uint id);\n\n    /// @notice An event emitted when the voting delay is set\n    event VotingDelaySet(uint oldVotingDelay, uint newVotingDelay);\n\n    /// @notice An event emitted when the voting period is set\n    event VotingPeriodSet(uint oldVotingPeriod, uint newVotingPeriod);\n\n    /// @notice Emitted when implementation is changed\n    event NewImplementation(address oldImplementation, address newImplementation);\n\n    /// @notice Emitted when proposal threshold is set\n    event ProposalThresholdSet(uint oldProposalThreshold, uint newProposalThreshold);\n\n    /// @notice Emitted when pendingAdmin is changed\n    event NewPendingAdmin(address oldPendingAdmin, address newPendingAdmin);\n\n    /// @notice Emitted when pendingAdmin is accepted, which means admin is updated\n    event NewAdmin(address oldAdmin, address newAdmin);\n\n    /// @notice Emitted when the new guardian address is set\n    event NewGuardian(address oldGuardian, address newGuardian);\n\n    /// @notice Emitted when the maximum number of operations in one proposal is updated\n    event ProposalMaxOperationsUpdated(uint oldMaxOperations, uint newMaxOperations);\n\n    /// @notice Emitted when the new validation params are set\n    event SetValidationParams(\n        uint256 oldMinVotingPeriod,\n        uint256 newMinVotingPeriod,\n        uint256 oldmaxVotingPeriod,\n        uint256 newmaxVotingPeriod,\n        uint256 oldminVotingDelay,\n        uint256 newminVotingDelay,\n        uint256 oldmaxVotingDelay,\n        uint256 newmaxVotingDelay\n    );\n\n    /// @notice Emitted when new Proposal configs added\n    event SetProposalConfigs(uint256 votingPeriod, uint256 votingDelay, uint256 proposalThreshold);\n}\n\n/**\n * @title GovernorBravoDelegatorStorage\n * @author Venus\n * @notice Storage layout of the `GovernorBravoDelegator` contract\n */\ncontract GovernorBravoDelegatorStorage {\n    /// @notice Administrator for this contract\n    address public admin;\n\n    /// @notice Pending administrator for this contract\n    address public pendingAdmin;\n\n    /// @notice Active brains of Governor\n    address public implementation;\n}\n\n/**\n * @title GovernorBravoDelegateStorageV1\n * @dev For future upgrades, do not change GovernorBravoDelegateStorageV1. Create a new\n * contract which implements GovernorBravoDelegateStorageV1 and following the naming convention\n * GovernorBravoDelegateStorageVX.\n */\ncontract GovernorBravoDelegateStorageV1 is GovernorBravoDelegatorStorage {\n    /// @notice DEPRECATED The delay before voting on a proposal may take place, once proposed, in blocks\n    uint public votingDelay;\n\n    /// @notice DEPRECATED The duration of voting on a proposal, in blocks\n    uint public votingPeriod;\n\n    /// @notice DEPRECATED The number of votes required in order for a voter to become a proposer\n    uint public proposalThreshold;\n\n    /// @notice Initial proposal id set at become\n    uint public initialProposalId;\n\n    /// @notice The total number of proposals\n    uint public proposalCount;\n\n    /// @notice The address of the Venus Protocol Timelock\n    TimelockInterface public timelock;\n\n    /// @notice The address of the Venus governance token\n    XvsVaultInterface public xvsVault;\n\n    /// @notice The official record of all proposals ever proposed\n    mapping(uint => Proposal) public proposals;\n\n    /// @notice The latest proposal for each proposer\n    mapping(address => uint) public latestProposalIds;\n\n    struct Proposal {\n        /// @notice Unique id for looking up a proposal\n        uint id;\n        /// @notice Creator of the proposal\n        address proposer;\n        /// @notice The timestamp that the proposal will be available for execution, set once the vote succeeds\n        uint eta;\n        /// @notice the ordered list of target addresses for calls to be made\n        address[] targets;\n        /// @notice The ordered list of values (i.e. msg.value) to be passed to the calls to be made\n        uint[] values;\n        /// @notice The ordered list of function signatures to be called\n        string[] signatures;\n        /// @notice The ordered list of calldata to be passed to each call\n        bytes[] calldatas;\n        /// @notice The block at which voting begins: holders must delegate their votes prior to this block\n        uint startBlock;\n        /// @notice The block at which voting ends: votes must be cast prior to this block\n        uint endBlock;\n        /// @notice Current number of votes in favor of this proposal\n        uint forVotes;\n        /// @notice Current number of votes in opposition to this proposal\n        uint againstVotes;\n        /// @notice Current number of votes for abstaining for this proposal\n        uint abstainVotes;\n        /// @notice Flag marking whether the proposal has been canceled\n        bool canceled;\n        /// @notice Flag marking whether the proposal has been executed\n        bool executed;\n        /// @notice Receipts of ballots for the entire set of voters\n        mapping(address => Receipt) receipts;\n        /// @notice The type of the proposal\n        uint8 proposalType;\n    }\n\n    /// @notice Ballot receipt record for a voter\n    struct Receipt {\n        /// @notice Whether or not a vote has been cast\n        bool hasVoted;\n        /// @notice Whether or not the voter supports the proposal or abstains\n        uint8 support;\n        /// @notice The number of votes the voter had, which were cast\n        uint96 votes;\n    }\n\n    /// @notice Possible states that a proposal may be in\n    enum ProposalState {\n        Pending,\n        Active,\n        Canceled,\n        Defeated,\n        Succeeded,\n        Queued,\n        Expired,\n        Executed\n    }\n\n    /// @notice The maximum number of actions that can be included in a proposal\n    uint public proposalMaxOperations;\n\n    /// @notice A privileged role that can cancel any proposal\n    address public guardian;\n}\n\n/**\n * @title GovernorBravoDelegateStorageV2\n * @dev For future upgrades, do not change GovernorBravoDelegateStorageV2. Create a new\n * contract which implements GovernorBravoDelegateStorageV2 and following the naming convention\n * GovernorBravoDelegateStorageVX.\n */\ncontract GovernorBravoDelegateStorageV2 is GovernorBravoDelegateStorageV1 {\n    enum ProposalType {\n        NORMAL,\n        FASTTRACK,\n        CRITICAL\n    }\n\n    struct ProposalConfig {\n        /// @notice The delay before voting on a proposal may take place, once proposed, in blocks\n        uint256 votingDelay;\n        /// @notice The duration of voting on a proposal, in blocks\n        uint256 votingPeriod;\n        /// @notice The number of votes required in order for a voter to become a proposer\n        uint256 proposalThreshold;\n    }\n\n    /// @notice mapping containing configuration for each proposal type\n    mapping(uint => ProposalConfig) public proposalConfigs;\n\n    /// @notice mapping containing Timelock addresses for each proposal type\n    mapping(uint => TimelockInterface) public proposalTimelocks;\n}\n\n/**\n * @title GovernorBravoDelegateStorageV3\n * @dev For future upgrades, do not change GovernorBravoDelegateStorageV3. Create a new\n * contract which implements GovernorBravoDelegateStorageV3 and following the naming convention\n * GovernorBravoDelegateStorageVX.\n */\ncontract GovernorBravoDelegateStorageV3 is GovernorBravoDelegateStorageV2 {\n    struct ValidationParams {\n        uint256 minVotingPeriod;\n        uint256 maxVotingPeriod;\n        uint256 minVotingDelay;\n        uint256 maxVotingDelay;\n    }\n    /// @notice Stores the current minimum and maximum values of voting delay and voting period\n    ValidationParams public validationParams;\n}\n\n/**\n * @title TimelockInterface\n * @author Venus\n * @notice Interface implemented by the Timelock contract.\n */\ninterface TimelockInterface {\n    function delay() external view returns (uint);\n\n    function GRACE_PERIOD() external view returns (uint);\n\n    function acceptAdmin() external;\n\n    function queuedTransactions(bytes32 hash) external view returns (bool);\n\n    function queueTransaction(\n        address target,\n        uint value,\n        string calldata signature,\n        bytes calldata data,\n        uint eta\n    ) external returns (bytes32);\n\n    function cancelTransaction(\n        address target,\n        uint value,\n        string calldata signature,\n        bytes calldata data,\n        uint eta\n    ) external;\n\n    function executeTransaction(\n        address target,\n        uint value,\n        string calldata signature,\n        bytes calldata data,\n        uint eta\n    ) external payable returns (bytes memory);\n}\n\ninterface XvsVaultInterface {\n    function getPriorVotes(address account, uint blockNumber) external view returns (uint96);\n}\n\ninterface GovernorAlphaInterface {\n    /// @notice The total number of proposals\n    function proposalCount() external returns (uint);\n}\n"
    },
    "contracts/legacy/GovenorBravoV1.sol": {
      "content": "pragma solidity ^0.5.16;\npragma experimental ABIEncoderV2;\n\nimport \"./GovernorBravoInterfaces.sol\";\n\n/**\n * @title GovernorBravoDelegator\n * @author Venus\n * @notice The `GovernorBravoDelegator` contract.\n */\ncontract GovernorBravoDelegatorV1 is GovernorBravoDelegatorStorage, GovernorBravoEventsV1 {\n    constructor(\n        address timelock_,\n        address xvsVault_,\n        address admin_,\n        address implementation_,\n        uint votingPeriod_,\n        uint votingDelay_,\n        uint proposalThreshold_,\n        address guardian_\n    ) public {\n        // Admin set to msg.sender for initialization\n        admin = msg.sender;\n\n        delegateTo(\n            implementation_,\n            abi.encodeWithSignature(\n                \"initialize(address,address,uint256,uint256,uint256,address)\",\n                timelock_,\n                xvsVault_,\n                votingPeriod_,\n                votingDelay_,\n                proposalThreshold_,\n                guardian_\n            )\n        );\n\n        _setImplementation(implementation_);\n\n        admin = admin_;\n    }\n\n    /**\n     * @notice Called by the admin to update the implementation of the delegator\n     * @param implementation_ The address of the new implementation for delegation\n     */\n    function _setImplementation(address implementation_) public {\n        require(msg.sender == admin, \"GovernorBravoDelegator::_setImplementation: admin only\");\n        require(\n            implementation_ != address(0),\n            \"GovernorBravoDelegator::_setImplementation: invalid implementation address\"\n        );\n\n        address oldImplementation = implementation;\n        implementation = implementation_;\n\n        emit NewImplementation(oldImplementation, implementation);\n    }\n\n    /**\n     * @notice Internal method to delegate execution to another contract\n     * @dev It returns to the external caller whatever the implementation returns or forwards reverts\n     * @param callee The contract to delegatecall\n     * @param data The raw data to delegatecall\n     */\n    function delegateTo(address callee, bytes memory data) internal {\n        (bool success, bytes memory returnData) = callee.delegatecall(data);\n        assembly {\n            if eq(success, 0) {\n                revert(add(returnData, 0x20), returndatasize)\n            }\n        }\n    }\n\n    /**\n     * @dev Delegates execution to an implementation contract.\n     * It returns to the external caller whatever the implementation returns\n     * or forwards reverts.\n     */\n    function() external payable {\n        // delegate all other functions to current implementation\n        (bool success, ) = implementation.delegatecall(msg.data);\n\n        assembly {\n            let free_mem_ptr := mload(0x40)\n            returndatacopy(free_mem_ptr, 0, returndatasize)\n\n            switch success\n            case 0 {\n                revert(free_mem_ptr, returndatasize)\n            }\n            default {\n                return(free_mem_ptr, returndatasize)\n            }\n        }\n    }\n}\n"
    },
    "contracts/legacy/GovernorBravoDelegateV1.sol": {
      "content": "pragma solidity ^0.5.16;\npragma experimental ABIEncoderV2;\n\nimport \"./GovernorBravoInterfaces.sol\";\n\n/**\n * @title GovernorBravoDelegateV1\n * @dev This contract is the first deployed implementation GovernorBravo.\n * It is included here for testing purposes because it has a different signature for the ProposalCreated event and Proposal struct\n */\ncontract GovernorBravoDelegateV1 is GovernorBravoDelegateStorageV1, GovernorBravoEventsV1 {\n    /// @notice The name of this contract\n    string public constant name = \"Venus Governor Bravo\";\n\n    /// @notice The minimum setable proposal threshold\n    uint public constant MIN_PROPOSAL_THRESHOLD = 150000e18; // 150,000 Xvs\n\n    /// @notice The maximum setable proposal threshold\n    uint public constant MAX_PROPOSAL_THRESHOLD = 300000e18; //300,000 Xvs\n\n    /// @notice The minimum setable voting period\n    uint public constant MIN_VOTING_PERIOD = 20 * 60 * 3; // About 3 hours, 3 secs per block\n\n    /// @notice The max setable voting period\n    uint public constant MAX_VOTING_PERIOD = 20 * 60 * 24 * 14; // About 2 weeks, 3 secs per block\n\n    /// @notice The min setable voting delay\n    uint public constant MIN_VOTING_DELAY = 1;\n\n    /// @notice The max setable voting delay\n    uint public constant MAX_VOTING_DELAY = 20 * 60 * 24 * 7; // About 1 week, 3 secs per block\n\n    /// @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\n    uint public constant quorumVotes = 600000e18; // 600,000 = 2% of Xvs\n\n    /// @notice The EIP-712 typehash for the contract's domain\n    bytes32 public constant DOMAIN_TYPEHASH =\n        keccak256(\"EIP712Domain(string name,uint256 chainId,address verifyingContract)\");\n\n    /// @notice The EIP-712 typehash for the ballot struct used by the contract\n    bytes32 public constant BALLOT_TYPEHASH = keccak256(\"Ballot(uint256 proposalId,uint8 support)\");\n\n    /**\n     * @notice Used to initialize the contract during delegator contructor\n     * @param timelock_ The address of the Timelock\n     * @param xvsVault_ The address of the XvsVault\n     * @param votingPeriod_ The initial voting period\n     * @param votingDelay_ The initial voting delay\n     * @param proposalThreshold_ The initial proposal threshold\n     */\n    function initialize(\n        address timelock_,\n        address xvsVault_,\n        uint votingPeriod_,\n        uint votingDelay_,\n        uint proposalThreshold_,\n        address guardian_\n    ) public {\n        require(address(timelock) == address(0), \"GovernorBravo::initialize: can only initialize once\");\n        require(msg.sender == admin, \"GovernorBravo::initialize: admin only\");\n        require(timelock_ != address(0), \"GovernorBravo::initialize: invalid timelock address\");\n        require(xvsVault_ != address(0), \"GovernorBravo::initialize: invalid xvs address\");\n        require(\n            votingPeriod_ >= MIN_VOTING_PERIOD && votingPeriod_ <= MAX_VOTING_PERIOD,\n            \"GovernorBravo::initialize: invalid voting period\"\n        );\n        require(\n            votingDelay_ >= MIN_VOTING_DELAY && votingDelay_ <= MAX_VOTING_DELAY,\n            \"GovernorBravo::initialize: invalid voting delay\"\n        );\n        require(\n            proposalThreshold_ >= MIN_PROPOSAL_THRESHOLD && proposalThreshold_ <= MAX_PROPOSAL_THRESHOLD,\n            \"GovernorBravo::initialize: invalid proposal threshold\"\n        );\n        require(guardian_ != address(0), \"GovernorBravo::initialize: invalid guardian\");\n\n        timelock = TimelockInterface(timelock_);\n        xvsVault = XvsVaultInterface(xvsVault_);\n        votingPeriod = votingPeriod_;\n        votingDelay = votingDelay_;\n        proposalThreshold = proposalThreshold_;\n        proposalMaxOperations = 10;\n        guardian = guardian_;\n    }\n\n    /**\n     * @notice Function used to propose a new proposal. Sender must have delegates above the proposal threshold\n     * @param targets Target addresses for proposal calls\n     * @param values Eth values for proposal calls\n     * @param signatures Function signatures for proposal calls\n     * @param calldatas Calldatas for proposal calls\n     * @param description String description of the proposal\n     * @return Proposal id of new proposal\n     */\n    function propose(\n        address[] memory targets,\n        uint[] memory values,\n        string[] memory signatures,\n        bytes[] memory calldatas,\n        string memory description\n    ) public returns (uint) {\n        // Reject proposals before initiating as Governor\n        require(initialProposalId != 0, \"GovernorBravo::propose: Governor Bravo not active\");\n        require(\n            xvsVault.getPriorVotes(msg.sender, sub256(block.number, 1)) > proposalThreshold,\n            \"GovernorBravo::propose: proposer votes below proposal threshold\"\n        );\n        require(\n            targets.length == values.length &&\n                targets.length == signatures.length &&\n                targets.length == calldatas.length,\n            \"GovernorBravo::propose: proposal function information arity mismatch\"\n        );\n        require(targets.length != 0, \"GovernorBravo::propose: must provide actions\");\n        require(targets.length <= proposalMaxOperations, \"GovernorBravo::propose: too many actions\");\n\n        uint latestProposalId = latestProposalIds[msg.sender];\n        if (latestProposalId != 0) {\n            ProposalState proposersLatestProposalState = state(latestProposalId);\n            require(\n                proposersLatestProposalState != ProposalState.Active,\n                \"GovernorBravo::propose: one live proposal per proposer, found an already active proposal\"\n            );\n            require(\n                proposersLatestProposalState != ProposalState.Pending,\n                \"GovernorBravo::propose: one live proposal per proposer, found an already pending proposal\"\n            );\n        }\n\n        uint startBlock = add256(block.number, votingDelay);\n        uint endBlock = add256(startBlock, votingPeriod);\n\n        proposalCount++;\n        Proposal memory newProposal = Proposal({\n            id: proposalCount,\n            proposer: msg.sender,\n            eta: 0,\n            targets: targets,\n            values: values,\n            signatures: signatures,\n            calldatas: calldatas,\n            startBlock: startBlock,\n            endBlock: endBlock,\n            forVotes: 0,\n            againstVotes: 0,\n            abstainVotes: 0,\n            canceled: false,\n            executed: false\n        });\n\n        proposals[newProposal.id] = newProposal;\n        latestProposalIds[newProposal.proposer] = newProposal.id;\n\n        emit ProposalCreated(\n            newProposal.id,\n            msg.sender,\n            targets,\n            values,\n            signatures,\n            calldatas,\n            startBlock,\n            endBlock,\n            description\n        );\n        return newProposal.id;\n    }\n\n    /**\n     * @notice Queues a proposal of state succeeded\n     * @param proposalId The id of the proposal to queue\n     */\n    function queue(uint proposalId) external {\n        require(\n            state(proposalId) == ProposalState.Succeeded,\n            \"GovernorBravo::queue: proposal can only be queued if it is succeeded\"\n        );\n        Proposal storage proposal = proposals[proposalId];\n        uint eta = add256(block.timestamp, timelock.delay());\n        for (uint i = 0; i < proposal.targets.length; i++) {\n            queueOrRevertInternal(\n                proposal.targets[i],\n                proposal.values[i],\n                proposal.signatures[i],\n                proposal.calldatas[i],\n                eta\n            );\n        }\n        proposal.eta = eta;\n        emit ProposalQueued(proposalId, eta);\n    }\n\n    function queueOrRevertInternal(\n        address target,\n        uint value,\n        string memory signature,\n        bytes memory data,\n        uint eta\n    ) internal {\n        require(\n            !timelock.queuedTransactions(keccak256(abi.encode(target, value, signature, data, eta))),\n            \"GovernorBravo::queueOrRevertInternal: identical proposal action already queued at eta\"\n        );\n        timelock.queueTransaction(target, value, signature, data, eta);\n    }\n\n    /**\n     * @notice Executes a queued proposal if eta has passed\n     * @param proposalId The id of the proposal to execute\n     */\n    function execute(uint proposalId) external {\n        require(\n            state(proposalId) == ProposalState.Queued,\n            \"GovernorBravo::execute: proposal can only be executed if it is queued\"\n        );\n        Proposal storage proposal = proposals[proposalId];\n        proposal.executed = true;\n        for (uint i = 0; i < proposal.targets.length; i++) {\n            timelock.executeTransaction(\n                proposal.targets[i],\n                proposal.values[i],\n                proposal.signatures[i],\n                proposal.calldatas[i],\n                proposal.eta\n            );\n        }\n        emit ProposalExecuted(proposalId);\n    }\n\n    /**\n     * @notice Cancels a proposal only if sender is the proposer, or proposer delegates dropped below proposal threshold\n     * @param proposalId The id of the proposal to cancel\n     */\n    function cancel(uint proposalId) external {\n        require(state(proposalId) != ProposalState.Executed, \"GovernorBravo::cancel: cannot cancel executed proposal\");\n\n        Proposal storage proposal = proposals[proposalId];\n        require(\n            msg.sender == guardian ||\n                msg.sender == proposal.proposer ||\n                xvsVault.getPriorVotes(proposal.proposer, sub256(block.number, 1)) < proposalThreshold,\n            \"GovernorBravo::cancel: proposer above threshold\"\n        );\n\n        proposal.canceled = true;\n        for (uint i = 0; i < proposal.targets.length; i++) {\n            timelock.cancelTransaction(\n                proposal.targets[i],\n                proposal.values[i],\n                proposal.signatures[i],\n                proposal.calldatas[i],\n                proposal.eta\n            );\n        }\n\n        emit ProposalCanceled(proposalId);\n    }\n\n    /**\n     * @notice Gets actions of a proposal\n     * @param proposalId the id of the proposal\n     * @return targets, values, signatures, and calldatas of the proposal actions\n     */\n    function getActions(\n        uint proposalId\n    )\n        external\n        view\n        returns (address[] memory targets, uint[] memory values, string[] memory signatures, bytes[] memory calldatas)\n    {\n        Proposal storage p = proposals[proposalId];\n        return (p.targets, p.values, p.signatures, p.calldatas);\n    }\n\n    /**\n     * @notice Gets the receipt for a voter on a given proposal\n     * @param proposalId the id of proposal\n     * @param voter The address of the voter\n     * @return The voting receipt\n     */\n    function getReceipt(uint proposalId, address voter) external view returns (Receipt memory) {\n        return proposals[proposalId].receipts[voter];\n    }\n\n    /**\n     * @notice Gets the state of a proposal\n     * @param proposalId The id of the proposal\n     * @return Proposal state\n     */\n    function state(uint proposalId) public view returns (ProposalState) {\n        require(\n            proposalCount >= proposalId && proposalId > initialProposalId,\n            \"GovernorBravo::state: invalid proposal id\"\n        );\n        Proposal storage proposal = proposals[proposalId];\n        if (proposal.canceled) {\n            return ProposalState.Canceled;\n        } else if (block.number <= proposal.startBlock) {\n            return ProposalState.Pending;\n        } else if (block.number <= proposal.endBlock) {\n            return ProposalState.Active;\n        } else if (proposal.forVotes <= proposal.againstVotes || proposal.forVotes < quorumVotes) {\n            return ProposalState.Defeated;\n        } else if (proposal.eta == 0) {\n            return ProposalState.Succeeded;\n        } else if (proposal.executed) {\n            return ProposalState.Executed;\n        } else if (block.timestamp >= add256(proposal.eta, timelock.GRACE_PERIOD())) {\n            return ProposalState.Expired;\n        } else {\n            return ProposalState.Queued;\n        }\n    }\n\n    /**\n     * @notice Cast a vote for a proposal\n     * @param proposalId The id of the proposal to vote on\n     * @param support The support value for the vote. 0=against, 1=for, 2=abstain\n     */\n    function castVote(uint proposalId, uint8 support) external {\n        emit VoteCast(msg.sender, proposalId, support, castVoteInternal(msg.sender, proposalId, support), \"\");\n    }\n\n    /**\n     * @notice Cast a vote for a proposal with a reason\n     * @param proposalId The id of the proposal to vote on\n     * @param support The support value for the vote. 0=against, 1=for, 2=abstain\n     * @param reason The reason given for the vote by the voter\n     */\n    function castVoteWithReason(uint proposalId, uint8 support, string calldata reason) external {\n        emit VoteCast(msg.sender, proposalId, support, castVoteInternal(msg.sender, proposalId, support), reason);\n    }\n\n    /**\n     * @notice Cast a vote for a proposal by signature\n     * @dev External function that accepts EIP-712 signatures for voting on proposals.\n     */\n    function castVoteBySig(uint proposalId, uint8 support, uint8 v, bytes32 r, bytes32 s) external {\n        bytes32 domainSeparator = keccak256(\n            abi.encode(DOMAIN_TYPEHASH, keccak256(bytes(name)), getChainIdInternal(), address(this))\n        );\n        bytes32 structHash = keccak256(abi.encode(BALLOT_TYPEHASH, proposalId, support));\n        bytes32 digest = keccak256(abi.encodePacked(\"\\x19\\x01\", domainSeparator, structHash));\n        address signatory = ecrecover(digest, v, r, s);\n        require(signatory != address(0), \"GovernorBravo::castVoteBySig: invalid signature\");\n        emit VoteCast(signatory, proposalId, support, castVoteInternal(signatory, proposalId, support), \"\");\n    }\n\n    /**\n     * @notice Internal function that caries out voting logic\n     * @param voter The voter that is casting their vote\n     * @param proposalId The id of the proposal to vote on\n     * @param support The support value for the vote. 0=against, 1=for, 2=abstain\n     * @return The number of votes cast\n     */\n    function castVoteInternal(address voter, uint proposalId, uint8 support) internal returns (uint96) {\n        require(state(proposalId) == ProposalState.Active, \"GovernorBravo::castVoteInternal: voting is closed\");\n        require(support <= 2, \"GovernorBravo::castVoteInternal: invalid vote type\");\n        Proposal storage proposal = proposals[proposalId];\n        Receipt storage receipt = proposal.receipts[voter];\n        require(receipt.hasVoted == false, \"GovernorBravo::castVoteInternal: voter already voted\");\n        uint96 votes = xvsVault.getPriorVotes(voter, proposal.startBlock);\n\n        if (support == 0) {\n            proposal.againstVotes = add256(proposal.againstVotes, votes);\n        } else if (support == 1) {\n            proposal.forVotes = add256(proposal.forVotes, votes);\n        } else if (support == 2) {\n            proposal.abstainVotes = add256(proposal.abstainVotes, votes);\n        }\n\n        receipt.hasVoted = true;\n        receipt.support = support;\n        receipt.votes = votes;\n\n        return votes;\n    }\n\n    /**\n     * @notice Sets the new governance guardian\n     * @param newGuardian the address of the new guardian\n     */\n    function _setGuardian(address newGuardian) external {\n        require(msg.sender == guardian || msg.sender == admin, \"GovernorBravo::_setGuardian: admin or guardian only\");\n        require(newGuardian != address(0), \"GovernorBravo::_setGuardian: cannot live without a guardian\");\n        address oldGuardian = guardian;\n        guardian = newGuardian;\n\n        emit NewGuardian(oldGuardian, newGuardian);\n    }\n\n    /**\n     * @notice Admin function for setting the voting delay\n     * @param newVotingDelay new voting delay, in blocks\n     */\n    function _setVotingDelay(uint newVotingDelay) external {\n        require(msg.sender == admin, \"GovernorBravo::_setVotingDelay: admin only\");\n        require(\n            newVotingDelay >= MIN_VOTING_DELAY && newVotingDelay <= MAX_VOTING_DELAY,\n            \"GovernorBravo::_setVotingDelay: invalid voting delay\"\n        );\n        uint oldVotingDelay = votingDelay;\n        votingDelay = newVotingDelay;\n\n        emit VotingDelaySet(oldVotingDelay, votingDelay);\n    }\n\n    /**\n     * @notice Admin function for setting the voting period\n     * @param newVotingPeriod new voting period, in blocks\n     */\n    function _setVotingPeriod(uint newVotingPeriod) external {\n        require(msg.sender == admin, \"GovernorBravo::_setVotingPeriod: admin only\");\n        require(\n            newVotingPeriod >= MIN_VOTING_PERIOD && newVotingPeriod <= MAX_VOTING_PERIOD,\n            \"GovernorBravo::_setVotingPeriod: invalid voting period\"\n        );\n        uint oldVotingPeriod = votingPeriod;\n        votingPeriod = newVotingPeriod;\n\n        emit VotingPeriodSet(oldVotingPeriod, votingPeriod);\n    }\n\n    /**\n     * @notice Admin function for setting the proposal threshold\n     * @dev newProposalThreshold must be greater than the hardcoded min\n     * @param newProposalThreshold new proposal threshold\n     */\n    function _setProposalThreshold(uint newProposalThreshold) external {\n        require(msg.sender == admin, \"GovernorBravo::_setProposalThreshold: admin only\");\n        require(\n            newProposalThreshold >= MIN_PROPOSAL_THRESHOLD && newProposalThreshold <= MAX_PROPOSAL_THRESHOLD,\n            \"GovernorBravo::_setProposalThreshold: invalid proposal threshold\"\n        );\n        uint oldProposalThreshold = proposalThreshold;\n        proposalThreshold = newProposalThreshold;\n\n        emit ProposalThresholdSet(oldProposalThreshold, proposalThreshold);\n    }\n\n    /**\n     * @notice Initiate the GovernorBravo contract\n     * @dev Admin only. Sets initial proposal id which initiates the contract, ensuring a continuous proposal id count\n     * @param governorAlpha The address for the Governor to continue the proposal id count from\n     */\n    function _initiate(address governorAlpha) external {\n        require(msg.sender == admin, \"GovernorBravo::_initiate: admin only\");\n        require(initialProposalId == 0, \"GovernorBravo::_initiate: can only initiate once\");\n        proposalCount = GovernorAlphaInterface(governorAlpha).proposalCount();\n        initialProposalId = proposalCount;\n        timelock.acceptAdmin();\n    }\n\n    /**\n     * @notice Set max proposal operations\n     * @dev Admin only.\n     * @param proposalMaxOperations_ Max proposal operations\n     */\n    function _setProposalMaxOperations(uint proposalMaxOperations_) external {\n        require(msg.sender == admin, \"GovernorBravo::_setProposalMaxOperations: admin only\");\n        uint oldProposalMaxOperations = proposalMaxOperations;\n        proposalMaxOperations = proposalMaxOperations_;\n\n        emit ProposalMaxOperationsUpdated(oldProposalMaxOperations, proposalMaxOperations_);\n    }\n\n    /**\n     * @notice Begins transfer of admin rights. The newPendingAdmin must call `_acceptAdmin` to finalize the transfer.\n     * @dev Admin function to begin change of admin. The newPendingAdmin must call `_acceptAdmin` to finalize the transfer.\n     * @param newPendingAdmin New pending admin.\n     */\n    function _setPendingAdmin(address newPendingAdmin) external {\n        // Check caller = admin\n        require(msg.sender == admin, \"GovernorBravo:_setPendingAdmin: admin only\");\n\n        // Save current value, if any, for inclusion in log\n        address oldPendingAdmin = pendingAdmin;\n\n        // Store pendingAdmin with value newPendingAdmin\n        pendingAdmin = newPendingAdmin;\n\n        // Emit NewPendingAdmin(oldPendingAdmin, newPendingAdmin)\n        emit NewPendingAdmin(oldPendingAdmin, newPendingAdmin);\n    }\n\n    /**\n     * @notice Accepts transfer of admin rights. msg.sender must be pendingAdmin\n     * @dev Admin function for pending admin to accept role and update admin\n     */\n    function _acceptAdmin() external {\n        // Check caller is pendingAdmin and pendingAdmin ≠ address(0)\n        require(\n            msg.sender == pendingAdmin && msg.sender != address(0),\n            \"GovernorBravo:_acceptAdmin: pending admin only\"\n        );\n\n        // Save current values for inclusion in log\n        address oldAdmin = admin;\n        address oldPendingAdmin = pendingAdmin;\n\n        // Store admin with value pendingAdmin\n        admin = pendingAdmin;\n\n        // Clear the pending value\n        pendingAdmin = address(0);\n\n        emit NewAdmin(oldAdmin, admin);\n        emit NewPendingAdmin(oldPendingAdmin, pendingAdmin);\n    }\n\n    function add256(uint256 a, uint256 b) internal pure returns (uint) {\n        uint c = a + b;\n        require(c >= a, \"addition overflow\");\n        return c;\n    }\n\n    function sub256(uint256 a, uint256 b) internal pure returns (uint) {\n        require(b <= a, \"subtraction underflow\");\n        return a - b;\n    }\n\n    function getChainIdInternal() internal pure returns (uint) {\n        uint chainId;\n        assembly {\n            chainId := chainid()\n        }\n        return chainId;\n    }\n}\n"
    },
    "contracts/legacy/GovernorBravoInterfaces.sol": {
      "content": "pragma solidity ^0.5.16;\npragma experimental ABIEncoderV2;\n\nimport { XvsVaultInterface, TimelockInterface, GovernorAlphaInterface } from \"../Governance/GovernorBravoInterfaces.sol\";\n\n/**\n * @title GovernorBravoEvents\n * @author Venus\n * @notice Set of events emitted by the first GovernorBravo implementation contract.\n * @dev This contract is included for archival and testing purposes as the ProposalCreated event has a different signature than the latest implementation.\n */\ncontract GovernorBravoEventsV1 {\n    /// @notice An event emitted when a new proposal is created\n    event ProposalCreated(\n        uint id,\n        address proposer,\n        address[] targets,\n        uint[] values,\n        string[] signatures,\n        bytes[] calldatas,\n        uint startBlock,\n        uint endBlock,\n        string description\n    );\n\n    /// @notice An event emitted when a vote has been cast on a proposal\n    /// @param voter The address which casted a vote\n    /// @param proposalId The proposal id which was voted on\n    /// @param support Support value for the vote. 0=against, 1=for, 2=abstain\n    /// @param votes Number of votes which were cast by the voter\n    /// @param reason The reason given for the vote by the voter\n    event VoteCast(address indexed voter, uint proposalId, uint8 support, uint votes, string reason);\n\n    /// @notice An event emitted when a proposal has been canceled\n    event ProposalCanceled(uint id);\n\n    /// @notice An event emitted when a proposal has been queued in the Timelock\n    event ProposalQueued(uint id, uint eta);\n\n    /// @notice An event emitted when a proposal has been executed in the Timelock\n    event ProposalExecuted(uint id);\n\n    /// @notice An event emitted when the voting delay is set\n    event VotingDelaySet(uint oldVotingDelay, uint newVotingDelay);\n\n    /// @notice An event emitted when the voting period is set\n    event VotingPeriodSet(uint oldVotingPeriod, uint newVotingPeriod);\n\n    /// @notice Emitted when implementation is changed\n    event NewImplementation(address oldImplementation, address newImplementation);\n\n    /// @notice Emitted when proposal threshold is set\n    event ProposalThresholdSet(uint oldProposalThreshold, uint newProposalThreshold);\n\n    /// @notice Emitted when pendingAdmin is changed\n    event NewPendingAdmin(address oldPendingAdmin, address newPendingAdmin);\n\n    /// @notice Emitted when pendingAdmin is accepted, which means admin is updated\n    event NewAdmin(address oldAdmin, address newAdmin);\n\n    /// @notice Emitted when the new guardian address is set\n    event NewGuardian(address oldGuardian, address newGuardian);\n\n    /// @notice Emitted when the maximum number of operations in one proposal is updated\n    event ProposalMaxOperationsUpdated(uint oldMaxOperations, uint newMaxOperations);\n}\n\n/**\n * @title GovernorBravoDelegatorStorage\n * @author Venus\n * @notice Storage layout of the `GovernorBravoDelegator` contract\n */\ncontract GovernorBravoDelegatorStorage {\n    /// @notice Administrator for this contract\n    address public admin;\n\n    /// @notice Pending administrator for this contract\n    address public pendingAdmin;\n\n    /// @notice Active brains of Governor\n    address public implementation;\n}\n\n/**\n * @title GovernorBravoDelegateStorageV1\n * @dev This contract is included for archival and testing purposes as the Proposal struct has a different shape than the latest implementation.\n */\ncontract GovernorBravoDelegateStorageV1 is GovernorBravoDelegatorStorage {\n    /// @notice DEPRECATED The delay before voting on a proposal may take place, once proposed, in blocks\n    uint public votingDelay;\n\n    /// @notice DEPRECATED The duration of voting on a proposal, in blocks\n    uint public votingPeriod;\n\n    /// @notice DEPRECATED The number of votes required in order for a voter to become a proposer\n    uint public proposalThreshold;\n\n    /// @notice Initial proposal id set at become\n    uint public initialProposalId;\n\n    /// @notice The total number of proposals\n    uint public proposalCount;\n\n    /// @notice The address of the Venus Protocol Timelock\n    TimelockInterface public timelock;\n\n    /// @notice The address of the Venus governance token\n    XvsVaultInterface public xvsVault;\n\n    /// @notice The official record of all proposals ever proposed\n    mapping(uint => Proposal) public proposals;\n\n    /// @notice The latest proposal for each proposer\n    mapping(address => uint) public latestProposalIds;\n\n    struct Proposal {\n        /// @notice Unique id for looking up a proposal\n        uint id;\n        /// @notice Creator of the proposal\n        address proposer;\n        /// @notice The timestamp that the proposal will be available for execution, set once the vote succeeds\n        uint eta;\n        /// @notice the ordered list of target addresses for calls to be made\n        address[] targets;\n        /// @notice The ordered list of values (i.e. msg.value) to be passed to the calls to be made\n        uint[] values;\n        /// @notice The ordered list of function signatures to be called\n        string[] signatures;\n        /// @notice The ordered list of calldata to be passed to each call\n        bytes[] calldatas;\n        /// @notice The block at which voting begins: holders must delegate their votes prior to this block\n        uint startBlock;\n        /// @notice The block at which voting ends: votes must be cast prior to this block\n        uint endBlock;\n        /// @notice Current number of votes in favor of this proposal\n        uint forVotes;\n        /// @notice Current number of votes in opposition to this proposal\n        uint againstVotes;\n        /// @notice Current number of votes for abstaining for this proposal\n        uint abstainVotes;\n        /// @notice Flag marking whether the proposal has been canceled\n        bool canceled;\n        /// @notice Flag marking whether the proposal has been executed\n        bool executed;\n        /// @notice Receipts of ballots for the entire set of voters\n        mapping(address => Receipt) receipts;\n    }\n\n    /// @notice Ballot receipt record for a voter\n    struct Receipt {\n        /// @notice Whether or not a vote has been cast\n        bool hasVoted;\n        /// @notice Whether or not the voter supports the proposal or abstains\n        uint8 support;\n        /// @notice The number of votes the voter had, which were cast\n        uint96 votes;\n    }\n\n    /// @notice Possible states that a proposal may be in\n    enum ProposalState {\n        Pending,\n        Active,\n        Canceled,\n        Defeated,\n        Succeeded,\n        Queued,\n        Expired,\n        Executed\n    }\n\n    /// @notice The maximum number of actions that can be included in a proposal\n    uint public proposalMaxOperations;\n\n    /// @notice A privileged role that can cancel any proposal\n    address public guardian;\n}\n"
    }
  },
  "settings": {
    "optimizer": {
      "enabled": true,
      "runs": 200
    },
    "outputSelection": {
      "*": {
        "*": [
          "storageLayout",
          "abi",
          "evm.bytecode",
          "evm.deployedBytecode",
          "evm.methodIdentifiers",
          "metadata",
          "devdoc",
          "userdoc",
          "evm.gasEstimates"
        ],
        "": ["ast"]
      }
    },
    "metadata": {
      "useLiteralContent": true
    }
  }
}
