{"file_path":"contracts/p1/RToken.sol","creation_status":"success","source_code":"// SPDX-License-Identifier: BlueOak-1.0.0\npragma solidity 0.8.28;\n\n// solhint-disable-next-line max-line-length\nimport \"@openzeppelin/contracts-upgradeable/token/ERC20/utils/SafeERC20Upgradeable.sol\";\nimport \"../interfaces/IMain.sol\";\nimport \"../interfaces/IRToken.sol\";\nimport \"../libraries/Fixed.sol\";\nimport \"../libraries/Throttle.sol\";\nimport \"../vendor/ERC20PermitUpgradeable.sol\";\nimport \"./mixins/Component.sol\";\n\n/**\n * @title RTokenP1\n * An ERC20 with an elastic supply and governable exchange rate to basket units.\n */\ncontract RTokenP1 is ComponentP1, ERC20PermitUpgradeable, IRToken {\n    using FixLib for uint192;\n    using ThrottleLib for ThrottleLib.Throttle;\n    using SafeERC20Upgradeable for IERC20Upgradeable;\n\n    uint256 public constant MIN_THROTTLE_RATE_AMT = 1e18; // {qRTok}\n    uint256 public constant MAX_THROTTLE_RATE_AMT = 1e48; // {qRTok}\n    uint192 public constant MAX_THROTTLE_PCT_AMT = 1e18; // {qRTok}\n    uint192 public constant MIN_EXCHANGE_RATE = 1e9; // D18{BU/rTok}\n    uint192 public constant MAX_EXCHANGE_RATE = 1e27; // D18{BU/rTok}\n    uint192 public constant MIN_THROTTLE_DELTA = 25e16; // {1} 25%\n\n    /// The mandate describes what goals its governors should try to achieve. By succinctly\n    /// explaining the RToken's purpose and what the RToken is intended to do, it provides common\n    /// ground for the governors to decide upon priorities and how to weigh tradeoffs.\n    ///\n    /// Example Mandates:\n    ///\n    /// - Capital preservation first. Spending power preservation second. Permissionless\n    ///     access third.\n    /// - Capital preservation above all else. All revenues fund the over-collateralization pool.\n    /// - Risk-neutral pursuit of profit for token holders.\n    ///     Maximize (gross revenue - payments for over-collateralization and governance).\n    /// - This RToken holds only FooCoin, to provide a trade for hedging against its\n    ///     possible collapse.\n    ///\n    /// The mandate may also be a URI to a longer body of text, presumably on IPFS or some other\n    /// immutable data store.\n    string public mandate;\n\n    // ==== Peer components ====\n    IAssetRegistry private assetRegistry;\n    IBasketHandler private basketHandler;\n    IBackingManager private backingManager;\n    IFurnace private furnace;\n\n    // The number of baskets that backingManager must hold\n    // in order for this RToken to be fully collateralized.\n    // The exchange rate for issuance and redemption is totalSupply()/basketsNeeded {BU}/{qRTok}.\n    uint192 public basketsNeeded; // D18{BU}\n\n    // === Supply throttles ===\n    ThrottleLib.Throttle private issuanceThrottle;\n    ThrottleLib.Throttle private redemptionThrottle;\n\n    function init(\n        IMain main_,\n        string calldata name_,\n        string calldata symbol_,\n        string calldata mandate_,\n        ThrottleLib.Params calldata issuanceThrottleParams_,\n        ThrottleLib.Params calldata redemptionThrottleParams_\n    ) external initializer {\n        require(bytes(name_).length != 0, \"name empty\");\n        require(bytes(symbol_).length != 0, \"symbol empty\");\n        __Component_init(main_);\n        __ERC20_init(name_, symbol_);\n        __ERC20Permit_init(name_);\n\n        assetRegistry = main_.assetRegistry();\n        basketHandler = main_.basketHandler();\n        backingManager = main_.backingManager();\n        furnace = main_.furnace();\n\n        setMandate(mandate_);\n        setThrottleParams(issuanceThrottleParams_, redemptionThrottleParams_);\n\n        issuanceThrottle.lastTimestamp = uint48(block.timestamp);\n        redemptionThrottle.lastTimestamp = uint48(block.timestamp);\n    }\n\n    /// Issue an RToken on the current basket\n    /// Do no use inifite approvals.  Instead, use BasketHandler.quote() to determine the amount\n    ///     of backing tokens to approve.\n    /// @param amount {qTok} The quantity of RToken to issue\n    /// @custom:interaction nearly CEI, but see comments around handling of refunds\n    function issue(uint256 amount) public {\n        issueTo(_msgSender(), amount);\n    }\n\n    /// Issue an RToken on the current basket, to a particular recipient\n    /// Do no use inifite approvals.  Instead, use BasketHandler.quote() to determine the amount\n    ///     of backing tokens to approve.\n    /// @param recipient The address to receive the issued RTokens\n    /// @param amount {qRTok} The quantity of RToken to issue\n    /// @custom:interaction RCEI\n    // BU exchange rate cannot decrease, and it can only increase when < FIX_ONE.\n    function issueTo(address recipient, uint256 amount)\n        public\n        notIssuancePausedOrFrozen\n        globalNonReentrant\n    {\n        require(amount != 0, \"Cannot issue zero\");\n\n        // == Refresh ==\n\n        assetRegistry.refresh();\n\n        // == Checks-effects block ==\n\n        address issuer = _msgSender(); // OK to save: it can't be changed in reentrant runs\n\n        // Ensure basket is ready, SOUND and not in warmup period\n        require(basketHandler.isReady(), \"basket not ready\");\n        uint256 supply = totalSupply();\n\n        // Revert if issuance exceeds either supply throttle\n        issuanceThrottle.useAvailable(supply, int256(amount)); // reverts on over-issuance\n        redemptionThrottle.useAvailable(supply, -int256(amount)); // shouldn't revert\n\n        // AT THIS POINT:\n        //   all contract invariants hold\n        //   furnace melting is up-to-date\n        //   asset states are up-to-date\n        //   throttle is up-to-date\n\n        // amtBaskets: the BU change to be recorded by this issuance\n        // D18{BU} = D18{BU} * {qRTok} / {qRTok}\n        // revert-on-overflow provided by FixLib functions\n        uint192 amtBaskets = supply != 0\n            ? basketsNeeded.muluDivu(amount, supply, CEIL)\n            : _safeWrap(amount);\n        emit Issuance(issuer, recipient, amount, amtBaskets);\n\n        // Get quote from BasketHandler including issuance premium\n        (address[] memory erc20s, uint256[] memory deposits) = basketHandler.quote(\n            amtBaskets,\n            true,\n            CEIL\n        );\n\n        // == Interactions: Create RToken + transfer tokens to BackingManager ==\n        _scaleUp(recipient, amtBaskets, supply);\n\n        for (uint256 i = 0; i < erc20s.length; ++i) {\n            IERC20Upgradeable(erc20s[i]).safeTransferFrom(\n                issuer,\n                address(backingManager),\n                deposits[i]\n            );\n        }\n    }\n\n    /// Redeem RToken for basket collateral\n    /// @param amount {qTok} The quantity {qRToken} of RToken to redeem\n    /// @custom:interaction CEI\n    function redeem(uint256 amount) external {\n        redeemTo(_msgSender(), amount);\n    }\n\n    /// Redeem RToken for basket collateral to a particular recipient\n    // checks:\n    //   amount > 0\n    //   amount <= balanceOf(caller)\n    //\n    // effects:\n    //   (so totalSupply -= amount and balanceOf(caller) -= amount)\n    //   basketsNeeded' / totalSupply' >== basketsNeeded / totalSupply\n    //   burn(caller, amount)\n    //\n    // actions:\n    //   let erc20s = basketHandler.erc20s()\n    //   for each token in erc20s:\n    //     let tokenAmt = (amount * basketsNeeded / totalSupply) current baskets\n    //     do token.transferFrom(backingManager, caller, tokenAmt)\n    // BU exchange rate cannot decrease, and it can only increase when < FIX_ONE.\n    /// @param recipient The address to receive the backing collateral tokens\n    /// @param amount {qRTok} The quantity {qRToken} of RToken to redeem\n    /// @custom:interaction RCEI\n    function redeemTo(address recipient, uint256 amount) public notFrozen globalNonReentrant {\n        // == Refresh ==\n        assetRegistry.refresh();\n\n        // == Checks and Effects ==\n\n        address caller = _msgSender();\n\n        require(amount != 0, \"Cannot redeem zero\");\n        require(recipient != address(0), \"cannot redeem to zero address\");\n        require(amount <= balanceOf(caller), \"insufficient balance\");\n        require(basketHandler.fullyCollateralized(), \"partial redemption; use redeemCustom\");\n        // redemption while IFFY/DISABLED allowed\n\n        uint256 supply = totalSupply();\n\n        // Revert if redemption exceeds either supply throttle\n        issuanceThrottle.useAvailable(supply, -int256(amount));\n        redemptionThrottle.useAvailable(supply, int256(amount)); // reverts on over-redemption\n\n        // {BU}\n        uint192 baskets = _scaleDown(caller, amount);\n        emit Redemption(caller, recipient, amount, baskets);\n\n        (address[] memory erc20s, uint256[] memory amounts) = basketHandler.quote(\n            baskets,\n            false,\n            FLOOR\n        );\n\n        // === Interactions ===\n\n        for (uint256 i = 0; i < erc20s.length; ++i) {\n            if (amounts[i] == 0) continue;\n\n            // Send withdrawal\n            // slither-disable-next-line arbitrary-send-erc20\n            IERC20Upgradeable(erc20s[i]).safeTransferFrom(\n                address(backingManager),\n                recipient,\n                amounts[i]\n            );\n        }\n    }\n\n    /// Redeem RToken for a linear combination of historical baskets, to a particular recipient\n    // checks:\n    //   amount > 0\n    //   amount <= balanceOf(caller)\n    //   sum(portions) == FIX_ONE\n    //   nonce >= basketHandler.primeNonce() for nonce in basketNonces\n    //\n    // effects:\n    //   (so totalSupply -= amount and balanceOf(caller) -= amount)\n    //   basketsNeeded' / totalSupply' >== basketsNeeded / totalSupply\n    //   burn(caller, amount)\n    //\n    // actions:\n    //   for each token in erc20s:\n    //     let tokenAmt = (amount * basketsNeeded / totalSupply) custom baskets\n    //     let prorataAmt = (amount / totalSupply) * token.balanceOf(backingManager)\n    //     do token.transferFrom(backingManager, caller, min(tokenAmt, prorataAmt))\n    // BU exchange rate cannot decrease, and it can only increase when < FIX_ONE.\n    /// @dev Allows partial redemptions up to the minAmounts\n    /// @param recipient The address to receive the backing collateral tokens\n    /// @param amount {qRTok} The quantity {qRToken} of RToken to redeem\n    /// @param basketNonces An array of basket nonces to do redemption from\n    /// @param portions {1} An array of Fix quantities that must add up to FIX_ONE\n    /// @param expectedERC20sOut An array of ERC20s expected out\n    /// @param minAmounts {qTok} The minimum ERC20 quantities the caller should receive\n    /// @custom:interaction RCEI\n    function redeemCustom(\n        address recipient,\n        uint256 amount,\n        uint48[] memory basketNonces,\n        uint192[] memory portions,\n        address[] memory expectedERC20sOut,\n        uint256[] memory minAmounts\n    ) external notFrozen globalNonReentrant {\n        // == Refresh ==\n        assetRegistry.refresh();\n\n        // == Checks and Effects ==\n\n        require(amount != 0, \"Cannot redeem zero\");\n        require(amount <= balanceOf(_msgSender()), \"insufficient balance\");\n        uint256 portionsSum;\n        for (uint256 i = 0; i < portions.length; ++i) {\n            portionsSum += portions[i];\n        }\n        require(portionsSum == FIX_ONE, \"portions do not add up to FIX_ONE\");\n\n        uint256 supply = totalSupply();\n\n        // Revert if redemption exceeds either supply throttle\n        issuanceThrottle.useAvailable(supply, -int256(amount));\n        redemptionThrottle.useAvailable(supply, int256(amount)); // reverts on over-redemption\n\n        // {BU}\n        uint192 baskets = _scaleDown(_msgSender(), amount);\n        emit Redemption(_msgSender(), recipient, amount, baskets);\n\n        // === Get basket redemption amounts ===\n\n        (address[] memory erc20s, uint256[] memory amounts) = basketHandler.quoteCustomRedemption(\n            basketNonces,\n            portions,\n            baskets\n        );\n\n        // ==== Prorate redemption ====\n        // i.e, set amounts = min(amounts, balances * amount / totalSupply)\n        //   where balances[i] = erc20s[i].balanceOf(backingManager)\n\n        // Bound each withdrawal by the prorata share, in case we're currently under-collateralized\n        for (uint256 i = 0; i < erc20s.length; ++i) {\n            // {qTok} = {qTok} * {qRTok} / {qRTok}\n            uint256 prorata = mulDiv256(\n                IERC20(erc20s[i]).balanceOf(address(backingManager)),\n                amount,\n                supply\n            ); // FLOOR\n\n            if (prorata < amounts[i]) amounts[i] = prorata;\n        }\n\n        // === Save initial recipient balances ===\n\n        uint256[] memory pastBals = new uint256[](expectedERC20sOut.length);\n        for (uint256 i = 0; i < expectedERC20sOut.length; ++i) {\n            pastBals[i] = IERC20(expectedERC20sOut[i]).balanceOf(recipient);\n            // we haven't verified this ERC20 is registered but this is always a staticcall\n        }\n\n        // === Interactions ===\n\n        // Distribute tokens; revert if empty redemption\n        {\n            bool allZero = true;\n            for (uint256 i = 0; i < erc20s.length; ++i) {\n                if (amounts[i] == 0) continue; // unregistered ERC20s will have 0 amount\n                if (allZero) allZero = false;\n\n                // Send withdrawal\n                // slither-disable-next-line arbitrary-send-erc20\n                IERC20Upgradeable(erc20s[i]).safeTransferFrom(\n                    address(backingManager),\n                    recipient,\n                    amounts[i]\n                );\n            }\n            if (allZero) revert(\"empty redemption\");\n        }\n\n        // === Post-checks ===\n\n        // Check post-balances\n        for (uint256 i = 0; i < expectedERC20sOut.length; ++i) {\n            uint256 bal = IERC20(expectedERC20sOut[i]).balanceOf(recipient);\n            // we haven't verified this ERC20 is registered but this is always a staticcall\n            require(bal - pastBals[i] >= minAmounts[i], \"redemption below minimum\");\n        }\n    }\n\n    /// Mint an amount of RToken equivalent to baskets BUs, scaling basketsNeeded up\n    /// Callable only by BackingManager\n    /// @param baskets {BU} The number of baskets to mint RToken for\n    /// @custom:protected\n    // checks: caller is backingManager\n    // effects:\n    //   bal'[recipient] = bal[recipient] + amtRToken\n    //   totalSupply' = totalSupply + amtRToken\n    //   basketsNeeded' = basketsNeeded + baskets\n    // BU exchange rate cannot decrease, and it can only increase when < FIX_ONE.\n    function mint(uint192 baskets) external {\n        require(_msgSender() == address(backingManager), \"not backing manager\");\n        uint256 supply = totalSupply();\n\n        // Accumulate the throttle before the supply change\n        issuanceThrottle.useAvailable(supply, 0);\n        redemptionThrottle.useAvailable(supply, 0);\n        _scaleUp(address(backingManager), baskets, supply);\n    }\n\n    /// Melt a quantity of RToken from the caller's account, increasing the basket rate\n    /// @param amtRToken {qRTok} The amtRToken to be melted\n    /// @custom:protected\n    // checks: caller is furnace\n    // effects:\n    //   bal'[caller] = bal[caller] - amtRToken\n    //   totalSupply' = totalSupply - amtRToken\n    // BU exchange rate cannot decrease\n    // BU exchange rate CAN increase, but we already trust furnace to do this slowly\n    function melt(uint256 amtRToken) external {\n        address caller = _msgSender();\n        require(caller == address(furnace), \"furnace only\");\n        _burn(caller, amtRToken);\n        emit Melted(amtRToken);\n        // do not update throttles: melting is frequent and always small\n    }\n\n    /// Burn an amount of RToken from caller's account and scale basketsNeeded down\n    /// Callable only by backingManager\n    /// @param amount {qRTok}\n    /// @custom:protected\n    // checks: caller is backingManager\n    // effects:\n    //   bal'[recipient] = bal[recipient] - amtRToken\n    //   totalSupply' = totalSupply - amtRToken\n    //   basketsNeeded' = basketsNeeded - baskets\n    // BU exchange rate cannot decrease, and it can only increase when < FIX_ONE.\n    function dissolve(uint256 amount) external {\n        address caller = _msgSender();\n        require(caller == address(backingManager), \"not backing manager\");\n        uint256 supply = totalSupply();\n\n        // Accumulate the throttle before the supply change\n        issuanceThrottle.useAvailable(supply, 0);\n        redemptionThrottle.useAvailable(supply, 0);\n        _scaleDown(caller, amount);\n    }\n\n    /// An affordance of last resort for Main in order to ensure re-capitalization\n    /// @custom:protected\n    // checks: caller is backingManager\n    // effects: basketsNeeded' = basketsNeeded_\n    function setBasketsNeeded(uint192 basketsNeeded_) external notTradingPausedOrFrozen {\n        require(_msgSender() == address(backingManager), \"not backing manager\");\n        emit BasketsNeededChanged(basketsNeeded, basketsNeeded_);\n        basketsNeeded = basketsNeeded_;\n\n        // == P0 exchangeRateIsValidAfter modifier ==\n        uint256 supply = totalSupply();\n        require(supply != 0, \"0 supply\");\n\n        // Note: These are D18s, even though they are uint256s. This is because\n        // we cannot assume we stay inside our valid range here, as that is what\n        // we are checking in the first place\n        uint256 low = (FIX_ONE_256 * basketsNeeded_) / supply; // D18{BU/rTok}\n        uint256 high = (FIX_ONE_256 * basketsNeeded_ + (supply - 1)) / supply; // D18{BU/rTok}\n\n        // here we take advantage of an implicit upcast from uint192 exchange rates\n        require(low >= MIN_EXCHANGE_RATE && high <= MAX_EXCHANGE_RATE, \"BU rate out of range\");\n    }\n\n    /// Sends all token balance of erc20 (if it is registered) to the BackingManager\n    /// @custom:interaction\n    function monetizeDonations(IERC20 erc20) external notTradingPausedOrFrozen globalNonReentrant {\n        require(assetRegistry.isRegistered(erc20), \"erc20 unregistered\");\n        IERC20Upgradeable(address(erc20)).safeTransfer(\n            address(backingManager),\n            erc20.balanceOf(address(this))\n        );\n    }\n\n    // ==== Throttle setters/getters ====\n\n    /// @return {qRTok} The maximum issuance that can be performed in the current block\n    function issuanceAvailable() external view returns (uint256) {\n        return issuanceThrottle.currentlyAvailable(issuanceThrottle.hourlyLimit(totalSupply()));\n    }\n\n    /// @return available {qRTok} The maximum redemption that can be performed in the current block\n    function redemptionAvailable() external view returns (uint256 available) {\n        uint256 supply = totalSupply();\n        available = redemptionThrottle.currentlyAvailable(redemptionThrottle.hourlyLimit(supply));\n        if (supply < available) available = supply;\n    }\n\n    /// @return The issuance throttle parametrization\n    function issuanceThrottleParams() external view returns (ThrottleLib.Params memory) {\n        return issuanceThrottle.params;\n    }\n\n    /// @return The redemption throttle parametrization\n    function redemptionThrottleParams() external view returns (ThrottleLib.Params memory) {\n        return redemptionThrottle.params;\n    }\n\n    /// @custom:governance\n    function setIssuanceThrottleParams(ThrottleLib.Params calldata params) public governance {\n        _setIssuanceThrottleParams(params);\n        require(\n            isRedemptionThrottleGreaterByDelta(params, redemptionThrottle.params),\n            \"redemption throttle too low\"\n        );\n    }\n\n    /// @custom:governance\n    function setRedemptionThrottleParams(ThrottleLib.Params calldata params) public governance {\n        _setRedemptionThrottleParams(params);\n        require(\n            isRedemptionThrottleGreaterByDelta(issuanceThrottle.params, params),\n            \"redemption throttle too low\"\n        );\n    }\n\n    /// @custom:governance\n    function setThrottleParams(\n        ThrottleLib.Params calldata issuanceParams,\n        ThrottleLib.Params calldata redemptionParams\n    ) public governance {\n        _setIssuanceThrottleParams(issuanceParams);\n        _setRedemptionThrottleParams(redemptionParams);\n        require(\n            isRedemptionThrottleGreaterByDelta(issuanceParams, redemptionParams),\n            \"redemption throttle too low\"\n        );\n    }\n\n    function setMandate(string calldata mandate_) public governance {\n        require(bytes(mandate_).length != 0, \"mandate empty\");\n        emit MandateSet(mandate, mandate_);\n        mandate = mandate_;\n    }\n\n    // === Private Helpers ===\n\n    function _setIssuanceThrottleParams(ThrottleLib.Params calldata params) private {\n        require(params.amtRate >= MIN_THROTTLE_RATE_AMT, \"issuance amtRate too small\");\n        require(params.amtRate <= MAX_THROTTLE_RATE_AMT, \"issuance amtRate too big\");\n        require(params.pctRate <= MAX_THROTTLE_PCT_AMT, \"issuance pctRate too big\");\n        issuanceThrottle.useAvailable(totalSupply(), 0);\n\n        emit IssuanceThrottleSet(issuanceThrottle.params, params);\n        issuanceThrottle.params = params;\n    }\n\n    /// @custom:governance\n    function _setRedemptionThrottleParams(ThrottleLib.Params calldata params) private {\n        require(params.amtRate >= MIN_THROTTLE_RATE_AMT, \"redemption amtRate too small\");\n        require(params.amtRate <= MAX_THROTTLE_RATE_AMT, \"redemption amtRate too big\");\n        require(params.pctRate <= MAX_THROTTLE_PCT_AMT, \"redemption pctRate too big\");\n        redemptionThrottle.useAvailable(totalSupply(), 0);\n\n        emit RedemptionThrottleSet(redemptionThrottle.params, params);\n        redemptionThrottle.params = params;\n    }\n\n    /// @notice Checks if the redemption throttle is greater than the issuance throttle by the\n    /// required delta\n    /// @dev Compares both amtRate and pctRate individually to ensure each meets the minimum\n    /// delta requirement\n    /// @param issuance The issuance throttle parameters to compare against\n    /// @param redemption The redemption throttle parameters to check\n    /// @return bool True if redemption throttle is greater by at least MIN_THROTTLE_DELTA,\n    /// false otherwise\n    function isRedemptionThrottleGreaterByDelta(\n        ThrottleLib.Params memory issuance,\n        ThrottleLib.Params memory redemption\n    ) private pure returns (bool) {\n        uint256 requiredAmtRate = issuance.amtRate +\n            ((issuance.amtRate * MIN_THROTTLE_DELTA) / FIX_ONE);\n        uint256 requiredPctRate = issuance.pctRate +\n            ((issuance.pctRate * MIN_THROTTLE_DELTA) / FIX_ONE);\n\n        return redemption.amtRate >= requiredAmtRate && redemption.pctRate >= requiredPctRate;\n    }\n\n    /// Mint an amount of RToken equivalent to amtBaskets and scale basketsNeeded up\n    /// @param recipient The address to receive the RTokens\n    /// @param amtBaskets {BU} The number of amtBaskets to mint RToken for\n    /// @param totalSupply {qRTok} The current totalSupply\n    // effects:\n    //   bal'[recipient] = bal[recipient] + amtRToken\n    //   totalSupply' = totalSupply + amtRToken\n    //   basketsNeeded' = basketsNeeded + amtBaskets\n    // BU exchange rate cannot decrease, and it can only increase when < FIX_ONE.\n    function _scaleUp(\n        address recipient,\n        uint192 amtBaskets,\n        uint256 totalSupply\n    ) private {\n        // take advantage of 18 decimals during casting\n        uint256 amtRToken = totalSupply != 0\n            ? amtBaskets.muluDivu(totalSupply, basketsNeeded) // {rTok} = {BU} * {qRTok} * {qRTok}\n            : amtBaskets; // {rTok}\n        emit BasketsNeededChanged(basketsNeeded, basketsNeeded + amtBaskets);\n        basketsNeeded += amtBaskets;\n\n        // Mint RToken to recipient\n        _mint(recipient, amtRToken);\n    }\n\n    /// Burn an amount of RToken and scale basketsNeeded down\n    /// @param account The address to dissolve RTokens from\n    /// @param amtRToken {qRTok} The amount of RToken to be dissolved\n    /// @return amtBaskets {BU} The equivalent number of baskets dissolved\n    // effects:\n    //   bal'[recipient] = bal[recipient] - amtRToken\n    //   totalSupply' = totalSupply - amtRToken\n    //   basketsNeeded' = basketsNeeded - amtBaskets\n    // BU exchange rate cannot decrease, and it can only increase when < FIX_ONE.\n    function _scaleDown(address account, uint256 amtRToken) private returns (uint192 amtBaskets) {\n        // D18{BU} = D18{BU} * {qRTok} / {qRTok}\n        amtBaskets = basketsNeeded.muluDivu(amtRToken, totalSupply()); // FLOOR\n        emit BasketsNeededChanged(basketsNeeded, basketsNeeded - amtBaskets);\n        basketsNeeded -= amtBaskets;\n\n        // Burn RToken from account; reverts if not enough balance\n        _burn(account, amtRToken);\n    }\n\n    /**\n     * @dev Hook that is called before any transfer of tokens. This includes\n     * minting and burning.\n     *\n     * Calling conditions:\n     *\n     * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens\n     * will be transferred to `to`.\n     * - when `from` is zero, `amount` tokens will be minted for `to`.\n     * - when `to` is zero, `amount` of ``from``'s tokens will be burned.\n     * - `from` and `to` are never both zero.\n     */\n    function _beforeTokenTransfer(\n        address,\n        address to,\n        uint256\n    ) internal virtual override {\n        require(to != address(this), \"RToken transfer to self\");\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     * RToken uses 56 slots, not 50.\n     */\n    uint256[42] private __gap;\n}\n","deployed_bytecode":"0x6080604052600436106102885760003560e01c806372b8b0511161015a578063aeb14bf6116100c1578063db006a751161007a578063db006a75146107f5578063dd62ed3e14610815578063ddc9587614610835578063dffeadd01461087a578063f17d835c146108b2578063f90b2bfe146108d257600080fd5b8063aeb14bf61461073d578063b32deb3d1461075d578063baa74f1f1461077d578063cc872b661461079d578063d505accf146107bd578063d6122e92146107dd57600080fd5b806395d89b411161011357806395d89b411461068e5780639926020b146106a35780639f200bba146106b8578063a16e1532146106d8578063a457c2d7146106fd578063a9059cbb1461071d57600080fd5b806372b8b0511461058c5780637ecebe00146105ac5780637f2d27b9146105cc57806384b0196e146105e15780638c83ed33146106095780638e31ab2e1461062957600080fd5b80633659cfe6116101fe57806354fd4d50116101b757806354fd4d50146104a75780635beafb3d146104d557806363965449146104f55780636b2ba67d1461051557806370a08231146105355780637121c2731461056b57600080fd5b80633659cfe61461040a578063395093511461042a57806339b1b96d1461044a5780634b35073f1461045f5780634f1ef2861461047f57806352d1902d1461049257600080fd5b806318160ddd1161025057806318160ddd1461036857806323282f6e1461037d57806323b872dd146103995780632f7605fb146103b9578063313ce567146103d95780633644e515146103f557600080fd5b806306fdde031461028d578063095ea7b3146102b85780630b0e54d0146102e85780631207f0c114610312578063180f913414610334575b600080fd5b34801561029957600080fd5b506102a26108f2565b6040516102af9190614eb9565b60405180910390f35b3480156102c457600080fd5b506102d86102d3366004614ef1565b610984565b60405190151581526020016102af565b3480156102f457600080fd5b50610304670de0b6b3a764000081565b6040519081526020016102af565b34801561031e57600080fd5b5061033261032d366004614ef1565b61099e565b005b34801561034057600080fd5b506103506703782dace9d9000081565b6040516001600160c01b0390911681526020016102af565b34801561037457600080fd5b5060cb54610304565b34801561038957600080fd5b50610350670de0b6b3a764000081565b3480156103a557600080fd5b506102d86103b4366004614f1d565b610e74565b3480156103c557600080fd5b506103326103d4366004614ef1565b610e98565b3480156103e557600080fd5b50604051601281526020016102af565b34801561040157600080fd5b5061030461136a565b34801561041657600080fd5b50610332610425366004614f5e565b611379565b34801561043657600080fd5b506102d8610445366004614ef1565b611458565b34801561045657600080fd5b506102a261147a565b34801561046b57600080fd5b506103506b033b2e3c9fd0803ce800000081565b61033261048d366004614fc1565b611509565b34801561049e57600080fd5b506103046115d9565b3480156104b357600080fd5b506040805180820190915260058152640342e322e360dc1b60208201526102a2565b3480156104e157600080fd5b506103326104f036600461507e565b61168c565b34801561050157600080fd5b506103326105103660046150af565b6117df565b34801561052157600080fd5b50610332610530366004615292565b611a46565b34801561054157600080fd5b50610304610550366004614f5e565b6001600160a01b0316600090815260c9602052604090205490565b34801561057757600080fd5b5061016654610350906001600160c01b031681565b34801561059857600080fd5b506103326105a736600461507e565b61226b565b3480156105b857600080fd5b506103046105c7366004614f5e565b612373565b3480156105d857600080fd5b50610304612392565b3480156105ed57600080fd5b506105f66123b5565b6040516102af9796959493929190615367565b34801561061557600080fd5b506103326106243660046153ff565b612453565b34801561063557600080fd5b506040805180820182526000808252602091820152815180830190925261016b54825261016c546001600160c01b0316908201525b60408051825181526020928301516001600160c01b031692810192909252016102af565b34801561069a57600080fd5b506102a26124e0565b3480156106af57600080fd5b506103046124ef565b3480156106c457600080fd5b506103326106d3366004615459565b612527565b3480156106e457600080fd5b506103046daf298d050e4395d69670b12b7f4160301b81565b34801561070957600080fd5b506102d8610718366004614ef1565b612691565b34801561072957600080fd5b506102d8610738366004614ef1565b61270c565b34801561074957600080fd5b506103326107583660046150af565b61271a565b34801561076957600080fd5b50610332610778366004614f5e565b61278f565b34801561078957600080fd5b5061033261079836600461549a565b612a57565b3480156107a957600080fd5b506103326107b83660046153ff565b612b9b565b3480156107c957600080fd5b506103326107d83660046154cf565b612ba5565b3480156107e957600080fd5b50610350633b9aca0081565b34801561080157600080fd5b506103326108103660046153ff565b612c9e565b34801561082157600080fd5b50610304610830366004615546565b612ca8565b34801561084157600080fd5b5060408051808201825260008082526020918201528151808301909252610167548252610168546001600160c01b03169082015261066a565b34801561088657600080fd5b5060975461089a906001600160a01b031681565b6040516001600160a01b0390911681526020016102af565b3480156108be57600080fd5b506103326108cd36600461557f565b612cd3565b3480156108de57600080fd5b506103326108ed3660046153ff565b61317a565b606060cc805461090190615658565b80601f016020809104026020016040519081016040528092919081815260200182805461092d90615658565b801561097a5780601f1061094f5761010080835404028352916020019161097a565b820191906000526020600020905b81548152906001019060200180831161095d57829003601f168201915b5050505050905090565b6000336109928185856131da565b60019150505b92915050565b609760009054906101000a90046001600160a01b03166001600160a01b03166375a8f9266040518163ffffffff1660e01b8152600401602060405180830381865afa1580156109f1573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610a15919061568c565b15610a675760405162461bcd60e51b815260206004820152601960248201527f66726f7a656e206f722069737375616e6365207061757365640000000000000060448201526064015b60405180910390fd5b609760009054906101000a90046001600160a01b03166001600160a01b03166314f4ded26040518163ffffffff1660e01b8152600401600060405180830381600087803b158015610ab757600080fd5b505af1158015610acb573d6000803e3d6000fd5b5050505080600003610b135760405162461bcd60e51b815260206004820152601160248201527043616e6e6f74206973737565207a65726f60781b6044820152606401610a5e565b61016260009054906101000a90046001600160a01b03166001600160a01b031663f8ac93e86040518163ffffffff1660e01b8152600401600060405180830381600087803b158015610b6457600080fd5b505af1158015610b78573d6000803e3d6000fd5b505050506000610b853390565b905061016360009054906101000a90046001600160a01b03166001600160a01b031663a094a0316040518163ffffffff1660e01b8152600401602060405180830381865afa158015610bdb573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610bff919061568c565b610c3e5760405162461bcd60e51b815260206004820152601060248201526f6261736b6574206e6f7420726561647960801b6044820152606401610a5e565b6000610c4960cb5490565b9050610c5861016782856132fe565b610c6f81610c65856156c4565b61016b91906132fe565b600081600003610c8757610c8284613408565b610ca1565b61016654610ca1906001600160c01b031685846002613432565b9050846001600160a01b0316836001600160a01b03167f93a73b97592126fd663d485c98f8a174c1d701035545e71ac88a05b71d6ad4ef8684604051610cfa9291909182526001600160c01b0316602082015260400190565b60405180910390a361016354604051631c89e88d60e11b815260009182916001600160a01b0390911690633913d11a90610d3e9086906001906002906004016156f6565b600060405180830381865afa158015610d5b573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f19168201604052610d839190810190615798565b91509150610d9287848661345c565b60005b8251811015610e0e57610e068661016460009054906101000a90046001600160a01b0316848481518110610dcb57610dcb615863565b6020026020010151868581518110610de557610de5615863565b60200260200101516001600160a01b0316613536909392919063ffffffff16565b600101610d95565b5050609754604080516331cfec0560e01b815290516001600160a01b0390921695506331cfec05945060048082019450600093509082900301818387803b158015610e5857600080fd5b505af1158015610e6c573d6000803e3d6000fd5b505050505050565b600033610e828582856135a1565b610e8d858585613615565b506001949350505050565b609760009054906101000a90046001600160a01b03166001600160a01b031663054f7d9c6040518163ffffffff1660e01b8152600401602060405180830381865afa158015610eeb573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610f0f919061568c565b15610f455760405162461bcd60e51b8152602060048201526006602482015265333937bd32b760d11b6044820152606401610a5e565b609760009054906101000a90046001600160a01b03166001600160a01b03166314f4ded26040518163ffffffff1660e01b8152600401600060405180830381600087803b158015610f9557600080fd5b505af1158015610fa9573d6000803e3d6000fd5b5050505061016260009054906101000a90046001600160a01b03166001600160a01b031663f8ac93e86040518163ffffffff1660e01b8152600401600060405180830381600087803b158015610ffe57600080fd5b505af1158015611012573d6000803e3d6000fd5b50505050600061101f3390565b9050816000036110665760405162461bcd60e51b815260206004820152601260248201527143616e6e6f742072656465656d207a65726f60701b6044820152606401610a5e565b6001600160a01b0383166110bc5760405162461bcd60e51b815260206004820152601d60248201527f63616e6e6f742072656465656d20746f207a65726f20616464726573730000006044820152606401610a5e565b6001600160a01b038116600090815260c9602052604090205482111561111b5760405162461bcd60e51b8152602060048201526014602482015273696e73756666696369656e742062616c616e636560601b6044820152606401610a5e565b61016360009054906101000a90046001600160a01b03166001600160a01b031663e45a5b2d6040518163ffffffff1660e01b8152600401602060405180830381865afa15801561116f573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611193919061568c565b6111eb5760405162461bcd60e51b8152602060048201526024808201527f7061727469616c20726564656d7074696f6e3b207573652072656465656d437560448201526373746f6d60e01b6064820152608401610a5e565b60006111f660cb5490565b905061120f81611205856156c4565b61016791906132fe565b61121c61016b82856132fe565b600061122883856137cb565b9050846001600160a01b0316836001600160a01b03167f49e15c2a707390f4ccf35ee268a61455f17aeb5b1983c01e1dd1f00b86a4725e86846040516112819291909182526001600160c01b0316602082015260400190565b60405180910390a361016354604051631c89e88d60e11b815260009182916001600160a01b0390911690633913d11a906112c3908690859081906004016156f6565b600060405180830381865afa1580156112e0573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f191682016040526113089190810190615798565b9150915060005b8251811015610e0e5781818151811061132a5761132a615863565b60200260200101516000031561136257610164548251611362916001600160a01b0316908a90859085908110610dcb57610dcb615863565b60010161130f565b600061137461389a565b905090565b6001600160a01b037f000000000000000000000000258ce833cf9ad19208372763a00aa1565dd40b3c1630036113c15760405162461bcd60e51b8152600401610a5e90615879565b7f000000000000000000000000258ce833cf9ad19208372763a00aa1565dd40b3c6001600160a01b031661140a600080516020615f6f833981519152546001600160a01b031690565b6001600160a01b0316146114305760405162461bcd60e51b8152600401610a5e906158c5565b611439816138a4565b60408051600080825260208201909252611455918391906138f3565b50565b60003361099281858561146b8383612ca8565b6114759190615911565b6131da565b610161805461148890615658565b80601f01602080910402602001604051908101604052809291908181526020018280546114b490615658565b80156115015780601f106114d657610100808354040283529160200191611501565b820191906000526020600020905b8154815290600101906020018083116114e457829003601f168201915b505050505081565b6001600160a01b037f000000000000000000000000258ce833cf9ad19208372763a00aa1565dd40b3c1630036115515760405162461bcd60e51b8152600401610a5e90615879565b7f000000000000000000000000258ce833cf9ad19208372763a00aa1565dd40b3c6001600160a01b031661159a600080516020615f6f833981519152546001600160a01b031690565b6001600160a01b0316146115c05760405162461bcd60e51b8152600401610a5e906158c5565b6115c9826138a4565b6115d5828260016138f3565b5050565b6000306001600160a01b037f000000000000000000000000258ce833cf9ad19208372763a00aa1565dd40b3c16146116795760405162461bcd60e51b815260206004820152603860248201527f555550535570677261646561626c653a206d757374206e6f742062652063616c60448201527f6c6564207468726f7567682064656c656761746563616c6c00000000000000006064820152608401610a5e565b50600080516020615f6f83398151915290565b60975460408051808201909152600581526427aba722a960d91b60208201526001600160a01b03909116906391d14854906116c690615924565b336040516001600160e01b031960e085901b16815260048101929092526001600160a01b03166024820152604401602060405180830381865afa158015611711573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611735919061568c565b6117515760405162461bcd60e51b8152600401610a5e90615948565b61175a81613a5e565b61179361176c36839003830183615971565b6040805180820190915261016b54815261016c546001600160c01b03166020820152613bea565b6114555760405162461bcd60e51b815260206004820152601b60248201527f726564656d7074696f6e207468726f74746c6520746f6f206c6f7700000000006044820152606401610a5e565b609760009054906101000a90046001600160a01b03166001600160a01b03166398f73e526040518163ffffffff1660e01b8152600401602060405180830381865afa158015611832573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611856919061568c565b1561189e5760405162461bcd60e51b8152602060048201526018602482015277199c9bde995b881bdc881d1c98591a5b99c81c185d5cd95960421b6044820152606401610a5e565b610164546001600160a01b0316336001600160a01b0316146118d25760405162461bcd60e51b8152600401610a5e906159c8565b61016654604080516001600160c01b03928316815291831660208301527f0b0ca69be72e0611a1f79eedf91aece404ff14cb8fcfd0c997a72b68d4fdd478910160405180910390a161016680546001600160c01b0319166001600160c01b03831617905560cb54806000036119745760405162461bcd60e51b81526020600482015260086024820152673020737570706c7960c01b6044820152606401610a5e565b6000816119926001600160c01b038516670de0b6b3a76400006159f5565b61199c9190615a22565b90506000826119ac600182615a36565b6119c76001600160c01b038716670de0b6b3a76400006159f5565b6119d19190615911565b6119db9190615a22565b9050633b9aca0082108015906119fd57506b033b2e3c9fd0803ce80000008111155b611a405760405162461bcd60e51b815260206004820152601460248201527342552072617465206f7574206f662072616e676560601b6044820152606401610a5e565b50505050565b609760009054906101000a90046001600160a01b03166001600160a01b031663054f7d9c6040518163ffffffff1660e01b8152600401602060405180830381865afa158015611a99573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611abd919061568c565b15611af35760405162461bcd60e51b8152602060048201526006602482015265333937bd32b760d11b6044820152606401610a5e565b609760009054906101000a90046001600160a01b03166001600160a01b03166314f4ded26040518163ffffffff1660e01b8152600401600060405180830381600087803b158015611b4357600080fd5b505af1158015611b57573d6000803e3d6000fd5b5050505061016260009054906101000a90046001600160a01b03166001600160a01b031663f8ac93e86040518163ffffffff1660e01b8152600401600060405180830381600087803b158015611bac57600080fd5b505af1158015611bc0573d6000803e3d6000fd5b5050505084600003611c095760405162461bcd60e51b815260206004820152601260248201527143616e6e6f742072656465656d207a65726f60701b6044820152606401610a5e565b611c1233610550565b851115611c585760405162461bcd60e51b8152602060048201526014602482015273696e73756666696369656e742062616c616e636560601b6044820152606401610a5e565b6000805b8451811015611c9d57848181518110611c7757611c77615863565b60200260200101516001600160c01b031682611c939190615911565b9150600101611c5c565b50670de0b6b3a76400008114611cff5760405162461bcd60e51b815260206004820152602160248201527f706f7274696f6e7320646f206e6f742061646420757020746f204649585f4f4e6044820152604560f81b6064820152608401610a5e565b6000611d0a60cb5490565b9050611d1981611205896156c4565b611d2661016b82896132fe565b6000611d3233896137cb565b604080518a81526001600160c01b03831660208201529192506001600160a01b038b169133917f49e15c2a707390f4ccf35ee268a61455f17aeb5b1983c01e1dd1f00b86a4725e910160405180910390a361016354604051630e3363af60e21b815260009182916001600160a01b03909116906338cd8ebc90611dbd908c908c908890600401615a49565b600060405180830381865afa158015611dda573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f19168201604052611e029190810190615798565b9150915060005b8251811015611ef5576000611ea9848381518110611e2957611e29615863565b6020908102919091010151610164546040516370a0823160e01b81526001600160a01b0391821660048201529116906370a0823190602401602060405180830381865afa158015611e7e573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611ea29190615ae9565b8d88613ca0565b9050828281518110611ebd57611ebd615863565b6020026020010151811015611eec5780838381518110611edf57611edf615863565b6020026020010181815250505b50600101611e09565b50600087516001600160401b03811115611f1157611f11614f7b565b604051908082528060200260200182016040528015611f3a578160200160208202803683370190505b50905060005b8851811015611ff657888181518110611f5b57611f5b615863565b60209081029190910101516040516370a0823160e01b81526001600160a01b038f81166004830152909116906370a0823190602401602060405180830381865afa158015611fad573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611fd19190615ae9565b828281518110611fe357611fe3615863565b6020908102919091010152600101611f40565b50600160005b84518110156120815783818151811061201757612017615863565b60200260200101516000031561207957811561203257600091505b61207961016460009054906101000a90046001600160a01b03168f86848151811061205f5761205f615863565b6020026020010151888581518110610de557610de5615863565b600101611ffc565b5080156120c35760405162461bcd60e51b815260206004820152601060248201526f32b6b83a3c903932b232b6b83a34b7b760811b6044820152606401610a5e565b5060005b88518110156121ff5760008982815181106120e4576120e4615863565b60200260200101516001600160a01b03166370a082318f6040518263ffffffff1660e01b815260040161212691906001600160a01b0391909116815260200190565b602060405180830381865afa158015612143573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906121679190615ae9565b905088828151811061217b5761217b615863565b602002602001015183838151811061219557612195615863565b6020026020010151826121a89190615a36565b10156121f65760405162461bcd60e51b815260206004820152601860248201527f726564656d7074696f6e2062656c6f77206d696e696d756d00000000000000006044820152606401610a5e565b506001016120c7565b5050609754604080516331cfec0560e01b815290516001600160a01b0390921696506331cfec059550600480820195506000945091925082900301818387803b15801561224b57600080fd5b505af115801561225f573d6000803e3d6000fd5b50505050505050505050565b60975460408051808201909152600581526427aba722a960d91b60208201526001600160a01b03909116906391d14854906122a590615924565b336040516001600160e01b031960e085901b16815260048101929092526001600160a01b03166024820152604401602060405180830381865afa1580156122f0573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612314919061568c565b6123305760405162461bcd60e51b8152600401610a5e90615948565b61233981613d83565b60408051808201909152610167548152610168546001600160c01b031660208201526117939061236e36849003840184615971565b613bea565b6001600160a01b038116600090815261012f6020526040812054610998565b60006113746123ac6123a360cb5490565b61016790613f0f565b61016790613f5a565b60006060806000806000606060fb546000801b1480156123d5575060fc54155b6124195760405162461bcd60e51b81526020600482015260156024820152741152540dcc4c8e88155b9a5b9a5d1a585b1a5e9959605a1b6044820152606401610a5e565b612421613fb8565b612429613fc7565b60408051600080825260208201909252600f60f81b9b939a50919850469750309650945092509050565b6101655433906001600160a01b0316811461249f5760405162461bcd60e51b815260206004820152600c60248201526b6675726e616365206f6e6c7960a01b6044820152606401610a5e565b6124a98183613fd6565b6040518281527f12b02b431a920654430b36652724950afbd1e5279648b404790dbd036b1a58a79060200160405180910390a15050565b606060cd805461090190615658565b6000806124fb60cb5490565b905061251561250c61016b83613f0f565b61016b90613f5a565b915081811015612523578091505b5090565b60975460408051808201909152600581526427aba722a960d91b60208201526001600160a01b03909116906391d148549061256190615924565b336040516001600160e01b031960e085901b16815260048101929092526001600160a01b03166024820152604401602060405180830381865afa1580156125ac573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906125d0919061568c565b6125ec5760405162461bcd60e51b8152600401610a5e90615948565b600081900361262d5760405162461bcd60e51b815260206004820152600d60248201526c6d616e6461746520656d70747960981b6044820152606401610a5e565b61016160405161263d9190615b02565b60405180910390207fbe9c7b8329f0e16f8d471d960d8b7b880afbac86134ea495ce1adc0ae7d53bcf8383604051612676929190615b77565b60405180910390a261016161268c828483615bed565b505050565b6000338161269f8286612ca8565b9050838110156126ff5760405162461bcd60e51b815260206004820152602560248201527f45524332303a2064656372656173656420616c6c6f77616e63652062656c6f77604482015264207a65726f60d81b6064820152608401610a5e565b610e8d82868684036131da565b600033610992818585613615565b610164546001600160a01b0316336001600160a01b03161461274e5760405162461bcd60e51b8152600401610a5e906159c8565b600061275960cb5490565b90506127696101678260006132fe565b61277761016b8260006132fe565b610164546115d5906001600160a01b0316838361345c565b609760009054906101000a90046001600160a01b03166001600160a01b03166398f73e526040518163ffffffff1660e01b8152600401602060405180830381865afa1580156127e2573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612806919061568c565b1561284e5760405162461bcd60e51b8152602060048201526018602482015277199c9bde995b881bdc881d1c98591a5b99c81c185d5cd95960421b6044820152606401610a5e565b609760009054906101000a90046001600160a01b03166001600160a01b03166314f4ded26040518163ffffffff1660e01b8152600401600060405180830381600087803b15801561289e57600080fd5b505af11580156128b2573d6000803e3d6000fd5b50506101625460405163c3c5a54760e01b81526001600160a01b038581166004830152909116925063c3c5a5479150602401602060405180830381865afa158015612901573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612925919061568c565b6129665760405162461bcd60e51b8152602060048201526012602482015271195c98cc8c081d5b9c9959da5cdd195c995960721b6044820152606401610a5e565b610164546040516370a0823160e01b81523060048201526129ec916001600160a01b0390811691908416906370a0823190602401602060405180830381865afa1580156129b7573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906129db9190615ae9565b6001600160a01b0384169190614116565b609760009054906101000a90046001600160a01b03166001600160a01b03166331cfec056040518163ffffffff1660e01b8152600401600060405180830381600087803b158015612a3c57600080fd5b505af1158015612a50573d6000803e3d6000fd5b5050505050565b60975460408051808201909152600581526427aba722a960d91b60208201526001600160a01b03909116906391d1485490612a9190615924565b336040516001600160e01b031960e085901b16815260048101929092526001600160a01b03166024820152604401602060405180830381865afa158015612adc573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612b00919061568c565b612b1c5760405162461bcd60e51b8152600401610a5e90615948565b612b2582613a5e565b612b2e81613d83565b612b4f612b4036849003840184615971565b61236e36849003840184615971565b6115d55760405162461bcd60e51b815260206004820152601b60248201527f726564656d7074696f6e207468726f74746c6520746f6f206c6f7700000000006044820152606401610a5e565b611455338261099e565b83421115612bf55760405162461bcd60e51b815260206004820152601d60248201527f45524332305065726d69743a206578706972656420646561646c696e650000006044820152606401610a5e565b60007f6e71edae12b1b97f4d1f60370fef10105fa2faae0126114a169c64845d6126c9888888612c248c614146565b6040805160208101969096526001600160a01b0394851690860152929091166060840152608083015260a082015260c0810186905260e001604051602081830303815290604052805190602001209050612c8988612c818361416f565b86868661419c565b612c948888886131da565b5050505050505050565b6114553382610e98565b6001600160a01b03918216600090815260ca6020908152604080832093909416825291909152205490565b600054610100900460ff1615808015612cf35750600054600160ff909116105b80612d0d5750303b158015612d0d575060005460ff166001145b612d705760405162461bcd60e51b815260206004820152602e60248201527f496e697469616c697a61626c653a20636f6e747261637420697320616c72656160448201526d191e481a5b9a5d1a585b1a5e995960921b6064820152608401610a5e565b6000805460ff191660011790558015612d93576000805461ff0019166101001790555b6000889003612dd15760405162461bcd60e51b815260206004820152600a6024820152696e616d6520656d70747960b01b6044820152606401610a5e565b6000869003612e115760405162461bcd60e51b815260206004820152600c60248201526b73796d626f6c20656d70747960a01b6044820152606401610a5e565b612e1a8a61433a565b612e8d89898080601f01602080910402602001604051908101604052809392919081815260200183838082843760009201919091525050604080516020601f8d018190048102820181019092528b815292508b91508a90819084018382808284376000920191909152506143d892505050565b612ecc89898080601f01602080910402602001604051908101604052809392919081815260200183838082843760009201919091525061440992505050565b896001600160a01b031663979d7e866040518163ffffffff1660e01b8152600401602060405180830381865afa158015612f0a573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612f2e9190615cac565b61016260006101000a8154816001600160a01b0302191690836001600160a01b03160217905550896001600160a01b0316632f2439b16040518163ffffffff1660e01b8152600401602060405180830381865afa158015612f93573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612fb79190615cac565b61016360006101000a8154816001600160a01b0302191690836001600160a01b03160217905550896001600160a01b031663dc8af5f66040518163ffffffff1660e01b8152600401602060405180830381865afa15801561301c573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906130409190615cac565b61016460006101000a8154816001600160a01b0302191690836001600160a01b03160217905550896001600160a01b031663656e96e16040518163ffffffff1660e01b8152600401602060405180830381865afa1580156130a5573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906130c99190615cac565b61016580546001600160a01b0319166001600160a01b03929092169190911790556130f48585612527565b6130fe8383612a57565b610169805465ffffffffffff421665ffffffffffff19918216811790925561016d80549091169091179055801561225f576000805461ff0019169055604051600181527f7f26b83ff96e1f2b6a682f133852f6798a09c465da95921460cefb38474024989060200160405180910390a150505050505050505050565b6101645433906001600160a01b031681146131a75760405162461bcd60e51b8152600401610a5e906159c8565b60006131b260cb5490565b90506131c26101678260006132fe565b6131d061016b8260006132fe565b611a4082846137cb565b6001600160a01b03831661323c5760405162461bcd60e51b8152602060048201526024808201527f45524332303a20617070726f76652066726f6d20746865207a65726f206164646044820152637265737360e01b6064820152608401610a5e565b6001600160a01b03821661329d5760405162461bcd60e51b815260206004820152602260248201527f45524332303a20617070726f766520746f20746865207a65726f206164647265604482015261737360f01b6064820152608401610a5e565b6001600160a01b03838116600081815260ca602090815260408083209487168084529482529182902085905590518481527f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925910160405180910390a3505050565b8254158015613318575060018301546001600160c01b0316155b1561332257505050565b600061332e8484613f0f565b9050600061333c8583613f5a565b905084600301548114158061335057508181145b156133715760028501805465ffffffffffff19164265ffffffffffff161790555b60008313156133db57808311156133ca5760405162461bcd60e51b815260206004820152601760248201527f737570706c79206368616e6765207468726f74746c65640000000000000000006044820152606401610a5e565b6133d48382615a36565b90506133fa565b60008312156133fa576133ed836156c4565b6133f79082615911565b90505b600390940193909355505050565b60006001600160c01b038211156125235760405163f44398f560e01b815260040160405180910390fd5b600061345161344c866001600160c01b0316868686614457565b613408565b90505b949350505050565b60008160000361346c5782613488565b61016654613488906001600160c01b0385811691859116614504565b610166546001600160c01b0391821692507f0b0ca69be72e0611a1f79eedf91aece404ff14cb8fcfd0c997a72b68d4fdd47891166134c68582615cc9565b604080516001600160c01b0393841681529290911660208301520160405180910390a161016680548491906000906135089084906001600160c01b0316615cc9565b92506101000a8154816001600160c01b0302191690836001600160c01b03160217905550611a408482614513565b6040516001600160a01b0380851660248301528316604482015260648101829052611a409085906323b872dd60e01b906084015b60408051601f198184030181529190526020810180516001600160e01b03166001600160e01b0319909316929092179091526145e0565b60006135ad8484612ca8565b90506000198114611a4057818110156136085760405162461bcd60e51b815260206004820152601d60248201527f45524332303a20696e73756666696369656e7420616c6c6f77616e63650000006044820152606401610a5e565b611a4084848484036131da565b6001600160a01b0383166136795760405162461bcd60e51b815260206004820152602560248201527f45524332303a207472616e736665722066726f6d20746865207a65726f206164604482015264647265737360d81b6064820152608401610a5e565b6001600160a01b0382166136db5760405162461bcd60e51b815260206004820152602360248201527f45524332303a207472616e7366657220746f20746865207a65726f206164647260448201526265737360e81b6064820152608401610a5e565b6136e68383836146b5565b6001600160a01b038316600090815260c960205260409020548181101561375e5760405162461bcd60e51b815260206004820152602660248201527f45524332303a207472616e7366657220616d6f756e7420657863656564732062604482015265616c616e636560d01b6064820152608401610a5e565b6001600160a01b03808516600081815260c9602052604080822086860390559286168082529083902080548601905591517fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef906137be9086815260200190565b60405180910390a3611a40565b60006137ee826137da60cb5490565b610166546001600160c01b03169190614504565b610166549091507f0b0ca69be72e0611a1f79eedf91aece404ff14cb8fcfd0c997a72b68d4fdd478906001600160c01b031661382a8382615ce8565b604080516001600160c01b0393841681529290911660208301520160405180910390a1610166805482919060009061386c9084906001600160c01b0316615ce8565b92506101000a8154816001600160c01b0302191690836001600160c01b031602179055506109988383613fd6565b600061137461470d565b6097546001600160a01b0316336001600160a01b0316146114555760405162461bcd60e51b81526020600482015260096024820152686d61696e206f6e6c7960b81b6044820152606401610a5e565b7f4910fdfa16fed3260ed0e7147f7cc6da11a60208b5b9406d12a635614ffd91435460ff16156139265761268c83614781565b826001600160a01b03166352d1902d6040518163ffffffff1660e01b8152600401602060405180830381865afa925050508015613980575060408051601f3d908101601f1916820190925261397d91810190615ae9565b60015b6139e35760405162461bcd60e51b815260206004820152602e60248201527f45524331393637557067726164653a206e657720696d706c656d656e7461746960448201526d6f6e206973206e6f74205555505360901b6064820152608401610a5e565b600080516020615f6f8339815191528114613a525760405162461bcd60e51b815260206004820152602960248201527f45524331393637557067726164653a20756e737570706f727465642070726f786044820152681a58589b195555525160ba1b6064820152608401610a5e565b5061268c83838361481d565b670de0b6b3a764000081351015613ab75760405162461bcd60e51b815260206004820152601a60248201527f69737375616e636520616d745261746520746f6f20736d616c6c0000000000006044820152606401610a5e565b6daf298d050e4395d69670b12b7f4160301b81351115613b195760405162461bcd60e51b815260206004820152601860248201527f69737375616e636520616d745261746520746f6f2062696700000000000000006044820152606401610a5e565b670de0b6b3a7640000613b3260408301602084016150af565b6001600160c01b03161115613b895760405162461bcd60e51b815260206004820152601860248201527f69737375616e6365207063745261746520746f6f2062696700000000000000006044820152606401610a5e565b613ba0613b9560cb5490565b6101679060006132fe565b6040517fa3e16a02f78ca4f5cf54ab43fd2cb34e5014ba4ec2e0cafb751203dcdd0aa82790613bd490610167908490615d07565b60405180910390a18061016761268c8282615d53565b81516000908190670de0b6b3a764000090613c0e906703782dace9d90000906159f5565b613c189190615a22565b8451613c249190615911565b90506000670de0b6b3a76400006001600160401b03166703782dace9d900008660200151613c529190615d88565b613c5c9190615db9565b8560200151613c6b9190615cc9565b6001600160c01b0316905081846000015110158015613c9757508084602001516001600160c01b031610155b95945050505050565b6000806000613caf8686614842565b91509150838210613cd35760405163f44398f560e01b815260040160405180910390fd5b60008480613ce357613ce3615a0c565b868809905081811115613cf7576001830392505b908190039060008590038516808681613d1257613d12615a0c565b049550808381613d2457613d24615a0c565b049250808160000381613d3957613d39615a0c565b046001019390930291909101600285810380870282030280870282030280870282030280870282030280870282030280870282030295860290039094029390930295945050505050565b670de0b6b3a764000081351015613ddc5760405162461bcd60e51b815260206004820152601c60248201527f726564656d7074696f6e20616d745261746520746f6f20736d616c6c000000006044820152606401610a5e565b6daf298d050e4395d69670b12b7f4160301b81351115613e3e5760405162461bcd60e51b815260206004820152601a60248201527f726564656d7074696f6e20616d745261746520746f6f206269670000000000006044820152606401610a5e565b670de0b6b3a7640000613e5760408301602084016150af565b6001600160c01b03161115613eae5760405162461bcd60e51b815260206004820152601a60248201527f726564656d7074696f6e207063745261746520746f6f206269670000000000006044820152606401610a5e565b613ec5613eba60cb5490565b61016b9060006132fe565b6040517fae0adad2741496b9b813ff6121945ff13626d9b550f6d2852530d28a79051ac290613ef99061016b908490615d07565b60405180910390a18061016b61268c8282615d53565b60018201546000908390670de0b6b3a764000090613f36906001600160c01b0316856159f5565b613f409190615a22565b91508181600001541115613f5357805491505b5092915050565b60028201546000908190613f769065ffffffffffff1642615de8565b9050610e10613f8d65ffffffffffff8316856159f5565b613f979190615a22565b8460030154613fa69190615911565b915082821115613f5357509092915050565b606060fd805461090190615658565b606060fe805461090190615658565b6001600160a01b0382166140365760405162461bcd60e51b815260206004820152602160248201527f45524332303a206275726e2066726f6d20746865207a65726f206164647265736044820152607360f81b6064820152608401610a5e565b614042826000836146b5565b6001600160a01b038216600090815260c96020526040902054818110156140b65760405162461bcd60e51b815260206004820152602260248201527f45524332303a206275726e20616d6f756e7420657863656564732062616c616e604482015261636560f01b6064820152608401610a5e565b6001600160a01b038316600081815260c960209081526040808320868603905560cb80548790039055518581529192917fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef910160405180910390a3505050565b6040516001600160a01b03831660248201526044810182905261268c90849063a9059cbb60e01b9060640161356a565b6001600160a01b038116600090815261012f602052604090208054600181018255905b50919050565b600061099861417c61389a565b8360405161190160f01b8152600281019290925260228201526042902090565b6001600160a01b0385163b156142aa57604080516020810184905280820183905260f885901b6001600160f81b0319166060820152815160418183030181526061820192839052630b135d3f60e11b9092526001600160a01b03871691631626ba7e9161420d918891606501615e06565b602060405180830381865afa15801561422a573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061424e9190615e1f565b6001600160e01b031916631626ba7e60e01b146142a55760405162461bcd60e51b8152602060048201526015602482015274115490cc4c8dcc4e88155b985d5d1a1bdc9a5e9959605a1b6044820152606401610a5e565b612a50565b60408051602081018490529081018290526001600160f81b031960f885901b1660608201526142ee908690869060610160405160208183030381529060405261486f565b612a505760405162461bcd60e51b815260206004820152601e60248201527f45524332305065726d69743a20696e76616c6964207369676e617475726500006044820152606401610a5e565b600054610100900460ff166143615760405162461bcd60e51b8152600401610a5e90615e49565b6001600160a01b0381166143ae5760405162461bcd60e51b81526020600482015260146024820152736d61696e206973207a65726f206164647265737360601b6044820152606401610a5e565b6143b66148d0565b609780546001600160a01b0319166001600160a01b0392909216919091179055565b600054610100900460ff166143ff5760405162461bcd60e51b8152600401610a5e90615e49565b6115d582826148f9565b600054610100900460ff166144305760405162461bcd60e51b8152600401610a5e90615e49565b61145581604051806040016040528060058152602001640342e322e360dc1b815250614939565b600080614465868686613ca0565b9050600083600281111561447b5761447b6156e0565b03614487579050613454565b6000848061449757614497615a0c565b868809905060028460028111156144b0576144b06156e0565b036144ce5780156144c9576144c6600183615911565b91505b6144fa565b60026144db600187615a36565b6144e59190615a22565b8111156144fa576144f7600183615911565b91505b5095945050505050565b60006134548484846000613432565b6001600160a01b0382166145695760405162461bcd60e51b815260206004820152601f60248201527f45524332303a206d696e7420746f20746865207a65726f2061646472657373006044820152606401610a5e565b614575600083836146b5565b8060cb60008282546145879190615911565b90915550506001600160a01b038216600081815260c960209081526040808320805486019055518481527fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef910160405180910390a35050565b6000614635826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b03166149889092919063ffffffff16565b9050805160001480614656575080806020019051810190614656919061568c565b61268c5760405162461bcd60e51b815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e6044820152691bdd081cdd58d8d9595960b21b6064820152608401610a5e565b306001600160a01b0383160361268c5760405162461bcd60e51b815260206004820152601760248201527f52546f6b656e207472616e7366657220746f2073656c660000000000000000006044820152606401610a5e565b60007f8b73c3c69bb8fe3d512ecc4cf759cc79239f7b179b0ffacaa9a75d522b39400f614738614997565b6147406149f0565b60408051602081019490945283019190915260608201524660808201523060a082015260c00160405160208183030381529060405280519060200120905090565b6001600160a01b0381163b6147ee5760405162461bcd60e51b815260206004820152602d60248201527f455243313936373a206e657720696d706c656d656e746174696f6e206973206e60448201526c1bdd08184818dbdb9d1c9858dd609a1b6064820152608401610a5e565b600080516020615f6f83398151915280546001600160a01b0319166001600160a01b0392909216919091179055565b61482683614a21565b6000825111806148335750805b1561268c57611a408383614a61565b6000808060001984860990508385029150818103925081811015614867576001830392505b509250929050565b600080600061487e8585614a8d565b90925090506000816004811115614897576148976156e0565b1480156148b55750856001600160a01b0316826001600160a01b0316145b806148c657506148c6868686614ad2565b9695505050505050565b600054610100900460ff166148f75760405162461bcd60e51b8152600401610a5e90615e49565b565b600054610100900460ff166149205760405162461bcd60e51b8152600401610a5e90615e49565b60cc61492c8382615e94565b5060cd61268c8282615e94565b600054610100900460ff166149605760405162461bcd60e51b8152600401610a5e90615e49565b60fd61496c8382615e94565b5060fe6149798282615e94565b5050600060fb81905560fc5550565b60606134548484600085614bbe565b6000806149a2613fb8565b8051909150156149b9578051602090910120919050565b60fb5480156149c85792915050565b7fc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a4709250505090565b6000806149fb613fc7565b805190915015614a12578051602090910120919050565b60fc5480156149c85792915050565b614a2a81614781565b6040516001600160a01b038216907fbc7cd75a20ee27fd9adebab32041f755214dbc6bffa90cc0225b39da2e5c2d3b90600090a250565b6060614a868383604051806060016040528060278152602001615f8f60279139614c99565b9392505050565b6000808251604103614ac35760208301516040840151606085015160001a614ab787828585614d07565b94509450505050614acb565b506000905060025b9250929050565b6000806000856001600160a01b0316631626ba7e60e01b8686604051602401614afc929190615e06565b60408051601f198184030181529181526020820180516001600160e01b03166001600160e01b0319909416939093179092529051614b3a9190615f52565b600060405180830381855afa9150503d8060008114614b75576040519150601f19603f3d011682016040523d82523d6000602084013e614b7a565b606091505b5091509150818015614b8e57506020815110155b80156148c657508051630b135d3f60e11b90614bb39083016020908101908401615ae9565b149695505050505050565b606082471015614c1f5760405162461bcd60e51b815260206004820152602660248201527f416464726573733a20696e73756666696369656e742062616c616e636520666f6044820152651c8818d85b1b60d21b6064820152608401610a5e565b600080866001600160a01b03168587604051614c3b9190615f52565b60006040518083038185875af1925050503d8060008114614c78576040519150601f19603f3d011682016040523d82523d6000602084013e614c7d565b606091505b5091509150614c8e87838387614dcb565b979650505050505050565b6060600080856001600160a01b031685604051614cb69190615f52565b600060405180830381855af49150503d8060008114614cf1576040519150601f19603f3d011682016040523d82523d6000602084013e614cf6565b606091505b50915091506148c686838387614dcb565b6000807f7fffffffffffffffffffffffffffffff5d576e7357a4501ddfe92f46681b20a0831115614d3e5750600090506003614dc2565b6040805160008082526020820180845289905260ff881692820192909252606081018690526080810185905260019060a0016020604051602081039080840390855afa158015614d92573d6000803e3d6000fd5b5050604051601f1901519150506001600160a01b038116614dbb57600060019250925050614dc2565b9150600090505b94509492505050565b60608315614e3a578251600003614e33576001600160a01b0385163b614e335760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e74726163740000006044820152606401610a5e565b5081613454565b6134548383815115614e4f5781518083602001fd5b8060405162461bcd60e51b8152600401610a5e9190614eb9565b60005b83811015614e84578181015183820152602001614e6c565b50506000910152565b60008151808452614ea5816020860160208601614e69565b601f01601f19169290920160200192915050565b602081526000614a866020830184614e8d565b6001600160a01b038116811461145557600080fd5b8035614eec81614ecc565b919050565b60008060408385031215614f0457600080fd5b8235614f0f81614ecc565b946020939093013593505050565b600080600060608486031215614f3257600080fd5b8335614f3d81614ecc565b92506020840135614f4d81614ecc565b929592945050506040919091013590565b600060208284031215614f7057600080fd5b8135614a8681614ecc565b634e487b7160e01b600052604160045260246000fd5b604051601f8201601f191681016001600160401b0381118282101715614fb957614fb9614f7b565b604052919050565b60008060408385031215614fd457600080fd5b8235614fdf81614ecc565b915060208301356001600160401b03811115614ffa57600080fd5b8301601f8101851361500b57600080fd5b80356001600160401b0381111561502457615024614f7b565b615037601f8201601f1916602001614f91565b81815286602083850101111561504c57600080fd5b816020840160208301376000602083830101528093505050509250929050565b60006040828403121561416957600080fd5b60006040828403121561509057600080fd5b614a86838361506c565b6001600160c01b038116811461145557600080fd5b6000602082840312156150c157600080fd5b8135614a868161509a565b60006001600160401b038211156150e5576150e5614f7b565b5060051b60200190565b600082601f83011261510057600080fd5b813561511361510e826150cc565b614f91565b8082825260208201915060208360051b86010192508583111561513557600080fd5b602085015b838110156144fa57803565ffffffffffff8116811461515857600080fd5b83526020928301920161513a565b600082601f83011261517757600080fd5b813561518561510e826150cc565b8082825260208201915060208360051b8601019250858311156151a757600080fd5b602085015b838110156144fa5780356151bf8161509a565b8352602092830192016151ac565b600082601f8301126151de57600080fd5b81356151ec61510e826150cc565b8082825260208201915060208360051b86010192508583111561520e57600080fd5b602085015b838110156144fa57803561522681614ecc565b835260209283019201615213565b600082601f83011261524557600080fd5b813561525361510e826150cc565b8082825260208201915060208360051b86010192508583111561527557600080fd5b602085015b838110156144fa57803583526020928301920161527a565b60008060008060008060c087890312156152ab57600080fd5b6152b487614ee1565b95506020870135945060408701356001600160401b038111156152d657600080fd5b6152e289828a016150ef565b94505060608701356001600160401b038111156152fe57600080fd5b61530a89828a01615166565b93505060808701356001600160401b0381111561532657600080fd5b61533289828a016151cd565b92505060a08701356001600160401b0381111561534e57600080fd5b61535a89828a01615234565b9150509295509295509295565b60ff60f81b8816815260e06020820152600061538660e0830189614e8d565b82810360408401526153988189614e8d565b606084018890526001600160a01b038716608085015260a0840186905283810360c08501528451808252602080870193509091019060005b818110156153ee5783518352602093840193909201916001016153d0565b50909b9a5050505050505050505050565b60006020828403121561541157600080fd5b5035919050565b60008083601f84011261542a57600080fd5b5081356001600160401b0381111561544157600080fd5b602083019150836020828501011115614acb57600080fd5b6000806020838503121561546c57600080fd5b82356001600160401b0381111561548257600080fd5b61548e85828601615418565b90969095509350505050565b600080608083850312156154ad57600080fd5b6154b7848461506c565b91506154c6846040850161506c565b90509250929050565b600080600080600080600060e0888a0312156154ea57600080fd5b87356154f581614ecc565b9650602088013561550581614ecc565b95506040880135945060608801359350608088013560ff8116811461552957600080fd5b9699959850939692959460a0840135945060c09093013592915050565b6000806040838503121561555957600080fd5b823561556481614ecc565b9150602083013561557481614ecc565b809150509250929050565b60008060008060008060008060006101008a8c03121561559e57600080fd5b89356155a981614ecc565b985060208a01356001600160401b038111156155c457600080fd5b6155d08c828d01615418565b90995097505060408a01356001600160401b038111156155ef57600080fd5b6155fb8c828d01615418565b90975095505060608a01356001600160401b0381111561561a57600080fd5b6156268c828d01615418565b909550935061563a90508b60808c0161506c565b91506156498b60c08c0161506c565b90509295985092959850929598565b600181811c9082168061566c57607f821691505b60208210810361416957634e487b7160e01b600052602260045260246000fd5b60006020828403121561569e57600080fd5b81518015158114614a8657600080fd5b634e487b7160e01b600052601160045260246000fd5b6000600160ff1b82016156d9576156d96156ae565b5060000390565b634e487b7160e01b600052602160045260246000fd5b6001600160c01b03841681528215156020820152606081016003831061572c57634e487b7160e01b600052602160045260246000fd5b826040830152949350505050565b600082601f83011261574b57600080fd5b815161575961510e826150cc565b8082825260208201915060208360051b86010192508583111561577b57600080fd5b602085015b838110156144fa578051835260209283019201615780565b600080604083850312156157ab57600080fd5b82516001600160401b038111156157c157600080fd5b8301601f810185136157d257600080fd5b80516157e061510e826150cc565b8082825260208201915060208360051b85010192508783111561580257600080fd5b6020840193505b8284101561582d57835161581c81614ecc565b825260209384019390910190615809565b8095505050505060208301516001600160401b0381111561584d57600080fd5b6158598582860161573a565b9150509250929050565b634e487b7160e01b600052603260045260246000fd5b6020808252602c908201527f46756e6374696f6e206d7573742062652063616c6c6564207468726f7567682060408201526b19195b1959d85d1958d85b1b60a21b606082015260800190565b6020808252602c908201527f46756e6374696f6e206d7573742062652063616c6c6564207468726f7567682060408201526b6163746976652070726f787960a01b606082015260800190565b80820180821115610998576109986156ae565b805160208083015191908110156141695760001960209190910360031b1b16919050565b6020808252600f908201526e676f7665726e616e6365206f6e6c7960881b604082015260600190565b6000604082840312801561598457600080fd5b50604080519081016001600160401b03811182821017156159a7576159a7614f7b565b6040528235815260208301356159bc8161509a565b60208201529392505050565b6020808252601390820152723737ba103130b1b5b4b7339036b0b730b3b2b960691b604082015260600190565b8082028115828204841417610998576109986156ae565b634e487b7160e01b600052601260045260246000fd5b600082615a3157615a31615a0c565b500490565b81810381811115610998576109986156ae565b6060808252845190820181905260009060208601906080840190835b81811015615a8b57835165ffffffffffff16835260209384019390920191600101615a65565b50508381036020808601919091528651808352918101925086019060005b81811015615ad05782516001600160c01b0316845260209384019390920191600101615aa9565b5050506001600160c01b03841660408401529050613454565b600060208284031215615afb57600080fd5b5051919050565b6000808354615b1081615658565b600182168015615b275760018114615b3c57615b6c565b60ff1983168652811515820286019350615b6c565b86600052602060002060005b83811015615b6457815488820152600190910190602001615b48565b505081860193505b509195945050505050565b60208152816020820152818360408301376000818301604090810191909152601f909201601f19160101919050565b601f82111561268c57806000526020600020601f840160051c81016020851015615bcd5750805b601f840160051c820191505b81811015612a505760008155600101615bd9565b6001600160401b03831115615c0457615c04614f7b565b615c1883615c128354615658565b83615ba6565b6000601f841160018114615c4c5760008515615c345750838201355b600019600387901b1c1916600186901b178355612a50565b600083815260209020601f19861690835b82811015615c7d5786850135825560209485019460019092019101615c5d565b5086821015615c9a5760001960f88860031b161c19848701351681555b505060018560011b0183555050505050565b600060208284031215615cbe57600080fd5b8151614a8681614ecc565b6001600160c01b038181168382160190811115610998576109986156ae565b6001600160c01b038281168282160390811115610998576109986156ae565b8254815260018301546001600160c01b0316602080830191909152823560408301526080820190830135615d3a8161509a565b6001600160c01b03166060929092019190915292915050565b81358155600181016020830135615d698161509a565b81546001600160c01b0319166001600160c01b03919091161790555050565b6001600160c01b03818116838216818102909216918183048114821517615db157615db16156ae565b505092915050565b60006001600160c01b03831680615dd257615dd2615a0c565b6001600160c01b03929092169190910492915050565b65ffffffffffff8281168282160390811115610998576109986156ae565b8281526040602082015260006134546040830184614e8d565b600060208284031215615e3157600080fd5b81516001600160e01b031981168114614a8657600080fd5b6020808252602b908201527f496e697469616c697a61626c653a20636f6e7472616374206973206e6f74206960408201526a6e697469616c697a696e6760a81b606082015260800190565b81516001600160401b03811115615ead57615ead614f7b565b615ec181615ebb8454615658565b84615ba6565b6020601f821160018114615ef55760008315615edd5750848201515b600019600385901b1c1916600184901b178455612a50565b600084815260208120601f198516915b82811015615f255787850151825560209485019460019092019101615f05565b5084821015615f435786840151600019600387901b60f8161c191681555b50505050600190811b01905550565b60008251615f64818460208701614e69565b919091019291505056fe360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc416464726573733a206c6f772d6c6576656c2064656c65676174652063616c6c206661696c6564a264697066735822122064e4a5f34bfc73f3e4daa932bed73959af1525e625df50fe736e51370d9c67f564736f6c634300081c0033","optimization_enabled":true,"verified_twin_address_hash":null,"is_verified":true,"compiler_settings":{"evmVersion":"paris","libraries":{},"optimizer":{"enabled":true,"runs":200},"outputSelection":{"*":{"":["*"],"*":["*"]}}},"optimization_runs":200,"sourcify_repo_url":null,"decoded_constructor_args":null,"compiler_version":"v0.8.28+commit.7893614a","is_verified_via_verifier_alliance":false,"verified_at":"2025-12-17T21:21:32.996494Z","implementations":[],"proxy_type":null,"external_libraries":[],"creation_bytecode":"0x60a06040523060805234801561001457600080fd5b50600054610100900460ff16158080156100355750600054600160ff909116105b8061004f5750303b15801561004f575060005460ff166001145b6100b65760405162461bcd60e51b815260206004820152602e60248201527f496e697469616c697a61626c653a20636f6e747261637420697320616c72656160448201526d191e481a5b9a5d1a585b1a5e995960921b606482015260840160405180910390fd5b6000805460ff1916600117905580156100d9576000805461ff0019166101001790555b801561011f576000805461ff0019169055604051600181527f7f26b83ff96e1f2b6a682f133852f6798a09c465da95921460cefb38474024989060200160405180910390a15b50608051615feb61015760003960008181611383015281816113c3015281816115130152818161155301526115e60152615feb6000f3fe6080604052600436106102885760003560e01c806372b8b0511161015a578063aeb14bf6116100c1578063db006a751161007a578063db006a75146107f5578063dd62ed3e14610815578063ddc9587614610835578063dffeadd01461087a578063f17d835c146108b2578063f90b2bfe146108d257600080fd5b8063aeb14bf61461073d578063b32deb3d1461075d578063baa74f1f1461077d578063cc872b661461079d578063d505accf146107bd578063d6122e92146107dd57600080fd5b806395d89b411161011357806395d89b411461068e5780639926020b146106a35780639f200bba146106b8578063a16e1532146106d8578063a457c2d7146106fd578063a9059cbb1461071d57600080fd5b806372b8b0511461058c5780637ecebe00146105ac5780637f2d27b9146105cc57806384b0196e146105e15780638c83ed33146106095780638e31ab2e1461062957600080fd5b80633659cfe6116101fe57806354fd4d50116101b757806354fd4d50146104a75780635beafb3d146104d557806363965449146104f55780636b2ba67d1461051557806370a08231146105355780637121c2731461056b57600080fd5b80633659cfe61461040a578063395093511461042a57806339b1b96d1461044a5780634b35073f1461045f5780634f1ef2861461047f57806352d1902d1461049257600080fd5b806318160ddd1161025057806318160ddd1461036857806323282f6e1461037d57806323b872dd146103995780632f7605fb146103b9578063313ce567146103d95780633644e515146103f557600080fd5b806306fdde031461028d578063095ea7b3146102b85780630b0e54d0146102e85780631207f0c114610312578063180f913414610334575b600080fd5b34801561029957600080fd5b506102a26108f2565b6040516102af9190614eb9565b60405180910390f35b3480156102c457600080fd5b506102d86102d3366004614ef1565b610984565b60405190151581526020016102af565b3480156102f457600080fd5b50610304670de0b6b3a764000081565b6040519081526020016102af565b34801561031e57600080fd5b5061033261032d366004614ef1565b61099e565b005b34801561034057600080fd5b506103506703782dace9d9000081565b6040516001600160c01b0390911681526020016102af565b34801561037457600080fd5b5060cb54610304565b34801561038957600080fd5b50610350670de0b6b3a764000081565b3480156103a557600080fd5b506102d86103b4366004614f1d565b610e74565b3480156103c557600080fd5b506103326103d4366004614ef1565b610e98565b3480156103e557600080fd5b50604051601281526020016102af565b34801561040157600080fd5b5061030461136a565b34801561041657600080fd5b50610332610425366004614f5e565b611379565b34801561043657600080fd5b506102d8610445366004614ef1565b611458565b34801561045657600080fd5b506102a261147a565b34801561046b57600080fd5b506103506b033b2e3c9fd0803ce800000081565b61033261048d366004614fc1565b611509565b34801561049e57600080fd5b506103046115d9565b3480156104b357600080fd5b506040805180820190915260058152640342e322e360dc1b60208201526102a2565b3480156104e157600080fd5b506103326104f036600461507e565b61168c565b34801561050157600080fd5b506103326105103660046150af565b6117df565b34801561052157600080fd5b50610332610530366004615292565b611a46565b34801561054157600080fd5b50610304610550366004614f5e565b6001600160a01b0316600090815260c9602052604090205490565b34801561057757600080fd5b5061016654610350906001600160c01b031681565b34801561059857600080fd5b506103326105a736600461507e565b61226b565b3480156105b857600080fd5b506103046105c7366004614f5e565b612373565b3480156105d857600080fd5b50610304612392565b3480156105ed57600080fd5b506105f66123b5565b6040516102af9796959493929190615367565b34801561061557600080fd5b506103326106243660046153ff565b612453565b34801561063557600080fd5b506040805180820182526000808252602091820152815180830190925261016b54825261016c546001600160c01b0316908201525b60408051825181526020928301516001600160c01b031692810192909252016102af565b34801561069a57600080fd5b506102a26124e0565b3480156106af57600080fd5b506103046124ef565b3480156106c457600080fd5b506103326106d3366004615459565b612527565b3480156106e457600080fd5b506103046daf298d050e4395d69670b12b7f4160301b81565b34801561070957600080fd5b506102d8610718366004614ef1565b612691565b34801561072957600080fd5b506102d8610738366004614ef1565b61270c565b34801561074957600080fd5b506103326107583660046150af565b61271a565b34801561076957600080fd5b50610332610778366004614f5e565b61278f565b34801561078957600080fd5b5061033261079836600461549a565b612a57565b3480156107a957600080fd5b506103326107b83660046153ff565b612b9b565b3480156107c957600080fd5b506103326107d83660046154cf565b612ba5565b3480156107e957600080fd5b50610350633b9aca0081565b34801561080157600080fd5b506103326108103660046153ff565b612c9e565b34801561082157600080fd5b50610304610830366004615546565b612ca8565b34801561084157600080fd5b5060408051808201825260008082526020918201528151808301909252610167548252610168546001600160c01b03169082015261066a565b34801561088657600080fd5b5060975461089a906001600160a01b031681565b6040516001600160a01b0390911681526020016102af565b3480156108be57600080fd5b506103326108cd36600461557f565b612cd3565b3480156108de57600080fd5b506103326108ed3660046153ff565b61317a565b606060cc805461090190615658565b80601f016020809104026020016040519081016040528092919081815260200182805461092d90615658565b801561097a5780601f1061094f5761010080835404028352916020019161097a565b820191906000526020600020905b81548152906001019060200180831161095d57829003601f168201915b5050505050905090565b6000336109928185856131da565b60019150505b92915050565b609760009054906101000a90046001600160a01b03166001600160a01b03166375a8f9266040518163ffffffff1660e01b8152600401602060405180830381865afa1580156109f1573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610a15919061568c565b15610a675760405162461bcd60e51b815260206004820152601960248201527f66726f7a656e206f722069737375616e6365207061757365640000000000000060448201526064015b60405180910390fd5b609760009054906101000a90046001600160a01b03166001600160a01b03166314f4ded26040518163ffffffff1660e01b8152600401600060405180830381600087803b158015610ab757600080fd5b505af1158015610acb573d6000803e3d6000fd5b5050505080600003610b135760405162461bcd60e51b815260206004820152601160248201527043616e6e6f74206973737565207a65726f60781b6044820152606401610a5e565b61016260009054906101000a90046001600160a01b03166001600160a01b031663f8ac93e86040518163ffffffff1660e01b8152600401600060405180830381600087803b158015610b6457600080fd5b505af1158015610b78573d6000803e3d6000fd5b505050506000610b853390565b905061016360009054906101000a90046001600160a01b03166001600160a01b031663a094a0316040518163ffffffff1660e01b8152600401602060405180830381865afa158015610bdb573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610bff919061568c565b610c3e5760405162461bcd60e51b815260206004820152601060248201526f6261736b6574206e6f7420726561647960801b6044820152606401610a5e565b6000610c4960cb5490565b9050610c5861016782856132fe565b610c6f81610c65856156c4565b61016b91906132fe565b600081600003610c8757610c8284613408565b610ca1565b61016654610ca1906001600160c01b031685846002613432565b9050846001600160a01b0316836001600160a01b03167f93a73b97592126fd663d485c98f8a174c1d701035545e71ac88a05b71d6ad4ef8684604051610cfa9291909182526001600160c01b0316602082015260400190565b60405180910390a361016354604051631c89e88d60e11b815260009182916001600160a01b0390911690633913d11a90610d3e9086906001906002906004016156f6565b600060405180830381865afa158015610d5b573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f19168201604052610d839190810190615798565b91509150610d9287848661345c565b60005b8251811015610e0e57610e068661016460009054906101000a90046001600160a01b0316848481518110610dcb57610dcb615863565b6020026020010151868581518110610de557610de5615863565b60200260200101516001600160a01b0316613536909392919063ffffffff16565b600101610d95565b5050609754604080516331cfec0560e01b815290516001600160a01b0390921695506331cfec05945060048082019450600093509082900301818387803b158015610e5857600080fd5b505af1158015610e6c573d6000803e3d6000fd5b505050505050565b600033610e828582856135a1565b610e8d858585613615565b506001949350505050565b609760009054906101000a90046001600160a01b03166001600160a01b031663054f7d9c6040518163ffffffff1660e01b8152600401602060405180830381865afa158015610eeb573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610f0f919061568c565b15610f455760405162461bcd60e51b8152602060048201526006602482015265333937bd32b760d11b6044820152606401610a5e565b609760009054906101000a90046001600160a01b03166001600160a01b03166314f4ded26040518163ffffffff1660e01b8152600401600060405180830381600087803b158015610f9557600080fd5b505af1158015610fa9573d6000803e3d6000fd5b5050505061016260009054906101000a90046001600160a01b03166001600160a01b031663f8ac93e86040518163ffffffff1660e01b8152600401600060405180830381600087803b158015610ffe57600080fd5b505af1158015611012573d6000803e3d6000fd5b50505050600061101f3390565b9050816000036110665760405162461bcd60e51b815260206004820152601260248201527143616e6e6f742072656465656d207a65726f60701b6044820152606401610a5e565b6001600160a01b0383166110bc5760405162461bcd60e51b815260206004820152601d60248201527f63616e6e6f742072656465656d20746f207a65726f20616464726573730000006044820152606401610a5e565b6001600160a01b038116600090815260c9602052604090205482111561111b5760405162461bcd60e51b8152602060048201526014602482015273696e73756666696369656e742062616c616e636560601b6044820152606401610a5e565b61016360009054906101000a90046001600160a01b03166001600160a01b031663e45a5b2d6040518163ffffffff1660e01b8152600401602060405180830381865afa15801561116f573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611193919061568c565b6111eb5760405162461bcd60e51b8152602060048201526024808201527f7061727469616c20726564656d7074696f6e3b207573652072656465656d437560448201526373746f6d60e01b6064820152608401610a5e565b60006111f660cb5490565b905061120f81611205856156c4565b61016791906132fe565b61121c61016b82856132fe565b600061122883856137cb565b9050846001600160a01b0316836001600160a01b03167f49e15c2a707390f4ccf35ee268a61455f17aeb5b1983c01e1dd1f00b86a4725e86846040516112819291909182526001600160c01b0316602082015260400190565b60405180910390a361016354604051631c89e88d60e11b815260009182916001600160a01b0390911690633913d11a906112c3908690859081906004016156f6565b600060405180830381865afa1580156112e0573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f191682016040526113089190810190615798565b9150915060005b8251811015610e0e5781818151811061132a5761132a615863565b60200260200101516000031561136257610164548251611362916001600160a01b0316908a90859085908110610dcb57610dcb615863565b60010161130f565b600061137461389a565b905090565b6001600160a01b037f00000000000000000000000000000000000000000000000000000000000000001630036113c15760405162461bcd60e51b8152600401610a5e90615879565b7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031661140a600080516020615f6f833981519152546001600160a01b031690565b6001600160a01b0316146114305760405162461bcd60e51b8152600401610a5e906158c5565b611439816138a4565b60408051600080825260208201909252611455918391906138f3565b50565b60003361099281858561146b8383612ca8565b6114759190615911565b6131da565b610161805461148890615658565b80601f01602080910402602001604051908101604052809291908181526020018280546114b490615658565b80156115015780601f106114d657610100808354040283529160200191611501565b820191906000526020600020905b8154815290600101906020018083116114e457829003601f168201915b505050505081565b6001600160a01b037f00000000000000000000000000000000000000000000000000000000000000001630036115515760405162461bcd60e51b8152600401610a5e90615879565b7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031661159a600080516020615f6f833981519152546001600160a01b031690565b6001600160a01b0316146115c05760405162461bcd60e51b8152600401610a5e906158c5565b6115c9826138a4565b6115d5828260016138f3565b5050565b6000306001600160a01b037f000000000000000000000000000000000000000000000000000000000000000016146116795760405162461bcd60e51b815260206004820152603860248201527f555550535570677261646561626c653a206d757374206e6f742062652063616c60448201527f6c6564207468726f7567682064656c656761746563616c6c00000000000000006064820152608401610a5e565b50600080516020615f6f83398151915290565b60975460408051808201909152600581526427aba722a960d91b60208201526001600160a01b03909116906391d14854906116c690615924565b336040516001600160e01b031960e085901b16815260048101929092526001600160a01b03166024820152604401602060405180830381865afa158015611711573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611735919061568c565b6117515760405162461bcd60e51b8152600401610a5e90615948565b61175a81613a5e565b61179361176c36839003830183615971565b6040805180820190915261016b54815261016c546001600160c01b03166020820152613bea565b6114555760405162461bcd60e51b815260206004820152601b60248201527f726564656d7074696f6e207468726f74746c6520746f6f206c6f7700000000006044820152606401610a5e565b609760009054906101000a90046001600160a01b03166001600160a01b03166398f73e526040518163ffffffff1660e01b8152600401602060405180830381865afa158015611832573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611856919061568c565b1561189e5760405162461bcd60e51b8152602060048201526018602482015277199c9bde995b881bdc881d1c98591a5b99c81c185d5cd95960421b6044820152606401610a5e565b610164546001600160a01b0316336001600160a01b0316146118d25760405162461bcd60e51b8152600401610a5e906159c8565b61016654604080516001600160c01b03928316815291831660208301527f0b0ca69be72e0611a1f79eedf91aece404ff14cb8fcfd0c997a72b68d4fdd478910160405180910390a161016680546001600160c01b0319166001600160c01b03831617905560cb54806000036119745760405162461bcd60e51b81526020600482015260086024820152673020737570706c7960c01b6044820152606401610a5e565b6000816119926001600160c01b038516670de0b6b3a76400006159f5565b61199c9190615a22565b90506000826119ac600182615a36565b6119c76001600160c01b038716670de0b6b3a76400006159f5565b6119d19190615911565b6119db9190615a22565b9050633b9aca0082108015906119fd57506b033b2e3c9fd0803ce80000008111155b611a405760405162461bcd60e51b815260206004820152601460248201527342552072617465206f7574206f662072616e676560601b6044820152606401610a5e565b50505050565b609760009054906101000a90046001600160a01b03166001600160a01b031663054f7d9c6040518163ffffffff1660e01b8152600401602060405180830381865afa158015611a99573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611abd919061568c565b15611af35760405162461bcd60e51b8152602060048201526006602482015265333937bd32b760d11b6044820152606401610a5e565b609760009054906101000a90046001600160a01b03166001600160a01b03166314f4ded26040518163ffffffff1660e01b8152600401600060405180830381600087803b158015611b4357600080fd5b505af1158015611b57573d6000803e3d6000fd5b5050505061016260009054906101000a90046001600160a01b03166001600160a01b031663f8ac93e86040518163ffffffff1660e01b8152600401600060405180830381600087803b158015611bac57600080fd5b505af1158015611bc0573d6000803e3d6000fd5b5050505084600003611c095760405162461bcd60e51b815260206004820152601260248201527143616e6e6f742072656465656d207a65726f60701b6044820152606401610a5e565b611c1233610550565b851115611c585760405162461bcd60e51b8152602060048201526014602482015273696e73756666696369656e742062616c616e636560601b6044820152606401610a5e565b6000805b8451811015611c9d57848181518110611c7757611c77615863565b60200260200101516001600160c01b031682611c939190615911565b9150600101611c5c565b50670de0b6b3a76400008114611cff5760405162461bcd60e51b815260206004820152602160248201527f706f7274696f6e7320646f206e6f742061646420757020746f204649585f4f4e6044820152604560f81b6064820152608401610a5e565b6000611d0a60cb5490565b9050611d1981611205896156c4565b611d2661016b82896132fe565b6000611d3233896137cb565b604080518a81526001600160c01b03831660208201529192506001600160a01b038b169133917f49e15c2a707390f4ccf35ee268a61455f17aeb5b1983c01e1dd1f00b86a4725e910160405180910390a361016354604051630e3363af60e21b815260009182916001600160a01b03909116906338cd8ebc90611dbd908c908c908890600401615a49565b600060405180830381865afa158015611dda573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f19168201604052611e029190810190615798565b9150915060005b8251811015611ef5576000611ea9848381518110611e2957611e29615863565b6020908102919091010151610164546040516370a0823160e01b81526001600160a01b0391821660048201529116906370a0823190602401602060405180830381865afa158015611e7e573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611ea29190615ae9565b8d88613ca0565b9050828281518110611ebd57611ebd615863565b6020026020010151811015611eec5780838381518110611edf57611edf615863565b6020026020010181815250505b50600101611e09565b50600087516001600160401b03811115611f1157611f11614f7b565b604051908082528060200260200182016040528015611f3a578160200160208202803683370190505b50905060005b8851811015611ff657888181518110611f5b57611f5b615863565b60209081029190910101516040516370a0823160e01b81526001600160a01b038f81166004830152909116906370a0823190602401602060405180830381865afa158015611fad573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611fd19190615ae9565b828281518110611fe357611fe3615863565b6020908102919091010152600101611f40565b50600160005b84518110156120815783818151811061201757612017615863565b60200260200101516000031561207957811561203257600091505b61207961016460009054906101000a90046001600160a01b03168f86848151811061205f5761205f615863565b6020026020010151888581518110610de557610de5615863565b600101611ffc565b5080156120c35760405162461bcd60e51b815260206004820152601060248201526f32b6b83a3c903932b232b6b83a34b7b760811b6044820152606401610a5e565b5060005b88518110156121ff5760008982815181106120e4576120e4615863565b60200260200101516001600160a01b03166370a082318f6040518263ffffffff1660e01b815260040161212691906001600160a01b0391909116815260200190565b602060405180830381865afa158015612143573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906121679190615ae9565b905088828151811061217b5761217b615863565b602002602001015183838151811061219557612195615863565b6020026020010151826121a89190615a36565b10156121f65760405162461bcd60e51b815260206004820152601860248201527f726564656d7074696f6e2062656c6f77206d696e696d756d00000000000000006044820152606401610a5e565b506001016120c7565b5050609754604080516331cfec0560e01b815290516001600160a01b0390921696506331cfec059550600480820195506000945091925082900301818387803b15801561224b57600080fd5b505af115801561225f573d6000803e3d6000fd5b50505050505050505050565b60975460408051808201909152600581526427aba722a960d91b60208201526001600160a01b03909116906391d14854906122a590615924565b336040516001600160e01b031960e085901b16815260048101929092526001600160a01b03166024820152604401602060405180830381865afa1580156122f0573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612314919061568c565b6123305760405162461bcd60e51b8152600401610a5e90615948565b61233981613d83565b60408051808201909152610167548152610168546001600160c01b031660208201526117939061236e36849003840184615971565b613bea565b6001600160a01b038116600090815261012f6020526040812054610998565b60006113746123ac6123a360cb5490565b61016790613f0f565b61016790613f5a565b60006060806000806000606060fb546000801b1480156123d5575060fc54155b6124195760405162461bcd60e51b81526020600482015260156024820152741152540dcc4c8e88155b9a5b9a5d1a585b1a5e9959605a1b6044820152606401610a5e565b612421613fb8565b612429613fc7565b60408051600080825260208201909252600f60f81b9b939a50919850469750309650945092509050565b6101655433906001600160a01b0316811461249f5760405162461bcd60e51b815260206004820152600c60248201526b6675726e616365206f6e6c7960a01b6044820152606401610a5e565b6124a98183613fd6565b6040518281527f12b02b431a920654430b36652724950afbd1e5279648b404790dbd036b1a58a79060200160405180910390a15050565b606060cd805461090190615658565b6000806124fb60cb5490565b905061251561250c61016b83613f0f565b61016b90613f5a565b915081811015612523578091505b5090565b60975460408051808201909152600581526427aba722a960d91b60208201526001600160a01b03909116906391d148549061256190615924565b336040516001600160e01b031960e085901b16815260048101929092526001600160a01b03166024820152604401602060405180830381865afa1580156125ac573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906125d0919061568c565b6125ec5760405162461bcd60e51b8152600401610a5e90615948565b600081900361262d5760405162461bcd60e51b815260206004820152600d60248201526c6d616e6461746520656d70747960981b6044820152606401610a5e565b61016160405161263d9190615b02565b60405180910390207fbe9c7b8329f0e16f8d471d960d8b7b880afbac86134ea495ce1adc0ae7d53bcf8383604051612676929190615b77565b60405180910390a261016161268c828483615bed565b505050565b6000338161269f8286612ca8565b9050838110156126ff5760405162461bcd60e51b815260206004820152602560248201527f45524332303a2064656372656173656420616c6c6f77616e63652062656c6f77604482015264207a65726f60d81b6064820152608401610a5e565b610e8d82868684036131da565b600033610992818585613615565b610164546001600160a01b0316336001600160a01b03161461274e5760405162461bcd60e51b8152600401610a5e906159c8565b600061275960cb5490565b90506127696101678260006132fe565b61277761016b8260006132fe565b610164546115d5906001600160a01b0316838361345c565b609760009054906101000a90046001600160a01b03166001600160a01b03166398f73e526040518163ffffffff1660e01b8152600401602060405180830381865afa1580156127e2573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612806919061568c565b1561284e5760405162461bcd60e51b8152602060048201526018602482015277199c9bde995b881bdc881d1c98591a5b99c81c185d5cd95960421b6044820152606401610a5e565b609760009054906101000a90046001600160a01b03166001600160a01b03166314f4ded26040518163ffffffff1660e01b8152600401600060405180830381600087803b15801561289e57600080fd5b505af11580156128b2573d6000803e3d6000fd5b50506101625460405163c3c5a54760e01b81526001600160a01b038581166004830152909116925063c3c5a5479150602401602060405180830381865afa158015612901573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612925919061568c565b6129665760405162461bcd60e51b8152602060048201526012602482015271195c98cc8c081d5b9c9959da5cdd195c995960721b6044820152606401610a5e565b610164546040516370a0823160e01b81523060048201526129ec916001600160a01b0390811691908416906370a0823190602401602060405180830381865afa1580156129b7573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906129db9190615ae9565b6001600160a01b0384169190614116565b609760009054906101000a90046001600160a01b03166001600160a01b03166331cfec056040518163ffffffff1660e01b8152600401600060405180830381600087803b158015612a3c57600080fd5b505af1158015612a50573d6000803e3d6000fd5b5050505050565b60975460408051808201909152600581526427aba722a960d91b60208201526001600160a01b03909116906391d1485490612a9190615924565b336040516001600160e01b031960e085901b16815260048101929092526001600160a01b03166024820152604401602060405180830381865afa158015612adc573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612b00919061568c565b612b1c5760405162461bcd60e51b8152600401610a5e90615948565b612b2582613a5e565b612b2e81613d83565b612b4f612b4036849003840184615971565b61236e36849003840184615971565b6115d55760405162461bcd60e51b815260206004820152601b60248201527f726564656d7074696f6e207468726f74746c6520746f6f206c6f7700000000006044820152606401610a5e565b611455338261099e565b83421115612bf55760405162461bcd60e51b815260206004820152601d60248201527f45524332305065726d69743a206578706972656420646561646c696e650000006044820152606401610a5e565b60007f6e71edae12b1b97f4d1f60370fef10105fa2faae0126114a169c64845d6126c9888888612c248c614146565b6040805160208101969096526001600160a01b0394851690860152929091166060840152608083015260a082015260c0810186905260e001604051602081830303815290604052805190602001209050612c8988612c818361416f565b86868661419c565b612c948888886131da565b5050505050505050565b6114553382610e98565b6001600160a01b03918216600090815260ca6020908152604080832093909416825291909152205490565b600054610100900460ff1615808015612cf35750600054600160ff909116105b80612d0d5750303b158015612d0d575060005460ff166001145b612d705760405162461bcd60e51b815260206004820152602e60248201527f496e697469616c697a61626c653a20636f6e747261637420697320616c72656160448201526d191e481a5b9a5d1a585b1a5e995960921b6064820152608401610a5e565b6000805460ff191660011790558015612d93576000805461ff0019166101001790555b6000889003612dd15760405162461bcd60e51b815260206004820152600a6024820152696e616d6520656d70747960b01b6044820152606401610a5e565b6000869003612e115760405162461bcd60e51b815260206004820152600c60248201526b73796d626f6c20656d70747960a01b6044820152606401610a5e565b612e1a8a61433a565b612e8d89898080601f01602080910402602001604051908101604052809392919081815260200183838082843760009201919091525050604080516020601f8d018190048102820181019092528b815292508b91508a90819084018382808284376000920191909152506143d892505050565b612ecc89898080601f01602080910402602001604051908101604052809392919081815260200183838082843760009201919091525061440992505050565b896001600160a01b031663979d7e866040518163ffffffff1660e01b8152600401602060405180830381865afa158015612f0a573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612f2e9190615cac565b61016260006101000a8154816001600160a01b0302191690836001600160a01b03160217905550896001600160a01b0316632f2439b16040518163ffffffff1660e01b8152600401602060405180830381865afa158015612f93573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612fb79190615cac565b61016360006101000a8154816001600160a01b0302191690836001600160a01b03160217905550896001600160a01b031663dc8af5f66040518163ffffffff1660e01b8152600401602060405180830381865afa15801561301c573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906130409190615cac565b61016460006101000a8154816001600160a01b0302191690836001600160a01b03160217905550896001600160a01b031663656e96e16040518163ffffffff1660e01b8152600401602060405180830381865afa1580156130a5573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906130c99190615cac565b61016580546001600160a01b0319166001600160a01b03929092169190911790556130f48585612527565b6130fe8383612a57565b610169805465ffffffffffff421665ffffffffffff19918216811790925561016d80549091169091179055801561225f576000805461ff0019169055604051600181527f7f26b83ff96e1f2b6a682f133852f6798a09c465da95921460cefb38474024989060200160405180910390a150505050505050505050565b6101645433906001600160a01b031681146131a75760405162461bcd60e51b8152600401610a5e906159c8565b60006131b260cb5490565b90506131c26101678260006132fe565b6131d061016b8260006132fe565b611a4082846137cb565b6001600160a01b03831661323c5760405162461bcd60e51b8152602060048201526024808201527f45524332303a20617070726f76652066726f6d20746865207a65726f206164646044820152637265737360e01b6064820152608401610a5e565b6001600160a01b03821661329d5760405162461bcd60e51b815260206004820152602260248201527f45524332303a20617070726f766520746f20746865207a65726f206164647265604482015261737360f01b6064820152608401610a5e565b6001600160a01b03838116600081815260ca602090815260408083209487168084529482529182902085905590518481527f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925910160405180910390a3505050565b8254158015613318575060018301546001600160c01b0316155b1561332257505050565b600061332e8484613f0f565b9050600061333c8583613f5a565b905084600301548114158061335057508181145b156133715760028501805465ffffffffffff19164265ffffffffffff161790555b60008313156133db57808311156133ca5760405162461bcd60e51b815260206004820152601760248201527f737570706c79206368616e6765207468726f74746c65640000000000000000006044820152606401610a5e565b6133d48382615a36565b90506133fa565b60008312156133fa576133ed836156c4565b6133f79082615911565b90505b600390940193909355505050565b60006001600160c01b038211156125235760405163f44398f560e01b815260040160405180910390fd5b600061345161344c866001600160c01b0316868686614457565b613408565b90505b949350505050565b60008160000361346c5782613488565b61016654613488906001600160c01b0385811691859116614504565b610166546001600160c01b0391821692507f0b0ca69be72e0611a1f79eedf91aece404ff14cb8fcfd0c997a72b68d4fdd47891166134c68582615cc9565b604080516001600160c01b0393841681529290911660208301520160405180910390a161016680548491906000906135089084906001600160c01b0316615cc9565b92506101000a8154816001600160c01b0302191690836001600160c01b03160217905550611a408482614513565b6040516001600160a01b0380851660248301528316604482015260648101829052611a409085906323b872dd60e01b906084015b60408051601f198184030181529190526020810180516001600160e01b03166001600160e01b0319909316929092179091526145e0565b60006135ad8484612ca8565b90506000198114611a4057818110156136085760405162461bcd60e51b815260206004820152601d60248201527f45524332303a20696e73756666696369656e7420616c6c6f77616e63650000006044820152606401610a5e565b611a4084848484036131da565b6001600160a01b0383166136795760405162461bcd60e51b815260206004820152602560248201527f45524332303a207472616e736665722066726f6d20746865207a65726f206164604482015264647265737360d81b6064820152608401610a5e565b6001600160a01b0382166136db5760405162461bcd60e51b815260206004820152602360248201527f45524332303a207472616e7366657220746f20746865207a65726f206164647260448201526265737360e81b6064820152608401610a5e565b6136e68383836146b5565b6001600160a01b038316600090815260c960205260409020548181101561375e5760405162461bcd60e51b815260206004820152602660248201527f45524332303a207472616e7366657220616d6f756e7420657863656564732062604482015265616c616e636560d01b6064820152608401610a5e565b6001600160a01b03808516600081815260c9602052604080822086860390559286168082529083902080548601905591517fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef906137be9086815260200190565b60405180910390a3611a40565b60006137ee826137da60cb5490565b610166546001600160c01b03169190614504565b610166549091507f0b0ca69be72e0611a1f79eedf91aece404ff14cb8fcfd0c997a72b68d4fdd478906001600160c01b031661382a8382615ce8565b604080516001600160c01b0393841681529290911660208301520160405180910390a1610166805482919060009061386c9084906001600160c01b0316615ce8565b92506101000a8154816001600160c01b0302191690836001600160c01b031602179055506109988383613fd6565b600061137461470d565b6097546001600160a01b0316336001600160a01b0316146114555760405162461bcd60e51b81526020600482015260096024820152686d61696e206f6e6c7960b81b6044820152606401610a5e565b7f4910fdfa16fed3260ed0e7147f7cc6da11a60208b5b9406d12a635614ffd91435460ff16156139265761268c83614781565b826001600160a01b03166352d1902d6040518163ffffffff1660e01b8152600401602060405180830381865afa925050508015613980575060408051601f3d908101601f1916820190925261397d91810190615ae9565b60015b6139e35760405162461bcd60e51b815260206004820152602e60248201527f45524331393637557067726164653a206e657720696d706c656d656e7461746960448201526d6f6e206973206e6f74205555505360901b6064820152608401610a5e565b600080516020615f6f8339815191528114613a525760405162461bcd60e51b815260206004820152602960248201527f45524331393637557067726164653a20756e737570706f727465642070726f786044820152681a58589b195555525160ba1b6064820152608401610a5e565b5061268c83838361481d565b670de0b6b3a764000081351015613ab75760405162461bcd60e51b815260206004820152601a60248201527f69737375616e636520616d745261746520746f6f20736d616c6c0000000000006044820152606401610a5e565b6daf298d050e4395d69670b12b7f4160301b81351115613b195760405162461bcd60e51b815260206004820152601860248201527f69737375616e636520616d745261746520746f6f2062696700000000000000006044820152606401610a5e565b670de0b6b3a7640000613b3260408301602084016150af565b6001600160c01b03161115613b895760405162461bcd60e51b815260206004820152601860248201527f69737375616e6365207063745261746520746f6f2062696700000000000000006044820152606401610a5e565b613ba0613b9560cb5490565b6101679060006132fe565b6040517fa3e16a02f78ca4f5cf54ab43fd2cb34e5014ba4ec2e0cafb751203dcdd0aa82790613bd490610167908490615d07565b60405180910390a18061016761268c8282615d53565b81516000908190670de0b6b3a764000090613c0e906703782dace9d90000906159f5565b613c189190615a22565b8451613c249190615911565b90506000670de0b6b3a76400006001600160401b03166703782dace9d900008660200151613c529190615d88565b613c5c9190615db9565b8560200151613c6b9190615cc9565b6001600160c01b0316905081846000015110158015613c9757508084602001516001600160c01b031610155b95945050505050565b6000806000613caf8686614842565b91509150838210613cd35760405163f44398f560e01b815260040160405180910390fd5b60008480613ce357613ce3615a0c565b868809905081811115613cf7576001830392505b908190039060008590038516808681613d1257613d12615a0c565b049550808381613d2457613d24615a0c565b049250808160000381613d3957613d39615a0c565b046001019390930291909101600285810380870282030280870282030280870282030280870282030280870282030280870282030295860290039094029390930295945050505050565b670de0b6b3a764000081351015613ddc5760405162461bcd60e51b815260206004820152601c60248201527f726564656d7074696f6e20616d745261746520746f6f20736d616c6c000000006044820152606401610a5e565b6daf298d050e4395d69670b12b7f4160301b81351115613e3e5760405162461bcd60e51b815260206004820152601a60248201527f726564656d7074696f6e20616d745261746520746f6f206269670000000000006044820152606401610a5e565b670de0b6b3a7640000613e5760408301602084016150af565b6001600160c01b03161115613eae5760405162461bcd60e51b815260206004820152601a60248201527f726564656d7074696f6e207063745261746520746f6f206269670000000000006044820152606401610a5e565b613ec5613eba60cb5490565b61016b9060006132fe565b6040517fae0adad2741496b9b813ff6121945ff13626d9b550f6d2852530d28a79051ac290613ef99061016b908490615d07565b60405180910390a18061016b61268c8282615d53565b60018201546000908390670de0b6b3a764000090613f36906001600160c01b0316856159f5565b613f409190615a22565b91508181600001541115613f5357805491505b5092915050565b60028201546000908190613f769065ffffffffffff1642615de8565b9050610e10613f8d65ffffffffffff8316856159f5565b613f979190615a22565b8460030154613fa69190615911565b915082821115613f5357509092915050565b606060fd805461090190615658565b606060fe805461090190615658565b6001600160a01b0382166140365760405162461bcd60e51b815260206004820152602160248201527f45524332303a206275726e2066726f6d20746865207a65726f206164647265736044820152607360f81b6064820152608401610a5e565b614042826000836146b5565b6001600160a01b038216600090815260c96020526040902054818110156140b65760405162461bcd60e51b815260206004820152602260248201527f45524332303a206275726e20616d6f756e7420657863656564732062616c616e604482015261636560f01b6064820152608401610a5e565b6001600160a01b038316600081815260c960209081526040808320868603905560cb80548790039055518581529192917fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef910160405180910390a3505050565b6040516001600160a01b03831660248201526044810182905261268c90849063a9059cbb60e01b9060640161356a565b6001600160a01b038116600090815261012f602052604090208054600181018255905b50919050565b600061099861417c61389a565b8360405161190160f01b8152600281019290925260228201526042902090565b6001600160a01b0385163b156142aa57604080516020810184905280820183905260f885901b6001600160f81b0319166060820152815160418183030181526061820192839052630b135d3f60e11b9092526001600160a01b03871691631626ba7e9161420d918891606501615e06565b602060405180830381865afa15801561422a573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061424e9190615e1f565b6001600160e01b031916631626ba7e60e01b146142a55760405162461bcd60e51b8152602060048201526015602482015274115490cc4c8dcc4e88155b985d5d1a1bdc9a5e9959605a1b6044820152606401610a5e565b612a50565b60408051602081018490529081018290526001600160f81b031960f885901b1660608201526142ee908690869060610160405160208183030381529060405261486f565b612a505760405162461bcd60e51b815260206004820152601e60248201527f45524332305065726d69743a20696e76616c6964207369676e617475726500006044820152606401610a5e565b600054610100900460ff166143615760405162461bcd60e51b8152600401610a5e90615e49565b6001600160a01b0381166143ae5760405162461bcd60e51b81526020600482015260146024820152736d61696e206973207a65726f206164647265737360601b6044820152606401610a5e565b6143b66148d0565b609780546001600160a01b0319166001600160a01b0392909216919091179055565b600054610100900460ff166143ff5760405162461bcd60e51b8152600401610a5e90615e49565b6115d582826148f9565b600054610100900460ff166144305760405162461bcd60e51b8152600401610a5e90615e49565b61145581604051806040016040528060058152602001640342e322e360dc1b815250614939565b600080614465868686613ca0565b9050600083600281111561447b5761447b6156e0565b03614487579050613454565b6000848061449757614497615a0c565b868809905060028460028111156144b0576144b06156e0565b036144ce5780156144c9576144c6600183615911565b91505b6144fa565b60026144db600187615a36565b6144e59190615a22565b8111156144fa576144f7600183615911565b91505b5095945050505050565b60006134548484846000613432565b6001600160a01b0382166145695760405162461bcd60e51b815260206004820152601f60248201527f45524332303a206d696e7420746f20746865207a65726f2061646472657373006044820152606401610a5e565b614575600083836146b5565b8060cb60008282546145879190615911565b90915550506001600160a01b038216600081815260c960209081526040808320805486019055518481527fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef910160405180910390a35050565b6000614635826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b03166149889092919063ffffffff16565b9050805160001480614656575080806020019051810190614656919061568c565b61268c5760405162461bcd60e51b815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e6044820152691bdd081cdd58d8d9595960b21b6064820152608401610a5e565b306001600160a01b0383160361268c5760405162461bcd60e51b815260206004820152601760248201527f52546f6b656e207472616e7366657220746f2073656c660000000000000000006044820152606401610a5e565b60007f8b73c3c69bb8fe3d512ecc4cf759cc79239f7b179b0ffacaa9a75d522b39400f614738614997565b6147406149f0565b60408051602081019490945283019190915260608201524660808201523060a082015260c00160405160208183030381529060405280519060200120905090565b6001600160a01b0381163b6147ee5760405162461bcd60e51b815260206004820152602d60248201527f455243313936373a206e657720696d706c656d656e746174696f6e206973206e60448201526c1bdd08184818dbdb9d1c9858dd609a1b6064820152608401610a5e565b600080516020615f6f83398151915280546001600160a01b0319166001600160a01b0392909216919091179055565b61482683614a21565b6000825111806148335750805b1561268c57611a408383614a61565b6000808060001984860990508385029150818103925081811015614867576001830392505b509250929050565b600080600061487e8585614a8d565b90925090506000816004811115614897576148976156e0565b1480156148b55750856001600160a01b0316826001600160a01b0316145b806148c657506148c6868686614ad2565b9695505050505050565b600054610100900460ff166148f75760405162461bcd60e51b8152600401610a5e90615e49565b565b600054610100900460ff166149205760405162461bcd60e51b8152600401610a5e90615e49565b60cc61492c8382615e94565b5060cd61268c8282615e94565b600054610100900460ff166149605760405162461bcd60e51b8152600401610a5e90615e49565b60fd61496c8382615e94565b5060fe6149798282615e94565b5050600060fb81905560fc5550565b60606134548484600085614bbe565b6000806149a2613fb8565b8051909150156149b9578051602090910120919050565b60fb5480156149c85792915050565b7fc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a4709250505090565b6000806149fb613fc7565b805190915015614a12578051602090910120919050565b60fc5480156149c85792915050565b614a2a81614781565b6040516001600160a01b038216907fbc7cd75a20ee27fd9adebab32041f755214dbc6bffa90cc0225b39da2e5c2d3b90600090a250565b6060614a868383604051806060016040528060278152602001615f8f60279139614c99565b9392505050565b6000808251604103614ac35760208301516040840151606085015160001a614ab787828585614d07565b94509450505050614acb565b506000905060025b9250929050565b6000806000856001600160a01b0316631626ba7e60e01b8686604051602401614afc929190615e06565b60408051601f198184030181529181526020820180516001600160e01b03166001600160e01b0319909416939093179092529051614b3a9190615f52565b600060405180830381855afa9150503d8060008114614b75576040519150601f19603f3d011682016040523d82523d6000602084013e614b7a565b606091505b5091509150818015614b8e57506020815110155b80156148c657508051630b135d3f60e11b90614bb39083016020908101908401615ae9565b149695505050505050565b606082471015614c1f5760405162461bcd60e51b815260206004820152602660248201527f416464726573733a20696e73756666696369656e742062616c616e636520666f6044820152651c8818d85b1b60d21b6064820152608401610a5e565b600080866001600160a01b03168587604051614c3b9190615f52565b60006040518083038185875af1925050503d8060008114614c78576040519150601f19603f3d011682016040523d82523d6000602084013e614c7d565b606091505b5091509150614c8e87838387614dcb565b979650505050505050565b6060600080856001600160a01b031685604051614cb69190615f52565b600060405180830381855af49150503d8060008114614cf1576040519150601f19603f3d011682016040523d82523d6000602084013e614cf6565b606091505b50915091506148c686838387614dcb565b6000807f7fffffffffffffffffffffffffffffff5d576e7357a4501ddfe92f46681b20a0831115614d3e5750600090506003614dc2565b6040805160008082526020820180845289905260ff881692820192909252606081018690526080810185905260019060a0016020604051602081039080840390855afa158015614d92573d6000803e3d6000fd5b5050604051601f1901519150506001600160a01b038116614dbb57600060019250925050614dc2565b9150600090505b94509492505050565b60608315614e3a578251600003614e33576001600160a01b0385163b614e335760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e74726163740000006044820152606401610a5e565b5081613454565b6134548383815115614e4f5781518083602001fd5b8060405162461bcd60e51b8152600401610a5e9190614eb9565b60005b83811015614e84578181015183820152602001614e6c565b50506000910152565b60008151808452614ea5816020860160208601614e69565b601f01601f19169290920160200192915050565b602081526000614a866020830184614e8d565b6001600160a01b038116811461145557600080fd5b8035614eec81614ecc565b919050565b60008060408385031215614f0457600080fd5b8235614f0f81614ecc565b946020939093013593505050565b600080600060608486031215614f3257600080fd5b8335614f3d81614ecc565b92506020840135614f4d81614ecc565b929592945050506040919091013590565b600060208284031215614f7057600080fd5b8135614a8681614ecc565b634e487b7160e01b600052604160045260246000fd5b604051601f8201601f191681016001600160401b0381118282101715614fb957614fb9614f7b565b604052919050565b60008060408385031215614fd457600080fd5b8235614fdf81614ecc565b915060208301356001600160401b03811115614ffa57600080fd5b8301601f8101851361500b57600080fd5b80356001600160401b0381111561502457615024614f7b565b615037601f8201601f1916602001614f91565b81815286602083850101111561504c57600080fd5b816020840160208301376000602083830101528093505050509250929050565b60006040828403121561416957600080fd5b60006040828403121561509057600080fd5b614a86838361506c565b6001600160c01b038116811461145557600080fd5b6000602082840312156150c157600080fd5b8135614a868161509a565b60006001600160401b038211156150e5576150e5614f7b565b5060051b60200190565b600082601f83011261510057600080fd5b813561511361510e826150cc565b614f91565b8082825260208201915060208360051b86010192508583111561513557600080fd5b602085015b838110156144fa57803565ffffffffffff8116811461515857600080fd5b83526020928301920161513a565b600082601f83011261517757600080fd5b813561518561510e826150cc565b8082825260208201915060208360051b8601019250858311156151a757600080fd5b602085015b838110156144fa5780356151bf8161509a565b8352602092830192016151ac565b600082601f8301126151de57600080fd5b81356151ec61510e826150cc565b8082825260208201915060208360051b86010192508583111561520e57600080fd5b602085015b838110156144fa57803561522681614ecc565b835260209283019201615213565b600082601f83011261524557600080fd5b813561525361510e826150cc565b8082825260208201915060208360051b86010192508583111561527557600080fd5b602085015b838110156144fa57803583526020928301920161527a565b60008060008060008060c087890312156152ab57600080fd5b6152b487614ee1565b95506020870135945060408701356001600160401b038111156152d657600080fd5b6152e289828a016150ef565b94505060608701356001600160401b038111156152fe57600080fd5b61530a89828a01615166565b93505060808701356001600160401b0381111561532657600080fd5b61533289828a016151cd565b92505060a08701356001600160401b0381111561534e57600080fd5b61535a89828a01615234565b9150509295509295509295565b60ff60f81b8816815260e06020820152600061538660e0830189614e8d565b82810360408401526153988189614e8d565b606084018890526001600160a01b038716608085015260a0840186905283810360c08501528451808252602080870193509091019060005b818110156153ee5783518352602093840193909201916001016153d0565b50909b9a5050505050505050505050565b60006020828403121561541157600080fd5b5035919050565b60008083601f84011261542a57600080fd5b5081356001600160401b0381111561544157600080fd5b602083019150836020828501011115614acb57600080fd5b6000806020838503121561546c57600080fd5b82356001600160401b0381111561548257600080fd5b61548e85828601615418565b90969095509350505050565b600080608083850312156154ad57600080fd5b6154b7848461506c565b91506154c6846040850161506c565b90509250929050565b600080600080600080600060e0888a0312156154ea57600080fd5b87356154f581614ecc565b9650602088013561550581614ecc565b95506040880135945060608801359350608088013560ff8116811461552957600080fd5b9699959850939692959460a0840135945060c09093013592915050565b6000806040838503121561555957600080fd5b823561556481614ecc565b9150602083013561557481614ecc565b809150509250929050565b60008060008060008060008060006101008a8c03121561559e57600080fd5b89356155a981614ecc565b985060208a01356001600160401b038111156155c457600080fd5b6155d08c828d01615418565b90995097505060408a01356001600160401b038111156155ef57600080fd5b6155fb8c828d01615418565b90975095505060608a01356001600160401b0381111561561a57600080fd5b6156268c828d01615418565b909550935061563a90508b60808c0161506c565b91506156498b60c08c0161506c565b90509295985092959850929598565b600181811c9082168061566c57607f821691505b60208210810361416957634e487b7160e01b600052602260045260246000fd5b60006020828403121561569e57600080fd5b81518015158114614a8657600080fd5b634e487b7160e01b600052601160045260246000fd5b6000600160ff1b82016156d9576156d96156ae565b5060000390565b634e487b7160e01b600052602160045260246000fd5b6001600160c01b03841681528215156020820152606081016003831061572c57634e487b7160e01b600052602160045260246000fd5b826040830152949350505050565b600082601f83011261574b57600080fd5b815161575961510e826150cc565b8082825260208201915060208360051b86010192508583111561577b57600080fd5b602085015b838110156144fa578051835260209283019201615780565b600080604083850312156157ab57600080fd5b82516001600160401b038111156157c157600080fd5b8301601f810185136157d257600080fd5b80516157e061510e826150cc565b8082825260208201915060208360051b85010192508783111561580257600080fd5b6020840193505b8284101561582d57835161581c81614ecc565b825260209384019390910190615809565b8095505050505060208301516001600160401b0381111561584d57600080fd5b6158598582860161573a565b9150509250929050565b634e487b7160e01b600052603260045260246000fd5b6020808252602c908201527f46756e6374696f6e206d7573742062652063616c6c6564207468726f7567682060408201526b19195b1959d85d1958d85b1b60a21b606082015260800190565b6020808252602c908201527f46756e6374696f6e206d7573742062652063616c6c6564207468726f7567682060408201526b6163746976652070726f787960a01b606082015260800190565b80820180821115610998576109986156ae565b805160208083015191908110156141695760001960209190910360031b1b16919050565b6020808252600f908201526e676f7665726e616e6365206f6e6c7960881b604082015260600190565b6000604082840312801561598457600080fd5b50604080519081016001600160401b03811182821017156159a7576159a7614f7b565b6040528235815260208301356159bc8161509a565b60208201529392505050565b6020808252601390820152723737ba103130b1b5b4b7339036b0b730b3b2b960691b604082015260600190565b8082028115828204841417610998576109986156ae565b634e487b7160e01b600052601260045260246000fd5b600082615a3157615a31615a0c565b500490565b81810381811115610998576109986156ae565b6060808252845190820181905260009060208601906080840190835b81811015615a8b57835165ffffffffffff16835260209384019390920191600101615a65565b50508381036020808601919091528651808352918101925086019060005b81811015615ad05782516001600160c01b0316845260209384019390920191600101615aa9565b5050506001600160c01b03841660408401529050613454565b600060208284031215615afb57600080fd5b5051919050565b6000808354615b1081615658565b600182168015615b275760018114615b3c57615b6c565b60ff1983168652811515820286019350615b6c565b86600052602060002060005b83811015615b6457815488820152600190910190602001615b48565b505081860193505b509195945050505050565b60208152816020820152818360408301376000818301604090810191909152601f909201601f19160101919050565b601f82111561268c57806000526020600020601f840160051c81016020851015615bcd5750805b601f840160051c820191505b81811015612a505760008155600101615bd9565b6001600160401b03831115615c0457615c04614f7b565b615c1883615c128354615658565b83615ba6565b6000601f841160018114615c4c5760008515615c345750838201355b600019600387901b1c1916600186901b178355612a50565b600083815260209020601f19861690835b82811015615c7d5786850135825560209485019460019092019101615c5d565b5086821015615c9a5760001960f88860031b161c19848701351681555b505060018560011b0183555050505050565b600060208284031215615cbe57600080fd5b8151614a8681614ecc565b6001600160c01b038181168382160190811115610998576109986156ae565b6001600160c01b038281168282160390811115610998576109986156ae565b8254815260018301546001600160c01b0316602080830191909152823560408301526080820190830135615d3a8161509a565b6001600160c01b03166060929092019190915292915050565b81358155600181016020830135615d698161509a565b81546001600160c01b0319166001600160c01b03919091161790555050565b6001600160c01b03818116838216818102909216918183048114821517615db157615db16156ae565b505092915050565b60006001600160c01b03831680615dd257615dd2615a0c565b6001600160c01b03929092169190910492915050565b65ffffffffffff8281168282160390811115610998576109986156ae565b8281526040602082015260006134546040830184614e8d565b600060208284031215615e3157600080fd5b81516001600160e01b031981168114614a8657600080fd5b6020808252602b908201527f496e697469616c697a61626c653a20636f6e7472616374206973206e6f74206960408201526a6e697469616c697a696e6760a81b606082015260800190565b81516001600160401b03811115615ead57615ead614f7b565b615ec181615ebb8454615658565b84615ba6565b6020601f821160018114615ef55760008315615edd5750848201515b600019600385901b1c1916600184901b178455612a50565b600084815260208120601f198516915b82811015615f255787850151825560209485019460019092019101615f05565b5084821015615f435786840151600019600387901b60f8161c191681555b50505050600190811b01905550565b60008251615f64818460208701614e69565b919091019291505056fe360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc416464726573733a206c6f772d6c6576656c2064656c65676174652063616c6c206661696c6564a264697066735822122064e4a5f34bfc73f3e4daa932bed73959af1525e625df50fe736e51370d9c67f564736f6c634300081c0033","name":"RTokenP1","is_blueprint":false,"license_type":"none","is_fully_verified":true,"is_verified_via_eth_bytecode_db":true,"language":"solidity","evm_version":"paris","can_be_visualized_via_sol2uml":true,"is_verified_via_sourcify":false,"additional_sources":[{"file_path":"@openzeppelin/contracts/utils/structs/EnumerableSet.sol","source_code":"// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.9.0) (utils/structs/EnumerableSet.sol)\n// This file was procedurally generated from scripts/generate/templates/EnumerableSet.js.\n\npragma solidity ^0.8.0;\n\n/**\n * @dev Library for managing\n * https://en.wikipedia.org/wiki/Set_(abstract_data_type)[sets] of primitive\n * types.\n *\n * Sets have the following properties:\n *\n * - Elements are added, removed, and checked for existence in constant time\n * (O(1)).\n * - Elements are enumerated in O(n). No guarantees are made on the ordering.\n *\n * ```solidity\n * contract Example {\n *     // Add the library methods\n *     using EnumerableSet for EnumerableSet.AddressSet;\n *\n *     // Declare a set state variable\n *     EnumerableSet.AddressSet private mySet;\n * }\n * ```\n *\n * As of v3.3.0, sets of type `bytes32` (`Bytes32Set`), `address` (`AddressSet`)\n * and `uint256` (`UintSet`) are supported.\n *\n * [WARNING]\n * ====\n * Trying to delete such a structure from storage will likely result in data corruption, rendering the structure\n * unusable.\n * See https://github.com/ethereum/solidity/pull/11843[ethereum/solidity#11843] for more info.\n *\n * In order to clean an EnumerableSet, you can either remove all elements one by one or create a fresh instance using an\n * array of EnumerableSet.\n * ====\n */\nlibrary EnumerableSet {\n    // To implement this library for multiple types with as little code\n    // repetition as possible, we write it in terms of a generic Set type with\n    // bytes32 values.\n    // The Set implementation uses private functions, and user-facing\n    // implementations (such as AddressSet) are just wrappers around the\n    // underlying Set.\n    // This means that we can only create new EnumerableSets for types that fit\n    // in bytes32.\n\n    struct Set {\n        // Storage of set values\n        bytes32[] _values;\n        // Position of the value in the `values` array, plus 1 because index 0\n        // means a value is not in the set.\n        mapping(bytes32 => uint256) _indexes;\n    }\n\n    /**\n     * @dev Add a value to a set. O(1).\n     *\n     * Returns true if the value was added to the set, that is if it was not\n     * already present.\n     */\n    function _add(Set storage set, bytes32 value) private returns (bool) {\n        if (!_contains(set, value)) {\n            set._values.push(value);\n            // The value is stored at length-1, but we add 1 to all indexes\n            // and use 0 as a sentinel value\n            set._indexes[value] = set._values.length;\n            return true;\n        } else {\n            return false;\n        }\n    }\n\n    /**\n     * @dev Removes a value from a set. O(1).\n     *\n     * Returns true if the value was removed from the set, that is if it was\n     * present.\n     */\n    function _remove(Set storage set, bytes32 value) private returns (bool) {\n        // We read and store the value's index to prevent multiple reads from the same storage slot\n        uint256 valueIndex = set._indexes[value];\n\n        if (valueIndex != 0) {\n            // Equivalent to contains(set, value)\n            // To delete an element from the _values array in O(1), we swap the element to delete with the last one in\n            // the array, and then remove the last element (sometimes called as 'swap and pop').\n            // This modifies the order of the array, as noted in {at}.\n\n            uint256 toDeleteIndex = valueIndex - 1;\n            uint256 lastIndex = set._values.length - 1;\n\n            if (lastIndex != toDeleteIndex) {\n                bytes32 lastValue = set._values[lastIndex];\n\n                // Move the last value to the index where the value to delete is\n                set._values[toDeleteIndex] = lastValue;\n                // Update the index for the moved value\n                set._indexes[lastValue] = valueIndex; // Replace lastValue's index to valueIndex\n            }\n\n            // Delete the slot where the moved value was stored\n            set._values.pop();\n\n            // Delete the index for the deleted slot\n            delete set._indexes[value];\n\n            return true;\n        } else {\n            return false;\n        }\n    }\n\n    /**\n     * @dev Returns true if the value is in the set. O(1).\n     */\n    function _contains(Set storage set, bytes32 value) private view returns (bool) {\n        return set._indexes[value] != 0;\n    }\n\n    /**\n     * @dev Returns the number of values on the set. O(1).\n     */\n    function _length(Set storage set) private view returns (uint256) {\n        return set._values.length;\n    }\n\n    /**\n     * @dev Returns the value stored at position `index` in the set. O(1).\n     *\n     * Note that there are no guarantees on the ordering of values inside the\n     * array, and it may change when more values are added or removed.\n     *\n     * Requirements:\n     *\n     * - `index` must be strictly less than {length}.\n     */\n    function _at(Set storage set, uint256 index) private view returns (bytes32) {\n        return set._values[index];\n    }\n\n    /**\n     * @dev Return the entire set in an array\n     *\n     * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed\n     * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that\n     * this function has an unbounded cost, and using it as part of a state-changing function may render the function\n     * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.\n     */\n    function _values(Set storage set) private view returns (bytes32[] memory) {\n        return set._values;\n    }\n\n    // Bytes32Set\n\n    struct Bytes32Set {\n        Set _inner;\n    }\n\n    /**\n     * @dev Add a value to a set. O(1).\n     *\n     * Returns true if the value was added to the set, that is if it was not\n     * already present.\n     */\n    function add(Bytes32Set storage set, bytes32 value) internal returns (bool) {\n        return _add(set._inner, value);\n    }\n\n    /**\n     * @dev Removes a value from a set. O(1).\n     *\n     * Returns true if the value was removed from the set, that is if it was\n     * present.\n     */\n    function remove(Bytes32Set storage set, bytes32 value) internal returns (bool) {\n        return _remove(set._inner, value);\n    }\n\n    /**\n     * @dev Returns true if the value is in the set. O(1).\n     */\n    function contains(Bytes32Set storage set, bytes32 value) internal view returns (bool) {\n        return _contains(set._inner, value);\n    }\n\n    /**\n     * @dev Returns the number of values in the set. O(1).\n     */\n    function length(Bytes32Set storage set) internal view returns (uint256) {\n        return _length(set._inner);\n    }\n\n    /**\n     * @dev Returns the value stored at position `index` in the set. O(1).\n     *\n     * Note that there are no guarantees on the ordering of values inside the\n     * array, and it may change when more values are added or removed.\n     *\n     * Requirements:\n     *\n     * - `index` must be strictly less than {length}.\n     */\n    function at(Bytes32Set storage set, uint256 index) internal view returns (bytes32) {\n        return _at(set._inner, index);\n    }\n\n    /**\n     * @dev Return the entire set in an array\n     *\n     * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed\n     * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that\n     * this function has an unbounded cost, and using it as part of a state-changing function may render the function\n     * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.\n     */\n    function values(Bytes32Set storage set) internal view returns (bytes32[] memory) {\n        bytes32[] memory store = _values(set._inner);\n        bytes32[] memory result;\n\n        /// @solidity memory-safe-assembly\n        assembly {\n            result := store\n        }\n\n        return result;\n    }\n\n    // AddressSet\n\n    struct AddressSet {\n        Set _inner;\n    }\n\n    /**\n     * @dev Add a value to a set. O(1).\n     *\n     * Returns true if the value was added to the set, that is if it was not\n     * already present.\n     */\n    function add(AddressSet storage set, address value) internal returns (bool) {\n        return _add(set._inner, bytes32(uint256(uint160(value))));\n    }\n\n    /**\n     * @dev Removes a value from a set. O(1).\n     *\n     * Returns true if the value was removed from the set, that is if it was\n     * present.\n     */\n    function remove(AddressSet storage set, address value) internal returns (bool) {\n        return _remove(set._inner, bytes32(uint256(uint160(value))));\n    }\n\n    /**\n     * @dev Returns true if the value is in the set. O(1).\n     */\n    function contains(AddressSet storage set, address value) internal view returns (bool) {\n        return _contains(set._inner, bytes32(uint256(uint160(value))));\n    }\n\n    /**\n     * @dev Returns the number of values in the set. O(1).\n     */\n    function length(AddressSet storage set) internal view returns (uint256) {\n        return _length(set._inner);\n    }\n\n    /**\n     * @dev Returns the value stored at position `index` in the set. O(1).\n     *\n     * Note that there are no guarantees on the ordering of values inside the\n     * array, and it may change when more values are added or removed.\n     *\n     * Requirements:\n     *\n     * - `index` must be strictly less than {length}.\n     */\n    function at(AddressSet storage set, uint256 index) internal view returns (address) {\n        return address(uint160(uint256(_at(set._inner, index))));\n    }\n\n    /**\n     * @dev Return the entire set in an array\n     *\n     * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed\n     * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that\n     * this function has an unbounded cost, and using it as part of a state-changing function may render the function\n     * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.\n     */\n    function values(AddressSet storage set) internal view returns (address[] memory) {\n        bytes32[] memory store = _values(set._inner);\n        address[] memory result;\n\n        /// @solidity memory-safe-assembly\n        assembly {\n            result := store\n        }\n\n        return result;\n    }\n\n    // UintSet\n\n    struct UintSet {\n        Set _inner;\n    }\n\n    /**\n     * @dev Add a value to a set. O(1).\n     *\n     * Returns true if the value was added to the set, that is if it was not\n     * already present.\n     */\n    function add(UintSet storage set, uint256 value) internal returns (bool) {\n        return _add(set._inner, bytes32(value));\n    }\n\n    /**\n     * @dev Removes a value from a set. O(1).\n     *\n     * Returns true if the value was removed from the set, that is if it was\n     * present.\n     */\n    function remove(UintSet storage set, uint256 value) internal returns (bool) {\n        return _remove(set._inner, bytes32(value));\n    }\n\n    /**\n     * @dev Returns true if the value is in the set. O(1).\n     */\n    function contains(UintSet storage set, uint256 value) internal view returns (bool) {\n        return _contains(set._inner, bytes32(value));\n    }\n\n    /**\n     * @dev Returns the number of values in the set. O(1).\n     */\n    function length(UintSet storage set) internal view returns (uint256) {\n        return _length(set._inner);\n    }\n\n    /**\n     * @dev Returns the value stored at position `index` in the set. O(1).\n     *\n     * Note that there are no guarantees on the ordering of values inside the\n     * array, and it may change when more values are added or removed.\n     *\n     * Requirements:\n     *\n     * - `index` must be strictly less than {length}.\n     */\n    function at(UintSet storage set, uint256 index) internal view returns (uint256) {\n        return uint256(_at(set._inner, index));\n    }\n\n    /**\n     * @dev Return the entire set in an array\n     *\n     * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed\n     * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that\n     * this function has an unbounded cost, and using it as part of a state-changing function may render the function\n     * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.\n     */\n    function values(UintSet storage set) internal view returns (uint256[] memory) {\n        bytes32[] memory store = _values(set._inner);\n        uint256[] memory result;\n\n        /// @solidity memory-safe-assembly\n        assembly {\n            result := store\n        }\n\n        return result;\n    }\n}\n"},{"file_path":"@openzeppelin/contracts-upgradeable/token/ERC20/IERC20Upgradeable.sol","source_code":"// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.9.0) (token/ERC20/IERC20.sol)\n\npragma solidity ^0.8.0;\n\n/**\n * @dev Interface of the ERC20 standard as defined in the EIP.\n */\ninterface IERC20Upgradeable {\n    /**\n     * @dev Emitted when `value` tokens are moved from one account (`from`) to\n     * another (`to`).\n     *\n     * Note that `value` may be zero.\n     */\n    event Transfer(address indexed from, address indexed to, uint256 value);\n\n    /**\n     * @dev Emitted when the allowance of a `spender` for an `owner` is set by\n     * a call to {approve}. `value` is the new allowance.\n     */\n    event Approval(address indexed owner, address indexed spender, uint256 value);\n\n    /**\n     * @dev Returns the amount of tokens in existence.\n     */\n    function totalSupply() external view returns (uint256);\n\n    /**\n     * @dev Returns the amount of tokens owned by `account`.\n     */\n    function balanceOf(address account) external view returns (uint256);\n\n    /**\n     * @dev Moves `amount` tokens from the caller's account to `to`.\n     *\n     * Returns a boolean value indicating whether the operation succeeded.\n     *\n     * Emits a {Transfer} event.\n     */\n    function transfer(address to, uint256 amount) external returns (bool);\n\n    /**\n     * @dev Returns the remaining number of tokens that `spender` will be\n     * allowed to spend on behalf of `owner` through {transferFrom}. This is\n     * zero by default.\n     *\n     * This value changes when {approve} or {transferFrom} are called.\n     */\n    function allowance(address owner, address spender) external view returns (uint256);\n\n    /**\n     * @dev Sets `amount` as the allowance of `spender` over the caller's tokens.\n     *\n     * Returns a boolean value indicating whether the operation succeeded.\n     *\n     * IMPORTANT: Beware that changing an allowance with this method brings the risk\n     * that someone may use both the old and the new allowance by unfortunate\n     * transaction ordering. One possible solution to mitigate this race\n     * condition is to first reduce the spender's allowance to 0 and set the\n     * desired value afterwards:\n     * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729\n     *\n     * Emits an {Approval} event.\n     */\n    function approve(address spender, uint256 amount) external returns (bool);\n\n    /**\n     * @dev Moves `amount` tokens from `from` to `to` using the\n     * allowance mechanism. `amount` is then deducted from the caller's\n     * allowance.\n     *\n     * Returns a boolean value indicating whether the operation succeeded.\n     *\n     * Emits a {Transfer} event.\n     */\n    function transferFrom(address from, address to, uint256 amount) external returns (bool);\n}\n"},{"file_path":"@openzeppelin/contracts-upgradeable/interfaces/IERC1967Upgradeable.sol","source_code":"// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.9.0) (interfaces/IERC1967.sol)\n\npragma solidity ^0.8.0;\n\n/**\n * @dev ERC-1967: Proxy Storage Slots. This interface contains the events defined in the ERC.\n *\n * _Available since v4.8.3._\n */\ninterface IERC1967Upgradeable {\n    /**\n     * @dev Emitted when the implementation is upgraded.\n     */\n    event Upgraded(address indexed implementation);\n\n    /**\n     * @dev Emitted when the admin account has changed.\n     */\n    event AdminChanged(address previousAdmin, address newAdmin);\n\n    /**\n     * @dev Emitted when the beacon is changed.\n     */\n    event BeaconUpgraded(address indexed beacon);\n}\n"},{"file_path":"@openzeppelin/contracts-upgradeable/utils/cryptography/EIP712Upgradeable.sol","source_code":"// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.9.0) (utils/cryptography/EIP712.sol)\n\npragma solidity ^0.8.8;\n\nimport \"./ECDSAUpgradeable.sol\";\nimport \"../../interfaces/IERC5267Upgradeable.sol\";\nimport {Initializable} from \"../../proxy/utils/Initializable.sol\";\n\n/**\n * @dev https://eips.ethereum.org/EIPS/eip-712[EIP 712] is a standard for hashing and signing of typed structured data.\n *\n * The encoding specified in the EIP is very generic, and such a generic implementation in Solidity is not feasible,\n * thus this contract does not implement the encoding itself. Protocols need to implement the type-specific encoding\n * they need in their contracts using a combination of `abi.encode` and `keccak256`.\n *\n * This contract implements the EIP 712 domain separator ({_domainSeparatorV4}) that is used as part of the encoding\n * scheme, and the final step of the encoding to obtain the message digest that is then signed via ECDSA\n * ({_hashTypedDataV4}).\n *\n * The implementation of the domain separator was designed to be as efficient as possible while still properly updating\n * the chain id to protect against replay attacks on an eventual fork of the chain.\n *\n * NOTE: This contract implements the version of the encoding known as \"v4\", as implemented by the JSON RPC method\n * https://docs.metamask.io/guide/signing-data.html[`eth_signTypedDataV4` in MetaMask].\n *\n * NOTE: In the upgradeable version of this contract, the cached values will correspond to the address, and the domain\n * separator of the implementation contract. This will cause the `_domainSeparatorV4` function to always rebuild the\n * separator from the immutable values, which is cheaper than accessing a cached version in cold storage.\n *\n * _Available since v3.4._\n *\n * @custom:storage-size 52\n */\nabstract contract EIP712Upgradeable is Initializable, IERC5267Upgradeable {\n    bytes32 private constant _TYPE_HASH =\n        keccak256(\"EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)\");\n\n    /// @custom:oz-renamed-from _HASHED_NAME\n    bytes32 private _hashedName;\n    /// @custom:oz-renamed-from _HASHED_VERSION\n    bytes32 private _hashedVersion;\n\n    string private _name;\n    string private _version;\n\n    /**\n     * @dev Initializes the domain separator and parameter caches.\n     *\n     * The meaning of `name` and `version` is specified in\n     * https://eips.ethereum.org/EIPS/eip-712#definition-of-domainseparator[EIP 712]:\n     *\n     * - `name`: the user readable name of the signing domain, i.e. the name of the DApp or the protocol.\n     * - `version`: the current major version of the signing domain.\n     *\n     * NOTE: These parameters cannot be changed except through a xref:learn::upgrading-smart-contracts.adoc[smart\n     * contract upgrade].\n     */\n    function __EIP712_init(string memory name, string memory version) internal onlyInitializing {\n        __EIP712_init_unchained(name, version);\n    }\n\n    function __EIP712_init_unchained(string memory name, string memory version) internal onlyInitializing {\n        _name = name;\n        _version = version;\n\n        // Reset prior values in storage if upgrading\n        _hashedName = 0;\n        _hashedVersion = 0;\n    }\n\n    /**\n     * @dev Returns the domain separator for the current chain.\n     */\n    function _domainSeparatorV4() internal view returns (bytes32) {\n        return _buildDomainSeparator();\n    }\n\n    function _buildDomainSeparator() private view returns (bytes32) {\n        return keccak256(abi.encode(_TYPE_HASH, _EIP712NameHash(), _EIP712VersionHash(), block.chainid, address(this)));\n    }\n\n    /**\n     * @dev Given an already https://eips.ethereum.org/EIPS/eip-712#definition-of-hashstruct[hashed struct], this\n     * function returns the hash of the fully encoded EIP712 message for this domain.\n     *\n     * This hash can be used together with {ECDSA-recover} to obtain the signer of a message. For example:\n     *\n     * ```solidity\n     * bytes32 digest = _hashTypedDataV4(keccak256(abi.encode(\n     *     keccak256(\"Mail(address to,string contents)\"),\n     *     mailTo,\n     *     keccak256(bytes(mailContents))\n     * )));\n     * address signer = ECDSA.recover(digest, signature);\n     * ```\n     */\n    function _hashTypedDataV4(bytes32 structHash) internal view virtual returns (bytes32) {\n        return ECDSAUpgradeable.toTypedDataHash(_domainSeparatorV4(), structHash);\n    }\n\n    /**\n     * @dev See {EIP-5267}.\n     *\n     * _Available since v4.9._\n     */\n    function eip712Domain()\n        public\n        view\n        virtual\n        override\n        returns (\n            bytes1 fields,\n            string memory name,\n            string memory version,\n            uint256 chainId,\n            address verifyingContract,\n            bytes32 salt,\n            uint256[] memory extensions\n        )\n    {\n        // If the hashed name and version in storage are non-zero, the contract hasn't been properly initialized\n        // and the EIP712 domain is not reliable, as it will be missing name and version.\n        require(_hashedName == 0 && _hashedVersion == 0, \"EIP712: Uninitialized\");\n\n        return (\n            hex\"0f\", // 01111\n            _EIP712Name(),\n            _EIP712Version(),\n            block.chainid,\n            address(this),\n            bytes32(0),\n            new uint256[](0)\n        );\n    }\n\n    /**\n     * @dev The name parameter for the EIP712 domain.\n     *\n     * NOTE: This function reads from storage by default, but can be redefined to return a constant value if gas costs\n     * are a concern.\n     */\n    function _EIP712Name() internal virtual view returns (string memory) {\n        return _name;\n    }\n\n    /**\n     * @dev The version parameter for the EIP712 domain.\n     *\n     * NOTE: This function reads from storage by default, but can be redefined to return a constant value if gas costs\n     * are a concern.\n     */\n    function _EIP712Version() internal virtual view returns (string memory) {\n        return _version;\n    }\n\n    /**\n     * @dev The hash of the name parameter for the EIP712 domain.\n     *\n     * NOTE: In previous versions this function was virtual. In this version you should override `_EIP712Name` instead.\n     */\n    function _EIP712NameHash() internal view returns (bytes32) {\n        string memory name = _EIP712Name();\n        if (bytes(name).length > 0) {\n            return keccak256(bytes(name));\n        } else {\n            // If the name is empty, the contract may have been upgraded without initializing the new storage.\n            // We return the name hash in storage if non-zero, otherwise we assume the name is empty by design.\n            bytes32 hashedName = _hashedName;\n            if (hashedName != 0) {\n                return hashedName;\n            } else {\n                return keccak256(\"\");\n            }\n        }\n    }\n\n    /**\n     * @dev The hash of the version parameter for the EIP712 domain.\n     *\n     * NOTE: In previous versions this function was virtual. In this version you should override `_EIP712Version` instead.\n     */\n    function _EIP712VersionHash() internal view returns (bytes32) {\n        string memory version = _EIP712Version();\n        if (bytes(version).length > 0) {\n            return keccak256(bytes(version));\n        } else {\n            // If the version is empty, the contract may have been upgraded without initializing the new storage.\n            // We return the version hash in storage if non-zero, otherwise we assume the version is empty by design.\n            bytes32 hashedVersion = _hashedVersion;\n            if (hashedVersion != 0) {\n                return hashedVersion;\n            } else {\n                return keccak256(\"\");\n            }\n        }\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"},{"file_path":"@openzeppelin/contracts-upgradeable/utils/StorageSlotUpgradeable.sol","source_code":"// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.9.0) (utils/StorageSlot.sol)\n// This file was procedurally generated from scripts/generate/templates/StorageSlot.js.\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 * ```solidity\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`, `uint256`._\n * _Available since v4.9 for `string`, `bytes`._\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    struct StringSlot {\n        string value;\n    }\n\n    struct BytesSlot {\n        bytes 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    /**\n     * @dev Returns an `StringSlot` with member `value` located at `slot`.\n     */\n    function getStringSlot(bytes32 slot) internal pure returns (StringSlot storage r) {\n        /// @solidity memory-safe-assembly\n        assembly {\n            r.slot := slot\n        }\n    }\n\n    /**\n     * @dev Returns an `StringSlot` representation of the string storage pointer `store`.\n     */\n    function getStringSlot(string storage store) internal pure returns (StringSlot storage r) {\n        /// @solidity memory-safe-assembly\n        assembly {\n            r.slot := store.slot\n        }\n    }\n\n    /**\n     * @dev Returns an `BytesSlot` with member `value` located at `slot`.\n     */\n    function getBytesSlot(bytes32 slot) internal pure returns (BytesSlot storage r) {\n        /// @solidity memory-safe-assembly\n        assembly {\n            r.slot := slot\n        }\n    }\n\n    /**\n     * @dev Returns an `BytesSlot` representation of the bytes storage pointer `store`.\n     */\n    function getBytesSlot(bytes storage store) internal pure returns (BytesSlot storage r) {\n        /// @solidity memory-safe-assembly\n        assembly {\n            r.slot := store.slot\n        }\n    }\n}\n"},{"file_path":"contracts/interfaces/IRewardable.sol","source_code":"// SPDX-License-Identifier: BlueOak-1.0.0\npragma solidity 0.8.28;\n\nimport \"@openzeppelin/contracts/token/ERC20/IERC20.sol\";\n\n/**\n * @title IRewardable\n * @notice A simple interface mixin to support claiming of rewards.\n */\ninterface IRewardable {\n    /// Emitted whenever a reward token balance is claimed\n    /// @param erc20 The ERC20 of the reward token\n    /// @param amount {qTok}\n    event RewardsClaimed(IERC20 indexed erc20, uint256 amount);\n\n    /// Claim rewards earned by holding a balance of the ERC20 token\n    /// Must emit `RewardsClaimed` for each token rewards are claimed for\n    /// @custom:interaction\n    function claimRewards() external;\n}\n\n/**\n * @title IRewardableComponent\n * @notice A simple interface mixin to support claiming of rewards.\n */\ninterface IRewardableComponent is IRewardable {\n    /// Claim rewards for a single ERC20\n    /// Must emit `RewardsClaimed` for each token rewards are claimed for\n    /// @custom:interaction\n    function claimRewardsSingle(IERC20 erc20) external;\n}\n"},{"file_path":"@reserve-protocol/trusted-fillers/contracts/interfaces/ITrustedFillerRegistry.sol","source_code":"// SPDX-License-Identifier: MIT\npragma solidity ^0.8.19;\n\nimport { IBaseTrustedFiller } from \"./IBaseTrustedFiller.sol\";\n\ninterface ITrustedFillerRegistry {\n    error TrustedFillerRegistry__InvalidCaller();\n    error TrustedFillerRegistry__InvalidRoleRegistry();\n    error TrustedFillerRegistry__InvalidFiller();\n\n    event TrustedFillerCreated(address creator, IBaseTrustedFiller filler);\n    event TrustedFillerAdded(IBaseTrustedFiller filler);\n    event TrustedFillerDeprecated(IBaseTrustedFiller filler);\n\n    function addTrustedFiller(IBaseTrustedFiller _filler) external;\n\n    function deprecateTrustedFiller(IBaseTrustedFiller _filler) external;\n\n    function createTrustedFiller(\n        address senderSource,\n        address trustedFiller,\n        bytes32 deploymentSalt\n    ) external returns (IBaseTrustedFiller trustedFillerInstance);\n\n    function isAllowed(address _filler) external view returns (bool);\n}\n"},{"file_path":"contracts/interfaces/IRToken.sol","source_code":"// SPDX-License-Identifier: BlueOak-1.0.0\npragma solidity 0.8.28;\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 \"@openzeppelin/contracts/token/ERC20/IERC20.sol\";\nimport \"../libraries/Throttle.sol\";\nimport \"./IComponent.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 IComponent, IERC20MetadataUpgradeable, IERC20PermitUpgradeable {\n    /// Emitted when an issuance of RToken occurs, whether it occurs via slow minting or not\n    /// @param issuer The address holding collateral tokens\n    /// @param recipient The address of the recipient of the RTokens\n    /// @param amount The quantity of RToken being issued\n    /// @param baskets The corresponding number of baskets\n    event Issuance(\n        address indexed issuer,\n        address indexed recipient,\n        uint256 amount,\n        uint192 baskets\n    );\n\n    /// Emitted when a redemption of RToken occurs\n    /// @param redeemer The address holding RToken\n    /// @param recipient The address of the account receiving the backing collateral tokens\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(\n        address indexed redeemer,\n        address indexed recipient,\n        uint256 amount,\n        uint192 baskets\n    );\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 issuance SupplyThrottle params are set\n    event IssuanceThrottleSet(ThrottleLib.Params oldVal, ThrottleLib.Params newVal);\n\n    /// Emitted when redemption SupplyThrottle params are set\n    event RedemptionThrottleSet(ThrottleLib.Params oldVal, ThrottleLib.Params newVal);\n\n    /// Emitted when the mandate is set\n    event MandateSet(string indexed oldVal, string newVal);\n\n    // Initialization\n    function init(\n        IMain main_,\n        string memory name_,\n        string memory symbol_,\n        string memory mandate_,\n        ThrottleLib.Params calldata issuanceThrottleParams,\n        ThrottleLib.Params calldata redemptionThrottleParams\n    ) external;\n\n    /// Issue an RToken with basket collateral\n    /// @param amount {qRTok} The quantity of RToken to issue\n    /// @custom:interaction\n    function issue(uint256 amount) external;\n\n    /// Issue an RToken with basket collateral, to a particular recipient\n    /// @param recipient The address to receive the issued RTokens\n    /// @param amount {qRTok} The quantity of RToken to issue\n    /// @custom:interaction\n    function issueTo(address recipient, uint256 amount) external;\n\n    /// Redeem RToken for basket collateral\n    /// @dev Use redeemCustom for non-current baskets\n    /// @param amount {qRTok} The quantity {qRToken} of RToken to redeem\n    /// @custom:interaction\n    function redeem(uint256 amount) external;\n\n    /// Redeem RToken for basket collateral to a particular recipient\n    /// @dev Use redeemCustom for non-current baskets\n    /// @param recipient The address to receive the backing collateral tokens\n    /// @param amount {qRTok} The quantity {qRToken} of RToken to redeem\n    /// @custom:interaction\n    function redeemTo(address recipient, uint256 amount) external;\n\n    /// Redeem RToken for a linear combination of historical baskets, to a particular recipient\n    /// @dev Allows partial redemptions up to the minAmounts\n    /// @param recipient The address to receive the backing collateral tokens\n    /// @param amount {qRTok} The quantity {qRToken} of RToken to redeem\n    /// @param basketNonces An array of basket nonces to do redemption from\n    /// @param portions {1} An array of Fix quantities that must add up to FIX_ONE\n    /// @param expectedERC20sOut An array of ERC20s expected out\n    /// @param minAmounts {qTok} The minimum ERC20 quantities the caller should receive\n    /// @custom:interaction\n    function redeemCustom(\n        address recipient,\n        uint256 amount,\n        uint48[] memory basketNonces,\n        uint192[] memory portions,\n        address[] memory expectedERC20sOut,\n        uint256[] memory minAmounts\n    ) external;\n\n    /// Mint an amount of RToken equivalent to baskets BUs, scaling basketsNeeded up\n    /// Callable only by BackingManager\n    /// @param baskets {BU} The number of baskets to mint RToken for\n    /// @custom:protected\n    function mint(uint192 baskets) external;\n\n    /// Melt a quantity of RToken from the caller's account\n    /// @param amount {qRTok} The amount to be melted\n    /// @custom:protected\n    function melt(uint256 amount) external;\n\n    /// Burn an amount of RToken from caller's account and scale basketsNeeded down\n    /// Callable only by BackingManager\n    /// @custom:protected\n    function dissolve(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 issuance that can be performed in the current block\n    function issuanceAvailable() external view returns (uint256);\n\n    /// @return {qRTok} The maximum redemption that can be performed in the current block\n    function redemptionAvailable() external view returns (uint256);\n}\n\ninterface TestIRToken is IRToken {\n    function setIssuanceThrottleParams(ThrottleLib.Params calldata) external;\n\n    function setRedemptionThrottleParams(ThrottleLib.Params calldata) external;\n\n    function setThrottleParams(\n        ThrottleLib.Params calldata issuanceParams,\n        ThrottleLib.Params calldata redemptionParams\n    ) external;\n\n    function setMandate(string calldata mandate) external;\n\n    function mandate() external view returns (string memory);\n\n    function issuanceThrottleParams() external view returns (ThrottleLib.Params memory);\n\n    function redemptionThrottleParams() external view returns (ThrottleLib.Params memory);\n\n    function increaseAllowance(address, uint256) external returns (bool);\n\n    function decreaseAllowance(address, uint256) external returns (bool);\n\n    function monetizeDonations(IERC20) external;\n}\n"},{"file_path":"contracts/interfaces/IMain.sol","source_code":"// SPDX-License-Identifier: BlueOak-1.0.0\npragma solidity 0.8.28;\n\nimport \"@openzeppelin/contracts-upgradeable/access/IAccessControlUpgradeable.sol\";\nimport \"@openzeppelin/contracts/token/ERC20/IERC20.sol\";\nimport \"../registry/AssetPluginRegistry.sol\";\nimport \"../registry/VersionRegistry.sol\";\nimport \"../registry/DAOFeeRegistry.sol\";\nimport \"./IAssetRegistry.sol\";\nimport \"./IBasketHandler.sol\";\nimport \"./IBackingManager.sol\";\nimport \"./IBroker.sol\";\nimport \"./IDistributor.sol\";\nimport \"./IFurnace.sol\";\nimport \"./IGnosis.sol\";\nimport \"./IRToken.sol\";\nimport \"./IRevenueTrader.sol\";\nimport \"./IStRSR.sol\";\nimport \"./ITrading.sol\";\nimport \"./IVersioned.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 oldVal, uint48 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 oldDuration, uint48 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 oldDuration, uint48 newDuration);\n\n    /// Emitted when the system is paused or unpaused for trading\n    /// @param oldVal The old value of `tradingPaused`\n    /// @param newVal The new value of `tradingPaused`\n    event TradingPausedSet(bool oldVal, bool newVal);\n\n    /// Emitted when the system is paused or unpaused for issuance\n    /// @param oldVal The old value of `issuancePaused`\n    /// @param newVal The new value of `issuancePaused`\n    event IssuancePausedSet(bool oldVal, bool newVal);\n\n    /**\n     * Trading Paused: Disable everything except for OWNER actions, RToken.issue, RToken.redeem,\n     * StRSR.stake, and StRSR.payoutRewards\n     * Issuance Paused: Disable RToken.issue\n     * Frozen: Disable everything except for OWNER actions + StRSR.stake (for governance)\n     */\n\n    function tradingPausedOrFrozen() external view returns (bool);\n\n    function issuancePausedOrFrozen() 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 pauseTrading() external;\n\n    function unpauseTrading() external;\n\n    function pauseIssuance() external;\n\n    function unpauseIssuance() 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 oldVal, IStRSR newVal);\n\n    function stRSR() external view returns (IStRSR);\n\n    event AssetRegistrySet(IAssetRegistry oldVal, IAssetRegistry newVal);\n\n    function assetRegistry() external view returns (IAssetRegistry);\n\n    event BasketHandlerSet(IBasketHandler oldVal, IBasketHandler newVal);\n\n    function basketHandler() external view returns (IBasketHandler);\n\n    event BackingManagerSet(IBackingManager oldVal, IBackingManager newVal);\n\n    function backingManager() external view returns (IBackingManager);\n\n    event DistributorSet(IDistributor oldVal, IDistributor newVal);\n\n    function distributor() external view returns (IDistributor);\n\n    event RSRTraderSet(IRevenueTrader oldVal, IRevenueTrader newVal);\n\n    function rsrTrader() external view returns (IRevenueTrader);\n\n    event RTokenTraderSet(IRevenueTrader oldVal, IRevenueTrader newVal);\n\n    function rTokenTrader() external view returns (IRevenueTrader);\n\n    event FurnaceSet(IFurnace oldVal, IFurnace newVal);\n\n    function furnace() external view returns (IFurnace);\n\n    event BrokerSet(IBroker oldVal, IBroker newVal);\n\n    function broker() external view returns (IBroker);\n\n    function isComponent(address addr) external view returns (bool);\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 IVersioned, 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    function assetPluginRegistry() external view returns (AssetPluginRegistry);\n\n    function versionRegistry() external view returns (VersionRegistry);\n\n    function daoFeeRegistry() external view returns (DAOFeeRegistry);\n\n    // === Control flow ===\n\n    function beginTx() external;\n\n    function endTx() external;\n}\n\ninterface TestIMain is IMain {\n    error ReentrancyGuardReentrantCall();\n\n    function setVersionRegistry(VersionRegistry) external;\n\n    function setAssetPluginRegistry(AssetPluginRegistry) external;\n\n    function setDAOFeeRegistry(DAOFeeRegistry) external;\n\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 tradingPaused() external view returns (bool);\n\n    function issuancePaused() external view returns (bool);\n}\n"},{"file_path":"@openzeppelin/contracts-upgradeable/utils/ContextUpgradeable.sol","source_code":"// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.9.4) (utils/Context.sol)\n\npragma solidity ^0.8.0;\nimport {Initializable} from \"../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    function _contextSuffixLength() internal view virtual returns (uint256) {\n        return 0;\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"},{"file_path":"@openzeppelin/contracts-upgradeable/utils/math/MathUpgradeable.sol","source_code":"// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.9.0) (utils/math/Math.sol)\n\npragma solidity ^0.8.0;\n\n/**\n * @dev Standard math utilities missing in the Solidity language.\n */\nlibrary MathUpgradeable {\n    enum Rounding {\n        Down, // Toward negative infinity\n        Up, // Toward infinity\n        Zero // Toward zero\n    }\n\n    /**\n     * @dev Returns the largest of two numbers.\n     */\n    function max(uint256 a, uint256 b) internal pure returns (uint256) {\n        return a > b ? a : b;\n    }\n\n    /**\n     * @dev Returns the smallest of two numbers.\n     */\n    function min(uint256 a, uint256 b) internal pure returns (uint256) {\n        return a < b ? a : b;\n    }\n\n    /**\n     * @dev Returns the average of two numbers. The result is rounded towards\n     * zero.\n     */\n    function average(uint256 a, uint256 b) internal pure returns (uint256) {\n        // (a + b) / 2 can overflow.\n        return (a & b) + (a ^ b) / 2;\n    }\n\n    /**\n     * @dev Returns the ceiling of the division of two numbers.\n     *\n     * This differs from standard division with `/` in that it rounds up instead\n     * of rounding down.\n     */\n    function ceilDiv(uint256 a, uint256 b) internal pure returns (uint256) {\n        // (a + b - 1) / b can overflow on addition, so we distribute.\n        return a == 0 ? 0 : (a - 1) / b + 1;\n    }\n\n    /**\n     * @notice Calculates floor(x * y / denominator) with full precision. Throws if result overflows a uint256 or denominator == 0\n     * @dev Original credit to Remco Bloemen under MIT license (https://xn--2-umb.com/21/muldiv)\n     * with further edits by Uniswap Labs also under MIT license.\n     */\n    function mulDiv(uint256 x, uint256 y, uint256 denominator) internal pure returns (uint256 result) {\n        unchecked {\n            // 512-bit multiply [prod1 prod0] = x * y. Compute the product mod 2^256 and mod 2^256 - 1, then use\n            // use the Chinese Remainder Theorem to reconstruct the 512 bit result. The result is stored in two 256\n            // variables such that product = prod1 * 2^256 + prod0.\n            uint256 prod0; // Least significant 256 bits of the product\n            uint256 prod1; // Most significant 256 bits of the product\n            assembly {\n                let mm := mulmod(x, y, not(0))\n                prod0 := mul(x, y)\n                prod1 := sub(sub(mm, prod0), lt(mm, prod0))\n            }\n\n            // Handle non-overflow cases, 256 by 256 division.\n            if (prod1 == 0) {\n                // Solidity will revert if denominator == 0, unlike the div opcode on its own.\n                // The surrounding unchecked block does not change this fact.\n                // See https://docs.soliditylang.org/en/latest/control-structures.html#checked-or-unchecked-arithmetic.\n                return prod0 / denominator;\n            }\n\n            // Make sure the result is less than 2^256. Also prevents denominator == 0.\n            require(denominator > prod1, \"Math: mulDiv overflow\");\n\n            ///////////////////////////////////////////////\n            // 512 by 256 division.\n            ///////////////////////////////////////////////\n\n            // Make division exact by subtracting the remainder from [prod1 prod0].\n            uint256 remainder;\n            assembly {\n                // Compute remainder using mulmod.\n                remainder := mulmod(x, y, denominator)\n\n                // Subtract 256 bit number from 512 bit number.\n                prod1 := sub(prod1, gt(remainder, prod0))\n                prod0 := sub(prod0, remainder)\n            }\n\n            // Factor powers of two out of denominator and compute largest power of two divisor of denominator. Always >= 1.\n            // See https://cs.stackexchange.com/q/138556/92363.\n\n            // Does not overflow because the denominator cannot be zero at this stage in the function.\n            uint256 twos = denominator & (~denominator + 1);\n            assembly {\n                // Divide denominator by twos.\n                denominator := div(denominator, twos)\n\n                // Divide [prod1 prod0] by twos.\n                prod0 := div(prod0, twos)\n\n                // Flip twos such that it is 2^256 / twos. If twos is zero, then it becomes one.\n                twos := add(div(sub(0, twos), twos), 1)\n            }\n\n            // Shift in bits from prod1 into prod0.\n            prod0 |= prod1 * twos;\n\n            // Invert denominator mod 2^256. Now that denominator is an odd number, it has an inverse modulo 2^256 such\n            // that denominator * inv = 1 mod 2^256. Compute the inverse by starting with a seed that is correct for\n            // four bits. That is, denominator * inv = 1 mod 2^4.\n            uint256 inverse = (3 * denominator) ^ 2;\n\n            // Use the Newton-Raphson iteration to improve the precision. Thanks to Hensel's lifting lemma, this also works\n            // in modular arithmetic, doubling the correct bits in each step.\n            inverse *= 2 - denominator * inverse; // inverse mod 2^8\n            inverse *= 2 - denominator * inverse; // inverse mod 2^16\n            inverse *= 2 - denominator * inverse; // inverse mod 2^32\n            inverse *= 2 - denominator * inverse; // inverse mod 2^64\n            inverse *= 2 - denominator * inverse; // inverse mod 2^128\n            inverse *= 2 - denominator * inverse; // inverse mod 2^256\n\n            // Because the division is now exact we can divide by multiplying with the modular inverse of denominator.\n            // This will give us the correct result modulo 2^256. Since the preconditions guarantee that the outcome is\n            // less than 2^256, this is the final result. We don't need to compute the high bits of the result and prod1\n            // is no longer required.\n            result = prod0 * inverse;\n            return result;\n        }\n    }\n\n    /**\n     * @notice Calculates x * y / denominator with full precision, following the selected rounding direction.\n     */\n    function mulDiv(uint256 x, uint256 y, uint256 denominator, Rounding rounding) internal pure returns (uint256) {\n        uint256 result = mulDiv(x, y, denominator);\n        if (rounding == Rounding.Up && mulmod(x, y, denominator) > 0) {\n            result += 1;\n        }\n        return result;\n    }\n\n    /**\n     * @dev Returns the square root of a number. If the number is not a perfect square, the value is rounded down.\n     *\n     * Inspired by Henry S. Warren, Jr.'s \"Hacker's Delight\" (Chapter 11).\n     */\n    function sqrt(uint256 a) internal pure returns (uint256) {\n        if (a == 0) {\n            return 0;\n        }\n\n        // For our first guess, we get the biggest power of 2 which is smaller than the square root of the target.\n        //\n        // We know that the \"msb\" (most significant bit) of our target number `a` is a power of 2 such that we have\n        // `msb(a) <= a < 2*msb(a)`. This value can be written `msb(a)=2**k` with `k=log2(a)`.\n        //\n        // This can be rewritten `2**log2(a) <= a < 2**(log2(a) + 1)`\n        // → `sqrt(2**k) <= sqrt(a) < sqrt(2**(k+1))`\n        // → `2**(k/2) <= sqrt(a) < 2**((k+1)/2) <= 2**(k/2 + 1)`\n        //\n        // Consequently, `2**(log2(a) / 2)` is a good first approximation of `sqrt(a)` with at least 1 correct bit.\n        uint256 result = 1 << (log2(a) >> 1);\n\n        // At this point `result` is an estimation with one bit of precision. We know the true value is a uint128,\n        // since it is the square root of a uint256. Newton's method converges quadratically (precision doubles at\n        // every iteration). We thus need at most 7 iteration to turn our partial result with one bit of precision\n        // into the expected uint128 result.\n        unchecked {\n            result = (result + a / result) >> 1;\n            result = (result + a / result) >> 1;\n            result = (result + a / result) >> 1;\n            result = (result + a / result) >> 1;\n            result = (result + a / result) >> 1;\n            result = (result + a / result) >> 1;\n            result = (result + a / result) >> 1;\n            return min(result, a / result);\n        }\n    }\n\n    /**\n     * @notice Calculates sqrt(a), following the selected rounding direction.\n     */\n    function sqrt(uint256 a, Rounding rounding) internal pure returns (uint256) {\n        unchecked {\n            uint256 result = sqrt(a);\n            return result + (rounding == Rounding.Up && result * result < a ? 1 : 0);\n        }\n    }\n\n    /**\n     * @dev Return the log in base 2, rounded down, of a positive value.\n     * Returns 0 if given 0.\n     */\n    function log2(uint256 value) internal pure returns (uint256) {\n        uint256 result = 0;\n        unchecked {\n            if (value >> 128 > 0) {\n                value >>= 128;\n                result += 128;\n            }\n            if (value >> 64 > 0) {\n                value >>= 64;\n                result += 64;\n            }\n            if (value >> 32 > 0) {\n                value >>= 32;\n                result += 32;\n            }\n            if (value >> 16 > 0) {\n                value >>= 16;\n                result += 16;\n            }\n            if (value >> 8 > 0) {\n                value >>= 8;\n                result += 8;\n            }\n            if (value >> 4 > 0) {\n                value >>= 4;\n                result += 4;\n            }\n            if (value >> 2 > 0) {\n                value >>= 2;\n                result += 2;\n            }\n            if (value >> 1 > 0) {\n                result += 1;\n            }\n        }\n        return result;\n    }\n\n    /**\n     * @dev Return the log in base 2, following the selected rounding direction, of a positive value.\n     * Returns 0 if given 0.\n     */\n    function log2(uint256 value, Rounding rounding) internal pure returns (uint256) {\n        unchecked {\n            uint256 result = log2(value);\n            return result + (rounding == Rounding.Up && 1 << result < value ? 1 : 0);\n        }\n    }\n\n    /**\n     * @dev Return the log in base 10, rounded down, of a positive value.\n     * Returns 0 if given 0.\n     */\n    function log10(uint256 value) internal pure returns (uint256) {\n        uint256 result = 0;\n        unchecked {\n            if (value >= 10 ** 64) {\n                value /= 10 ** 64;\n                result += 64;\n            }\n            if (value >= 10 ** 32) {\n                value /= 10 ** 32;\n                result += 32;\n            }\n            if (value >= 10 ** 16) {\n                value /= 10 ** 16;\n                result += 16;\n            }\n            if (value >= 10 ** 8) {\n                value /= 10 ** 8;\n                result += 8;\n            }\n            if (value >= 10 ** 4) {\n                value /= 10 ** 4;\n                result += 4;\n            }\n            if (value >= 10 ** 2) {\n                value /= 10 ** 2;\n                result += 2;\n            }\n            if (value >= 10 ** 1) {\n                result += 1;\n            }\n        }\n        return result;\n    }\n\n    /**\n     * @dev Return the log in base 10, following the selected rounding direction, of a positive value.\n     * Returns 0 if given 0.\n     */\n    function log10(uint256 value, Rounding rounding) internal pure returns (uint256) {\n        unchecked {\n            uint256 result = log10(value);\n            return result + (rounding == Rounding.Up && 10 ** result < value ? 1 : 0);\n        }\n    }\n\n    /**\n     * @dev Return the log in base 256, rounded down, of a positive value.\n     * Returns 0 if given 0.\n     *\n     * Adding one to the result gives the number of pairs of hex symbols needed to represent `value` as a hex string.\n     */\n    function log256(uint256 value) internal pure returns (uint256) {\n        uint256 result = 0;\n        unchecked {\n            if (value >> 128 > 0) {\n                value >>= 128;\n                result += 16;\n            }\n            if (value >> 64 > 0) {\n                value >>= 64;\n                result += 8;\n            }\n            if (value >> 32 > 0) {\n                value >>= 32;\n                result += 4;\n            }\n            if (value >> 16 > 0) {\n                value >>= 16;\n                result += 2;\n            }\n            if (value >> 8 > 0) {\n                result += 1;\n            }\n        }\n        return result;\n    }\n\n    /**\n     * @dev Return the log in base 256, following the selected rounding direction, of a positive value.\n     * Returns 0 if given 0.\n     */\n    function log256(uint256 value, Rounding rounding) internal pure returns (uint256) {\n        unchecked {\n            uint256 result = log256(value);\n            return result + (rounding == Rounding.Up && 1 << (result << 3) < value ? 1 : 0);\n        }\n    }\n}\n"},{"file_path":"@openzeppelin/contracts/access/IAccessControl.sol","source_code":"// 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 IAccessControl {\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"},{"file_path":"@openzeppelin/contracts-upgradeable/proxy/ERC1967/ERC1967UpgradeUpgradeable.sol","source_code":"// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.9.0) (proxy/ERC1967/ERC1967Upgrade.sol)\n\npragma solidity ^0.8.2;\n\nimport \"../beacon/IBeaconUpgradeable.sol\";\nimport \"../../interfaces/IERC1967Upgradeable.sol\";\nimport \"../../interfaces/draft-IERC1822Upgradeable.sol\";\nimport \"../../utils/AddressUpgradeable.sol\";\nimport \"../../utils/StorageSlotUpgradeable.sol\";\nimport {Initializable} from \"../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 */\nabstract contract ERC1967UpgradeUpgradeable is Initializable, IERC1967Upgradeable {\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    function __ERC1967Upgrade_init() internal onlyInitializing {\n    }\n\n    function __ERC1967Upgrade_init_unchained() internal onlyInitializing {\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(address newImplementation, bytes memory data, bool forceCall) internal {\n        _upgradeTo(newImplementation);\n        if (data.length > 0 || forceCall) {\n            AddressUpgradeable.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(address newImplementation, bytes memory data, bool forceCall) 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 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 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(address newBeacon, bytes memory data, bool forceCall) internal {\n        _setBeacon(newBeacon);\n        emit BeaconUpgraded(newBeacon);\n        if (data.length > 0 || forceCall) {\n            AddressUpgradeable.functionDelegateCall(IBeaconUpgradeable(newBeacon).implementation(), data);\n        }\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"},{"file_path":"contracts/libraries/Throttle.sol","source_code":"// SPDX-License-Identifier: BlueOak-1.0.0\npragma solidity 0.8.28;\n\nimport \"./Fixed.sol\";\n\nuint48 constant ONE_HOUR = 3600; // {seconds/hour}\n\n/**\n * @title ThrottleLib\n * A library that implements a usage throttle that can be used to ensure net issuance\n * or net redemption for an RToken never exceeds some bounds per unit time (hour).\n *\n * It is expected for the RToken to use this library with two instances, one for issuance\n * and one for redemption. Issuance causes the available redemption amount to increase, and\n * visa versa.\n */\nlibrary ThrottleLib {\n    using FixLib for uint192;\n\n    struct Params {\n        uint256 amtRate; // {qRTok/hour} a quantity of RToken hourly; cannot be 0\n        uint192 pctRate; // {1/hour} a fraction of RToken hourly; can be 0\n    }\n\n    struct Throttle {\n        // === Gov params ===\n        Params params;\n        // === Cache ===\n        uint48 lastTimestamp; // {seconds}\n        uint256 lastAvailable; // {qRTok}\n    }\n\n    /// Reverts if usage amount exceeds available amount\n    /// @param supply {qRTok} Total RToken supply beforehand\n    /// @param amount {qRTok} Amount of RToken to use. Should be negative for the issuance\n    ///   throttle during redemption and for the redemption throttle during issuance.\n    function useAvailable(\n        Throttle storage throttle,\n        uint256 supply,\n        int256 amount\n    ) internal {\n        // untestable: amtRate will always be > 0 due to previous validations\n        if (throttle.params.amtRate == 0 && throttle.params.pctRate == 0) return;\n\n        // Calculate hourly limit\n        uint256 limit = hourlyLimit(throttle, supply); // {qRTok}\n\n        // Calculate available amount before supply change\n        uint256 available = currentlyAvailable(throttle, limit);\n\n        // Update throttle.timestamp if available amount changed or at limit\n        if (available != throttle.lastAvailable || available == limit) {\n            throttle.lastTimestamp = uint48(block.timestamp);\n        }\n\n        // Update throttle.lastAvailable\n        if (amount > 0) {\n            require(uint256(amount) <= available, \"supply change throttled\");\n            available -= uint256(amount);\n            // untestable: the final else statement, amount will never be 0\n        } else if (amount < 0) {\n            available += uint256(-amount);\n        }\n        throttle.lastAvailable = available;\n    }\n\n    /// @param limit {qRTok/hour} The hourly limit\n    /// @return available {qRTok} Amount currently available for consumption\n    function currentlyAvailable(Throttle storage throttle, uint256 limit)\n        internal\n        view\n        returns (uint256 available)\n    {\n        uint48 delta = uint48(block.timestamp) - throttle.lastTimestamp; // {seconds}\n        available = throttle.lastAvailable + (limit * delta) / ONE_HOUR;\n        if (available > limit) available = limit;\n    }\n\n    /// @return limit {qRTok} The hourly limit\n    function hourlyLimit(Throttle storage throttle, uint256 supply)\n        internal\n        view\n        returns (uint256 limit)\n    {\n        Params storage params = throttle.params;\n\n        // Calculate hourly limit as: max(params.amtRate, supply.mul(params.pctRate))\n        limit = (supply * params.pctRate) / FIX_ONE_256; // {qRTok}\n        if (params.amtRate > limit) limit = params.amtRate;\n    }\n}\n"},{"file_path":"@openzeppelin/contracts-upgradeable/access/IAccessControlUpgradeable.sol","source_code":"// 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"},{"file_path":"@openzeppelin/contracts-upgradeable/utils/AddressUpgradeable.sol","source_code":"// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.9.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     * Furthermore, `isContract` will also return true if the target contract within\n     * the same transaction is already scheduled for destruction by `SELFDESTRUCT`,\n     * which only has an effect at the end of a transaction.\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://consensys.net/diligence/blog/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.8.0/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].\n     */\n    function sendValue(address payable recipient, uint256 amount) internal {\n        require(address(this).balance >= amount, \"Address: insufficient balance\");\n\n        (bool success, ) = recipient.call{value: amount}(\"\");\n        require(success, \"Address: unable to send value, recipient may have reverted\");\n    }\n\n    /**\n     * @dev Performs a Solidity function call using a low level `call`. A\n     * plain `call` is an unsafe replacement for a function call: use this\n     * function instead.\n     *\n     * If `target` reverts with a revert reason, it is bubbled up by this\n     * function (like regular Solidity function calls).\n     *\n     * Returns the raw returned data. To convert to the expected return value,\n     * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].\n     *\n     * Requirements:\n     *\n     * - `target` must be a contract.\n     * - calling `target` with `data` must not revert.\n     *\n     * _Available since v3.1._\n     */\n    function functionCall(address target, bytes memory data) internal returns (bytes memory) {\n        return functionCallWithValue(target, data, 0, \"Address: low-level call failed\");\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with\n     * `errorMessage` as a fallback revert reason when `target` reverts.\n     *\n     * _Available since v3.1._\n     */\n    function functionCall(\n        address target,\n        bytes memory data,\n        string memory errorMessage\n    ) internal returns (bytes memory) {\n        return functionCallWithValue(target, data, 0, errorMessage);\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],\n     * but also transferring `value` wei to `target`.\n     *\n     * Requirements:\n     *\n     * - the calling contract must have an ETH balance of at least `value`.\n     * - the called Solidity function must be `payable`.\n     *\n     * _Available since v3.1._\n     */\n    function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {\n        return functionCallWithValue(target, data, value, \"Address: low-level call with value failed\");\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but\n     * with `errorMessage` as a fallback revert reason when `target` reverts.\n     *\n     * _Available since v3.1._\n     */\n    function functionCallWithValue(\n        address target,\n        bytes memory data,\n        uint256 value,\n        string memory errorMessage\n    ) internal returns (bytes memory) {\n        require(address(this).balance >= value, \"Address: insufficient balance for call\");\n        (bool success, bytes memory returndata) = target.call{value: value}(data);\n        return verifyCallResultFromTarget(target, success, returndata, errorMessage);\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],\n     * but performing a static call.\n     *\n     * _Available since v3.3._\n     */\n    function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {\n        return functionStaticCall(target, data, \"Address: low-level static call failed\");\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],\n     * but performing a static call.\n     *\n     * _Available since v3.3._\n     */\n    function functionStaticCall(\n        address target,\n        bytes memory data,\n        string memory errorMessage\n    ) internal view returns (bytes memory) {\n        (bool success, bytes memory returndata) = target.staticcall(data);\n        return verifyCallResultFromTarget(target, success, returndata, errorMessage);\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],\n     * but performing a delegate call.\n     *\n     * _Available since v3.4._\n     */\n    function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {\n        return functionDelegateCall(target, data, \"Address: low-level delegate call failed\");\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],\n     * but performing a delegate call.\n     *\n     * _Available since v3.4._\n     */\n    function functionDelegateCall(\n        address target,\n        bytes memory data,\n        string memory errorMessage\n    ) internal returns (bytes memory) {\n        (bool success, bytes memory returndata) = target.delegatecall(data);\n        return verifyCallResultFromTarget(target, success, returndata, errorMessage);\n    }\n\n    /**\n     * @dev Tool to verify that a low level call to smart-contract was successful, and revert (either by bubbling\n     * the revert reason or using the provided one) in case of unsuccessful call or if target was not a contract.\n     *\n     * _Available since v4.8._\n     */\n    function verifyCallResultFromTarget(\n        address target,\n        bool success,\n        bytes memory returndata,\n        string memory errorMessage\n    ) internal view returns (bytes memory) {\n        if (success) {\n            if (returndata.length == 0) {\n                // only check isContract if the call was successful and the return data is empty\n                // otherwise we already know that it was a contract\n                require(isContract(target), \"Address: call to non-contract\");\n            }\n            return returndata;\n        } else {\n            _revert(returndata, errorMessage);\n        }\n    }\n\n    /**\n     * @dev Tool to verify that a low level call was successful, and revert if it wasn't, either by bubbling the\n     * revert reason or using the provided one.\n     *\n     * _Available since v4.3._\n     */\n    function verifyCallResult(\n        bool success,\n        bytes memory returndata,\n        string memory errorMessage\n    ) internal pure returns (bytes memory) {\n        if (success) {\n            return returndata;\n        } else {\n            _revert(returndata, errorMessage);\n        }\n    }\n\n    function _revert(bytes memory returndata, string memory errorMessage) private pure {\n        // Look for revert reason and bubble it up if present\n        if (returndata.length > 0) {\n            // The easiest way to bubble the revert reason is using memory via assembly\n            /// @solidity memory-safe-assembly\n            assembly {\n                let returndata_size := mload(returndata)\n                revert(add(32, returndata), returndata_size)\n            }\n        } else {\n            revert(errorMessage);\n        }\n    }\n}\n"},{"file_path":"contracts/interfaces/IBackingManager.sol","source_code":"// SPDX-License-Identifier: BlueOak-1.0.0\npragma solidity 0.8.28;\n\nimport \"@openzeppelin/contracts/token/ERC20/IERC20.sol\";\nimport \"./IAssetRegistry.sol\";\nimport \"./IBasketHandler.sol\";\nimport \"./IComponent.sol\";\nimport \"./IRToken.sol\";\nimport \"./IStRSR.sol\";\nimport \"./ITrading.sol\";\n\n/// Memory struct for RecollateralizationLibP1 + RTokenAsset\n/// Struct purposes:\n///   1. Configure trading\n///   2. Stay under stack limit with fewer vars\n///   3. Cache information such as component addresses and basket quantities, to save on gas\nstruct TradingContext {\n    BasketRange basketsHeld; // {BU}\n    // basketsHeld.top is the number of partial baskets units held\n    // basketsHeld.bottom is the number of full basket units held\n\n    // Components\n    IBasketHandler bh;\n    IAssetRegistry ar;\n    IStRSR stRSR;\n    IERC20 rsr;\n    IRToken rToken;\n    // Gov Vars\n    uint192 minTradeVolume; // {UoA}\n    uint192 maxTradeSlippage; // {1}\n    // Cached values\n    uint192[] quantities; // {tok/BU} basket quantities\n    uint192[] bals; // {tok} balances in BackingManager + out on trades\n}\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 *     - rebalance()\n *   - If already collateralized, excess assets are transferred to RevenueTraders.\n *     - forwardRevenue(IERC20[] calldata erc20s)\n */\ninterface IBackingManager is IComponent, ITrading {\n    /// Emitted when the trading delay is changed\n    /// @param oldVal The old trading delay\n    /// @param newVal The new trading delay\n    event TradingDelaySet(uint48 oldVal, uint48 newVal);\n\n    /// Emitted when the backing buffer is changed\n    /// @param oldVal The old backing buffer\n    /// @param newVal The new backing buffer\n    event BackingBufferSet(uint192 oldVal, uint192 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    /// Apply the overall backing policy using the specified TradeKind, taking a haircut if unable\n    /// @param kind TradeKind.DUTCH_AUCTION or TradeKind.BATCH_AUCTION\n    /// @custom:interaction RCEI\n    function rebalance(TradeKind kind) external;\n\n    /// Forward revenue to RevenueTraders; reverts if not fully collateralized\n    /// @param erc20s The tokens to forward\n    /// @custom:interaction RCEI\n    function forwardRevenue(IERC20[] calldata erc20s) external;\n\n    /// Structs for trading\n    /// @param basketsHeld The number of baskets held by the BackingManager\n    /// @return ctx The TradingContext\n    /// @return reg Contents of AssetRegistry.getRegistry()\n    function tradingContext(BasketRange memory basketsHeld)\n        external\n        view\n        returns (TradingContext memory ctx, Registry memory reg);\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"},{"file_path":"contracts/mixins/Versioned.sol","source_code":"// SPDX-License-Identifier: BlueOak-1.0.0\npragma solidity 0.8.28;\n\nimport \"../interfaces/IVersioned.sol\";\n\n// This value should be updated on each release\nstring constant VERSION = \"4.2.0\";\n\n/**\n * @title Versioned\n * @notice A mix-in to track semantic versioning uniformly across contracts.\n */\nabstract contract Versioned is IVersioned {\n    function version() public pure virtual override returns (string memory) {\n        return VERSION;\n    }\n}\n"},{"file_path":"contracts/registry/VersionRegistry.sol","source_code":"// SPDX-License-Identifier: BlueOak-1.0.0\npragma solidity 0.8.28;\n\nimport { IDeployer, Implementations } from \"../interfaces/IDeployer.sol\";\nimport { RoleRegistry } from \"./RoleRegistry.sol\";\n\n/**\n * @title VersionRegistry\n * @notice A tiny contract for tracking deployment versions\n *         All versions registered are expected to be >=4.0.0\n */\ncontract VersionRegistry {\n    mapping(bytes32 => IDeployer) public deployments;\n    mapping(bytes32 => bool) public isDeprecated;\n    bytes32 private latestVersion;\n    RoleRegistry public roleRegistry;\n\n    error VersionRegistry__ZeroAddress();\n    error VersionRegistry__InvalidRegistration();\n    error VersionRegistry__AlreadyDeprecated();\n    error VersionRegistry__InvalidRoleRegistry();\n    error VersionRegistry__InvalidCaller();\n\n    event VersionRegistered(bytes32 versionHash, IDeployer deployer);\n    event VersionDeprecated(bytes32 versionHash);\n\n    constructor(RoleRegistry _roleRegistry) {\n        if (address(_roleRegistry) == address(0)) {\n            revert VersionRegistry__ZeroAddress();\n        }\n\n        roleRegistry = _roleRegistry;\n    }\n\n    /// Register a deployer address, keyed by version.\n    /// @param deployer The deployer contract address for the version to be added.\n    function registerVersion(IDeployer deployer) external {\n        if (!roleRegistry.isOwner(msg.sender)) {\n            revert VersionRegistry__InvalidCaller();\n        }\n\n        if (address(deployer) == address(0)) {\n            revert VersionRegistry__ZeroAddress();\n        }\n\n        string memory version = deployer.version();\n        bytes32 versionHash = keccak256(abi.encodePacked(version));\n\n        if (address(deployments[versionHash]) != address(0)) {\n            revert VersionRegistry__InvalidRegistration();\n        }\n\n        deployments[versionHash] = deployer;\n        latestVersion = versionHash;\n\n        emit VersionRegistered(versionHash, deployer);\n    }\n\n    function deprecateVersion(bytes32 versionHash) external {\n        if (!roleRegistry.isOwnerOrEmergencyCouncil(msg.sender)) {\n            revert VersionRegistry__InvalidCaller();\n        }\n\n        if (isDeprecated[versionHash]) {\n            revert VersionRegistry__AlreadyDeprecated();\n        }\n        isDeprecated[versionHash] = true;\n\n        emit VersionDeprecated(versionHash);\n    }\n\n    function getLatestVersion()\n        external\n        view\n        returns (\n            bytes32 versionHash,\n            string memory version,\n            IDeployer deployer,\n            bool deprecated\n        )\n    {\n        versionHash = latestVersion;\n        deployer = deployments[versionHash];\n        version = deployer.version();\n        deprecated = isDeprecated[versionHash];\n    }\n\n    function getImplementationForVersion(bytes32 versionHash)\n        external\n        view\n        returns (Implementations memory)\n    {\n        return deployments[versionHash].implementations();\n    }\n}\n"},{"file_path":"contracts/libraries/Fixed.sol","source_code":"// SPDX-License-Identifier: BlueOak-1.0.0\n// solhint-disable func-name-mixedcase func-visibility\n// slither-disable-start divide-before-multiply\npragma solidity 0.8.28;\n\n/// @title FixedPoint, a fixed-point arithmetic library defining the custom type uint192\n/// @author Matt Elder <matt.elder@reserve.org> 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 [0, 2^192-1 / 10^18 = 6.2e39].\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();\nbytes32 constant UIntOutofBoundsHash = keccak256(abi.encodeWithSignature(\"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 6.2e39\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.17/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    // conditions for avoiding overflow\n    if (x == 0) return 0;\n    if (shiftLeft <= -96) return (rounding == CEIL ? 1 : 0); // 0 < uint.max / 10**77 < 0.5\n    if (40 <= shiftLeft) revert UIntOutOfBounds(); // 10**57 < FIX_MAX < 10**58\n\n    shiftLeft += 18;\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        // Handle overflow cases\n        if (x == 0) return 0;\n        if (decimals <= -59) return (rounding == CEIL ? 1 : 0); // 59, because 1e58 > 2**192\n        if (58 <= decimals) revert UIntOutOfBounds(); // 58, because x * 1e58 > 2 ** 192 if x != 0\n\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. Requires that x_ <= FIX_ONE\n    /// Gas cost is O(lg(y)), precision is +- 1e-18.\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        require(x_ <= FIX_ONE);\n        if (y == 1) return x_;\n        if (x_ == FIX_ONE || y == 0) return FIX_ONE;\n        uint256 x = uint256(x_) * FIX_SCALE; // x is D36\n        uint256 result = FIX_SCALE_SQ; // result is D36\n        while (true) {\n            if (y & 1 == 1) result = (result * x + FIX_SCALE_SQ / 2) / FIX_SCALE_SQ;\n            if (y <= 1) break;\n            y = (y >> 1);\n            x = (x * x + FIX_SCALE_SQ / 2) / FIX_SCALE_SQ;\n        }\n        return _safeWrap(result / FIX_SCALE);\n    }\n\n    function sqrt(uint192 x) internal pure returns (uint192) {\n        return _safeWrap(sqrt256(x * FIX_ONE_256)); // FLOOR\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        // Handle overflow cases\n        if (x == 0) return 0; // always computable, no matter what decimals is\n        if (decimals <= -42) return (rounding == CEIL ? 1 : 0);\n        if (96 <= decimals) revert UIntOutOfBounds();\n\n        decimals -= 18; // shift so that toUint happens at the same time.\n\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    // === safe*() ===\n\n    /// Multiply two fixes, rounding up to FIX_MAX and down to 0\n    /// @param a First param to multiply\n    /// @param b Second param to multiply\n    function safeMul(\n        uint192 a,\n        uint192 b,\n        RoundingMode rounding\n    ) internal pure returns (uint192) {\n        // untestable:\n        //      a will never = 0 here because of the check in _price()\n        if (a == 0 || b == 0) return 0;\n        // untestable:\n        //      a = FIX_MAX iff b = 0\n        if (a == FIX_MAX || b == FIX_MAX) return FIX_MAX;\n\n        // return FIX_MAX instead of throwing overflow errors.\n        unchecked {\n            // p and mul *are* Fix values, so have 18 decimals (D18)\n            uint256 rawDelta = uint256(b) * a; // {D36} = {D18} * {D18}\n            // if we overflowed, then return FIX_MAX\n            if (rawDelta / b != a) return FIX_MAX;\n            uint256 shiftDelta = rawDelta;\n\n            // add in rounding\n            if (rounding == RoundingMode.ROUND) shiftDelta += (FIX_ONE / 2);\n            else if (rounding == RoundingMode.CEIL) shiftDelta += FIX_ONE - 1;\n\n            // untestable (here there be dragons):\n            // (below explanation is for the ROUND case, but it extends to the FLOOR/CEIL too)\n            //          A)  shiftDelta = rawDelta + (FIX_ONE / 2)\n            //      shiftDelta overflows if:\n            //          B)  shiftDelta = MAX_UINT256 - FIX_ONE/2 + 1\n            //              rawDelta + (FIX_ONE/2) = MAX_UINT256 - FIX_ONE/2 + 1\n            //              b * a = MAX_UINT256 - FIX_ONE + 1\n            //      therefore shiftDelta overflows if:\n            //          C)  b = (MAX_UINT256 - FIX_ONE + 1) / a\n            //      MAX_UINT256 ~= 1e77 , FIX_MAX ~= 6e57 (6e20 difference in magnitude)\n            //      a <= 1e21 (MAX_TARGET_AMT)\n            //      a must be between 1e19 & 1e20 in order for b in (C) to be uint192,\n            //      but a would have to be < 1e18 in order for (A) to overflow\n            if (shiftDelta < rawDelta) return FIX_MAX;\n\n            // return FIX_MAX if return result would truncate\n            if (shiftDelta / FIX_ONE > FIX_MAX) return FIX_MAX;\n\n            // return _div(rawDelta, FIX_ONE, rounding)\n            return uint192(shiftDelta / FIX_ONE); // {D18} = {D36} / {D18}\n        }\n    }\n\n    /// Divide two fixes, rounding up to FIX_MAX and down to 0\n    /// @param a Numerator\n    /// @param b Denominator\n    function safeDiv(\n        uint192 a,\n        uint192 b,\n        RoundingMode rounding\n    ) internal pure returns (uint192) {\n        if (a == 0) return 0;\n        if (b == 0) return FIX_MAX;\n\n        uint256 raw = _divrnd(FIX_ONE_256 * a, uint256(b), rounding);\n        if (raw >= FIX_MAX) return FIX_MAX;\n        return uint192(raw); // don't need _safeWrap\n    }\n\n    /// Multiplies two fixes and divide by a third\n    /// @param a First to multiply\n    /// @param b Second to multiply\n    /// @param c Denominator\n    function safeMulDiv(\n        uint192 a,\n        uint192 b,\n        uint192 c,\n        RoundingMode rounding\n    ) internal pure returns (uint192 result) {\n        if (a == 0 || b == 0) return 0;\n        if (a == FIX_MAX || b == FIX_MAX || c == 0) return FIX_MAX;\n\n        uint256 result_256;\n        unchecked {\n            (uint256 hi, uint256 lo) = fullMul(a, b);\n            if (hi >= c) return FIX_MAX;\n            uint256 mm = mulmod(a, b, c);\n            if (mm > lo) hi -= 1;\n            lo -= mm;\n            uint256 pow2 = c & (0 - c);\n\n            uint256 c_256 = uint256(c);\n            c_256 /= pow2;\n            lo /= pow2;\n            lo += hi * ((0 - pow2) / pow2 + 1);\n            uint256 r = 1;\n            r *= 2 - c_256 * r;\n            r *= 2 - c_256 * r;\n            r *= 2 - c_256 * r;\n            r *= 2 - c_256 * r;\n            r *= 2 - c_256 * r;\n            r *= 2 - c_256 * r;\n            r *= 2 - c_256 * r;\n            r *= 2 - c_256 * r;\n            result_256 = lo * r;\n\n            // Apply rounding\n            if (rounding == CEIL) {\n                if (mm != 0) result_256 += 1;\n            } else if (rounding == ROUND) {\n                if (mm > ((c - 1) / 2)) result_256 += 1; // intentional: use pre-divided c here\n            }\n        }\n\n        if (result_256 >= FIX_MAX) return FIX_MAX;\n        return uint192(result_256);\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\n// =============== from prbMath at commit 28055f6cd9a2367f9ad7ab6c8e01c9ac8e9acc61 ===============\n/// @notice Calculates the square root of x using the Babylonian method.\n///\n/// @dev See https://en.wikipedia.org/wiki/Methods_of_computing_square_roots#Babylonian_method.\n///\n/// Notes:\n/// - If x is not a perfect square, the result is rounded down.\n/// - Credits to OpenZeppelin for the explanations in comments below.\n///\n/// @param x The uint256 number for which to calculate the square root.\n/// @return result The result as a uint256.\nfunction sqrt256(uint256 x) pure returns (uint256 result) {\n    if (x == 0) {\n        return 0;\n    }\n\n    // For our first guess, we calculate the biggest power of 2 which is smaller than the square root of x.\n    //\n    // We know that the \"msb\" (most significant bit) of x is a power of 2 such that we have:\n    //\n    // $$\n    // msb(x) <= x <= 2*msb(x)$\n    // $$\n    //\n    // We write $msb(x)$ as $2^k$, and we get:\n    //\n    // $$\n    // k = log_2(x)\n    // $$\n    //\n    // Thus, we can write the initial inequality as:\n    //\n    // $$\n    // 2^{log_2(x)} <= x <= 2*2^{log_2(x)+1} \\\\\n    // sqrt(2^k) <= sqrt(x) < sqrt(2^{k+1}) \\\\\n    // 2^{k/2} <= sqrt(x) < 2^{(k+1)/2} <= 2^{(k/2)+1}\n    // $$\n    //\n    // Consequently, $2^{log_2(x) /2} is a good first approximation of sqrt(x) with at least one correct bit.\n    uint256 xAux = uint256(x);\n    result = 1;\n    if (xAux >= 2**128) {\n        xAux >>= 128;\n        result <<= 64;\n    }\n    if (xAux >= 2**64) {\n        xAux >>= 64;\n        result <<= 32;\n    }\n    if (xAux >= 2**32) {\n        xAux >>= 32;\n        result <<= 16;\n    }\n    if (xAux >= 2**16) {\n        xAux >>= 16;\n        result <<= 8;\n    }\n    if (xAux >= 2**8) {\n        xAux >>= 8;\n        result <<= 4;\n    }\n    if (xAux >= 2**4) {\n        xAux >>= 4;\n        result <<= 2;\n    }\n    if (xAux >= 2**2) {\n        result <<= 1;\n    }\n\n    // At this point, `result` is an estimation with at least one bit of precision. We know the true value has at\n    // most 128 bits, since it is the square root of a uint256. Newton's method converges quadratically (precision\n    // doubles at every iteration). We thus need at most 7 iteration to turn our partial result with one bit of\n    // precision into the expected uint128 result.\n    unchecked {\n        result = (result + x / result) >> 1;\n        result = (result + x / result) >> 1;\n        result = (result + x / result) >> 1;\n        result = (result + x / result) >> 1;\n        result = (result + x / result) >> 1;\n        result = (result + x / result) >> 1;\n        result = (result + x / result) >> 1;\n\n        // If x is not a perfect square, round the result toward zero.\n        uint256 roundedResult = x / result;\n        if (result >= roundedResult) {\n            result = roundedResult;\n        }\n    }\n}\n// slither-disable-end divide-before-multiply\n"},{"file_path":"@openzeppelin/contracts-upgradeable/interfaces/draft-IERC1822Upgradeable.sol","source_code":"// 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"},{"file_path":"@openzeppelin/contracts/utils/introspection/ERC165.sol","source_code":"// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts v4.4.1 (utils/introspection/ERC165.sol)\n\npragma solidity ^0.8.0;\n\nimport \"./IERC165.sol\";\n\n/**\n * @dev Implementation of the {IERC165} interface.\n *\n * Contracts that want to implement ERC165 should inherit from this contract and override {supportsInterface} to check\n * for the additional interface id that will be supported. For example:\n *\n * ```solidity\n * function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {\n *     return interfaceId == type(MyInterface).interfaceId || super.supportsInterface(interfaceId);\n * }\n * ```\n *\n * Alternatively, {ERC165Storage} provides an easier to use but more expensive implementation.\n */\nabstract contract ERC165 is IERC165 {\n    /**\n     * @dev See {IERC165-supportsInterface}.\n     */\n    function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {\n        return interfaceId == type(IERC165).interfaceId;\n    }\n}\n"},{"file_path":"@openzeppelin/contracts/utils/Strings.sol","source_code":"// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.9.0) (utils/Strings.sol)\n\npragma solidity ^0.8.0;\n\nimport \"./math/Math.sol\";\nimport \"./math/SignedMath.sol\";\n\n/**\n * @dev String operations.\n */\nlibrary Strings {\n    bytes16 private constant _SYMBOLS = \"0123456789abcdef\";\n    uint8 private constant _ADDRESS_LENGTH = 20;\n\n    /**\n     * @dev Converts a `uint256` to its ASCII `string` decimal representation.\n     */\n    function toString(uint256 value) internal pure returns (string memory) {\n        unchecked {\n            uint256 length = Math.log10(value) + 1;\n            string memory buffer = new string(length);\n            uint256 ptr;\n            /// @solidity memory-safe-assembly\n            assembly {\n                ptr := add(buffer, add(32, length))\n            }\n            while (true) {\n                ptr--;\n                /// @solidity memory-safe-assembly\n                assembly {\n                    mstore8(ptr, byte(mod(value, 10), _SYMBOLS))\n                }\n                value /= 10;\n                if (value == 0) break;\n            }\n            return buffer;\n        }\n    }\n\n    /**\n     * @dev Converts a `int256` to its ASCII `string` decimal representation.\n     */\n    function toString(int256 value) internal pure returns (string memory) {\n        return string(abi.encodePacked(value < 0 ? \"-\" : \"\", toString(SignedMath.abs(value))));\n    }\n\n    /**\n     * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation.\n     */\n    function toHexString(uint256 value) internal pure returns (string memory) {\n        unchecked {\n            return toHexString(value, Math.log256(value) + 1);\n        }\n    }\n\n    /**\n     * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length.\n     */\n    function toHexString(uint256 value, uint256 length) internal pure returns (string memory) {\n        bytes memory buffer = new bytes(2 * length + 2);\n        buffer[0] = \"0\";\n        buffer[1] = \"x\";\n        for (uint256 i = 2 * length + 1; i > 1; --i) {\n            buffer[i] = _SYMBOLS[value & 0xf];\n            value >>= 4;\n        }\n        require(value == 0, \"Strings: hex length insufficient\");\n        return string(buffer);\n    }\n\n    /**\n     * @dev Converts an `address` with fixed length of 20 bytes to its not checksummed ASCII `string` hexadecimal representation.\n     */\n    function toHexString(address addr) internal pure returns (string memory) {\n        return toHexString(uint256(uint160(addr)), _ADDRESS_LENGTH);\n    }\n\n    /**\n     * @dev Returns true if the two strings are equal.\n     */\n    function equal(string memory a, string memory b) internal pure returns (bool) {\n        return keccak256(bytes(a)) == keccak256(bytes(b));\n    }\n}\n"},{"file_path":"@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol","source_code":"// 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"},{"file_path":"@openzeppelin/contracts-upgradeable/interfaces/IERC5267Upgradeable.sol","source_code":"// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.9.0) (interfaces/IERC5267.sol)\n\npragma solidity ^0.8.0;\n\ninterface IERC5267Upgradeable {\n    /**\n     * @dev MAY be emitted to signal that the domain could have changed.\n     */\n    event EIP712DomainChanged();\n\n    /**\n     * @dev returns the fields and values that describe the domain separator used by this contract for EIP-712\n     * signature.\n     */\n    function eip712Domain()\n        external\n        view\n        returns (\n            bytes1 fields,\n            string memory name,\n            string memory version,\n            uint256 chainId,\n            address verifyingContract,\n            bytes32 salt,\n            uint256[] memory extensions\n        );\n}\n"},{"file_path":"@openzeppelin/contracts-upgradeable/token/ERC20/ERC20Upgradeable.sol","source_code":"// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.9.0) (token/ERC20/ERC20.sol)\n\npragma solidity ^0.8.0;\n\nimport \"./IERC20Upgradeable.sol\";\nimport \"./extensions/IERC20MetadataUpgradeable.sol\";\nimport \"../../utils/ContextUpgradeable.sol\";\nimport {Initializable} from \"../../proxy/utils/Initializable.sol\";\n\n/**\n * @dev Implementation of the {IERC20} interface.\n *\n * This implementation is agnostic to the way tokens are created. This means\n * that a supply mechanism has to be added in a derived contract using {_mint}.\n * For a generic mechanism see {ERC20PresetMinterPauser}.\n *\n * TIP: For a detailed writeup see our guide\n * https://forum.openzeppelin.com/t/how-to-implement-erc20-supply-mechanisms/226[How\n * to implement supply mechanisms].\n *\n * The default value of {decimals} is 18. To change this, you should override\n * this function so it returns a different value.\n *\n * We have followed general OpenZeppelin Contracts guidelines: functions revert\n * instead returning `false` on failure. This behavior is nonetheless\n * conventional and does not conflict with the expectations of ERC20\n * applications.\n *\n * Additionally, an {Approval} event is emitted on calls to {transferFrom}.\n * This allows applications to reconstruct the allowance for all accounts just\n * by listening to said events. Other implementations of the EIP may not emit\n * these events, as it isn't required by the specification.\n *\n * Finally, the non-standard {decreaseAllowance} and {increaseAllowance}\n * functions have been added to mitigate the well-known issues around setting\n * allowances. See {IERC20-approve}.\n */\ncontract ERC20Upgradeable is Initializable, ContextUpgradeable, IERC20Upgradeable, IERC20MetadataUpgradeable {\n    mapping(address => uint256) private _balances;\n\n    mapping(address => mapping(address => uint256)) private _allowances;\n\n    uint256 private _totalSupply;\n\n    string private _name;\n    string private _symbol;\n\n    /**\n     * @dev Sets the values for {name} and {symbol}.\n     *\n     * All two of these values are immutable: they can only be set once during\n     * construction.\n     */\n    function __ERC20_init(string memory name_, string memory symbol_) internal onlyInitializing {\n        __ERC20_init_unchained(name_, symbol_);\n    }\n\n    function __ERC20_init_unchained(string memory name_, string memory symbol_) internal onlyInitializing {\n        _name = name_;\n        _symbol = symbol_;\n    }\n\n    /**\n     * @dev Returns the name of the token.\n     */\n    function name() public view virtual override returns (string memory) {\n        return _name;\n    }\n\n    /**\n     * @dev Returns the symbol of the token, usually a shorter version of the\n     * name.\n     */\n    function symbol() public view virtual override returns (string memory) {\n        return _symbol;\n    }\n\n    /**\n     * @dev Returns the number of decimals used to get its user representation.\n     * For example, if `decimals` equals `2`, a balance of `505` tokens should\n     * be displayed to a user as `5.05` (`505 / 10 ** 2`).\n     *\n     * Tokens usually opt for a value of 18, imitating the relationship between\n     * Ether and Wei. This is the default value returned by this function, unless\n     * it's overridden.\n     *\n     * NOTE: This information is only used for _display_ purposes: it in\n     * no way affects any of the arithmetic of the contract, including\n     * {IERC20-balanceOf} and {IERC20-transfer}.\n     */\n    function decimals() public view virtual override returns (uint8) {\n        return 18;\n    }\n\n    /**\n     * @dev See {IERC20-totalSupply}.\n     */\n    function totalSupply() public view virtual override returns (uint256) {\n        return _totalSupply;\n    }\n\n    /**\n     * @dev See {IERC20-balanceOf}.\n     */\n    function balanceOf(address account) public view virtual override returns (uint256) {\n        return _balances[account];\n    }\n\n    /**\n     * @dev See {IERC20-transfer}.\n     *\n     * Requirements:\n     *\n     * - `to` cannot be the zero address.\n     * - the caller must have a balance of at least `amount`.\n     */\n    function transfer(address to, uint256 amount) public virtual override returns (bool) {\n        address owner = _msgSender();\n        _transfer(owner, to, amount);\n        return true;\n    }\n\n    /**\n     * @dev See {IERC20-allowance}.\n     */\n    function allowance(address owner, address spender) public view virtual override returns (uint256) {\n        return _allowances[owner][spender];\n    }\n\n    /**\n     * @dev See {IERC20-approve}.\n     *\n     * NOTE: If `amount` is the maximum `uint256`, the allowance is not updated on\n     * `transferFrom`. This is semantically equivalent to an infinite approval.\n     *\n     * Requirements:\n     *\n     * - `spender` cannot be the zero address.\n     */\n    function approve(address spender, uint256 amount) public virtual override returns (bool) {\n        address owner = _msgSender();\n        _approve(owner, spender, amount);\n        return true;\n    }\n\n    /**\n     * @dev See {IERC20-transferFrom}.\n     *\n     * Emits an {Approval} event indicating the updated allowance. This is not\n     * required by the EIP. See the note at the beginning of {ERC20}.\n     *\n     * NOTE: Does not update the allowance if the current allowance\n     * is the maximum `uint256`.\n     *\n     * Requirements:\n     *\n     * - `from` and `to` cannot be the zero address.\n     * - `from` must have a balance of at least `amount`.\n     * - the caller must have allowance for ``from``'s tokens of at least\n     * `amount`.\n     */\n    function transferFrom(address from, address to, uint256 amount) public virtual override returns (bool) {\n        address spender = _msgSender();\n        _spendAllowance(from, spender, amount);\n        _transfer(from, to, amount);\n        return true;\n    }\n\n    /**\n     * @dev Atomically increases the allowance granted to `spender` by the caller.\n     *\n     * This is an alternative to {approve} that can be used as a mitigation for\n     * problems described in {IERC20-approve}.\n     *\n     * Emits an {Approval} event indicating the updated allowance.\n     *\n     * Requirements:\n     *\n     * - `spender` cannot be the zero address.\n     */\n    function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) {\n        address owner = _msgSender();\n        _approve(owner, spender, allowance(owner, spender) + addedValue);\n        return true;\n    }\n\n    /**\n     * @dev Atomically decreases the allowance granted to `spender` by the caller.\n     *\n     * This is an alternative to {approve} that can be used as a mitigation for\n     * problems described in {IERC20-approve}.\n     *\n     * Emits an {Approval} event indicating the updated allowance.\n     *\n     * Requirements:\n     *\n     * - `spender` cannot be the zero address.\n     * - `spender` must have allowance for the caller of at least\n     * `subtractedValue`.\n     */\n    function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) {\n        address owner = _msgSender();\n        uint256 currentAllowance = allowance(owner, spender);\n        require(currentAllowance >= subtractedValue, \"ERC20: decreased allowance below zero\");\n        unchecked {\n            _approve(owner, spender, currentAllowance - subtractedValue);\n        }\n\n        return true;\n    }\n\n    /**\n     * @dev Moves `amount` of tokens from `from` to `to`.\n     *\n     * This internal function is equivalent to {transfer}, and can be used to\n     * e.g. implement automatic token fees, slashing mechanisms, etc.\n     *\n     * Emits a {Transfer} event.\n     *\n     * Requirements:\n     *\n     * - `from` cannot be the zero address.\n     * - `to` cannot be the zero address.\n     * - `from` must have a balance of at least `amount`.\n     */\n    function _transfer(address from, address to, uint256 amount) internal virtual {\n        require(from != address(0), \"ERC20: transfer from the zero address\");\n        require(to != address(0), \"ERC20: transfer to the zero address\");\n\n        _beforeTokenTransfer(from, to, amount);\n\n        uint256 fromBalance = _balances[from];\n        require(fromBalance >= amount, \"ERC20: transfer amount exceeds balance\");\n        unchecked {\n            _balances[from] = fromBalance - amount;\n            // Overflow not possible: the sum of all balances is capped by totalSupply, and the sum is preserved by\n            // decrementing then incrementing.\n            _balances[to] += amount;\n        }\n\n        emit Transfer(from, to, amount);\n\n        _afterTokenTransfer(from, to, amount);\n    }\n\n    /** @dev Creates `amount` tokens and assigns them to `account`, increasing\n     * the total supply.\n     *\n     * Emits a {Transfer} event with `from` set to the zero address.\n     *\n     * Requirements:\n     *\n     * - `account` cannot be the zero address.\n     */\n    function _mint(address account, uint256 amount) internal virtual {\n        require(account != address(0), \"ERC20: mint to the zero address\");\n\n        _beforeTokenTransfer(address(0), account, amount);\n\n        _totalSupply += amount;\n        unchecked {\n            // Overflow not possible: balance + amount is at most totalSupply + amount, which is checked above.\n            _balances[account] += amount;\n        }\n        emit Transfer(address(0), account, amount);\n\n        _afterTokenTransfer(address(0), account, amount);\n    }\n\n    /**\n     * @dev Destroys `amount` tokens from `account`, reducing the\n     * total supply.\n     *\n     * Emits a {Transfer} event with `to` set to the zero address.\n     *\n     * Requirements:\n     *\n     * - `account` cannot be the zero address.\n     * - `account` must have at least `amount` tokens.\n     */\n    function _burn(address account, uint256 amount) internal virtual {\n        require(account != address(0), \"ERC20: burn from the zero address\");\n\n        _beforeTokenTransfer(account, address(0), amount);\n\n        uint256 accountBalance = _balances[account];\n        require(accountBalance >= amount, \"ERC20: burn amount exceeds balance\");\n        unchecked {\n            _balances[account] = accountBalance - amount;\n            // Overflow not possible: amount <= accountBalance <= totalSupply.\n            _totalSupply -= amount;\n        }\n\n        emit Transfer(account, address(0), amount);\n\n        _afterTokenTransfer(account, address(0), amount);\n    }\n\n    /**\n     * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens.\n     *\n     * This internal function is equivalent to `approve`, and can be used to\n     * e.g. set automatic allowances for certain subsystems, etc.\n     *\n     * Emits an {Approval} event.\n     *\n     * Requirements:\n     *\n     * - `owner` cannot be the zero address.\n     * - `spender` cannot be the zero address.\n     */\n    function _approve(address owner, address spender, uint256 amount) internal virtual {\n        require(owner != address(0), \"ERC20: approve from the zero address\");\n        require(spender != address(0), \"ERC20: approve to the zero address\");\n\n        _allowances[owner][spender] = amount;\n        emit Approval(owner, spender, amount);\n    }\n\n    /**\n     * @dev Updates `owner` s allowance for `spender` based on spent `amount`.\n     *\n     * Does not update the allowance amount in case of infinite allowance.\n     * Revert if not enough allowance is available.\n     *\n     * Might emit an {Approval} event.\n     */\n    function _spendAllowance(address owner, address spender, uint256 amount) internal virtual {\n        uint256 currentAllowance = allowance(owner, spender);\n        if (currentAllowance != type(uint256).max) {\n            require(currentAllowance >= amount, \"ERC20: insufficient allowance\");\n            unchecked {\n                _approve(owner, spender, currentAllowance - amount);\n            }\n        }\n    }\n\n    /**\n     * @dev Hook that is called before any transfer of tokens. This includes\n     * minting and burning.\n     *\n     * Calling conditions:\n     *\n     * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens\n     * will be transferred to `to`.\n     * - when `from` is zero, `amount` tokens will be minted for `to`.\n     * - when `to` is zero, `amount` of ``from``'s tokens will be burned.\n     * - `from` and `to` are never both zero.\n     *\n     * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].\n     */\n    function _beforeTokenTransfer(address from, address to, uint256 amount) internal virtual {}\n\n    /**\n     * @dev Hook that is called after any transfer of tokens. This includes\n     * minting and burning.\n     *\n     * Calling conditions:\n     *\n     * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens\n     * has been transferred to `to`.\n     * - when `from` is zero, `amount` tokens have been minted for `to`.\n     * - when `to` is zero, `amount` of ``from``'s tokens have been burned.\n     * - `from` and `to` are never both zero.\n     *\n     * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].\n     */\n    function _afterTokenTransfer(address from, address to, uint256 amount) 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[45] private __gap;\n}\n"},{"file_path":"@openzeppelin/contracts-upgradeable/utils/math/SignedMathUpgradeable.sol","source_code":"// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.8.0) (utils/math/SignedMath.sol)\n\npragma solidity ^0.8.0;\n\n/**\n * @dev Standard signed math utilities missing in the Solidity language.\n */\nlibrary SignedMathUpgradeable {\n    /**\n     * @dev Returns the largest of two signed numbers.\n     */\n    function max(int256 a, int256 b) internal pure returns (int256) {\n        return a > b ? a : b;\n    }\n\n    /**\n     * @dev Returns the smallest of two signed numbers.\n     */\n    function min(int256 a, int256 b) internal pure returns (int256) {\n        return a < b ? a : b;\n    }\n\n    /**\n     * @dev Returns the average of two signed numbers without overflow.\n     * The result is rounded towards zero.\n     */\n    function average(int256 a, int256 b) internal pure returns (int256) {\n        // Formula from the book \"Hacker's Delight\"\n        int256 x = (a & b) + ((a ^ b) >> 1);\n        return x + (int256(uint256(x) >> 255) & (a ^ b));\n    }\n\n    /**\n     * @dev Returns the absolute unsigned value of a signed value.\n     */\n    function abs(int256 n) internal pure returns (uint256) {\n        unchecked {\n            // must be unchecked in order to support `n = type(int256).min`\n            return uint256(n >= 0 ? n : -n);\n        }\n    }\n}\n"},{"file_path":"contracts/interfaces/ITrade.sol","source_code":"// SPDX-License-Identifier: BlueOak-1.0.0\npragma solidity 0.8.28;\n\nimport \"@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol\";\nimport \"./IBroker.sol\";\nimport \"./IVersioned.sol\";\n\nenum TradeStatus {\n    NOT_STARTED, // before init()\n    OPEN, // after init() and before settle()\n    CLOSED, // after settle()\n    // === Intermediate-tx state ===\n    PENDING // during init() or settle() (reentrancy protection)\n}\n\n/**\n * Simple generalized trading interface for all Trade contracts to obey\n *\n * Usage: if (canSettle()) settle()\n */\ninterface ITrade is IVersioned {\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    function sell() external view returns (IERC20Metadata);\n\n    function buy() external view returns (IERC20Metadata);\n\n    /// @return {tok} The sell amount of the trade, in whole tokens\n    function sellAmount() external view returns (uint192);\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    /// @return TradeKind.DUTCH_AUCTION or TradeKind.BATCH_AUCTION\n    // solhint-disable-next-line func-name-mixedcase\n    function KIND() external view returns (TradeKind);\n}\n"},{"file_path":"@openzeppelin/contracts/interfaces/IERC1271.sol","source_code":"// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts v4.4.1 (interfaces/IERC1271.sol)\n\npragma solidity ^0.8.0;\n\n/**\n * @dev Interface of the ERC1271 standard signature validation method for\n * contracts as defined in https://eips.ethereum.org/EIPS/eip-1271[ERC-1271].\n *\n * _Available since v4.1._\n */\ninterface IERC1271 {\n    /**\n     * @dev Should return whether the signature provided is valid for the provided data\n     * @param hash      Hash of the data to be signed\n     * @param signature Signature byte array associated with _data\n     */\n    function isValidSignature(bytes32 hash, bytes memory signature) external view returns (bytes4 magicValue);\n}\n"},{"file_path":"@openzeppelin/contracts/access/AccessControlEnumerable.sol","source_code":"// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.5.0) (access/AccessControlEnumerable.sol)\n\npragma solidity ^0.8.0;\n\nimport \"./IAccessControlEnumerable.sol\";\nimport \"./AccessControl.sol\";\nimport \"../utils/structs/EnumerableSet.sol\";\n\n/**\n * @dev Extension of {AccessControl} that allows enumerating the members of each role.\n */\nabstract contract AccessControlEnumerable is IAccessControlEnumerable, AccessControl {\n    using EnumerableSet for EnumerableSet.AddressSet;\n\n    mapping(bytes32 => EnumerableSet.AddressSet) private _roleMembers;\n\n    /**\n     * @dev See {IERC165-supportsInterface}.\n     */\n    function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {\n        return interfaceId == type(IAccessControlEnumerable).interfaceId || super.supportsInterface(interfaceId);\n    }\n\n    /**\n     * @dev Returns one of the accounts that have `role`. `index` must be a\n     * value between 0 and {getRoleMemberCount}, non-inclusive.\n     *\n     * Role bearers are not sorted in any particular way, and their ordering may\n     * change at any point.\n     *\n     * WARNING: When using {getRoleMember} and {getRoleMemberCount}, make sure\n     * you perform all queries on the same block. See the following\n     * https://forum.openzeppelin.com/t/iterating-over-elements-on-enumerableset-in-openzeppelin-contracts/2296[forum post]\n     * for more information.\n     */\n    function getRoleMember(bytes32 role, uint256 index) public view virtual override returns (address) {\n        return _roleMembers[role].at(index);\n    }\n\n    /**\n     * @dev Returns the number of accounts that have `role`. Can be used\n     * together with {getRoleMember} to enumerate all bearers of a role.\n     */\n    function getRoleMemberCount(bytes32 role) public view virtual override returns (uint256) {\n        return _roleMembers[role].length();\n    }\n\n    /**\n     * @dev Overload {_grantRole} to track enumerable memberships\n     */\n    function _grantRole(bytes32 role, address account) internal virtual override {\n        super._grantRole(role, account);\n        _roleMembers[role].add(account);\n    }\n\n    /**\n     * @dev Overload {_revokeRole} to track enumerable memberships\n     */\n    function _revokeRole(bytes32 role, address account) internal virtual override {\n        super._revokeRole(role, account);\n        _roleMembers[role].remove(account);\n    }\n}\n"},{"file_path":"contracts/registry/DAOFeeRegistry.sol","source_code":"// SPDX-License-Identifier: BlueOak-1.0.0\npragma solidity 0.8.28;\n\nimport { RoleRegistry } from \"./RoleRegistry.sol\";\n\nuint256 constant MAX_FEE_NUMERATOR = 15_00; // Max DAO Fee: 15%\nuint256 constant FEE_DENOMINATOR = 100_00;\n\ncontract DAOFeeRegistry {\n    RoleRegistry public roleRegistry;\n\n    address private feeRecipient;\n    uint256 private defaultFeeNumerator; // 0%\n\n    mapping(address => uint256) private rTokenFeeNumerator;\n    mapping(address => bool) private rTokenFeeSet;\n\n    error DAOFeeRegistry__FeeRecipientAlreadySet();\n    error DAOFeeRegistry__InvalidFeeRecipient();\n    error DAOFeeRegistry__InvalidFeeNumerator();\n    error DAOFeeRegistry__InvalidRoleRegistry();\n    error DAOFeeRegistry__InvalidCaller();\n\n    event FeeRecipientSet(address indexed feeRecipient);\n    event DefaultFeeNumeratorSet(uint256 defaultFeeNumerator);\n    event RTokenFeeNumeratorSet(address indexed rToken, uint256 feeNumerator, bool isActive);\n\n    modifier onlyOwner() {\n        if (!roleRegistry.isOwner(msg.sender)) {\n            revert DAOFeeRegistry__InvalidCaller();\n        }\n        _;\n    }\n\n    constructor(RoleRegistry _roleRegistry, address _feeRecipient) {\n        if (address(_roleRegistry) == address(0)) {\n            revert DAOFeeRegistry__InvalidRoleRegistry();\n        }\n\n        roleRegistry = _roleRegistry;\n        feeRecipient = _feeRecipient;\n    }\n\n    function setFeeRecipient(address feeRecipient_) external onlyOwner {\n        if (feeRecipient_ == address(0)) {\n            revert DAOFeeRegistry__InvalidFeeRecipient();\n        }\n        if (feeRecipient_ == feeRecipient) {\n            revert DAOFeeRegistry__FeeRecipientAlreadySet();\n        }\n\n        feeRecipient = feeRecipient_;\n        emit FeeRecipientSet(feeRecipient_);\n    }\n\n    function setDefaultFeeNumerator(uint256 feeNumerator_) external onlyOwner {\n        if (feeNumerator_ > MAX_FEE_NUMERATOR) {\n            revert DAOFeeRegistry__InvalidFeeNumerator();\n        }\n\n        defaultFeeNumerator = feeNumerator_;\n        emit DefaultFeeNumeratorSet(defaultFeeNumerator);\n    }\n\n    /// @dev A fee below 1% not recommended due to poor precision in the Distributor\n    function setRTokenFeeNumerator(address rToken, uint256 feeNumerator_) external onlyOwner {\n        if (feeNumerator_ > MAX_FEE_NUMERATOR) {\n            revert DAOFeeRegistry__InvalidFeeNumerator();\n        }\n\n        rTokenFeeNumerator[rToken] = feeNumerator_;\n        rTokenFeeSet[rToken] = true;\n        emit RTokenFeeNumeratorSet(rToken, feeNumerator_, true);\n    }\n\n    function resetRTokenFee(address rToken) external onlyOwner {\n        rTokenFeeNumerator[rToken] = 0;\n        rTokenFeeSet[rToken] = false;\n\n        emit RTokenFeeNumeratorSet(rToken, 0, false);\n    }\n\n    function getFeeDetails(address rToken)\n        external\n        view\n        returns (\n            address recipient,\n            uint256 feeNumerator,\n            uint256 feeDenominator\n        )\n    {\n        recipient = feeRecipient;\n        feeNumerator = rTokenFeeSet[rToken] ? rTokenFeeNumerator[rToken] : defaultFeeNumerator;\n        feeDenominator = FEE_DENOMINATOR;\n    }\n}\n"},{"file_path":"@openzeppelin/contracts/access/IAccessControlEnumerable.sol","source_code":"// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts v4.4.1 (access/IAccessControlEnumerable.sol)\n\npragma solidity ^0.8.0;\n\nimport \"./IAccessControl.sol\";\n\n/**\n * @dev External interface of AccessControlEnumerable declared to support ERC165 detection.\n */\ninterface IAccessControlEnumerable is IAccessControl {\n    /**\n     * @dev Returns one of the accounts that have `role`. `index` must be a\n     * value between 0 and {getRoleMemberCount}, non-inclusive.\n     *\n     * Role bearers are not sorted in any particular way, and their ordering may\n     * change at any point.\n     *\n     * WARNING: When using {getRoleMember} and {getRoleMemberCount}, make sure\n     * you perform all queries on the same block. See the following\n     * https://forum.openzeppelin.com/t/iterating-over-elements-on-enumerableset-in-openzeppelin-contracts/2296[forum post]\n     * for more information.\n     */\n    function getRoleMember(bytes32 role, uint256 index) external view returns (address);\n\n    /**\n     * @dev Returns the number of accounts that have `role`. Can be used\n     * together with {getRoleMember} to enumerate all bearers of a role.\n     */\n    function getRoleMemberCount(bytes32 role) external view returns (uint256);\n}\n"},{"file_path":"contracts/registry/RoleRegistry.sol","source_code":"// SPDX-License-Identifier: BlueOak-1.0.0\npragma solidity 0.8.28;\n\n// solhint-disable-next-line max-line-length\nimport { AccessControlEnumerable } from \"@openzeppelin/contracts/access/AccessControlEnumerable.sol\";\n\n/**\n * @title RoleRegistry\n * @notice Contract to manage roles for RToken <> DAO interactions\n */\ncontract RoleRegistry is AccessControlEnumerable {\n    bytes32 public constant EMERGENCY_COUNCIL = keccak256(\"EMERGENCY_COUNCIL\");\n\n    constructor() {\n        _setupRole(DEFAULT_ADMIN_ROLE, msg.sender);\n    }\n\n    function isOwner(address account) public view returns (bool) {\n        return hasRole(DEFAULT_ADMIN_ROLE, account);\n    }\n\n    function isEmergencyCouncil(address account) public view returns (bool) {\n        return hasRole(EMERGENCY_COUNCIL, account);\n    }\n\n    function isOwnerOrEmergencyCouncil(address account) public view returns (bool) {\n        return hasRole(DEFAULT_ADMIN_ROLE, account) || hasRole(EMERGENCY_COUNCIL, account);\n    }\n}\n"},{"file_path":"@openzeppelin/contracts-upgradeable/token/ERC20/extensions/IERC20MetadataUpgradeable.sol","source_code":"// 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"},{"file_path":"contracts/registry/AssetPluginRegistry.sol","source_code":"// SPDX-License-Identifier: BlueOak-1.0.0\npragma solidity 0.8.28;\n\nimport { Ownable } from \"@openzeppelin/contracts/access/Ownable.sol\";\nimport { VersionRegistry } from \"./VersionRegistry.sol\";\nimport { RoleRegistry } from \"./RoleRegistry.sol\";\n\n/**\n * @title Asset Plugin Registry\n * @notice A tiny contract for tracking asset plugins\n */\ncontract AssetPluginRegistry {\n    VersionRegistry public versionRegistry;\n    RoleRegistry public roleRegistry;\n    // versionHash => asset => isValid\n    mapping(bytes32 => mapping(address => bool)) private _isValidAsset;\n    mapping(address => bool) public isDeprecated;\n\n    error AssetPluginRegistry__InvalidAsset();\n    error AssetPluginRegistry__InvalidCaller();\n    error AssetPluginRegistry__InvalidVersion();\n    error AssetPluginRegistry__LengthMismatch();\n\n    event AssetPluginRegistryUpdated(bytes32 versionHash, address asset, bool validity);\n\n    constructor(address _versionRegistry) {\n        versionRegistry = VersionRegistry(_versionRegistry);\n        roleRegistry = versionRegistry.roleRegistry();\n    }\n\n    function registerAsset(address _asset, bytes32[] calldata validForVersions) external {\n        if (!roleRegistry.isOwner(msg.sender)) {\n            revert AssetPluginRegistry__InvalidCaller();\n        }\n        if (_asset == address(0)) {\n            revert AssetPluginRegistry__InvalidAsset();\n        }\n\n        for (uint256 i = 0; i < validForVersions.length; ++i) {\n            bytes32 versionHash = validForVersions[i];\n            if (address(versionRegistry.deployments(versionHash)) == address(0)) {\n                revert AssetPluginRegistry__InvalidVersion();\n            }\n\n            _isValidAsset[versionHash][_asset] = true;\n\n            emit AssetPluginRegistryUpdated(versionHash, _asset, true);\n        }\n    }\n\n    function updateVersionsByAsset(\n        address _asset,\n        bytes32[] calldata _versionHashes,\n        bool[] calldata _validities\n    ) external {\n        if (!roleRegistry.isOwner(msg.sender)) {\n            revert AssetPluginRegistry__InvalidCaller();\n        }\n        if (_versionHashes.length != _validities.length) {\n            revert AssetPluginRegistry__LengthMismatch();\n        }\n\n        if (_asset == address(0)) {\n            revert AssetPluginRegistry__InvalidAsset();\n        }\n\n        for (uint256 i = 0; i < _versionHashes.length; ++i) {\n            bytes32 versionHash = _versionHashes[i];\n            if (address(versionRegistry.deployments(versionHash)) == address(0)) {\n                revert AssetPluginRegistry__InvalidVersion();\n            }\n\n            _isValidAsset[versionHash][_asset] = _validities[i];\n\n            emit AssetPluginRegistryUpdated(versionHash, _asset, _validities[i]);\n        }\n    }\n\n    function updateAssetsByVersion(\n        bytes32 _versionHash,\n        address[] calldata _assets,\n        bool[] calldata _validities\n    ) external {\n        if (!roleRegistry.isOwner(msg.sender)) {\n            revert AssetPluginRegistry__InvalidCaller();\n        }\n        if (_assets.length != _validities.length) {\n            revert AssetPluginRegistry__LengthMismatch();\n        }\n\n        if (address(versionRegistry.deployments(_versionHash)) == address(0)) {\n            revert AssetPluginRegistry__InvalidVersion();\n        }\n\n        for (uint256 i = 0; i < _assets.length; ++i) {\n            address asset = _assets[i];\n            if (asset == address(0)) {\n                revert AssetPluginRegistry__InvalidAsset();\n            }\n\n            _isValidAsset[_versionHash][asset] = _validities[i];\n\n            emit AssetPluginRegistryUpdated(_versionHash, asset, _validities[i]);\n        }\n    }\n\n    function deprecateAsset(address _asset) external {\n        if (!roleRegistry.isOwnerOrEmergencyCouncil(msg.sender)) {\n            revert AssetPluginRegistry__InvalidCaller();\n        }\n\n        isDeprecated[_asset] = true;\n    }\n\n    function isValidAsset(bytes32 _versionHash, address _asset) external view returns (bool) {\n        if (!isDeprecated[_asset]) {\n            return _isValidAsset[_versionHash][_asset];\n        }\n\n        return false;\n    }\n}\n"},{"file_path":"contracts/interfaces/IAsset.sol","source_code":"// SPDX-License-Identifier: BlueOak-1.0.0\npragma solidity 0.8.28;\n\nimport \"@chainlink/contracts/src/v0.8/interfaces/AggregatorV3Interface.sol\";\nimport \"@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol\";\nimport \"../libraries/Fixed.sol\";\nimport \"./IMain.sol\";\nimport \"./IRewardable.sol\";\n\n// Not used directly in the IAsset interface, but used by many consumers to save stack space\nstruct Price {\n    uint192 low; // {UoA/tok}\n    uint192 high; // {UoA/tok}\n}\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 is IRewardable {\n    /// Refresh saved price\n    /// The Reserve protocol calls this at least once per transaction, before relying on\n    /// the Asset's other functions.\n    /// @dev Called immediately after deployment, before use\n    function refresh() external;\n\n    /// Should not revert\n    /// low should be nonzero if the asset could be worth selling\n    /// @return low {UoA/tok} The lower end of the price estimate\n    /// @return high {UoA/tok} The upper end of the price estimate\n    function price() external view returns (uint192 low, uint192 high);\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    /// @return {UoA} The max trade volume, in UoA\n    function maxTradeVolume() external view returns (uint192);\n\n    /// @return {s} The timestamp of the last refresh() that saved prices\n    function lastSave() external view returns (uint48);\n}\n\n// Used only in Testing. Strictly speaking an Asset does not need to adhere to this interface\ninterface TestIAsset is IAsset {\n    /// @return The address of the chainlink feed\n    function chainlinkFeed() external view returns (AggregatorV3Interface);\n\n    /// {1} The max % deviation allowed by the oracle\n    function oracleError() external view returns (uint192);\n\n    /// @return {s} Seconds that an oracle value is considered valid\n    function oracleTimeout() external view returns (uint48);\n\n    /// @return {s} The maximum of all oracle timeouts on the plugin\n    function maxOracleTimeout() external view returns (uint48);\n\n    /// @return {s} Seconds that the price() should decay over, after stale price\n    function priceTimeout() external view returns (uint48);\n\n    /// @return {UoA/tok} The last saved low price\n    function savedLowPrice() external view returns (uint192);\n\n    /// @return {UoA/tok} The last saved high price\n    function savedHighPrice() external view returns (uint192);\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 CollateralStatusChanged(\n        CollateralStatus indexed oldStatus,\n        CollateralStatus indexed newStatus\n    );\n\n    /// @dev refresh()\n    /// Refresh exchange rates and update default status.\n    /// VERY IMPORTANT: In any valid implementation, status() MUST become DISABLED in refresh() if\n    /// refPerTok() has ever decreased since last call.\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 {target/ref} The peg price of the token during the last update\n    function savedPegPrice() external view returns (uint192);\n}\n\n// Used only in Testing. Strictly speaking a Collateral does not need to adhere to this interface\ninterface TestICollateral is TestIAsset, ICollateral {\n    /// @return The epoch timestamp when the collateral will default from IFFY to DISABLED\n    function whenDefault() external view returns (uint256);\n\n    /// @return The amount of time a collateral must be in IFFY status until being DISABLED\n    function delayUntilDefault() external view returns (uint48);\n\n    /// @return The underlying refPerTok, likely not included in all collaterals however.\n    function underlyingRefPerTok() external view returns (uint192);\n}\n"},{"file_path":"contracts/interfaces/IStRSR.sol","source_code":"// SPDX-License-Identifier: BlueOak-1.0.0\npragma solidity 0.8.28;\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 \"../libraries/Fixed.sol\";\nimport \"./IComponent.sol\";\n\n/**\n * @title IStRSR\n * @notice An ERC20 token representing shares of the RSR over-collateralization 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    error InsufficientBalance();\n    error IndexOutOfBounds();\n    error WithdrawalUnavailable();\n    error RTokenNotReady();\n    error NotBackingManager();\n    error SeizeExceedsBalance();\n    error RatesStillSafe();\n    error DecreaseAllowanceError();\n    error InsufficientAllowance();\n    error TransferToSelf();\n    error ZeroAddress();\n    error ZeroAmount();\n    error ExpiredDeadline();\n    error InvalidUnstakingDelay();\n    error InvalidRewardRatio();\n    error InvalidWithdrawalLeak();\n    error SignatureExpired();\n    error InvalidNonce();\n    error FutureLookup();\n    error NameEmpty();\n    error SymbolEmpty();\n\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 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 when RSR unstaking is cancelled\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 UnstakingCancelled(\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 oldVal, uint192 newVal);\n\n    /// Emitted whenever RSR are paids out\n    event RewardsPaid(uint256 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 oldVal, uint48 newVal);\n    event RewardRatioSet(uint192 oldVal, uint192 newVal);\n    event WithdrawalLeakSet(uint192 oldVal, uint192 newVal);\n\n    // Initialization\n    function init(\n        IMain main_,\n        string memory name_,\n        string memory symbol_,\n        uint48 unstakingDelay_,\n        uint192 rewardRatio_,\n        uint192 withdrawalLeak_\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 over-collateralized\n    /// 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    /// Cancel unstaking for the account, up to (but not including!) `endId`\n    /// @custom:interaction\n    function cancelUnstake(uint256 endId) external;\n\n    /// Seize RSR, only callable by main.backingManager()\n    /// @custom:protected\n    function seizeRSR(uint256 amount) external;\n\n    /// Reset all stakes and advance era\n    /// @custom:governance\n    function resetStakes() 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 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 withdrawalLeak() external view returns (uint192);\n\n    function setWithdrawalLeak(uint192) 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"},{"file_path":"@openzeppelin/contracts-upgradeable/utils/cryptography/SignatureCheckerUpgradeable.sol","source_code":"// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.9.0) (utils/cryptography/SignatureChecker.sol)\n\npragma solidity ^0.8.0;\n\nimport \"./ECDSAUpgradeable.sol\";\nimport \"../../interfaces/IERC1271Upgradeable.sol\";\n\n/**\n * @dev Signature verification helper that can be used instead of `ECDSA.recover` to seamlessly support both ECDSA\n * signatures from externally owned accounts (EOAs) as well as ERC1271 signatures from smart contract wallets like\n * Argent and Gnosis Safe.\n *\n * _Available since v4.1._\n */\nlibrary SignatureCheckerUpgradeable {\n    /**\n     * @dev Checks if a signature is valid for a given signer and data hash. If the signer is a smart contract, the\n     * signature is validated against that smart contract using ERC1271, otherwise it's validated using `ECDSA.recover`.\n     *\n     * NOTE: Unlike ECDSA signatures, contract signatures are revocable, and the outcome of this function can thus\n     * change through time. It could return true at block N and false at block N+1 (or the opposite).\n     */\n    function isValidSignatureNow(address signer, bytes32 hash, bytes memory signature) internal view returns (bool) {\n        (address recovered, ECDSAUpgradeable.RecoverError error) = ECDSAUpgradeable.tryRecover(hash, signature);\n        return\n            (error == ECDSAUpgradeable.RecoverError.NoError && recovered == signer) ||\n            isValidERC1271SignatureNow(signer, hash, signature);\n    }\n\n    /**\n     * @dev Checks if a signature is valid for a given signer and data hash. The signature is validated\n     * against the signer smart contract using ERC1271.\n     *\n     * NOTE: Unlike ECDSA signatures, contract signatures are revocable, and the outcome of this function can thus\n     * change through time. It could return true at block N and false at block N+1 (or the opposite).\n     */\n    function isValidERC1271SignatureNow(\n        address signer,\n        bytes32 hash,\n        bytes memory signature\n    ) internal view returns (bool) {\n        (bool success, bytes memory result) = signer.staticcall(\n            abi.encodeWithSelector(IERC1271Upgradeable.isValidSignature.selector, hash, signature)\n        );\n        return (success &&\n            result.length >= 32 &&\n            abi.decode(result, (bytes32)) == bytes32(IERC1271Upgradeable.isValidSignature.selector));\n    }\n}\n"},{"file_path":"contracts/interfaces/IFurnace.sol","source_code":"// SPDX-License-Identifier: BlueOak-1.0.0\npragma solidity 0.8.28;\n\nimport \"../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(IMain main_, uint192 ratio_) 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 oldRatio, uint192 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"},{"file_path":"contracts/interfaces/IBroker.sol","source_code":"// SPDX-License-Identifier: BlueOak-1.0.0\npragma solidity 0.8.28;\n\nimport \"@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol\";\nimport \"@reserve-protocol/trusted-fillers/contracts/interfaces/ITrustedFillerRegistry.sol\";\nimport \"./IAsset.sol\";\nimport \"./IComponent.sol\";\nimport \"./IGnosis.sol\";\nimport \"./ITrade.sol\";\n\nenum TradeKind {\n    DUTCH_AUCTION,\n    BATCH_AUCTION\n}\n\n/// Cache of all prices for a pair to prevent re-lookup\nstruct TradePrices {\n    uint192 sellLow; // {UoA/sellTok} can be 0\n    uint192 sellHigh; // {UoA/sellTok} should not be 0\n    uint192 buyLow; // {UoA/buyTok} should not be 0\n    uint192 buyHigh; // {UoA/buyTok} should not be 0 or FIX_MAX\n}\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 BatchTradeImplementationSet(ITrade oldVal, ITrade newVal);\n    event DutchTradeImplementationSet(ITrade oldVal, ITrade newVal);\n    event BatchAuctionLengthSet(uint48 oldVal, uint48 newVal);\n    event DutchAuctionLengthSet(uint48 oldVal, uint48 newVal);\n    event BatchTradeDisabledSet(bool prevVal, bool newVal);\n    event DutchTradeDisabledSet(IERC20Metadata indexed erc20, bool prevVal, bool newVal);\n    event TrustedFillerRegistrySet(address trustedFillerRegistry, bool isEnabled);\n\n    // Initialization\n    function init(\n        IMain main_,\n        ITrade batchTradeImplemention_,\n        uint48 batchAuctionLength_,\n        ITrade dutchTradeImplemention_,\n        uint48 dutchAuctionLength_\n    ) external;\n\n    /// Request a trade from the broker\n    /// @dev Requires setting an allowance in advance\n    /// @custom:interaction\n    function openTrade(\n        TradeKind kind,\n        TradeRequest memory req,\n        TradePrices memory prices\n    ) external returns (ITrade);\n\n    /// Only callable by one of the trading contracts the broker deploys\n    function reportViolation() external;\n\n    function batchTradeDisabled() external view returns (bool);\n\n    function dutchTradeDisabled(IERC20Metadata erc20) external view returns (bool);\n}\n\ninterface IExtendedBroker is IBroker {\n    function setBatchTradeImplementation(ITrade newTradeImplementation) external;\n\n    function setDutchTradeImplementation(ITrade newTradeImplementation) external;\n\n    function setTrustedFillerRegistry(address newRegistry, bool enabled) external;\n\n    function trustedFillerRegistry() external view returns (ITrustedFillerRegistry);\n\n    function trustedFillerEnabled() external view returns (bool);\n}\n\ninterface TestIBroker is IBroker {\n    function gnosis() external view returns (IGnosis);\n\n    function batchTradeImplementation() external view returns (ITrade);\n\n    function dutchTradeImplementation() external view returns (ITrade);\n\n    function batchAuctionLength() external view returns (uint48);\n\n    function dutchAuctionLength() external view returns (uint48);\n\n    function setBatchTradeImplementation(ITrade newTradeImplementation) external;\n\n    function setBatchAuctionLength(uint48 newAuctionLength) external;\n\n    function setDutchTradeImplementation(ITrade newTradeImplementation) external;\n\n    function setDutchAuctionLength(uint48 newAuctionLength) external;\n\n    function enableBatchTrade() external;\n\n    function enableDutchTrade(IERC20Metadata erc20) external;\n\n    // only present on pre-3.0.0 Brokers; used by EasyAuction regression test\n    function disabled() external view returns (bool);\n\n    function setTrustedFillerRegistry(address newRegistry, bool enabled) external;\n\n    function trustedFillerRegistry() external view returns (ITrustedFillerRegistry);\n\n    function trustedFillerEnabled() external view returns (bool);\n}\n"},{"file_path":"@openzeppelin/contracts/utils/Context.sol","source_code":"// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.9.4) (utils/Context.sol)\n\npragma solidity ^0.8.0;\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 Context {\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    function _contextSuffixLength() internal view virtual returns (uint256) {\n        return 0;\n    }\n}\n"},{"file_path":"@openzeppelin/contracts-upgradeable/token/ERC20/extensions/draft-IERC20PermitUpgradeable.sol","source_code":"// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.9.0) (token/ERC20/extensions/draft-IERC20Permit.sol)\n\npragma solidity ^0.8.0;\n\n// EIP-2612 is Final as of 2022-11-01. This file is deprecated.\n\nimport \"./IERC20PermitUpgradeable.sol\";\n"},{"file_path":"@openzeppelin/contracts-upgradeable/utils/cryptography/draft-EIP712Upgradeable.sol","source_code":"// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.8.0) (utils/cryptography/draft-EIP712.sol)\n\npragma solidity ^0.8.0;\n\n// EIP-712 is Final as of 2022-08-11. This file is deprecated.\n\nimport \"./EIP712Upgradeable.sol\";\n"},{"file_path":"@openzeppelin/contracts/token/ERC20/IERC20.sol","source_code":"// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.9.0) (token/ERC20/IERC20.sol)\n\npragma solidity ^0.8.0;\n\n/**\n * @dev Interface of the ERC20 standard as defined in the EIP.\n */\ninterface 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(address from, address to, uint256 amount) external returns (bool);\n}\n"},{"file_path":"@openzeppelin/contracts/utils/math/SignedMath.sol","source_code":"// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.8.0) (utils/math/SignedMath.sol)\n\npragma solidity ^0.8.0;\n\n/**\n * @dev Standard signed math utilities missing in the Solidity language.\n */\nlibrary SignedMath {\n    /**\n     * @dev Returns the largest of two signed numbers.\n     */\n    function max(int256 a, int256 b) internal pure returns (int256) {\n        return a > b ? a : b;\n    }\n\n    /**\n     * @dev Returns the smallest of two signed numbers.\n     */\n    function min(int256 a, int256 b) internal pure returns (int256) {\n        return a < b ? a : b;\n    }\n\n    /**\n     * @dev Returns the average of two signed numbers without overflow.\n     * The result is rounded towards zero.\n     */\n    function average(int256 a, int256 b) internal pure returns (int256) {\n        // Formula from the book \"Hacker's Delight\"\n        int256 x = (a & b) + ((a ^ b) >> 1);\n        return x + (int256(uint256(x) >> 255) & (a ^ b));\n    }\n\n    /**\n     * @dev Returns the absolute unsigned value of a signed value.\n     */\n    function abs(int256 n) internal pure returns (uint256) {\n        unchecked {\n            // must be unchecked in order to support `n = type(int256).min`\n            return uint256(n >= 0 ? n : -n);\n        }\n    }\n}\n"},{"file_path":"contracts/interfaces/IGnosis.sol","source_code":"// SPDX-License-Identifier: BlueOak-1.0.0\npragma solidity 0.8.28;\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"},{"file_path":"contracts/interfaces/IDeployer.sol","source_code":"// SPDX-License-Identifier: BlueOak-1.0.0\npragma solidity 0.8.28;\n\nimport \"@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol\";\nimport \"../libraries/Throttle.sol\";\nimport \"./IAsset.sol\";\nimport \"./IDistributor.sol\";\nimport \"./IGnosis.sol\";\nimport \"./IMain.sol\";\nimport \"./IRToken.sol\";\nimport \"./IStRSR.sol\";\nimport \"./ITrade.sol\";\nimport \"./IVersioned.sol\";\n\nimport \"../registry/VersionRegistry.sol\";\nimport \"../registry/AssetPluginRegistry.sol\";\nimport \"../registry/DAOFeeRegistry.sol\";\nimport \"@reserve-protocol/trusted-fillers/contracts/interfaces/ITrustedFillerRegistry.sol\";\n\n/**\n * @title DeploymentParams\n * @notice The set of protocol params needed to configure a new system deployment.\n * meaning that after deployment there is freedom to allow parametrizations to deviate.\n */\nstruct DeploymentParams {\n    // === Revenue sharing ===\n    RevenueShare dist; // revenue sharing splits between RToken and RSR\n    //\n    // === Trade sizing ===\n    uint192 minTradeVolume; // {UoA}\n    uint192 rTokenMaxTradeVolume; // {UoA}\n    //\n    // === Freezing ===\n    uint48 shortFreeze; // {s} how long an initial freeze lasts\n    uint48 longFreeze; // {s} how long each freeze extension lasts\n    //\n    // === Rewards (Furnace + StRSR) ===\n    uint192 rewardRatio; // the fraction of available revenues that are paid out each block period\n    //\n    // === StRSR ===\n    uint48 unstakingDelay; // {s} the \"thawing time\" of staked RSR before withdrawal\n    uint192 withdrawalLeak; // {1} fraction of RSR that can be withdrawn without refresh\n    //\n    // === BasketHandler ===\n    uint48 warmupPeriod; // {s} how long to wait until issuance/trading after regaining SOUND\n    bool reweightable; // whether the target amounts in the prime basket can change\n    bool enableIssuancePremium; // whether to enable the issuance premium\n    //\n    // === BackingManager ===\n    uint48 tradingDelay; // {s} how long to wait until starting auctions after switching basket\n    uint48 batchAuctionLength; // {s} the length of a Gnosis EasyAuction\n    uint48 dutchAuctionLength; // {s} the length of a falling-price dutch auction\n    uint192 backingBuffer; // {1} how much extra backing collateral to keep\n    uint192 maxTradeSlippage; // {1} max slippage acceptable in a trade\n    //\n    // === RToken Supply Throttles ===\n    ThrottleLib.Params issuanceThrottle; // see ThrottleLib\n    ThrottleLib.Params redemptionThrottle;\n}\n\n/**\n * @title Implementations\n * @notice The set of implementation contracts to be used for proxies in the Deployer\n */\nstruct Implementations {\n    IMain main;\n    Components components;\n    TradePlugins trading;\n}\n\nstruct TradePlugins {\n    ITrade gnosisTrade;\n    ITrade dutchTrade;\n}\n\n/**\n * @title IDeployer\n * @notice Factory contract for an RToken system instance\n */\ninterface IDeployer is IVersioned {\n    /// Emitted when a new RToken and accompanying system is deployed\n    /// @param main The address of `Main`\n    /// @param rToken The address of the RToken ERC20\n    /// @param stRSR The address of the StRSR ERC20 staking pool/token\n    /// @param owner The owner of the newly deployed system\n    /// @param version The semantic versioning version string (see: https://semver.org)\n    event RTokenCreated(\n        IMain indexed main,\n        IRToken indexed rToken,\n        IStRSR stRSR,\n        address indexed owner,\n        string version\n    );\n\n    /// Emitted when a new RTokenAsset is deployed during `deployRTokenAsset`\n    /// @param rToken The address of the RToken ERC20\n    /// @param rTokenAsset The address of the RTokenAsset\n    event RTokenAssetCreated(IRToken indexed rToken, IAsset rTokenAsset);\n\n    struct Registries {\n        VersionRegistry versionRegistry;\n        AssetPluginRegistry assetPluginRegistry;\n        DAOFeeRegistry daoFeeRegistry;\n        ITrustedFillerRegistry trustedFillerRegistry;\n    }\n\n    /// Deploys an instance of the entire system\n    /// @param name The name of the RToken to deploy\n    /// @param symbol The symbol of the RToken to deploy\n    /// @param mandate An IPFS link or direct string; describes what the RToken _should be_\n    /// @param owner The address that should own the entire system, hopefully a governance contract\n    /// @param params Deployment params\n    /// @param registries Registries list; can be 0 to unset\n    /// @return The address of the newly deployed Main instance.\n    function deploy(\n        string calldata name,\n        string calldata symbol,\n        string calldata mandate,\n        address owner,\n        DeploymentParams calldata params,\n        Registries calldata registries\n    ) external returns (address);\n\n    function implementations() external view returns (Implementations memory);\n}\n"},{"file_path":"@openzeppelin/contracts-upgradeable/proxy/beacon/IBeaconUpgradeable.sol","source_code":"// 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"},{"file_path":"@reserve-protocol/trusted-fillers/contracts/interfaces/IBaseTrustedFiller.sol","source_code":"// SPDX-License-Identifier: MIT\npragma solidity ^0.8.19;\n\nimport { IERC20 } from \"@openzeppelin/contracts/token/ERC20/IERC20.sol\";\nimport { IERC1271 } from \"@openzeppelin/contracts/interfaces/IERC1271.sol\";\n\ninterface IBaseTrustedFiller is IERC1271 {\n    error BaseTrustedFiller__SwapActive();\n\n    function initialize(\n        address _creator,\n        IERC20 _sellToken,\n        IERC20 _buyToken,\n        uint256 _sellAmount,\n        uint256 _minBuyAmount\n    ) external;\n\n    function buyToken() external view returns (IERC20);\n\n    function sellToken() external view returns (IERC20);\n\n    function swapActive() external view returns (bool);\n\n    function closeFiller() external;\n\n    function rescueToken(IERC20 token) external;\n\n    function setPartiallyFillable(bool _partiallyFillable) external;\n}\n"},{"file_path":"@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol","source_code":"// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.9.0) (proxy/utils/UUPSUpgradeable.sol)\n\npragma solidity ^0.8.0;\n\nimport \"../../interfaces/draft-IERC1822Upgradeable.sol\";\nimport \"../ERC1967/ERC1967UpgradeUpgradeable.sol\";\nimport {Initializable} from \"./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    /// @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    function __UUPSUpgradeable_init() internal onlyInitializing {\n    }\n\n    function __UUPSUpgradeable_init_unchained() internal onlyInitializing {\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 the implementation's compatibility when performing 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     * @custom:oz-upgrades-unsafe-allow-reachable delegatecall\n     */\n    function upgradeTo(address newImplementation) public 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     * @custom:oz-upgrades-unsafe-allow-reachable delegatecall\n     */\n    function upgradeToAndCall(address newImplementation, bytes memory data) public 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"},{"file_path":"contracts/interfaces/IVersioned.sol","source_code":"// SPDX-License-Identifier: BlueOak-1.0.0\npragma solidity 0.8.28;\n\ninterface IVersioned {\n    function version() external view returns (string memory);\n}\n"},{"file_path":"@openzeppelin/contracts-upgradeable/utils/StringsUpgradeable.sol","source_code":"// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.9.0) (utils/Strings.sol)\n\npragma solidity ^0.8.0;\n\nimport \"./math/MathUpgradeable.sol\";\nimport \"./math/SignedMathUpgradeable.sol\";\n\n/**\n * @dev String operations.\n */\nlibrary StringsUpgradeable {\n    bytes16 private constant _SYMBOLS = \"0123456789abcdef\";\n    uint8 private constant _ADDRESS_LENGTH = 20;\n\n    /**\n     * @dev Converts a `uint256` to its ASCII `string` decimal representation.\n     */\n    function toString(uint256 value) internal pure returns (string memory) {\n        unchecked {\n            uint256 length = MathUpgradeable.log10(value) + 1;\n            string memory buffer = new string(length);\n            uint256 ptr;\n            /// @solidity memory-safe-assembly\n            assembly {\n                ptr := add(buffer, add(32, length))\n            }\n            while (true) {\n                ptr--;\n                /// @solidity memory-safe-assembly\n                assembly {\n                    mstore8(ptr, byte(mod(value, 10), _SYMBOLS))\n                }\n                value /= 10;\n                if (value == 0) break;\n            }\n            return buffer;\n        }\n    }\n\n    /**\n     * @dev Converts a `int256` to its ASCII `string` decimal representation.\n     */\n    function toString(int256 value) internal pure returns (string memory) {\n        return string(abi.encodePacked(value < 0 ? \"-\" : \"\", toString(SignedMathUpgradeable.abs(value))));\n    }\n\n    /**\n     * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation.\n     */\n    function toHexString(uint256 value) internal pure returns (string memory) {\n        unchecked {\n            return toHexString(value, MathUpgradeable.log256(value) + 1);\n        }\n    }\n\n    /**\n     * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length.\n     */\n    function toHexString(uint256 value, uint256 length) internal pure returns (string memory) {\n        bytes memory buffer = new bytes(2 * length + 2);\n        buffer[0] = \"0\";\n        buffer[1] = \"x\";\n        for (uint256 i = 2 * length + 1; i > 1; --i) {\n            buffer[i] = _SYMBOLS[value & 0xf];\n            value >>= 4;\n        }\n        require(value == 0, \"Strings: hex length insufficient\");\n        return string(buffer);\n    }\n\n    /**\n     * @dev Converts an `address` with fixed length of 20 bytes to its not checksummed ASCII `string` hexadecimal representation.\n     */\n    function toHexString(address addr) internal pure returns (string memory) {\n        return toHexString(uint256(uint160(addr)), _ADDRESS_LENGTH);\n    }\n\n    /**\n     * @dev Returns true if the two strings are equal.\n     */\n    function equal(string memory a, string memory b) internal pure returns (bool) {\n        return keccak256(bytes(a)) == keccak256(bytes(b));\n    }\n}\n"},{"file_path":"@openzeppelin/contracts/access/AccessControl.sol","source_code":"// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.9.0) (access/AccessControl.sol)\n\npragma solidity ^0.8.0;\n\nimport \"./IAccessControl.sol\";\nimport \"../utils/Context.sol\";\nimport \"../utils/Strings.sol\";\nimport \"../utils/introspection/ERC165.sol\";\n\n/**\n * @dev Contract module that allows children to implement role-based access\n * control mechanisms. This is a lightweight version that doesn't allow enumerating role\n * members except through off-chain means by accessing the contract event logs. Some\n * applications may benefit from on-chain enumerability, for those cases see\n * {AccessControlEnumerable}.\n *\n * Roles are referred to by their `bytes32` identifier. These should be exposed\n * in the external API and be unique. The best way to achieve this is by\n * using `public constant` hash digests:\n *\n * ```solidity\n * bytes32 public constant MY_ROLE = keccak256(\"MY_ROLE\");\n * ```\n *\n * Roles can be used to represent a set of permissions. To restrict access to a\n * function call, use {hasRole}:\n *\n * ```solidity\n * function foo() public {\n *     require(hasRole(MY_ROLE, msg.sender));\n *     ...\n * }\n * ```\n *\n * Roles can be granted and revoked dynamically via the {grantRole} and\n * {revokeRole} functions. Each role has an associated admin role, and only\n * accounts that have a role's admin role can call {grantRole} and {revokeRole}.\n *\n * By default, the admin role for all roles is `DEFAULT_ADMIN_ROLE`, which means\n * that only accounts with this role will be able to grant or revoke other\n * roles. More complex role relationships can be created by using\n * {_setRoleAdmin}.\n *\n * WARNING: The `DEFAULT_ADMIN_ROLE` is also its own admin: it has permission to\n * grant and revoke this role. Extra precautions should be taken to secure\n * accounts that have been granted it. We recommend using {AccessControlDefaultAdminRules}\n * to enforce additional security measures for this role.\n */\nabstract contract AccessControl is Context, IAccessControl, ERC165 {\n    struct RoleData {\n        mapping(address => bool) members;\n        bytes32 adminRole;\n    }\n\n    mapping(bytes32 => RoleData) private _roles;\n\n    bytes32 public constant DEFAULT_ADMIN_ROLE = 0x00;\n\n    /**\n     * @dev Modifier that checks that an account has a specific role. Reverts\n     * with a standardized message including the required role.\n     *\n     * The format of the revert reason is given by the following regular expression:\n     *\n     *  /^AccessControl: account (0x[0-9a-f]{40}) is missing role (0x[0-9a-f]{64})$/\n     *\n     * _Available since v4.1._\n     */\n    modifier onlyRole(bytes32 role) {\n        _checkRole(role);\n        _;\n    }\n\n    /**\n     * @dev See {IERC165-supportsInterface}.\n     */\n    function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {\n        return interfaceId == type(IAccessControl).interfaceId || super.supportsInterface(interfaceId);\n    }\n\n    /**\n     * @dev Returns `true` if `account` has been granted `role`.\n     */\n    function hasRole(bytes32 role, address account) public view virtual override returns (bool) {\n        return _roles[role].members[account];\n    }\n\n    /**\n     * @dev Revert with a standard message if `_msgSender()` is missing `role`.\n     * Overriding this function changes the behavior of the {onlyRole} modifier.\n     *\n     * Format of the revert message is described in {_checkRole}.\n     *\n     * _Available since v4.6._\n     */\n    function _checkRole(bytes32 role) internal view virtual {\n        _checkRole(role, _msgSender());\n    }\n\n    /**\n     * @dev Revert with a standard message if `account` is missing `role`.\n     *\n     * The format of the revert reason is given by the following regular expression:\n     *\n     *  /^AccessControl: account (0x[0-9a-f]{40}) is missing role (0x[0-9a-f]{64})$/\n     */\n    function _checkRole(bytes32 role, address account) internal view virtual {\n        if (!hasRole(role, account)) {\n            revert(\n                string(\n                    abi.encodePacked(\n                        \"AccessControl: account \",\n                        Strings.toHexString(account),\n                        \" is missing role \",\n                        Strings.toHexString(uint256(role), 32)\n                    )\n                )\n            );\n        }\n    }\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 {_setRoleAdmin}.\n     */\n    function getRoleAdmin(bytes32 role) public view virtual override returns (bytes32) {\n        return _roles[role].adminRole;\n    }\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     * May emit a {RoleGranted} event.\n     */\n    function grantRole(bytes32 role, address account) public virtual override onlyRole(getRoleAdmin(role)) {\n        _grantRole(role, account);\n    }\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     * May emit a {RoleRevoked} event.\n     */\n    function revokeRole(bytes32 role, address account) public virtual override onlyRole(getRoleAdmin(role)) {\n        _revokeRole(role, account);\n    }\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 revoked `role`, emits a {RoleRevoked}\n     * event.\n     *\n     * Requirements:\n     *\n     * - the caller must be `account`.\n     *\n     * May emit a {RoleRevoked} event.\n     */\n    function renounceRole(bytes32 role, address account) public virtual override {\n        require(account == _msgSender(), \"AccessControl: can only renounce roles for self\");\n\n        _revokeRole(role, account);\n    }\n\n    /**\n     * @dev Grants `role` to `account`.\n     *\n     * If `account` had not been already granted `role`, emits a {RoleGranted}\n     * event. Note that unlike {grantRole}, this function doesn't perform any\n     * checks on the calling account.\n     *\n     * May emit a {RoleGranted} event.\n     *\n     * [WARNING]\n     * ====\n     * This function should only be called from the constructor when setting\n     * up the initial roles for the system.\n     *\n     * Using this function in any other way is effectively circumventing the admin\n     * system imposed by {AccessControl}.\n     * ====\n     *\n     * NOTE: This function is deprecated in favor of {_grantRole}.\n     */\n    function _setupRole(bytes32 role, address account) internal virtual {\n        _grantRole(role, account);\n    }\n\n    /**\n     * @dev Sets `adminRole` as ``role``'s admin role.\n     *\n     * Emits a {RoleAdminChanged} event.\n     */\n    function _setRoleAdmin(bytes32 role, bytes32 adminRole) internal virtual {\n        bytes32 previousAdminRole = getRoleAdmin(role);\n        _roles[role].adminRole = adminRole;\n        emit RoleAdminChanged(role, previousAdminRole, adminRole);\n    }\n\n    /**\n     * @dev Grants `role` to `account`.\n     *\n     * Internal function without access restriction.\n     *\n     * May emit a {RoleGranted} event.\n     */\n    function _grantRole(bytes32 role, address account) internal virtual {\n        if (!hasRole(role, account)) {\n            _roles[role].members[account] = true;\n            emit RoleGranted(role, account, _msgSender());\n        }\n    }\n\n    /**\n     * @dev Revokes `role` from `account`.\n     *\n     * Internal function without access restriction.\n     *\n     * May emit a {RoleRevoked} event.\n     */\n    function _revokeRole(bytes32 role, address account) internal virtual {\n        if (hasRole(role, account)) {\n            _roles[role].members[account] = false;\n            emit RoleRevoked(role, account, _msgSender());\n        }\n    }\n}\n"},{"file_path":"@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol","source_code":"// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.9.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 * ```solidity\n * contract MyToken is ERC20Upgradeable {\n *     function initialize() initializer public {\n *         __ERC20_init(\"MyToken\", \"MTK\");\n *     }\n * }\n *\n * contract MyTokenV2 is MyToken, ERC20PermitUpgradeable {\n *     function initializeV2() reinitializer(2) public {\n *         __ERC20Permit_init(\"MyToken\");\n *     }\n * }\n * ```\n *\n * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as\n * possible by providing the encoded function call as the `_data` argument to {ERC1967Proxy-constructor}.\n *\n * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure\n * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity.\n *\n * [CAUTION]\n * ====\n * Avoid leaving a contract uninitialized.\n *\n * An uninitialized contract can be taken over by an attacker. This applies to both a proxy and its implementation\n * contract, which may impact the proxy. To prevent the implementation contract from being used, you should invoke\n * the {_disableInitializers} function in the constructor to automatically lock it when it is deployed:\n *\n * [.hljs-theme-light.nopadding]\n * ```\n * /// @custom:oz-upgrades-unsafe-allow constructor\n * constructor() {\n *     _disableInitializers();\n * }\n * ```\n * ====\n */\nabstract contract Initializable {\n    /**\n     * @dev Indicates that the contract has been initialized.\n     * @custom:oz-retyped-from bool\n     */\n    uint8 private _initialized;\n\n    /**\n     * @dev Indicates that the contract is in the process of being initialized.\n     */\n    bool private _initializing;\n\n    /**\n     * @dev Triggered when the contract has been initialized or reinitialized.\n     */\n    event Initialized(uint8 version);\n\n    /**\n     * @dev A modifier that defines a protected initializer function that can be invoked at most once. In its scope,\n     * `onlyInitializing` functions can be used to initialize parent contracts.\n     *\n     * Similar to `reinitializer(1)`, except that functions marked with `initializer` can be nested in the context of a\n     * constructor.\n     *\n     * Emits an {Initialized} event.\n     */\n    modifier initializer() {\n        bool isTopLevelCall = !_initializing;\n        require(\n            (isTopLevelCall && _initialized < 1) || (!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     * A reinitializer may be used after the original initialization step. This is essential to configure modules that\n     * are added through upgrades and that require initialization.\n     *\n     * When `version` is 1, this modifier is similar to `initializer`, except that functions marked with `reinitializer`\n     * cannot be nested. If one is invoked in the context of another, execution will revert.\n     *\n     * Note that versions can jump in increments greater than 1; this implies that if multiple reinitializers coexist in\n     * a contract, executing them in the right order is up to the developer or operator.\n     *\n     * WARNING: setting the version to 255 will prevent any future reinitialization.\n     *\n     * Emits an {Initialized} event.\n     */\n    modifier reinitializer(uint8 version) {\n        require(!_initializing && _initialized < version, \"Initializable: contract is already initialized\");\n        _initialized = version;\n        _initializing = true;\n        _;\n        _initializing = false;\n        emit Initialized(version);\n    }\n\n    /**\n     * @dev Modifier to protect an initialization function so that it can only be invoked by functions with the\n     * {initializer} and {reinitializer} modifiers, directly or indirectly.\n     */\n    modifier onlyInitializing() {\n        require(_initializing, \"Initializable: contract is not initializing\");\n        _;\n    }\n\n    /**\n     * @dev Locks the contract, preventing any future reinitialization. This cannot be part of an initializer call.\n     * Calling this in the constructor of a contract will prevent that contract from being initialized or reinitialized\n     * to any version. It is recommended to use this to lock implementation contracts that are designed to be called\n     * through proxies.\n     *\n     * Emits an {Initialized} event the first time it is successfully executed.\n     */\n    function _disableInitializers() internal virtual {\n        require(!_initializing, \"Initializable: contract is initializing\");\n        if (_initialized != type(uint8).max) {\n            _initialized = type(uint8).max;\n            emit Initialized(type(uint8).max);\n        }\n    }\n\n    /**\n     * @dev Returns the highest version that has been initialized. See {reinitializer}.\n     */\n    function _getInitializedVersion() internal view returns (uint8) {\n        return _initialized;\n    }\n\n    /**\n     * @dev Returns `true` if the contract is currently initializing. See {onlyInitializing}.\n     */\n    function _isInitializing() internal view returns (bool) {\n        return _initializing;\n    }\n}\n"},{"file_path":"@chainlink/contracts/src/v0.8/interfaces/AggregatorV3Interface.sol","source_code":"// 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  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"},{"file_path":"@openzeppelin/contracts-upgradeable/token/ERC20/extensions/IERC20PermitUpgradeable.sol","source_code":"// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.9.4) (token/ERC20/extensions/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 *\n * ==== Security Considerations\n *\n * There are two important considerations concerning the use of `permit`. The first is that a valid permit signature\n * expresses an allowance, and it should not be assumed to convey additional meaning. In particular, it should not be\n * considered as an intention to spend the allowance in any specific way. The second is that because permits have\n * built-in replay protection and can be submitted by anyone, they can be frontrun. A protocol that uses permits should\n * take this into consideration and allow a `permit` call to fail. Combining these two aspects, a pattern that may be\n * generally recommended is:\n *\n * ```solidity\n * function doThingWithPermit(..., uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s) public {\n *     try token.permit(msg.sender, address(this), value, deadline, v, r, s) {} catch {}\n *     doThing(..., value);\n * }\n *\n * function doThing(..., uint256 value) public {\n *     token.safeTransferFrom(msg.sender, address(this), value);\n *     ...\n * }\n * ```\n *\n * Observe that: 1) `msg.sender` is used as the owner, leaving no ambiguity as to the signer intent, and 2) the use of\n * `try/catch` allows the permit to fail and makes the code tolerant to frontrunning. (See also\n * {SafeERC20-safeTransferFrom}).\n *\n * Additionally, note that smart contract wallets (such as Argent or Safe) are not able to produce permit signatures, so\n * contracts should have entry points that don't rely on permit.\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     * CAUTION: See Security Considerations above.\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"},{"file_path":"@openzeppelin/contracts-upgradeable/token/ERC20/utils/SafeERC20Upgradeable.sol","source_code":"// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.9.3) (token/ERC20/utils/SafeERC20.sol)\n\npragma solidity ^0.8.0;\n\nimport \"../IERC20Upgradeable.sol\";\nimport \"../extensions/IERC20PermitUpgradeable.sol\";\nimport \"../../../utils/AddressUpgradeable.sol\";\n\n/**\n * @title SafeERC20\n * @dev Wrappers around ERC20 operations that throw on failure (when the token\n * contract returns false). Tokens that return no value (and instead revert or\n * throw on failure) are also supported, non-reverting calls are assumed to be\n * successful.\n * To use this library you can add a `using SafeERC20 for IERC20;` statement to your contract,\n * which allows you to call the safe operations as `token.safeTransfer(...)`, etc.\n */\nlibrary SafeERC20Upgradeable {\n    using AddressUpgradeable for address;\n\n    /**\n     * @dev Transfer `value` amount of `token` from the calling contract to `to`. If `token` returns no value,\n     * non-reverting calls are assumed to be successful.\n     */\n    function safeTransfer(IERC20Upgradeable token, address to, uint256 value) internal {\n        _callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value));\n    }\n\n    /**\n     * @dev Transfer `value` amount of `token` from `from` to `to`, spending the approval given by `from` to the\n     * calling contract. If `token` returns no value, non-reverting calls are assumed to be successful.\n     */\n    function safeTransferFrom(IERC20Upgradeable token, address from, address to, uint256 value) internal {\n        _callOptionalReturn(token, abi.encodeWithSelector(token.transferFrom.selector, from, to, value));\n    }\n\n    /**\n     * @dev Deprecated. This function has issues similar to the ones found in\n     * {IERC20-approve}, and its usage is discouraged.\n     *\n     * Whenever possible, use {safeIncreaseAllowance} and\n     * {safeDecreaseAllowance} instead.\n     */\n    function safeApprove(IERC20Upgradeable token, address spender, uint256 value) internal {\n        // safeApprove should only be called when setting an initial allowance,\n        // or when resetting it to zero. To increase and decrease it, use\n        // 'safeIncreaseAllowance' and 'safeDecreaseAllowance'\n        require(\n            (value == 0) || (token.allowance(address(this), spender) == 0),\n            \"SafeERC20: approve from non-zero to non-zero allowance\"\n        );\n        _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, value));\n    }\n\n    /**\n     * @dev Increase the calling contract's allowance toward `spender` by `value`. If `token` returns no value,\n     * non-reverting calls are assumed to be successful.\n     */\n    function safeIncreaseAllowance(IERC20Upgradeable token, address spender, uint256 value) internal {\n        uint256 oldAllowance = token.allowance(address(this), spender);\n        _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, oldAllowance + value));\n    }\n\n    /**\n     * @dev Decrease the calling contract's allowance toward `spender` by `value`. If `token` returns no value,\n     * non-reverting calls are assumed to be successful.\n     */\n    function safeDecreaseAllowance(IERC20Upgradeable token, address spender, uint256 value) internal {\n        unchecked {\n            uint256 oldAllowance = token.allowance(address(this), spender);\n            require(oldAllowance >= value, \"SafeERC20: decreased allowance below zero\");\n            _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, oldAllowance - value));\n        }\n    }\n\n    /**\n     * @dev Set the calling contract's allowance toward `spender` to `value`. If `token` returns no value,\n     * non-reverting calls are assumed to be successful. Meant to be used with tokens that require the approval\n     * to be set to zero before setting it to a non-zero value, such as USDT.\n     */\n    function forceApprove(IERC20Upgradeable token, address spender, uint256 value) internal {\n        bytes memory approvalCall = abi.encodeWithSelector(token.approve.selector, spender, value);\n\n        if (!_callOptionalReturnBool(token, approvalCall)) {\n            _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, 0));\n            _callOptionalReturn(token, approvalCall);\n        }\n    }\n\n    /**\n     * @dev Use a ERC-2612 signature to set the `owner` approval toward `spender` on `token`.\n     * Revert on invalid signature.\n     */\n    function safePermit(\n        IERC20PermitUpgradeable token,\n        address owner,\n        address spender,\n        uint256 value,\n        uint256 deadline,\n        uint8 v,\n        bytes32 r,\n        bytes32 s\n    ) internal {\n        uint256 nonceBefore = token.nonces(owner);\n        token.permit(owner, spender, value, deadline, v, r, s);\n        uint256 nonceAfter = token.nonces(owner);\n        require(nonceAfter == nonceBefore + 1, \"SafeERC20: permit did not succeed\");\n    }\n\n    /**\n     * @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement\n     * on the return value: the return value is optional (but if data is returned, it must not be false).\n     * @param token The token targeted by the call.\n     * @param data The call data (encoded using abi.encode or one of its variants).\n     */\n    function _callOptionalReturn(IERC20Upgradeable token, bytes memory data) private {\n        // We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since\n        // we're implementing it ourselves. We use {Address-functionCall} to perform this call, which verifies that\n        // the target address contains contract code and also asserts for success in the low-level call.\n\n        bytes memory returndata = address(token).functionCall(data, \"SafeERC20: low-level call failed\");\n        require(returndata.length == 0 || abi.decode(returndata, (bool)), \"SafeERC20: ERC20 operation did not succeed\");\n    }\n\n    /**\n     * @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement\n     * on the return value: the return value is optional (but if data is returned, it must not be false).\n     * @param token The token targeted by the call.\n     * @param data The call data (encoded using abi.encode or one of its variants).\n     *\n     * This is a variant of {_callOptionalReturn} that silents catches all reverts and returns a bool instead.\n     */\n    function _callOptionalReturnBool(IERC20Upgradeable token, bytes memory data) private returns (bool) {\n        // We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since\n        // we're implementing it ourselves. We cannot use {Address-functionCall} here since this should return false\n        // and not revert is the subcall reverts.\n\n        (bool success, bytes memory returndata) = address(token).call(data);\n        return\n            success && (returndata.length == 0 || abi.decode(returndata, (bool))) && AddressUpgradeable.isContract(address(token));\n    }\n}\n"},{"file_path":"contracts/interfaces/IAssetRegistry.sol","source_code":"// SPDX-License-Identifier: BlueOak-1.0.0\npragma solidity 0.8.28;\n\nimport \"@openzeppelin/contracts/token/ERC20/IERC20.sol\";\nimport \"./IAsset.sol\";\nimport \"./IComponent.sol\";\n\n/// A serialization of the AssetRegistry to be passed around in the P1 impl for gas optimization\nstruct Registry {\n    IERC20[] erc20s;\n    IAsset[] assets;\n}\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:refresher\n    function refresh() external;\n\n    /// Register a new JIT-deployed RTokenAsset instance\n    /// @param maxTradeVolume {UoA} The maximum trade volume for the RTokenAsset\n    /// @return swapped If the asset was swapped for a previously-registered asset\n    /// @custom:governance\n    function registerNewRTokenAsset(uint192 maxTradeVolume) external returns (bool swapped);\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    function register(IAsset asset) external returns (bool);\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    function swapRegistered(IAsset asset) external returns (bool swapped);\n\n    /// Unregister an asset, requiring that it is already registered\n    /// @custom:governance\n    function unregister(IAsset asset) external;\n\n    /// @return {s} The timestamp of the last refresh\n    function lastRefresh() external view returns (uint48);\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    /// @return reg The list of registered ERC20s and Assets, in the same order\n    function getRegistry() external view returns (Registry memory reg);\n\n    /// Validate that the current assets in the registry are compatible with the current version\n    function validateCurrentAssets() external view;\n\n    /// @return The number of registered ERC20s\n    function size() external view returns (uint256);\n}\n"},{"file_path":"@openzeppelin/contracts-upgradeable/interfaces/IERC1271Upgradeable.sol","source_code":"// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts v4.4.1 (interfaces/IERC1271.sol)\n\npragma solidity ^0.8.0;\n\n/**\n * @dev Interface of the ERC1271 standard signature validation method for\n * contracts as defined in https://eips.ethereum.org/EIPS/eip-1271[ERC-1271].\n *\n * _Available since v4.1._\n */\ninterface IERC1271Upgradeable {\n    /**\n     * @dev Should return whether the signature provided is valid for the provided data\n     * @param hash      Hash of the data to be signed\n     * @param signature Signature byte array associated with _data\n     */\n    function isValidSignature(bytes32 hash, bytes memory signature) external view returns (bytes4 magicValue);\n}\n"},{"file_path":"@openzeppelin/contracts/utils/math/Math.sol","source_code":"// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.9.0) (utils/math/Math.sol)\n\npragma solidity ^0.8.0;\n\n/**\n * @dev Standard math utilities missing in the Solidity language.\n */\nlibrary Math {\n    enum Rounding {\n        Down, // Toward negative infinity\n        Up, // Toward infinity\n        Zero // Toward zero\n    }\n\n    /**\n     * @dev Returns the largest of two numbers.\n     */\n    function max(uint256 a, uint256 b) internal pure returns (uint256) {\n        return a > b ? a : b;\n    }\n\n    /**\n     * @dev Returns the smallest of two numbers.\n     */\n    function min(uint256 a, uint256 b) internal pure returns (uint256) {\n        return a < b ? a : b;\n    }\n\n    /**\n     * @dev Returns the average of two numbers. The result is rounded towards\n     * zero.\n     */\n    function average(uint256 a, uint256 b) internal pure returns (uint256) {\n        // (a + b) / 2 can overflow.\n        return (a & b) + (a ^ b) / 2;\n    }\n\n    /**\n     * @dev Returns the ceiling of the division of two numbers.\n     *\n     * This differs from standard division with `/` in that it rounds up instead\n     * of rounding down.\n     */\n    function ceilDiv(uint256 a, uint256 b) internal pure returns (uint256) {\n        // (a + b - 1) / b can overflow on addition, so we distribute.\n        return a == 0 ? 0 : (a - 1) / b + 1;\n    }\n\n    /**\n     * @notice Calculates floor(x * y / denominator) with full precision. Throws if result overflows a uint256 or denominator == 0\n     * @dev Original credit to Remco Bloemen under MIT license (https://xn--2-umb.com/21/muldiv)\n     * with further edits by Uniswap Labs also under MIT license.\n     */\n    function mulDiv(uint256 x, uint256 y, uint256 denominator) internal pure returns (uint256 result) {\n        unchecked {\n            // 512-bit multiply [prod1 prod0] = x * y. Compute the product mod 2^256 and mod 2^256 - 1, then use\n            // use the Chinese Remainder Theorem to reconstruct the 512 bit result. The result is stored in two 256\n            // variables such that product = prod1 * 2^256 + prod0.\n            uint256 prod0; // Least significant 256 bits of the product\n            uint256 prod1; // Most significant 256 bits of the product\n            assembly {\n                let mm := mulmod(x, y, not(0))\n                prod0 := mul(x, y)\n                prod1 := sub(sub(mm, prod0), lt(mm, prod0))\n            }\n\n            // Handle non-overflow cases, 256 by 256 division.\n            if (prod1 == 0) {\n                // Solidity will revert if denominator == 0, unlike the div opcode on its own.\n                // The surrounding unchecked block does not change this fact.\n                // See https://docs.soliditylang.org/en/latest/control-structures.html#checked-or-unchecked-arithmetic.\n                return prod0 / denominator;\n            }\n\n            // Make sure the result is less than 2^256. Also prevents denominator == 0.\n            require(denominator > prod1, \"Math: mulDiv overflow\");\n\n            ///////////////////////////////////////////////\n            // 512 by 256 division.\n            ///////////////////////////////////////////////\n\n            // Make division exact by subtracting the remainder from [prod1 prod0].\n            uint256 remainder;\n            assembly {\n                // Compute remainder using mulmod.\n                remainder := mulmod(x, y, denominator)\n\n                // Subtract 256 bit number from 512 bit number.\n                prod1 := sub(prod1, gt(remainder, prod0))\n                prod0 := sub(prod0, remainder)\n            }\n\n            // Factor powers of two out of denominator and compute largest power of two divisor of denominator. Always >= 1.\n            // See https://cs.stackexchange.com/q/138556/92363.\n\n            // Does not overflow because the denominator cannot be zero at this stage in the function.\n            uint256 twos = denominator & (~denominator + 1);\n            assembly {\n                // Divide denominator by twos.\n                denominator := div(denominator, twos)\n\n                // Divide [prod1 prod0] by twos.\n                prod0 := div(prod0, twos)\n\n                // Flip twos such that it is 2^256 / twos. If twos is zero, then it becomes one.\n                twos := add(div(sub(0, twos), twos), 1)\n            }\n\n            // Shift in bits from prod1 into prod0.\n            prod0 |= prod1 * twos;\n\n            // Invert denominator mod 2^256. Now that denominator is an odd number, it has an inverse modulo 2^256 such\n            // that denominator * inv = 1 mod 2^256. Compute the inverse by starting with a seed that is correct for\n            // four bits. That is, denominator * inv = 1 mod 2^4.\n            uint256 inverse = (3 * denominator) ^ 2;\n\n            // Use the Newton-Raphson iteration to improve the precision. Thanks to Hensel's lifting lemma, this also works\n            // in modular arithmetic, doubling the correct bits in each step.\n            inverse *= 2 - denominator * inverse; // inverse mod 2^8\n            inverse *= 2 - denominator * inverse; // inverse mod 2^16\n            inverse *= 2 - denominator * inverse; // inverse mod 2^32\n            inverse *= 2 - denominator * inverse; // inverse mod 2^64\n            inverse *= 2 - denominator * inverse; // inverse mod 2^128\n            inverse *= 2 - denominator * inverse; // inverse mod 2^256\n\n            // Because the division is now exact we can divide by multiplying with the modular inverse of denominator.\n            // This will give us the correct result modulo 2^256. Since the preconditions guarantee that the outcome is\n            // less than 2^256, this is the final result. We don't need to compute the high bits of the result and prod1\n            // is no longer required.\n            result = prod0 * inverse;\n            return result;\n        }\n    }\n\n    /**\n     * @notice Calculates x * y / denominator with full precision, following the selected rounding direction.\n     */\n    function mulDiv(uint256 x, uint256 y, uint256 denominator, Rounding rounding) internal pure returns (uint256) {\n        uint256 result = mulDiv(x, y, denominator);\n        if (rounding == Rounding.Up && mulmod(x, y, denominator) > 0) {\n            result += 1;\n        }\n        return result;\n    }\n\n    /**\n     * @dev Returns the square root of a number. If the number is not a perfect square, the value is rounded down.\n     *\n     * Inspired by Henry S. Warren, Jr.'s \"Hacker's Delight\" (Chapter 11).\n     */\n    function sqrt(uint256 a) internal pure returns (uint256) {\n        if (a == 0) {\n            return 0;\n        }\n\n        // For our first guess, we get the biggest power of 2 which is smaller than the square root of the target.\n        //\n        // We know that the \"msb\" (most significant bit) of our target number `a` is a power of 2 such that we have\n        // `msb(a) <= a < 2*msb(a)`. This value can be written `msb(a)=2**k` with `k=log2(a)`.\n        //\n        // This can be rewritten `2**log2(a) <= a < 2**(log2(a) + 1)`\n        // → `sqrt(2**k) <= sqrt(a) < sqrt(2**(k+1))`\n        // → `2**(k/2) <= sqrt(a) < 2**((k+1)/2) <= 2**(k/2 + 1)`\n        //\n        // Consequently, `2**(log2(a) / 2)` is a good first approximation of `sqrt(a)` with at least 1 correct bit.\n        uint256 result = 1 << (log2(a) >> 1);\n\n        // At this point `result` is an estimation with one bit of precision. We know the true value is a uint128,\n        // since it is the square root of a uint256. Newton's method converges quadratically (precision doubles at\n        // every iteration). We thus need at most 7 iteration to turn our partial result with one bit of precision\n        // into the expected uint128 result.\n        unchecked {\n            result = (result + a / result) >> 1;\n            result = (result + a / result) >> 1;\n            result = (result + a / result) >> 1;\n            result = (result + a / result) >> 1;\n            result = (result + a / result) >> 1;\n            result = (result + a / result) >> 1;\n            result = (result + a / result) >> 1;\n            return min(result, a / result);\n        }\n    }\n\n    /**\n     * @notice Calculates sqrt(a), following the selected rounding direction.\n     */\n    function sqrt(uint256 a, Rounding rounding) internal pure returns (uint256) {\n        unchecked {\n            uint256 result = sqrt(a);\n            return result + (rounding == Rounding.Up && result * result < a ? 1 : 0);\n        }\n    }\n\n    /**\n     * @dev Return the log in base 2, rounded down, of a positive value.\n     * Returns 0 if given 0.\n     */\n    function log2(uint256 value) internal pure returns (uint256) {\n        uint256 result = 0;\n        unchecked {\n            if (value >> 128 > 0) {\n                value >>= 128;\n                result += 128;\n            }\n            if (value >> 64 > 0) {\n                value >>= 64;\n                result += 64;\n            }\n            if (value >> 32 > 0) {\n                value >>= 32;\n                result += 32;\n            }\n            if (value >> 16 > 0) {\n                value >>= 16;\n                result += 16;\n            }\n            if (value >> 8 > 0) {\n                value >>= 8;\n                result += 8;\n            }\n            if (value >> 4 > 0) {\n                value >>= 4;\n                result += 4;\n            }\n            if (value >> 2 > 0) {\n                value >>= 2;\n                result += 2;\n            }\n            if (value >> 1 > 0) {\n                result += 1;\n            }\n        }\n        return result;\n    }\n\n    /**\n     * @dev Return the log in base 2, following the selected rounding direction, of a positive value.\n     * Returns 0 if given 0.\n     */\n    function log2(uint256 value, Rounding rounding) internal pure returns (uint256) {\n        unchecked {\n            uint256 result = log2(value);\n            return result + (rounding == Rounding.Up && 1 << result < value ? 1 : 0);\n        }\n    }\n\n    /**\n     * @dev Return the log in base 10, rounded down, of a positive value.\n     * Returns 0 if given 0.\n     */\n    function log10(uint256 value) internal pure returns (uint256) {\n        uint256 result = 0;\n        unchecked {\n            if (value >= 10 ** 64) {\n                value /= 10 ** 64;\n                result += 64;\n            }\n            if (value >= 10 ** 32) {\n                value /= 10 ** 32;\n                result += 32;\n            }\n            if (value >= 10 ** 16) {\n                value /= 10 ** 16;\n                result += 16;\n            }\n            if (value >= 10 ** 8) {\n                value /= 10 ** 8;\n                result += 8;\n            }\n            if (value >= 10 ** 4) {\n                value /= 10 ** 4;\n                result += 4;\n            }\n            if (value >= 10 ** 2) {\n                value /= 10 ** 2;\n                result += 2;\n            }\n            if (value >= 10 ** 1) {\n                result += 1;\n            }\n        }\n        return result;\n    }\n\n    /**\n     * @dev Return the log in base 10, following the selected rounding direction, of a positive value.\n     * Returns 0 if given 0.\n     */\n    function log10(uint256 value, Rounding rounding) internal pure returns (uint256) {\n        unchecked {\n            uint256 result = log10(value);\n            return result + (rounding == Rounding.Up && 10 ** result < value ? 1 : 0);\n        }\n    }\n\n    /**\n     * @dev Return the log in base 256, rounded down, of a positive value.\n     * Returns 0 if given 0.\n     *\n     * Adding one to the result gives the number of pairs of hex symbols needed to represent `value` as a hex string.\n     */\n    function log256(uint256 value) internal pure returns (uint256) {\n        uint256 result = 0;\n        unchecked {\n            if (value >> 128 > 0) {\n                value >>= 128;\n                result += 16;\n            }\n            if (value >> 64 > 0) {\n                value >>= 64;\n                result += 8;\n            }\n            if (value >> 32 > 0) {\n                value >>= 32;\n                result += 4;\n            }\n            if (value >> 16 > 0) {\n                value >>= 16;\n                result += 2;\n            }\n            if (value >> 8 > 0) {\n                result += 1;\n            }\n        }\n        return result;\n    }\n\n    /**\n     * @dev Return the log in base 256, following the selected rounding direction, of a positive value.\n     * Returns 0 if given 0.\n     */\n    function log256(uint256 value, Rounding rounding) internal pure returns (uint256) {\n        unchecked {\n            uint256 result = log256(value);\n            return result + (rounding == Rounding.Up && 1 << (result << 3) < value ? 1 : 0);\n        }\n    }\n}\n"},{"file_path":"contracts/interfaces/IComponent.sol","source_code":"// SPDX-License-Identifier: BlueOak-1.0.0\npragma solidity 0.8.28;\n\nimport \"./IMain.sol\";\nimport \"./IVersioned.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 is IVersioned {\n    function main() external view returns (IMain);\n}\n"},{"file_path":"@openzeppelin/contracts/access/Ownable.sol","source_code":"// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.9.0) (access/Ownable.sol)\n\npragma solidity ^0.8.0;\n\nimport \"../utils/Context.sol\";\n\n/**\n * @dev Contract module which provides a basic access control mechanism, where\n * there is an account (an owner) that can be granted exclusive access to\n * specific functions.\n *\n * By default, the owner account will be the one that deploys the contract. This\n * can later be changed with {transferOwnership}.\n *\n * This module is used through inheritance. It will make available the modifier\n * `onlyOwner`, which can be applied to your functions to restrict their use to\n * the owner.\n */\nabstract contract Ownable is Context {\n    address private _owner;\n\n    event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);\n\n    /**\n     * @dev Initializes the contract setting the deployer as the initial owner.\n     */\n    constructor() {\n        _transferOwnership(_msgSender());\n    }\n\n    /**\n     * @dev Throws if called by any account other than the owner.\n     */\n    modifier onlyOwner() {\n        _checkOwner();\n        _;\n    }\n\n    /**\n     * @dev Returns the address of the current owner.\n     */\n    function owner() public view virtual returns (address) {\n        return _owner;\n    }\n\n    /**\n     * @dev Throws if the sender is not the owner.\n     */\n    function _checkOwner() internal view virtual {\n        require(owner() == _msgSender(), \"Ownable: caller is not the owner\");\n    }\n\n    /**\n     * @dev Leaves the contract without owner. It will not be possible to call\n     * `onlyOwner` functions. Can only be called by the current owner.\n     *\n     * NOTE: Renouncing ownership will leave the contract without an owner,\n     * thereby disabling any functionality that is only available to the owner.\n     */\n    function renounceOwnership() public virtual onlyOwner {\n        _transferOwnership(address(0));\n    }\n\n    /**\n     * @dev Transfers ownership of the contract to a new account (`newOwner`).\n     * Can only be called by the current owner.\n     */\n    function transferOwnership(address newOwner) public virtual onlyOwner {\n        require(newOwner != address(0), \"Ownable: new owner is the zero address\");\n        _transferOwnership(newOwner);\n    }\n\n    /**\n     * @dev Transfers ownership of the contract to a new account (`newOwner`).\n     * Internal function without access restriction.\n     */\n    function _transferOwnership(address newOwner) internal virtual {\n        address oldOwner = _owner;\n        _owner = newOwner;\n        emit OwnershipTransferred(oldOwner, newOwner);\n    }\n}\n"},{"file_path":"contracts/p1/mixins/Component.sol","source_code":"// SPDX-License-Identifier: BlueOak-1.0.0\npragma solidity 0.8.28;\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 \"../../interfaces/IComponent.sol\";\nimport \"../../interfaces/IMain.sol\";\nimport \"../../mixins/Versioned.sol\";\n\n/**\n * Abstract superclass for system contracts registered in Main\n */\nabstract contract ComponentP1 is\n    Versioned,\n    Initializable,\n    ContextUpgradeable,\n    UUPSUpgradeable,\n    IComponent\n{\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    // untestable:\n    //      `else` branch of `onlyInitializing` (ie. revert) is currently untestable.\n    //      This function is only called inside other `init` functions, each of which is wrapped\n    //      in an `initializer` modifier, which would fail first.\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/pause-freeze-states.md ===\n\n    modifier notTradingPausedOrFrozen() {\n        require(!main.tradingPausedOrFrozen(), \"frozen or trading paused\");\n        _;\n    }\n\n    modifier notIssuancePausedOrFrozen() {\n        require(!main.issuancePausedOrFrozen(), \"frozen or issuance paused\");\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    modifier onlyMain() {\n        require(_msgSender() == address(main), \"main only\");\n        _;\n    }\n\n    // === Control Flow ===\n\n    /**\n     * @dev Prevents reentrancy by implementing a global lock shared by all components\n     * Calling a `globalNonReentrant` function from another `globalNonReentrant`\n     * function is not supported.\n     */\n    modifier globalNonReentrant() {\n        main.beginTx();\n        _;\n        main.endTx();\n    }\n\n    // solhint-disable-next-line no-empty-blocks\n    function _authorizeUpgrade(address newImplementation) internal view override onlyMain {}\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"},{"file_path":"contracts/libraries/Permit.sol","source_code":"// SPDX-License-Identifier: BlueOak-1.0.0\npragma solidity 0.8.28;\n\nimport \"@openzeppelin/contracts-upgradeable/utils/AddressUpgradeable.sol\";\nimport \"@openzeppelin/contracts-upgradeable/utils/cryptography/SignatureCheckerUpgradeable.sol\";\n\n/// Internal library for verifying metatx sigs for EOAs and smart contract wallets\n/// See ERC1271\nlibrary PermitLib {\n    function requireSignature(\n        address owner,\n        bytes32 hash,\n        uint8 v,\n        bytes32 r,\n        bytes32 s\n    ) internal view {\n        if (AddressUpgradeable.isContract(owner)) {\n            require(\n                IERC1271Upgradeable(owner).isValidSignature(hash, abi.encodePacked(r, s, v)) ==\n                    0x1626ba7e,\n                \"ERC1271: Unauthorized\"\n            );\n        } else {\n            require(\n                SignatureCheckerUpgradeable.isValidSignatureNow(\n                    owner,\n                    hash,\n                    abi.encodePacked(r, s, v)\n                ),\n                \"ERC20Permit: invalid signature\"\n            );\n        }\n    }\n}\n"},{"file_path":"contracts/interfaces/IDistributor.sol","source_code":"// SPDX-License-Identifier: BlueOak-1.0.0\npragma solidity 0.8.28;\n\nimport \"@openzeppelin/contracts/token/ERC20/IERC20.sol\";\nimport \"./IComponent.sol\";\n\nuint256 constant MAX_DISTRIBUTION = 1e4; // 10,000\nuint8 constant MAX_DESTINATIONS = 100; // maximum number of RevenueShare destinations\n\n// === 4.0.0 ===\n// Invariant: sum across destinations must be at *least* MAX_DISTRIBUTION\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 100 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 indexed 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 amount);\n\n    // Initialization\n    function init(IMain main_, RevenueShare calldata dist) external;\n\n    /// @custom:governance\n    function setDistribution(address dest, RevenueShare calldata share) external;\n\n    /// @custom:governance\n    function setDistributions(address[] calldata dests, RevenueShare[] calldata shares) external;\n\n    /// Distribute the `erc20` token across all revenue destinations\n    /// Only callable by RevenueTraders\n    /// @custom:protected\n    function distribute(IERC20 erc20, uint256 amount) 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    /// @return rTokenDist The RToken distribution for the address\n    /// @return rsrDist The RSR distribution for the address\n    function distribution(address) external view returns (uint16 rTokenDist, uint16 rsrDist);\n}\n"},{"file_path":"@openzeppelin/contracts-upgradeable/utils/CountersUpgradeable.sol","source_code":"// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts v4.4.1 (utils/Counters.sol)\n\npragma solidity ^0.8.0;\n\n/**\n * @title Counters\n * @author Matt Condon (@shrugs)\n * @dev Provides counters that can only be incremented, decremented or reset. This can be used e.g. to track the number\n * of elements in a mapping, issuing ERC721 ids, or counting request ids.\n *\n * Include with `using Counters for Counters.Counter;`\n */\nlibrary CountersUpgradeable {\n    struct Counter {\n        // This variable should never be directly accessed by users of the library: interactions must be restricted to\n        // the library's function. As of Solidity v0.5.2, this cannot be enforced, though there is a proposal to add\n        // this feature: see https://github.com/ethereum/solidity/issues/4637\n        uint256 _value; // default: 0\n    }\n\n    function current(Counter storage counter) internal view returns (uint256) {\n        return counter._value;\n    }\n\n    function increment(Counter storage counter) internal {\n        unchecked {\n            counter._value += 1;\n        }\n    }\n\n    function decrement(Counter storage counter) internal {\n        uint256 value = counter._value;\n        require(value > 0, \"Counter: decrement overflow\");\n        unchecked {\n            counter._value = value - 1;\n        }\n    }\n\n    function reset(Counter storage counter) internal {\n        counter._value = 0;\n    }\n}\n"},{"file_path":"contracts/interfaces/IRevenueTrader.sol","source_code":"// SPDX-License-Identifier: BlueOak-1.0.0\npragma solidity 0.8.28;\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    /// Distribute tokenToBuy to its destinations\n    /// @dev Special-case of manageTokens()\n    /// @custom:interaction\n    function distributeTokenToBuy() external;\n\n    /// Return registered ERC20s to the BackingManager if distribution for tokenToBuy is 0\n    /// @custom:interaction\n    function returnTokens(IERC20[] memory erc20s) external;\n\n    /// Process some number of tokens\n    /// If the tokenToBuy is included in erc20s, RevenueTrader will distribute it at end of the tx\n    /// @param erc20s The ERC20s to manage; can be tokenToBuy or anything registered\n    /// @param kinds The kinds of auctions to launch: DUTCH_AUCTION | BATCH_AUCTION\n    /// @custom:interaction\n    function manageTokens(IERC20[] memory erc20s, TradeKind[] memory kinds) external;\n\n    function tokenToBuy() external view returns (IERC20);\n}\n\n// solhint-disable-next-line no-empty-blocks\ninterface TestIRevenueTrader is IRevenueTrader, TestITrading {\n\n}\n"},{"file_path":"@openzeppelin/contracts-upgradeable/utils/cryptography/ECDSAUpgradeable.sol","source_code":"// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.9.0) (utils/cryptography/ECDSA.sol)\n\npragma solidity ^0.8.0;\n\nimport \"../StringsUpgradeable.sol\";\n\n/**\n * @dev Elliptic Curve Digital Signature Algorithm (ECDSA) operations.\n *\n * These functions can be used to verify that a message was signed by the holder\n * of the private keys of a given address.\n */\nlibrary ECDSAUpgradeable {\n    enum RecoverError {\n        NoError,\n        InvalidSignature,\n        InvalidSignatureLength,\n        InvalidSignatureS,\n        InvalidSignatureV // Deprecated in v4.8\n    }\n\n    function _throwError(RecoverError error) private pure {\n        if (error == RecoverError.NoError) {\n            return; // no error: do nothing\n        } else if (error == RecoverError.InvalidSignature) {\n            revert(\"ECDSA: invalid signature\");\n        } else if (error == RecoverError.InvalidSignatureLength) {\n            revert(\"ECDSA: invalid signature length\");\n        } else if (error == RecoverError.InvalidSignatureS) {\n            revert(\"ECDSA: invalid signature 's' value\");\n        }\n    }\n\n    /**\n     * @dev Returns the address that signed a hashed message (`hash`) with\n     * `signature` or error string. This address can then be used for verification purposes.\n     *\n     * The `ecrecover` EVM opcode allows for malleable (non-unique) signatures:\n     * this function rejects them by requiring the `s` value to be in the lower\n     * half order, and the `v` value to be either 27 or 28.\n     *\n     * IMPORTANT: `hash` _must_ be the result of a hash operation for the\n     * verification to be secure: it is possible to craft signatures that\n     * recover to arbitrary addresses for non-hashed data. A safe way to ensure\n     * this is by receiving a hash of the original message (which may otherwise\n     * be too long), and then calling {toEthSignedMessageHash} on it.\n     *\n     * Documentation for signature generation:\n     * - with https://web3js.readthedocs.io/en/v1.3.4/web3-eth-accounts.html#sign[Web3.js]\n     * - with https://docs.ethers.io/v5/api/signer/#Signer-signMessage[ethers]\n     *\n     * _Available since v4.3._\n     */\n    function tryRecover(bytes32 hash, bytes memory signature) internal pure returns (address, RecoverError) {\n        if (signature.length == 65) {\n            bytes32 r;\n            bytes32 s;\n            uint8 v;\n            // ecrecover takes the signature parameters, and the only way to get them\n            // currently is to use assembly.\n            /// @solidity memory-safe-assembly\n            assembly {\n                r := mload(add(signature, 0x20))\n                s := mload(add(signature, 0x40))\n                v := byte(0, mload(add(signature, 0x60)))\n            }\n            return tryRecover(hash, v, r, s);\n        } else {\n            return (address(0), RecoverError.InvalidSignatureLength);\n        }\n    }\n\n    /**\n     * @dev Returns the address that signed a hashed message (`hash`) with\n     * `signature`. This address can then be used for verification purposes.\n     *\n     * The `ecrecover` EVM opcode allows for malleable (non-unique) signatures:\n     * this function rejects them by requiring the `s` value to be in the lower\n     * half order, and the `v` value to be either 27 or 28.\n     *\n     * IMPORTANT: `hash` _must_ be the result of a hash operation for the\n     * verification to be secure: it is possible to craft signatures that\n     * recover to arbitrary addresses for non-hashed data. A safe way to ensure\n     * this is by receiving a hash of the original message (which may otherwise\n     * be too long), and then calling {toEthSignedMessageHash} on it.\n     */\n    function recover(bytes32 hash, bytes memory signature) internal pure returns (address) {\n        (address recovered, RecoverError error) = tryRecover(hash, signature);\n        _throwError(error);\n        return recovered;\n    }\n\n    /**\n     * @dev Overload of {ECDSA-tryRecover} that receives the `r` and `vs` short-signature fields separately.\n     *\n     * See https://eips.ethereum.org/EIPS/eip-2098[EIP-2098 short signatures]\n     *\n     * _Available since v4.3._\n     */\n    function tryRecover(bytes32 hash, bytes32 r, bytes32 vs) internal pure returns (address, RecoverError) {\n        bytes32 s = vs & bytes32(0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff);\n        uint8 v = uint8((uint256(vs) >> 255) + 27);\n        return tryRecover(hash, v, r, s);\n    }\n\n    /**\n     * @dev Overload of {ECDSA-recover} that receives the `r and `vs` short-signature fields separately.\n     *\n     * _Available since v4.2._\n     */\n    function recover(bytes32 hash, bytes32 r, bytes32 vs) internal pure returns (address) {\n        (address recovered, RecoverError error) = tryRecover(hash, r, vs);\n        _throwError(error);\n        return recovered;\n    }\n\n    /**\n     * @dev Overload of {ECDSA-tryRecover} that receives the `v`,\n     * `r` and `s` signature fields separately.\n     *\n     * _Available since v4.3._\n     */\n    function tryRecover(bytes32 hash, uint8 v, bytes32 r, bytes32 s) internal pure returns (address, RecoverError) {\n        // EIP-2 still allows signature malleability for ecrecover(). Remove this possibility and make the signature\n        // unique. Appendix F in the Ethereum Yellow paper (https://ethereum.github.io/yellowpaper/paper.pdf), defines\n        // the valid range for s in (301): 0 < s < secp256k1n ÷ 2 + 1, and for v in (302): v ∈ {27, 28}. Most\n        // signatures from current libraries generate a unique signature with an s-value in the lower half order.\n        //\n        // If your library generates malleable signatures, such as s-values in the upper range, calculate a new s-value\n        // with 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141 - s1 and flip v from 27 to 28 or\n        // vice versa. If your library also generates signatures with 0/1 for v instead 27/28, add 27 to v to accept\n        // these malleable signatures as well.\n        if (uint256(s) > 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5D576E7357A4501DDFE92F46681B20A0) {\n            return (address(0), RecoverError.InvalidSignatureS);\n        }\n\n        // If the signature is valid (and not malleable), return the signer address\n        address signer = ecrecover(hash, v, r, s);\n        if (signer == address(0)) {\n            return (address(0), RecoverError.InvalidSignature);\n        }\n\n        return (signer, RecoverError.NoError);\n    }\n\n    /**\n     * @dev Overload of {ECDSA-recover} that receives the `v`,\n     * `r` and `s` signature fields separately.\n     */\n    function recover(bytes32 hash, uint8 v, bytes32 r, bytes32 s) internal pure returns (address) {\n        (address recovered, RecoverError error) = tryRecover(hash, v, r, s);\n        _throwError(error);\n        return recovered;\n    }\n\n    /**\n     * @dev Returns an Ethereum Signed Message, created from a `hash`. This\n     * produces hash corresponding to the one signed with the\n     * https://eth.wiki/json-rpc/API#eth_sign[`eth_sign`]\n     * JSON-RPC method as part of EIP-191.\n     *\n     * See {recover}.\n     */\n    function toEthSignedMessageHash(bytes32 hash) internal pure returns (bytes32 message) {\n        // 32 is the length in bytes of hash,\n        // enforced by the type signature above\n        /// @solidity memory-safe-assembly\n        assembly {\n            mstore(0x00, \"\\x19Ethereum Signed Message:\\n32\")\n            mstore(0x1c, hash)\n            message := keccak256(0x00, 0x3c)\n        }\n    }\n\n    /**\n     * @dev Returns an Ethereum Signed Message, created from `s`. This\n     * produces hash corresponding to the one signed with the\n     * https://eth.wiki/json-rpc/API#eth_sign[`eth_sign`]\n     * JSON-RPC method as part of EIP-191.\n     *\n     * See {recover}.\n     */\n    function toEthSignedMessageHash(bytes memory s) internal pure returns (bytes32) {\n        return keccak256(abi.encodePacked(\"\\x19Ethereum Signed Message:\\n\", StringsUpgradeable.toString(s.length), s));\n    }\n\n    /**\n     * @dev Returns an Ethereum Signed Typed Data, created from a\n     * `domainSeparator` and a `structHash`. This produces hash corresponding\n     * to the one signed with the\n     * https://eips.ethereum.org/EIPS/eip-712[`eth_signTypedData`]\n     * JSON-RPC method as part of EIP-712.\n     *\n     * See {recover}.\n     */\n    function toTypedDataHash(bytes32 domainSeparator, bytes32 structHash) internal pure returns (bytes32 data) {\n        /// @solidity memory-safe-assembly\n        assembly {\n            let ptr := mload(0x40)\n            mstore(ptr, \"\\x19\\x01\")\n            mstore(add(ptr, 0x02), domainSeparator)\n            mstore(add(ptr, 0x22), structHash)\n            data := keccak256(ptr, 0x42)\n        }\n    }\n\n    /**\n     * @dev Returns an Ethereum Signed Data with intended validator, created from a\n     * `validator` and `data` according to the version 0 of EIP-191.\n     *\n     * See {recover}.\n     */\n    function toDataWithIntendedValidatorHash(address validator, bytes memory data) internal pure returns (bytes32) {\n        return keccak256(abi.encodePacked(\"\\x19\\x00\", validator, data));\n    }\n}\n"},{"file_path":"contracts/vendor/ERC20PermitUpgradeable.sol","source_code":"// SPDX-License-Identifier: MIT\n// Taken from OZ release 4.7.3 at commit a035b235b4f2c9af4ba88edc4447f02e37f8d124\n// The only modification that has been made is in the body of the `permit` function at line 83,\n/// where we failover to SignatureChecker in order to handle approvals for smart contracts.\n\npragma solidity 0.8.28;\nimport \"@openzeppelin/contracts-upgradeable/token/ERC20/extensions/draft-IERC20PermitUpgradeable.sol\";\nimport \"@openzeppelin/contracts-upgradeable/token/ERC20/ERC20Upgradeable.sol\";\nimport \"@openzeppelin/contracts-upgradeable/utils/cryptography/draft-EIP712Upgradeable.sol\";\nimport \"@openzeppelin/contracts-upgradeable/utils/CountersUpgradeable.sol\";\nimport \"@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol\";\nimport \"../libraries/Permit.sol\";\nimport \"../mixins/Versioned.sol\";\n\n/**\n * @dev Implementation 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 *\n * Note: We have modified `permit` to support EIP-1271, technically violating EIP-2612.\n *\n * _Available since v3.4._\n *\n * @custom:storage-size 51\n */\nabstract contract ERC20PermitUpgradeable is\n    Initializable,\n    ERC20Upgradeable,\n    IERC20PermitUpgradeable,\n    EIP712Upgradeable\n{\n    using CountersUpgradeable for CountersUpgradeable.Counter;\n\n    mapping(address => CountersUpgradeable.Counter) private _nonces;\n\n    // solhint-disable-next-line var-name-mixedcase\n    bytes32 private constant _PERMIT_TYPEHASH =\n        keccak256(\n            \"Permit(address owner,address spender,uint256 value,uint256 nonce,uint256 deadline)\"\n        );\n    /**\n     * @dev In previous versions `_PERMIT_TYPEHASH` was declared as `immutable`.\n     * However, to ensure consistency with the upgradeable transpiler, we will continue\n     * to reserve a slot.\n     * @custom:oz-renamed-from _PERMIT_TYPEHASH\n     */\n    // solhint-disable-next-line var-name-mixedcase\n    bytes32 private _PERMIT_TYPEHASH_DEPRECATED_SLOT;\n\n    // untestable:\n    //      `else` branch of `onlyInitializing` (ie. revert) is currently untestable.\n    //      This function is only called inside other `init` functions, each of which is wrapped\n    //      in an `initializer` modifier, which would fail first.\n    /**\n     * @dev Initializes the {EIP712} domain separator using the `name` parameter, and setting `version` to\n     *      the system-wide semver release version.\n     *\n     * It's a good idea to use the same `name` that is defined as the ERC20 token name.\n     */\n    function __ERC20Permit_init(string memory name) internal onlyInitializing {\n        __EIP712_init_unchained(name, VERSION);\n    }\n\n    // untestable:\n    //        This is not needed in the way we handle initializations\n    function __ERC20Permit_init_unchained(string memory) internal onlyInitializing {}\n\n    /**\n     * @dev See {IERC20Permit-permit}.\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    ) public virtual override {\n        require(block.timestamp <= deadline, \"ERC20Permit: expired deadline\");\n\n        bytes32 structHash = keccak256(\n            abi.encode(_PERMIT_TYPEHASH, owner, spender, value, _useNonce(owner), deadline)\n        );\n\n        /// ==== MODIFICATIONS START ====\n\n        PermitLib.requireSignature(owner, _hashTypedDataV4(structHash), v, r, s);\n\n        /// ==== MODIFICATIONS END ====\n\n        _approve(owner, spender, value);\n    }\n\n    /**\n     * @dev See {IERC20Permit-nonces}.\n     */\n    function nonces(address owner) public view virtual override returns (uint256) {\n        return _nonces[owner].current();\n    }\n\n    /**\n     * @dev See {IERC20Permit-DOMAIN_SEPARATOR}.\n     */\n    // solhint-disable-next-line func-name-mixedcase\n    function DOMAIN_SEPARATOR() external view override returns (bytes32) {\n        return _domainSeparatorV4();\n    }\n\n    /**\n     * @dev \"Consume a nonce\": return the current value and increment.\n     *\n     * _Available since v4.1._\n     */\n    function _useNonce(address owner) internal virtual returns (uint256 current) {\n        CountersUpgradeable.Counter storage nonce = _nonces[owner];\n        current = nonce.current();\n        nonce.increment();\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"},{"file_path":"contracts/interfaces/ITrading.sol","source_code":"// SPDX-License-Identifier: BlueOak-1.0.0\npragma solidity 0.8.28;\n\nimport \"@openzeppelin/contracts/token/ERC20/IERC20.sol\";\nimport \"../libraries/Fixed.sol\";\nimport \"./IComponent.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 IComponent, IRewardableComponent {\n    event MaxTradeSlippageSet(uint192 oldVal, uint192 newVal);\n    event MinTradeVolumeSet(uint192 oldVal, uint192 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    /// Forcibly settle a trade, losing all value\n    /// Should only be called in case of censorship\n    /// @param trade The trade address itself\n    /// @custom:governance\n    function forceSettleTrade(ITrade trade) external;\n\n    /// Settle a single trade, expected to be used with multicall for efficient mass settlement\n    /// @param sell The sell token in the trade\n    /// @return The trade settled\n    /// @custom:refresher\n    function settleTrade(IERC20 sell) external returns (ITrade);\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    /// @return The number of ongoing trades open\n    function tradesOpen() external view returns (uint48);\n\n    /// @return The number of total trades ever opened\n    function tradesNonce() external view returns (uint256);\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"},{"file_path":"contracts/interfaces/IBasketHandler.sol","source_code":"// SPDX-License-Identifier: BlueOak-1.0.0\npragma solidity 0.8.28;\n\nimport \"@openzeppelin/contracts/token/ERC20/IERC20.sol\";\nimport \"../libraries/Fixed.sol\";\nimport \"./IAsset.sol\";\nimport \"./IComponent.sol\";\n\nstruct BasketRange {\n    uint192 bottom; // {BU}\n    uint192 top; // {BU}\n}\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 {basketNonce} 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 max, IERC20[] erc20s);\n\n    /// Emitted when the warmup period is changed\n    /// @param oldVal The old warmup period\n    /// @param newVal The new warmup period\n    event WarmupPeriodSet(uint48 oldVal, uint48 newVal);\n\n    /// Emitted when the issuance premium logic is changed\n    /// @param oldVal The old value of enableIssuancePremium\n    /// @param newVal The new value of enableIssuancePremium\n    event EnableIssuancePremiumSet(bool oldVal, bool newVal);\n\n    /// Emitted when the status of a basket has changed\n    /// @param oldStatus The previous basket status\n    /// @param newStatus The new basket status\n    event BasketStatusChanged(CollateralStatus oldStatus, CollateralStatus newStatus);\n\n    /// Emitted when the last basket nonce available for redemption is changed\n    /// @param oldVal The old value of lastCollateralized\n    /// @param newVal The new value of lastCollateralized\n    event LastCollateralizedChanged(uint48 oldVal, uint48 newVal);\n\n    // Initialization\n    function init(\n        IMain main_,\n        uint48 warmupPeriod_,\n        bool reweightable_,\n        bool enableIssuancePremium_\n    ) external;\n\n    /// Set the prime basket, checking target amounts are constant\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[] calldata erc20s, uint192[] calldata targetAmts) external;\n\n    /// Set the prime basket, skipping any constant target amount checks if RToken is reweightable\n    /// Warning: Reweightable RTokens SHOULD use a spell to execute this function to avoid\n    ///          accidentally changing the UoA value of the RToken.\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 forceSetPrimeBasket(IERC20[] calldata erc20s, uint192[] calldata 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    /// Track basket status and collateralization changes\n    /// @custom:refresher\n    function trackStatus() 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 If the basket is ready to issue and trade\n    function isReady() external view returns (bool);\n\n    /// Returns basket quantity rounded up, wihout any issuance premium\n    /// @param erc20 The ERC20 token contract for the asset\n    /// @return {tok/BU} The redemption quantity of token in the reference basket, rounded up\n    /// Returns 0 if erc20 is not registered 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    /// Returns basket quantity rounded up, wihout any issuance premium\n    /// Like quantity(), but unsafe because it DOES NOT CONFIRM THAT THE ASSET IS CORRECT\n    /// @param erc20 The ERC20 token contract for the asset\n    /// @param asset The registered asset plugin contract for the erc20\n    /// @return {tok/BU} The redemption quantity of token in the reference basket, rounded up\n    /// Returns 0 if erc20 is not registered 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 quantityUnsafe(IERC20 erc20, IAsset asset) external view returns (uint192);\n\n    /// @param amount {BU}\n    /// @param applyIssuancePremium Whether to apply the issuance premium\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(\n        uint192 amount,\n        bool applyIssuancePremium,\n        RoundingMode rounding\n    ) external view returns (address[] memory erc20s, uint256[] memory quantities);\n\n    /// Return the redemption value of `amount` BUs for a linear combination of historical baskets\n    /// @param basketNonces An array of basket nonces to do redemption from\n    /// @param portions {1} An array of Fix quantities that must add up to FIX_ONE\n    /// @param amount {BU}\n    /// @return erc20s The backing collateral erc20s\n    /// @return quantities {qTok} ERC20 token quantities equal to `amount` BUs\n    function quoteCustomRedemption(\n        uint48[] memory basketNonces,\n        uint192[] memory portions,\n        uint192 amount\n    ) external view returns (address[] memory erc20s, uint256[] memory quantities);\n\n    /// @return top {BU} The number of partial basket units: e.g max(coll.map((c) => c.balAsBUs())\n    ///         bottom {BU} The number of whole basket units held by the account\n    function basketsHeldBy(address account) external view returns (BasketRange memory);\n\n    /// Should not revert\n    /// low should be nonzero when BUs are worth selling\n    /// @param applyIssuancePremium Whether to apply the issuance premium to the high price\n    /// @return low {UoA/BU} The lower end of the price estimate\n    /// @return high {UoA/BU} The upper end of the price estimate\n    function price(bool applyIssuancePremium) external view returns (uint192 low, uint192 high);\n\n    /// @return timestamp The timestamp at which the basket was last set\n    function timestamp() external view returns (uint48);\n\n    /// @return The current basket nonce, regardless of status\n    function nonce() external view returns (uint48);\n}\n\ninterface TestIBasketHandler is IBasketHandler {\n    function getPrimeBasket()\n        external\n        view\n        returns (\n            IERC20[] memory erc20s,\n            bytes32[] memory targetNames,\n            uint192[] memory targetAmts\n        );\n\n    function getBackupConfig(bytes32 targetName)\n        external\n        view\n        returns (IERC20[] memory erc20s, uint256 max);\n\n    function lastCollateralized() external view returns (uint48);\n\n    function warmupPeriod() external view returns (uint48);\n\n    function setWarmupPeriod(uint48 val) external;\n\n    function enableIssuancePremium() external view returns (bool);\n\n    function setIssuancePremiumEnabled(bool val) external;\n}\n"},{"file_path":"@openzeppelin/contracts/utils/introspection/IERC165.sol","source_code":"// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts v4.4.1 (utils/introspection/IERC165.sol)\n\npragma solidity ^0.8.0;\n\n/**\n * @dev Interface of the ERC165 standard, as defined in the\n * https://eips.ethereum.org/EIPS/eip-165[EIP].\n *\n * Implementers can declare support of contract interfaces, which can then be\n * queried by others ({ERC165Checker}).\n *\n * For an implementation, see {ERC165}.\n */\ninterface IERC165 {\n    /**\n     * @dev Returns true if this contract implements the interface defined by\n     * `interfaceId`. See the corresponding\n     * https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section]\n     * to learn more about how these ids are created.\n     *\n     * This function call must use less than 30 000 gas.\n     */\n    function supportsInterface(bytes4 interfaceId) external view returns (bool);\n}\n"}],"certified":false,"conflicting_implementations":null,"abi":[{"inputs":[],"name":"UIntOutOfBounds","type":"error"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"previousAdmin","type":"address"},{"indexed":false,"internalType":"address","name":"newAdmin","type":"address"}],"name":"AdminChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":true,"internalType":"address","name":"spender","type":"address"},{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":"Approval","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint192","name":"oldBasketsNeeded","type":"uint192"},{"indexed":false,"internalType":"uint192","name":"newBasketsNeeded","type":"uint192"}],"name":"BasketsNeededChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"beacon","type":"address"}],"name":"BeaconUpgraded","type":"event"},{"anonymous":false,"inputs":[],"name":"EIP712DomainChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint8","name":"version","type":"uint8"}],"name":"Initialized","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"issuer","type":"address"},{"indexed":true,"internalType":"address","name":"recipient","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"},{"indexed":false,"internalType":"uint192","name":"baskets","type":"uint192"}],"name":"Issuance","type":"event"},{"anonymous":false,"inputs":[{"components":[{"internalType":"uint256","name":"amtRate","type":"uint256"},{"internalType":"uint192","name":"pctRate","type":"uint192"}],"indexed":false,"internalType":"struct ThrottleLib.Params","name":"oldVal","type":"tuple"},{"components":[{"internalType":"uint256","name":"amtRate","type":"uint256"},{"internalType":"uint192","name":"pctRate","type":"uint192"}],"indexed":false,"internalType":"struct ThrottleLib.Params","name":"newVal","type":"tuple"}],"name":"IssuanceThrottleSet","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"string","name":"oldVal","type":"string"},{"indexed":false,"internalType":"string","name":"newVal","type":"string"}],"name":"MandateSet","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"Melted","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"redeemer","type":"address"},{"indexed":true,"internalType":"address","name":"recipient","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"},{"indexed":false,"internalType":"uint192","name":"baskets","type":"uint192"}],"name":"Redemption","type":"event"},{"anonymous":false,"inputs":[{"components":[{"internalType":"uint256","name":"amtRate","type":"uint256"},{"internalType":"uint192","name":"pctRate","type":"uint192"}],"indexed":false,"internalType":"struct ThrottleLib.Params","name":"oldVal","type":"tuple"},{"components":[{"internalType":"uint256","name":"amtRate","type":"uint256"},{"internalType":"uint192","name":"pctRate","type":"uint192"}],"indexed":false,"internalType":"struct ThrottleLib.Params","name":"newVal","type":"tuple"}],"name":"RedemptionThrottleSet","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"from","type":"address"},{"indexed":true,"internalType":"address","name":"to","type":"address"},{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":"Transfer","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"implementation","type":"address"}],"name":"Upgraded","type":"event"},{"inputs":[],"name":"DOMAIN_SEPARATOR","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"MAX_EXCHANGE_RATE","outputs":[{"internalType":"uint192","name":"","type":"uint192"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"MAX_THROTTLE_PCT_AMT","outputs":[{"internalType":"uint192","name":"","type":"uint192"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"MAX_THROTTLE_RATE_AMT","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"MIN_EXCHANGE_RATE","outputs":[{"internalType":"uint192","name":"","type":"uint192"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"MIN_THROTTLE_DELTA","outputs":[{"internalType":"uint192","name":"","type":"uint192"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"MIN_THROTTLE_RATE_AMT","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"},{"internalType":"address","name":"spender","type":"address"}],"name":"allowance","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"approve","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"balanceOf","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"basketsNeeded","outputs":[{"internalType":"uint192","name":"","type":"uint192"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"decimals","outputs":[{"internalType":"uint8","name":"","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"subtractedValue","type":"uint256"}],"name":"decreaseAllowance","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"dissolve","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"eip712Domain","outputs":[{"internalType":"bytes1","name":"fields","type":"bytes1"},{"internalType":"string","name":"name","type":"string"},{"internalType":"string","name":"version","type":"string"},{"internalType":"uint256","name":"chainId","type":"uint256"},{"internalType":"address","name":"verifyingContract","type":"address"},{"internalType":"bytes32","name":"salt","type":"bytes32"},{"internalType":"uint256[]","name":"extensions","type":"uint256[]"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"addedValue","type":"uint256"}],"name":"increaseAllowance","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"contract IMain","name":"main_","type":"address"},{"internalType":"string","name":"name_","type":"string"},{"internalType":"string","name":"symbol_","type":"string"},{"internalType":"string","name":"mandate_","type":"string"},{"components":[{"internalType":"uint256","name":"amtRate","type":"uint256"},{"internalType":"uint192","name":"pctRate","type":"uint192"}],"internalType":"struct ThrottleLib.Params","name":"issuanceThrottleParams_","type":"tuple"},{"components":[{"internalType":"uint256","name":"amtRate","type":"uint256"},{"internalType":"uint192","name":"pctRate","type":"uint192"}],"internalType":"struct ThrottleLib.Params","name":"redemptionThrottleParams_","type":"tuple"}],"name":"init","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"issuanceAvailable","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"issuanceThrottleParams","outputs":[{"components":[{"internalType":"uint256","name":"amtRate","type":"uint256"},{"internalType":"uint192","name":"pctRate","type":"uint192"}],"internalType":"struct ThrottleLib.Params","name":"","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"issue","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"recipient","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"issueTo","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"main","outputs":[{"internalType":"contract IMain","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"mandate","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"amtRToken","type":"uint256"}],"name":"melt","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint192","name":"baskets","type":"uint192"}],"name":"mint","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"contract IERC20","name":"erc20","type":"address"}],"name":"monetizeDonations","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"name","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"}],"name":"nonces","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"},{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"value","type":"uint256"},{"internalType":"uint256","name":"deadline","type":"uint256"},{"internalType":"uint8","name":"v","type":"uint8"},{"internalType":"bytes32","name":"r","type":"bytes32"},{"internalType":"bytes32","name":"s","type":"bytes32"}],"name":"permit","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"proxiableUUID","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"redeem","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"recipient","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"uint48[]","name":"basketNonces","type":"uint48[]"},{"internalType":"uint192[]","name":"portions","type":"uint192[]"},{"internalType":"address[]","name":"expectedERC20sOut","type":"address[]"},{"internalType":"uint256[]","name":"minAmounts","type":"uint256[]"}],"name":"redeemCustom","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"recipient","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"redeemTo","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"redemptionAvailable","outputs":[{"internalType":"uint256","name":"available","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"redemptionThrottleParams","outputs":[{"components":[{"internalType":"uint256","name":"amtRate","type":"uint256"},{"internalType":"uint192","name":"pctRate","type":"uint192"}],"internalType":"struct ThrottleLib.Params","name":"","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint192","name":"basketsNeeded_","type":"uint192"}],"name":"setBasketsNeeded","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"components":[{"internalType":"uint256","name":"amtRate","type":"uint256"},{"internalType":"uint192","name":"pctRate","type":"uint192"}],"internalType":"struct ThrottleLib.Params","name":"params","type":"tuple"}],"name":"setIssuanceThrottleParams","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"string","name":"mandate_","type":"string"}],"name":"setMandate","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"components":[{"internalType":"uint256","name":"amtRate","type":"uint256"},{"internalType":"uint192","name":"pctRate","type":"uint192"}],"internalType":"struct ThrottleLib.Params","name":"params","type":"tuple"}],"name":"setRedemptionThrottleParams","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"components":[{"internalType":"uint256","name":"amtRate","type":"uint256"},{"internalType":"uint192","name":"pctRate","type":"uint192"}],"internalType":"struct ThrottleLib.Params","name":"issuanceParams","type":"tuple"},{"components":[{"internalType":"uint256","name":"amtRate","type":"uint256"},{"internalType":"uint192","name":"pctRate","type":"uint192"}],"internalType":"struct ThrottleLib.Params","name":"redemptionParams","type":"tuple"}],"name":"setThrottleParams","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"symbol","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalSupply","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"transfer","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"from","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"transferFrom","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newImplementation","type":"address"}],"name":"upgradeTo","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newImplementation","type":"address"},{"internalType":"bytes","name":"data","type":"bytes"}],"name":"upgradeToAndCall","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[],"name":"version","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"pure","type":"function"}],"is_changed_bytecode":false,"is_partially_verified":false,"constructor_args":null}