File size: 135,491 Bytes
f998fcd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
{
  "language": "Solidity",
  "sources": {
    "contracts/p1/AssetRegistry.sol": {
      "content": "// SPDX-License-Identifier: BlueOak-1.0.0\npragma solidity 0.8.9;\n\nimport \"@openzeppelin/contracts/token/ERC20/IERC20.sol\";\nimport \"@openzeppelin/contracts/utils/structs/EnumerableSet.sol\";\nimport \"contracts/interfaces/IAssetRegistry.sol\";\nimport \"contracts/interfaces/IMain.sol\";\nimport \"contracts/p1/mixins/Component.sol\";\n\n/// The AssetRegistry provides the mapping from ERC20 to Asset, allowing the rest of Main\n/// to think in terms of ERC20 tokens and target/ref units.\ncontract AssetRegistryP1 is ComponentP1, IAssetRegistry {\n    using EnumerableSet for EnumerableSet.AddressSet;\n\n    // Registered ERC20s\n    EnumerableSet.AddressSet private _erc20s;\n\n    // Registered Assets\n    mapping(IERC20 => IAsset) private assets;\n\n    /* ==== Contract Invariants ====\n       The contract state is just the mapping assets; _erc20s is ignored in properties.\n\n       invariant: _erc20s == keys(assets)\n       invariant: addr == assets[addr].erc20()\n           where: addr in assets\n     */\n\n    /// Initialize the AssetRegistry with assets\n    // effects: assets' = {a.erc20(): a for a in assets_}\n    function init(IMain main_, IAsset[] calldata assets_) external initializer {\n        __Component_init(main_);\n        uint256 length = assets_.length;\n        for (uint256 i = 0; i < length; ++i) {\n            _register(assets_[i]);\n        }\n    }\n\n    /// Update the state of all assets\n    /// @custom:refresher\n    // actions: calls refresh(c) for c in keys(assets) when c.isCollateral()\n    function refresh() external {\n        // It's a waste of gas to require notPausedOrFrozen because assets can be updated directly\n        uint256 length = _erc20s.length();\n        for (uint256 i = 0; i < length; ++i) {\n            IAsset asset = assets[IERC20(_erc20s.at(i))];\n            if (asset.isCollateral()) ICollateral(address(asset)).refresh();\n        }\n    }\n\n    /// Register `asset`\n    /// If either the erc20 address or the asset was already registered, fail\n    /// @return true if the erc20 address was not already registered.\n    /// @custom:governance\n    // checks: asset.erc20() not in keys(assets) or assets[asset.erc20] == asset\n    // effects: assets' = assets.set(asset.erc20(), asset)\n    // returns: (asset.erc20 not in keys(assets))\n    function register(IAsset asset) external governance returns (bool) {\n        return _register(asset);\n    }\n\n    /// Register `asset` if and only if its erc20 address is already registered.\n    /// If the erc20 address was not registered, revert.\n    /// @return swapped If the asset was swapped for a previously-registered asset\n    /// @custom:governance\n    // contract\n    // checks: asset.erc20() in assets\n    // effects: assets' = assets + {asset.erc20(): asset}\n    // actions: if asset.erc20() is in basketHandler's basket then basketHandler.disableBasket()\n    function swapRegistered(IAsset asset) external governance returns (bool swapped) {\n        require(_erc20s.contains(address(asset.erc20())), \"no ERC20 collision\");\n\n        uint192 quantity = main.basketHandler().quantity(asset.erc20());\n\n        swapped = _registerIgnoringCollisions(asset);\n\n        if (quantity > 0) main.basketHandler().disableBasket();\n    }\n\n    /// Unregister an asset, requiring that it is already registered\n    /// @custom:governance\n    // checks: assets[asset.erc20()] == asset\n    // effects: assets' = assets - {asset.erc20():_} + {asset.erc20(), asset}\n    function unregister(IAsset asset) external governance {\n        require(_erc20s.contains(address(asset.erc20())), \"no asset to unregister\");\n        require(assets[asset.erc20()] == asset, \"asset not found\");\n        uint192 quantity = main.basketHandler().quantity(asset.erc20());\n\n        _erc20s.remove(address(asset.erc20()));\n        assets[asset.erc20()] = IAsset(address(0));\n        emit AssetUnregistered(asset.erc20(), asset);\n\n        if (quantity > 0) main.basketHandler().disableBasket();\n    }\n\n    /// Return the Asset registered for erc20; revert if erc20 is not registered.\n    // checks: erc20 in assets\n    // returns: assets[erc20]\n    function toAsset(IERC20 erc20) external view returns (IAsset) {\n        require(_erc20s.contains(address(erc20)), \"erc20 unregistered\");\n        return assets[erc20];\n    }\n\n    /// Return the Collateral registered for erc20; revert if erc20 is not registered as Collateral\n    // checks: erc20 in assets, assets[erc20].isCollateral()\n    // returns: assets[erc20]\n    function toColl(IERC20 erc20) external view returns (ICollateral) {\n        require(_erc20s.contains(address(erc20)), \"erc20 unregistered\");\n        require(assets[erc20].isCollateral(), \"erc20 is not collateral\");\n        return ICollateral(address(assets[erc20]));\n    }\n\n    /// Returns true if erc20 is registered.\n    // returns: (erc20 in assets)\n    function isRegistered(IERC20 erc20) external view returns (bool) {\n        return _erc20s.contains(address(erc20));\n    }\n\n    /// Returns keys(assets) as a (duplicate-free) list.\n    // returns: [keys(assets)] without duplicates.\n    function erc20s() external view returns (IERC20[] memory erc20s_) {\n        uint256 length = _erc20s.length();\n        erc20s_ = new IERC20[](length);\n        for (uint256 i = 0; i < length; ++i) {\n            erc20s_[i] = IERC20(_erc20s.at(i));\n        }\n    }\n\n    /// Register an asset\n    /// Forbids registering a different asset for an ERC20 that is already registered\n    /// @return registered If the asset was moved from unregistered to registered\n    // checks: (asset.erc20() not in assets) or (assets[asset.erc20()] == asset)\n    // effects: assets' = assets.set(asset.erc20(), asset)\n    // returns: assets.erc20() not in assets\n    function _register(IAsset asset) internal returns (bool registered) {\n        require(\n            !_erc20s.contains(address(asset.erc20())) || assets[asset.erc20()] == asset,\n            \"duplicate ERC20 detected\"\n        );\n\n        registered = _registerIgnoringCollisions(asset);\n    }\n\n    /// Register an asset, unregistering any previous asset with the same ERC20.\n    // effects: assets' = assets.set(asset.erc20(), asset)\n    // returns: assets[asset.erc20()] != asset\n    function _registerIgnoringCollisions(IAsset asset) private returns (bool swapped) {\n        IERC20Metadata erc20 = asset.erc20();\n        if (_erc20s.contains(address(erc20))) {\n            if (assets[erc20] == asset) return false;\n            else emit AssetUnregistered(erc20, assets[erc20]);\n        } else {\n            _erc20s.add(address(erc20));\n        }\n\n        assets[erc20] = asset;\n        emit AssetRegistered(erc20, asset);\n        return true;\n    }\n\n    /**\n     * @dev This empty reserved space is put in place to allow future versions to add new\n     * variables without shifting down storage in the inheritance chain.\n     * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps\n     */\n    uint256[48] private __gap;\n}\n"
    },
    "@openzeppelin/contracts/token/ERC20/IERC20.sol": {
      "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.6.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 IERC20 {\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(\n        address from,\n        address to,\n        uint256 amount\n    ) external returns (bool);\n}\n"
    },
    "@openzeppelin/contracts/utils/structs/EnumerableSet.sol": {
      "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.7.0) (utils/structs/EnumerableSet.sol)\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 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 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        return _values(set._inner);\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 on 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"
    },
    "contracts/interfaces/IAssetRegistry.sol": {
      "content": "// SPDX-License-Identifier: BlueOak-1.0.0\npragma solidity 0.8.9;\n\nimport \"@openzeppelin/contracts/token/ERC20/IERC20.sol\";\nimport \"contracts/interfaces/IAsset.sol\";\nimport \"./IComponent.sol\";\n\n/**\n * @title IAssetRegistry\n * @notice The AssetRegistry is in charge of maintaining the ERC20 tokens eligible\n *   to be handled by the rest of the system. If an asset is in the registry, this means:\n *      1. Its ERC20 contract has been vetted\n *      2. The asset is the only asset for that ERC20\n *      3. The asset can be priced in the UoA, usually via an oracle\n */\ninterface IAssetRegistry is IComponent {\n    /// Emitted when an asset is added to the registry\n    /// @param erc20 The ERC20 contract for the asset\n    /// @param asset The asset contract added to the registry\n    event AssetRegistered(IERC20 indexed erc20, IAsset indexed asset);\n\n    /// Emitted when an asset is removed from the registry\n    /// @param erc20 The ERC20 contract for the asset\n    /// @param asset The asset contract removed from the registry\n    event AssetUnregistered(IERC20 indexed erc20, IAsset indexed asset);\n\n    // Initialization\n    function init(IMain main_, IAsset[] memory assets_) external;\n\n    /// Fully refresh all asset state\n    /// @custom:interaction\n    function refresh() external;\n\n    /// @return The corresponding asset for ERC20, or reverts if not registered\n    function toAsset(IERC20 erc20) external view returns (IAsset);\n\n    /// @return The corresponding collateral, or reverts if unregistered or not collateral\n    function toColl(IERC20 erc20) external view returns (ICollateral);\n\n    /// @return If the ERC20 is registered\n    function isRegistered(IERC20 erc20) external view returns (bool);\n\n    /// @return A list of all registered ERC20s\n    function erc20s() external view returns (IERC20[] memory);\n\n    function register(IAsset asset) external returns (bool);\n\n    function swapRegistered(IAsset asset) external returns (bool swapped);\n\n    function unregister(IAsset asset) external;\n}\n"
    },
    "contracts/interfaces/IMain.sol": {
      "content": "// SPDX-License-Identifier: BlueOak-1.0.0\npragma solidity 0.8.9;\n\nimport \"@openzeppelin/contracts-upgradeable/access/IAccessControlUpgradeable.sol\";\nimport \"@openzeppelin/contracts/token/ERC20/IERC20.sol\";\nimport \"./IAssetRegistry.sol\";\nimport \"./IBasketHandler.sol\";\nimport \"./IBackingManager.sol\";\nimport \"./IBroker.sol\";\nimport \"./IGnosis.sol\";\nimport \"./IFurnace.sol\";\nimport \"./IDistributor.sol\";\nimport \"./IRToken.sol\";\nimport \"./IRevenueTrader.sol\";\nimport \"./IStRSR.sol\";\nimport \"./ITrading.sol\";\n\n// === Auth roles ===\n\nbytes32 constant OWNER = bytes32(bytes(\"OWNER\"));\nbytes32 constant SHORT_FREEZER = bytes32(bytes(\"SHORT_FREEZER\"));\nbytes32 constant LONG_FREEZER = bytes32(bytes(\"LONG_FREEZER\"));\nbytes32 constant PAUSER = bytes32(bytes(\"PAUSER\"));\n\n/**\n * Main is a central hub that maintains a list of Component contracts.\n *\n * Components:\n *   - perform a specific function\n *   - defer auth to Main\n *   - usually (but not always) contain sizeable state that require a proxy\n */\nstruct Components {\n    // Definitely need proxy\n    IRToken rToken;\n    IStRSR stRSR;\n    IAssetRegistry assetRegistry;\n    IBasketHandler basketHandler;\n    IBackingManager backingManager;\n    IDistributor distributor;\n    IFurnace furnace;\n    IBroker broker;\n    IRevenueTrader rsrTrader;\n    IRevenueTrader rTokenTrader;\n}\n\ninterface IAuth is IAccessControlUpgradeable {\n    /// Emitted when `unfreezeAt` is changed\n    /// @param oldVal The old value of `unfreezeAt`\n    /// @param newVal The new value of `unfreezeAt`\n    event UnfreezeAtSet(uint48 indexed oldVal, uint48 indexed newVal);\n\n    /// Emitted when the short freeze duration governance param is changed\n    /// @param oldDuration The old short freeze duration\n    /// @param newDuration The new short freeze duration\n    event ShortFreezeDurationSet(uint48 indexed oldDuration, uint48 indexed newDuration);\n\n    /// Emitted when the long freeze duration governance param is changed\n    /// @param oldDuration The old long freeze duration\n    /// @param newDuration The new long freeze duration\n    event LongFreezeDurationSet(uint48 indexed oldDuration, uint48 indexed newDuration);\n\n    /// Emitted when the system is paused or unpaused\n    /// @param oldVal The old value of `paused`\n    /// @param newVal The new value of `paused`\n    event PausedSet(bool indexed oldVal, bool indexed newVal);\n\n    /**\n     * Paused: Disable everything except for OWNER actions and RToken.redeem/cancel\n     * Frozen: Disable everything except for OWNER actions\n     */\n\n    function pausedOrFrozen() external view returns (bool);\n\n    function frozen() external view returns (bool);\n\n    function shortFreeze() external view returns (uint48);\n\n    function longFreeze() external view returns (uint48);\n\n    // ====\n\n    // onlyRole(OWNER)\n    function freezeForever() external;\n\n    // onlyRole(SHORT_FREEZER)\n    function freezeShort() external;\n\n    // onlyRole(LONG_FREEZER)\n    function freezeLong() external;\n\n    // onlyRole(OWNER)\n    function unfreeze() external;\n\n    function pause() external;\n\n    function unpause() external;\n}\n\ninterface IComponentRegistry {\n    // === Component setters/getters ===\n\n    event RTokenSet(IRToken indexed oldVal, IRToken indexed newVal);\n\n    function rToken() external view returns (IRToken);\n\n    event StRSRSet(IStRSR indexed oldVal, IStRSR indexed newVal);\n\n    function stRSR() external view returns (IStRSR);\n\n    event AssetRegistrySet(IAssetRegistry indexed oldVal, IAssetRegistry indexed newVal);\n\n    function assetRegistry() external view returns (IAssetRegistry);\n\n    event BasketHandlerSet(IBasketHandler indexed oldVal, IBasketHandler indexed newVal);\n\n    function basketHandler() external view returns (IBasketHandler);\n\n    event BackingManagerSet(IBackingManager indexed oldVal, IBackingManager indexed newVal);\n\n    function backingManager() external view returns (IBackingManager);\n\n    event DistributorSet(IDistributor indexed oldVal, IDistributor indexed newVal);\n\n    function distributor() external view returns (IDistributor);\n\n    event RSRTraderSet(IRevenueTrader indexed oldVal, IRevenueTrader indexed newVal);\n\n    function rsrTrader() external view returns (IRevenueTrader);\n\n    event RTokenTraderSet(IRevenueTrader indexed oldVal, IRevenueTrader indexed newVal);\n\n    function rTokenTrader() external view returns (IRevenueTrader);\n\n    event FurnaceSet(IFurnace indexed oldVal, IFurnace indexed newVal);\n\n    function furnace() external view returns (IFurnace);\n\n    event BrokerSet(IBroker indexed oldVal, IBroker indexed newVal);\n\n    function broker() external view returns (IBroker);\n}\n\n/**\n * @title IMain\n * @notice The central hub for the entire system. Maintains components and an owner singleton role\n */\ninterface IMain is IAuth, IComponentRegistry {\n    function poke() external; // not used in p1\n\n    // === Initialization ===\n\n    event MainInitialized();\n\n    function init(\n        Components memory components,\n        IERC20 rsr_,\n        uint48 shortFreeze_,\n        uint48 longFreeze_\n    ) external;\n\n    function rsr() external view returns (IERC20);\n}\n\ninterface TestIMain is IMain {\n    /// @custom:governance\n    function setShortFreeze(uint48) external;\n\n    /// @custom:governance\n    function setLongFreeze(uint48) external;\n\n    function shortFreeze() external view returns (uint48);\n\n    function longFreeze() external view returns (uint48);\n\n    function longFreezes(address account) external view returns (uint256);\n\n    function paused() external view returns (bool);\n}\n"
    },
    "contracts/p1/mixins/Component.sol": {
      "content": "// SPDX-License-Identifier: BlueOak-1.0.0\npragma solidity 0.8.9;\n\nimport \"@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol\";\nimport \"@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol\";\nimport \"@openzeppelin/contracts-upgradeable/utils/ContextUpgradeable.sol\";\nimport \"contracts/interfaces/IComponent.sol\";\nimport \"contracts/interfaces/IMain.sol\";\n\n/**\n * Abstract superclass for system contracts registered in Main\n */\nabstract contract ComponentP1 is Initializable, ContextUpgradeable, UUPSUpgradeable, IComponent {\n    IMain public main;\n\n    /// @custom:oz-upgrades-unsafe-allow constructor\n    // solhint-disable-next-line no-empty-blocks\n    constructor() initializer {}\n\n    // Sets main for the component - Can only be called during initialization\n    // solhint-disable-next-line func-name-mixedcase\n    function __Component_init(IMain main_) internal onlyInitializing {\n        require(address(main_) != address(0), \"main is zero address\");\n        __UUPSUpgradeable_init();\n        main = main_;\n    }\n\n    // === See docs/security.md ===\n\n    modifier notPausedOrFrozen() {\n        require(!main.pausedOrFrozen(), \"paused or frozen\");\n        _;\n    }\n\n    modifier notFrozen() {\n        require(!main.frozen(), \"frozen\");\n        _;\n    }\n\n    modifier governance() {\n        require(main.hasRole(OWNER, _msgSender()), \"governance only\");\n        _;\n    }\n\n    // solhint-disable-next-line no-empty-blocks\n    function _authorizeUpgrade(address newImplementation) internal view override governance {}\n\n    /**\n     * @dev This empty reserved space is put in place to allow future versions to add new\n     * variables without shifting down storage in the inheritance chain.\n     * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps\n     */\n    uint256[49] private __gap;\n}\n"
    },
    "contracts/interfaces/IAsset.sol": {
      "content": "// SPDX-License-Identifier: BlueOak-1.0.0\npragma solidity 0.8.9;\n\nimport \"@chainlink/contracts/src/v0.8/interfaces/AggregatorV3Interface.sol\";\nimport \"@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol\";\nimport \"contracts/libraries/Fixed.sol\";\nimport \"./IMain.sol\";\n\n/**\n * @title IAsset\n * @notice Supertype. Any token that interacts with our system must be wrapped in an asset,\n * whether it is used as RToken backing or not. Any token that can report a price in the UoA\n * is eligible to be an asset.\n */\ninterface IAsset {\n    /// Can return 0, can revert\n    /// Shortcut for price(false)\n    /// @return {UoA/tok} The current price(), without considering fallback prices\n    function strictPrice() external view returns (uint192);\n\n    /// Can return 0\n    /// Should not revert if `allowFallback` is true. Can revert if false.\n    /// @param allowFallback Whether to try the fallback price in case precise price reverts\n    /// @return isFallback If the price is a failover price\n    /// @return {UoA/tok} The current price(), or if it's reverting, a fallback price\n    function price(bool allowFallback) external view returns (bool isFallback, uint192);\n\n    /// @return {tok} The balance of the ERC20 in whole tokens\n    function bal(address account) external view returns (uint192);\n\n    /// @return The ERC20 contract of the token with decimals() available\n    function erc20() external view returns (IERC20Metadata);\n\n    /// @return The number of decimals in the ERC20; just for gas optimization\n    function erc20Decimals() external view returns (uint8);\n\n    /// @return If the asset is an instance of ICollateral or not\n    function isCollateral() external view returns (bool);\n\n    /// @param {UoA} The max trade volume, in UoA\n    function maxTradeVolume() external view returns (uint192);\n\n    // ==== Rewards ====\n\n    /// Get the message needed to call in order to claim rewards for holding this asset.\n    /// Returns zero values if there is no reward function to call.\n    /// @return _to The address to send the call to\n    /// @return _calldata The calldata to send\n    function getClaimCalldata() external view returns (address _to, bytes memory _calldata);\n\n    /// The ERC20 token address that this Asset's rewards are paid in.\n    /// If there are no rewards, will return a zero value.\n    function rewardERC20() external view returns (IERC20 reward);\n}\n\ninterface TestIAsset is IAsset {\n    function chainlinkFeed() external view returns (AggregatorV3Interface);\n}\n\n/// CollateralStatus must obey a linear ordering. That is:\n/// - being DISABLED is worse than being IFFY, or SOUND\n/// - being IFFY is worse than being SOUND.\nenum CollateralStatus {\n    SOUND,\n    IFFY, // When a peg is not holding or a chainlink feed is stale\n    DISABLED // When the collateral has completely defaulted\n}\n\n/// Upgrade-safe maximum operator for CollateralStatus\nlibrary CollateralStatusComparator {\n    /// @return Whether a is worse than b\n    function worseThan(CollateralStatus a, CollateralStatus b) internal pure returns (bool) {\n        return uint256(a) > uint256(b);\n    }\n}\n\n/**\n * @title ICollateral\n * @notice A subtype of Asset that consists of the tokens eligible to back the RToken.\n */\ninterface ICollateral is IAsset {\n    /// Emitted whenever the collateral status is changed\n    /// @param newStatus The old CollateralStatus\n    /// @param newStatus The updated CollateralStatus\n    event DefaultStatusChanged(\n        CollateralStatus indexed oldStatus,\n        CollateralStatus indexed newStatus\n    );\n\n    /// Refresh exchange rates and update default status.\n    /// The Reserve protocol calls this at least once per transaction, before relying on\n    /// this collateral's prices or default status.\n    /// @dev This default check assumes that the collateral's price() value is expected\n    /// to stay close to pricePerTarget() * targetPerRef(). If that's not true for the\n    /// collateral you're defining, you MUST redefine refresh()!!\n    function refresh() external;\n\n    /// @return The canonical name of this collateral's target unit.\n    function targetName() external view returns (bytes32);\n\n    /// @return The status of this collateral asset. (Is it defaulting? Might it soon?)\n    function status() external view returns (CollateralStatus);\n\n    // ==== Exchange Rates ====\n\n    /// @return {ref/tok} Quantity of whole reference units per whole collateral tokens\n    function refPerTok() external view returns (uint192);\n\n    /// @return {target/ref} Quantity of whole target units per whole reference unit in the peg\n    function targetPerRef() external view returns (uint192);\n\n    /// @return {UoA/target} The price of the target unit in UoA (usually this is {UoA/UoA} = 1)\n    function pricePerTarget() external view returns (uint192);\n}\n"
    },
    "contracts/interfaces/IComponent.sol": {
      "content": "// SPDX-License-Identifier: BlueOak-1.0.0\npragma solidity 0.8.9;\n\nimport \"./IMain.sol\";\n\n/**\n * @title IComponent\n * @notice A Component is the central building block of all our system contracts. Components\n *   contain important state that must be migrated during upgrades, and they delegate\n *   their ownership to Main's owner.\n */\ninterface IComponent {\n    function main() external view returns (IMain);\n}\n"
    },
    "@chainlink/contracts/src/v0.8/interfaces/AggregatorV3Interface.sol": {
      "content": "// SPDX-License-Identifier: MIT\npragma solidity ^0.8.0;\n\ninterface AggregatorV3Interface {\n  function decimals() external view returns (uint8);\n\n  function description() external view returns (string memory);\n\n  function version() external view returns (uint256);\n\n  // getRoundData and latestRoundData should both raise \"No data present\"\n  // if they do not have data to report, instead of returning unset values\n  // which could be misinterpreted as actual reported values.\n  function getRoundData(uint80 _roundId)\n    external\n    view\n    returns (\n      uint80 roundId,\n      int256 answer,\n      uint256 startedAt,\n      uint256 updatedAt,\n      uint80 answeredInRound\n    );\n\n  function latestRoundData()\n    external\n    view\n    returns (\n      uint80 roundId,\n      int256 answer,\n      uint256 startedAt,\n      uint256 updatedAt,\n      uint80 answeredInRound\n    );\n}\n"
    },
    "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol": {
      "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts v4.4.1 (token/ERC20/extensions/IERC20Metadata.sol)\n\npragma solidity ^0.8.0;\n\nimport \"../IERC20.sol\";\n\n/**\n * @dev Interface for the optional metadata functions from the ERC20 standard.\n *\n * _Available since v4.1._\n */\ninterface IERC20Metadata is IERC20 {\n    /**\n     * @dev Returns the name of the token.\n     */\n    function name() external view returns (string memory);\n\n    /**\n     * @dev Returns the symbol of the token.\n     */\n    function symbol() external view returns (string memory);\n\n    /**\n     * @dev Returns the decimals places of the token.\n     */\n    function decimals() external view returns (uint8);\n}\n"
    },
    "contracts/libraries/Fixed.sol": {
      "content": "// SPDX-License-Identifier: BlueOak-1.0.0\n// solhint-disable func-name-mixedcase func-visibility\npragma solidity ^0.8.9;\n\n/// @title FixedPoint, a fixed-point arithmetic library defining the custom type uint192\n/// @author Matt Elder <[email protected]> and the Reserve Team <https://reserve.org>\n\n/** The logical type `uint192 ` is a 192 bit value, representing an 18-decimal Fixed-point\n    fractional value.  This is what's described in the Solidity documentation as\n    \"fixed192x18\" -- a value represented by 192 bits, that makes 18 digits available to\n    the right of the decimal point.\n\n    The range of values that uint192 can represent is about [-1.7e20, 1.7e20].\n    Unless a function explicitly says otherwise, it will fail on overflow.\n    To be clear, the following should hold:\n    toFix(0) == 0\n    toFix(1) == 1e18\n*/\n\n// Analysis notes:\n//   Every function should revert iff its result is out of bounds.\n//   Unless otherwise noted, when a rounding mode is given, that mode is applied to\n//     a single division that may happen as the last step in the computation.\n//   Unless otherwise noted, when a rounding mode is *not* given but is needed, it's FLOOR.\n//   For each, we comment:\n//   - @return is the value expressed  in \"value space\", where uint192(1e18) \"is\" 1.0\n//   - as-ints: is the value expressed in \"implementation space\", where uint192(1e18) \"is\" 1e18\n//   The \"@return\" expression is suitable for actually using the library\n//   The \"as-ints\" expression is suitable for testing\n\n// A uint value passed to this library was out of bounds for uint192 operations\nerror UIntOutOfBounds();\n\n// Used by P1 implementation for easier casting\nuint256 constant FIX_ONE_256 = 1e18;\nuint8 constant FIX_DECIMALS = 18;\n\n// If a particular uint192 is represented by the uint192 n, then the uint192 represents the\n// value n/FIX_SCALE.\nuint64 constant FIX_SCALE = 1e18;\n\n// FIX_SCALE Squared:\nuint128 constant FIX_SCALE_SQ = 1e36;\n\n// The largest integer that can be converted to uint192 .\n// This is a bit bigger than 3.1e39\nuint192 constant FIX_MAX_INT = type(uint192).max / FIX_SCALE;\n\nuint192 constant FIX_ZERO = 0; // The uint192 representation of zero.\nuint192 constant FIX_ONE = FIX_SCALE; // The uint192 representation of one.\nuint192 constant FIX_MAX = type(uint192).max; // The largest uint192. (Not an integer!)\nuint192 constant FIX_MIN = 0; // The smallest uint192.\n\n/// An enum that describes a rounding approach for converting to ints\nenum RoundingMode {\n    FLOOR, // Round towards zero\n    ROUND, // Round to the nearest int\n    CEIL // Round away from zero\n}\n\nRoundingMode constant FLOOR = RoundingMode.FLOOR;\nRoundingMode constant ROUND = RoundingMode.ROUND;\nRoundingMode constant CEIL = RoundingMode.CEIL;\n\n/* @dev Solidity 0.8.x only allows you to change one of type or size per type conversion.\n   Thus, all the tedious-looking double conversions like uint256(uint256 (foo))\n   See: https://docs.soliditylang.org/en/v0.8.9/080-breaking-changes.html#new-restrictions\n */\n\n/// Explicitly convert a uint256 to a uint192. Revert if the input is out of bounds.\nfunction _safeWrap(uint256 x) pure returns (uint192) {\n    if (FIX_MAX < x) revert UIntOutOfBounds();\n    return uint192(x);\n}\n\n/// Convert a uint to its Fix representation.\n/// @return x\n// as-ints: x * 1e18\nfunction toFix(uint256 x) pure returns (uint192) {\n    return _safeWrap(x * FIX_SCALE);\n}\n\n/// Convert a uint to its fixed-point representation, and left-shift its value `shiftLeft`\n/// decimal digits.\n/// @return x * 10**shiftLeft\n// as-ints: x * 10**(shiftLeft + 18)\nfunction shiftl_toFix(uint256 x, int8 shiftLeft) pure returns (uint192) {\n    return shiftl_toFix(x, shiftLeft, FLOOR);\n}\n\n/// @return x * 10**shiftLeft\n// as-ints: x * 10**(shiftLeft + 18)\nfunction shiftl_toFix(\n    uint256 x,\n    int8 shiftLeft,\n    RoundingMode rounding\n) pure returns (uint192) {\n    shiftLeft += 18;\n\n    if (x == 0) return 0;\n    if (shiftLeft <= -77) return (rounding == CEIL ? 1 : 0); // 0 < uint.max / 10**77 < 0.5\n    if (57 <= shiftLeft) revert UIntOutOfBounds(); // 10**56 < FIX_MAX < 10**57\n\n    uint256 coeff = 10**abs(shiftLeft);\n    uint256 shifted = (shiftLeft >= 0) ? x * coeff : _divrnd(x, coeff, rounding);\n\n    return _safeWrap(shifted);\n}\n\n/// Divide a uint by a uint192, yielding a uint192\n/// This may also fail if the result is MIN_uint192! not fixing this for optimization's sake.\n/// @return x / y\n// as-ints: x * 1e36 / y\nfunction divFix(uint256 x, uint192 y) pure returns (uint192) {\n    // If we didn't have to worry about overflow, we'd just do `return x * 1e36 / _y`\n    // If it's safe to do this operation the easy way, do it:\n    if (x < uint256(type(uint256).max / FIX_SCALE_SQ)) {\n        return _safeWrap(uint256(x * FIX_SCALE_SQ) / y);\n    } else {\n        return _safeWrap(mulDiv256(x, FIX_SCALE_SQ, y));\n    }\n}\n\n/// Divide a uint by a uint, yielding a  uint192\n/// @return x / y\n// as-ints: x * 1e18 / y\nfunction divuu(uint256 x, uint256 y) pure returns (uint192) {\n    return _safeWrap(mulDiv256(FIX_SCALE, x, y));\n}\n\n/// @return min(x,y)\n// as-ints: min(x,y)\nfunction fixMin(uint192 x, uint192 y) pure returns (uint192) {\n    return x < y ? x : y;\n}\n\n/// @return max(x,y)\n// as-ints: max(x,y)\nfunction fixMax(uint192 x, uint192 y) pure returns (uint192) {\n    return x > y ? x : y;\n}\n\n/// @return absoluteValue(x,y)\n// as-ints: absoluteValue(x,y)\nfunction abs(int256 x) pure returns (uint256) {\n    return x < 0 ? uint256(-x) : uint256(x);\n}\n\n/// Divide two uints, returning a uint, using rounding mode `rounding`.\n/// @return numerator / divisor\n// as-ints: numerator / divisor\nfunction _divrnd(\n    uint256 numerator,\n    uint256 divisor,\n    RoundingMode rounding\n) pure returns (uint256) {\n    uint256 result = numerator / divisor;\n\n    if (rounding == FLOOR) return result;\n\n    if (rounding == ROUND) {\n        if (numerator % divisor > (divisor - 1) / 2) {\n            result++;\n        }\n    } else {\n        if (numerator % divisor > 0) {\n            result++;\n        }\n    }\n\n    return result;\n}\n\nlibrary FixLib {\n    /// Again, all arithmetic functions fail if and only if the result is out of bounds.\n\n    /// Convert this fixed-point value to a uint. Round towards zero if needed.\n    /// @return x\n    // as-ints: x / 1e18\n    function toUint(uint192 x) internal pure returns (uint136) {\n        return toUint(x, FLOOR);\n    }\n\n    /// Convert this uint192 to a uint\n    /// @return x\n    // as-ints: x / 1e18 with rounding\n    function toUint(uint192 x, RoundingMode rounding) internal pure returns (uint136) {\n        return uint136(_divrnd(uint256(x), FIX_SCALE, rounding));\n    }\n\n    /// Return the uint192 shifted to the left by `decimal` digits\n    /// (Similar to a bitshift but in base 10)\n    /// @return x * 10**decimals\n    // as-ints: x * 10**decimals\n    function shiftl(uint192 x, int8 decimals) internal pure returns (uint192) {\n        return shiftl(x, decimals, FLOOR);\n    }\n\n    /// Return the uint192 shifted to the left by `decimal` digits\n    /// (Similar to a bitshift but in base 10)\n    /// @return x * 10**decimals\n    // as-ints: x * 10**decimals\n    function shiftl(\n        uint192 x,\n        int8 decimals,\n        RoundingMode rounding\n    ) internal pure returns (uint192) {\n        uint256 coeff = uint256(10**abs(decimals));\n        return _safeWrap(decimals >= 0 ? x * coeff : _divrnd(x, coeff, rounding));\n    }\n\n    /// Add a uint192 to this uint192\n    /// @return x + y\n    // as-ints: x + y\n    function plus(uint192 x, uint192 y) internal pure returns (uint192) {\n        return x + y;\n    }\n\n    /// Add a uint to this uint192\n    /// @return x + y\n    // as-ints: x + y*1e18\n    function plusu(uint192 x, uint256 y) internal pure returns (uint192) {\n        return _safeWrap(x + y * FIX_SCALE);\n    }\n\n    /// Subtract a uint192 from this uint192\n    /// @return x - y\n    // as-ints: x - y\n    function minus(uint192 x, uint192 y) internal pure returns (uint192) {\n        return x - y;\n    }\n\n    /// Subtract a uint from this uint192\n    /// @return x - y\n    // as-ints: x - y*1e18\n    function minusu(uint192 x, uint256 y) internal pure returns (uint192) {\n        return _safeWrap(uint256(x) - uint256(y * FIX_SCALE));\n    }\n\n    /// Multiply this uint192 by a uint192\n    /// Round truncated values to the nearest available value. 5e-19 rounds away from zero.\n    /// @return x * y\n    // as-ints: x * y/1e18  [division using ROUND, not FLOOR]\n    function mul(uint192 x, uint192 y) internal pure returns (uint192) {\n        return mul(x, y, ROUND);\n    }\n\n    /// Multiply this uint192 by a uint192\n    /// @return x * y\n    // as-ints: x * y/1e18\n    function mul(\n        uint192 x,\n        uint192 y,\n        RoundingMode rounding\n    ) internal pure returns (uint192) {\n        return _safeWrap(_divrnd(uint256(x) * uint256(y), FIX_SCALE, rounding));\n    }\n\n    /// Multiply this uint192 by a uint\n    /// @return x * y\n    // as-ints: x * y\n    function mulu(uint192 x, uint256 y) internal pure returns (uint192) {\n        return _safeWrap(x * y);\n    }\n\n    /// Divide this uint192 by a uint192\n    /// @return x / y\n    // as-ints: x * 1e18 / y\n    function div(uint192 x, uint192 y) internal pure returns (uint192) {\n        return div(x, y, FLOOR);\n    }\n\n    /// Divide this uint192 by a uint192\n    /// @return x / y\n    // as-ints: x * 1e18 / y\n    function div(\n        uint192 x,\n        uint192 y,\n        RoundingMode rounding\n    ) internal pure returns (uint192) {\n        // Multiply-in FIX_SCALE before dividing by y to preserve precision.\n        return _safeWrap(_divrnd(uint256(x) * FIX_SCALE, y, rounding));\n    }\n\n    /// Divide this uint192 by a uint\n    /// @return x / y\n    // as-ints: x / y\n    function divu(uint192 x, uint256 y) internal pure returns (uint192) {\n        return divu(x, y, FLOOR);\n    }\n\n    /// Divide this uint192 by a uint\n    /// @return x / y\n    // as-ints: x / y\n    function divu(\n        uint192 x,\n        uint256 y,\n        RoundingMode rounding\n    ) internal pure returns (uint192) {\n        return _safeWrap(_divrnd(x, y, rounding));\n    }\n\n    uint64 constant FIX_HALF = uint64(FIX_SCALE) / 2;\n\n    /// Raise this uint192 to a nonnegative integer power.\n    /// Intermediate muls do nearest-value rounding.\n    /// Presumes that powu(0.0, 0) = 1\n    /// @dev The gas cost is O(lg(y))\n    /// @return x_ ** y\n    // as-ints: x_ ** y / 1e18**(y-1)    <- technically correct for y = 0. :D\n    function powu(uint192 x_, uint48 y) internal pure returns (uint192) {\n        // The algorithm is exponentiation by squaring. See: https://w.wiki/4LjE\n        if (y == 1) return x_;\n        if (x_ == FIX_ONE || y == 0) return FIX_ONE;\n        uint256 x = uint256(x_);\n        uint256 result = FIX_SCALE;\n        while (true) {\n            if (y & 1 == 1) result = (result * x + FIX_HALF) / FIX_SCALE;\n            if (y <= 1) break;\n            y = y >> 1;\n            x = (x * x + FIX_HALF) / FIX_SCALE;\n        }\n        return _safeWrap(result);\n    }\n\n    /// Comparison operators...\n    function lt(uint192 x, uint192 y) internal pure returns (bool) {\n        return x < y;\n    }\n\n    function lte(uint192 x, uint192 y) internal pure returns (bool) {\n        return x <= y;\n    }\n\n    function gt(uint192 x, uint192 y) internal pure returns (bool) {\n        return x > y;\n    }\n\n    function gte(uint192 x, uint192 y) internal pure returns (bool) {\n        return x >= y;\n    }\n\n    function eq(uint192 x, uint192 y) internal pure returns (bool) {\n        return x == y;\n    }\n\n    function neq(uint192 x, uint192 y) internal pure returns (bool) {\n        return x != y;\n    }\n\n    /// Return whether or not this uint192 is less than epsilon away from y.\n    /// @return |x - y| < epsilon\n    // as-ints: |x - y| < epsilon\n    function near(\n        uint192 x,\n        uint192 y,\n        uint192 epsilon\n    ) internal pure returns (bool) {\n        uint192 diff = x <= y ? y - x : x - y;\n        return diff < epsilon;\n    }\n\n    // ================ Chained Operations ================\n    // The operation foo_bar() always means:\n    //   Do foo() followed by bar(), and overflow only if the _end_ result doesn't fit in an uint192\n\n    /// Shift this uint192 left by `decimals` digits, and convert to a uint\n    /// @return x * 10**decimals\n    // as-ints: x * 10**(decimals - 18)\n    function shiftl_toUint(uint192 x, int8 decimals) internal pure returns (uint256) {\n        return shiftl_toUint(x, decimals, FLOOR);\n    }\n\n    /// Shift this uint192 left by `decimals` digits, and convert to a uint.\n    /// @return x * 10**decimals\n    // as-ints: x * 10**(decimals - 18)\n    function shiftl_toUint(\n        uint192 x,\n        int8 decimals,\n        RoundingMode rounding\n    ) internal pure returns (uint256) {\n        decimals -= 18; // shift so that toUint happens at the same time.\n        uint256 coeff = uint256(10**abs(decimals));\n        return decimals >= 0 ? uint256(x * coeff) : uint256(_divrnd(x, coeff, rounding));\n    }\n\n    /// Multiply this uint192 by a uint, and output the result as a uint\n    /// @return x * y\n    // as-ints: x * y / 1e18\n    function mulu_toUint(uint192 x, uint256 y) internal pure returns (uint256) {\n        return mulDiv256(uint256(x), y, FIX_SCALE);\n    }\n\n    /// Multiply this uint192 by a uint, and output the result as a uint\n    /// @return x * y\n    // as-ints: x * y / 1e18\n    function mulu_toUint(\n        uint192 x,\n        uint256 y,\n        RoundingMode rounding\n    ) internal pure returns (uint256) {\n        return mulDiv256(uint256(x), y, FIX_SCALE, rounding);\n    }\n\n    /// Multiply this uint192 by a uint192 and output the result as a uint\n    /// @return x * y\n    // as-ints: x * y / 1e36\n    function mul_toUint(uint192 x, uint192 y) internal pure returns (uint256) {\n        return mulDiv256(uint256(x), uint256(y), FIX_SCALE_SQ);\n    }\n\n    /// Multiply this uint192 by a uint192 and output the result as a uint\n    /// @return x * y\n    // as-ints: x * y / 1e36\n    function mul_toUint(\n        uint192 x,\n        uint192 y,\n        RoundingMode rounding\n    ) internal pure returns (uint256) {\n        return mulDiv256(uint256(x), uint256(y), FIX_SCALE_SQ, rounding);\n    }\n\n    /// Compute x * y / z avoiding intermediate overflow\n    /// @dev Only use if you need to avoid overflow; costlier than x * y / z\n    /// @return x * y / z\n    // as-ints: x * y / z\n    function muluDivu(\n        uint192 x,\n        uint256 y,\n        uint256 z\n    ) internal pure returns (uint192) {\n        return muluDivu(x, y, z, FLOOR);\n    }\n\n    /// Compute x * y / z, avoiding intermediate overflow\n    /// @dev Only use if you need to avoid overflow; costlier than x * y / z\n    /// @return x * y / z\n    // as-ints: x * y / z\n    function muluDivu(\n        uint192 x,\n        uint256 y,\n        uint256 z,\n        RoundingMode rounding\n    ) internal pure returns (uint192) {\n        return _safeWrap(mulDiv256(x, y, z, rounding));\n    }\n\n    /// Compute x * y / z on Fixes, avoiding intermediate overflow\n    /// @dev Only use if you need to avoid overflow; costlier than x * y / z\n    /// @return x * y / z\n    // as-ints: x * y / z\n    function mulDiv(\n        uint192 x,\n        uint192 y,\n        uint192 z\n    ) internal pure returns (uint192) {\n        return mulDiv(x, y, z, FLOOR);\n    }\n\n    /// Compute x * y / z on Fixes, avoiding intermediate overflow\n    /// @dev Only use if you need to avoid overflow; costlier than x * y / z\n    /// @return x * y / z\n    // as-ints: x * y / z\n    function mulDiv(\n        uint192 x,\n        uint192 y,\n        uint192 z,\n        RoundingMode rounding\n    ) internal pure returns (uint192) {\n        return _safeWrap(mulDiv256(x, y, z, rounding));\n    }\n}\n\n// ================ a couple pure-uint helpers================\n// as-ints comments are omitted here, because they're the same as @return statements, because\n// these are all pure uint functions\n\n/// Return (x*y/z), avoiding intermediate overflow.\n//  Adapted from sources:\n//    https://medium.com/coinmonks/4db014e080b1, https://medium.com/wicketh/afa55870a65\n//    and quite a few of the other excellent \"Mathemagic\" posts from https://medium.com/wicketh\n/// @dev Only use if you need to avoid overflow; costlier than x * y / z\n/// @return result x * y / z\nfunction mulDiv256(\n    uint256 x,\n    uint256 y,\n    uint256 z\n) pure returns (uint256 result) {\n    unchecked {\n        (uint256 hi, uint256 lo) = fullMul(x, y);\n        if (hi >= z) revert UIntOutOfBounds();\n        uint256 mm = mulmod(x, y, z);\n        if (mm > lo) hi -= 1;\n        lo -= mm;\n        uint256 pow2 = z & (0 - z);\n        z /= pow2;\n        lo /= pow2;\n        lo += hi * ((0 - pow2) / pow2 + 1);\n        uint256 r = 1;\n        r *= 2 - z * r;\n        r *= 2 - z * r;\n        r *= 2 - z * r;\n        r *= 2 - z * r;\n        r *= 2 - z * r;\n        r *= 2 - z * r;\n        r *= 2 - z * r;\n        r *= 2 - z * r;\n        result = lo * r;\n    }\n}\n\n/// Return (x*y/z), avoiding intermediate overflow.\n/// @dev Only use if you need to avoid overflow; costlier than x * y / z\n/// @return x * y / z\nfunction mulDiv256(\n    uint256 x,\n    uint256 y,\n    uint256 z,\n    RoundingMode rounding\n) pure returns (uint256) {\n    uint256 result = mulDiv256(x, y, z);\n    if (rounding == FLOOR) return result;\n\n    uint256 mm = mulmod(x, y, z);\n    if (rounding == CEIL) {\n        if (mm > 0) result += 1;\n    } else {\n        if (mm > ((z - 1) / 2)) result += 1; // z should be z-1\n    }\n    return result;\n}\n\n/// Return (x*y) as a \"virtual uint512\" (lo, hi), representing (hi*2**256 + lo)\n///   Adapted from sources:\n///   https://medium.com/wicketh/27650fec525d, https://medium.com/coinmonks/4db014e080b1\n/// @dev Intended to be internal to this library\n/// @return hi (hi, lo) satisfies  hi*(2**256) + lo == x * y\n/// @return lo (paired with `hi`)\nfunction fullMul(uint256 x, uint256 y) pure returns (uint256 hi, uint256 lo) {\n    unchecked {\n        uint256 mm = mulmod(x, y, uint256(0) - uint256(1));\n        lo = x * y;\n        hi = mm - lo;\n        if (mm < lo) hi -= 1;\n    }\n}\n"
    },
    "@openzeppelin/contracts-upgradeable/access/IAccessControlUpgradeable.sol": {
      "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts v4.4.1 (access/IAccessControl.sol)\n\npragma solidity ^0.8.0;\n\n/**\n * @dev External interface of AccessControl declared to support ERC165 detection.\n */\ninterface IAccessControlUpgradeable {\n    /**\n     * @dev Emitted when `newAdminRole` is set as ``role``'s admin role, replacing `previousAdminRole`\n     *\n     * `DEFAULT_ADMIN_ROLE` is the starting admin for all roles, despite\n     * {RoleAdminChanged} not being emitted signaling this.\n     *\n     * _Available since v3.1._\n     */\n    event RoleAdminChanged(bytes32 indexed role, bytes32 indexed previousAdminRole, bytes32 indexed newAdminRole);\n\n    /**\n     * @dev Emitted when `account` is granted `role`.\n     *\n     * `sender` is the account that originated the contract call, an admin role\n     * bearer except when using {AccessControl-_setupRole}.\n     */\n    event RoleGranted(bytes32 indexed role, address indexed account, address indexed sender);\n\n    /**\n     * @dev Emitted when `account` is revoked `role`.\n     *\n     * `sender` is the account that originated the contract call:\n     *   - if using `revokeRole`, it is the admin role bearer\n     *   - if using `renounceRole`, it is the role bearer (i.e. `account`)\n     */\n    event RoleRevoked(bytes32 indexed role, address indexed account, address indexed sender);\n\n    /**\n     * @dev Returns `true` if `account` has been granted `role`.\n     */\n    function hasRole(bytes32 role, address account) external view returns (bool);\n\n    /**\n     * @dev Returns the admin role that controls `role`. See {grantRole} and\n     * {revokeRole}.\n     *\n     * To change a role's admin, use {AccessControl-_setRoleAdmin}.\n     */\n    function getRoleAdmin(bytes32 role) external view returns (bytes32);\n\n    /**\n     * @dev Grants `role` to `account`.\n     *\n     * If `account` had not been already granted `role`, emits a {RoleGranted}\n     * event.\n     *\n     * Requirements:\n     *\n     * - the caller must have ``role``'s admin role.\n     */\n    function grantRole(bytes32 role, address account) external;\n\n    /**\n     * @dev Revokes `role` from `account`.\n     *\n     * If `account` had been granted `role`, emits a {RoleRevoked} event.\n     *\n     * Requirements:\n     *\n     * - the caller must have ``role``'s admin role.\n     */\n    function revokeRole(bytes32 role, address account) external;\n\n    /**\n     * @dev Revokes `role` from the calling account.\n     *\n     * Roles are often managed via {grantRole} and {revokeRole}: this function's\n     * purpose is to provide a mechanism for accounts to lose their privileges\n     * if they are compromised (such as when a trusted device is misplaced).\n     *\n     * If the calling account had been granted `role`, emits a {RoleRevoked}\n     * event.\n     *\n     * Requirements:\n     *\n     * - the caller must be `account`.\n     */\n    function renounceRole(bytes32 role, address account) external;\n}\n"
    },
    "contracts/interfaces/IBasketHandler.sol": {
      "content": "// SPDX-License-Identifier: BlueOak-1.0.0\npragma solidity 0.8.9;\n\nimport \"@openzeppelin/contracts/token/ERC20/IERC20.sol\";\nimport \"contracts/libraries/Fixed.sol\";\nimport \"./IAsset.sol\";\nimport \"./IComponent.sol\";\n\n/**\n * @title IBasketHandler\n * @notice The BasketHandler aims to maintain a reference basket of constant target unit amounts.\n * When a collateral token defaults, a new reference basket of equal target units is set.\n * When _all_ collateral tokens default for a target unit, only then is the basket allowed to fall\n *   in terms of target unit amounts. The basket is considered defaulted in this case.\n */\ninterface IBasketHandler is IComponent {\n    /// Emitted when the prime basket is set\n    /// @param erc20s The collateral tokens for the prime basket\n    /// @param targetAmts {target/BU} A list of quantities of target unit per basket unit\n    /// @param targetNames Each collateral token's targetName\n    event PrimeBasketSet(IERC20[] erc20s, uint192[] targetAmts, bytes32[] targetNames);\n\n    /// Emitted when the reference basket is set\n    /// @param nonce The basket nonce\n    /// @param erc20s The list of collateral tokens in the reference basket\n    /// @param refAmts {ref/BU} The reference amounts of the basket collateral tokens\n    /// @param disabled True when the list of erc20s + refAmts may not be correct\n    event BasketSet(uint256 indexed nonce, IERC20[] erc20s, uint192[] refAmts, bool disabled);\n\n    /// Emitted when a backup config is set for a target unit\n    /// @param targetName The name of the target unit as a bytes32\n    /// @param max The max number to use from `erc20s`\n    /// @param erc20s The set of backup collateral tokens\n    event BackupConfigSet(bytes32 indexed targetName, uint256 indexed max, IERC20[] erc20s);\n\n    // Initialization\n    function init(IMain main_) external;\n\n    /// Set the prime basket\n    /// @param erc20s The collateral tokens for the new prime basket\n    /// @param targetAmts The target amounts (in) {target/BU} for the new prime basket\n    ///                   required range: 1e9 values; absolute range irrelevant.\n    /// @custom:governance\n    function setPrimeBasket(IERC20[] memory erc20s, uint192[] memory targetAmts) external;\n\n    /// Set the backup configuration for a given target\n    /// @param targetName The name of the target as a bytes32\n    /// @param max The maximum number of collateral tokens to use from this target\n    ///            Required range: 1-255\n    /// @param erc20s A list of ordered backup collateral tokens\n    /// @custom:governance\n    function setBackupConfig(\n        bytes32 targetName,\n        uint256 max,\n        IERC20[] calldata erc20s\n    ) external;\n\n    /// Default the basket in order to schedule a basket refresh\n    /// @custom:protected\n    function disableBasket() external;\n\n    /// Governance-controlled setter to cause a basket switch explicitly\n    /// @custom:governance\n    /// @custom:interaction\n    function refreshBasket() external;\n\n    /// @return If the BackingManager has sufficient collateral to redeem the entire RToken supply\n    function fullyCollateralized() external view returns (bool);\n\n    /// @return status The worst CollateralStatus of all collateral in the basket\n    function status() external view returns (CollateralStatus status);\n\n    /// @return {tok/BU} The whole token quantity of token in the reference basket\n    /// Returns 0 if erc20 is not registered, disabled, or not in the basket\n    /// Returns FIX_MAX (in lieu of +infinity) if Collateral.refPerTok() is 0.\n    /// Otherwise, returns (token's basket.refAmts / token's Collateral.refPerTok())\n    function quantity(IERC20 erc20) external view returns (uint192);\n\n    /// @param amount {BU}\n    /// @return erc20s The addresses of the ERC20 tokens in the reference basket\n    /// @return quantities {qTok} The quantity of each ERC20 token to issue `amount` baskets\n    function quote(uint192 amount, RoundingMode rounding)\n        external\n        view\n        returns (address[] memory erc20s, uint256[] memory quantities);\n\n    /// @return baskets {BU} The quantity of complete baskets at an address. A balance for BUs\n    function basketsHeldBy(address account) external view returns (uint192 baskets);\n\n    /// @param allowFallback Whether to fail over to the fallback price or not\n    /// @return isFallback If any fallback prices were used\n    /// @return p {UoA/BU} The protocol's best guess at what a BU would be priced at in UoA\n    function price(bool allowFallback) external view returns (bool isFallback, uint192 p);\n\n    /// @return The basket nonce, a monotonically increasing unique identifier\n    function nonce() external view returns (uint48);\n\n    /// @return timestamp The timestamp at which the basket was last set\n    function timestamp() external view returns (uint48);\n}\n"
    },
    "contracts/interfaces/IBackingManager.sol": {
      "content": "// SPDX-License-Identifier: BlueOak-1.0.0\npragma solidity 0.8.9;\n\nimport \"@openzeppelin/contracts/token/ERC20/IERC20.sol\";\nimport \"./IComponent.sol\";\nimport \"./ITrading.sol\";\n\n/**\n * @title IBackingManager\n * @notice The BackingManager handles changes in the ERC20 balances that back an RToken.\n *   - It computes which trades to perform, if any, and initiates these trades with the Broker.\n *   - If already capitalized, excess assets are transferred to RevenueTraders.\n *\n * `manageTokens(erc20s)` and `manageTokensSortedOrder(erc20s)` are handles for getting at the\n *   same underlying functionality. The former allows an ERC20 list in any order, while the\n *   latter requires a sorted array, and executes in O(n) rather than O(n^2) time. In the\n *   vast majority of cases we expect the the O(n^2) function to be acceptable.\n */\ninterface IBackingManager is IComponent, ITrading {\n    event TradingDelaySet(uint48 indexed oldVal, uint48 indexed newVal);\n    event BackingBufferSet(uint192 indexed oldVal, uint192 indexed newVal);\n\n    // Initialization\n    function init(\n        IMain main_,\n        uint48 tradingDelay_,\n        uint192 backingBuffer_,\n        uint192 maxTradeSlippage_,\n        uint192 minTradeVolume_\n    ) external;\n\n    // Give RToken max allowance over a registered token\n    /// @custom:refresher\n    /// @custom:interaction\n    function grantRTokenAllowance(IERC20) external;\n\n    /// Mointain the overall backing policy; handout assets otherwise\n    /// @dev Performs a uniqueness check on the erc20s list in O(n^2)\n    /// @custom:interaction\n    function manageTokens(IERC20[] memory erc20s) external;\n\n    /// Mointain the overall backing policy; handout assets otherwise\n    /// @dev Tokens must be in sorted order!\n    /// @dev Performs a uniqueness check on the erc20s list in O(n)\n    /// @custom:interaction\n    function manageTokensSortedOrder(IERC20[] memory erc20s) external;\n}\n\ninterface TestIBackingManager is IBackingManager, TestITrading {\n    function tradingDelay() external view returns (uint48);\n\n    function backingBuffer() external view returns (uint192);\n\n    function setTradingDelay(uint48 val) external;\n\n    function setBackingBuffer(uint192 val) external;\n}\n"
    },
    "contracts/interfaces/IBroker.sol": {
      "content": "// SPDX-License-Identifier: BlueOak-1.0.0\npragma solidity 0.8.9;\n\nimport \"./IAsset.sol\";\nimport \"./IComponent.sol\";\nimport \"./IGnosis.sol\";\nimport \"./ITrade.sol\";\n\n/// The data format that describes a request for trade with the Broker\nstruct TradeRequest {\n    IAsset sell;\n    IAsset buy;\n    uint256 sellAmount; // {qSellTok}\n    uint256 minBuyAmount; // {qBuyTok}\n}\n\n/**\n * @title IBroker\n * @notice The Broker deploys oneshot Trade contracts for Traders and monitors\n *   the continued proper functioning of trading platforms.\n */\ninterface IBroker is IComponent {\n    event AuctionLengthSet(uint48 indexed oldVal, uint48 indexed newVal);\n    event DisabledSet(bool indexed prevVal, bool indexed newVal);\n\n    // Initialization\n    function init(\n        IMain main_,\n        IGnosis gnosis_,\n        ITrade tradeImplementation_,\n        uint48 auctionLength_\n    ) external;\n\n    /// Request a trade from the broker\n    /// @dev Requires setting an allowance in advance\n    /// @custom:interaction\n    function openTrade(TradeRequest memory req) external returns (ITrade);\n\n    /// Only callable by one of the trading contracts the broker deploys\n    function reportViolation() external;\n\n    function disabled() external view returns (bool);\n}\n\ninterface TestIBroker is IBroker {\n    function gnosis() external view returns (IGnosis);\n\n    function auctionLength() external view returns (uint48);\n\n    function setAuctionLength(uint48 newAuctionLength) external;\n\n    function setDisabled(bool disabled_) external;\n}\n"
    },
    "contracts/interfaces/IGnosis.sol": {
      "content": "// SPDX-License-Identifier: BlueOak-1.0.0\npragma solidity 0.8.9;\n\nimport \"@openzeppelin/contracts/token/ERC20/IERC20.sol\";\n\nstruct GnosisAuctionData {\n    IERC20 auctioningToken;\n    IERC20 biddingToken;\n    uint256 orderCancellationEndDate;\n    uint256 auctionEndDate;\n    bytes32 initialAuctionOrder;\n    uint256 minimumBiddingAmountPerOrder;\n    uint256 interimSumBidAmount;\n    bytes32 interimOrder;\n    bytes32 clearingPriceOrder;\n    uint96 volumeClearingPriceOrder;\n    bool minFundingThresholdNotReached;\n    bool isAtomicClosureAllowed;\n    uint256 feeNumerator;\n    uint256 minFundingThreshold;\n}\n\n/// The relevant portion of the interface of the live Gnosis EasyAuction contract\n/// https://github.com/gnosis/ido-contracts/blob/main/contracts/EasyAuction.sol\ninterface IGnosis {\n    function initiateAuction(\n        IERC20 auctioningToken,\n        IERC20 biddingToken,\n        uint256 orderCancellationEndDate,\n        uint256 auctionEndDate,\n        uint96 auctionedSellAmount,\n        uint96 minBuyAmount,\n        uint256 minimumBiddingAmountPerOrder,\n        uint256 minFundingThreshold,\n        bool isAtomicClosureAllowed,\n        address accessManagerContract,\n        bytes memory accessManagerContractData\n    ) external returns (uint256 auctionId);\n\n    function auctionData(uint256 auctionId) external view returns (GnosisAuctionData memory);\n\n    /// @param auctionId The external auction id\n    /// @dev See here for decoding: https://git.io/JMang\n    /// @return encodedOrder The order, encoded in a bytes 32\n    function settleAuction(uint256 auctionId) external returns (bytes32 encodedOrder);\n\n    /// @return The numerator over a 1000-valued denominator\n    function feeNumerator() external returns (uint256);\n}\n"
    },
    "contracts/interfaces/IFurnace.sol": {
      "content": "// SPDX-License-Identifier: BlueOak-1.0.0\npragma solidity 0.8.9;\n\nimport \"contracts/libraries/Fixed.sol\";\nimport \"./IComponent.sol\";\n\n/**\n * @title IFurnace\n * @notice A helper contract to burn RTokens slowly and permisionlessly.\n */\ninterface IFurnace is IComponent {\n    // Initialization\n    function init(\n        IMain main_,\n        uint48 period_,\n        uint192 ratio_\n    ) external;\n\n    /// Emitted when the melting period is changed\n    /// @param oldPeriod The old period\n    /// @param newPeriod The new period\n    event PeriodSet(uint48 indexed oldPeriod, uint48 indexed newPeriod);\n\n    function period() external view returns (uint48);\n\n    /// @custom:governance\n    function setPeriod(uint48) external;\n\n    /// Emitted when the melting ratio is changed\n    /// @param oldRatio The old ratio\n    /// @param newRatio The new ratio\n    event RatioSet(uint192 indexed oldRatio, uint192 indexed newRatio);\n\n    function ratio() external view returns (uint192);\n\n    ///    Needed value range: [0, 1], granularity 1e-9\n    /// @custom:governance\n    function setRatio(uint192) external;\n\n    /// Performs any RToken melting that has vested since the last payout.\n    /// @custom:refresher\n    function melt() external;\n}\n\ninterface TestIFurnace is IFurnace {\n    function lastPayout() external view returns (uint256);\n\n    function lastPayoutBal() external view returns (uint256);\n}\n"
    },
    "contracts/interfaces/IDistributor.sol": {
      "content": "// SPDX-License-Identifier: BlueOak-1.0.0\npragma solidity 0.8.9;\n\nimport \"@openzeppelin/contracts/token/ERC20/IERC20.sol\";\nimport \"./IComponent.sol\";\n\nstruct RevenueShare {\n    uint16 rTokenDist; // {revShare} A value between [0, 10,000]\n    uint16 rsrDist; // {revShare} A value between [0, 10,000]\n}\n\n/// Assumes no more than 1024 independent distributions.\nstruct RevenueTotals {\n    uint24 rTokenTotal; // {revShare}\n    uint24 rsrTotal; // {revShare}\n}\n\n/**\n * @title IDistributor\n * @notice The Distributor Component maintains a revenue distribution table that dictates\n *   how to divide revenue across the Furnace, StRSR, and any other destinations.\n */\ninterface IDistributor is IComponent {\n    /// Emitted when a distribution is set\n    /// @param dest The address set to receive the distribution\n    /// @param rTokenDist The distribution of RToken that should go to `dest`\n    /// @param rsrDist The distribution of RSR that should go to `dest`\n    event DistributionSet(address dest, uint16 rTokenDist, uint16 rsrDist);\n\n    /// Emitted when revenue is distributed\n    /// @param erc20 The token being distributed, either RSR or the RToken itself\n    /// @param source The address providing the revenue\n    /// @param amount The amount of the revenue\n    event RevenueDistributed(IERC20 indexed erc20, address indexed source, uint256 indexed amount);\n\n    // Initialization\n    function init(IMain main_, RevenueShare memory dist) external;\n\n    /// @custom:governance\n    function setDistribution(address dest, RevenueShare memory share) external;\n\n    /// Distribute the `erc20` token across all revenue destinations\n    /// @custom:interaction\n    function distribute(\n        IERC20 erc20,\n        address from,\n        uint256 amount\n    ) external;\n\n    /// @return revTotals The total of all  destinations\n    function totals() external view returns (RevenueTotals memory revTotals);\n}\n\ninterface TestIDistributor is IDistributor {\n    // solhint-disable-next-line func-name-mixedcase\n    function FURNACE() external view returns (address);\n\n    // solhint-disable-next-line func-name-mixedcase\n    function ST_RSR() external view returns (address);\n}\n"
    },
    "contracts/interfaces/IRToken.sol": {
      "content": "// SPDX-License-Identifier: BlueOak-1.0.0\npragma solidity 0.8.9;\n\nimport \"@openzeppelin/contracts-upgradeable/token/ERC20/extensions/IERC20MetadataUpgradeable.sol\";\n// solhint-disable-next-line max-line-length\nimport \"@openzeppelin/contracts-upgradeable/token/ERC20/extensions/draft-IERC20PermitUpgradeable.sol\";\nimport \"contracts/libraries/Fixed.sol\";\nimport \"./IAsset.sol\";\nimport \"./IComponent.sol\";\nimport \"./IMain.sol\";\nimport \"./IRewardable.sol\";\n\n/**\n * @title IRToken\n * @notice An RToken is an ERC20 that is permissionlessly issuable/redeemable and tracks an\n *   exchange rate against a single unit: baskets, or {BU} in our type notation.\n */\ninterface IRToken is IRewardable, IERC20MetadataUpgradeable, IERC20PermitUpgradeable {\n    /// Emitted when issuance is started, at the point collateral is taken in\n    /// @param issuer The account performing the issuance\n    /// @param index The index off the issuance in the issuer's queue\n    /// @param amount The quantity of RToken being issued\n    /// @param baskets The basket unit-equivalent of the collateral deposits\n    /// @param erc20s The ERC20 collateral tokens corresponding to the quantities\n    /// @param quantities The quantities of tokens paid with\n    /// @param blockAvailableAt The (continuous) block at which the issuance vests\n    event IssuanceStarted(\n        address indexed issuer,\n        uint256 indexed index,\n        uint256 indexed amount,\n        uint192 baskets,\n        address[] erc20s,\n        uint256[] quantities,\n        uint192 blockAvailableAt\n    );\n\n    /// Emitted when an RToken issuance is canceled, such as during a default\n    /// @param issuer The account of the issuer\n    /// @param firstId The first of the cancelled issuances in the issuer's queue\n    /// @param endId The index _after_ the last of the cancelled issuances in the issuer's queue\n    /// @param amount {qRTok} The amount of RTokens canceled\n    /// That is, id was cancelled iff firstId <= id < endId\n    event IssuancesCanceled(\n        address indexed issuer,\n        uint256 indexed firstId,\n        uint256 indexed endId,\n        uint256 amount\n    );\n\n    /// Emitted when an RToken issuance is completed successfully\n    /// @param issuer The account of the issuer\n    /// @param firstId The first of the completed issuances in the issuer's queue\n    /// @param endId The id directly after the last of the completed issuances\n    /// @param amount {qRTok} The amount of RTokens canceled\n    event IssuancesCompleted(\n        address indexed issuer,\n        uint256 indexed firstId,\n        uint256 indexed endId,\n        uint256 amount\n    );\n\n    /// Emitted when an issuance of RToken occurs, whether it occurs via slow minting or not\n    /// @param issuer The address of the account issuing RTokens\n    /// @param amount The quantity of RToken being issued\n    /// @param baskets The corresponding number of baskets\n    event Issuance(address indexed issuer, uint256 indexed amount, uint192 indexed baskets);\n\n    /// Emitted when a redemption of RToken occurs\n    /// @param redeemer The address of the account redeeeming RTokens\n    /// @param amount The quantity of RToken being redeemed\n    /// @param baskets The corresponding number of baskets\n    /// @param amount {qRTok} The amount of RTokens canceled\n    event Redemption(address indexed redeemer, uint256 indexed amount, uint192 baskets);\n\n    /// Emitted when the number of baskets needed changes\n    /// @param oldBasketsNeeded Previous number of baskets units needed\n    /// @param newBasketsNeeded New number of basket units needed\n    event BasketsNeededChanged(uint192 oldBasketsNeeded, uint192 newBasketsNeeded);\n\n    /// Emitted when RToken is melted, i.e the RToken supply is decreased but basketsNeeded is not\n    /// @param amount {qRTok}\n    event Melted(uint256 amount);\n\n    /// Emitted when the IssuanceRate is set\n    event IssuanceRateSet(uint192 indexed oldVal, uint192 indexed newVal);\n\n    /// Emitted when the redemption battery max charge is set\n    event ScalingRedemptionRateSet(uint192 indexed oldVal, uint192 indexed newVal);\n\n    /// Emitted when the dust supply is set\n    event RedemptionRateFloorSet(uint256 indexed oldVal, uint256 indexed newVal);\n\n    // Initialization\n    function init(\n        IMain main_,\n        string memory name_,\n        string memory symbol_,\n        string memory mandate_,\n        uint192 issuanceRate_,\n        uint192 redemptionBattery_,\n        uint256 redemptionVirtualSupply_\n    ) external;\n\n    /// Begin a time-delayed issuance of RToken for basket collateral\n    /// @param amount {qRTok} The quantity of RToken to issue\n    /// @custom:interaction\n    function issue(uint256 amount) external;\n\n    /// Cancels a vesting slow issuance of _msgSender\n    /// If earliest == true, cancel id if id < endId\n    /// If earliest == false, cancel id if endId <= id\n    /// @param endId One edge of the issuance range to cancel\n    /// @param earliest If true, cancel earliest issuances; else, cancel latest issuances\n    /// @custom:interaction\n    function cancel(uint256 endId, bool earliest) external;\n\n    /// Completes vested slow issuances for the account, up to endId.\n    /// @param account The address of the account to vest issuances for\n    /// @custom:interaction\n    function vest(address account, uint256 endId) external;\n\n    /// Redeem RToken for basket collateral\n    /// @param amount {qRTok} The quantity {qRToken} of RToken to redeem\n    /// @custom:interaction\n    function redeem(uint256 amount) external;\n\n    /// Mints a quantity of RToken to the `recipient`, callable only by the BackingManager\n    /// @param recipient The recipient of the newly minted RToken\n    /// @param amount {qRTok} The amount to be minted\n    /// @custom:protected\n    function mint(address recipient, uint256 amount) external;\n\n    /// Melt a quantity of RToken from the caller's account\n    /// @param amount {qRTok} The amount to be melted\n    function melt(uint256 amount) external;\n\n    /// Set the number of baskets needed directly, callable only by the BackingManager\n    /// @param basketsNeeded {BU} The number of baskets to target\n    ///                      needed range: pretty interesting\n    /// @custom:protected\n    function setBasketsNeeded(uint192 basketsNeeded) external;\n\n    /// @return {BU} How many baskets are being targeted\n    function basketsNeeded() external view returns (uint192);\n\n    /// @return {qRTok} The maximum redemption that can be performed in the current block\n    function redemptionLimit() external view returns (uint256);\n}\n\ninterface TestIRToken is IRToken {\n    /// Set the issuance rate as a % of RToken supply\n    function setIssuanceRate(uint192) external;\n\n    /// @return {1} The issuance rate as a percentage of the RToken supply\n    function issuanceRate() external view returns (uint192);\n\n    /// Set the fraction of the RToken supply that can be reedemed at once\n    function setScalingRedemptionRate(uint192 val) external;\n\n    /// @return {1/hour} The maximum fraction of the RToken supply that can be redeemed at once\n    function scalingRedemptionRate() external view returns (uint192);\n\n    /// Set the RToken supply at which full redemptions become enabled\n    function setRedemptionRateFloor(uint256 val) external;\n\n    /// @return {qRTok/hour} The lowest possible hourly redemption limit\n    function redemptionRateFloor() external view returns (uint256);\n}\n"
    },
    "contracts/interfaces/IRevenueTrader.sol": {
      "content": "// SPDX-License-Identifier: BlueOak-1.0.0\npragma solidity 0.8.9;\n\nimport \"./IComponent.sol\";\nimport \"./ITrading.sol\";\n\n/**\n * @title IRevenueTrader\n * @notice The RevenueTrader is an extension of the trading mixin that trades all\n *   assets at its address for a single target asset. There are two runtime instances\n *   of the RevenueTrader, 1 for RToken and 1 for RSR.\n */\ninterface IRevenueTrader is IComponent, ITrading {\n    // Initialization\n    function init(\n        IMain main_,\n        IERC20 tokenToBuy_,\n        uint192 maxTradeSlippage_,\n        uint192 minTradeVolume_\n    ) external;\n\n    /// Processes a single token; unpermissioned\n    /// @dev Intended to be used with multicall\n    /// @custom:interaction\n    function manageToken(IERC20 sell) external;\n}\n\n// solhint-disable-next-line no-empty-blocks\ninterface TestIRevenueTrader is IRevenueTrader, TestITrading {\n    function tokenToBuy() external view returns (IERC20);\n}\n"
    },
    "contracts/interfaces/IStRSR.sol": {
      "content": "// SPDX-License-Identifier: BlueOak-1.0.0\npragma solidity 0.8.9;\n\nimport \"@openzeppelin/contracts-upgradeable/token/ERC20/extensions/IERC20MetadataUpgradeable.sol\";\n// solhint-disable-next-line max-line-length\nimport \"@openzeppelin/contracts-upgradeable/token/ERC20/extensions/draft-IERC20PermitUpgradeable.sol\";\nimport \"contracts/libraries/Fixed.sol\";\nimport \"./IComponent.sol\";\nimport \"./IMain.sol\";\n\n/**\n * @title IStRSR\n * @notice An ERC20 token representing shares of the RSR insurance pool.\n *\n * StRSR permits the BackingManager to take RSR in times of need. In return, the BackingManager\n * benefits the StRSR pool with RSR rewards purchased with a portion of its revenue.\n *\n * In the absence of collateral default or losses due to slippage, StRSR should have a\n * monotonically increasing exchange rate with respect to RSR, meaning that over time\n * StRSR is redeemable for more RSR. It is non-rebasing.\n */\ninterface IStRSR is IERC20MetadataUpgradeable, IERC20PermitUpgradeable, IComponent {\n    /// Emitted when RSR is staked\n    /// @param era The era at time of staking\n    /// @param staker The address of the staker\n    /// @param rsrAmount {qRSR} How much RSR was staked\n    /// @param stRSRAmount {qStRSR} How much stRSR was minted by this staking\n    event Staked(\n        uint256 indexed era,\n        address indexed staker,\n        uint256 rsrAmount,\n        uint256 indexed stRSRAmount\n    );\n\n    /// Emitted when an unstaking is started\n    /// @param draftId The id of the draft.\n    /// @param draftEra The era of the draft.\n    /// @param staker The address of the unstaker\n    ///   The triple (staker, draftEra, draftId) is a unique ID\n    /// @param rsrAmount {qRSR} How much RSR this unstaking will be worth, absent seizures\n    /// @param stRSRAmount {qStRSR} How much stRSR was burned by this unstaking\n    event UnstakingStarted(\n        uint256 indexed draftId,\n        uint256 indexed draftEra,\n        address indexed staker,\n        uint256 rsrAmount,\n        uint256 stRSRAmount,\n        uint256 availableAt\n    );\n\n    /// Emitted when RSR is unstaked\n    /// @param firstId The beginning of the range of draft IDs withdrawn in this transaction\n    /// @param endId The end of range of draft IDs withdrawn in this transaction\n    ///   (ID i was withdrawn if firstId <= i < endId)\n    /// @param draftEra The era of the draft.\n    ///   The triple (staker, draftEra, id) is a unique ID among drafts\n    /// @param staker The address of the unstaker\n\n    /// @param rsrAmount {qRSR} How much RSR this unstaking was worth\n    event UnstakingCompleted(\n        uint256 indexed firstId,\n        uint256 indexed endId,\n        uint256 draftEra,\n        address indexed staker,\n        uint256 rsrAmount\n    );\n\n    /// Emitted whenever the exchange rate changes\n    event ExchangeRateSet(uint192 indexed oldVal, uint192 indexed newVal);\n\n    /// Emitted whenever RSR are paids out\n    event RewardsPaid(uint256 indexed rsrAmt);\n\n    /// Emitted if all the RSR in the staking pool is seized and all balances are reset to zero.\n    event AllBalancesReset(uint256 indexed newEra);\n    /// Emitted if all the RSR in the unstakin pool is seized, and all ongoing unstaking is voided.\n    event AllUnstakingReset(uint256 indexed newEra);\n\n    event UnstakingDelaySet(uint48 indexed oldVal, uint48 indexed newVal);\n    event RewardPeriodSet(uint48 indexed oldVal, uint48 indexed newVal);\n    event RewardRatioSet(uint192 indexed oldVal, uint192 indexed newVal);\n\n    // Initialization\n    function init(\n        IMain main_,\n        string memory name_,\n        string memory symbol_,\n        uint48 unstakingDelay_,\n        uint48 rewardPeriod_,\n        uint192 rewardRatio_\n    ) external;\n\n    /// Gather and payout rewards from rsrTrader\n    /// @custom:interaction\n    function payoutRewards() external;\n\n    /// Stakes an RSR `amount` on the corresponding RToken to earn yield and insure the system\n    /// @param amount {qRSR}\n    /// @custom:interaction\n    function stake(uint256 amount) external;\n\n    /// Begins a delayed unstaking for `amount` stRSR\n    /// @param amount {qStRSR}\n    /// @custom:interaction\n    function unstake(uint256 amount) external;\n\n    /// Complete delayed unstaking for the account, up to (but not including!) `endId`\n    /// @custom:interaction\n    function withdraw(address account, uint256 endId) external;\n\n    /// Seize RSR, only callable by main.backingManager()\n    /// @custom:protected\n    function seizeRSR(uint256 amount) external;\n\n    /// Return the maximum valid value of endId such that withdraw(endId) should immediately work\n    function endIdForWithdraw(address account) external view returns (uint256 endId);\n\n    /// @return {qRSR/qStRSR} The exchange rate between RSR and StRSR\n    function exchangeRate() external view returns (uint192);\n}\n\ninterface TestIStRSR is IStRSR {\n    function rewardPeriod() external view returns (uint48);\n\n    function setRewardPeriod(uint48) external;\n\n    function rewardRatio() external view returns (uint192);\n\n    function setRewardRatio(uint192) external;\n\n    function unstakingDelay() external view returns (uint48);\n\n    function setUnstakingDelay(uint48) external;\n\n    function setName(string calldata) external;\n\n    function setSymbol(string calldata) external;\n\n    function increaseAllowance(address, uint256) external returns (bool);\n\n    function decreaseAllowance(address, uint256) external returns (bool);\n\n    /// @return {qStRSR/qRSR} The exchange rate between StRSR and RSR\n    function exchangeRate() external view returns (uint192);\n}\n"
    },
    "contracts/interfaces/ITrading.sol": {
      "content": "// SPDX-License-Identifier: BlueOak-1.0.0\npragma solidity 0.8.9;\n\nimport \"@openzeppelin/contracts/token/ERC20/IERC20.sol\";\nimport \"contracts/libraries/Fixed.sol\";\nimport \"./IAsset.sol\";\nimport \"./ITrade.sol\";\nimport \"./IRewardable.sol\";\n\n/**\n * @title ITrading\n * @notice Common events and refresher function for all Trading contracts\n */\ninterface ITrading is IRewardable {\n    event MaxTradeSlippageSet(uint192 indexed oldVal, uint192 indexed newVal);\n    event MinTradeVolumeSet(uint192 indexed oldVal, uint192 indexed newVal);\n\n    /// Emitted when a trade is started\n    /// @param trade The one-time-use trade contract that was just deployed\n    /// @param sell The token to sell\n    /// @param buy The token to buy\n    /// @param sellAmount {qSellTok} The quantity of the selling token\n    /// @param minBuyAmount {qBuyTok} The minimum quantity of the buying token to accept\n    event TradeStarted(\n        ITrade indexed trade,\n        IERC20 indexed sell,\n        IERC20 indexed buy,\n        uint256 sellAmount,\n        uint256 minBuyAmount\n    );\n\n    /// Emitted after a trade ends\n    /// @param trade The one-time-use trade contract\n    /// @param sell The token to sell\n    /// @param buy The token to buy\n    /// @param sellAmount {qSellTok} The quantity of the token sold\n    /// @param buyAmount {qBuyTok} The quantity of the token bought\n    event TradeSettled(\n        ITrade indexed trade,\n        IERC20 indexed sell,\n        IERC20 indexed buy,\n        uint256 sellAmount,\n        uint256 buyAmount\n    );\n\n    /// Settle a single trade, expected to be used with multicall for efficient mass settlement\n    /// @custom:refresher\n    function settleTrade(IERC20 sell) external;\n\n    /// @return {%} The maximum trade slippage acceptable\n    function maxTradeSlippage() external view returns (uint192);\n\n    /// @return {UoA} The minimum trade volume in UoA, applies to all assets\n    function minTradeVolume() external view returns (uint192);\n\n    /// @return The ongoing trade for a sell token, or the zero address\n    function trades(IERC20 sell) external view returns (ITrade);\n}\n\ninterface TestITrading is ITrading {\n    /// @custom:governance\n    function setMaxTradeSlippage(uint192 val) external;\n\n    /// @custom:governance\n    function setMinTradeVolume(uint192 val) external;\n\n    /// @return The number of ongoing trades open\n    function tradesOpen() external view returns (uint48);\n}\n"
    },
    "contracts/interfaces/ITrade.sol": {
      "content": "// SPDX-License-Identifier: BlueOak-1.0.0\npragma solidity 0.8.9;\n\nimport \"@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol\";\n\n/**\n * Simple generalized trading interface for all Trade contracts to obey\n *\n * Usage: if (canSettle()) settle()\n */\ninterface ITrade {\n    function sell() external view returns (IERC20Metadata);\n\n    function buy() external view returns (IERC20Metadata);\n\n    /// @return The timestamp at which the trade is projected to become settle-able\n    function endTime() external view returns (uint48);\n\n    /// @return True if the trade can be settled\n    /// @dev Should be guaranteed to be true eventually as an invariant\n    function canSettle() external view returns (bool);\n\n    /// Complete the trade and transfer tokens back to the origin trader\n    /// @return soldAmt {qSellTok} The quantity of tokens sold\n    /// @return boughtAmt {qBuyTok} The quantity of tokens bought\n    function settle() external returns (uint256 soldAmt, uint256 boughtAmt);\n}\n"
    },
    "contracts/interfaces/IRewardable.sol": {
      "content": "// SPDX-License-Identifier: BlueOak-1.0.0\npragma solidity 0.8.9;\n\nimport \"./IComponent.sol\";\nimport \"./IMain.sol\";\n\n/**\n * @title IRewardable\n * @notice A simple component mixin interface to support claiming + monetization of rewards\n */\ninterface IRewardable is IComponent {\n    /// Emitted whenever rewards are claimed\n    event RewardsClaimed(address indexed erc20, uint256 indexed amount);\n\n    /// Claim reward tokens from integrated defi protocols such as Compound/Aave\n    /// @custom:interaction\n    function claimAndSweepRewards() external;\n}\n"
    },
    "@openzeppelin/contracts-upgradeable/token/ERC20/extensions/IERC20MetadataUpgradeable.sol": {
      "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts v4.4.1 (token/ERC20/extensions/IERC20Metadata.sol)\n\npragma solidity ^0.8.0;\n\nimport \"../IERC20Upgradeable.sol\";\n\n/**\n * @dev Interface for the optional metadata functions from the ERC20 standard.\n *\n * _Available since v4.1._\n */\ninterface IERC20MetadataUpgradeable is IERC20Upgradeable {\n    /**\n     * @dev Returns the name of the token.\n     */\n    function name() external view returns (string memory);\n\n    /**\n     * @dev Returns the symbol of the token.\n     */\n    function symbol() external view returns (string memory);\n\n    /**\n     * @dev Returns the decimals places of the token.\n     */\n    function decimals() external view returns (uint8);\n}\n"
    },
    "@openzeppelin/contracts-upgradeable/token/ERC20/extensions/draft-IERC20PermitUpgradeable.sol": {
      "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts v4.4.1 (token/ERC20/extensions/draft-IERC20Permit.sol)\n\npragma solidity ^0.8.0;\n\n/**\n * @dev Interface of the ERC20 Permit extension allowing approvals to be made via signatures, as defined in\n * https://eips.ethereum.org/EIPS/eip-2612[EIP-2612].\n *\n * Adds the {permit} method, which can be used to change an account's ERC20 allowance (see {IERC20-allowance}) by\n * presenting a message signed by the account. By not relying on {IERC20-approve}, the token holder account doesn't\n * need to send a transaction, and thus is not required to hold Ether at all.\n */\ninterface IERC20PermitUpgradeable {\n    /**\n     * @dev Sets `value` as the allowance of `spender` over ``owner``'s tokens,\n     * given ``owner``'s signed approval.\n     *\n     * IMPORTANT: The same issues {IERC20-approve} has related to transaction\n     * ordering also apply here.\n     *\n     * Emits an {Approval} event.\n     *\n     * Requirements:\n     *\n     * - `spender` cannot be the zero address.\n     * - `deadline` must be a timestamp in the future.\n     * - `v`, `r` and `s` must be a valid `secp256k1` signature from `owner`\n     * over the EIP712-formatted function arguments.\n     * - the signature must use ``owner``'s current nonce (see {nonces}).\n     *\n     * For more information on the signature format, see the\n     * https://eips.ethereum.org/EIPS/eip-2612#specification[relevant EIP\n     * section].\n     */\n    function permit(\n        address owner,\n        address spender,\n        uint256 value,\n        uint256 deadline,\n        uint8 v,\n        bytes32 r,\n        bytes32 s\n    ) external;\n\n    /**\n     * @dev Returns the current nonce for `owner`. This value must be\n     * included whenever a signature is generated for {permit}.\n     *\n     * Every successful call to {permit} increases ``owner``'s nonce by one. This\n     * prevents a signature from being used multiple times.\n     */\n    function nonces(address owner) external view returns (uint256);\n\n    /**\n     * @dev Returns the domain separator used in the encoding of the signature for {permit}, as defined by {EIP712}.\n     */\n    // solhint-disable-next-line func-name-mixedcase\n    function DOMAIN_SEPARATOR() external view returns (bytes32);\n}\n"
    },
    "@openzeppelin/contracts-upgradeable/token/ERC20/IERC20Upgradeable.sol": {
      "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.6.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(\n        address from,\n        address to,\n        uint256 amount\n    ) external returns (bool);\n}\n"
    },
    "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol": {
      "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.7.0) (proxy/utils/Initializable.sol)\n\npragma solidity ^0.8.2;\n\nimport \"../../utils/AddressUpgradeable.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. Equivalent to `reinitializer(1)`.\n     */\n    modifier initializer() {\n        bool isTopLevelCall = !_initializing;\n        require(\n            (isTopLevelCall && _initialized < 1) || (!AddressUpgradeable.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     * `initializer` is equivalent to `reinitializer(1)`, so a reinitializer may be used after the original\n     * initialization step. This is essential to configure modules that are added through upgrades and that require\n     * initialization.\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    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    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"
    },
    "@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol": {
      "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.5.0) (proxy/utils/UUPSUpgradeable.sol)\n\npragma solidity ^0.8.0;\n\nimport \"../../interfaces/draft-IERC1822Upgradeable.sol\";\nimport \"../ERC1967/ERC1967UpgradeUpgradeable.sol\";\nimport \"./Initializable.sol\";\n\n/**\n * @dev An upgradeability mechanism designed for UUPS proxies. The functions included here can perform an upgrade of an\n * {ERC1967Proxy}, when this contract is set as the implementation behind such a proxy.\n *\n * A security mechanism ensures that an upgrade does not turn off upgradeability accidentally, although this risk is\n * reinstated if the upgrade retains upgradeability but removes the security mechanism, e.g. by replacing\n * `UUPSUpgradeable` with a custom implementation of upgrades.\n *\n * The {_authorizeUpgrade} function must be overridden to include access restriction to the upgrade mechanism.\n *\n * _Available since v4.1._\n */\nabstract contract UUPSUpgradeable is Initializable, IERC1822ProxiableUpgradeable, ERC1967UpgradeUpgradeable {\n    function __UUPSUpgradeable_init() internal onlyInitializing {\n    }\n\n    function __UUPSUpgradeable_init_unchained() internal onlyInitializing {\n    }\n    /// @custom:oz-upgrades-unsafe-allow state-variable-immutable state-variable-assignment\n    address private immutable __self = address(this);\n\n    /**\n     * @dev Check that the execution is being performed through a delegatecall call and that the execution context is\n     * a proxy contract with an implementation (as defined in ERC1967) pointing to self. This should only be the case\n     * for UUPS and transparent proxies that are using the current contract as their implementation. Execution of a\n     * function through ERC1167 minimal proxies (clones) would not normally pass this test, but is not guaranteed to\n     * fail.\n     */\n    modifier onlyProxy() {\n        require(address(this) != __self, \"Function must be called through delegatecall\");\n        require(_getImplementation() == __self, \"Function must be called through active proxy\");\n        _;\n    }\n\n    /**\n     * @dev Check that the execution is not being performed through a delegate call. This allows a function to be\n     * callable on the implementing contract but not through proxies.\n     */\n    modifier notDelegated() {\n        require(address(this) == __self, \"UUPSUpgradeable: must not be called through delegatecall\");\n        _;\n    }\n\n    /**\n     * @dev Implementation of the ERC1822 {proxiableUUID} function. This returns the storage slot used by the\n     * implementation. It is used to validate that the this implementation remains valid after an upgrade.\n     *\n     * IMPORTANT: A proxy pointing at a proxiable contract should not be considered proxiable itself, because this risks\n     * bricking a proxy that upgrades to it, by delegating to itself until out of gas. Thus it is critical that this\n     * function revert if invoked through a proxy. This is guaranteed by the `notDelegated` modifier.\n     */\n    function proxiableUUID() external view virtual override notDelegated returns (bytes32) {\n        return _IMPLEMENTATION_SLOT;\n    }\n\n    /**\n     * @dev Upgrade the implementation of the proxy to `newImplementation`.\n     *\n     * Calls {_authorizeUpgrade}.\n     *\n     * Emits an {Upgraded} event.\n     */\n    function upgradeTo(address newImplementation) external virtual onlyProxy {\n        _authorizeUpgrade(newImplementation);\n        _upgradeToAndCallUUPS(newImplementation, new bytes(0), false);\n    }\n\n    /**\n     * @dev Upgrade the implementation of the proxy to `newImplementation`, and subsequently execute the function call\n     * encoded in `data`.\n     *\n     * Calls {_authorizeUpgrade}.\n     *\n     * Emits an {Upgraded} event.\n     */\n    function upgradeToAndCall(address newImplementation, bytes memory data) external payable virtual onlyProxy {\n        _authorizeUpgrade(newImplementation);\n        _upgradeToAndCallUUPS(newImplementation, data, true);\n    }\n\n    /**\n     * @dev Function that should revert when `msg.sender` is not authorized to upgrade the contract. Called by\n     * {upgradeTo} and {upgradeToAndCall}.\n     *\n     * Normally, this function will use an xref:access.adoc[access control] modifier such as {Ownable-onlyOwner}.\n     *\n     * ```solidity\n     * function _authorizeUpgrade(address) internal override onlyOwner {}\n     * ```\n     */\n    function _authorizeUpgrade(address newImplementation) internal virtual;\n\n    /**\n     * @dev This empty reserved space is put in place to allow future versions to add new\n     * variables without shifting down storage in the inheritance chain.\n     * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps\n     */\n    uint256[50] private __gap;\n}\n"
    },
    "@openzeppelin/contracts-upgradeable/utils/ContextUpgradeable.sol": {
      "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts v4.4.1 (utils/Context.sol)\n\npragma solidity ^0.8.0;\nimport \"../proxy/utils/Initializable.sol\";\n\n/**\n * @dev Provides information about the current execution context, including the\n * sender of the transaction and its data. While these are generally available\n * via msg.sender and msg.data, they should not be accessed in such a direct\n * manner, since when dealing with meta-transactions the account sending and\n * paying for execution may not be the actual sender (as far as an application\n * is concerned).\n *\n * This contract is only required for intermediate, library-like contracts.\n */\nabstract contract ContextUpgradeable is Initializable {\n    function __Context_init() internal onlyInitializing {\n    }\n\n    function __Context_init_unchained() internal onlyInitializing {\n    }\n    function _msgSender() internal view virtual returns (address) {\n        return msg.sender;\n    }\n\n    function _msgData() internal view virtual returns (bytes calldata) {\n        return msg.data;\n    }\n\n    /**\n     * @dev This empty reserved space is put in place to allow future versions to add new\n     * variables without shifting down storage in the inheritance chain.\n     * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps\n     */\n    uint256[50] private __gap;\n}\n"
    },
    "@openzeppelin/contracts-upgradeable/utils/AddressUpgradeable.sol": {
      "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.7.0) (utils/Address.sol)\n\npragma solidity ^0.8.1;\n\n/**\n * @dev Collection of functions related to the address type\n */\nlibrary AddressUpgradeable {\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 functionCall(target, data, \"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        require(isContract(target), \"Address: call to non-contract\");\n\n        (bool success, bytes memory returndata) = target.call{value: value}(data);\n        return verifyCallResult(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        require(isContract(target), \"Address: static call to non-contract\");\n\n        (bool success, bytes memory returndata) = target.staticcall(data);\n        return verifyCallResult(success, returndata, errorMessage);\n    }\n\n    /**\n     * @dev Tool to verifies that a low level call was successful, and revert if it wasn't, either by bubbling the\n     * revert reason 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            // 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}\n"
    },
    "@openzeppelin/contracts-upgradeable/interfaces/draft-IERC1822Upgradeable.sol": {
      "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.5.0) (interfaces/draft-IERC1822.sol)\n\npragma solidity ^0.8.0;\n\n/**\n * @dev ERC1822: Universal Upgradeable Proxy Standard (UUPS) documents a method for upgradeability through a simplified\n * proxy whose upgrades are fully controlled by the current implementation.\n */\ninterface IERC1822ProxiableUpgradeable {\n    /**\n     * @dev Returns the storage slot that the proxiable contract assumes is being used to store the implementation\n     * address.\n     *\n     * IMPORTANT: A proxy pointing at a proxiable contract should not be considered proxiable itself, because this risks\n     * bricking a proxy that upgrades to it, by delegating to itself until out of gas. Thus it is critical that this\n     * function revert if invoked through a proxy.\n     */\n    function proxiableUUID() external view returns (bytes32);\n}\n"
    },
    "@openzeppelin/contracts-upgradeable/proxy/ERC1967/ERC1967UpgradeUpgradeable.sol": {
      "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.5.0) (proxy/ERC1967/ERC1967Upgrade.sol)\n\npragma solidity ^0.8.2;\n\nimport \"../beacon/IBeaconUpgradeable.sol\";\nimport \"../../interfaces/draft-IERC1822Upgradeable.sol\";\nimport \"../../utils/AddressUpgradeable.sol\";\nimport \"../../utils/StorageSlotUpgradeable.sol\";\nimport \"../utils/Initializable.sol\";\n\n/**\n * @dev This abstract contract provides getters and event emitting update functions for\n * https://eips.ethereum.org/EIPS/eip-1967[EIP1967] slots.\n *\n * _Available since v4.1._\n *\n * @custom:oz-upgrades-unsafe-allow delegatecall\n */\nabstract contract ERC1967UpgradeUpgradeable is Initializable {\n    function __ERC1967Upgrade_init() internal onlyInitializing {\n    }\n\n    function __ERC1967Upgrade_init_unchained() internal onlyInitializing {\n    }\n    // This is the keccak-256 hash of \"eip1967.proxy.rollback\" subtracted by 1\n    bytes32 private constant _ROLLBACK_SLOT = 0x4910fdfa16fed3260ed0e7147f7cc6da11a60208b5b9406d12a635614ffd9143;\n\n    /**\n     * @dev Storage slot with the address of the current implementation.\n     * This is the keccak-256 hash of \"eip1967.proxy.implementation\" subtracted by 1, and is\n     * validated in the constructor.\n     */\n    bytes32 internal constant _IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc;\n\n    /**\n     * @dev Emitted when the implementation is upgraded.\n     */\n    event Upgraded(address indexed implementation);\n\n    /**\n     * @dev Returns the current implementation address.\n     */\n    function _getImplementation() internal view returns (address) {\n        return StorageSlotUpgradeable.getAddressSlot(_IMPLEMENTATION_SLOT).value;\n    }\n\n    /**\n     * @dev Stores a new address in the EIP1967 implementation slot.\n     */\n    function _setImplementation(address newImplementation) private {\n        require(AddressUpgradeable.isContract(newImplementation), \"ERC1967: new implementation is not a contract\");\n        StorageSlotUpgradeable.getAddressSlot(_IMPLEMENTATION_SLOT).value = newImplementation;\n    }\n\n    /**\n     * @dev Perform implementation upgrade\n     *\n     * Emits an {Upgraded} event.\n     */\n    function _upgradeTo(address newImplementation) internal {\n        _setImplementation(newImplementation);\n        emit Upgraded(newImplementation);\n    }\n\n    /**\n     * @dev Perform implementation upgrade with additional setup call.\n     *\n     * Emits an {Upgraded} event.\n     */\n    function _upgradeToAndCall(\n        address newImplementation,\n        bytes memory data,\n        bool forceCall\n    ) internal {\n        _upgradeTo(newImplementation);\n        if (data.length > 0 || forceCall) {\n            _functionDelegateCall(newImplementation, data);\n        }\n    }\n\n    /**\n     * @dev Perform implementation upgrade with security checks for UUPS proxies, and additional setup call.\n     *\n     * Emits an {Upgraded} event.\n     */\n    function _upgradeToAndCallUUPS(\n        address newImplementation,\n        bytes memory data,\n        bool forceCall\n    ) internal {\n        // Upgrades from old implementations will perform a rollback test. This test requires the new\n        // implementation to upgrade back to the old, non-ERC1822 compliant, implementation. Removing\n        // this special case will break upgrade paths from old UUPS implementation to new ones.\n        if (StorageSlotUpgradeable.getBooleanSlot(_ROLLBACK_SLOT).value) {\n            _setImplementation(newImplementation);\n        } else {\n            try IERC1822ProxiableUpgradeable(newImplementation).proxiableUUID() returns (bytes32 slot) {\n                require(slot == _IMPLEMENTATION_SLOT, \"ERC1967Upgrade: unsupported proxiableUUID\");\n            } catch {\n                revert(\"ERC1967Upgrade: new implementation is not UUPS\");\n            }\n            _upgradeToAndCall(newImplementation, data, forceCall);\n        }\n    }\n\n    /**\n     * @dev Storage slot with the admin of the contract.\n     * This is the keccak-256 hash of \"eip1967.proxy.admin\" subtracted by 1, and is\n     * validated in the constructor.\n     */\n    bytes32 internal constant _ADMIN_SLOT = 0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103;\n\n    /**\n     * @dev Emitted when the admin account has changed.\n     */\n    event AdminChanged(address previousAdmin, address newAdmin);\n\n    /**\n     * @dev Returns the current admin.\n     */\n    function _getAdmin() internal view returns (address) {\n        return StorageSlotUpgradeable.getAddressSlot(_ADMIN_SLOT).value;\n    }\n\n    /**\n     * @dev Stores a new address in the EIP1967 admin slot.\n     */\n    function _setAdmin(address newAdmin) private {\n        require(newAdmin != address(0), \"ERC1967: new admin is the zero address\");\n        StorageSlotUpgradeable.getAddressSlot(_ADMIN_SLOT).value = newAdmin;\n    }\n\n    /**\n     * @dev Changes the admin of the proxy.\n     *\n     * Emits an {AdminChanged} event.\n     */\n    function _changeAdmin(address newAdmin) internal {\n        emit AdminChanged(_getAdmin(), newAdmin);\n        _setAdmin(newAdmin);\n    }\n\n    /**\n     * @dev The storage slot of the UpgradeableBeacon contract which defines the implementation for this proxy.\n     * This is bytes32(uint256(keccak256('eip1967.proxy.beacon')) - 1)) and is validated in the constructor.\n     */\n    bytes32 internal constant _BEACON_SLOT = 0xa3f0ad74e5423aebfd80d3ef4346578335a9a72aeaee59ff6cb3582b35133d50;\n\n    /**\n     * @dev Emitted when the beacon is upgraded.\n     */\n    event BeaconUpgraded(address indexed beacon);\n\n    /**\n     * @dev Returns the current beacon.\n     */\n    function _getBeacon() internal view returns (address) {\n        return StorageSlotUpgradeable.getAddressSlot(_BEACON_SLOT).value;\n    }\n\n    /**\n     * @dev Stores a new beacon in the EIP1967 beacon slot.\n     */\n    function _setBeacon(address newBeacon) private {\n        require(AddressUpgradeable.isContract(newBeacon), \"ERC1967: new beacon is not a contract\");\n        require(\n            AddressUpgradeable.isContract(IBeaconUpgradeable(newBeacon).implementation()),\n            \"ERC1967: beacon implementation is not a contract\"\n        );\n        StorageSlotUpgradeable.getAddressSlot(_BEACON_SLOT).value = newBeacon;\n    }\n\n    /**\n     * @dev Perform beacon upgrade with additional setup call. Note: This upgrades the address of the beacon, it does\n     * not upgrade the implementation contained in the beacon (see {UpgradeableBeacon-_setImplementation} for that).\n     *\n     * Emits a {BeaconUpgraded} event.\n     */\n    function _upgradeBeaconToAndCall(\n        address newBeacon,\n        bytes memory data,\n        bool forceCall\n    ) internal {\n        _setBeacon(newBeacon);\n        emit BeaconUpgraded(newBeacon);\n        if (data.length > 0 || forceCall) {\n            _functionDelegateCall(IBeaconUpgradeable(newBeacon).implementation(), data);\n        }\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(address target, bytes memory data) private returns (bytes memory) {\n        require(AddressUpgradeable.isContract(target), \"Address: delegate call to non-contract\");\n\n        // solhint-disable-next-line avoid-low-level-calls\n        (bool success, bytes memory returndata) = target.delegatecall(data);\n        return AddressUpgradeable.verifyCallResult(success, returndata, \"Address: low-level delegate call failed\");\n    }\n\n    /**\n     * @dev This empty reserved space is put in place to allow future versions to add new\n     * variables without shifting down storage in the inheritance chain.\n     * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps\n     */\n    uint256[50] private __gap;\n}\n"
    },
    "@openzeppelin/contracts-upgradeable/proxy/beacon/IBeaconUpgradeable.sol": {
      "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts v4.4.1 (proxy/beacon/IBeacon.sol)\n\npragma solidity ^0.8.0;\n\n/**\n * @dev This is the interface that {BeaconProxy} expects of its beacon.\n */\ninterface IBeaconUpgradeable {\n    /**\n     * @dev Must return an address that can be used as a delegate call target.\n     *\n     * {BeaconProxy} will check that this address is a contract.\n     */\n    function implementation() external view returns (address);\n}\n"
    },
    "@openzeppelin/contracts-upgradeable/utils/StorageSlotUpgradeable.sol": {
      "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.7.0) (utils/StorageSlot.sol)\n\npragma solidity ^0.8.0;\n\n/**\n * @dev Library for reading and writing primitive types to specific storage slots.\n *\n * Storage slots are often used to avoid storage conflict when dealing with upgradeable contracts.\n * This library helps with reading and writing to such slots without the need for inline assembly.\n *\n * The functions in this library return Slot structs that contain a `value` member that can be used to read or write.\n *\n * Example usage to set ERC1967 implementation slot:\n * ```\n * contract ERC1967 {\n *     bytes32 internal constant _IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc;\n *\n *     function _getImplementation() internal view returns (address) {\n *         return StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value;\n *     }\n *\n *     function _setImplementation(address newImplementation) internal {\n *         require(Address.isContract(newImplementation), \"ERC1967: new implementation is not a contract\");\n *         StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value = newImplementation;\n *     }\n * }\n * ```\n *\n * _Available since v4.1 for `address`, `bool`, `bytes32`, and `uint256`._\n */\nlibrary StorageSlotUpgradeable {\n    struct AddressSlot {\n        address value;\n    }\n\n    struct BooleanSlot {\n        bool value;\n    }\n\n    struct Bytes32Slot {\n        bytes32 value;\n    }\n\n    struct Uint256Slot {\n        uint256 value;\n    }\n\n    /**\n     * @dev Returns an `AddressSlot` with member `value` located at `slot`.\n     */\n    function getAddressSlot(bytes32 slot) internal pure returns (AddressSlot storage r) {\n        /// @solidity memory-safe-assembly\n        assembly {\n            r.slot := slot\n        }\n    }\n\n    /**\n     * @dev Returns an `BooleanSlot` with member `value` located at `slot`.\n     */\n    function getBooleanSlot(bytes32 slot) internal pure returns (BooleanSlot storage r) {\n        /// @solidity memory-safe-assembly\n        assembly {\n            r.slot := slot\n        }\n    }\n\n    /**\n     * @dev Returns an `Bytes32Slot` with member `value` located at `slot`.\n     */\n    function getBytes32Slot(bytes32 slot) internal pure returns (Bytes32Slot storage r) {\n        /// @solidity memory-safe-assembly\n        assembly {\n            r.slot := slot\n        }\n    }\n\n    /**\n     * @dev Returns an `Uint256Slot` with member `value` located at `slot`.\n     */\n    function getUint256Slot(bytes32 slot) internal pure returns (Uint256Slot storage r) {\n        /// @solidity memory-safe-assembly\n        assembly {\n            r.slot := slot\n        }\n    }\n}\n"
    }
  },
  "settings": {
    "optimizer": {
      "enabled": true,
      "runs": 200
    },
    "outputSelection": {
      "*": {
        "*": [
          "evm.bytecode",
          "evm.deployedBytecode",
          "devdoc",
          "userdoc",
          "metadata",
          "abi"
        ]
      }
    },
    "libraries": {}
  }
}