creation_sourcecode: {{
    "language": "Solidity",
    "sources": {
      "GovernanceManager.sol": {
        "content": "// SPDX-License-Identifier: GPL-3.0-or-later\npragma solidity ^0.8.17;\n\nimport \"Address.sol\";\nimport \"EnumerableSet.sol\";\nimport \"EnumerableMap.sol\";\nimport \"Initializable.sol\";\n\nimport \"DataTypes.sol\";\nimport \"ScaledMath.sol\";\nimport \"VaultsSnapshot.sol\";\nimport \"Errors.sol\";\n\nimport \"IVault.sol\";\nimport \"IGovernanceManager.sol\";\nimport \"IVotingPowerAggregator.sol\";\nimport \"ITierer.sol\";\nimport \"ITierStrategy.sol\";\nimport \"IBoundedERC20WithEMA.sol\";\n\ncontract GovernanceManager is IGovernanceManager, Initializable {\n    using Address for address;\n    using ScaledMath for uint256;\n    using EnumerableSet for EnumerableSet.UintSet;\n    using EnumerableMap for EnumerableMap.AddressToUintMap;\n    using VaultsSnapshot for DataTypes.VaultSnapshot[];\n\n    uint256 internal constant _MULTISIG_SUNSET_PERIOD = 90 days;\n\n    address public immutable multisig;\n    IVotingPowerAggregator public immutable votingPowerAggregator;\n    ITierer public immutable tierer;\n\n    uint256 public multisigSunsetAt;\n    IBoundedERC20WithEMA public bGYD;\n    DataTypes.LimitUpgradeabilityParameters public limitUpgradeabilityParams;\n\n    uint16 public proposalsCount;\n\n    EnumerableSet.UintSet internal _activeProposals;\n    EnumerableSet.UintSet internal _timelockedProposals;\n    mapping(uint16 => DataTypes.Proposal) internal _proposals;\n    mapping(uint16 => DataTypes.VaultSnapshot[]) internal _vaultSnapshots;\n\n    mapping(address => mapping(uint16 => DataTypes.Ballot)) internal _votes;\n    mapping(uint16 => mapping(DataTypes.Ballot => EnumerableMap.AddressToUintMap))\n        internal _totals;\n\n    modifier onlySelf() {\n        if (msg.sender != address(this))\n            revert Errors.NotAuthorized(msg.sender, address(this));\n        _;\n    }\n\n    modifier onlyMultisig() {\n        if (msg.sender != multisig)\n            revert Errors.NotAuthorized(msg.sender, multisig);\n        if (block.timestamp >= multisigSunsetAt) revert Errors.MultisigSunset();\n        _;\n    }\n\n    constructor(\n        address _multisig,\n        IVotingPowerAggregator _votingPowerAggregator,\n        ITierer _tierer\n    ) {\n        multisig = _multisig;\n        votingPowerAggregator = _votingPowerAggregator;\n        tierer = _tierer;\n    }\n\n    function initialize(\n        IBoundedERC20WithEMA _bGYD,\n        DataTypes.LimitUpgradeabilityParameters memory _params\n    ) external initializer {\n        bGYD = _bGYD;\n        limitUpgradeabilityParams = _params;\n        multisigSunsetAt = block.timestamp + _MULTISIG_SUNSET_PERIOD;\n    }\n\n    event MultisigSunsetAtUpdated(uint256 originalSunset, uint256 newSunset);\n\n    function extendMultisigSunsetAt(\n        uint256 extensionPeriod\n    ) external onlyMultisig {\n        uint256 oldMultisigSunsetAt = multisigSunsetAt;\n        multisigSunsetAt += extensionPeriod;\n        emit MultisigSunsetAtUpdated(oldMultisigSunsetAt, multisigSunsetAt);\n    }\n\n    event ProposalCreated(\n        uint16 indexed id,\n        address proposer,\n        DataTypes.ProposalAction[] actions\n    );\n\n    function createProposal(\n        DataTypes.ProposalAction[] calldata actions\n    ) external override {\n        require(actions.length > 0, \"cannot create a proposal with no actions\");\n\n        DataTypes.Tier memory tier = _getTier(actions);\n\n        // If a sufficiently large amount of GYD is bounded, this signifies that holders\n        // are happy with the system and are against further high-level upgrades.\n        // As a result, we should apply a higher tier if the proposed action has big impacts.\n        if (_isUpgradeabilityLimited(tier.actionLevel)) {\n            tier = _getLimitUpgradeabilityTier();\n        }\n\n        DataTypes.VaultVotingPower[] memory rawPower = votingPowerAggregator\n            .getVotingPower(msg.sender, block.timestamp - 1);\n        uint256 votingPowerPct = votingPowerAggregator\n            .calculateWeightedPowerPct(rawPower);\n        require(\n            votingPowerPct > tier.proposalThreshold,\n            \"proposer doesn't have enough voting power to propose this action\"\n        );\n\n        uint64 createdAt = uint64(block.timestamp);\n        uint64 votingEndsAt = createdAt + tier.proposalLength;\n        uint64 executableAt = votingEndsAt + tier.timeLockDuration;\n\n        DataTypes.Proposal storage p = _proposals[proposalsCount];\n        p.id = proposalsCount;\n        p.proposer = msg.sender;\n        p.createdAt = createdAt;\n        p.actionLevel = tier.actionLevel;\n        p.votingEndsAt = votingEndsAt;\n        p.executableAt = executableAt;\n        p.status = DataTypes.Status.Active;\n        p.quorum = tier.quorum;\n        p.voteThreshold = tier.voteThreshold;\n\n        for (uint256 i = 0; i < actions.length; i++) {\n            p.actions.push(actions[i]);\n        }\n\n        votingPowerAggregator.createVaultsSnapshot().persist(\n            _vaultSnapshots[p.id]\n        );\n\n        proposalsCount = p.id + 1;\n        _activeProposals.add(uint256(p.id));\n\n        emit ProposalCreated(p.id, p.proposer, actions);\n    }\n\n    event VoteCast(\n        uint16 indexed proposalId,\n        address voter,\n        DataTypes.Ballot vote\n    );\n\n    function vote(\n        uint16 proposalId,\n        DataTypes.Ballot ballot\n    ) external override {\n        DataTypes.Proposal storage proposal = _proposals[proposalId];\n        require(proposal.createdAt != 0, \"proposal does not exist\");\n        require(block.timestamp > proposal.createdAt, \"voting has not started\");\n\n        require(\n            proposal.votingEndsAt > uint64(block.timestamp),\n            \"voting is closed on this proposal\"\n        );\n\n        require(\n            ballot != DataTypes.Ballot.Undefined,\n            \"ballot must be cast For, Against, or Abstain\"\n        );\n\n        DataTypes.VaultSnapshot[] memory vaultSnapshots = _vaultSnapshots[\n            proposalId\n        ];\n\n        DataTypes.VaultVotingPower[] memory uvp = votingPowerAggregator\n            .getVotingPower(\n                msg.sender,\n                proposal.createdAt,\n                _vaultAddresses(vaultSnapshots)\n            );\n\n        DataTypes.Ballot existingVote = _votes[msg.sender][proposalId];\n\n        bool isNewVote = existingVote == DataTypes.Ballot.Undefined;\n        for (uint256 i = 0; i < uvp.length; i++) {\n            DataTypes.VaultVotingPower memory vvp = uvp[i];\n\n            // cancel out the previous vote if it was cast\n            if (!isNewVote) {\n                (, uint256 prevBallotTotal) = _totals[proposalId][existingVote]\n                    .tryGet(vvp.vaultAddress);\n                _totals[proposalId][existingVote].set(\n                    vvp.vaultAddress,\n                    prevBallotTotal - vvp.votingPower\n                );\n            }\n\n            (, uint256 newBallotTotal) = _totals[proposalId][ballot].tryGet(\n                vvp.vaultAddress\n            );\n            _totals[proposalId][ballot].set(\n                vvp.vaultAddress,\n                newBallotTotal + vvp.votingPower\n            );\n        }\n\n        // Then update the record of this user's vote to the latest ballot and voting power\n        _votes[msg.sender][proposalId] = ballot;\n\n        emit VoteCast(proposalId, msg.sender, ballot);\n    }\n\n    function getVoteTotals(\n        uint16 proposalId\n    ) external view override returns (DataTypes.VoteTotals memory) {\n        return _toVoteTotals(_totals[proposalId]);\n    }\n\n    function _toVoteTotals(\n        mapping(DataTypes.Ballot => EnumerableMap.AddressToUintMap)\n            storage totals\n    ) internal view returns (DataTypes.VoteTotals memory) {\n        EnumerableMap.AddressToUintMap storage forVotingPower = totals[\n            DataTypes.Ballot.For\n        ];\n        DataTypes.VaultVotingPower[] memory forTotals = _toVotingPowers(\n            forVotingPower\n        );\n\n        EnumerableMap.AddressToUintMap storage againstVotingPower = totals[\n            DataTypes.Ballot.Against\n        ];\n        DataTypes.VaultVotingPower[] memory againstTotals = _toVotingPowers(\n            againstVotingPower\n        );\n\n        EnumerableMap.AddressToUintMap storage abstentionsVotingPower = totals[\n            DataTypes.Ballot.Abstain\n        ];\n        DataTypes.VaultVotingPower[] memory abstentionsTotals = _toVotingPowers(\n            abstentionsVotingPower\n        );\n\n        return\n            DataTypes.VoteTotals({\n                _for: forTotals,\n                against: againstTotals,\n                abstentions: abstentionsTotals\n            });\n    }\n\n    event ProposalTallied(\n        uint16 indexed proposalId,\n        DataTypes.Status status,\n        DataTypes.ProposalOutcome outcome\n    );\n\n    function tallyVote(uint16 proposalId) external override {\n        DataTypes.Proposal storage proposal = _proposals[proposalId];\n        require(proposal.createdAt != 0, \"proposal does not exist\");\n\n        require(\n            proposal.status == DataTypes.Status.Active &&\n                _activeProposals.contains(uint256(proposalId)),\n            \"proposal is not currently active\"\n        );\n\n        require(\n            uint64(block.timestamp) > proposal.votingEndsAt,\n            \"voting is ongoing for this proposal\"\n        );\n\n        (\n            uint256 forTotalPct,\n            uint256 againstTotalPct,\n            uint256 abstentionsTotalPct\n        ) = _getCurrentPercentages(proposal);\n\n        uint256 quorum = proposal.quorum;\n        uint256 voteThreshold = proposal.voteThreshold;\n        if (_isUpgradeabilityLimited(proposal.actionLevel)) {\n            DataTypes.Tier memory tier = _getLimitUpgradeabilityTier();\n            quorum = tier.quorum;\n            voteThreshold = tier.voteThreshold;\n        }\n\n        uint256 combinedPct = forTotalPct +\n            againstTotalPct +\n            abstentionsTotalPct;\n        if (combinedPct < quorum) {\n            proposal.status = DataTypes.Status.Rejected;\n            _activeProposals.remove(uint256(proposalId));\n            emit ProposalTallied(\n                proposalId,\n                proposal.status,\n                DataTypes.ProposalOutcome.QuorumNotMet\n            );\n            return;\n        }\n\n        uint256 result = 0;\n        if (forTotalPct + againstTotalPct > 0) {\n            result = forTotalPct.divDown(forTotalPct + againstTotalPct);\n        }\n        DataTypes.ProposalOutcome outcome = DataTypes.ProposalOutcome.Undefined;\n        if (result >= voteThreshold) {\n            proposal.status = DataTypes.Status.Queued;\n            outcome = DataTypes.ProposalOutcome.Successful;\n            _timelockedProposals.add(uint256(proposalId));\n        } else {\n            proposal.status = DataTypes.Status.Rejected;\n            outcome = DataTypes.ProposalOutcome.ThresholdNotMet;\n        }\n        _activeProposals.remove(uint256(proposalId));\n        emit ProposalTallied(proposalId, proposal.status, outcome);\n    }\n\n    function getCurrentPercentages(\n        uint16 proposalId\n    )\n        external\n        view\n        override\n        returns (uint256 for_, uint256 against, uint256 abstain)\n    {\n        DataTypes.Proposal storage proposal = _proposals[proposalId];\n        require(proposal.createdAt != 0, \"proposal does not exist\");\n        return _getCurrentPercentages(proposal);\n    }\n\n    function _getCurrentPercentages(\n        DataTypes.Proposal storage proposal\n    ) internal view returns (uint256 for_, uint256 against, uint256 abstain) {\n        DataTypes.VaultSnapshot[] memory snapshot = _vaultSnapshots[\n            proposal.id\n        ];\n        mapping(DataTypes.Ballot => EnumerableMap.AddressToUintMap)\n            storage propTotals = _totals[proposal.id];\n        for_ = snapshot.getBallotPercentage(propTotals[DataTypes.Ballot.For]);\n        against = snapshot.getBallotPercentage(\n            propTotals[DataTypes.Ballot.Against]\n        );\n        abstain = snapshot.getBallotPercentage(\n            propTotals[DataTypes.Ballot.Abstain]\n        );\n    }\n\n    function _toVotingPowers(\n        EnumerableMap.AddressToUintMap storage map\n    ) internal view returns (DataTypes.VaultVotingPower[] memory) {\n        DataTypes.VaultVotingPower[]\n            memory vvps = new DataTypes.VaultVotingPower[](map.length());\n        for (uint256 i = 0; i < map.length(); i++) {\n            (address key, uint256 value) = map.at(i);\n            vvps[i] = DataTypes.VaultVotingPower({\n                vaultAddress: key,\n                votingPower: value\n            });\n        }\n\n        return vvps;\n    }\n\n    event ProposalExecuted(uint16 indexed proposalId);\n\n    function executeProposal(uint16 proposalId) external override {\n        DataTypes.Proposal storage proposal = _proposals[proposalId];\n        if (proposal.createdAt == uint64(0)) {\n            revert(\"proposal does not exist\");\n        }\n\n        require(\n            proposal.status == DataTypes.Status.Queued &&\n                _timelockedProposals.contains(uint256(proposalId)) &&\n                uint64(block.timestamp) > proposal.executableAt,\n            \"proposal must be queued and ready to execute\"\n        );\n\n        for (uint256 i = 0; i < proposal.actions.length; i++) {\n            proposal.actions[i].target.functionCall(\n                proposal.actions[i].data,\n                \"proposal execution failed\"\n            );\n        }\n        proposal.status = DataTypes.Status.Executed;\n        _timelockedProposals.remove(uint256(proposalId));\n        emit ProposalExecuted(proposalId);\n    }\n\n    function createAndExecuteProposal(\n        DataTypes.ProposalAction[] calldata actions\n    ) external onlyMultisig {\n        uint16 proposalId = proposalsCount++;\n        DataTypes.Proposal storage p = _proposals[proposalId];\n        p.id = proposalId;\n        p.proposer = msg.sender;\n        p.createdAt = uint64(block.timestamp);\n        p.votingEndsAt = uint64(block.timestamp);\n        p.executableAt = uint64(block.timestamp);\n        p.status = DataTypes.Status.Executed;\n        p.quorum = 0;\n        p.voteThreshold = 0;\n\n        for (uint256 i = 0; i < actions.length; i++) {\n            DataTypes.ProposalAction memory action = actions[i];\n            p.actions.push(action);\n            action.target.functionCall(\n                action.data,\n                \"proposal execution failed\"\n            );\n        }\n        emit ProposalCreated(proposalId, msg.sender, actions);\n        emit ProposalExecuted(proposalId);\n    }\n\n    event ProposalVetoed(uint16 indexed proposalId);\n\n    function vetoProposal(uint16 proposalId) external onlyMultisig {\n        DataTypes.Proposal storage proposal = _proposals[proposalId];\n        require(proposal.createdAt > 0, \"proposal does not exist\");\n\n        require(\n            proposal.status == DataTypes.Status.Active ||\n                proposal.status == DataTypes.Status.Queued,\n            \"proposal must be active or queued\"\n        );\n\n        proposal.status = DataTypes.Status.Vetoed;\n        _activeProposals.remove(uint256(proposalId));\n        _timelockedProposals.remove(uint256(proposalId));\n\n        emit ProposalVetoed(proposalId);\n    }\n\n    event MultisigSunset();\n\n    function sunsetMultisig() external onlySelf {\n        multisigSunsetAt = block.timestamp;\n        emit MultisigSunset();\n    }\n\n    function getBallot(\n        address voter,\n        uint16 proposalId\n    ) external view returns (DataTypes.Ballot) {\n        return _votes[voter][proposalId];\n    }\n\n    function getProposal(\n        uint16 proposalId\n    ) external view returns (DataTypes.Proposal memory) {\n        return _proposals[proposalId];\n    }\n\n    function updateLimitUpgradeabilityParams(\n        DataTypes.LimitUpgradeabilityParameters memory _params\n    ) external onlySelf {\n        limitUpgradeabilityParams = _params;\n    }\n\n    function listActiveProposals()\n        external\n        view\n        returns (DataTypes.Proposal[] memory)\n    {\n        return _listProposals(_activeProposals.values());\n    }\n\n    function listTimelockedProposals()\n        external\n        view\n        returns (DataTypes.Proposal[] memory)\n    {\n        return _listProposals(_timelockedProposals.values());\n    }\n\n    function _listProposals(\n        uint256[] memory ids\n    ) internal view returns (DataTypes.Proposal[] memory) {\n        uint256 len = ids.length;\n        DataTypes.Proposal[] memory proposals = new DataTypes.Proposal[](len);\n        for (uint256 i = 0; i < len; i++) {\n            proposals[i] = _proposals[uint16(ids[i])];\n        }\n        return proposals;\n    }\n\n    function _vaultAddresses(\n        DataTypes.VaultSnapshot[] memory vaultSnapshots\n    ) internal pure returns (address[] memory) {\n        uint256 len = vaultSnapshots.length;\n        address[] memory vaultAddresses = new address[](len);\n        for (uint256 i = 0; i < len; i++) {\n            vaultAddresses[i] = vaultSnapshots[i].vaultAddress;\n        }\n        return vaultAddresses;\n    }\n\n    function _getTier(\n        DataTypes.ProposalAction[] memory actions\n    ) internal view returns (DataTypes.Tier memory tier) {\n        // Determine the tier associated with this proposal by taking the tier of the most impactful\n        // action, determined by the tier's actionLevel parameter.\n        DataTypes.ProposalAction memory action = actions[0];\n        tier = tierer.getTier(action.target, action.data);\n        for (uint256 i = 1; i < actions.length; i++) {\n            DataTypes.Tier memory currentTier = tierer.getTier(\n                actions[i].target,\n                actions[i].data\n            );\n            if (currentTier.actionLevel > tier.actionLevel) {\n                tier = currentTier;\n            }\n        }\n    }\n\n    function _isUpgradeabilityLimited(\n        uint8 actionLevel\n    ) internal view returns (bool) {\n        return\n            address(bGYD) != address(0) &&\n            bGYD.totalSupply() >= limitUpgradeabilityParams.minBGYDSupply &&\n            bGYD.boundedPctEMA() > limitUpgradeabilityParams.emaThreshold &&\n            actionLevel >= limitUpgradeabilityParams.actionLevelThreshold;\n    }\n\n    function _getLimitUpgradeabilityTier()\n        internal\n        view\n        returns (DataTypes.Tier memory)\n    {\n        // NOTE: tierStrategy is always static, so the calldata is unused\n        return\n            ITierStrategy(limitUpgradeabilityParams.tierStrategy).getTier(\"\");\n    }\n}\n"
      },
      "Address.sol": {
        "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.8.0) (utils/Address.sol)\n\npragma solidity ^0.8.1;\n\n/**\n * @dev Collection of functions related to the address type\n */\nlibrary Address {\n    /**\n     * @dev Returns true if `account` is a contract.\n     *\n     * [IMPORTANT]\n     * ====\n     * It is unsafe to assume that an address for which this function returns\n     * false is an externally-owned account (EOA) and not a contract.\n     *\n     * Among others, `isContract` will return false for the following\n     * types of addresses:\n     *\n     *  - an externally-owned account\n     *  - a contract in construction\n     *  - an address where a contract will be created\n     *  - an address where a contract lived, but was destroyed\n     * ====\n     *\n     * [IMPORTANT]\n     * ====\n     * You shouldn't rely on `isContract` to protect against flash loan attacks!\n     *\n     * Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets\n     * like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract\n     * constructor.\n     * ====\n     */\n    function isContract(address account) internal view returns (bool) {\n        // This method relies on extcodesize/address.code.length, which returns 0\n        // for contracts in construction, since the code is only stored at the end\n        // of the constructor execution.\n\n        return account.code.length > 0;\n    }\n\n    /**\n     * @dev Replacement for Solidity's `transfer`: sends `amount` wei to\n     * `recipient`, forwarding all available gas and reverting on errors.\n     *\n     * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost\n     * of certain opcodes, possibly making contracts go over the 2300 gas limit\n     * imposed by `transfer`, making them unable to receive funds via\n     * `transfer`. {sendValue} removes this limitation.\n     *\n     * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more].\n     *\n     * IMPORTANT: because control is transferred to `recipient`, care must be\n     * taken to not create reentrancy vulnerabilities. Consider using\n     * {ReentrancyGuard} or the\n     * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].\n     */\n    function sendValue(address payable recipient, uint256 amount) internal {\n        require(address(this).balance >= amount, \"Address: insufficient balance\");\n\n        (bool success, ) = recipient.call{value: amount}(\"\");\n        require(success, \"Address: unable to send value, recipient may have reverted\");\n    }\n\n    /**\n     * @dev Performs a Solidity function call using a low level `call`. A\n     * plain `call` is an unsafe replacement for a function call: use this\n     * function instead.\n     *\n     * If `target` reverts with a revert reason, it is bubbled up by this\n     * function (like regular Solidity function calls).\n     *\n     * Returns the raw returned data. To convert to the expected return value,\n     * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].\n     *\n     * Requirements:\n     *\n     * - `target` must be a contract.\n     * - calling `target` with `data` must not revert.\n     *\n     * _Available since v3.1._\n     */\n    function functionCall(address target, bytes memory data) internal returns (bytes memory) {\n        return functionCallWithValue(target, data, 0, \"Address: low-level call failed\");\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with\n     * `errorMessage` as a fallback revert reason when `target` reverts.\n     *\n     * _Available since v3.1._\n     */\n    function functionCall(\n        address target,\n        bytes memory data,\n        string memory errorMessage\n    ) internal returns (bytes memory) {\n        return functionCallWithValue(target, data, 0, errorMessage);\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],\n     * but also transferring `value` wei to `target`.\n     *\n     * Requirements:\n     *\n     * - the calling contract must have an ETH balance of at least `value`.\n     * - the called Solidity function must be `payable`.\n     *\n     * _Available since v3.1._\n     */\n    function functionCallWithValue(\n        address target,\n        bytes memory data,\n        uint256 value\n    ) internal returns (bytes memory) {\n        return functionCallWithValue(target, data, value, \"Address: low-level call with value failed\");\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but\n     * with `errorMessage` as a fallback revert reason when `target` reverts.\n     *\n     * _Available since v3.1._\n     */\n    function functionCallWithValue(\n        address target,\n        bytes memory data,\n        uint256 value,\n        string memory errorMessage\n    ) internal returns (bytes memory) {\n        require(address(this).balance >= value, \"Address: insufficient balance for call\");\n        (bool success, bytes memory returndata) = target.call{value: value}(data);\n        return verifyCallResultFromTarget(target, success, returndata, errorMessage);\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],\n     * but performing a static call.\n     *\n     * _Available since v3.3._\n     */\n    function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {\n        return functionStaticCall(target, data, \"Address: low-level static call failed\");\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],\n     * but performing a static call.\n     *\n     * _Available since v3.3._\n     */\n    function functionStaticCall(\n        address target,\n        bytes memory data,\n        string memory errorMessage\n    ) internal view returns (bytes memory) {\n        (bool success, bytes memory returndata) = target.staticcall(data);\n        return verifyCallResultFromTarget(target, success, returndata, errorMessage);\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],\n     * but performing a delegate call.\n     *\n     * _Available since v3.4._\n     */\n    function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {\n        return functionDelegateCall(target, data, \"Address: low-level delegate call failed\");\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],\n     * but performing a delegate call.\n     *\n     * _Available since v3.4._\n     */\n    function functionDelegateCall(\n        address target,\n        bytes memory data,\n        string memory errorMessage\n    ) internal returns (bytes memory) {\n        (bool success, bytes memory returndata) = target.delegatecall(data);\n        return verifyCallResultFromTarget(target, success, returndata, errorMessage);\n    }\n\n    /**\n     * @dev Tool to verify that a low level call to smart-contract was successful, and revert (either by bubbling\n     * the revert reason or using the provided one) in case of unsuccessful call or if target was not a contract.\n     *\n     * _Available since v4.8._\n     */\n    function verifyCallResultFromTarget(\n        address target,\n        bool success,\n        bytes memory returndata,\n        string memory errorMessage\n    ) internal view returns (bytes memory) {\n        if (success) {\n            if (returndata.length == 0) {\n                // only check isContract if the call was successful and the return data is empty\n                // otherwise we already know that it was a contract\n                require(isContract(target), \"Address: call to non-contract\");\n            }\n            return returndata;\n        } else {\n            _revert(returndata, errorMessage);\n        }\n    }\n\n    /**\n     * @dev Tool to verify that a low level call was successful, and revert if it wasn't, either by bubbling the\n     * revert reason or using the provided one.\n     *\n     * _Available since v4.3._\n     */\n    function verifyCallResult(\n        bool success,\n        bytes memory returndata,\n        string memory errorMessage\n    ) internal pure returns (bytes memory) {\n        if (success) {\n            return returndata;\n        } else {\n            _revert(returndata, errorMessage);\n        }\n    }\n\n    function _revert(bytes memory returndata, string memory errorMessage) private pure {\n        // Look for revert reason and bubble it up if present\n        if (returndata.length > 0) {\n            // The easiest way to bubble the revert reason is using memory via assembly\n            /// @solidity memory-safe-assembly\n            assembly {\n                let returndata_size := mload(returndata)\n                revert(add(32, returndata), returndata_size)\n            }\n        } else {\n            revert(errorMessage);\n        }\n    }\n}\n"
      },
      "EnumerableSet.sol": {
        "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.8.0) (utils/structs/EnumerableSet.sol)\n// This file was procedurally generated from scripts/generate/templates/EnumerableSet.js.\n\npragma solidity ^0.8.0;\n\n/**\n * @dev Library for managing\n * https://en.wikipedia.org/wiki/Set_(abstract_data_type)[sets] of primitive\n * types.\n *\n * Sets have the following properties:\n *\n * - Elements are added, removed, and checked for existence in constant time\n * (O(1)).\n * - Elements are enumerated in O(n). No guarantees are made on the ordering.\n *\n * ```\n * contract Example {\n *     // Add the library methods\n *     using EnumerableSet for EnumerableSet.AddressSet;\n *\n *     // Declare a set state variable\n *     EnumerableSet.AddressSet private mySet;\n * }\n * ```\n *\n * As of v3.3.0, sets of type `bytes32` (`Bytes32Set`), `address` (`AddressSet`)\n * and `uint256` (`UintSet`) are supported.\n *\n * [WARNING]\n * ====\n * Trying to delete such a structure from storage will likely result in data corruption, rendering the structure\n * unusable.\n * See https://github.com/ethereum/solidity/pull/11843[ethereum/solidity#11843] for more info.\n *\n * In order to clean an EnumerableSet, you can either remove all elements one by one or create a fresh instance using an\n * array of EnumerableSet.\n * ====\n */\nlibrary EnumerableSet {\n    // To implement this library for multiple types with as little code\n    // repetition as possible, we write it in terms of a generic Set type with\n    // bytes32 values.\n    // The Set implementation uses private functions, and user-facing\n    // implementations (such as AddressSet) are just wrappers around the\n    // underlying Set.\n    // This means that we can only create new EnumerableSets for types that fit\n    // in bytes32.\n\n    struct Set {\n        // Storage of set values\n        bytes32[] _values;\n        // Position of the value in the `values` array, plus 1 because index 0\n        // means a value is not in the set.\n        mapping(bytes32 => uint256) _indexes;\n    }\n\n    /**\n     * @dev Add a value to a set. O(1).\n     *\n     * Returns true if the value was added to the set, that is if it was not\n     * already present.\n     */\n    function _add(Set storage set, bytes32 value) private returns (bool) {\n        if (!_contains(set, value)) {\n            set._values.push(value);\n            // The value is stored at length-1, but we add 1 to all indexes\n            // and use 0 as a sentinel value\n            set._indexes[value] = set._values.length;\n            return true;\n        } else {\n            return false;\n        }\n    }\n\n    /**\n     * @dev Removes a value from a set. O(1).\n     *\n     * Returns true if the value was removed from the set, that is if it was\n     * present.\n     */\n    function _remove(Set storage set, bytes32 value) private returns (bool) {\n        // We read and store the value's index to prevent multiple reads from the same storage slot\n        uint256 valueIndex = set._indexes[value];\n\n        if (valueIndex != 0) {\n            // Equivalent to contains(set, value)\n            // To delete an element from the _values array in O(1), we swap the element to delete with the last one in\n            // the array, and then remove the last element (sometimes called as 'swap and pop').\n            // This modifies the order of the array, as noted in {at}.\n\n            uint256 toDeleteIndex = valueIndex - 1;\n            uint256 lastIndex = set._values.length - 1;\n\n            if (lastIndex != toDeleteIndex) {\n                bytes32 lastValue = set._values[lastIndex];\n\n                // Move the last value to the index where the value to delete is\n                set._values[toDeleteIndex] = lastValue;\n                // Update the index for the moved value\n                set._indexes[lastValue] = valueIndex; // Replace lastValue's index to valueIndex\n            }\n\n            // Delete the slot where the moved value was stored\n            set._values.pop();\n\n            // Delete the index for the deleted slot\n            delete set._indexes[value];\n\n            return true;\n        } else {\n            return false;\n        }\n    }\n\n    /**\n     * @dev Returns true if the value is in the set. O(1).\n     */\n    function _contains(Set storage set, bytes32 value) private view returns (bool) {\n        return set._indexes[value] != 0;\n    }\n\n    /**\n     * @dev Returns the number of values on the set. O(1).\n     */\n    function _length(Set storage set) private view returns (uint256) {\n        return set._values.length;\n    }\n\n    /**\n     * @dev Returns the value stored at position `index` in the set. O(1).\n     *\n     * Note that there are no guarantees on the ordering of values inside the\n     * array, and it may change when more values are added or removed.\n     *\n     * Requirements:\n     *\n     * - `index` must be strictly less than {length}.\n     */\n    function _at(Set storage set, uint256 index) private view returns (bytes32) {\n        return set._values[index];\n    }\n\n    /**\n     * @dev Return the entire set in an array\n     *\n     * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed\n     * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that\n     * this function has an unbounded cost, and using it as part of a state-changing function may render the function\n     * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.\n     */\n    function _values(Set storage set) private view returns (bytes32[] memory) {\n        return set._values;\n    }\n\n    // Bytes32Set\n\n    struct Bytes32Set {\n        Set _inner;\n    }\n\n    /**\n     * @dev Add a value to a set. O(1).\n     *\n     * Returns true if the value was added to the set, that is if it was not\n     * already present.\n     */\n    function add(Bytes32Set storage set, bytes32 value) internal returns (bool) {\n        return _add(set._inner, value);\n    }\n\n    /**\n     * @dev Removes a value from a set. O(1).\n     *\n     * Returns true if the value was removed from the set, that is if it was\n     * present.\n     */\n    function remove(Bytes32Set storage set, bytes32 value) internal returns (bool) {\n        return _remove(set._inner, value);\n    }\n\n    /**\n     * @dev Returns true if the value is in the set. O(1).\n     */\n    function contains(Bytes32Set storage set, bytes32 value) internal view returns (bool) {\n        return _contains(set._inner, value);\n    }\n\n    /**\n     * @dev Returns the number of values in the set. O(1).\n     */\n    function length(Bytes32Set storage set) internal view returns (uint256) {\n        return _length(set._inner);\n    }\n\n    /**\n     * @dev Returns the value stored at position `index` in the set. O(1).\n     *\n     * Note that there are no guarantees on the ordering of values inside the\n     * array, and it may change when more values are added or removed.\n     *\n     * Requirements:\n     *\n     * - `index` must be strictly less than {length}.\n     */\n    function at(Bytes32Set storage set, uint256 index) internal view returns (bytes32) {\n        return _at(set._inner, index);\n    }\n\n    /**\n     * @dev Return the entire set in an array\n     *\n     * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed\n     * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that\n     * this function has an unbounded cost, and using it as part of a state-changing function may render the function\n     * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.\n     */\n    function values(Bytes32Set storage set) internal view returns (bytes32[] memory) {\n        bytes32[] memory store = _values(set._inner);\n        bytes32[] memory result;\n\n        /// @solidity memory-safe-assembly\n        assembly {\n            result := store\n        }\n\n        return result;\n    }\n\n    // AddressSet\n\n    struct AddressSet {\n        Set _inner;\n    }\n\n    /**\n     * @dev Add a value to a set. O(1).\n     *\n     * Returns true if the value was added to the set, that is if it was not\n     * already present.\n     */\n    function add(AddressSet storage set, address value) internal returns (bool) {\n        return _add(set._inner, bytes32(uint256(uint160(value))));\n    }\n\n    /**\n     * @dev Removes a value from a set. O(1).\n     *\n     * Returns true if the value was removed from the set, that is if it was\n     * present.\n     */\n    function remove(AddressSet storage set, address value) internal returns (bool) {\n        return _remove(set._inner, bytes32(uint256(uint160(value))));\n    }\n\n    /**\n     * @dev Returns true if the value is in the set. O(1).\n     */\n    function contains(AddressSet storage set, address value) internal view returns (bool) {\n        return _contains(set._inner, bytes32(uint256(uint160(value))));\n    }\n\n    /**\n     * @dev Returns the number of values in the set. O(1).\n     */\n    function length(AddressSet storage set) internal view returns (uint256) {\n        return _length(set._inner);\n    }\n\n    /**\n     * @dev Returns the value stored at position `index` in the set. O(1).\n     *\n     * Note that there are no guarantees on the ordering of values inside the\n     * array, and it may change when more values are added or removed.\n     *\n     * Requirements:\n     *\n     * - `index` must be strictly less than {length}.\n     */\n    function at(AddressSet storage set, uint256 index) internal view returns (address) {\n        return address(uint160(uint256(_at(set._inner, index))));\n    }\n\n    /**\n     * @dev Return the entire set in an array\n     *\n     * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed\n     * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that\n     * this function has an unbounded cost, and using it as part of a state-changing function may render the function\n     * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.\n     */\n    function values(AddressSet storage set) internal view returns (address[] memory) {\n        bytes32[] memory store = _values(set._inner);\n        address[] memory result;\n\n        /// @solidity memory-safe-assembly\n        assembly {\n            result := store\n        }\n\n        return result;\n    }\n\n    // UintSet\n\n    struct UintSet {\n        Set _inner;\n    }\n\n    /**\n     * @dev Add a value to a set. O(1).\n     *\n     * Returns true if the value was added to the set, that is if it was not\n     * already present.\n     */\n    function add(UintSet storage set, uint256 value) internal returns (bool) {\n        return _add(set._inner, bytes32(value));\n    }\n\n    /**\n     * @dev Removes a value from a set. O(1).\n     *\n     * Returns true if the value was removed from the set, that is if it was\n     * present.\n     */\n    function remove(UintSet storage set, uint256 value) internal returns (bool) {\n        return _remove(set._inner, bytes32(value));\n    }\n\n    /**\n     * @dev Returns true if the value is in the set. O(1).\n     */\n    function contains(UintSet storage set, uint256 value) internal view returns (bool) {\n        return _contains(set._inner, bytes32(value));\n    }\n\n    /**\n     * @dev Returns the number of values in the set. O(1).\n     */\n    function length(UintSet storage set) internal view returns (uint256) {\n        return _length(set._inner);\n    }\n\n    /**\n     * @dev Returns the value stored at position `index` in the set. O(1).\n     *\n     * Note that there are no guarantees on the ordering of values inside the\n     * array, and it may change when more values are added or removed.\n     *\n     * Requirements:\n     *\n     * - `index` must be strictly less than {length}.\n     */\n    function at(UintSet storage set, uint256 index) internal view returns (uint256) {\n        return uint256(_at(set._inner, index));\n    }\n\n    /**\n     * @dev Return the entire set in an array\n     *\n     * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed\n     * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that\n     * this function has an unbounded cost, and using it as part of a state-changing function may render the function\n     * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.\n     */\n    function values(UintSet storage set) internal view returns (uint256[] memory) {\n        bytes32[] memory store = _values(set._inner);\n        uint256[] memory result;\n\n        /// @solidity memory-safe-assembly\n        assembly {\n            result := store\n        }\n\n        return result;\n    }\n}\n"
      },
      "EnumerableMap.sol": {
        "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.8.0) (utils/structs/EnumerableMap.sol)\n// This file was procedurally generated from scripts/generate/templates/EnumerableMap.js.\n\npragma solidity ^0.8.0;\n\nimport \"EnumerableSet.sol\";\n\n/**\n * @dev Library for managing an enumerable variant of Solidity's\n * https://solidity.readthedocs.io/en/latest/types.html#mapping-types[`mapping`]\n * type.\n *\n * Maps have the following properties:\n *\n * - Entries are added, removed, and checked for existence in constant time\n * (O(1)).\n * - Entries are enumerated in O(n). No guarantees are made on the ordering.\n *\n * ```\n * contract Example {\n *     // Add the library methods\n *     using EnumerableMap for EnumerableMap.UintToAddressMap;\n *\n *     // Declare a set state variable\n *     EnumerableMap.UintToAddressMap private myMap;\n * }\n * ```\n *\n * The following map types are supported:\n *\n * - `uint256 -> address` (`UintToAddressMap`) since v3.0.0\n * - `address -> uint256` (`AddressToUintMap`) since v4.6.0\n * - `bytes32 -> bytes32` (`Bytes32ToBytes32Map`) since v4.6.0\n * - `uint256 -> uint256` (`UintToUintMap`) since v4.7.0\n * - `bytes32 -> uint256` (`Bytes32ToUintMap`) since v4.7.0\n *\n * [WARNING]\n * ====\n * Trying to delete such a structure from storage will likely result in data corruption, rendering the structure\n * unusable.\n * See https://github.com/ethereum/solidity/pull/11843[ethereum/solidity#11843] for more info.\n *\n * In order to clean an EnumerableMap, you can either remove all elements one by one or create a fresh instance using an\n * array of EnumerableMap.\n * ====\n */\nlibrary EnumerableMap {\n    using EnumerableSet for EnumerableSet.Bytes32Set;\n\n    // To implement this library for multiple types with as little code\n    // repetition as possible, we write it in terms of a generic Map type with\n    // bytes32 keys and values.\n    // The Map implementation uses private functions, and user-facing\n    // implementations (such as Uint256ToAddressMap) are just wrappers around\n    // the underlying Map.\n    // This means that we can only create new EnumerableMaps for types that fit\n    // in bytes32.\n\n    struct Bytes32ToBytes32Map {\n        // Storage of keys\n        EnumerableSet.Bytes32Set _keys;\n        mapping(bytes32 => bytes32) _values;\n    }\n\n    /**\n     * @dev Adds a key-value pair to a map, or updates the value for an existing\n     * key. O(1).\n     *\n     * Returns true if the key was added to the map, that is if it was not\n     * already present.\n     */\n    function set(\n        Bytes32ToBytes32Map storage map,\n        bytes32 key,\n        bytes32 value\n    ) internal returns (bool) {\n        map._values[key] = value;\n        return map._keys.add(key);\n    }\n\n    /**\n     * @dev Removes a key-value pair from a map. O(1).\n     *\n     * Returns true if the key was removed from the map, that is if it was present.\n     */\n    function remove(Bytes32ToBytes32Map storage map, bytes32 key) internal returns (bool) {\n        delete map._values[key];\n        return map._keys.remove(key);\n    }\n\n    /**\n     * @dev Returns true if the key is in the map. O(1).\n     */\n    function contains(Bytes32ToBytes32Map storage map, bytes32 key) internal view returns (bool) {\n        return map._keys.contains(key);\n    }\n\n    /**\n     * @dev Returns the number of key-value pairs in the map. O(1).\n     */\n    function length(Bytes32ToBytes32Map storage map) internal view returns (uint256) {\n        return map._keys.length();\n    }\n\n    /**\n     * @dev Returns the key-value pair stored at position `index` in the map. O(1).\n     *\n     * Note that there are no guarantees on the ordering of entries inside the\n     * array, and it may change when more entries are added or removed.\n     *\n     * Requirements:\n     *\n     * - `index` must be strictly less than {length}.\n     */\n    function at(Bytes32ToBytes32Map storage map, uint256 index) internal view returns (bytes32, bytes32) {\n        bytes32 key = map._keys.at(index);\n        return (key, map._values[key]);\n    }\n\n    /**\n     * @dev Tries to returns the value associated with `key`. O(1).\n     * Does not revert if `key` is not in the map.\n     */\n    function tryGet(Bytes32ToBytes32Map storage map, bytes32 key) internal view returns (bool, bytes32) {\n        bytes32 value = map._values[key];\n        if (value == bytes32(0)) {\n            return (contains(map, key), bytes32(0));\n        } else {\n            return (true, value);\n        }\n    }\n\n    /**\n     * @dev Returns the value associated with `key`. O(1).\n     *\n     * Requirements:\n     *\n     * - `key` must be in the map.\n     */\n    function get(Bytes32ToBytes32Map storage map, bytes32 key) internal view returns (bytes32) {\n        bytes32 value = map._values[key];\n        require(value != 0 || contains(map, key), \"EnumerableMap: nonexistent key\");\n        return value;\n    }\n\n    /**\n     * @dev Same as {get}, with a custom error message when `key` is not in the map.\n     *\n     * CAUTION: This function is deprecated because it requires allocating memory for the error\n     * message unnecessarily. For custom revert reasons use {tryGet}.\n     */\n    function get(\n        Bytes32ToBytes32Map storage map,\n        bytes32 key,\n        string memory errorMessage\n    ) internal view returns (bytes32) {\n        bytes32 value = map._values[key];\n        require(value != 0 || contains(map, key), errorMessage);\n        return value;\n    }\n\n    // UintToUintMap\n\n    struct UintToUintMap {\n        Bytes32ToBytes32Map _inner;\n    }\n\n    /**\n     * @dev Adds a key-value pair to a map, or updates the value for an existing\n     * key. O(1).\n     *\n     * Returns true if the key was added to the map, that is if it was not\n     * already present.\n     */\n    function set(\n        UintToUintMap storage map,\n        uint256 key,\n        uint256 value\n    ) internal returns (bool) {\n        return set(map._inner, bytes32(key), bytes32(value));\n    }\n\n    /**\n     * @dev Removes a value from a set. O(1).\n     *\n     * Returns true if the key was removed from the map, that is if it was present.\n     */\n    function remove(UintToUintMap storage map, uint256 key) internal returns (bool) {\n        return remove(map._inner, bytes32(key));\n    }\n\n    /**\n     * @dev Returns true if the key is in the map. O(1).\n     */\n    function contains(UintToUintMap storage map, uint256 key) internal view returns (bool) {\n        return contains(map._inner, bytes32(key));\n    }\n\n    /**\n     * @dev Returns the number of elements in the map. O(1).\n     */\n    function length(UintToUintMap storage map) internal view returns (uint256) {\n        return length(map._inner);\n    }\n\n    /**\n     * @dev Returns the element stored at position `index` in the set. O(1).\n     * Note that there are no guarantees on the ordering of values inside the\n     * array, and it may change when more values are added or removed.\n     *\n     * Requirements:\n     *\n     * - `index` must be strictly less than {length}.\n     */\n    function at(UintToUintMap storage map, uint256 index) internal view returns (uint256, uint256) {\n        (bytes32 key, bytes32 value) = at(map._inner, index);\n        return (uint256(key), uint256(value));\n    }\n\n    /**\n     * @dev Tries to returns the value associated with `key`. O(1).\n     * Does not revert if `key` is not in the map.\n     */\n    function tryGet(UintToUintMap storage map, uint256 key) internal view returns (bool, uint256) {\n        (bool success, bytes32 value) = tryGet(map._inner, bytes32(key));\n        return (success, uint256(value));\n    }\n\n    /**\n     * @dev Returns the value associated with `key`. O(1).\n     *\n     * Requirements:\n     *\n     * - `key` must be in the map.\n     */\n    function get(UintToUintMap storage map, uint256 key) internal view returns (uint256) {\n        return uint256(get(map._inner, bytes32(key)));\n    }\n\n    /**\n     * @dev Same as {get}, with a custom error message when `key` is not in the map.\n     *\n     * CAUTION: This function is deprecated because it requires allocating memory for the error\n     * message unnecessarily. For custom revert reasons use {tryGet}.\n     */\n    function get(\n        UintToUintMap storage map,\n        uint256 key,\n        string memory errorMessage\n    ) internal view returns (uint256) {\n        return uint256(get(map._inner, bytes32(key), errorMessage));\n    }\n\n    // UintToAddressMap\n\n    struct UintToAddressMap {\n        Bytes32ToBytes32Map _inner;\n    }\n\n    /**\n     * @dev Adds a key-value pair to a map, or updates the value for an existing\n     * key. O(1).\n     *\n     * Returns true if the key was added to the map, that is if it was not\n     * already present.\n     */\n    function set(\n        UintToAddressMap storage map,\n        uint256 key,\n        address value\n    ) internal returns (bool) {\n        return set(map._inner, bytes32(key), bytes32(uint256(uint160(value))));\n    }\n\n    /**\n     * @dev Removes a value from a set. O(1).\n     *\n     * Returns true if the key was removed from the map, that is if it was present.\n     */\n    function remove(UintToAddressMap storage map, uint256 key) internal returns (bool) {\n        return remove(map._inner, bytes32(key));\n    }\n\n    /**\n     * @dev Returns true if the key is in the map. O(1).\n     */\n    function contains(UintToAddressMap storage map, uint256 key) internal view returns (bool) {\n        return contains(map._inner, bytes32(key));\n    }\n\n    /**\n     * @dev Returns the number of elements in the map. O(1).\n     */\n    function length(UintToAddressMap storage map) internal view returns (uint256) {\n        return length(map._inner);\n    }\n\n    /**\n     * @dev Returns the element stored at position `index` in the set. O(1).\n     * Note that there are no guarantees on the ordering of values inside the\n     * array, and it may change when more values are added or removed.\n     *\n     * Requirements:\n     *\n     * - `index` must be strictly less than {length}.\n     */\n    function at(UintToAddressMap storage map, uint256 index) internal view returns (uint256, address) {\n        (bytes32 key, bytes32 value) = at(map._inner, index);\n        return (uint256(key), address(uint160(uint256(value))));\n    }\n\n    /**\n     * @dev Tries to returns the value associated with `key`. O(1).\n     * Does not revert if `key` is not in the map.\n     */\n    function tryGet(UintToAddressMap storage map, uint256 key) internal view returns (bool, address) {\n        (bool success, bytes32 value) = tryGet(map._inner, bytes32(key));\n        return (success, address(uint160(uint256(value))));\n    }\n\n    /**\n     * @dev Returns the value associated with `key`. O(1).\n     *\n     * Requirements:\n     *\n     * - `key` must be in the map.\n     */\n    function get(UintToAddressMap storage map, uint256 key) internal view returns (address) {\n        return address(uint160(uint256(get(map._inner, bytes32(key)))));\n    }\n\n    /**\n     * @dev Same as {get}, with a custom error message when `key` is not in the map.\n     *\n     * CAUTION: This function is deprecated because it requires allocating memory for the error\n     * message unnecessarily. For custom revert reasons use {tryGet}.\n     */\n    function get(\n        UintToAddressMap storage map,\n        uint256 key,\n        string memory errorMessage\n    ) internal view returns (address) {\n        return address(uint160(uint256(get(map._inner, bytes32(key), errorMessage))));\n    }\n\n    // AddressToUintMap\n\n    struct AddressToUintMap {\n        Bytes32ToBytes32Map _inner;\n    }\n\n    /**\n     * @dev Adds a key-value pair to a map, or updates the value for an existing\n     * key. O(1).\n     *\n     * Returns true if the key was added to the map, that is if it was not\n     * already present.\n     */\n    function set(\n        AddressToUintMap storage map,\n        address key,\n        uint256 value\n    ) internal returns (bool) {\n        return set(map._inner, bytes32(uint256(uint160(key))), bytes32(value));\n    }\n\n    /**\n     * @dev Removes a value from a set. O(1).\n     *\n     * Returns true if the key was removed from the map, that is if it was present.\n     */\n    function remove(AddressToUintMap storage map, address key) internal returns (bool) {\n        return remove(map._inner, bytes32(uint256(uint160(key))));\n    }\n\n    /**\n     * @dev Returns true if the key is in the map. O(1).\n     */\n    function contains(AddressToUintMap storage map, address key) internal view returns (bool) {\n        return contains(map._inner, bytes32(uint256(uint160(key))));\n    }\n\n    /**\n     * @dev Returns the number of elements in the map. O(1).\n     */\n    function length(AddressToUintMap storage map) internal view returns (uint256) {\n        return length(map._inner);\n    }\n\n    /**\n     * @dev Returns the element stored at position `index` in the set. O(1).\n     * Note that there are no guarantees on the ordering of values inside the\n     * array, and it may change when more values are added or removed.\n     *\n     * Requirements:\n     *\n     * - `index` must be strictly less than {length}.\n     */\n    function at(AddressToUintMap storage map, uint256 index) internal view returns (address, uint256) {\n        (bytes32 key, bytes32 value) = at(map._inner, index);\n        return (address(uint160(uint256(key))), uint256(value));\n    }\n\n    /**\n     * @dev Tries to returns the value associated with `key`. O(1).\n     * Does not revert if `key` is not in the map.\n     */\n    function tryGet(AddressToUintMap storage map, address key) internal view returns (bool, uint256) {\n        (bool success, bytes32 value) = tryGet(map._inner, bytes32(uint256(uint160(key))));\n        return (success, uint256(value));\n    }\n\n    /**\n     * @dev Returns the value associated with `key`. O(1).\n     *\n     * Requirements:\n     *\n     * - `key` must be in the map.\n     */\n    function get(AddressToUintMap storage map, address key) internal view returns (uint256) {\n        return uint256(get(map._inner, bytes32(uint256(uint160(key)))));\n    }\n\n    /**\n     * @dev Same as {get}, with a custom error message when `key` is not in the map.\n     *\n     * CAUTION: This function is deprecated because it requires allocating memory for the error\n     * message unnecessarily. For custom revert reasons use {tryGet}.\n     */\n    function get(\n        AddressToUintMap storage map,\n        address key,\n        string memory errorMessage\n    ) internal view returns (uint256) {\n        return uint256(get(map._inner, bytes32(uint256(uint160(key))), errorMessage));\n    }\n\n    // Bytes32ToUintMap\n\n    struct Bytes32ToUintMap {\n        Bytes32ToBytes32Map _inner;\n    }\n\n    /**\n     * @dev Adds a key-value pair to a map, or updates the value for an existing\n     * key. O(1).\n     *\n     * Returns true if the key was added to the map, that is if it was not\n     * already present.\n     */\n    function set(\n        Bytes32ToUintMap storage map,\n        bytes32 key,\n        uint256 value\n    ) internal returns (bool) {\n        return set(map._inner, key, bytes32(value));\n    }\n\n    /**\n     * @dev Removes a value from a set. O(1).\n     *\n     * Returns true if the key was removed from the map, that is if it was present.\n     */\n    function remove(Bytes32ToUintMap storage map, bytes32 key) internal returns (bool) {\n        return remove(map._inner, key);\n    }\n\n    /**\n     * @dev Returns true if the key is in the map. O(1).\n     */\n    function contains(Bytes32ToUintMap storage map, bytes32 key) internal view returns (bool) {\n        return contains(map._inner, key);\n    }\n\n    /**\n     * @dev Returns the number of elements in the map. O(1).\n     */\n    function length(Bytes32ToUintMap storage map) internal view returns (uint256) {\n        return length(map._inner);\n    }\n\n    /**\n     * @dev Returns the element stored at position `index` in the set. O(1).\n     * Note that there are no guarantees on the ordering of values inside the\n     * array, and it may change when more values are added or removed.\n     *\n     * Requirements:\n     *\n     * - `index` must be strictly less than {length}.\n     */\n    function at(Bytes32ToUintMap storage map, uint256 index) internal view returns (bytes32, uint256) {\n        (bytes32 key, bytes32 value) = at(map._inner, index);\n        return (key, uint256(value));\n    }\n\n    /**\n     * @dev Tries to returns the value associated with `key`. O(1).\n     * Does not revert if `key` is not in the map.\n     */\n    function tryGet(Bytes32ToUintMap storage map, bytes32 key) internal view returns (bool, uint256) {\n        (bool success, bytes32 value) = tryGet(map._inner, key);\n        return (success, uint256(value));\n    }\n\n    /**\n     * @dev Returns the value associated with `key`. O(1).\n     *\n     * Requirements:\n     *\n     * - `key` must be in the map.\n     */\n    function get(Bytes32ToUintMap storage map, bytes32 key) internal view returns (uint256) {\n        return uint256(get(map._inner, key));\n    }\n\n    /**\n     * @dev Same as {get}, with a custom error message when `key` is not in the map.\n     *\n     * CAUTION: This function is deprecated because it requires allocating memory for the error\n     * message unnecessarily. For custom revert reasons use {tryGet}.\n     */\n    function get(\n        Bytes32ToUintMap storage map,\n        bytes32 key,\n        string memory errorMessage\n    ) internal view returns (uint256) {\n        return uint256(get(map._inner, key, errorMessage));\n    }\n}\n"
      },
      "Initializable.sol": {
        "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.8.0) (proxy/utils/Initializable.sol)\n\npragma solidity ^0.8.2;\n\nimport \"Address.sol\";\n\n/**\n * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed\n * behind a proxy. Since proxied contracts do not make use of a constructor, it's common to move constructor logic to an\n * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer\n * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect.\n *\n * The initialization functions use a version number. Once a version number is used, it is consumed and cannot be\n * reused. This mechanism prevents re-execution of each \"step\" but allows the creation of new initialization steps in\n * case an upgrade adds a module that needs to be initialized.\n *\n * For example:\n *\n * [.hljs-theme-light.nopadding]\n * ```\n * contract MyToken is ERC20Upgradeable {\n *     function initialize() initializer public {\n *         __ERC20_init(\"MyToken\", \"MTK\");\n *     }\n * }\n * contract MyTokenV2 is MyToken, ERC20PermitUpgradeable {\n *     function initializeV2() reinitializer(2) public {\n *         __ERC20Permit_init(\"MyToken\");\n *     }\n * }\n * ```\n *\n * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as\n * possible by providing the encoded function call as the `_data` argument to {ERC1967Proxy-constructor}.\n *\n * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure\n * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity.\n *\n * [CAUTION]\n * ====\n * Avoid leaving a contract uninitialized.\n *\n * An uninitialized contract can be taken over by an attacker. This applies to both a proxy and its implementation\n * contract, which may impact the proxy. To prevent the implementation contract from being used, you should invoke\n * the {_disableInitializers} function in the constructor to automatically lock it when it is deployed:\n *\n * [.hljs-theme-light.nopadding]\n * ```\n * /// @custom:oz-upgrades-unsafe-allow constructor\n * constructor() {\n *     _disableInitializers();\n * }\n * ```\n * ====\n */\nabstract contract Initializable {\n    /**\n     * @dev Indicates that the contract has been initialized.\n     * @custom:oz-retyped-from bool\n     */\n    uint8 private _initialized;\n\n    /**\n     * @dev Indicates that the contract is in the process of being initialized.\n     */\n    bool private _initializing;\n\n    /**\n     * @dev Triggered when the contract has been initialized or reinitialized.\n     */\n    event Initialized(uint8 version);\n\n    /**\n     * @dev A modifier that defines a protected initializer function that can be invoked at most once. In its scope,\n     * `onlyInitializing` functions can be used to initialize parent contracts.\n     *\n     * Similar to `reinitializer(1)`, except that functions marked with `initializer` can be nested in the context of a\n     * constructor.\n     *\n     * Emits an {Initialized} event.\n     */\n    modifier initializer() {\n        bool isTopLevelCall = !_initializing;\n        require(\n            (isTopLevelCall && _initialized < 1) || (!Address.isContract(address(this)) && _initialized == 1),\n            \"Initializable: contract is already initialized\"\n        );\n        _initialized = 1;\n        if (isTopLevelCall) {\n            _initializing = true;\n        }\n        _;\n        if (isTopLevelCall) {\n            _initializing = false;\n            emit Initialized(1);\n        }\n    }\n\n    /**\n     * @dev A modifier that defines a protected reinitializer function that can be invoked at most once, and only if the\n     * contract hasn't been initialized to a greater version before. In its scope, `onlyInitializing` functions can be\n     * used to initialize parent contracts.\n     *\n     * A reinitializer may be used after the original initialization step. This is essential to configure modules that\n     * are added through upgrades and that require initialization.\n     *\n     * When `version` is 1, this modifier is similar to `initializer`, except that functions marked with `reinitializer`\n     * cannot be nested. If one is invoked in the context of another, execution will revert.\n     *\n     * Note that versions can jump in increments greater than 1; this implies that if multiple reinitializers coexist in\n     * a contract, executing them in the right order is up to the developer or operator.\n     *\n     * WARNING: setting the version to 255 will prevent any future reinitialization.\n     *\n     * Emits an {Initialized} event.\n     */\n    modifier reinitializer(uint8 version) {\n        require(!_initializing && _initialized < version, \"Initializable: contract is already initialized\");\n        _initialized = version;\n        _initializing = true;\n        _;\n        _initializing = false;\n        emit Initialized(version);\n    }\n\n    /**\n     * @dev Modifier to protect an initialization function so that it can only be invoked by functions with the\n     * {initializer} and {reinitializer} modifiers, directly or indirectly.\n     */\n    modifier onlyInitializing() {\n        require(_initializing, \"Initializable: contract is not initializing\");\n        _;\n    }\n\n    /**\n     * @dev Locks the contract, preventing any future reinitialization. This cannot be part of an initializer call.\n     * Calling this in the constructor of a contract will prevent that contract from being initialized or reinitialized\n     * to any version. It is recommended to use this to lock implementation contracts that are designed to be called\n     * through proxies.\n     *\n     * Emits an {Initialized} event the first time it is successfully executed.\n     */\n    function _disableInitializers() internal virtual {\n        require(!_initializing, \"Initializable: contract is initializing\");\n        if (_initialized < type(uint8).max) {\n            _initialized = type(uint8).max;\n            emit Initialized(type(uint8).max);\n        }\n    }\n\n    /**\n     * @dev Internal function that returns the initialized version. Returns `_initialized`\n     */\n    function _getInitializedVersion() internal view returns (uint8) {\n        return _initialized;\n    }\n\n    /**\n     * @dev Internal function that returns the initialized version. Returns `_initializing`\n     */\n    function _isInitializing() internal view returns (bool) {\n        return _initializing;\n    }\n}\n"
      },
      "DataTypes.sol": {
        "content": "// SPDX-License-Identifier: GPL-3.0-or-later\npragma solidity ^0.8.17;\n\nimport \"EnumerableMap.sol\";\n\nlibrary DataTypes {\n    enum Status {\n        Undefined,\n        Active,\n        Rejected,\n        Queued,\n        Executed,\n        Vetoed\n    }\n\n    struct ProposalAction {\n        address target;\n        bytes data;\n    }\n\n    struct Proposal {\n        uint64 createdAt;\n        uint64 executableAt;\n        uint64 votingEndsAt;\n        uint64 voteThreshold;\n        uint64 quorum;\n        uint16 id;\n        uint8 actionLevel;\n        address proposer;\n        Status status;\n        ProposalAction[] actions;\n    }\n\n    struct PendingWithdrawal {\n        uint256 id;\n        uint256 withdrawableAt;\n        uint256 amount;\n        address to;\n        address delegate;\n    }\n\n    struct VaultWeightSchedule {\n        VaultWeightConfiguration[] vaults;\n        uint256 startsAt;\n        uint256 endsAt;\n    }\n\n    struct VaultWeightConfiguration {\n        address vaultAddress;\n        uint256 initialWeight;\n        uint256 targetWeight;\n    }\n\n    struct VaultWeight {\n        address vaultAddress;\n        uint256 currentWeight;\n        uint256 initialWeight;\n        uint256 targetWeight;\n    }\n\n    struct VaultVotingPower {\n        address vaultAddress;\n        uint256 votingPower;\n    }\n\n    struct Tier {\n        uint64 quorum;\n        uint64 proposalThreshold;\n        uint64 voteThreshold;\n        uint32 timeLockDuration;\n        uint32 proposalLength;\n        uint8 actionLevel;\n    }\n\n    struct EmergencyRecoveryProposal {\n        uint64 createdAt;\n        uint64 completesAt;\n        Status status;\n        bytes payload;\n        EnumerableMap.AddressToUintMap vetos;\n    }\n\n    enum Ballot {\n        Undefined,\n        For,\n        Against,\n        Abstain\n    }\n\n    struct VoteTotals {\n        VaultVotingPower[] _for;\n        VaultVotingPower[] against;\n        VaultVotingPower[] abstentions;\n    }\n\n    struct VaultSnapshot {\n        address vaultAddress;\n        uint256 weight;\n        uint256 totalVotingPower;\n    }\n\n    enum ProposalOutcome {\n        Undefined,\n        QuorumNotMet,\n        ThresholdNotMet,\n        Successful\n    }\n\n    struct LimitUpgradeabilityParameters {\n        uint8 actionLevelThreshold;\n        uint256 emaThreshold;\n        uint256 minBGYDSupply;\n        address tierStrategy;\n    }\n\n    struct Delegation {\n        address delegate;\n        uint256 amount;\n    }\n}\n"
      },
      "ScaledMath.sol": {
        "content": "// SPDX-License-Identifier: GPL-3.0-or-later\npragma solidity ^0.8.17;\n\nlibrary ScaledMath {\n    uint256 internal constant ONE = 1e18;\n\n    function mulDown(uint256 a, uint256 b) internal pure returns (uint256) {\n        return (a * b) / ONE;\n    }\n\n    function divDown(uint256 a, uint256 b) internal pure returns (uint256) {\n        return (a * ONE) / b;\n    }\n\n    function changeScale(\n        uint256 a,\n        uint256 from,\n        uint256 to\n    ) internal pure returns (uint256) {\n        if (from == to) return a;\n        else if (from < to) return a * 10 ** (to - from);\n        else return a / 10 ** (from - to);\n    }\n}\n"
      },
      "VaultsSnapshot.sol": {
        "content": "// SPDX-License-Identifier: GPL-3.0-or-later\npragma solidity ^0.8.17;\n\nimport \"EnumerableMap.sol\";\n\nimport \"DataTypes.sol\";\nimport \"ScaledMath.sol\";\n\nlibrary VaultsSnapshot {\n    using EnumerableMap for EnumerableMap.AddressToUintMap;\n    using ScaledMath for uint256;\n\n    function getBallotPercentage(\n        DataTypes.VaultSnapshot[] memory snapshots,\n        EnumerableMap.AddressToUintMap storage vaultPowers\n    ) internal view returns (uint256 votingPowerPct) {\n        for (uint256 i; i < snapshots.length; i++) {\n            DataTypes.VaultSnapshot memory snapshot = snapshots[i];\n            (, uint256 ballotPower) = vaultPowers.tryGet(snapshot.vaultAddress);\n            votingPowerPct += ballotPower\n                .divDown(snapshot.totalVotingPower)\n                .mulDown(snapshot.weight);\n        }\n    }\n\n    /// @dev this simply appends, so the storage must be clean\n    function persist(\n        DataTypes.VaultSnapshot[] memory snapshots,\n        DataTypes.VaultSnapshot[] storage cleanStorage\n    ) internal {\n        require(cleanStorage.length == 0, \"storage must be clean\");\n        for (uint256 i; i < snapshots.length; i++) {\n            cleanStorage.push(snapshots[i]);\n        }\n    }\n}\n"
      },
      "Errors.sol": {
        "content": "// SPDX-License-Identifier: GPL-3.0-or-later\npragma solidity ^0.8.17;\n\nlibrary Errors {\n    error DuplicatedVault(address vault);\n    error InvalidTotalWeight(uint256 totalWeight);\n    error NotAuthorized(address actual, address expected);\n    error InvalidVotingPowerUpdate(\n        uint256 actualTotalPower,\n        uint256 givenTotalPower\n    );\n    error MultisigSunset();\n\n    error ZeroDivision();\n}\n"
      },
      "IVault.sol": {
        "content": "// SPDX-License-Identifier: GPL-3.0-or-later\npragma solidity ^0.8.17;\n\nimport \"VotingPowerHistory.sol\";\n\ninterface IVault {\n    function getRawVotingPower(address account) external view returns (uint256);\n\n    function getCurrentRecord(\n        address account\n    ) external view returns (VotingPowerHistory.Record memory);\n\n    function getRawVotingPower(\n        address account,\n        uint256 timestamp\n    ) external view returns (uint256);\n\n    function getTotalRawVotingPower() external view returns (uint256);\n\n    function getVaultType() external view returns (string memory);\n}\n"
      },
      "VotingPowerHistory.sol": {
        "content": "// SPDX-License-Identifier: GPL-3.0-or-later\npragma solidity ^0.8.17;\n\nimport \"ScaledMath.sol\";\n\nlibrary VotingPowerHistory {\n    using VotingPowerHistory for History;\n    using VotingPowerHistory for Record;\n    using ScaledMath for uint256;\n\n    struct Record {\n        uint256 at;\n        uint256 baseVotingPower;\n        uint256 multiplier;\n        int256 netDelegatedVotes;\n    }\n\n    function zeroRecord() internal pure returns (Record memory) {\n        return\n            Record({\n                at: 0,\n                baseVotingPower: 0,\n                multiplier: ScaledMath.ONE,\n                netDelegatedVotes: 0\n            });\n    }\n\n    function total(Record memory record) internal pure returns (uint256) {\n        return\n            uint256(\n                int256(record.baseVotingPower.mulDown(record.multiplier)) +\n                    record.netDelegatedVotes\n            );\n    }\n\n    struct History {\n        mapping(address => Record[]) votes;\n        mapping(address => mapping(address => uint256)) _delegations;\n        mapping(address => uint256) _delegatedToOthers;\n        mapping(address => uint256) _delegatedToSelf;\n    }\n\n    event VotesDelegated(address from, address to, uint256 amount);\n    event VotesUndelegated(address from, address to, uint256 amount);\n\n    function updateVotingPower(\n        History storage history,\n        address for_,\n        uint256 baseVotingPower,\n        uint256 multiplier,\n        int256 netDelegatedVotes\n    ) internal returns (Record memory) {\n        Record[] storage votesFor = history.votes[for_];\n        Record memory updatedRecord = Record({\n            at: block.timestamp,\n            baseVotingPower: baseVotingPower,\n            multiplier: multiplier,\n            netDelegatedVotes: netDelegatedVotes\n        });\n        Record memory lastRecord = history.currentRecord(for_);\n        if (lastRecord.at == block.timestamp && votesFor.length > 0) {\n            votesFor[votesFor.length - 1] = updatedRecord;\n        } else {\n            history.votes[for_].push(updatedRecord);\n        }\n        return updatedRecord;\n    }\n\n    function getVotingPower(\n        History storage history,\n        address for_,\n        uint256 at\n    ) internal view returns (uint256) {\n        (, Record memory record) = binarySearch(history.votes[for_], at);\n        return record.total();\n    }\n\n    function currentRecord(\n        History storage history,\n        address for_\n    ) internal view returns (Record memory) {\n        Record[] memory records = history.votes[for_];\n        if (records.length == 0) {\n            return zeroRecord();\n        } else {\n            return records[records.length - 1];\n        }\n    }\n\n    function binarySearch(\n        Record[] memory records,\n        uint256 at\n    ) internal view returns (bool found, Record memory) {\n        return _binarySearch(records, at, 0, records.length);\n    }\n\n    function _binarySearch(\n        Record[] memory records,\n        uint256 at,\n        uint256 startIdx,\n        uint256 endIdx\n    ) internal view returns (bool found, Record memory) {\n        if (startIdx >= endIdx) {\n            return (false, zeroRecord());\n        }\n\n        if (endIdx - startIdx == 1) {\n            Record memory rec = records[startIdx];\n            return rec.at <= at ? (true, rec) : (false, zeroRecord());\n        }\n\n        uint256 midIdx = (endIdx + startIdx) / 2;\n        Record memory lowerBound = records[midIdx - 1];\n        Record memory upperBound = records[midIdx];\n        if (lowerBound.at <= at && at < upperBound.at) {\n            return (true, lowerBound);\n        } else if (upperBound.at <= at) {\n            return _binarySearch(records, at, midIdx, endIdx);\n        } else {\n            return _binarySearch(records, at, startIdx, midIdx);\n        }\n    }\n\n    function delegateVote(\n        History storage history,\n        address from,\n        address to,\n        uint256 amount\n    ) internal {\n        Record memory fromCurrent = history.currentRecord(from);\n\n        uint256 availableToDelegate = fromCurrent.baseVotingPower.mulDown(\n            fromCurrent.multiplier\n        ) - history._delegatedToOthers[from];\n        require(\n            availableToDelegate >= amount,\n            \"insufficient balance to delegate\"\n        );\n\n        history._delegatedToSelf[to] += amount;\n        history._delegatedToOthers[from] += amount;\n        history._delegations[from][to] += amount;\n\n        history.updateVotingPower(\n            from,\n            fromCurrent.baseVotingPower,\n            fromCurrent.multiplier,\n            history.netDelegatedVotingPower(from)\n        );\n        Record memory toCurrent = history.currentRecord(to);\n        history.updateVotingPower(\n            to,\n            toCurrent.baseVotingPower,\n            toCurrent.multiplier,\n            history.netDelegatedVotingPower(to)\n        );\n\n        emit VotesDelegated(from, to, amount);\n    }\n\n    function undelegateVote(\n        History storage history,\n        address from,\n        address to,\n        uint256 amount\n    ) internal {\n        require(\n            history._delegations[from][to] >= amount,\n            \"user has not delegated enough to delegate\"\n        );\n\n        history._delegatedToSelf[to] -= amount;\n        history._delegatedToOthers[from] -= amount;\n        history._delegations[from][to] -= amount;\n\n        Record memory fromCurrent = history.currentRecord(from);\n        history.updateVotingPower(\n            from,\n            fromCurrent.baseVotingPower,\n            fromCurrent.multiplier,\n            history.netDelegatedVotingPower(from)\n        );\n        Record memory toCurrent = history.currentRecord(to);\n        history.updateVotingPower(\n            to,\n            toCurrent.baseVotingPower,\n            toCurrent.multiplier,\n            history.netDelegatedVotingPower(to)\n        );\n\n        emit VotesUndelegated(from, to, amount);\n    }\n\n    function netDelegatedVotingPower(\n        History storage history,\n        address who\n    ) internal view returns (int256) {\n        return\n            int256(history._delegatedToSelf[who]) -\n            int256(history._delegatedToOthers[who]);\n    }\n\n    function delegatedVotingPower(\n        History storage history,\n        address who\n    ) internal view returns (uint256) {\n        return history._delegatedToOthers[who];\n    }\n\n    function updateMultiplier(\n        History storage history,\n        address who,\n        uint256 multiplier\n    ) internal {\n        Record memory current = history.currentRecord(who);\n        require(current.multiplier <= multiplier, \"cannot decrease multiplier\");\n        history.updateVotingPower(\n            who,\n            current.baseVotingPower,\n            multiplier,\n            current.netDelegatedVotes\n        );\n    }\n}\n"
      },
      "IGovernanceManager.sol": {
        "content": "// SPDX-License-Identifier: GPL-3.0-or-later\npragma solidity ^0.8.17;\n\nimport \"DataTypes.sol\";\nimport \"IVotingPowerAggregator.sol\";\n\ninterface IGovernanceManager {\n    function createProposal(\n        DataTypes.ProposalAction[] calldata actions\n    ) external;\n\n    function vote(uint16 proposalId, DataTypes.Ballot ballot) external;\n\n    function getVoteTotals(\n        uint16 proposalId\n    ) external view returns (DataTypes.VoteTotals memory);\n\n    function tallyVote(uint16 proposalId) external;\n\n    function getCurrentPercentages(\n        uint16 proposalId\n    ) external view returns (uint256 for_, uint256 against, uint256 abstain);\n\n    function executeProposal(uint16 proposalId) external;\n\n    function getBallot(\n        address voter,\n        uint16 proposalId\n    ) external view returns (DataTypes.Ballot);\n\n    function getProposal(\n        uint16 proposalId\n    ) external view returns (DataTypes.Proposal memory);\n\n    function listActiveProposals()\n        external\n        view\n        returns (DataTypes.Proposal[] memory);\n\n    function listTimelockedProposals()\n        external\n        view\n        returns (DataTypes.Proposal[] memory);\n\n    function votingPowerAggregator()\n        external\n        view\n        returns (IVotingPowerAggregator);\n\n    function multisig() external view returns (address);\n}\n"
      },
      "IVotingPowerAggregator.sol": {
        "content": "// SPDX-License-Identifier: GPL-3.0-or-later\npragma solidity ^0.8.17;\n\nimport \"DataTypes.sol\";\n\ninterface IVotingPowerAggregator {\n    function createVaultsSnapshot()\n        external\n        view\n        returns (DataTypes.VaultSnapshot[] memory snapshots);\n\n    function getVotingPower(\n        address account,\n        uint256 timestamp\n    ) external view returns (DataTypes.VaultVotingPower[] memory);\n\n    function getVotingPower(\n        address account,\n        uint256 timestamp,\n        address[] memory vaults\n    ) external view returns (DataTypes.VaultVotingPower[] memory);\n\n    function calculateWeightedPowerPct(\n        DataTypes.VaultVotingPower[] calldata vaultVotingPowers\n    ) external view returns (uint256);\n\n    function listVaults()\n        external\n        view\n        returns (DataTypes.VaultWeight[] memory);\n\n    function getVaultWeight(address vault) external view returns (uint256);\n\n    function setSchedule(\n        DataTypes.VaultWeightSchedule calldata schedule\n    ) external;\n}\n"
      },
      "ITierer.sol": {
        "content": "// SPDX-License-Identifier: GPL-3.0-or-later\npragma solidity ^0.8.17;\n\nimport \"DataTypes.sol\";\n\ninterface ITierer {\n    event TierSet(\n        address indexed target,\n        bytes4 indexed sig,\n        address indexed strategy\n    );\n\n    function getTier(\n        address _contract,\n        bytes calldata payload\n    ) external view returns (DataTypes.Tier memory);\n}\n"
      },
      "ITierStrategy.sol": {
        "content": "// SPDX-License-Identifier: GPL-3.0-or-later\npragma solidity ^0.8.17;\n\nimport \"DataTypes.sol\";\n\ninterface ITierStrategy {\n    function getTier(\n        bytes calldata payload\n    ) external view returns (DataTypes.Tier memory);\n}\n"
      },
      "IBoundedERC20WithEMA.sol": {
        "content": "// SPDX-License-Identifier: GPL-3.0-or-later\npragma solidity ^0.8.17;\n\nimport \"IERC20Upgradeable.sol\";\n\ninterface IBoundedERC20WithEMA is IERC20Upgradeable {\n    function boundedPctEMA() external view returns (uint256);\n}\n"
      },
      "IERC20Upgradeable.sol": {
        "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.9.0) (token/ERC20/IERC20.sol)\n\npragma solidity ^0.8.0;\n\n/**\n * @dev Interface of the ERC20 standard as defined in the EIP.\n */\ninterface IERC20Upgradeable {\n    /**\n     * @dev Emitted when `value` tokens are moved from one account (`from`) to\n     * another (`to`).\n     *\n     * Note that `value` may be zero.\n     */\n    event Transfer(address indexed from, address indexed to, uint256 value);\n\n    /**\n     * @dev Emitted when the allowance of a `spender` for an `owner` is set by\n     * a call to {approve}. `value` is the new allowance.\n     */\n    event Approval(address indexed owner, address indexed spender, uint256 value);\n\n    /**\n     * @dev Returns the amount of tokens in existence.\n     */\n    function totalSupply() external view returns (uint256);\n\n    /**\n     * @dev Returns the amount of tokens owned by `account`.\n     */\n    function balanceOf(address account) external view returns (uint256);\n\n    /**\n     * @dev Moves `amount` tokens from the caller's account to `to`.\n     *\n     * Returns a boolean value indicating whether the operation succeeded.\n     *\n     * Emits a {Transfer} event.\n     */\n    function transfer(address to, uint256 amount) external returns (bool);\n\n    /**\n     * @dev Returns the remaining number of tokens that `spender` will be\n     * allowed to spend on behalf of `owner` through {transferFrom}. This is\n     * zero by default.\n     *\n     * This value changes when {approve} or {transferFrom} are called.\n     */\n    function allowance(address owner, address spender) external view returns (uint256);\n\n    /**\n     * @dev Sets `amount` as the allowance of `spender` over the caller's tokens.\n     *\n     * Returns a boolean value indicating whether the operation succeeded.\n     *\n     * IMPORTANT: Beware that changing an allowance with this method brings the risk\n     * that someone may use both the old and the new allowance by unfortunate\n     * transaction ordering. One possible solution to mitigate this race\n     * condition is to first reduce the spender's allowance to 0 and set the\n     * desired value afterwards:\n     * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729\n     *\n     * Emits an {Approval} event.\n     */\n    function approve(address spender, uint256 amount) external returns (bool);\n\n    /**\n     * @dev Moves `amount` tokens from `from` to `to` using the\n     * allowance mechanism. `amount` is then deducted from the caller's\n     * allowance.\n     *\n     * Returns a boolean value indicating whether the operation succeeded.\n     *\n     * Emits a {Transfer} event.\n     */\n    function transferFrom(address from, address to, uint256 amount) external returns (bool);\n}\n"
      }
    },
    "settings": {
      "evmVersion": "london",
      "optimizer": {
        "enabled": true,
        "runs": 200
      },
      "libraries": {
        "GovernanceManager.sol": {}
      },
      "outputSelection": {
        "*": {
          "*": [
            "evm.bytecode",
            "evm.deployedBytecode",
            "devdoc",
            "userdoc",
            "metadata",
            "abi"
          ]
        }
      }
    }
  }}