{"constructor_args":null,"is_partially_verified":true,"is_changed_bytecode":false,"abi":[{"inputs":[],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[{"internalType":"address","name":"authority","type":"address"}],"name":"AccessManagedInvalidAuthority","type":"error"},{"inputs":[{"internalType":"address","name":"caller","type":"address"},{"internalType":"uint32","name":"delay","type":"uint32"}],"name":"AccessManagedRequiredDelay","type":"error"},{"inputs":[{"internalType":"address","name":"caller","type":"address"}],"name":"AccessManagedUnauthorized","type":"error"},{"inputs":[{"internalType":"address","name":"target","type":"address"}],"name":"AddressEmptyCode","type":"error"},{"inputs":[{"internalType":"address","name":"implementation","type":"address"}],"name":"ERC1967InvalidImplementation","type":"error"},{"inputs":[],"name":"ERC1967NonPayable","type":"error"},{"inputs":[],"name":"FailedInnerCall","type":"error"},{"inputs":[],"name":"InvalidCollateral","type":"error"},{"inputs":[],"name":"InvalidCollateralList","type":"error"},{"inputs":[{"internalType":"uint256","name":"index","type":"uint256"}],"name":"InvalidIndex","type":"error"},{"inputs":[],"name":"InvalidInitialization","type":"error"},{"inputs":[],"name":"InvalidMaxCapUnder","type":"error"},{"inputs":[],"name":"InvalidTroveManagerAddresses","type":"error"},{"inputs":[],"name":"NotInitializing","type":"error"},{"inputs":[],"name":"NumberOfCollateralsExceeded","type":"error"},{"inputs":[],"name":"UUPSUnauthorizedCallContext","type":"error"},{"inputs":[{"internalType":"bytes32","name":"slot","type":"bytes32"}],"name":"UUPSUnsupportedProxiableUUID","type":"error"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"authority","type":"address"}],"name":"AuthorityUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"_baseRate","type":"uint256"}],"name":"BaseRateUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"_index","type":"uint256"},{"indexed":false,"internalType":"contract ITroveManager","name":"_troveManager","type":"address"},{"indexed":false,"internalType":"uint256","name":"_maxCap","type":"uint256"}],"name":"BranchCapUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"_index","type":"uint256"}],"name":"BranchShutdown","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"contract IERC20Metadata","name":"_token","type":"address"},{"indexed":false,"internalType":"contract ITroveManager","name":"_troveManager","type":"address"}],"name":"CollateralAdded","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint64","name":"version","type":"uint64"}],"name":"Initialized","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"_lastFeeOpTime","type":"uint256"}],"name":"LastFeeOpTimeUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"implementation","type":"address"}],"name":"Upgraded","type":"event"},{"inputs":[],"name":"UPGRADE_INTERFACE_VERSION","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"contract IERC20Metadata","name":"_token","type":"address"},{"internalType":"contract ITroveManager","name":"_troveManager","type":"address"},{"internalType":"uint256","name":"_maxCap","type":"uint256"}],"name":"addCollateral","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"authority","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"baseRate","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"boldToken","outputs":[{"internalType":"contract IBoldToken","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_index","type":"uint256"},{"internalType":"uint256","name":"_newValue","type":"uint256"}],"name":"decreaseMinAnnualInterestRate","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_index","type":"uint256"}],"name":"getBorrowerOperations","outputs":[{"internalType":"contract IBorrowerOperations","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getBranchCount","outputs":[{"internalType":"uint256","name":"branchCount","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_redeemAmount","type":"uint256"}],"name":"getEffectiveRedemptionFeeInBold","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_ETHDrawn","type":"uint256"}],"name":"getRedemptionFeeWithDecay","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getRedemptionRate","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_redeemAmount","type":"uint256"}],"name":"getRedemptionRateForRedeemedAmount","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getRedemptionRateWithDecay","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_index","type":"uint256"}],"name":"getToken","outputs":[{"internalType":"contract IERC20Metadata","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_index","type":"uint256"}],"name":"getTokenCap","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_troveManagerAddress","type":"address"}],"name":"getTokenCapByAddress","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_index","type":"uint256"}],"name":"getTroveManager","outputs":[{"internalType":"contract ITroveManager","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_authority","type":"address"},{"internalType":"contract IBoldToken","name":"_boldToken","type":"address"},{"internalType":"contract ISequencerSentinel","name":"_sequencerSentinel","type":"address"}],"name":"initialize","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"isConsumingScheduledOp","outputs":[{"internalType":"bytes4","name":"","type":"bytes4"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"lastFeeOperationTime","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"proxiableUUID","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_boldAmount","type":"uint256"},{"internalType":"uint256","name":"_maxIterationsPerCollateral","type":"uint256"},{"internalType":"uint256","name":"_maxFeePercentage","type":"uint256"}],"name":"redeemCollateral","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newAuthority","type":"address"}],"name":"setAuthority","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_index","type":"uint256"},{"internalType":"address","name":"_newInterestRouter","type":"address"}],"name":"setInterestRouter","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_index","type":"uint256"},{"internalType":"uint256","name":"_newValue","type":"uint256"}],"name":"setSPYieldSplit","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_index","type":"uint256"},{"internalType":"uint256","name":"_newValue","type":"uint256"}],"name":"setTokenCap","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_index","type":"uint256"},{"internalType":"uint256","name":"_newValue","type":"uint256"}],"name":"setTroveCCR","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_index","type":"uint256"},{"internalType":"uint256","name":"_newValue","type":"uint256"}],"name":"setTroveMCR","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_index","type":"uint256"},{"internalType":"uint256","name":"_newValue","type":"uint256"}],"name":"setTroveSCR","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_index","type":"uint256"}],"name":"shutdownBranch","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"totalCollaterals","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"newImplementation","type":"address"},{"internalType":"bytes","name":"data","type":"bytes"}],"name":"upgradeToAndCall","outputs":[],"stateMutability":"payable","type":"function"}],"conflicting_implementations":null,"certified":false,"additional_sources":[{"file_path":"src/Interfaces/ILiquityBase.sol","source_code":"// SPDX-License-Identifier: MIT\n\npragma solidity ^0.8.0;\n\nimport \"./IActivePool.sol\";\nimport \"./IDefaultPool.sol\";\nimport \"./IPriceFeed.sol\";\n\ninterface ILiquityBase {\n    function activePool() external view returns (IActivePool);\n    function getEntireBranchDebt() external view returns (uint256);\n    function getEntireBranchColl() external view returns (uint256);\n}\n"},{"file_path":"lib/openzeppelin-contracts-upgradeable/lib/openzeppelin-contracts/contracts/interfaces/draft-IERC1822.sol","source_code":"// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.0.0) (interfaces/draft-IERC1822.sol)\n\npragma solidity ^0.8.20;\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 IERC1822Proxiable {\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":"lib/openzeppelin-contracts-upgradeable/lib/openzeppelin-contracts/contracts/utils/math/Math.sol","source_code":"// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.0.0) (utils/math/Math.sol)\n\npragma solidity ^0.8.20;\n\n/**\n * @dev Standard math utilities missing in the Solidity language.\n */\nlibrary Math {\n    /**\n     * @dev Muldiv operation overflow.\n     */\n    error MathOverflowedMulDiv();\n\n    enum Rounding {\n        Floor, // Toward negative infinity\n        Ceil, // Toward positive infinity\n        Trunc, // Toward zero\n        Expand // Away from zero\n    }\n\n    /**\n     * @dev Returns the addition of two unsigned integers, with an overflow flag.\n     */\n    function tryAdd(uint256 a, uint256 b) internal pure returns (bool, uint256) {\n        unchecked {\n            uint256 c = a + b;\n            if (c < a) return (false, 0);\n            return (true, c);\n        }\n    }\n\n    /**\n     * @dev Returns the subtraction of two unsigned integers, with an overflow flag.\n     */\n    function trySub(uint256 a, uint256 b) internal pure returns (bool, uint256) {\n        unchecked {\n            if (b > a) return (false, 0);\n            return (true, a - b);\n        }\n    }\n\n    /**\n     * @dev Returns the multiplication of two unsigned integers, with an overflow flag.\n     */\n    function tryMul(uint256 a, uint256 b) internal pure returns (bool, uint256) {\n        unchecked {\n            // Gas optimization: this is cheaper than requiring 'a' not being zero, but the\n            // benefit is lost if 'b' is also tested.\n            // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522\n            if (a == 0) return (true, 0);\n            uint256 c = a * b;\n            if (c / a != b) return (false, 0);\n            return (true, c);\n        }\n    }\n\n    /**\n     * @dev Returns the division of two unsigned integers, with a division by zero flag.\n     */\n    function tryDiv(uint256 a, uint256 b) internal pure returns (bool, uint256) {\n        unchecked {\n            if (b == 0) return (false, 0);\n            return (true, a / b);\n        }\n    }\n\n    /**\n     * @dev Returns the remainder of dividing two unsigned integers, with a division by zero flag.\n     */\n    function tryMod(uint256 a, uint256 b) internal pure returns (bool, uint256) {\n        unchecked {\n            if (b == 0) return (false, 0);\n            return (true, a % b);\n        }\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 towards infinity instead\n     * of rounding towards zero.\n     */\n    function ceilDiv(uint256 a, uint256 b) internal pure returns (uint256) {\n        if (b == 0) {\n            // Guarantee the same behavior as in a regular Solidity division.\n            return a / b;\n        }\n\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\n     * denominator == 0.\n     * @dev Original credit to Remco Bloemen under MIT license (https://xn--2-umb.com/21/muldiv) with further edits by\n     * 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 = x * y; // 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                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            if (denominator <= prod1) {\n                revert MathOverflowedMulDiv();\n            }\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.\n            // Always >= 1. See https://cs.stackexchange.com/q/138556/92363.\n\n            uint256 twos = denominator & (0 - denominator);\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\n            // works 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 (unsignedRoundsUp(rounding) && 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\n     * towards zero.\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 + (unsignedRoundsUp(rounding) && result * result < a ? 1 : 0);\n        }\n    }\n\n    /**\n     * @dev Return the log in base 2 of a positive value rounded towards zero.\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 + (unsignedRoundsUp(rounding) && 1 << result < value ? 1 : 0);\n        }\n    }\n\n    /**\n     * @dev Return the log in base 10 of a positive value rounded towards zero.\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 + (unsignedRoundsUp(rounding) && 10 ** result < value ? 1 : 0);\n        }\n    }\n\n    /**\n     * @dev Return the log in base 256 of a positive value rounded towards zero.\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 + (unsignedRoundsUp(rounding) && 1 << (result << 3) < value ? 1 : 0);\n        }\n    }\n\n    /**\n     * @dev Returns whether a provided rounding mode is considered rounding up for unsigned integers.\n     */\n    function unsignedRoundsUp(Rounding rounding) internal pure returns (bool) {\n        return uint8(rounding) % 2 == 1;\n    }\n}\n"},{"file_path":"src/Interfaces/ISortedTroves.sol","source_code":"// SPDX-License-Identifier: MIT\n\npragma solidity ^0.8.0;\n\nimport \"./ITroveManager.sol\";\nimport {BatchId, BATCH_ID_ZERO} from \"../Types/BatchId.sol\";\n\ninterface ISortedTroves {\n    // -- Mutating functions (permissioned) --\n    function insert(uint256 _id, uint256 _annualInterestRate, uint256 _prevId, uint256 _nextId) external;\n    function insertIntoBatch(\n        uint256 _troveId,\n        BatchId _batchId,\n        uint256 _annualInterestRate,\n        uint256 _prevId,\n        uint256 _nextId\n    ) external;\n\n    function remove(uint256 _id) external;\n    function removeFromBatch(uint256 _id) external;\n\n    function reInsert(uint256 _id, uint256 _newAnnualInterestRate, uint256 _prevId, uint256 _nextId) external;\n    function reInsertBatch(BatchId _id, uint256 _newAnnualInterestRate, uint256 _prevId, uint256 _nextId) external;\n\n    // -- View functions --\n\n    function contains(uint256 _id) external view returns (bool);\n    function isBatchedNode(uint256 _id) external view returns (bool);\n    function isEmptyBatch(BatchId _id) external view returns (bool);\n\n    function isEmpty() external view returns (bool);\n    function getSize() external view returns (uint256);\n\n    function getFirst() external view returns (uint256);\n    function getLast() external view returns (uint256);\n    function getNext(uint256 _id) external view returns (uint256);\n    function getPrev(uint256 _id) external view returns (uint256);\n\n    function validInsertPosition(uint256 _annualInterestRate, uint256 _prevId, uint256 _nextId)\n        external\n        view\n        returns (bool);\n    function findInsertPosition(uint256 _annualInterestRate, uint256 _prevId, uint256 _nextId)\n        external\n        view\n        returns (uint256, uint256);\n\n    // Public state variable getters\n    function borrowerOperationsAddress() external view returns (address);\n    function troveManager() external view returns (ITroveManager);\n    function size() external view returns (uint256);\n    function nodes(uint256 _id) external view returns (uint256 nextId, uint256 prevId, BatchId batchId, bool exists);\n    function batches(BatchId _id) external view returns (uint256 head, uint256 tail);\n}\n"},{"file_path":"lib/openzeppelin-contracts-upgradeable/lib/openzeppelin-contracts/contracts/token/ERC721/extensions/IERC721Metadata.sol","source_code":"// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC721/extensions/IERC721Metadata.sol)\n\npragma solidity ^0.8.20;\n\nimport {IERC721} from \"../IERC721.sol\";\n\n/**\n * @title ERC-721 Non-Fungible Token Standard, optional metadata extension\n * @dev See https://eips.ethereum.org/EIPS/eip-721\n */\ninterface IERC721Metadata is IERC721 {\n    /**\n     * @dev Returns the token collection name.\n     */\n    function name() external view returns (string memory);\n\n    /**\n     * @dev Returns the token collection symbol.\n     */\n    function symbol() external view returns (string memory);\n\n    /**\n     * @dev Returns the Uniform Resource Identifier (URI) for `tokenId` token.\n     */\n    function tokenURI(uint256 tokenId) external view returns (string memory);\n}\n"},{"file_path":"src/Interfaces/ICollateralRegistry.sol","source_code":"// SPDX-License-Identifier: MIT\n\npragma solidity ^0.8.0;\n\nimport \"openzeppelin-contracts/contracts/token/ERC20/extensions/IERC20Metadata.sol\";\nimport \"./IBoldToken.sol\";\nimport \"./ITroveManager.sol\";\n\ninterface ICollateralRegistry {\n    function baseRate() external view returns (uint256);\n    function lastFeeOperationTime() external view returns (uint256);\n\n    function redeemCollateral(uint256 _boldamount, uint256 _maxIterations, uint256 _maxFeePercentage) external;\n\n    // getters\n    function totalCollaterals() external view returns (uint256);\n    function getToken(uint256 _index) external view returns (IERC20Metadata);\n    function getTroveManager(uint256 _index) external view returns (ITroveManager);\n    function getTokenCap(uint256 _index) external view returns (uint256);\n    function getTokenCapByAddress(address _troveManagerAddress) external view returns (uint256);\n    function boldToken() external view returns (IBoldToken);\n\n    function getRedemptionRate() external view returns (uint256);\n    function getRedemptionRateWithDecay() external view returns (uint256);\n    function getRedemptionRateForRedeemedAmount(uint256 _redeemAmount) external view returns (uint256);\n\n    function getRedemptionFeeWithDecay(uint256 _ETHDrawn) external view returns (uint256);\n    function getEffectiveRedemptionFeeInBold(uint256 _redeemAmount) external view returns (uint256);\n\n    // Governance functions\n\n    function addCollateral(IERC20Metadata _token, ITroveManager _troveManager, uint256 _maxCap) external;\n    function setTroveCCR(uint256 _index, uint256 _newValue) external;\n    function setTroveMCR(uint256 _index, uint256 _newValue) external;\n    function setTroveSCR(uint256 _index, uint256 _newValue) external;\n    function setSPYieldSplit(uint256 _index, uint256 _newValue) external;\n    function decreaseMinAnnualInterestRate(uint256 _index, uint256 _minAnnualInterestRate) external;\n    function setInterestRouter(uint256 _index, address _newInterestRouter) external;\n    function setTokenCap(uint256 _index, uint256 _newValue) external;\n\n    // Emergency Response functions\n    function shutdownBranch(uint256 _index) external;\n}\n"},{"file_path":"src/Interfaces/IBoldToken.sol","source_code":"// SPDX-License-Identifier: MIT\n\npragma solidity ^0.8.0;\n\nimport \"openzeppelin-contracts/contracts/token/ERC20/extensions/IERC20Metadata.sol\";\nimport \"openzeppelin-contracts/contracts/token/ERC20/extensions/IERC20Permit.sol\";\nimport \"openzeppelin-contracts/contracts/interfaces/IERC5267.sol\";\n\ninterface IBoldToken is IERC20Metadata, IERC20Permit, IERC5267 {\n    function setBranchAddresses(\n        uint256 _collIndex,\n        address _collateralAddress,\n        address _troveManagerAddress,\n        address _stabilityPoolAddress,\n        address _borrowerOperationsAddress,\n        address _activePoolAddress\n    ) external;\n\n    function setCollateralRegistry(address _collateralRegistryAddress) external;\n\n    function mint(address _account, uint256 _amount) external;\n\n    function burn(address _account, uint256 _amount) external;\n\n    function sendToPool(address _sender, address poolAddress, uint256 _amount) external;\n\n    function returnFromPool(address poolAddress, address user, uint256 _amount) external;\n}\n"},{"file_path":"src/Interfaces/IActivePool.sol","source_code":"// SPDX-License-Identifier: MIT\n\npragma solidity ^0.8.0;\n\nimport \"./IInterestRouter.sol\";\nimport \"./IBoldRewardsReceiver.sol\";\nimport \"../Types/TroveChange.sol\";\n\ninterface IActivePool {\n    function defaultPoolAddress() external view returns (address);\n    function borrowerOperationsAddress() external view returns (address);\n    function troveManagerAddress() external view returns (address);\n    function interestRouter() external view returns (IInterestRouter);\n    // We avoid IStabilityPool here in order to prevent creating a dependency cycle that would break flattening\n    function stabilityPool() external view returns (IBoldRewardsReceiver);\n\n    function getCollBalance() external view returns (uint256);\n    function stabilityPoolYieldSplit() external view returns (uint256);\n    function getBoldDebt() external view returns (uint256);\n    function lastAggUpdateTime() external view returns (uint256);\n    function aggRecordedDebt() external view returns (uint256);\n    function aggWeightedDebtSum() external view returns (uint256);\n    function aggBatchManagementFees() external view returns (uint256);\n    function aggWeightedBatchManagementFeeSum() external view returns (uint256);\n    function calcPendingAggInterest() external view returns (uint256);\n    function calcPendingSPYield() external view returns (uint256);\n    function calcPendingAggBatchManagementFee() external view returns (uint256);\n    function getNewApproxAvgInterestRateFromTroveChange(TroveChange calldata _troveChange)\n        external\n        view\n        returns (uint256);\n\n    function mintAggInterest() external;\n    function mintAggInterestAndAccountForTroveChange(TroveChange calldata _troveChange, address _batchManager)\n        external;\n    function mintBatchManagementFeeAndAccountForChange(TroveChange calldata _troveChange, address _batchAddress)\n        external;\n\n    function setShutdownFlag() external;\n    function hasBeenShutDown() external view returns (bool);\n    function shutdownTime() external view returns (uint256);\n\n    function sendColl(address _account, uint256 _amount) external;\n    function sendCollToDefaultPool(uint256 _amount) external;\n    function receiveColl(uint256 _amount) external;\n    function accountForReceivedColl(uint256 _amount) external;\n\n    // Governance \n    function setSPYieldSplit(uint256 _newSplit) external;\n    function setInterestRouter(address _newInterestRouter) external;\n}\n"},{"file_path":"src/Interfaces/IInterestRouter.sol","source_code":"// SPDX-License-Identifier: MIT\n\npragma solidity ^0.8.0;\n\ninterface IInterestRouter {\n// Currently the Interest Router doesn’t need any specific function\n}\n"},{"file_path":"src/Interfaces/ITroveManager.sol","source_code":"// SPDX-License-Identifier: MIT\n\npragma solidity ^0.8.0;\n\nimport \"./ILiquityBase.sol\";\nimport \"./ITroveNFT.sol\";\nimport \"./IBorrowerOperations.sol\";\nimport \"./IStabilityPool.sol\";\nimport \"./IBoldToken.sol\";\nimport \"./ISortedTroves.sol\";\nimport \"../Types/LatestTroveData.sol\";\nimport \"../Types/LatestBatchData.sol\";\n\n// Common interface for the Trove Manager.\ninterface ITroveManager is ILiquityBase {\n    enum Status {\n        nonExistent,\n        active,\n        closedByOwner,\n        closedByLiquidation,\n        zombie\n    }\n\n    function shutdownTime() external view returns (uint256);\n\n    function CCR() external view returns (uint256);\n    function MCR() external view returns (uint256);\n    function SCR() external view returns (uint256);\n    function BCR() external view returns (uint256);\n    function MIN_DEBT() external view returns (uint256);\n    function minAnnualInterestRate() external view returns (uint256);\n    function liquidationPenaltySP() external view returns (uint256);\n    function liquidationPenaltyRedistribution() external view returns (uint256);\n\n    function troveNFT() external view returns (ITroveNFT);\n    function stabilityPool() external view returns (IStabilityPool);\n    //function boldToken() external view returns (IBoldToken);\n    function sortedTroves() external view returns (ISortedTroves);\n    function borrowerOperations() external view returns (IBorrowerOperations);\n\n    function Troves(uint256 _id)\n        external\n        view\n        returns (\n            uint256 debt,\n            uint256 coll,\n            uint256 stake,\n            Status status,\n            uint64 arrayIndex,\n            uint64 lastDebtUpdateTime,\n            uint64 lastInterestRateAdjTime,\n            uint256 annualInterestRate,\n            address interestBatchManager,\n            uint256 batchDebtShares\n        );\n\n    function rewardSnapshots(uint256 _id) external view returns (uint256 coll, uint256 boldDebt);\n\n    function getTroveIdsCount() external view returns (uint256);\n\n    function getTroveFromTroveIdsArray(uint256 _index) external view returns (uint256);\n\n    function getCurrentICR(uint256 _troveId, uint256 _price) external view returns (uint256);\n\n    function getBorrowerOperations() external view returns (IBorrowerOperations);\n\n    function getCollateralRegistry() external view returns (address);\n\n    function lastZombieTroveId() external view returns (uint256);\n\n    function batchLiquidateTroves(uint256[] calldata _troveArray) external;\n\n    function redeemCollateral(\n        address _sender,\n        uint256 _boldAmount,\n        uint256 _price,\n        uint256 _redemptionRate,\n        uint256 _maxIterations\n    ) external returns (uint256 _redemeedAmount);\n\n    function shutdown() external;\n    function urgentRedemption(uint256 _boldAmount, uint256[] calldata _troveIds, uint256 _minCollateral) external;\n\n    function getUnbackedPortionPriceAndRedeemability() external returns (uint256, uint256, bool);\n\n    function getLatestTroveData(uint256 _troveId) external view returns (LatestTroveData memory);\n    function getTroveAnnualInterestRate(uint256 _troveId) external view returns (uint256);\n\n    function getTroveStatus(uint256 _troveId) external view returns (Status);\n\n    function getLatestBatchData(address _batchAddress) external view returns (LatestBatchData memory);\n\n    // -- permissioned functions called by BorrowerOperations\n\n    function onOpenTrove(address _owner, uint256 _troveId, TroveChange memory _troveChange, uint256 _annualInterestRate)\n        external;\n    function onOpenTroveAndJoinBatch(\n        address _owner,\n        uint256 _troveId,\n        TroveChange memory _troveChange,\n        address _batchAddress,\n        uint256 _batchColl,\n        uint256 _batchDebt\n    ) external;\n\n    // Called from `adjustZombieTrove()`\n    function setTroveStatusToActive(uint256 _troveId) external;\n\n    function onAdjustTroveInterestRate(\n        uint256 _troveId,\n        uint256 _newColl,\n        uint256 _newDebt,\n        uint256 _newAnnualInterestRate,\n        TroveChange calldata _troveChange\n    ) external;\n\n    function onAdjustTrove(uint256 _troveId, uint256 _newColl, uint256 _newDebt, TroveChange calldata _troveChange)\n        external;\n\n    function onAdjustTroveInsideBatch(\n        uint256 _troveId,\n        uint256 _newTroveColl,\n        uint256 _newTroveDebt,\n        TroveChange memory _troveChange,\n        address _batchAddress,\n        uint256 _newBatchColl,\n        uint256 _newBatchDebt\n    ) external;\n\n    function onApplyTroveInterest(\n        uint256 _troveId,\n        uint256 _newTroveColl,\n        uint256 _newTroveDebt,\n        address _batchAddress,\n        uint256 _newBatchColl,\n        uint256 _newBatchDebt,\n        TroveChange calldata _troveChange\n    ) external;\n\n    function onCloseTrove(\n        uint256 _troveId,\n        TroveChange memory _troveChange, // decrease vars: entire, with interest, batch fee and redistribution\n        address _batchAddress,\n        uint256 _newBatchColl,\n        uint256 _newBatchDebt // entire, with interest and batch fee\n    ) external;\n\n    // -- batches --\n    function onRegisterBatchManager(address _batchAddress, uint256 _annualInterestRate, uint256 _annualFee) external;\n    function onLowerBatchManagerAnnualFee(\n        address _batchAddress,\n        uint256 _newColl,\n        uint256 _newDebt,\n        uint256 _newAnnualManagementFee\n    ) external;\n    function onSetBatchManagerAnnualInterestRate(\n        address _batchAddress,\n        uint256 _newColl,\n        uint256 _newDebt,\n        uint256 _newAnnualInterestRate,\n        uint256 _upfrontFee // needed by BatchUpdated event\n    ) external;\n\n    struct OnSetInterestBatchManagerParams {\n        uint256 troveId;\n        uint256 troveColl; // entire, with redistribution\n        uint256 troveDebt; // entire, with interest, batch fee and redistribution\n        TroveChange troveChange;\n        address newBatchAddress;\n        uint256 newBatchColl; // updated collateral for new batch manager\n        uint256 newBatchDebt; // updated debt for new batch manager\n    }\n\n    function onSetInterestBatchManager(OnSetInterestBatchManagerParams calldata _params) external;\n    function onRemoveFromBatch(\n        uint256 _troveId,\n        uint256 _newTroveColl, // entire, with redistribution\n        uint256 _newTroveDebt, // entire, with interest, batch fee and redistribution\n        TroveChange memory _troveChange,\n        address _batchAddress,\n        uint256 _newBatchColl,\n        uint256 _newBatchDebt, // entire, with interest and batch fee\n        uint256 _newAnnualInterestRate\n    ) external;\n\n    // -- end of permissioned functions --\n\n    // Governance functions\n    function setNewBranchConfiguration(\n        uint256 _SCR,\n        uint256 _MCR,\n        uint256 _CCR,\n        uint256 _BCR,\n        uint256 _newLiquidationPenaltySP,\n        uint256 _newLiquidationPenaltyRedistribution,\n        uint256 _minAnnualInterestRate\n    ) external;\n\n    event BranchConfigurationUpdated(\n        uint256 _scr,\n        uint256 _mcr,\n        uint256 _ccr,\n        uint256 _bcr,\n        uint256 _newLiquidationPenaltySP,\n        uint256 _newLiquidationPenaltyRedistribution,\n        uint256 _minAnnualInterestRate\n    );\n}\n"},{"file_path":"src/Dependencies/Constants.sol","source_code":"// SPDX-License-Identifier: BUSL-1.1\npragma solidity ^0.8.24;\n\naddress constant ZERO_ADDRESS = address(0);\n\nuint256 constant MAX_UINT256 = type(uint256).max;\n\nuint256 constant DECIMAL_PRECISION = 1e18;\nuint256 constant _100pct = DECIMAL_PRECISION;\nuint256 constant _200pct = 2 * _100pct;\nuint256 constant _1pct = DECIMAL_PRECISION / 100;\n\n// Amount of ETH to be locked in gas pool on opening troves\nuint256 constant ETH_GAS_COMPENSATION = 0.005 ether;\n\n// Liquidation\nuint256 constant MIN_LIQUIDATION_PENALTY_SP = 5e16; // 5%\nuint256 constant MAX_LIQUIDATION_PENALTY_REDISTRIBUTION = 20e16; // 20%\n\n// Collateral branch parameters (SETH = staked ETH, i.e. wstETH / rETH)\nuint256 constant CCR_WETH = 150 * _1pct;\nuint256 constant CCR_SETH = 160 * _1pct;\n\nuint256 constant MCR_WETH = 110 * _1pct;\nuint256 constant MCR_SETH = 120 * _1pct;\n\nuint256 constant SCR_WETH = 110 * _1pct;\nuint256 constant SCR_SETH = 120 * _1pct;\n\n// Batch CR buffer (same for all branches for now)\n// On top of MCR to join a batch, or adjust inside a batch\nuint256 constant BCR_ALL = 10 * _1pct;\n\nuint256 constant LIQUIDATION_PENALTY_SP_WETH = 5 * _1pct;\nuint256 constant LIQUIDATION_PENALTY_SP_SETH = 5 * _1pct;\n\nuint256 constant LIQUIDATION_PENALTY_REDISTRIBUTION_WETH = 10 * _1pct;\nuint256 constant LIQUIDATION_PENALTY_REDISTRIBUTION_SETH = 20 * _1pct;\n\n// Fraction of collateral awarded to liquidator\nuint256 constant COLL_GAS_COMPENSATION_DIVISOR = 200; // dividing by 200 yields 0.5%\nuint256 constant COLL_GAS_COMPENSATION_CAP = 2 ether; // Max coll gas compensation capped at 2 ETH\n\n// Minimum amount of net Bold debt the protocol allows a trove must have\n// The actual amount is defined per collateral,\n// but can never be lower than this constant\nuint256 constant MIN_ALLOWED_DEBT = 200e18;\n\nuint256 constant MIN_POSSIBLE_ANNUAL_INTEREST_RATE = _1pct / 2; // 0.5%\n\n// we can't use math operators on the constant declaration, since that puts us above contract size limits\n// so this constant is hardcoded instead of depending on _1pct. To safeguard, a forge test was added to ensure the relationship remains the same and future refactors don't break anything\nuint256 constant MAX_ANNUAL_INTEREST_RATE = 350e16;\n\n// Batch management params\nuint128 constant MAX_ANNUAL_BATCH_MANAGEMENT_FEE = uint128(_100pct / 10); // 10%\nuint128 constant MIN_INTEREST_RATE_CHANGE_PERIOD = 1200 seconds; // prevents adjusting interest rates too frequently\n\nuint256 constant REDEMPTION_FEE_FLOOR = _1pct / 2; // 0.5%\n\n// For the debt / shares ratio to increase by a factor 1e9\n// at a average annual debt increase (compounded interest + fees) of 10%, it would take more than 217 years (log(1e9)/log(1.1))\n// at a average annual debt increase (compounded interest + fees) of 50%, it would take more than 51 years (log(1e9)/log(1.5))\n// The increase pace could be forced to be higher through an inflation attack,\n// but precisely the fact that we have this max value now prevents the attack\nuint256 constant MAX_BATCH_SHARES_RATIO = 1e9;\n\n// Half-life of 6h. 6h = 360 min\n// (1/2) = d^360 => d = (1/2)^(1/360)\nuint256 constant REDEMPTION_MINUTE_DECAY_FACTOR = 998076443575628800;\n\n// BETA: 18 digit decimal. Parameter by which to divide the redeemed fraction, in order to calc the new base rate from a redemption.\n// Corresponds to (1 / ALPHA) in the white paper.\nuint256 constant REDEMPTION_BETA = 1;\n\n// To prevent redemptions unless Bold depegs below 0.95 and allow the system to take off\nuint256 constant INITIAL_BASE_RATE = _100pct; // 100% initial redemption rate\n\n// Discount to be used once the shutdown thas been triggered\nuint256 constant URGENT_REDEMPTION_BONUS = 2e16; // 2%\n\nuint256 constant ONE_MINUTE = 1 minutes;\nuint256 constant ONE_YEAR = 365 days;\nuint256 constant UPFRONT_INTEREST_PERIOD = 7 days;\nuint256 constant INTEREST_RATE_ADJ_COOLDOWN = 7 days;\n\nuint256 constant MAX_NUMBER_COLLATERALS = 15;\n\nuint256 constant MINIMUM_MAX_CAP_PER_BRANCH = MIN_ALLOWED_DEBT * 10;\n\nuint256 constant MIN_BOLD_IN_SP = 1e18;\n\n// Dummy contract that lets legacy Hardhat tests query some of the constants\ncontract Constants {\n    uint256 public constant _ETH_GAS_COMPENSATION = ETH_GAS_COMPENSATION;\n}\n"},{"file_path":"src/Interfaces/IStabilityPool.sol","source_code":"// SPDX-License-Identifier: MIT\n\npragma solidity ^0.8.0;\n\nimport \"./IActivePool.sol\";\nimport \"./ILiquityBase.sol\";\nimport \"./IBoldToken.sol\";\nimport \"./ITroveManager.sol\";\nimport \"./IBoldRewardsReceiver.sol\";\n\n/*\n * The Stability Pool holds Bold tokens deposited by Stability Pool depositors.\n *\n * When a trove is liquidated, then depending on system conditions, some of its Bold debt gets offset with\n * Bold in the Stability Pool:  that is, the offset debt evaporates, and an equal amount of Bold tokens in the Stability Pool is burned.\n *\n * Thus, a liquidation causes each depositor to receive a Bold loss, in proportion to their deposit as a share of total deposits.\n * They also receive an Coll gain, as the collateral of the liquidated trove is distributed among Stability depositors,\n * in the same proportion.\n *\n * When a liquidation occurs, it depletes every deposit by the same fraction: for example, a liquidation that depletes 40%\n * of the total Bold in the Stability Pool, depletes 40% of each deposit.\n *\n * A deposit that has experienced a series of liquidations is termed a \"compounded deposit\": each liquidation depletes the deposit,\n * multiplying it by some factor in range ]0,1[\n *\n * Please see the implementation spec in the proof document, which closely follows on from the compounded deposit / Coll gain derivations:\n * https://github.com/liquity/liquity/blob/master/papers/Scalable_Reward_Distribution_with_Compounding_Stakes.pdf\n *\n*/\ninterface IStabilityPool is ILiquityBase, IBoldRewardsReceiver {\n    function boldToken() external view returns (IBoldToken);\n    function troveManager() external view returns (ITroveManager);\n\n    /*  provideToSP():\n    * - Calculates depositor's Coll gain\n    * - Calculates the compounded deposit\n    * - Increases deposit, and takes new snapshots of accumulators P and S\n    * - Sends depositor's accumulated Coll gains to depositor\n    */\n    function provideToSP(uint256 _amount, bool _doClaim) external;\n\n    /*  withdrawFromSP():\n    * - Calculates depositor's Coll gain\n    * - Calculates the compounded deposit\n    * - Sends the requested BOLD withdrawal to depositor\n    * - (If _amount > userDeposit, the user withdraws all of their compounded deposit)\n    * - Decreases deposit by withdrawn amount and takes new snapshots of accumulators P and S\n    */\n    function withdrawFromSP(uint256 _amount, bool doClaim) external;\n\n    function claimAllCollGains() external;\n\n    /*\n     * Initial checks:\n     * - Caller is TroveManager\n     * ---\n     * Cancels out the specified debt against the Bold contained in the Stability Pool (as far as possible)\n     * and transfers the Trove's collateral from ActivePool to StabilityPool.\n     * Only called by liquidation functions in the TroveManager.\n     */\n    function offset(uint256 _debt, uint256 _coll) external;\n\n    function deposits(address _depositor) external view returns (uint256 initialValue);\n    function stashedColl(address _depositor) external view returns (uint256);\n\n    /*\n     * Returns the total amount of Coll held by the pool, accounted in an internal variable instead of `balance`,\n     * to exclude edge cases like Coll received from a self-destruct.\n     */\n    function getCollBalance() external view returns (uint256);\n\n    /*\n     * Returns Bold held in the pool. Changes when users deposit/withdraw, and when Trove debt is offset.\n     */\n    function getTotalBoldDeposits() external view returns (uint256);\n\n    function getYieldGainsOwed() external view returns (uint256);\n    function getYieldGainsPending() external view returns (uint256);\n\n    /*\n     * Calculates the Coll gain earned by the deposit since its last snapshots were taken.\n     */\n    function getDepositorCollGain(address _depositor) external view returns (uint256);\n\n    /*\n     * Calculates the BOLD yield gain earned by the deposit since its last snapshots were taken.\n     */\n    function getDepositorYieldGain(address _depositor) external view returns (uint256);\n\n    /*\n     * Calculates what `getDepositorYieldGain` will be if interest is minted now.\n     */\n    function getDepositorYieldGainWithPending(address _depositor) external view returns (uint256);\n\n    /*\n     * Return the user's compounded deposit.\n     */\n    function getCompoundedBoldDeposit(address _depositor) external view returns (uint256);\n\n    function scaleToS(uint256 _scale) external view returns (uint256);\n\n    function scaleToB(uint256 _scale) external view returns (uint256);\n\n    function P() external view returns (uint256);\n    function currentScale() external view returns (uint256);\n\n    function P_PRECISION() external view returns (uint256);\n}\n"},{"file_path":"src/Interfaces/IDefaultPool.sol","source_code":"// SPDX-License-Identifier: MIT\n\npragma solidity ^0.8.0;\n\ninterface IDefaultPool {\n    function troveManagerAddress() external view returns (address);\n    function activePoolAddress() external view returns (address);\n    // --- Functions ---\n    function getCollBalance() external view returns (uint256);\n    function getBoldDebt() external view returns (uint256);\n    function sendCollToActivePool(uint256 _amount) external;\n    function receiveColl(uint256 _amount) external;\n\n    function increaseBoldDebt(uint256 _amount) external;\n    function decreaseBoldDebt(uint256 _amount) external;\n}\n"},{"file_path":"lib/openzeppelin-contracts-upgradeable/contracts/access/manager/AccessManagedUpgradeable.sol","source_code":"// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.0.0) (access/manager/AccessManaged.sol)\n\npragma solidity ^0.8.20;\n\nimport {IAuthority} from \"@openzeppelin/contracts/access/manager/IAuthority.sol\";\nimport {AuthorityUtils} from \"@openzeppelin/contracts/access/manager/AuthorityUtils.sol\";\nimport {IAccessManager} from \"@openzeppelin/contracts/access/manager/IAccessManager.sol\";\nimport {IAccessManaged} from \"@openzeppelin/contracts/access/manager/IAccessManaged.sol\";\nimport {ContextUpgradeable} from \"../../utils/ContextUpgradeable.sol\";\nimport {Initializable} from \"../../proxy/utils/Initializable.sol\";\n\n/**\n * @dev This contract module makes available a {restricted} modifier. Functions decorated with this modifier will be\n * permissioned according to an \"authority\": a contract like {AccessManager} that follows the {IAuthority} interface,\n * implementing a policy that allows certain callers to access certain functions.\n *\n * IMPORTANT: The `restricted` modifier should never be used on `internal` functions, judiciously used in `public`\n * functions, and ideally only used in `external` functions. See {restricted}.\n */\nabstract contract AccessManagedUpgradeable is Initializable, ContextUpgradeable, IAccessManaged {\n    /// @custom:storage-location erc7201:openzeppelin.storage.AccessManaged\n    struct AccessManagedStorage {\n        address _authority;\n\n        bool _consumingSchedule;\n    }\n\n    // keccak256(abi.encode(uint256(keccak256(\"openzeppelin.storage.AccessManaged\")) - 1)) & ~bytes32(uint256(0xff))\n    bytes32 private constant AccessManagedStorageLocation = 0xf3177357ab46d8af007ab3fdb9af81da189e1068fefdc0073dca88a2cab40a00;\n\n    function _getAccessManagedStorage() private pure returns (AccessManagedStorage storage $) {\n        assembly {\n            $.slot := AccessManagedStorageLocation\n        }\n    }\n\n    /**\n     * @dev Initializes the contract connected to an initial authority.\n     */\n    function __AccessManaged_init(address initialAuthority) internal onlyInitializing {\n        __AccessManaged_init_unchained(initialAuthority);\n    }\n\n    function __AccessManaged_init_unchained(address initialAuthority) internal onlyInitializing {\n        _setAuthority(initialAuthority);\n    }\n\n    /**\n     * @dev Restricts access to a function as defined by the connected Authority for this contract and the\n     * caller and selector of the function that entered the contract.\n     *\n     * [IMPORTANT]\n     * ====\n     * In general, this modifier should only be used on `external` functions. It is okay to use it on `public`\n     * functions that are used as external entry points and are not called internally. Unless you know what you're\n     * doing, it should never be used on `internal` functions. Failure to follow these rules can have critical security\n     * implications! This is because the permissions are determined by the function that entered the contract, i.e. the\n     * function at the bottom of the call stack, and not the function where the modifier is visible in the source code.\n     * ====\n     *\n     * [WARNING]\n     * ====\n     * Avoid adding this modifier to the https://docs.soliditylang.org/en/v0.8.20/contracts.html#receive-ether-function[`receive()`]\n     * function or the https://docs.soliditylang.org/en/v0.8.20/contracts.html#fallback-function[`fallback()`]. These\n     * functions are the only execution paths where a function selector cannot be unambiguosly determined from the calldata\n     * since the selector defaults to `0x00000000` in the `receive()` function and similarly in the `fallback()` function\n     * if no calldata is provided. (See {_checkCanCall}).\n     *\n     * The `receive()` function will always panic whereas the `fallback()` may panic depending on the calldata length.\n     * ====\n     */\n    modifier restricted() {\n        _checkCanCall(_msgSender(), _msgData());\n        _;\n    }\n\n    /// @inheritdoc IAccessManaged\n    function authority() public view virtual returns (address) {\n        AccessManagedStorage storage $ = _getAccessManagedStorage();\n        return $._authority;\n    }\n\n    /// @inheritdoc IAccessManaged\n    function setAuthority(address newAuthority) public virtual {\n        address caller = _msgSender();\n        if (caller != authority()) {\n            revert AccessManagedUnauthorized(caller);\n        }\n        if (newAuthority.code.length == 0) {\n            revert AccessManagedInvalidAuthority(newAuthority);\n        }\n        _setAuthority(newAuthority);\n    }\n\n    /// @inheritdoc IAccessManaged\n    function isConsumingScheduledOp() public view returns (bytes4) {\n        AccessManagedStorage storage $ = _getAccessManagedStorage();\n        return $._consumingSchedule ? this.isConsumingScheduledOp.selector : bytes4(0);\n    }\n\n    /**\n     * @dev Transfers control to a new authority. Internal function with no access restriction. Allows bypassing the\n     * permissions set by the current authority.\n     */\n    function _setAuthority(address newAuthority) internal virtual {\n        AccessManagedStorage storage $ = _getAccessManagedStorage();\n        $._authority = newAuthority;\n        emit AuthorityUpdated(newAuthority);\n    }\n\n    /**\n     * @dev Reverts if the caller is not allowed to call the function identified by a selector. Panics if the calldata\n     * is less than 4 bytes long.\n     */\n    function _checkCanCall(address caller, bytes calldata data) internal virtual {\n        AccessManagedStorage storage $ = _getAccessManagedStorage();\n        (bool immediate, uint32 delay) = AuthorityUtils.canCallWithDelay(\n            authority(),\n            caller,\n            address(this),\n            bytes4(data[0:4])\n        );\n        if (!immediate) {\n            if (delay > 0) {\n                $._consumingSchedule = true;\n                IAccessManager(authority()).consumeScheduledOp(caller, data);\n                $._consumingSchedule = false;\n            } else {\n                revert AccessManagedUnauthorized(caller);\n            }\n        }\n    }\n}\n"},{"file_path":"lib/openzeppelin-contracts-upgradeable/lib/openzeppelin-contracts/contracts/token/ERC20/extensions/IERC20Metadata.sol","source_code":"// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC20/extensions/IERC20Metadata.sol)\n\npragma solidity ^0.8.20;\n\nimport {IERC20} from \"../IERC20.sol\";\n\n/**\n * @dev Interface for the optional metadata functions from the ERC20 standard.\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":"lib/openzeppelin-contracts-upgradeable/lib/openzeppelin-contracts/contracts/access/manager/IAccessManaged.sol","source_code":"// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.0.0) (access/manager/IAccessManaged.sol)\n\npragma solidity ^0.8.20;\n\ninterface IAccessManaged {\n    /**\n     * @dev Authority that manages this contract was updated.\n     */\n    event AuthorityUpdated(address authority);\n\n    error AccessManagedUnauthorized(address caller);\n    error AccessManagedRequiredDelay(address caller, uint32 delay);\n    error AccessManagedInvalidAuthority(address authority);\n\n    /**\n     * @dev Returns the current authority.\n     */\n    function authority() external view returns (address);\n\n    /**\n     * @dev Transfers control to a new authority. The caller must be the current authority.\n     */\n    function setAuthority(address) external;\n\n    /**\n     * @dev Returns true only in the context of a delayed restricted call, at the moment that the scheduled operation is\n     * being consumed. Prevents denial of service for delayed restricted calls in the case that the contract performs\n     * attacker controlled calls.\n     */\n    function isConsumingScheduledOp() external view returns (bytes4);\n}\n"},{"file_path":"src/Dependencies/LiquityMath.sol","source_code":"// SPDX-License-Identifier: MIT\n\npragma solidity ^0.8.24;\n\nimport {DECIMAL_PRECISION} from \"./Constants.sol\";\n\nlibrary LiquityMath {\n    function _min(uint256 _a, uint256 _b) internal pure returns (uint256) {\n        return (_a < _b) ? _a : _b;\n    }\n\n    function _max(uint256 _a, uint256 _b) internal pure returns (uint256) {\n        return (_a >= _b) ? _a : _b;\n    }\n\n    function _sub_min_0(uint256 _a, uint256 _b) internal pure returns (uint256) {\n        return (_a > _b) ? _a - _b : 0;\n    }\n\n    /* \n    * Multiply two decimal numbers and use normal rounding rules:\n    * -round product up if 19'th mantissa digit >= 5\n    * -round product down if 19'th mantissa digit < 5\n    *\n    * Used only inside the exponentiation, _decPow().\n    */\n    function decMul(uint256 x, uint256 y) internal pure returns (uint256 decProd) {\n        uint256 prod_xy = x * y;\n\n        decProd = (prod_xy + DECIMAL_PRECISION / 2) / DECIMAL_PRECISION;\n    }\n\n    /* \n    * _decPow: Exponentiation function for 18-digit decimal base, and integer exponent n.\n    * \n    * Uses the efficient \"exponentiation by squaring\" algorithm. O(log(n)) complexity. \n    * \n    * Called by function CollateralRegistry._calcDecayedBaseRate, that represent time in units of minutes\n    *\n    * The exponent is capped to avoid reverting due to overflow. The cap 525600000 equals\n    * \"minutes in 1000 years\": 60 * 24 * 365 * 1000\n    * \n    * If a period of > 1000 years is ever used as an exponent in either of the above functions, the result will be\n    * negligibly different from just passing the cap, since: \n    *\n    * In function 1), the decayed base rate will be 0 for 1000 years or > 1000 years\n    * In function 2), the difference in tokens issued at 1000 years and any time > 1000 years, will be negligible\n    */\n    function _decPow(uint256 _base, uint256 _minutes) internal pure returns (uint256) {\n        if (_minutes > 525600000) _minutes = 525600000; // cap to avoid overflow\n\n        if (_minutes == 0) return DECIMAL_PRECISION;\n\n        uint256 y = DECIMAL_PRECISION;\n        uint256 x = _base;\n        uint256 n = _minutes;\n\n        // Exponentiation-by-squaring\n        while (n > 1) {\n            if (n % 2 == 0) {\n                x = decMul(x, x);\n                n = n / 2;\n            } else {\n                // if (n % 2 != 0)\n                y = decMul(x, y);\n                x = decMul(x, x);\n                n = (n - 1) / 2;\n            }\n        }\n\n        return decMul(x, y);\n    }\n\n    function _getAbsoluteDifference(uint256 _a, uint256 _b) internal pure returns (uint256) {\n        return (_a >= _b) ? _a - _b : _b - _a;\n    }\n\n    function _computeCR(uint256 _coll, uint256 _debt, uint256 _price) internal pure returns (uint256) {\n        if (_debt > 0) {\n            uint256 newCollRatio = _coll * _price / _debt;\n\n            return newCollRatio;\n        }\n        // Return the maximal value for uint256 if the debt is 0. Represents \"infinite\" CR.\n        else {\n            // if (_debt == 0)\n            return 2 ** 256 - 1;\n        }\n    }\n}\n"},{"file_path":"lib/openzeppelin-contracts-upgradeable/lib/openzeppelin-contracts/contracts/proxy/ERC1967/ERC1967Utils.sol","source_code":"// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.0.0) (proxy/ERC1967/ERC1967Utils.sol)\n\npragma solidity ^0.8.20;\n\nimport {IBeacon} from \"../beacon/IBeacon.sol\";\nimport {Address} from \"../../utils/Address.sol\";\nimport {StorageSlot} from \"../../utils/StorageSlot.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 */\nlibrary ERC1967Utils {\n    // We re-declare ERC-1967 events here because they can't be used directly from IERC1967.\n    // This will be fixed in Solidity 0.8.21. At that point we should remove these events.\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    /**\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.\n     */\n    // solhint-disable-next-line private-vars-leading-underscore\n    bytes32 internal constant IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc;\n\n    /**\n     * @dev The `implementation` of the proxy is invalid.\n     */\n    error ERC1967InvalidImplementation(address implementation);\n\n    /**\n     * @dev The `admin` of the proxy is invalid.\n     */\n    error ERC1967InvalidAdmin(address admin);\n\n    /**\n     * @dev The `beacon` of the proxy is invalid.\n     */\n    error ERC1967InvalidBeacon(address beacon);\n\n    /**\n     * @dev An upgrade function sees `msg.value > 0` that may be lost.\n     */\n    error ERC1967NonPayable();\n\n    /**\n     * @dev Returns the current implementation address.\n     */\n    function getImplementation() internal view returns (address) {\n        return StorageSlot.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        if (newImplementation.code.length == 0) {\n            revert ERC1967InvalidImplementation(newImplementation);\n        }\n        StorageSlot.getAddressSlot(IMPLEMENTATION_SLOT).value = newImplementation;\n    }\n\n    /**\n     * @dev Performs implementation upgrade with additional setup call if data is nonempty.\n     * This function is payable only if the setup call is performed, otherwise `msg.value` is rejected\n     * to avoid stuck value in the contract.\n     *\n     * Emits an {IERC1967-Upgraded} event.\n     */\n    function upgradeToAndCall(address newImplementation, bytes memory data) internal {\n        _setImplementation(newImplementation);\n        emit Upgraded(newImplementation);\n\n        if (data.length > 0) {\n            Address.functionDelegateCall(newImplementation, data);\n        } else {\n            _checkNonPayable();\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.\n     */\n    // solhint-disable-next-line private-vars-leading-underscore\n    bytes32 internal constant ADMIN_SLOT = 0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103;\n\n    /**\n     * @dev Returns the current admin.\n     *\n     * TIP: To get this value clients can read directly from the storage slot shown below (specified by EIP1967) using\n     * the https://eth.wiki/json-rpc/API#eth_getstorageat[`eth_getStorageAt`] RPC call.\n     * `0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103`\n     */\n    function getAdmin() internal view returns (address) {\n        return StorageSlot.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        if (newAdmin == address(0)) {\n            revert ERC1967InvalidAdmin(address(0));\n        }\n        StorageSlot.getAddressSlot(ADMIN_SLOT).value = newAdmin;\n    }\n\n    /**\n     * @dev Changes the admin of the proxy.\n     *\n     * Emits an {IERC1967-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 the keccak-256 hash of \"eip1967.proxy.beacon\" subtracted by 1.\n     */\n    // solhint-disable-next-line private-vars-leading-underscore\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 StorageSlot.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        if (newBeacon.code.length == 0) {\n            revert ERC1967InvalidBeacon(newBeacon);\n        }\n\n        StorageSlot.getAddressSlot(BEACON_SLOT).value = newBeacon;\n\n        address beaconImplementation = IBeacon(newBeacon).implementation();\n        if (beaconImplementation.code.length == 0) {\n            revert ERC1967InvalidImplementation(beaconImplementation);\n        }\n    }\n\n    /**\n     * @dev Change the beacon and trigger a setup call if data is nonempty.\n     * This function is payable only if the setup call is performed, otherwise `msg.value` is rejected\n     * to avoid stuck value in the contract.\n     *\n     * Emits an {IERC1967-BeaconUpgraded} event.\n     *\n     * CAUTION: Invoking this function has no effect on an instance of {BeaconProxy} since v5, since\n     * it uses an immutable beacon without looking at the value of the ERC-1967 beacon slot for\n     * efficiency.\n     */\n    function upgradeBeaconToAndCall(address newBeacon, bytes memory data) internal {\n        _setBeacon(newBeacon);\n        emit BeaconUpgraded(newBeacon);\n\n        if (data.length > 0) {\n            Address.functionDelegateCall(IBeacon(newBeacon).implementation(), data);\n        } else {\n            _checkNonPayable();\n        }\n    }\n\n    /**\n     * @dev Reverts if `msg.value` is not zero. It can be used to avoid `msg.value` stuck in the contract\n     * if an upgrade doesn't perform an initialization call.\n     */\n    function _checkNonPayable() private {\n        if (msg.value > 0) {\n            revert ERC1967NonPayable();\n        }\n    }\n}\n"},{"file_path":"src/Interfaces/IBorrowerOperations.sol","source_code":"// SPDX-License-Identifier: MIT\n\npragma solidity ^0.8.0;\n\nimport \"./ILiquityBase.sol\";\nimport \"./IAddRemoveManagers.sol\";\nimport \"./IBoldToken.sol\";\nimport \"./IPriceFeed.sol\";\nimport \"./ISortedTroves.sol\";\nimport \"./ITroveManager.sol\";\nimport \"./IWETH.sol\";\n\n// Common interface for the Borrower Operations.\ninterface IBorrowerOperations is ILiquityBase, IAddRemoveManagers {\n    function openTrove(\n        address _owner,\n        uint256 _ownerIndex,\n        uint256 _ETHAmount,\n        uint256 _boldAmount,\n        uint256 _upperHint,\n        uint256 _lowerHint,\n        uint256 _annualInterestRate,\n        uint256 _maxUpfrontFee,\n        address _addManager,\n        address _removeManager,\n        address _receiver\n    ) external returns (uint256);\n\n    struct OpenTroveAndJoinInterestBatchManagerParams {\n        address owner;\n        uint256 ownerIndex;\n        uint256 collAmount;\n        uint256 boldAmount;\n        uint256 upperHint;\n        uint256 lowerHint;\n        address interestBatchManager;\n        uint256 maxUpfrontFee;\n        address addManager;\n        address removeManager;\n        address receiver;\n    }\n\n    function openTroveAndJoinInterestBatchManager(OpenTroveAndJoinInterestBatchManagerParams calldata _params)\n        external\n        returns (uint256);\n\n    function addColl(uint256 _troveId, uint256 _ETHAmount) external;\n\n    function withdrawColl(uint256 _troveId, uint256 _amount) external;\n\n    function withdrawBold(uint256 _troveId, uint256 _amount, uint256 _maxUpfrontFee) external;\n\n    function repayBold(uint256 _troveId, uint256 _amount) external;\n\n    function closeTrove(uint256 _troveId) external;\n\n    function adjustTrove(\n        uint256 _troveId,\n        uint256 _collChange,\n        bool _isCollIncrease,\n        uint256 _debtChange,\n        bool isDebtIncrease,\n        uint256 _maxUpfrontFee\n    ) external;\n\n    function adjustZombieTrove(\n        uint256 _troveId,\n        uint256 _collChange,\n        bool _isCollIncrease,\n        uint256 _boldChange,\n        bool _isDebtIncrease,\n        uint256 _upperHint,\n        uint256 _lowerHint,\n        uint256 _maxUpfrontFee\n    ) external;\n\n    function adjustTroveInterestRate(\n        uint256 _troveId,\n        uint256 _newAnnualInterestRate,\n        uint256 _upperHint,\n        uint256 _lowerHint,\n        uint256 _maxUpfrontFee\n    ) external;\n\n    function applyPendingDebt(uint256 _troveId, uint256 _lowerHint, uint256 _upperHint) external;\n\n    function onLiquidateTrove(uint256 _troveId) external;\n\n    function claimCollateral() external;\n\n    function hasBeenShutDown() external view returns (bool);\n    function shutdown() external;\n    function shutdownFromOracleFailureOrGovernance() external;\n\n    function checkBatchManagerExists(address _batchMananger) external view returns (bool);\n\n    // -- individual delegation --\n    struct InterestIndividualDelegate {\n        address account;\n        uint128 minInterestRate;\n        uint128 maxInterestRate;\n        uint256 minInterestRateChangePeriod;\n    }\n\n    function getInterestIndividualDelegateOf(uint256 _troveId)\n        external\n        view\n        returns (InterestIndividualDelegate memory);\n    function setInterestIndividualDelegate(\n        uint256 _troveId,\n        address _delegate,\n        uint128 _minInterestRate,\n        uint128 _maxInterestRate,\n        // only needed if trove was previously in a batch:\n        uint256 _newAnnualInterestRate,\n        uint256 _upperHint,\n        uint256 _lowerHint,\n        uint256 _maxUpfrontFee,\n        uint256 _minInterestRateChangePeriod\n    ) external;\n    function removeInterestIndividualDelegate(uint256 _troveId) external;\n\n    // -- batches --\n    struct InterestBatchManager {\n        uint128 minInterestRate;\n        uint128 maxInterestRate;\n        uint256 minInterestRateChangePeriod;\n    }\n\n    function registerBatchManager(\n        uint128 minInterestRate,\n        uint128 maxInterestRate,\n        uint128 currentInterestRate,\n        uint128 fee,\n        uint128 minInterestRateChangePeriod\n    ) external;\n    function lowerBatchManagementFee(uint256 _newAnnualFee) external;\n    function setBatchManagerAnnualInterestRate(\n        uint128 _newAnnualInterestRate,\n        uint256 _upperHint,\n        uint256 _lowerHint,\n        uint256 _maxUpfrontFee\n    ) external;\n    function interestBatchManagerOf(uint256 _troveId) external view returns (address);\n    function getInterestBatchManager(address _account) external view returns (InterestBatchManager memory);\n    function setInterestBatchManager(\n        uint256 _troveId,\n        address _newBatchManager,\n        uint256 _upperHint,\n        uint256 _lowerHint,\n        uint256 _maxUpfrontFee\n    ) external;\n    function kickFromBatch(uint256 _troveId, uint256 _upperHint, uint256 _lowerHint) external;\n    function removeFromBatch(\n        uint256 _troveId,\n        uint256 _newAnnualInterestRate,\n        uint256 _upperHint,\n        uint256 _lowerHint,\n        uint256 _maxUpfrontFee\n    ) external;\n    function switchBatchManager(\n        uint256 _troveId,\n        uint256 _removeUpperHint,\n        uint256 _removeLowerHint,\n        address _newBatchManager,\n        uint256 _addUpperHint,\n        uint256 _addLowerHint,\n        uint256 _maxUpfrontFee\n    ) external;\n}\n"},{"file_path":"lib/openzeppelin-contracts-upgradeable/lib/openzeppelin-contracts/contracts/token/ERC20/IERC20.sol","source_code":"// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC20/IERC20.sol)\n\npragma solidity ^0.8.20;\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 value of tokens in existence.\n     */\n    function totalSupply() external view returns (uint256);\n\n    /**\n     * @dev Returns the value of tokens owned by `account`.\n     */\n    function balanceOf(address account) external view returns (uint256);\n\n    /**\n     * @dev Moves a `value` amount of 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 value) 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 a `value` amount of tokens as the allowance of `spender` over the\n     * 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 value) external returns (bool);\n\n    /**\n     * @dev Moves a `value` amount of tokens from `from` to `to` using the\n     * allowance mechanism. `value` 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 value) external returns (bool);\n}\n"},{"file_path":"lib/openzeppelin-contracts-upgradeable/contracts/proxy/utils/UUPSUpgradeable.sol","source_code":"// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.0.0) (proxy/utils/UUPSUpgradeable.sol)\n\npragma solidity ^0.8.20;\n\nimport {IERC1822Proxiable} from \"@openzeppelin/contracts/interfaces/draft-IERC1822.sol\";\nimport {ERC1967Utils} from \"@openzeppelin/contracts/proxy/ERC1967/ERC1967Utils.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 */\nabstract contract UUPSUpgradeable is Initializable, IERC1822Proxiable {\n    /// @custom:oz-upgrades-unsafe-allow state-variable-immutable\n    address private immutable __self = address(this);\n\n    /**\n     * @dev The version of the upgrade interface of the contract. If this getter is missing, both `upgradeTo(address)`\n     * and `upgradeToAndCall(address,bytes)` are present, and `upgradeTo` must be used if no function should be called,\n     * while `upgradeToAndCall` will invoke the `receive` function if the second argument is the empty byte string.\n     * If the getter returns `\"5.0.0\"`, only `upgradeToAndCall(address,bytes)` is present, and the second argument must\n     * be the empty byte string if no function should be called, making it impossible to invoke the `receive` function\n     * during an upgrade.\n     */\n    string public constant UPGRADE_INTERFACE_VERSION = \"5.0.0\";\n\n    /**\n     * @dev The call is from an unauthorized context.\n     */\n    error UUPSUnauthorizedCallContext();\n\n    /**\n     * @dev The storage `slot` is unsupported as a UUID.\n     */\n    error UUPSUnsupportedProxiableUUID(bytes32 slot);\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        _checkProxy();\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        _checkNotDelegated();\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 notDelegated returns (bytes32) {\n        return ERC1967Utils.IMPLEMENTATION_SLOT;\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);\n    }\n\n    /**\n     * @dev Reverts if the execution is not performed via delegatecall or the execution\n     * context is not of a proxy with an ERC1967-compliant implementation pointing to self.\n     * See {_onlyProxy}.\n     */\n    function _checkProxy() internal view virtual {\n        if (\n            address(this) == __self || // Must be called through delegatecall\n            ERC1967Utils.getImplementation() != __self // Must be called through an active proxy\n        ) {\n            revert UUPSUnauthorizedCallContext();\n        }\n    }\n\n    /**\n     * @dev Reverts if the execution is performed via delegatecall.\n     * See {notDelegated}.\n     */\n    function _checkNotDelegated() internal view virtual {\n        if (address(this) != __self) {\n            // Must not be called through delegatecall\n            revert UUPSUnauthorizedCallContext();\n        }\n    }\n\n    /**\n     * @dev Function that should revert when `msg.sender` is not authorized to upgrade the contract. Called by\n     * {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 onlyOwner {}\n     * ```\n     */\n    function _authorizeUpgrade(address newImplementation) internal virtual;\n\n    /**\n     * @dev Performs an implementation upgrade with a security check for UUPS proxies, and additional setup call.\n     *\n     * As a security check, {proxiableUUID} is invoked in the new implementation, and the return value\n     * is expected to be the implementation slot in ERC1967.\n     *\n     * Emits an {IERC1967-Upgraded} event.\n     */\n    function _upgradeToAndCallUUPS(address newImplementation, bytes memory data) private {\n        try IERC1822Proxiable(newImplementation).proxiableUUID() returns (bytes32 slot) {\n            if (slot != ERC1967Utils.IMPLEMENTATION_SLOT) {\n                revert UUPSUnsupportedProxiableUUID(slot);\n            }\n            ERC1967Utils.upgradeToAndCall(newImplementation, data);\n        } catch {\n            // The implementation is not UUPS\n            revert ERC1967Utils.ERC1967InvalidImplementation(newImplementation);\n        }\n    }\n}\n"},{"file_path":"lib/openzeppelin-contracts-upgradeable/lib/openzeppelin-contracts/contracts/token/ERC721/IERC721.sol","source_code":"// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC721/IERC721.sol)\n\npragma solidity ^0.8.20;\n\nimport {IERC165} from \"../../utils/introspection/IERC165.sol\";\n\n/**\n * @dev Required interface of an ERC721 compliant contract.\n */\ninterface IERC721 is IERC165 {\n    /**\n     * @dev Emitted when `tokenId` token is transferred from `from` to `to`.\n     */\n    event Transfer(address indexed from, address indexed to, uint256 indexed tokenId);\n\n    /**\n     * @dev Emitted when `owner` enables `approved` to manage the `tokenId` token.\n     */\n    event Approval(address indexed owner, address indexed approved, uint256 indexed tokenId);\n\n    /**\n     * @dev Emitted when `owner` enables or disables (`approved`) `operator` to manage all of its assets.\n     */\n    event ApprovalForAll(address indexed owner, address indexed operator, bool approved);\n\n    /**\n     * @dev Returns the number of tokens in ``owner``'s account.\n     */\n    function balanceOf(address owner) external view returns (uint256 balance);\n\n    /**\n     * @dev Returns the owner of the `tokenId` token.\n     *\n     * Requirements:\n     *\n     * - `tokenId` must exist.\n     */\n    function ownerOf(uint256 tokenId) external view returns (address owner);\n\n    /**\n     * @dev Safely transfers `tokenId` token from `from` to `to`.\n     *\n     * Requirements:\n     *\n     * - `from` cannot be the zero address.\n     * - `to` cannot be the zero address.\n     * - `tokenId` token must exist and be owned by `from`.\n     * - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}.\n     * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon\n     *   a safe transfer.\n     *\n     * Emits a {Transfer} event.\n     */\n    function safeTransferFrom(address from, address to, uint256 tokenId, bytes calldata data) external;\n\n    /**\n     * @dev Safely transfers `tokenId` token from `from` to `to`, checking first that contract recipients\n     * are aware of the ERC721 protocol to prevent tokens from being forever locked.\n     *\n     * Requirements:\n     *\n     * - `from` cannot be the zero address.\n     * - `to` cannot be the zero address.\n     * - `tokenId` token must exist and be owned by `from`.\n     * - If the caller is not `from`, it must have been allowed to move this token by either {approve} or\n     *   {setApprovalForAll}.\n     * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon\n     *   a safe transfer.\n     *\n     * Emits a {Transfer} event.\n     */\n    function safeTransferFrom(address from, address to, uint256 tokenId) external;\n\n    /**\n     * @dev Transfers `tokenId` token from `from` to `to`.\n     *\n     * WARNING: Note that the caller is responsible to confirm that the recipient is capable of receiving ERC721\n     * or else they may be permanently lost. Usage of {safeTransferFrom} prevents loss, though the caller must\n     * understand this adds an external call which potentially creates a reentrancy vulnerability.\n     *\n     * Requirements:\n     *\n     * - `from` cannot be the zero address.\n     * - `to` cannot be the zero address.\n     * - `tokenId` token must be owned by `from`.\n     * - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}.\n     *\n     * Emits a {Transfer} event.\n     */\n    function transferFrom(address from, address to, uint256 tokenId) external;\n\n    /**\n     * @dev Gives permission to `to` to transfer `tokenId` token to another account.\n     * The approval is cleared when the token is transferred.\n     *\n     * Only a single account can be approved at a time, so approving the zero address clears previous approvals.\n     *\n     * Requirements:\n     *\n     * - The caller must own the token or be an approved operator.\n     * - `tokenId` must exist.\n     *\n     * Emits an {Approval} event.\n     */\n    function approve(address to, uint256 tokenId) external;\n\n    /**\n     * @dev Approve or remove `operator` as an operator for the caller.\n     * Operators can call {transferFrom} or {safeTransferFrom} for any token owned by the caller.\n     *\n     * Requirements:\n     *\n     * - The `operator` cannot be the address zero.\n     *\n     * Emits an {ApprovalForAll} event.\n     */\n    function setApprovalForAll(address operator, bool approved) external;\n\n    /**\n     * @dev Returns the account approved for `tokenId` token.\n     *\n     * Requirements:\n     *\n     * - `tokenId` must exist.\n     */\n    function getApproved(uint256 tokenId) external view returns (address operator);\n\n    /**\n     * @dev Returns if the `operator` is allowed to manage all of the assets of `owner`.\n     *\n     * See {setApprovalForAll}\n     */\n    function isApprovedForAll(address owner, address operator) external view returns (bool);\n}\n"},{"file_path":"src/Interfaces/IAddRemoveManagers.sol","source_code":"// SPDX-License-Identifier: MIT\n\npragma solidity ^0.8.0;\n\ninterface IAddRemoveManagers {\n    function setAddManager(uint256 _troveId, address _manager) external;\n    function setRemoveManager(uint256 _troveId, address _manager) external;\n    function setRemoveManagerWithReceiver(uint256 _troveId, address _manager, address _receiver) external;\n    function addManagerOf(uint256 _troveId) external view returns (address);\n    function removeManagerReceiverOf(uint256 _troveId) external view returns (address, address);\n}\n"},{"file_path":"src/Types/LatestTroveData.sol","source_code":"// SPDX-License-Identifier: MIT\n\npragma solidity ^0.8.24;\n\nstruct LatestTroveData {\n    uint256 entireDebt;\n    uint256 entireColl;\n    uint256 redistBoldDebtGain;\n    uint256 redistCollGain;\n    uint256 accruedInterest;\n    uint256 recordedDebt;\n    uint256 annualInterestRate;\n    uint256 weightedRecordedDebt;\n    uint256 accruedBatchManagementFee;\n    uint256 lastInterestRateAdjTime;\n}\n"},{"file_path":"src/Interfaces/IBoldRewardsReceiver.sol","source_code":"// SPDX-License-Identifier: MIT\n\npragma solidity ^0.8.0;\n\ninterface IBoldRewardsReceiver {\n    function triggerBoldRewards(uint256 _boldYield) external;\n}\n"},{"file_path":"src/Types/LatestBatchData.sol","source_code":"// SPDX-License-Identifier: MIT\n\npragma solidity ^0.8.24;\n\nstruct LatestBatchData {\n    uint256 totalDebtShares;\n    uint256 entireDebtWithoutRedistribution;\n    uint256 entireCollWithoutRedistribution;\n    uint256 accruedInterest;\n    uint256 recordedDebt;\n    uint256 annualInterestRate;\n    uint256 weightedRecordedDebt;\n    uint256 annualManagementFee;\n    uint256 accruedManagementFee;\n    uint256 weightedRecordedBatchManagementFee;\n    uint256 lastDebtUpdateTime;\n    uint256 lastInterestRateAdjTime;\n}\n"},{"file_path":"src/Interfaces/IPriceFeed.sol","source_code":"// SPDX-License-Identifier: MIT\n\npragma solidity ^0.8.0;\n\ninterface IPriceFeed {\n    function fetchPrice() external returns (uint256, bool);\n    function fetchRedemptionPrice() external returns (uint256, bool);\n    function lastGoodPrice() external view returns (uint256);\n    function setAddresses(address _borrowerOperationsAddress) external;\n}\n"},{"file_path":"lib/openzeppelin-contracts-upgradeable/contracts/utils/ContextUpgradeable.sol","source_code":"// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.0.1) (utils/Context.sol)\n\npragma solidity ^0.8.20;\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"},{"file_path":"lib/openzeppelin-contracts-upgradeable/lib/openzeppelin-contracts/contracts/token/ERC20/extensions/IERC20Permit.sol","source_code":"// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC20/extensions/IERC20Permit.sol)\n\npragma solidity ^0.8.20;\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 IERC20Permit {\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":"lib/openzeppelin-contracts-upgradeable/lib/openzeppelin-contracts/contracts/access/manager/IAccessManager.sol","source_code":"// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.0.0) (access/manager/IAccessManager.sol)\n\npragma solidity ^0.8.20;\n\nimport {IAccessManaged} from \"./IAccessManaged.sol\";\nimport {Time} from \"../../utils/types/Time.sol\";\n\ninterface IAccessManager {\n    /**\n     * @dev A delayed operation was scheduled.\n     */\n    event OperationScheduled(\n        bytes32 indexed operationId,\n        uint32 indexed nonce,\n        uint48 schedule,\n        address caller,\n        address target,\n        bytes data\n    );\n\n    /**\n     * @dev A scheduled operation was executed.\n     */\n    event OperationExecuted(bytes32 indexed operationId, uint32 indexed nonce);\n\n    /**\n     * @dev A scheduled operation was canceled.\n     */\n    event OperationCanceled(bytes32 indexed operationId, uint32 indexed nonce);\n\n    /**\n     * @dev Informational labelling for a roleId.\n     */\n    event RoleLabel(uint64 indexed roleId, string label);\n\n    /**\n     * @dev Emitted when `account` is granted `roleId`.\n     *\n     * NOTE: The meaning of the `since` argument depends on the `newMember` argument.\n     * If the role is granted to a new member, the `since` argument indicates when the account becomes a member of the role,\n     * otherwise it indicates the execution delay for this account and roleId is updated.\n     */\n    event RoleGranted(uint64 indexed roleId, address indexed account, uint32 delay, uint48 since, bool newMember);\n\n    /**\n     * @dev Emitted when `account` membership or `roleId` is revoked. Unlike granting, revoking is instantaneous.\n     */\n    event RoleRevoked(uint64 indexed roleId, address indexed account);\n\n    /**\n     * @dev Role acting as admin over a given `roleId` is updated.\n     */\n    event RoleAdminChanged(uint64 indexed roleId, uint64 indexed admin);\n\n    /**\n     * @dev Role acting as guardian over a given `roleId` is updated.\n     */\n    event RoleGuardianChanged(uint64 indexed roleId, uint64 indexed guardian);\n\n    /**\n     * @dev Grant delay for a given `roleId` will be updated to `delay` when `since` is reached.\n     */\n    event RoleGrantDelayChanged(uint64 indexed roleId, uint32 delay, uint48 since);\n\n    /**\n     * @dev Target mode is updated (true = closed, false = open).\n     */\n    event TargetClosed(address indexed target, bool closed);\n\n    /**\n     * @dev Role required to invoke `selector` on `target` is updated to `roleId`.\n     */\n    event TargetFunctionRoleUpdated(address indexed target, bytes4 selector, uint64 indexed roleId);\n\n    /**\n     * @dev Admin delay for a given `target` will be updated to `delay` when `since` is reached.\n     */\n    event TargetAdminDelayUpdated(address indexed target, uint32 delay, uint48 since);\n\n    error AccessManagerAlreadyScheduled(bytes32 operationId);\n    error AccessManagerNotScheduled(bytes32 operationId);\n    error AccessManagerNotReady(bytes32 operationId);\n    error AccessManagerExpired(bytes32 operationId);\n    error AccessManagerLockedAccount(address account);\n    error AccessManagerLockedRole(uint64 roleId);\n    error AccessManagerBadConfirmation();\n    error AccessManagerUnauthorizedAccount(address msgsender, uint64 roleId);\n    error AccessManagerUnauthorizedCall(address caller, address target, bytes4 selector);\n    error AccessManagerUnauthorizedConsume(address target);\n    error AccessManagerUnauthorizedCancel(address msgsender, address caller, address target, bytes4 selector);\n    error AccessManagerInvalidInitialAdmin(address initialAdmin);\n\n    /**\n     * @dev Check if an address (`caller`) is authorised to call a given function on a given contract directly (with\n     * no restriction). Additionally, it returns the delay needed to perform the call indirectly through the {schedule}\n     * & {execute} workflow.\n     *\n     * This function is usually called by the targeted contract to control immediate execution of restricted functions.\n     * Therefore we only return true if the call can be performed without any delay. If the call is subject to a\n     * previously set delay (not zero), then the function should return false and the caller should schedule the operation\n     * for future execution.\n     *\n     * If `immediate` is true, the delay can be disregarded and the operation can be immediately executed, otherwise\n     * the operation can be executed if and only if delay is greater than 0.\n     *\n     * NOTE: The IAuthority interface does not include the `uint32` delay. This is an extension of that interface that\n     * is backward compatible. Some contracts may thus ignore the second return argument. In that case they will fail\n     * to identify the indirect workflow, and will consider calls that require a delay to be forbidden.\n     *\n     * NOTE: This function does not report the permissions of this manager itself. These are defined by the\n     * {_canCallSelf} function instead.\n     */\n    function canCall(\n        address caller,\n        address target,\n        bytes4 selector\n    ) external view returns (bool allowed, uint32 delay);\n\n    /**\n     * @dev Expiration delay for scheduled proposals. Defaults to 1 week.\n     *\n     * IMPORTANT: Avoid overriding the expiration with 0. Otherwise every contract proposal will be expired immediately,\n     * disabling any scheduling usage.\n     */\n    function expiration() external view returns (uint32);\n\n    /**\n     * @dev Minimum setback for all delay updates, with the exception of execution delays. It\n     * can be increased without setback (and reset via {revokeRole} in the case event of an\n     * accidental increase). Defaults to 5 days.\n     */\n    function minSetback() external view returns (uint32);\n\n    /**\n     * @dev Get whether the contract is closed disabling any access. Otherwise role permissions are applied.\n     */\n    function isTargetClosed(address target) external view returns (bool);\n\n    /**\n     * @dev Get the role required to call a function.\n     */\n    function getTargetFunctionRole(address target, bytes4 selector) external view returns (uint64);\n\n    /**\n     * @dev Get the admin delay for a target contract. Changes to contract configuration are subject to this delay.\n     */\n    function getTargetAdminDelay(address target) external view returns (uint32);\n\n    /**\n     * @dev Get the id of the role that acts as an admin for the given role.\n     *\n     * The admin permission is required to grant the role, revoke the role and update the execution delay to execute\n     * an operation that is restricted to this role.\n     */\n    function getRoleAdmin(uint64 roleId) external view returns (uint64);\n\n    /**\n     * @dev Get the role that acts as a guardian for a given role.\n     *\n     * The guardian permission allows canceling operations that have been scheduled under the role.\n     */\n    function getRoleGuardian(uint64 roleId) external view returns (uint64);\n\n    /**\n     * @dev Get the role current grant delay.\n     *\n     * Its value may change at any point without an event emitted following a call to {setGrantDelay}.\n     * Changes to this value, including effect timepoint are notified in advance by the {RoleGrantDelayChanged} event.\n     */\n    function getRoleGrantDelay(uint64 roleId) external view returns (uint32);\n\n    /**\n     * @dev Get the access details for a given account for a given role. These details include the timepoint at which\n     * membership becomes active, and the delay applied to all operation by this user that requires this permission\n     * level.\n     *\n     * Returns:\n     * [0] Timestamp at which the account membership becomes valid. 0 means role is not granted.\n     * [1] Current execution delay for the account.\n     * [2] Pending execution delay for the account.\n     * [3] Timestamp at which the pending execution delay will become active. 0 means no delay update is scheduled.\n     */\n    function getAccess(uint64 roleId, address account) external view returns (uint48, uint32, uint32, uint48);\n\n    /**\n     * @dev Check if a given account currently has the permission level corresponding to a given role. Note that this\n     * permission might be associated with an execution delay. {getAccess} can provide more details.\n     */\n    function hasRole(uint64 roleId, address account) external view returns (bool, uint32);\n\n    /**\n     * @dev Give a label to a role, for improved role discoverability by UIs.\n     *\n     * Requirements:\n     *\n     * - the caller must be a global admin\n     *\n     * Emits a {RoleLabel} event.\n     */\n    function labelRole(uint64 roleId, string calldata label) external;\n\n    /**\n     * @dev Add `account` to `roleId`, or change its execution delay.\n     *\n     * This gives the account the authorization to call any function that is restricted to this role. An optional\n     * execution delay (in seconds) can be set. If that delay is non 0, the user is required to schedule any operation\n     * that is restricted to members of this role. The user will only be able to execute the operation after the delay has\n     * passed, before it has expired. During this period, admin and guardians can cancel the operation (see {cancel}).\n     *\n     * If the account has already been granted this role, the execution delay will be updated. This update is not\n     * immediate and follows the delay rules. For example, if a user currently has a delay of 3 hours, and this is\n     * called to reduce that delay to 1 hour, the new delay will take some time to take effect, enforcing that any\n     * operation executed in the 3 hours that follows this update was indeed scheduled before this update.\n     *\n     * Requirements:\n     *\n     * - the caller must be an admin for the role (see {getRoleAdmin})\n     * - granted role must not be the `PUBLIC_ROLE`\n     *\n     * Emits a {RoleGranted} event.\n     */\n    function grantRole(uint64 roleId, address account, uint32 executionDelay) external;\n\n    /**\n     * @dev Remove an account from a role, with immediate effect. If the account does not have the role, this call has\n     * no effect.\n     *\n     * Requirements:\n     *\n     * - the caller must be an admin for the role (see {getRoleAdmin})\n     * - revoked role must not be the `PUBLIC_ROLE`\n     *\n     * Emits a {RoleRevoked} event if the account had the role.\n     */\n    function revokeRole(uint64 roleId, address account) external;\n\n    /**\n     * @dev Renounce role permissions for the calling account with immediate effect. If the sender is not in\n     * the role this call has no effect.\n     *\n     * Requirements:\n     *\n     * - the caller must be `callerConfirmation`.\n     *\n     * Emits a {RoleRevoked} event if the account had the role.\n     */\n    function renounceRole(uint64 roleId, address callerConfirmation) external;\n\n    /**\n     * @dev Change admin role for a given role.\n     *\n     * Requirements:\n     *\n     * - the caller must be a global admin\n     *\n     * Emits a {RoleAdminChanged} event\n     */\n    function setRoleAdmin(uint64 roleId, uint64 admin) external;\n\n    /**\n     * @dev Change guardian role for a given role.\n     *\n     * Requirements:\n     *\n     * - the caller must be a global admin\n     *\n     * Emits a {RoleGuardianChanged} event\n     */\n    function setRoleGuardian(uint64 roleId, uint64 guardian) external;\n\n    /**\n     * @dev Update the delay for granting a `roleId`.\n     *\n     * Requirements:\n     *\n     * - the caller must be a global admin\n     *\n     * Emits a {RoleGrantDelayChanged} event.\n     */\n    function setGrantDelay(uint64 roleId, uint32 newDelay) external;\n\n    /**\n     * @dev Set the role required to call functions identified by the `selectors` in the `target` contract.\n     *\n     * Requirements:\n     *\n     * - the caller must be a global admin\n     *\n     * Emits a {TargetFunctionRoleUpdated} event per selector.\n     */\n    function setTargetFunctionRole(address target, bytes4[] calldata selectors, uint64 roleId) external;\n\n    /**\n     * @dev Set the delay for changing the configuration of a given target contract.\n     *\n     * Requirements:\n     *\n     * - the caller must be a global admin\n     *\n     * Emits a {TargetAdminDelayUpdated} event.\n     */\n    function setTargetAdminDelay(address target, uint32 newDelay) external;\n\n    /**\n     * @dev Set the closed flag for a contract.\n     *\n     * Requirements:\n     *\n     * - the caller must be a global admin\n     *\n     * Emits a {TargetClosed} event.\n     */\n    function setTargetClosed(address target, bool closed) external;\n\n    /**\n     * @dev Return the timepoint at which a scheduled operation will be ready for execution. This returns 0 if the\n     * operation is not yet scheduled, has expired, was executed, or was canceled.\n     */\n    function getSchedule(bytes32 id) external view returns (uint48);\n\n    /**\n     * @dev Return the nonce for the latest scheduled operation with a given id. Returns 0 if the operation has never\n     * been scheduled.\n     */\n    function getNonce(bytes32 id) external view returns (uint32);\n\n    /**\n     * @dev Schedule a delayed operation for future execution, and return the operation identifier. It is possible to\n     * choose the timestamp at which the operation becomes executable as long as it satisfies the execution delays\n     * required for the caller. The special value zero will automatically set the earliest possible time.\n     *\n     * Returns the `operationId` that was scheduled. Since this value is a hash of the parameters, it can reoccur when\n     * the same parameters are used; if this is relevant, the returned `nonce` can be used to uniquely identify this\n     * scheduled operation from other occurrences of the same `operationId` in invocations of {execute} and {cancel}.\n     *\n     * Emits a {OperationScheduled} event.\n     *\n     * NOTE: It is not possible to concurrently schedule more than one operation with the same `target` and `data`. If\n     * this is necessary, a random byte can be appended to `data` to act as a salt that will be ignored by the target\n     * contract if it is using standard Solidity ABI encoding.\n     */\n    function schedule(address target, bytes calldata data, uint48 when) external returns (bytes32, uint32);\n\n    /**\n     * @dev Execute a function that is delay restricted, provided it was properly scheduled beforehand, or the\n     * execution delay is 0.\n     *\n     * Returns the nonce that identifies the previously scheduled operation that is executed, or 0 if the\n     * operation wasn't previously scheduled (if the caller doesn't have an execution delay).\n     *\n     * Emits an {OperationExecuted} event only if the call was scheduled and delayed.\n     */\n    function execute(address target, bytes calldata data) external payable returns (uint32);\n\n    /**\n     * @dev Cancel a scheduled (delayed) operation. Returns the nonce that identifies the previously scheduled\n     * operation that is cancelled.\n     *\n     * Requirements:\n     *\n     * - the caller must be the proposer, a guardian of the targeted function, or a global admin\n     *\n     * Emits a {OperationCanceled} event.\n     */\n    function cancel(address caller, address target, bytes calldata data) external returns (uint32);\n\n    /**\n     * @dev Consume a scheduled operation targeting the caller. If such an operation exists, mark it as consumed\n     * (emit an {OperationExecuted} event and clean the state). Otherwise, throw an error.\n     *\n     * This is useful for contract that want to enforce that calls targeting them were scheduled on the manager,\n     * with all the verifications that it implies.\n     *\n     * Emit a {OperationExecuted} event.\n     */\n    function consumeScheduledOp(address caller, bytes calldata data) external;\n\n    /**\n     * @dev Hashing function for delayed operations.\n     */\n    function hashOperation(address caller, address target, bytes calldata data) external view returns (bytes32);\n\n    /**\n     * @dev Changes the authority of a target managed by this manager instance.\n     *\n     * Requirements:\n     *\n     * - the caller must be a global admin\n     */\n    function updateAuthority(address target, address newAuthority) external;\n}\n"},{"file_path":"lib/openzeppelin-contracts-upgradeable/lib/openzeppelin-contracts/contracts/access/manager/AuthorityUtils.sol","source_code":"// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.0.0) (access/manager/AuthorityUtils.sol)\n\npragma solidity ^0.8.20;\n\nimport {IAuthority} from \"./IAuthority.sol\";\n\nlibrary AuthorityUtils {\n    /**\n     * @dev Since `AccessManager` implements an extended IAuthority interface, invoking `canCall` with backwards compatibility\n     * for the preexisting `IAuthority` interface requires special care to avoid reverting on insufficient return data.\n     * This helper function takes care of invoking `canCall` in a backwards compatible way without reverting.\n     */\n    function canCallWithDelay(\n        address authority,\n        address caller,\n        address target,\n        bytes4 selector\n    ) internal view returns (bool immediate, uint32 delay) {\n        (bool success, bytes memory data) = authority.staticcall(\n            abi.encodeCall(IAuthority.canCall, (caller, target, selector))\n        );\n        if (success) {\n            if (data.length >= 0x40) {\n                (immediate, delay) = abi.decode(data, (bool, uint32));\n            } else if (data.length >= 0x20) {\n                immediate = abi.decode(data, (bool));\n            }\n        }\n        return (immediate, delay);\n    }\n}\n"},{"file_path":"lib/openzeppelin-contracts-upgradeable/lib/openzeppelin-contracts/contracts/proxy/beacon/IBeacon.sol","source_code":"// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.0.0) (proxy/beacon/IBeacon.sol)\n\npragma solidity ^0.8.20;\n\n/**\n * @dev This is the interface that {BeaconProxy} expects of its beacon.\n */\ninterface IBeacon {\n    /**\n     * @dev Must return an address that can be used as a delegate call target.\n     *\n     * {UpgradeableBeacon} will check that this address is a contract.\n     */\n    function implementation() external view returns (address);\n}\n"},{"file_path":"lib/openzeppelin-contracts-upgradeable/lib/openzeppelin-contracts/contracts/utils/math/SafeCast.sol","source_code":"// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.0.0) (utils/math/SafeCast.sol)\n// This file was procedurally generated from scripts/generate/templates/SafeCast.js.\n\npragma solidity ^0.8.20;\n\n/**\n * @dev Wrappers over Solidity's uintXX/intXX casting operators with added overflow\n * checks.\n *\n * Downcasting from uint256/int256 in Solidity does not revert on overflow. This can\n * easily result in undesired exploitation or bugs, since developers usually\n * assume that overflows raise errors. `SafeCast` restores this intuition by\n * reverting the transaction when such an operation overflows.\n *\n * Using this library instead of the unchecked operations eliminates an entire\n * class of bugs, so it's recommended to use it always.\n */\nlibrary SafeCast {\n    /**\n     * @dev Value doesn't fit in an uint of `bits` size.\n     */\n    error SafeCastOverflowedUintDowncast(uint8 bits, uint256 value);\n\n    /**\n     * @dev An int value doesn't fit in an uint of `bits` size.\n     */\n    error SafeCastOverflowedIntToUint(int256 value);\n\n    /**\n     * @dev Value doesn't fit in an int of `bits` size.\n     */\n    error SafeCastOverflowedIntDowncast(uint8 bits, int256 value);\n\n    /**\n     * @dev An uint value doesn't fit in an int of `bits` size.\n     */\n    error SafeCastOverflowedUintToInt(uint256 value);\n\n    /**\n     * @dev Returns the downcasted uint248 from uint256, reverting on\n     * overflow (when the input is greater than largest uint248).\n     *\n     * Counterpart to Solidity's `uint248` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 248 bits\n     */\n    function toUint248(uint256 value) internal pure returns (uint248) {\n        if (value > type(uint248).max) {\n            revert SafeCastOverflowedUintDowncast(248, value);\n        }\n        return uint248(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint240 from uint256, reverting on\n     * overflow (when the input is greater than largest uint240).\n     *\n     * Counterpart to Solidity's `uint240` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 240 bits\n     */\n    function toUint240(uint256 value) internal pure returns (uint240) {\n        if (value > type(uint240).max) {\n            revert SafeCastOverflowedUintDowncast(240, value);\n        }\n        return uint240(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint232 from uint256, reverting on\n     * overflow (when the input is greater than largest uint232).\n     *\n     * Counterpart to Solidity's `uint232` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 232 bits\n     */\n    function toUint232(uint256 value) internal pure returns (uint232) {\n        if (value > type(uint232).max) {\n            revert SafeCastOverflowedUintDowncast(232, value);\n        }\n        return uint232(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint224 from uint256, reverting on\n     * overflow (when the input is greater than largest uint224).\n     *\n     * Counterpart to Solidity's `uint224` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 224 bits\n     */\n    function toUint224(uint256 value) internal pure returns (uint224) {\n        if (value > type(uint224).max) {\n            revert SafeCastOverflowedUintDowncast(224, value);\n        }\n        return uint224(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint216 from uint256, reverting on\n     * overflow (when the input is greater than largest uint216).\n     *\n     * Counterpart to Solidity's `uint216` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 216 bits\n     */\n    function toUint216(uint256 value) internal pure returns (uint216) {\n        if (value > type(uint216).max) {\n            revert SafeCastOverflowedUintDowncast(216, value);\n        }\n        return uint216(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint208 from uint256, reverting on\n     * overflow (when the input is greater than largest uint208).\n     *\n     * Counterpart to Solidity's `uint208` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 208 bits\n     */\n    function toUint208(uint256 value) internal pure returns (uint208) {\n        if (value > type(uint208).max) {\n            revert SafeCastOverflowedUintDowncast(208, value);\n        }\n        return uint208(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint200 from uint256, reverting on\n     * overflow (when the input is greater than largest uint200).\n     *\n     * Counterpart to Solidity's `uint200` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 200 bits\n     */\n    function toUint200(uint256 value) internal pure returns (uint200) {\n        if (value > type(uint200).max) {\n            revert SafeCastOverflowedUintDowncast(200, value);\n        }\n        return uint200(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint192 from uint256, reverting on\n     * overflow (when the input is greater than largest uint192).\n     *\n     * Counterpart to Solidity's `uint192` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 192 bits\n     */\n    function toUint192(uint256 value) internal pure returns (uint192) {\n        if (value > type(uint192).max) {\n            revert SafeCastOverflowedUintDowncast(192, value);\n        }\n        return uint192(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint184 from uint256, reverting on\n     * overflow (when the input is greater than largest uint184).\n     *\n     * Counterpart to Solidity's `uint184` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 184 bits\n     */\n    function toUint184(uint256 value) internal pure returns (uint184) {\n        if (value > type(uint184).max) {\n            revert SafeCastOverflowedUintDowncast(184, value);\n        }\n        return uint184(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint176 from uint256, reverting on\n     * overflow (when the input is greater than largest uint176).\n     *\n     * Counterpart to Solidity's `uint176` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 176 bits\n     */\n    function toUint176(uint256 value) internal pure returns (uint176) {\n        if (value > type(uint176).max) {\n            revert SafeCastOverflowedUintDowncast(176, value);\n        }\n        return uint176(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint168 from uint256, reverting on\n     * overflow (when the input is greater than largest uint168).\n     *\n     * Counterpart to Solidity's `uint168` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 168 bits\n     */\n    function toUint168(uint256 value) internal pure returns (uint168) {\n        if (value > type(uint168).max) {\n            revert SafeCastOverflowedUintDowncast(168, value);\n        }\n        return uint168(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint160 from uint256, reverting on\n     * overflow (when the input is greater than largest uint160).\n     *\n     * Counterpart to Solidity's `uint160` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 160 bits\n     */\n    function toUint160(uint256 value) internal pure returns (uint160) {\n        if (value > type(uint160).max) {\n            revert SafeCastOverflowedUintDowncast(160, value);\n        }\n        return uint160(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint152 from uint256, reverting on\n     * overflow (when the input is greater than largest uint152).\n     *\n     * Counterpart to Solidity's `uint152` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 152 bits\n     */\n    function toUint152(uint256 value) internal pure returns (uint152) {\n        if (value > type(uint152).max) {\n            revert SafeCastOverflowedUintDowncast(152, value);\n        }\n        return uint152(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint144 from uint256, reverting on\n     * overflow (when the input is greater than largest uint144).\n     *\n     * Counterpart to Solidity's `uint144` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 144 bits\n     */\n    function toUint144(uint256 value) internal pure returns (uint144) {\n        if (value > type(uint144).max) {\n            revert SafeCastOverflowedUintDowncast(144, value);\n        }\n        return uint144(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint136 from uint256, reverting on\n     * overflow (when the input is greater than largest uint136).\n     *\n     * Counterpart to Solidity's `uint136` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 136 bits\n     */\n    function toUint136(uint256 value) internal pure returns (uint136) {\n        if (value > type(uint136).max) {\n            revert SafeCastOverflowedUintDowncast(136, value);\n        }\n        return uint136(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint128 from uint256, reverting on\n     * overflow (when the input is greater than largest uint128).\n     *\n     * Counterpart to Solidity's `uint128` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 128 bits\n     */\n    function toUint128(uint256 value) internal pure returns (uint128) {\n        if (value > type(uint128).max) {\n            revert SafeCastOverflowedUintDowncast(128, value);\n        }\n        return uint128(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint120 from uint256, reverting on\n     * overflow (when the input is greater than largest uint120).\n     *\n     * Counterpart to Solidity's `uint120` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 120 bits\n     */\n    function toUint120(uint256 value) internal pure returns (uint120) {\n        if (value > type(uint120).max) {\n            revert SafeCastOverflowedUintDowncast(120, value);\n        }\n        return uint120(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint112 from uint256, reverting on\n     * overflow (when the input is greater than largest uint112).\n     *\n     * Counterpart to Solidity's `uint112` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 112 bits\n     */\n    function toUint112(uint256 value) internal pure returns (uint112) {\n        if (value > type(uint112).max) {\n            revert SafeCastOverflowedUintDowncast(112, value);\n        }\n        return uint112(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint104 from uint256, reverting on\n     * overflow (when the input is greater than largest uint104).\n     *\n     * Counterpart to Solidity's `uint104` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 104 bits\n     */\n    function toUint104(uint256 value) internal pure returns (uint104) {\n        if (value > type(uint104).max) {\n            revert SafeCastOverflowedUintDowncast(104, value);\n        }\n        return uint104(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint96 from uint256, reverting on\n     * overflow (when the input is greater than largest uint96).\n     *\n     * Counterpart to Solidity's `uint96` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 96 bits\n     */\n    function toUint96(uint256 value) internal pure returns (uint96) {\n        if (value > type(uint96).max) {\n            revert SafeCastOverflowedUintDowncast(96, value);\n        }\n        return uint96(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint88 from uint256, reverting on\n     * overflow (when the input is greater than largest uint88).\n     *\n     * Counterpart to Solidity's `uint88` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 88 bits\n     */\n    function toUint88(uint256 value) internal pure returns (uint88) {\n        if (value > type(uint88).max) {\n            revert SafeCastOverflowedUintDowncast(88, value);\n        }\n        return uint88(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint80 from uint256, reverting on\n     * overflow (when the input is greater than largest uint80).\n     *\n     * Counterpart to Solidity's `uint80` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 80 bits\n     */\n    function toUint80(uint256 value) internal pure returns (uint80) {\n        if (value > type(uint80).max) {\n            revert SafeCastOverflowedUintDowncast(80, value);\n        }\n        return uint80(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint72 from uint256, reverting on\n     * overflow (when the input is greater than largest uint72).\n     *\n     * Counterpart to Solidity's `uint72` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 72 bits\n     */\n    function toUint72(uint256 value) internal pure returns (uint72) {\n        if (value > type(uint72).max) {\n            revert SafeCastOverflowedUintDowncast(72, value);\n        }\n        return uint72(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint64 from uint256, reverting on\n     * overflow (when the input is greater than largest uint64).\n     *\n     * Counterpart to Solidity's `uint64` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 64 bits\n     */\n    function toUint64(uint256 value) internal pure returns (uint64) {\n        if (value > type(uint64).max) {\n            revert SafeCastOverflowedUintDowncast(64, value);\n        }\n        return uint64(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint56 from uint256, reverting on\n     * overflow (when the input is greater than largest uint56).\n     *\n     * Counterpart to Solidity's `uint56` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 56 bits\n     */\n    function toUint56(uint256 value) internal pure returns (uint56) {\n        if (value > type(uint56).max) {\n            revert SafeCastOverflowedUintDowncast(56, value);\n        }\n        return uint56(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint48 from uint256, reverting on\n     * overflow (when the input is greater than largest uint48).\n     *\n     * Counterpart to Solidity's `uint48` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 48 bits\n     */\n    function toUint48(uint256 value) internal pure returns (uint48) {\n        if (value > type(uint48).max) {\n            revert SafeCastOverflowedUintDowncast(48, value);\n        }\n        return uint48(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint40 from uint256, reverting on\n     * overflow (when the input is greater than largest uint40).\n     *\n     * Counterpart to Solidity's `uint40` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 40 bits\n     */\n    function toUint40(uint256 value) internal pure returns (uint40) {\n        if (value > type(uint40).max) {\n            revert SafeCastOverflowedUintDowncast(40, value);\n        }\n        return uint40(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint32 from uint256, reverting on\n     * overflow (when the input is greater than largest uint32).\n     *\n     * Counterpart to Solidity's `uint32` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 32 bits\n     */\n    function toUint32(uint256 value) internal pure returns (uint32) {\n        if (value > type(uint32).max) {\n            revert SafeCastOverflowedUintDowncast(32, value);\n        }\n        return uint32(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint24 from uint256, reverting on\n     * overflow (when the input is greater than largest uint24).\n     *\n     * Counterpart to Solidity's `uint24` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 24 bits\n     */\n    function toUint24(uint256 value) internal pure returns (uint24) {\n        if (value > type(uint24).max) {\n            revert SafeCastOverflowedUintDowncast(24, value);\n        }\n        return uint24(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint16 from uint256, reverting on\n     * overflow (when the input is greater than largest uint16).\n     *\n     * Counterpart to Solidity's `uint16` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 16 bits\n     */\n    function toUint16(uint256 value) internal pure returns (uint16) {\n        if (value > type(uint16).max) {\n            revert SafeCastOverflowedUintDowncast(16, value);\n        }\n        return uint16(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint8 from uint256, reverting on\n     * overflow (when the input is greater than largest uint8).\n     *\n     * Counterpart to Solidity's `uint8` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 8 bits\n     */\n    function toUint8(uint256 value) internal pure returns (uint8) {\n        if (value > type(uint8).max) {\n            revert SafeCastOverflowedUintDowncast(8, value);\n        }\n        return uint8(value);\n    }\n\n    /**\n     * @dev Converts a signed int256 into an unsigned uint256.\n     *\n     * Requirements:\n     *\n     * - input must be greater than or equal to 0.\n     */\n    function toUint256(int256 value) internal pure returns (uint256) {\n        if (value < 0) {\n            revert SafeCastOverflowedIntToUint(value);\n        }\n        return uint256(value);\n    }\n\n    /**\n     * @dev Returns the downcasted int248 from int256, reverting on\n     * overflow (when the input is less than smallest int248 or\n     * greater than largest int248).\n     *\n     * Counterpart to Solidity's `int248` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 248 bits\n     */\n    function toInt248(int256 value) internal pure returns (int248 downcasted) {\n        downcasted = int248(value);\n        if (downcasted != value) {\n            revert SafeCastOverflowedIntDowncast(248, value);\n        }\n    }\n\n    /**\n     * @dev Returns the downcasted int240 from int256, reverting on\n     * overflow (when the input is less than smallest int240 or\n     * greater than largest int240).\n     *\n     * Counterpart to Solidity's `int240` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 240 bits\n     */\n    function toInt240(int256 value) internal pure returns (int240 downcasted) {\n        downcasted = int240(value);\n        if (downcasted != value) {\n            revert SafeCastOverflowedIntDowncast(240, value);\n        }\n    }\n\n    /**\n     * @dev Returns the downcasted int232 from int256, reverting on\n     * overflow (when the input is less than smallest int232 or\n     * greater than largest int232).\n     *\n     * Counterpart to Solidity's `int232` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 232 bits\n     */\n    function toInt232(int256 value) internal pure returns (int232 downcasted) {\n        downcasted = int232(value);\n        if (downcasted != value) {\n            revert SafeCastOverflowedIntDowncast(232, value);\n        }\n    }\n\n    /**\n     * @dev Returns the downcasted int224 from int256, reverting on\n     * overflow (when the input is less than smallest int224 or\n     * greater than largest int224).\n     *\n     * Counterpart to Solidity's `int224` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 224 bits\n     */\n    function toInt224(int256 value) internal pure returns (int224 downcasted) {\n        downcasted = int224(value);\n        if (downcasted != value) {\n            revert SafeCastOverflowedIntDowncast(224, value);\n        }\n    }\n\n    /**\n     * @dev Returns the downcasted int216 from int256, reverting on\n     * overflow (when the input is less than smallest int216 or\n     * greater than largest int216).\n     *\n     * Counterpart to Solidity's `int216` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 216 bits\n     */\n    function toInt216(int256 value) internal pure returns (int216 downcasted) {\n        downcasted = int216(value);\n        if (downcasted != value) {\n            revert SafeCastOverflowedIntDowncast(216, value);\n        }\n    }\n\n    /**\n     * @dev Returns the downcasted int208 from int256, reverting on\n     * overflow (when the input is less than smallest int208 or\n     * greater than largest int208).\n     *\n     * Counterpart to Solidity's `int208` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 208 bits\n     */\n    function toInt208(int256 value) internal pure returns (int208 downcasted) {\n        downcasted = int208(value);\n        if (downcasted != value) {\n            revert SafeCastOverflowedIntDowncast(208, value);\n        }\n    }\n\n    /**\n     * @dev Returns the downcasted int200 from int256, reverting on\n     * overflow (when the input is less than smallest int200 or\n     * greater than largest int200).\n     *\n     * Counterpart to Solidity's `int200` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 200 bits\n     */\n    function toInt200(int256 value) internal pure returns (int200 downcasted) {\n        downcasted = int200(value);\n        if (downcasted != value) {\n            revert SafeCastOverflowedIntDowncast(200, value);\n        }\n    }\n\n    /**\n     * @dev Returns the downcasted int192 from int256, reverting on\n     * overflow (when the input is less than smallest int192 or\n     * greater than largest int192).\n     *\n     * Counterpart to Solidity's `int192` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 192 bits\n     */\n    function toInt192(int256 value) internal pure returns (int192 downcasted) {\n        downcasted = int192(value);\n        if (downcasted != value) {\n            revert SafeCastOverflowedIntDowncast(192, value);\n        }\n    }\n\n    /**\n     * @dev Returns the downcasted int184 from int256, reverting on\n     * overflow (when the input is less than smallest int184 or\n     * greater than largest int184).\n     *\n     * Counterpart to Solidity's `int184` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 184 bits\n     */\n    function toInt184(int256 value) internal pure returns (int184 downcasted) {\n        downcasted = int184(value);\n        if (downcasted != value) {\n            revert SafeCastOverflowedIntDowncast(184, value);\n        }\n    }\n\n    /**\n     * @dev Returns the downcasted int176 from int256, reverting on\n     * overflow (when the input is less than smallest int176 or\n     * greater than largest int176).\n     *\n     * Counterpart to Solidity's `int176` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 176 bits\n     */\n    function toInt176(int256 value) internal pure returns (int176 downcasted) {\n        downcasted = int176(value);\n        if (downcasted != value) {\n            revert SafeCastOverflowedIntDowncast(176, value);\n        }\n    }\n\n    /**\n     * @dev Returns the downcasted int168 from int256, reverting on\n     * overflow (when the input is less than smallest int168 or\n     * greater than largest int168).\n     *\n     * Counterpart to Solidity's `int168` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 168 bits\n     */\n    function toInt168(int256 value) internal pure returns (int168 downcasted) {\n        downcasted = int168(value);\n        if (downcasted != value) {\n            revert SafeCastOverflowedIntDowncast(168, value);\n        }\n    }\n\n    /**\n     * @dev Returns the downcasted int160 from int256, reverting on\n     * overflow (when the input is less than smallest int160 or\n     * greater than largest int160).\n     *\n     * Counterpart to Solidity's `int160` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 160 bits\n     */\n    function toInt160(int256 value) internal pure returns (int160 downcasted) {\n        downcasted = int160(value);\n        if (downcasted != value) {\n            revert SafeCastOverflowedIntDowncast(160, value);\n        }\n    }\n\n    /**\n     * @dev Returns the downcasted int152 from int256, reverting on\n     * overflow (when the input is less than smallest int152 or\n     * greater than largest int152).\n     *\n     * Counterpart to Solidity's `int152` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 152 bits\n     */\n    function toInt152(int256 value) internal pure returns (int152 downcasted) {\n        downcasted = int152(value);\n        if (downcasted != value) {\n            revert SafeCastOverflowedIntDowncast(152, value);\n        }\n    }\n\n    /**\n     * @dev Returns the downcasted int144 from int256, reverting on\n     * overflow (when the input is less than smallest int144 or\n     * greater than largest int144).\n     *\n     * Counterpart to Solidity's `int144` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 144 bits\n     */\n    function toInt144(int256 value) internal pure returns (int144 downcasted) {\n        downcasted = int144(value);\n        if (downcasted != value) {\n            revert SafeCastOverflowedIntDowncast(144, value);\n        }\n    }\n\n    /**\n     * @dev Returns the downcasted int136 from int256, reverting on\n     * overflow (when the input is less than smallest int136 or\n     * greater than largest int136).\n     *\n     * Counterpart to Solidity's `int136` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 136 bits\n     */\n    function toInt136(int256 value) internal pure returns (int136 downcasted) {\n        downcasted = int136(value);\n        if (downcasted != value) {\n            revert SafeCastOverflowedIntDowncast(136, value);\n        }\n    }\n\n    /**\n     * @dev Returns the downcasted int128 from int256, reverting on\n     * overflow (when the input is less than smallest int128 or\n     * greater than largest int128).\n     *\n     * Counterpart to Solidity's `int128` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 128 bits\n     */\n    function toInt128(int256 value) internal pure returns (int128 downcasted) {\n        downcasted = int128(value);\n        if (downcasted != value) {\n            revert SafeCastOverflowedIntDowncast(128, value);\n        }\n    }\n\n    /**\n     * @dev Returns the downcasted int120 from int256, reverting on\n     * overflow (when the input is less than smallest int120 or\n     * greater than largest int120).\n     *\n     * Counterpart to Solidity's `int120` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 120 bits\n     */\n    function toInt120(int256 value) internal pure returns (int120 downcasted) {\n        downcasted = int120(value);\n        if (downcasted != value) {\n            revert SafeCastOverflowedIntDowncast(120, value);\n        }\n    }\n\n    /**\n     * @dev Returns the downcasted int112 from int256, reverting on\n     * overflow (when the input is less than smallest int112 or\n     * greater than largest int112).\n     *\n     * Counterpart to Solidity's `int112` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 112 bits\n     */\n    function toInt112(int256 value) internal pure returns (int112 downcasted) {\n        downcasted = int112(value);\n        if (downcasted != value) {\n            revert SafeCastOverflowedIntDowncast(112, value);\n        }\n    }\n\n    /**\n     * @dev Returns the downcasted int104 from int256, reverting on\n     * overflow (when the input is less than smallest int104 or\n     * greater than largest int104).\n     *\n     * Counterpart to Solidity's `int104` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 104 bits\n     */\n    function toInt104(int256 value) internal pure returns (int104 downcasted) {\n        downcasted = int104(value);\n        if (downcasted != value) {\n            revert SafeCastOverflowedIntDowncast(104, value);\n        }\n    }\n\n    /**\n     * @dev Returns the downcasted int96 from int256, reverting on\n     * overflow (when the input is less than smallest int96 or\n     * greater than largest int96).\n     *\n     * Counterpart to Solidity's `int96` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 96 bits\n     */\n    function toInt96(int256 value) internal pure returns (int96 downcasted) {\n        downcasted = int96(value);\n        if (downcasted != value) {\n            revert SafeCastOverflowedIntDowncast(96, value);\n        }\n    }\n\n    /**\n     * @dev Returns the downcasted int88 from int256, reverting on\n     * overflow (when the input is less than smallest int88 or\n     * greater than largest int88).\n     *\n     * Counterpart to Solidity's `int88` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 88 bits\n     */\n    function toInt88(int256 value) internal pure returns (int88 downcasted) {\n        downcasted = int88(value);\n        if (downcasted != value) {\n            revert SafeCastOverflowedIntDowncast(88, value);\n        }\n    }\n\n    /**\n     * @dev Returns the downcasted int80 from int256, reverting on\n     * overflow (when the input is less than smallest int80 or\n     * greater than largest int80).\n     *\n     * Counterpart to Solidity's `int80` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 80 bits\n     */\n    function toInt80(int256 value) internal pure returns (int80 downcasted) {\n        downcasted = int80(value);\n        if (downcasted != value) {\n            revert SafeCastOverflowedIntDowncast(80, value);\n        }\n    }\n\n    /**\n     * @dev Returns the downcasted int72 from int256, reverting on\n     * overflow (when the input is less than smallest int72 or\n     * greater than largest int72).\n     *\n     * Counterpart to Solidity's `int72` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 72 bits\n     */\n    function toInt72(int256 value) internal pure returns (int72 downcasted) {\n        downcasted = int72(value);\n        if (downcasted != value) {\n            revert SafeCastOverflowedIntDowncast(72, value);\n        }\n    }\n\n    /**\n     * @dev Returns the downcasted int64 from int256, reverting on\n     * overflow (when the input is less than smallest int64 or\n     * greater than largest int64).\n     *\n     * Counterpart to Solidity's `int64` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 64 bits\n     */\n    function toInt64(int256 value) internal pure returns (int64 downcasted) {\n        downcasted = int64(value);\n        if (downcasted != value) {\n            revert SafeCastOverflowedIntDowncast(64, value);\n        }\n    }\n\n    /**\n     * @dev Returns the downcasted int56 from int256, reverting on\n     * overflow (when the input is less than smallest int56 or\n     * greater than largest int56).\n     *\n     * Counterpart to Solidity's `int56` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 56 bits\n     */\n    function toInt56(int256 value) internal pure returns (int56 downcasted) {\n        downcasted = int56(value);\n        if (downcasted != value) {\n            revert SafeCastOverflowedIntDowncast(56, value);\n        }\n    }\n\n    /**\n     * @dev Returns the downcasted int48 from int256, reverting on\n     * overflow (when the input is less than smallest int48 or\n     * greater than largest int48).\n     *\n     * Counterpart to Solidity's `int48` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 48 bits\n     */\n    function toInt48(int256 value) internal pure returns (int48 downcasted) {\n        downcasted = int48(value);\n        if (downcasted != value) {\n            revert SafeCastOverflowedIntDowncast(48, value);\n        }\n    }\n\n    /**\n     * @dev Returns the downcasted int40 from int256, reverting on\n     * overflow (when the input is less than smallest int40 or\n     * greater than largest int40).\n     *\n     * Counterpart to Solidity's `int40` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 40 bits\n     */\n    function toInt40(int256 value) internal pure returns (int40 downcasted) {\n        downcasted = int40(value);\n        if (downcasted != value) {\n            revert SafeCastOverflowedIntDowncast(40, value);\n        }\n    }\n\n    /**\n     * @dev Returns the downcasted int32 from int256, reverting on\n     * overflow (when the input is less than smallest int32 or\n     * greater than largest int32).\n     *\n     * Counterpart to Solidity's `int32` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 32 bits\n     */\n    function toInt32(int256 value) internal pure returns (int32 downcasted) {\n        downcasted = int32(value);\n        if (downcasted != value) {\n            revert SafeCastOverflowedIntDowncast(32, value);\n        }\n    }\n\n    /**\n     * @dev Returns the downcasted int24 from int256, reverting on\n     * overflow (when the input is less than smallest int24 or\n     * greater than largest int24).\n     *\n     * Counterpart to Solidity's `int24` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 24 bits\n     */\n    function toInt24(int256 value) internal pure returns (int24 downcasted) {\n        downcasted = int24(value);\n        if (downcasted != value) {\n            revert SafeCastOverflowedIntDowncast(24, value);\n        }\n    }\n\n    /**\n     * @dev Returns the downcasted int16 from int256, reverting on\n     * overflow (when the input is less than smallest int16 or\n     * greater than largest int16).\n     *\n     * Counterpart to Solidity's `int16` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 16 bits\n     */\n    function toInt16(int256 value) internal pure returns (int16 downcasted) {\n        downcasted = int16(value);\n        if (downcasted != value) {\n            revert SafeCastOverflowedIntDowncast(16, value);\n        }\n    }\n\n    /**\n     * @dev Returns the downcasted int8 from int256, reverting on\n     * overflow (when the input is less than smallest int8 or\n     * greater than largest int8).\n     *\n     * Counterpart to Solidity's `int8` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 8 bits\n     */\n    function toInt8(int256 value) internal pure returns (int8 downcasted) {\n        downcasted = int8(value);\n        if (downcasted != value) {\n            revert SafeCastOverflowedIntDowncast(8, value);\n        }\n    }\n\n    /**\n     * @dev Converts an unsigned uint256 into a signed int256.\n     *\n     * Requirements:\n     *\n     * - input must be less than or equal to maxInt256.\n     */\n    function toInt256(uint256 value) internal pure returns (int256) {\n        // Note: Unsafe cast below is okay because `type(int256).max` is guaranteed to be positive\n        if (value > uint256(type(int256).max)) {\n            revert SafeCastOverflowedUintToInt(value);\n        }\n        return int256(value);\n    }\n}\n"},{"file_path":"src/Quill/QuillUUPSUpgradeable.sol","source_code":"// SPDX-License-Identifier: MIT\npragma solidity ^0.8.24;\n\nimport {Initializable} from \"openzeppelin-contracts-upgradeable/contracts/proxy/utils/Initializable.sol\";\nimport {UUPSUpgradeable} from \"openzeppelin-contracts-upgradeable/contracts/proxy/utils/UUPSUpgradeable.sol\";\nimport {AccessManagedUpgradeable} from\n    \"openzeppelin-contracts-upgradeable/contracts/access/manager/AccessManagedUpgradeable.sol\";\n\nabstract contract QuillUUPSUpgradeable is Initializable, UUPSUpgradeable, AccessManagedUpgradeable {\n    /// @param _authority Must be the address of the QuillAccessManager instance\n    function __QuillUUPSUpgradeable_init(address _authority) internal onlyInitializing {\n        __AccessManaged_init(_authority);\n        __UUPSUpgradeable_init();\n    }\n\n    function _authorizeUpgrade(address newImplementation) internal override restricted {}\n\n    uint256[50] private __gap;\n}\n"},{"file_path":"lib/openzeppelin-contracts-upgradeable/lib/openzeppelin-contracts/contracts/utils/introspection/IERC165.sol","source_code":"// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.0.0) (utils/introspection/IERC165.sol)\n\npragma solidity ^0.8.20;\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"},{"file_path":"src/Interfaces/ITroveNFT.sol","source_code":"// SPDX-License-Identifier: MIT\n\npragma solidity ^0.8.0;\n\nimport \"openzeppelin-contracts/contracts/token/ERC721/extensions/IERC721Metadata.sol\";\n\nimport \"./ITroveManager.sol\";\n\ninterface ITroveNFT is IERC721Metadata {\n    function mint(address _owner, uint256 _troveId) external;\n    function burn(uint256 _troveId) external;\n}\n"},{"file_path":"lib/openzeppelin-contracts-upgradeable/lib/openzeppelin-contracts/contracts/utils/StorageSlot.sol","source_code":"// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.0.0) (utils/StorageSlot.sol)\n// This file was procedurally generated from scripts/generate/templates/StorageSlot.js.\n\npragma solidity ^0.8.20;\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(newImplementation.code.length > 0);\n *         StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value = newImplementation;\n *     }\n * }\n * ```\n */\nlibrary StorageSlot {\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":"src/Quill/Interfaces/ISequencerSentinel.sol","source_code":"// SPDX-License-Identifier: MIT\n\npragma solidity ^0.8.0;\n\ninterface ISequencerSentinel {\n    /**\n     * @dev Emitted after the grace period is updated\n     * @param newGracePeriod The new grace period value\n     */\n    event GracePeriodUpdated(uint256 newGracePeriod);\n\n    /**\n     * @dev Emitted after the SequencerOracle is updated\n     * @param newSequencerOracle The new SequencerOracle address\n     */\n    event SequencerOracleUpdated(address newSequencerOracle);\n\n    error SequencerDown();\n    error SystemUnderGracePeriod();\n\n    /**\n     * @notice Reverts if sequencer is down.\n     * @dev Operation not allowed when Sequencer feed returns `answer == 1`.\n     */\n    function requireUp() external view;\n\n    /**\n     * @notice Reverts if system is down or if system is under grace period.\n     * @dev Operation allowed when sequencer feed returns `answer == 0` and  `startAt` + gracePeriod < block.timestamp.\n     */\n    function requireUpAndOverGracePeriod() external view;\n\n    /**\n     * @notice Updates the oracle's address\n     * @param newSequencerOracle The address of the new SequencerOracle\n     */\n    function setSequencerOracle(address newSequencerOracle) external;\n\n    /**\n     * @notice Updates the duration of the grace period\n     * @param newGracePeriod The value of the new grace period duration\n     */\n    function setGracePeriod(uint256 newGracePeriod) external;\n\n    /**\n     * @notice Returns the grace period\n     * @return The duration of the grace period\n     */\n    function gracePeriod() external view returns (uint256);\n}\n"},{"file_path":"lib/openzeppelin-contracts-upgradeable/lib/openzeppelin-contracts/contracts/access/manager/IAuthority.sol","source_code":"// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.0.0) (access/manager/IAuthority.sol)\n\npragma solidity ^0.8.20;\n\n/**\n * @dev Standard interface for permissioning originally defined in Dappsys.\n */\ninterface IAuthority {\n    /**\n     * @dev Returns true if the caller can invoke on a target the function identified by a function selector.\n     */\n    function canCall(address caller, address target, bytes4 selector) external view returns (bool allowed);\n}\n"},{"file_path":"lib/openzeppelin-contracts-upgradeable/lib/openzeppelin-contracts/contracts/utils/Address.sol","source_code":"// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.0.0) (utils/Address.sol)\n\npragma solidity ^0.8.20;\n\n/**\n * @dev Collection of functions related to the address type\n */\nlibrary Address {\n    /**\n     * @dev The ETH balance of the account is not enough to perform the operation.\n     */\n    error AddressInsufficientBalance(address account);\n\n    /**\n     * @dev There's no code at `target` (it is not a contract).\n     */\n    error AddressEmptyCode(address target);\n\n    /**\n     * @dev A call to an address target failed. The target may have reverted.\n     */\n    error FailedInnerCall();\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.20/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].\n     */\n    function sendValue(address payable recipient, uint256 amount) internal {\n        if (address(this).balance < amount) {\n            revert AddressInsufficientBalance(address(this));\n        }\n\n        (bool success, ) = recipient.call{value: amount}(\"\");\n        if (!success) {\n            revert FailedInnerCall();\n        }\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 or custom error, it is bubbled\n     * up by this function (like regular Solidity function calls). However, if\n     * the call reverted with no returned reason, this function reverts with a\n     * {FailedInnerCall} error.\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    function functionCall(address target, bytes memory data) internal returns (bytes memory) {\n        return functionCallWithValue(target, data, 0);\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    function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {\n        if (address(this).balance < value) {\n            revert AddressInsufficientBalance(address(this));\n        }\n        (bool success, bytes memory returndata) = target.call{value: value}(data);\n        return verifyCallResultFromTarget(target, success, returndata);\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],\n     * but performing a static call.\n     */\n    function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {\n        (bool success, bytes memory returndata) = target.staticcall(data);\n        return verifyCallResultFromTarget(target, success, returndata);\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],\n     * but performing a delegate call.\n     */\n    function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {\n        (bool success, bytes memory returndata) = target.delegatecall(data);\n        return verifyCallResultFromTarget(target, success, returndata);\n    }\n\n    /**\n     * @dev Tool to verify that a low level call to smart-contract was successful, and reverts if the target\n     * was not a contract or bubbling up the revert reason (falling back to {FailedInnerCall}) in case of an\n     * unsuccessful call.\n     */\n    function verifyCallResultFromTarget(\n        address target,\n        bool success,\n        bytes memory returndata\n    ) internal view returns (bytes memory) {\n        if (!success) {\n            _revert(returndata);\n        } else {\n            // only check if target is a contract if the call was successful and the return data is empty\n            // otherwise we already know that it was a contract\n            if (returndata.length == 0 && target.code.length == 0) {\n                revert AddressEmptyCode(target);\n            }\n            return returndata;\n        }\n    }\n\n    /**\n     * @dev Tool to verify that a low level call was successful, and reverts if it wasn't, either by bubbling the\n     * revert reason or with a default {FailedInnerCall} error.\n     */\n    function verifyCallResult(bool success, bytes memory returndata) internal pure returns (bytes memory) {\n        if (!success) {\n            _revert(returndata);\n        } else {\n            return returndata;\n        }\n    }\n\n    /**\n     * @dev Reverts with returndata if present. Otherwise reverts with {FailedInnerCall}.\n     */\n    function _revert(bytes memory returndata) 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 FailedInnerCall();\n        }\n    }\n}\n"},{"file_path":"src/Interfaces/IWETH.sol","source_code":"// SPDX-License-Identifier: MIT\n\npragma solidity ^0.8.0;\n\nimport \"openzeppelin-contracts/contracts/token/ERC20/extensions/IERC20Metadata.sol\";\n\ninterface IWETH is IERC20Metadata {\n    function deposit() external payable;\n    function withdraw(uint256 wad) external;\n}\n"},{"file_path":"src/Types/BatchId.sol","source_code":"// SPDX-License-Identifier: MIT\n\npragma solidity ^0.8.24;\n\ntype BatchId is address;\n\nusing {equals as ==, notEquals as !=, isZero, isNotZero} for BatchId global;\n\nfunction equals(BatchId a, BatchId b) pure returns (bool) {\n    return BatchId.unwrap(a) == BatchId.unwrap(b);\n}\n\nfunction notEquals(BatchId a, BatchId b) pure returns (bool) {\n    return !(a == b);\n}\n\nfunction isZero(BatchId x) pure returns (bool) {\n    return x == BATCH_ID_ZERO;\n}\n\nfunction isNotZero(BatchId x) pure returns (bool) {\n    return !x.isZero();\n}\n\nBatchId constant BATCH_ID_ZERO = BatchId.wrap(address(0));\n"},{"file_path":"lib/openzeppelin-contracts-upgradeable/contracts/proxy/utils/Initializable.sol","source_code":"// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.0.0) (proxy/utils/Initializable.sol)\n\npragma solidity ^0.8.20;\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 Storage of the initializable contract.\n     *\n     * It's implemented on a custom ERC-7201 namespace to reduce the risk of storage collisions\n     * when using with upgradeable contracts.\n     *\n     * @custom:storage-location erc7201:openzeppelin.storage.Initializable\n     */\n    struct InitializableStorage {\n        /**\n         * @dev Indicates that the contract has been initialized.\n         */\n        uint64 _initialized;\n        /**\n         * @dev Indicates that the contract is in the process of being initialized.\n         */\n        bool _initializing;\n    }\n\n    // keccak256(abi.encode(uint256(keccak256(\"openzeppelin.storage.Initializable\")) - 1)) & ~bytes32(uint256(0xff))\n    bytes32 private constant INITIALIZABLE_STORAGE = 0xf0c57e16840df040f15088dc2f81fe391c3923bec73e23a9662efc9c229c6a00;\n\n    /**\n     * @dev The contract is already initialized.\n     */\n    error InvalidInitialization();\n\n    /**\n     * @dev The contract is not initializing.\n     */\n    error NotInitializing();\n\n    /**\n     * @dev Triggered when the contract has been initialized or reinitialized.\n     */\n    event Initialized(uint64 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 in the context of a constructor an `initializer` may be invoked any\n     * number of times. This behavior in the constructor can be useful during testing and is not expected to be used in\n     * production.\n     *\n     * Emits an {Initialized} event.\n     */\n    modifier initializer() {\n        // solhint-disable-next-line var-name-mixedcase\n        InitializableStorage storage $ = _getInitializableStorage();\n\n        // Cache values to avoid duplicated sloads\n        bool isTopLevelCall = !$._initializing;\n        uint64 initialized = $._initialized;\n\n        // Allowed calls:\n        // - initialSetup: the contract is not in the initializing state and no previous version was\n        //                 initialized\n        // - construction: the contract is initialized at version 1 (no reininitialization) and the\n        //                 current contract is just being deployed\n        bool initialSetup = initialized == 0 && isTopLevelCall;\n        bool construction = initialized == 1 && address(this).code.length == 0;\n\n        if (!initialSetup && !construction) {\n            revert InvalidInitialization();\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 2**64 - 1 will prevent any future reinitialization.\n     *\n     * Emits an {Initialized} event.\n     */\n    modifier reinitializer(uint64 version) {\n        // solhint-disable-next-line var-name-mixedcase\n        InitializableStorage storage $ = _getInitializableStorage();\n\n        if ($._initializing || $._initialized >= version) {\n            revert InvalidInitialization();\n        }\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        _checkInitializing();\n        _;\n    }\n\n    /**\n     * @dev Reverts if the contract is not in an initializing state. See {onlyInitializing}.\n     */\n    function _checkInitializing() internal view virtual {\n        if (!_isInitializing()) {\n            revert NotInitializing();\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        // solhint-disable-next-line var-name-mixedcase\n        InitializableStorage storage $ = _getInitializableStorage();\n\n        if ($._initializing) {\n            revert InvalidInitialization();\n        }\n        if ($._initialized != type(uint64).max) {\n            $._initialized = type(uint64).max;\n            emit Initialized(type(uint64).max);\n        }\n    }\n\n    /**\n     * @dev Returns the highest version that has been initialized. See {reinitializer}.\n     */\n    function _getInitializedVersion() internal view returns (uint64) {\n        return _getInitializableStorage()._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 _getInitializableStorage()._initializing;\n    }\n\n    /**\n     * @dev Returns a pointer to the storage namespace.\n     */\n    // solhint-disable-next-line var-name-mixedcase\n    function _getInitializableStorage() private pure returns (InitializableStorage storage $) {\n        assembly {\n            $.slot := INITIALIZABLE_STORAGE\n        }\n    }\n}\n"},{"file_path":"lib/openzeppelin-contracts-upgradeable/lib/openzeppelin-contracts/contracts/utils/types/Time.sol","source_code":"// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.0.0) (utils/types/Time.sol)\n\npragma solidity ^0.8.20;\n\nimport {Math} from \"../math/Math.sol\";\nimport {SafeCast} from \"../math/SafeCast.sol\";\n\n/**\n * @dev This library provides helpers for manipulating time-related objects.\n *\n * It uses the following types:\n * - `uint48` for timepoints\n * - `uint32` for durations\n *\n * While the library doesn't provide specific types for timepoints and duration, it does provide:\n * - a `Delay` type to represent duration that can be programmed to change value automatically at a given point\n * - additional helper functions\n */\nlibrary Time {\n    using Time for *;\n\n    /**\n     * @dev Get the block timestamp as a Timepoint.\n     */\n    function timestamp() internal view returns (uint48) {\n        return SafeCast.toUint48(block.timestamp);\n    }\n\n    /**\n     * @dev Get the block number as a Timepoint.\n     */\n    function blockNumber() internal view returns (uint48) {\n        return SafeCast.toUint48(block.number);\n    }\n\n    // ==================================================== Delay =====================================================\n    /**\n     * @dev A `Delay` is a uint32 duration that can be programmed to change value automatically at a given point in the\n     * future. The \"effect\" timepoint describes when the transitions happens from the \"old\" value to the \"new\" value.\n     * This allows updating the delay applied to some operation while keeping some guarantees.\n     *\n     * In particular, the {update} function guarantees that if the delay is reduced, the old delay still applies for\n     * some time. For example if the delay is currently 7 days to do an upgrade, the admin should not be able to set\n     * the delay to 0 and upgrade immediately. If the admin wants to reduce the delay, the old delay (7 days) should\n     * still apply for some time.\n     *\n     *\n     * The `Delay` type is 112 bits long, and packs the following:\n     *\n     * ```\n     *   | [uint48]: effect date (timepoint)\n     *   |           | [uint32]: value before (duration)\n     *   ↓           ↓       ↓ [uint32]: value after (duration)\n     * 0xAAAAAAAAAAAABBBBBBBBCCCCCCCC\n     * ```\n     *\n     * NOTE: The {get} and {withUpdate} functions operate using timestamps. Block number based delays are not currently\n     * supported.\n     */\n    type Delay is uint112;\n\n    /**\n     * @dev Wrap a duration into a Delay to add the one-step \"update in the future\" feature\n     */\n    function toDelay(uint32 duration) internal pure returns (Delay) {\n        return Delay.wrap(duration);\n    }\n\n    /**\n     * @dev Get the value at a given timepoint plus the pending value and effect timepoint if there is a scheduled\n     * change after this timepoint. If the effect timepoint is 0, then the pending value should not be considered.\n     */\n    function _getFullAt(Delay self, uint48 timepoint) private pure returns (uint32, uint32, uint48) {\n        (uint32 valueBefore, uint32 valueAfter, uint48 effect) = self.unpack();\n        return effect <= timepoint ? (valueAfter, 0, 0) : (valueBefore, valueAfter, effect);\n    }\n\n    /**\n     * @dev Get the current value plus the pending value and effect timepoint if there is a scheduled change. If the\n     * effect timepoint is 0, then the pending value should not be considered.\n     */\n    function getFull(Delay self) internal view returns (uint32, uint32, uint48) {\n        return _getFullAt(self, timestamp());\n    }\n\n    /**\n     * @dev Get the current value.\n     */\n    function get(Delay self) internal view returns (uint32) {\n        (uint32 delay, , ) = self.getFull();\n        return delay;\n    }\n\n    /**\n     * @dev Update a Delay object so that it takes a new duration after a timepoint that is automatically computed to\n     * enforce the old delay at the moment of the update. Returns the updated Delay object and the timestamp when the\n     * new delay becomes effective.\n     */\n    function withUpdate(\n        Delay self,\n        uint32 newValue,\n        uint32 minSetback\n    ) internal view returns (Delay updatedDelay, uint48 effect) {\n        uint32 value = self.get();\n        uint32 setback = uint32(Math.max(minSetback, value > newValue ? value - newValue : 0));\n        effect = timestamp() + setback;\n        return (pack(value, newValue, effect), effect);\n    }\n\n    /**\n     * @dev Split a delay into its components: valueBefore, valueAfter and effect (transition timepoint).\n     */\n    function unpack(Delay self) internal pure returns (uint32 valueBefore, uint32 valueAfter, uint48 effect) {\n        uint112 raw = Delay.unwrap(self);\n\n        valueAfter = uint32(raw);\n        valueBefore = uint32(raw >> 32);\n        effect = uint48(raw >> 64);\n\n        return (valueBefore, valueAfter, effect);\n    }\n\n    /**\n     * @dev pack the components into a Delay object.\n     */\n    function pack(uint32 valueBefore, uint32 valueAfter, uint48 effect) internal pure returns (Delay) {\n        return Delay.wrap((uint112(effect) << 64) | (uint112(valueBefore) << 32) | uint112(valueAfter));\n    }\n}\n"},{"file_path":"lib/openzeppelin-contracts-upgradeable/lib/openzeppelin-contracts/contracts/interfaces/IERC5267.sol","source_code":"// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.0.0) (interfaces/IERC5267.sol)\n\npragma solidity ^0.8.20;\n\ninterface IERC5267 {\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":"src/Types/TroveChange.sol","source_code":"// SPDX-License-Identifier: MIT\n\npragma solidity ^0.8.24;\n\nstruct TroveChange {\n    uint256 appliedRedistBoldDebtGain;\n    uint256 appliedRedistCollGain;\n    uint256 collIncrease;\n    uint256 collDecrease;\n    uint256 debtIncrease;\n    uint256 debtDecrease;\n    uint256 newWeightedRecordedDebt;\n    uint256 oldWeightedRecordedDebt;\n    uint256 upfrontFee;\n    uint256 batchAccruedManagementFee;\n    uint256 newWeightedRecordedBatchManagementFee;\n    uint256 oldWeightedRecordedBatchManagementFee;\n}\n"}],"is_verified_via_sourcify":false,"can_be_visualized_via_sol2uml":true,"evm_version":"cancun","language":"solidity","is_verified_via_eth_bytecode_db":false,"is_fully_verified":false,"license_type":"none","is_blueprint":false,"name":"CollateralRegistry","creation_bytecode":"0x60a060405230608052348015610013575f80fd5b5061001c610021565b6100d3565b7ff0c57e16840df040f15088dc2f81fe391c3923bec73e23a9662efc9c229c6a00805468010000000000000000900460ff16156100715760405163f92ee8a960e01b815260040160405180910390fd5b80546001600160401b03908116146100d05780546001600160401b0319166001600160401b0390811782556040519081527fc7f505b2f371ae2175ee4913f4499e1f2633a7b5936321eed1cdaeb6115181d29060200160405180910390a15b50565b6080516130256100f95f395f81816121d0015281816121f9015261234301526130255ff3fe6080604052600436106101da575f3560e01c80637f06d28d116100fd578063c0c53b8b11610092578063d380a37c11610062578063d380a37c1461054f578063d5b3563514610564578063e4b50cb814610583578063f2cfc21a146105a2575f80fd5b8063c0c53b8b146104de578063c3bfd842146104fd578063c52861f21461051c578063cc9ece6414610530575f80fd5b8063aa7fc7e5116100cd578063aa7fc7e51461044f578063ab6d53bd1461046e578063ad3cb1cc1461048d578063bf7e214f146104ca575f80fd5b80637f06d28d146103c55780638fb36037146103e45780639a1c9323146104115780639c85dc6214610430575f80fd5b80634f1ef28611610173578063630afce511610143578063630afce51461034957806363f1134e146103685780637a9e5e4b146103875780637d10dbff146103a6575f80fd5b80634f1ef286146102e457806352278e48146102f757806352d1902d14610316578063597810341461032a575f80fd5b8063230fe6e5116101ae578063230fe6e51461027d5780632b11551a1461029c57806330504b6f146102b05780633a331022146102c5575f80fd5b806202ad2f146101de5780630b3c44d3146101ff5780630bc17feb1461021e5780631f68f20a1461025a575b5f80fd5b3480156101e9575f80fd5b506101fd6101f8366004612b3a565b6105b6565b005b34801561020a575f80fd5b506101fd610219366004612b68565b610690565b348015610229575f80fd5b5061023d610238366004612b68565b61072b565b6040516001600160a01b0390911681526020015b60405180910390f35b348015610265575f80fd5b5061026f60385481565b604051908152602001610251565b348015610288575f80fd5b506101fd610297366004612b7f565b610789565b3480156102a7575f80fd5b5061026f61083c565b3480156102bb575f80fd5b5061026f60325481565b3480156102d0575f80fd5b506101fd6102df366004612b7f565b61084d565b6101fd6102f2366004612bb3565b610b2b565b348015610302575f80fd5b5061026f610311366004612b68565b610b4a565b348015610321575f80fd5b5061026f610b78565b348015610335575f80fd5b506101fd610344366004612c71565b610b93565b348015610354575f80fd5b5060365461023d906001600160a01b031681565b348015610373575f80fd5b5061026f610382366004612b68565b610fb2565b348015610392575f80fd5b506101fd6103a1366004612caf565b611048565b3480156103b1575f80fd5b506101fd6103c0366004612b7f565b6110ca565b3480156103d0575f80fd5b506101fd6103df366004612b7f565b6111eb565b3480156103ef575f80fd5b506103f86112de565b6040516001600160e01b03199091168152602001610251565b34801561041c575f80fd5b5061026f61042b366004612caf565b611314565b34801561043b575f80fd5b5061023d61044a366004612b68565b6113df565b34801561045a575f80fd5b506101fd610469366004612b7f565b61144e565b348015610479575f80fd5b506101fd610488366004612cca565b6116fc565b348015610498575f80fd5b506104bd604051806040016040528060058152602001640352e302e360dc1b81525081565b6040516102519190612cf3565b3480156104d5575f80fd5b5061023d611d51565b3480156104e9575f80fd5b506101fd6104f8366004612d28565b611d6c565b348015610508575f80fd5b5061026f610517366004612b68565b611ef7565b348015610527575f80fd5b5061026f611f8e565b34801561053b575f80fd5b506101fd61054a366004612b7f565b611f9a565b34801561055a575f80fd5b5061026f60395481565b34801561056f575f80fd5b5061026f61057e366004612b68565b61205b565b34801561058e575f80fd5b5061023d61059d366004612b68565b61206d565b3480156105ad575f80fd5b5060345461026f565b6105c2335b5f3661208b565b5f6105cc8361072b565b90505f816001600160a01b0316637f7dde4a6040518163ffffffff1660e01b8152600401602060405180830381865afa15801561060b573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061062f9190612d70565b604051637fbde1fb60e01b81526001600160a01b03858116600483015291925090821690637fbde1fb906024015b5f604051808303815f87803b158015610674575f80fd5b505af1158015610686573d5f803e3d5ffd5b5050505050505050565b610699336105bb565b6106a2816113df565b6001600160a01b031663ee556e756040518163ffffffff1660e01b81526004015f604051808303815f87803b1580156106d9575f80fd5b505af11580156106eb573d5f803e3d5ffd5b505050507f2845be095a376ba6d0263c3932f31944d8be8a589668c36834e5e5a5685c84028160405161072091815260200190565b60405180910390a150565b5f603254821015610763576034828154811061074957610749612d8b565b5f918252602090912001546001600160a01b031692915050565b60405163042a2e7160e11b8152600481018390526024015b60405180910390fd5b919050565b610792336105bb565b6107a6680ad78ebc5ac6200000600a612db3565b8110156107c65760405163271a0d5960e01b815260040160405180910390fd5b80603583815481106107da576107da612d8b565b5f918252602090912001557f7264a10feda41027513c4effa4bf5a3d4f36c3c3b8fbbde4df55edc104108b4f826108108161072b565b604080519283526001600160a01b03909116602083015281018390526060015b60405180910390a15050565b5f610848603854612189565b905090565b610856336105bb565b5f6108608361072b565b9050806001600160a01b031663c3ef7d81826001600160a01b03166358d5a9616040518163ffffffff1660e01b8152600401602060405180830381865afa1580156108ad573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906108d19190612dca565b84846001600160a01b0316635733d58f6040518163ffffffff1660e01b8152600401602060405180830381865afa15801561090e573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906109329190612dca565b856001600160a01b03166388f471a56040518163ffffffff1660e01b8152600401602060405180830381865afa15801561096e573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906109929190612dca565b866001600160a01b031663c24055f86040518163ffffffff1660e01b8152600401602060405180830381865afa1580156109ce573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906109f29190612dca565b876001600160a01b0316636f6713f96040518163ffffffff1660e01b8152600401602060405180830381865afa158015610a2e573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610a529190612dca565b886001600160a01b031663f6286d3f6040518163ffffffff1660e01b8152600401602060405180830381865afa158015610a8e573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610ab29190612dca565b6040516001600160e01b031960e08a901b1681526004810197909752602487019590955260448601939093526064850191909152608484015260a483015260c482015260e4015b5f604051808303815f87803b158015610b10575f80fd5b505af1158015610b22573d5f803e3d5ffd5b50505050505050565b610b336121c5565b610b3c8261226b565b610b468282612277565b5050565b5f6032548210156107635760358281548110610b6857610b68612d8b565b905f5260205f2001549050919050565b5f610b81612338565b505f80516020612fd083398151915290565b610b9c336105bb565b600f60325403610bbf5760405163f586b1c960e01b815260040160405180910390fd5b6036546001600160a01b0390811690841603610bee576040516368f7a67560e11b815260040160405180910390fd5b610c02680ad78ebc5ac6200000600a612db3565b811015610c225760405163271a0d5960e01b815260040160405180910390fd5b5f5b60345460ff82161015610c905760348160ff1681548110610c4757610c47612d8b565b5f918252602090912001546001600160a01b0390811690841603610c7e5760405163fe746c0f60e01b815260040160405180910390fd5b80610c8881612de1565b915050610c24565b506033805460018082019092557f82a75bdeeae8604d839476ae9efd8b0e15aa447e21bfd7f41283bb54e22c9a82810180546001600160a01b038088166001600160a01b031992831617909255603480548086019091557f46bddb1178e94d7f2892ff5f366840eb658911794f2c3a44c450aa2c505186c1018054928716929091169190911790556035805492830181555f9081527fcfa4bec1d3298408bb5afcfcd9c430549c5b31f8aa5c5848151c0a55f473c34d909201839055603280549192610d5b83612dff565b919050555060365f9054906101000a90046001600160a01b03166001600160a01b031663e90d173b828686876001600160a01b031663048c661d6040518163ffffffff1660e01b8152600401602060405180830381865afa158015610dc2573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610de69190612d70565b886001600160a01b03166377553ad46040518163ffffffff1660e01b8152600401602060405180830381865afa158015610e22573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610e469190612d70565b896001600160a01b0316637f7dde4a6040518163ffffffff1660e01b8152600401602060405180830381865afa158015610e82573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610ea69190612d70565b6040516001600160e01b031960e089901b16815260048101969096526001600160a01b03948516602487015292841660448601529083166064850152821660848401521660a482015260c4015f604051808303815f87803b158015610f09575f80fd5b505af1158015610f1b573d5f803e3d5ffd5b5050604080516001600160a01b038089168252871660208201527f63b5dc5e99047761794ba2b13700899319b3d9e518330e2eb21dd505d2f4b733935001905060405180910390a1604080518281526001600160a01b03851660208201529081018390527f7264a10feda41027513c4effa4bf5a3d4f36c3c3b8fbbde4df55edc104108b4f9060600160405180910390a150505050565b5f8060365f9054906101000a90046001600160a01b03166001600160a01b03166318160ddd6040518163ffffffff1660e01b8152600401602060405180830381865afa158015611004573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906110289190612dca565b90505f6110358483612381565b905061104081612189565b949350505050565b33611051611d51565b6001600160a01b0316816001600160a01b03161461108c5760405162d1953b60e31b81526001600160a01b038216600482015260240161077b565b816001600160a01b03163b5f036110c1576040516361798f2f60e11b81526001600160a01b038316600482015260240161077b565b610b46826123e1565b6110d3336105bb565b5f6110dd8361072b565b9050806001600160a01b031663c3ef7d81826001600160a01b03166358d5a9616040518163ffffffff1660e01b8152600401602060405180830381865afa15801561112a573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061114e9190612dca565b836001600160a01b031663794e57246040518163ffffffff1660e01b8152600401602060405180830381865afa15801561118a573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906111ae9190612dca565b85856001600160a01b03166388f471a56040518163ffffffff1660e01b8152600401602060405180830381865afa15801561096e573d5f803e3d5ffd5b6111f4336105bb565b5f6111fe8361072b565b90505f816001600160a01b0316637f7dde4a6040518163ffffffff1660e01b8152600401602060405180830381865afa15801561123d573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906112619190612d70565b9050806001600160a01b0316631bfa0d7b6040518163ffffffff1660e01b81526004015f604051808303815f87803b15801561129b575f80fd5b505af11580156112ad573d5f803e3d5ffd5b505060405163641c74f760e11b8152600481018690526001600160a01b038416925063c838e9ee915060240161065d565b5f80516020612fb083398151915280545f9190600160a01b900460ff16611305575f61130e565b638fb3603760e01b5b91505090565b5f805b60345481101561138357826001600160a01b03166034828154811061133e5761133e612d8b565b5f918252602090912001546001600160a01b03160361137b576035818154811061136a5761136a612d8b565b905f5260205f200154915050919050565b600101611317565b5060405162461bcd60e51b815260206004820152602a60248201527f436f6c6c61746572616c52656769737472793a2054726f76654d616e61676572604482015269081b9bdd08199bdd5b9960b21b606482015260840161077b565b5f6113e98261072b565b6001600160a01b031663e100a03a6040518163ffffffff1660e01b8152600401602060405180830381865afa158015611424573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906114489190612d70565b92915050565b611457336105bb565b5f6114618361072b565b9050806001600160a01b031663c3ef7d81826001600160a01b03166358d5a9616040518163ffffffff1660e01b8152600401602060405180830381865afa1580156114ae573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906114d29190612dca565b836001600160a01b031663794e57246040518163ffffffff1660e01b8152600401602060405180830381865afa15801561150e573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906115329190612dca565b846001600160a01b0316635733d58f6040518163ffffffff1660e01b8152600401602060405180830381865afa15801561156e573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906115929190612dca565b856001600160a01b03166388f471a56040518163ffffffff1660e01b8152600401602060405180830381865afa1580156115ce573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906115f29190612dca565b866001600160a01b031663c24055f86040518163ffffffff1660e01b8152600401602060405180830381865afa15801561162e573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906116529190612dca565b876001600160a01b0316636f6713f96040518163ffffffff1660e01b8152600401602060405180830381865afa15801561168e573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906116b29190612dca565b6040516001600160e01b031960e089901b1681526004810196909652602486019490945260448501929092526064840152608483015260a482015260c4810185905260e401610af9565b61170461243a565b61170d8161249d565b61171683612538565b61173d60405180608001604052805f81526020015f81526020015f81526020015f81525090565b6032548082525f9067ffffffffffffffff81111561175d5761175d612b9f565b604051908082528060200260200182016040528015611786578160200160208202803683370190505b5090505f825f015167ffffffffffffffff8111156117a6576117a6612b9f565b6040519080825280602002602001820160405280156117cf578160200160208202803683370190505b5090505f5b83518110156118c0575f6117e78261072b565b90505f805f836001600160a01b0316634ea15f376040518163ffffffff1660e01b81526004016060604051808303815f875af1158015611829573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061184d9190612e26565b9250925092508186868151811061186657611866612d8b565b60200260200101818152505080156118b057828860400181815161188a9190612e58565b905250865183908890879081106118a3576118a3612d8b565b6020026020010181815250505b5050600190920191506117d49050565b5082604001515f03611a4157825167ffffffffffffffff8111156118e6576118e6612b9f565b60405190808252806020026020018201604052801561190f578160200160208202803683370190505b5091505f5b8351811015611a3b575f6119278261072b565b90505f816001600160a01b0316634ea15f376040518163ffffffff1660e01b81526004016060604051808303815f875af1158015611967573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061198b9190612e26565b925050508015611a31575f826001600160a01b031663105b403b6040518163ffffffff1660e01b8152600401602060405180830381865afa1580156119d2573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906119f69190612dca565b90508087604001818151611a0a9190612e58565b90525085518190879086908110611a2357611a23612d8b565b602002602001018181525050505b5050600101611914565b50611a55565b8260400151861115611a5557826040015195505b60365f9054906101000a90046001600160a01b03166001600160a01b03166318160ddd6040518163ffffffff1660e01b8152600401602060405180830381865afa158015611aa5573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190611ac99190612dca565b602084018190525f90611ae690611ae1908990612381565b612189565b905084811115611b425760405162461bcd60e51b815260206004820152602160248201527f43523a204665652065786365656465642070726f7669646564206d6178696d756044820152606d60f81b606482015260840161077b565b5f5b8451811015611cc6575f848281518110611b6057611b60612d8b565b60200260200101511115611cbe575f8560400151858381518110611b8657611b86612d8b565b60200260200101518a611b999190612db3565b611ba39190612e7f565b90508015611c82575f611bb58361072b565b90505f816001600160a01b031663f8a239e83385898881518110611bdb57611bdb612d8b565b60209081029190910101516040516001600160e01b031960e086901b1681526001600160a01b0390931660048401526024830191909152604482015260648101889052608481018d905260a4016020604051808303815f875af1158015611c44573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190611c689190612dca565b90508088606001818151611c7c9190612e58565b90525050505b611c8c818a612e92565b9850848281518110611ca057611ca0612d8b565b602002602001015186604001818151611cb99190612e92565b905250505b600101611b44565b50611cd9846060015185602001516125a4565b606084015115610b22576036546060850151604051632770a7eb60e21b815233600482015260248101919091526001600160a01b0390911690639dc29fac906044015f604051808303815f87803b158015611d32575f80fd5b505af1158015611d44573d5f803e3d5ffd5b5050505050505050505050565b5f80516020612fb0833981519152546001600160a01b031690565b7ff0c57e16840df040f15088dc2f81fe391c3923bec73e23a9662efc9c229c6a008054600160401b810460ff16159067ffffffffffffffff165f81158015611db15750825b90505f8267ffffffffffffffff166001148015611dcd5750303b155b905081158015611ddb575080155b15611df95760405163f92ee8a960e01b815260040160405180910390fd5b845467ffffffffffffffff191660011785558315611e2357845460ff60401b1916600160401b1785555b611e2c886125f2565b42603955603680546001600160a01b03808a166001600160a01b0319928316179092556037805492891692909116919091179055670de0b6b3a764000060388190556040517fc454ee9b76c52f782a256af821b857ca6e125d1e3333bcede402fec2bed9600c91611ea09190815260200190565b60405180910390a1831561068657845460ff60401b19168555604051600181527fc7f505b2f371ae2175ee4913f4499e1f2633a7b5936321eed1cdaeb6115181d29060200160405180910390a15050505050505050565b5f8060365f9054906101000a90046001600160a01b03166001600160a01b03166318160ddd6040518163ffffffff1660e01b8152600401602060405180830381865afa158015611f49573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190611f6d9190612dca565b90505f611f7a8483612381565b9050611040611f8882612189565b8561260b565b5f610848611ae161262a565b611fa3336105bb565b5f611fad8361072b565b9050806001600160a01b031663c3ef7d8183836001600160a01b031663794e57246040518163ffffffff1660e01b8152600401602060405180830381865afa158015611ffb573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061201f9190612dca565b846001600160a01b0316635733d58f6040518163ffffffff1660e01b8152600401602060405180830381865afa15801561090e573d5f803e3d5ffd5b5f611448612067611f8e565b8361260b565b5f603254821015610763576033828154811061074957610749612d8b565b5f80516020612fb08339815191525f806120c36120a6611d51565b87306120b560045f8a8c612ea5565b6120be91612ecc565b612673565b91509150816121815763ffffffff81161561215e57825460ff60a01b1916600160a01b1783556120f1611d51565b6001600160a01b03166394c7d7ee8787876040518463ffffffff1660e01b815260040161212093929190612efc565b5f604051808303815f87803b158015612137575f80fd5b505af1158015612149573d5f803e3d5ffd5b5050845460ff60a01b19168555506121819050565b60405162d1953b60e31b81526001600160a01b038716600482015260240161077b565b505050505050565b5f6114488260026121a36064670de0b6b3a7640000612e7f565b6121ad9190612e7f565b6121b79190612e58565b670de0b6b3a764000061277b565b306001600160a01b037f000000000000000000000000000000000000000000000000000000000000000016148061224b57507f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031661223f5f80516020612fd0833981519152546001600160a01b031690565b6001600160a01b031614155b156122695760405163703e46dd60e11b815260040160405180910390fd5b565b612274336105bb565b50565b816001600160a01b03166352d1902d6040518163ffffffff1660e01b8152600401602060405180830381865afa9250505080156122d1575060408051601f3d908101601f191682019092526122ce91810190612dca565b60015b6122f957604051634c9c8ce360e01b81526001600160a01b038316600482015260240161077b565b5f80516020612fd0833981519152811461232957604051632a87526960e21b81526004810182905260240161077b565b6123338383612792565b505050565b306001600160a01b037f000000000000000000000000000000000000000000000000000000000000000016146122695760405163703e46dd60e11b815260040160405180910390fd5b5f8061238b61262a565b90505f836123a1670de0b6b3a764000087612db3565b6123ab9190612e7f565b90505f6123b9600183612e7f565b6123c39084612e58565b90506123d781670de0b6b3a764000061277b565b9695505050505050565b5f80516020612fb083398151915280546001600160a01b0319166001600160a01b03831690811782556040519081527f2f658b440c35314f52658ea8a740e05b284cdc84dc9ae01e891f21b8933e7cad90602001610830565b60375f9054906101000a90046001600160a01b03166001600160a01b031663a6b6db5e6040518163ffffffff1660e01b81526004015f6040518083038186803b158015612485575f80fd5b505afa158015612497573d5f803e3d5ffd5b50505050565b60026124b26064670de0b6b3a7640000612e7f565b6124bc9190612e7f565b81101580156124d35750670de0b6b3a76400008111155b6122745760405162461bcd60e51b815260206004820152603060248201527f4d6178206665652070657263656e74616765206d75737420626520626574776560448201526f656e20302e352520616e64203130302560801b606482015260840161077b565b5f81116122745760405162461bcd60e51b815260206004820152603460248201527f436f6c6c61746572616c52656769737472793a20416d6f756e74206d7573742060448201527362652067726561746572207468616e207a65726f60601b606482015260840161077b565b5f6125af8383612381565b60388190556040518181529091507fc454ee9b76c52f782a256af821b857ca6e125d1e3333bcede402fec2bed9600c9060200160405180910390a16123336127e7565b6125fa61284b565b61260381612894565b6122746128a5565b5f80670de0b6b3a76400006126208486612db3565b6110409190612e7f565b5f806126346128ad565b90505f612649670dd9e13cc602b400836128c8565b9050670de0b6b3a7640000816038546126629190612db3565b61266c9190612e7f565b9250505090565b6040516001600160a01b03848116602483015283811660448301526001600160e01b0319831660648301525f9182918291829189169060840160408051601f198184030181529181526020820180516001600160e01b031663b700961360e01b179052516126e19190612f3b565b5f60405180830381855afa9150503d805f8114612719576040519150601f19603f3d011682016040523d82523d5f602084013e61271e565b606091505b5091509150811561277057604081511061275057808060200190518101906127469190612f51565b9094509250612770565b6020815110612770578080602001905181019061276d9190612f83565b93505b505094509492505050565b5f818310612789578161278b565b825b9392505050565b61279b82612970565b6040516001600160a01b038316907fbc7cd75a20ee27fd9adebab32041f755214dbc6bffa90cc0225b39da2e5c2d3b905f90a28051156127df5761233382826129d3565b610b46612a45565b5f6127f06128ad565b905080156122745761280381603c612db3565b60395f8282546128139190612e58565b90915550506039546040519081527f860f8d2f0c74dd487e89e2883e3b25b8159ce1e1b3433a291cba7b82c508f3bc90602001610720565b7ff0c57e16840df040f15088dc2f81fe391c3923bec73e23a9662efc9c229c6a0054600160401b900460ff1661226957604051631afcd79f60e31b815260040160405180910390fd5b61289c61284b565b61227481612a64565b61226961284b565b5f603c603954426128be9190612e92565b6108489190612e7f565b5f631f5405008211156128dd57631f54050091505b815f036128f35750670de0b6b3a7640000611448565b670de0b6b3a764000083835b600181111561296657612913600282612f9c565b5f03612937576129238283612a75565b9150612930600282612e7f565b90506128ff565b6129418284612a75565b925061294d8283612a75565b9150600261295c600183612e92565b6129309190612e7f565b6123d78284612a75565b806001600160a01b03163b5f036129a557604051634c9c8ce360e01b81526001600160a01b038216600482015260240161077b565b5f80516020612fd083398151915280546001600160a01b0319166001600160a01b0392909216919091179055565b60605f80846001600160a01b0316846040516129ef9190612f3b565b5f60405180830381855af49150503d805f8114612a27576040519150601f19603f3d011682016040523d82523d5f602084013e612a2c565b606091505b5091509150612a3c858383612aa1565b95945050505050565b34156122695760405163b398979f60e01b815260040160405180910390fd5b612a6c61284b565b612274816123e1565b5f80612a818385612db3565b9050670de0b6b3a7640000612a97600282612e7f565b6126209083612e58565b606082612ab657612ab182612afd565b61278b565b8151158015612acd57506001600160a01b0384163b155b15612af657604051639996b31560e01b81526001600160a01b038516600482015260240161077b565b5092915050565b805115612b0d5780518082602001fd5b604051630a12f52160e11b815260040160405180910390fd5b6001600160a01b0381168114612274575f80fd5b5f8060408385031215612b4b575f80fd5b823591506020830135612b5d81612b26565b809150509250929050565b5f60208284031215612b78575f80fd5b5035919050565b5f8060408385031215612b90575f80fd5b50508035926020909101359150565b634e487b7160e01b5f52604160045260245ffd5b5f8060408385031215612bc4575f80fd5b8235612bcf81612b26565b9150602083013567ffffffffffffffff80821115612beb575f80fd5b818501915085601f830112612bfe575f80fd5b813581811115612c1057612c10612b9f565b604051601f8201601f19908116603f01168101908382118183101715612c3857612c38612b9f565b81604052828152886020848701011115612c50575f80fd5b826020860160208301375f6020848301015280955050505050509250929050565b5f805f60608486031215612c83575f80fd5b8335612c8e81612b26565b92506020840135612c9e81612b26565b929592945050506040919091013590565b5f60208284031215612cbf575f80fd5b813561278b81612b26565b5f805f60608486031215612cdc575f80fd5b505081359360208301359350604090920135919050565b602081525f82518060208401528060208501604085015e5f604082850101526040601f19601f83011684010191505092915050565b5f805f60608486031215612d3a575f80fd5b8335612d4581612b26565b92506020840135612d5581612b26565b91506040840135612d6581612b26565b809150509250925092565b5f60208284031215612d80575f80fd5b815161278b81612b26565b634e487b7160e01b5f52603260045260245ffd5b634e487b7160e01b5f52601160045260245ffd5b808202811582820484141761144857611448612d9f565b5f60208284031215612dda575f80fd5b5051919050565b5f60ff821660ff8103612df657612df6612d9f565b60010192915050565b5f60018201612e1057612e10612d9f565b5060010190565b80518015158114610784575f80fd5b5f805f60608486031215612e38575f80fd5b8351925060208401519150612e4f60408501612e17565b90509250925092565b8082018082111561144857611448612d9f565b634e487b7160e01b5f52601260045260245ffd5b5f82612e8d57612e8d612e6b565b500490565b8181038181111561144857611448612d9f565b5f8085851115612eb3575f80fd5b83861115612ebf575f80fd5b5050820193919092039150565b6001600160e01b03198135818116916004851015612ef45780818660040360031b1b83161692505b505092915050565b6001600160a01b03841681526040602082018190528101829052818360608301375f818301606090810191909152601f909201601f1916010192915050565b5f82518060208501845e5f920191825250919050565b5f8060408385031215612f62575f80fd5b612f6b83612e17565b9150602083015163ffffffff81168114612b5d575f80fd5b5f60208284031215612f93575f80fd5b61278b82612e17565b5f82612faa57612faa612e6b565b50069056fef3177357ab46d8af007ab3fdb9af81da189e1068fefdc0073dca88a2cab40a00360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbca2646970667358221220d27cb72f85ee55a22c14eb8ff29e491de031712b6011498a7541b0ececc1d6f064736f6c63430008190033","external_libraries":[{"name":"BorrowerOperationsSupportingLib","address_hash":"0x5A627DD0352a7C15685aD5BC2012346BC2901E30"}],"proxy_type":null,"implementations":[],"verified_at":"2026-03-14T13:36:52.649626Z","is_verified_via_verifier_alliance":false,"compiler_version":"v0.8.25+commit.b61c2a91","decoded_constructor_args":null,"sourcify_repo_url":null,"optimization_runs":200,"compiler_settings":{"evmVersion":"cancun","libraries":{"src/Quill/BorrowerOperationsSupportingLib.sol":{"BorrowerOperationsSupportingLib":"0x5A627DD0352a7C15685aD5BC2012346BC2901E30"}},"metadata":{"appendCBOR":true,"bytecodeHash":"ipfs","useLiteralContent":false},"optimizer":{"enabled":true,"runs":200},"outputSelection":{"*":{"":["*"],"*":["*"]}},"remappings":["@openzeppelin/contracts-upgradeable/=lib/openzeppelin-contracts-upgradeable/contracts/","@openzeppelin/contracts/=lib/openzeppelin-contracts-upgradeable/lib/openzeppelin-contracts/contracts/","Solady/=lib/Solady/src/","ds-test/=lib/openzeppelin-foundry-upgrades/lib/solidity-stringutils/lib/ds-test/src/","erc4626-tests/=lib/openzeppelin-contracts-upgradeable/lib/erc4626-tests/","forge-std/=lib/forge-std/src/","openzeppelin-contracts-upgradeable/=lib/openzeppelin-contracts-upgradeable/","openzeppelin-contracts/=lib/openzeppelin-contracts-upgradeable/lib/openzeppelin-contracts/","openzeppelin-foundry-upgrades/=lib/openzeppelin-foundry-upgrades/src/","safe-smart-account/=lib/safe-smart-account/","solidity-stringutils/=lib/openzeppelin-foundry-upgrades/lib/solidity-stringutils/"],"viaIR":false},"is_verified":true,"verified_twin_address_hash":null,"optimization_enabled":true,"deployed_bytecode":"0x6080604052600436106101da575f3560e01c80637f06d28d116100fd578063c0c53b8b11610092578063d380a37c11610062578063d380a37c1461054f578063d5b3563514610564578063e4b50cb814610583578063f2cfc21a146105a2575f80fd5b8063c0c53b8b146104de578063c3bfd842146104fd578063c52861f21461051c578063cc9ece6414610530575f80fd5b8063aa7fc7e5116100cd578063aa7fc7e51461044f578063ab6d53bd1461046e578063ad3cb1cc1461048d578063bf7e214f146104ca575f80fd5b80637f06d28d146103c55780638fb36037146103e45780639a1c9323146104115780639c85dc6214610430575f80fd5b80634f1ef28611610173578063630afce511610143578063630afce51461034957806363f1134e146103685780637a9e5e4b146103875780637d10dbff146103a6575f80fd5b80634f1ef286146102e457806352278e48146102f757806352d1902d14610316578063597810341461032a575f80fd5b8063230fe6e5116101ae578063230fe6e51461027d5780632b11551a1461029c57806330504b6f146102b05780633a331022146102c5575f80fd5b806202ad2f146101de5780630b3c44d3146101ff5780630bc17feb1461021e5780631f68f20a1461025a575b5f80fd5b3480156101e9575f80fd5b506101fd6101f8366004612b3a565b6105b6565b005b34801561020a575f80fd5b506101fd610219366004612b68565b610690565b348015610229575f80fd5b5061023d610238366004612b68565b61072b565b6040516001600160a01b0390911681526020015b60405180910390f35b348015610265575f80fd5b5061026f60385481565b604051908152602001610251565b348015610288575f80fd5b506101fd610297366004612b7f565b610789565b3480156102a7575f80fd5b5061026f61083c565b3480156102bb575f80fd5b5061026f60325481565b3480156102d0575f80fd5b506101fd6102df366004612b7f565b61084d565b6101fd6102f2366004612bb3565b610b2b565b348015610302575f80fd5b5061026f610311366004612b68565b610b4a565b348015610321575f80fd5b5061026f610b78565b348015610335575f80fd5b506101fd610344366004612c71565b610b93565b348015610354575f80fd5b5060365461023d906001600160a01b031681565b348015610373575f80fd5b5061026f610382366004612b68565b610fb2565b348015610392575f80fd5b506101fd6103a1366004612caf565b611048565b3480156103b1575f80fd5b506101fd6103c0366004612b7f565b6110ca565b3480156103d0575f80fd5b506101fd6103df366004612b7f565b6111eb565b3480156103ef575f80fd5b506103f86112de565b6040516001600160e01b03199091168152602001610251565b34801561041c575f80fd5b5061026f61042b366004612caf565b611314565b34801561043b575f80fd5b5061023d61044a366004612b68565b6113df565b34801561045a575f80fd5b506101fd610469366004612b7f565b61144e565b348015610479575f80fd5b506101fd610488366004612cca565b6116fc565b348015610498575f80fd5b506104bd604051806040016040528060058152602001640352e302e360dc1b81525081565b6040516102519190612cf3565b3480156104d5575f80fd5b5061023d611d51565b3480156104e9575f80fd5b506101fd6104f8366004612d28565b611d6c565b348015610508575f80fd5b5061026f610517366004612b68565b611ef7565b348015610527575f80fd5b5061026f611f8e565b34801561053b575f80fd5b506101fd61054a366004612b7f565b611f9a565b34801561055a575f80fd5b5061026f60395481565b34801561056f575f80fd5b5061026f61057e366004612b68565b61205b565b34801561058e575f80fd5b5061023d61059d366004612b68565b61206d565b3480156105ad575f80fd5b5060345461026f565b6105c2335b5f3661208b565b5f6105cc8361072b565b90505f816001600160a01b0316637f7dde4a6040518163ffffffff1660e01b8152600401602060405180830381865afa15801561060b573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061062f9190612d70565b604051637fbde1fb60e01b81526001600160a01b03858116600483015291925090821690637fbde1fb906024015b5f604051808303815f87803b158015610674575f80fd5b505af1158015610686573d5f803e3d5ffd5b5050505050505050565b610699336105bb565b6106a2816113df565b6001600160a01b031663ee556e756040518163ffffffff1660e01b81526004015f604051808303815f87803b1580156106d9575f80fd5b505af11580156106eb573d5f803e3d5ffd5b505050507f2845be095a376ba6d0263c3932f31944d8be8a589668c36834e5e5a5685c84028160405161072091815260200190565b60405180910390a150565b5f603254821015610763576034828154811061074957610749612d8b565b5f918252602090912001546001600160a01b031692915050565b60405163042a2e7160e11b8152600481018390526024015b60405180910390fd5b919050565b610792336105bb565b6107a6680ad78ebc5ac6200000600a612db3565b8110156107c65760405163271a0d5960e01b815260040160405180910390fd5b80603583815481106107da576107da612d8b565b5f918252602090912001557f7264a10feda41027513c4effa4bf5a3d4f36c3c3b8fbbde4df55edc104108b4f826108108161072b565b604080519283526001600160a01b03909116602083015281018390526060015b60405180910390a15050565b5f610848603854612189565b905090565b610856336105bb565b5f6108608361072b565b9050806001600160a01b031663c3ef7d81826001600160a01b03166358d5a9616040518163ffffffff1660e01b8152600401602060405180830381865afa1580156108ad573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906108d19190612dca565b84846001600160a01b0316635733d58f6040518163ffffffff1660e01b8152600401602060405180830381865afa15801561090e573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906109329190612dca565b856001600160a01b03166388f471a56040518163ffffffff1660e01b8152600401602060405180830381865afa15801561096e573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906109929190612dca565b866001600160a01b031663c24055f86040518163ffffffff1660e01b8152600401602060405180830381865afa1580156109ce573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906109f29190612dca565b876001600160a01b0316636f6713f96040518163ffffffff1660e01b8152600401602060405180830381865afa158015610a2e573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610a529190612dca565b886001600160a01b031663f6286d3f6040518163ffffffff1660e01b8152600401602060405180830381865afa158015610a8e573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610ab29190612dca565b6040516001600160e01b031960e08a901b1681526004810197909752602487019590955260448601939093526064850191909152608484015260a483015260c482015260e4015b5f604051808303815f87803b158015610b10575f80fd5b505af1158015610b22573d5f803e3d5ffd5b50505050505050565b610b336121c5565b610b3c8261226b565b610b468282612277565b5050565b5f6032548210156107635760358281548110610b6857610b68612d8b565b905f5260205f2001549050919050565b5f610b81612338565b505f80516020612fd083398151915290565b610b9c336105bb565b600f60325403610bbf5760405163f586b1c960e01b815260040160405180910390fd5b6036546001600160a01b0390811690841603610bee576040516368f7a67560e11b815260040160405180910390fd5b610c02680ad78ebc5ac6200000600a612db3565b811015610c225760405163271a0d5960e01b815260040160405180910390fd5b5f5b60345460ff82161015610c905760348160ff1681548110610c4757610c47612d8b565b5f918252602090912001546001600160a01b0390811690841603610c7e5760405163fe746c0f60e01b815260040160405180910390fd5b80610c8881612de1565b915050610c24565b506033805460018082019092557f82a75bdeeae8604d839476ae9efd8b0e15aa447e21bfd7f41283bb54e22c9a82810180546001600160a01b038088166001600160a01b031992831617909255603480548086019091557f46bddb1178e94d7f2892ff5f366840eb658911794f2c3a44c450aa2c505186c1018054928716929091169190911790556035805492830181555f9081527fcfa4bec1d3298408bb5afcfcd9c430549c5b31f8aa5c5848151c0a55f473c34d909201839055603280549192610d5b83612dff565b919050555060365f9054906101000a90046001600160a01b03166001600160a01b031663e90d173b828686876001600160a01b031663048c661d6040518163ffffffff1660e01b8152600401602060405180830381865afa158015610dc2573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610de69190612d70565b886001600160a01b03166377553ad46040518163ffffffff1660e01b8152600401602060405180830381865afa158015610e22573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610e469190612d70565b896001600160a01b0316637f7dde4a6040518163ffffffff1660e01b8152600401602060405180830381865afa158015610e82573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610ea69190612d70565b6040516001600160e01b031960e089901b16815260048101969096526001600160a01b03948516602487015292841660448601529083166064850152821660848401521660a482015260c4015f604051808303815f87803b158015610f09575f80fd5b505af1158015610f1b573d5f803e3d5ffd5b5050604080516001600160a01b038089168252871660208201527f63b5dc5e99047761794ba2b13700899319b3d9e518330e2eb21dd505d2f4b733935001905060405180910390a1604080518281526001600160a01b03851660208201529081018390527f7264a10feda41027513c4effa4bf5a3d4f36c3c3b8fbbde4df55edc104108b4f9060600160405180910390a150505050565b5f8060365f9054906101000a90046001600160a01b03166001600160a01b03166318160ddd6040518163ffffffff1660e01b8152600401602060405180830381865afa158015611004573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906110289190612dca565b90505f6110358483612381565b905061104081612189565b949350505050565b33611051611d51565b6001600160a01b0316816001600160a01b03161461108c5760405162d1953b60e31b81526001600160a01b038216600482015260240161077b565b816001600160a01b03163b5f036110c1576040516361798f2f60e11b81526001600160a01b038316600482015260240161077b565b610b46826123e1565b6110d3336105bb565b5f6110dd8361072b565b9050806001600160a01b031663c3ef7d81826001600160a01b03166358d5a9616040518163ffffffff1660e01b8152600401602060405180830381865afa15801561112a573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061114e9190612dca565b836001600160a01b031663794e57246040518163ffffffff1660e01b8152600401602060405180830381865afa15801561118a573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906111ae9190612dca565b85856001600160a01b03166388f471a56040518163ffffffff1660e01b8152600401602060405180830381865afa15801561096e573d5f803e3d5ffd5b6111f4336105bb565b5f6111fe8361072b565b90505f816001600160a01b0316637f7dde4a6040518163ffffffff1660e01b8152600401602060405180830381865afa15801561123d573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906112619190612d70565b9050806001600160a01b0316631bfa0d7b6040518163ffffffff1660e01b81526004015f604051808303815f87803b15801561129b575f80fd5b505af11580156112ad573d5f803e3d5ffd5b505060405163641c74f760e11b8152600481018690526001600160a01b038416925063c838e9ee915060240161065d565b5f80516020612fb083398151915280545f9190600160a01b900460ff16611305575f61130e565b638fb3603760e01b5b91505090565b5f805b60345481101561138357826001600160a01b03166034828154811061133e5761133e612d8b565b5f918252602090912001546001600160a01b03160361137b576035818154811061136a5761136a612d8b565b905f5260205f200154915050919050565b600101611317565b5060405162461bcd60e51b815260206004820152602a60248201527f436f6c6c61746572616c52656769737472793a2054726f76654d616e61676572604482015269081b9bdd08199bdd5b9960b21b606482015260840161077b565b5f6113e98261072b565b6001600160a01b031663e100a03a6040518163ffffffff1660e01b8152600401602060405180830381865afa158015611424573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906114489190612d70565b92915050565b611457336105bb565b5f6114618361072b565b9050806001600160a01b031663c3ef7d81826001600160a01b03166358d5a9616040518163ffffffff1660e01b8152600401602060405180830381865afa1580156114ae573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906114d29190612dca565b836001600160a01b031663794e57246040518163ffffffff1660e01b8152600401602060405180830381865afa15801561150e573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906115329190612dca565b846001600160a01b0316635733d58f6040518163ffffffff1660e01b8152600401602060405180830381865afa15801561156e573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906115929190612dca565b856001600160a01b03166388f471a56040518163ffffffff1660e01b8152600401602060405180830381865afa1580156115ce573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906115f29190612dca565b866001600160a01b031663c24055f86040518163ffffffff1660e01b8152600401602060405180830381865afa15801561162e573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906116529190612dca565b876001600160a01b0316636f6713f96040518163ffffffff1660e01b8152600401602060405180830381865afa15801561168e573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906116b29190612dca565b6040516001600160e01b031960e089901b1681526004810196909652602486019490945260448501929092526064840152608483015260a482015260c4810185905260e401610af9565b61170461243a565b61170d8161249d565b61171683612538565b61173d60405180608001604052805f81526020015f81526020015f81526020015f81525090565b6032548082525f9067ffffffffffffffff81111561175d5761175d612b9f565b604051908082528060200260200182016040528015611786578160200160208202803683370190505b5090505f825f015167ffffffffffffffff8111156117a6576117a6612b9f565b6040519080825280602002602001820160405280156117cf578160200160208202803683370190505b5090505f5b83518110156118c0575f6117e78261072b565b90505f805f836001600160a01b0316634ea15f376040518163ffffffff1660e01b81526004016060604051808303815f875af1158015611829573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061184d9190612e26565b9250925092508186868151811061186657611866612d8b565b60200260200101818152505080156118b057828860400181815161188a9190612e58565b905250865183908890879081106118a3576118a3612d8b565b6020026020010181815250505b5050600190920191506117d49050565b5082604001515f03611a4157825167ffffffffffffffff8111156118e6576118e6612b9f565b60405190808252806020026020018201604052801561190f578160200160208202803683370190505b5091505f5b8351811015611a3b575f6119278261072b565b90505f816001600160a01b0316634ea15f376040518163ffffffff1660e01b81526004016060604051808303815f875af1158015611967573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061198b9190612e26565b925050508015611a31575f826001600160a01b031663105b403b6040518163ffffffff1660e01b8152600401602060405180830381865afa1580156119d2573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906119f69190612dca565b90508087604001818151611a0a9190612e58565b90525085518190879086908110611a2357611a23612d8b565b602002602001018181525050505b5050600101611914565b50611a55565b8260400151861115611a5557826040015195505b60365f9054906101000a90046001600160a01b03166001600160a01b03166318160ddd6040518163ffffffff1660e01b8152600401602060405180830381865afa158015611aa5573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190611ac99190612dca565b602084018190525f90611ae690611ae1908990612381565b612189565b905084811115611b425760405162461bcd60e51b815260206004820152602160248201527f43523a204665652065786365656465642070726f7669646564206d6178696d756044820152606d60f81b606482015260840161077b565b5f5b8451811015611cc6575f848281518110611b6057611b60612d8b565b60200260200101511115611cbe575f8560400151858381518110611b8657611b86612d8b565b60200260200101518a611b999190612db3565b611ba39190612e7f565b90508015611c82575f611bb58361072b565b90505f816001600160a01b031663f8a239e83385898881518110611bdb57611bdb612d8b565b60209081029190910101516040516001600160e01b031960e086901b1681526001600160a01b0390931660048401526024830191909152604482015260648101889052608481018d905260a4016020604051808303815f875af1158015611c44573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190611c689190612dca565b90508088606001818151611c7c9190612e58565b90525050505b611c8c818a612e92565b9850848281518110611ca057611ca0612d8b565b602002602001015186604001818151611cb99190612e92565b905250505b600101611b44565b50611cd9846060015185602001516125a4565b606084015115610b22576036546060850151604051632770a7eb60e21b815233600482015260248101919091526001600160a01b0390911690639dc29fac906044015f604051808303815f87803b158015611d32575f80fd5b505af1158015611d44573d5f803e3d5ffd5b5050505050505050505050565b5f80516020612fb0833981519152546001600160a01b031690565b7ff0c57e16840df040f15088dc2f81fe391c3923bec73e23a9662efc9c229c6a008054600160401b810460ff16159067ffffffffffffffff165f81158015611db15750825b90505f8267ffffffffffffffff166001148015611dcd5750303b155b905081158015611ddb575080155b15611df95760405163f92ee8a960e01b815260040160405180910390fd5b845467ffffffffffffffff191660011785558315611e2357845460ff60401b1916600160401b1785555b611e2c886125f2565b42603955603680546001600160a01b03808a166001600160a01b0319928316179092556037805492891692909116919091179055670de0b6b3a764000060388190556040517fc454ee9b76c52f782a256af821b857ca6e125d1e3333bcede402fec2bed9600c91611ea09190815260200190565b60405180910390a1831561068657845460ff60401b19168555604051600181527fc7f505b2f371ae2175ee4913f4499e1f2633a7b5936321eed1cdaeb6115181d29060200160405180910390a15050505050505050565b5f8060365f9054906101000a90046001600160a01b03166001600160a01b03166318160ddd6040518163ffffffff1660e01b8152600401602060405180830381865afa158015611f49573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190611f6d9190612dca565b90505f611f7a8483612381565b9050611040611f8882612189565b8561260b565b5f610848611ae161262a565b611fa3336105bb565b5f611fad8361072b565b9050806001600160a01b031663c3ef7d8183836001600160a01b031663794e57246040518163ffffffff1660e01b8152600401602060405180830381865afa158015611ffb573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061201f9190612dca565b846001600160a01b0316635733d58f6040518163ffffffff1660e01b8152600401602060405180830381865afa15801561090e573d5f803e3d5ffd5b5f611448612067611f8e565b8361260b565b5f603254821015610763576033828154811061074957610749612d8b565b5f80516020612fb08339815191525f806120c36120a6611d51565b87306120b560045f8a8c612ea5565b6120be91612ecc565b612673565b91509150816121815763ffffffff81161561215e57825460ff60a01b1916600160a01b1783556120f1611d51565b6001600160a01b03166394c7d7ee8787876040518463ffffffff1660e01b815260040161212093929190612efc565b5f604051808303815f87803b158015612137575f80fd5b505af1158015612149573d5f803e3d5ffd5b5050845460ff60a01b19168555506121819050565b60405162d1953b60e31b81526001600160a01b038716600482015260240161077b565b505050505050565b5f6114488260026121a36064670de0b6b3a7640000612e7f565b6121ad9190612e7f565b6121b79190612e58565b670de0b6b3a764000061277b565b306001600160a01b037f000000000000000000000000e7a22549c0faad72f888b3ef96b2e269ae70458416148061224b57507f000000000000000000000000e7a22549c0faad72f888b3ef96b2e269ae7045846001600160a01b031661223f5f80516020612fd0833981519152546001600160a01b031690565b6001600160a01b031614155b156122695760405163703e46dd60e11b815260040160405180910390fd5b565b612274336105bb565b50565b816001600160a01b03166352d1902d6040518163ffffffff1660e01b8152600401602060405180830381865afa9250505080156122d1575060408051601f3d908101601f191682019092526122ce91810190612dca565b60015b6122f957604051634c9c8ce360e01b81526001600160a01b038316600482015260240161077b565b5f80516020612fd0833981519152811461232957604051632a87526960e21b81526004810182905260240161077b565b6123338383612792565b505050565b306001600160a01b037f000000000000000000000000e7a22549c0faad72f888b3ef96b2e269ae70458416146122695760405163703e46dd60e11b815260040160405180910390fd5b5f8061238b61262a565b90505f836123a1670de0b6b3a764000087612db3565b6123ab9190612e7f565b90505f6123b9600183612e7f565b6123c39084612e58565b90506123d781670de0b6b3a764000061277b565b9695505050505050565b5f80516020612fb083398151915280546001600160a01b0319166001600160a01b03831690811782556040519081527f2f658b440c35314f52658ea8a740e05b284cdc84dc9ae01e891f21b8933e7cad90602001610830565b60375f9054906101000a90046001600160a01b03166001600160a01b031663a6b6db5e6040518163ffffffff1660e01b81526004015f6040518083038186803b158015612485575f80fd5b505afa158015612497573d5f803e3d5ffd5b50505050565b60026124b26064670de0b6b3a7640000612e7f565b6124bc9190612e7f565b81101580156124d35750670de0b6b3a76400008111155b6122745760405162461bcd60e51b815260206004820152603060248201527f4d6178206665652070657263656e74616765206d75737420626520626574776560448201526f656e20302e352520616e64203130302560801b606482015260840161077b565b5f81116122745760405162461bcd60e51b815260206004820152603460248201527f436f6c6c61746572616c52656769737472793a20416d6f756e74206d7573742060448201527362652067726561746572207468616e207a65726f60601b606482015260840161077b565b5f6125af8383612381565b60388190556040518181529091507fc454ee9b76c52f782a256af821b857ca6e125d1e3333bcede402fec2bed9600c9060200160405180910390a16123336127e7565b6125fa61284b565b61260381612894565b6122746128a5565b5f80670de0b6b3a76400006126208486612db3565b6110409190612e7f565b5f806126346128ad565b90505f612649670dd9e13cc602b400836128c8565b9050670de0b6b3a7640000816038546126629190612db3565b61266c9190612e7f565b9250505090565b6040516001600160a01b03848116602483015283811660448301526001600160e01b0319831660648301525f9182918291829189169060840160408051601f198184030181529181526020820180516001600160e01b031663b700961360e01b179052516126e19190612f3b565b5f60405180830381855afa9150503d805f8114612719576040519150601f19603f3d011682016040523d82523d5f602084013e61271e565b606091505b5091509150811561277057604081511061275057808060200190518101906127469190612f51565b9094509250612770565b6020815110612770578080602001905181019061276d9190612f83565b93505b505094509492505050565b5f818310612789578161278b565b825b9392505050565b61279b82612970565b6040516001600160a01b038316907fbc7cd75a20ee27fd9adebab32041f755214dbc6bffa90cc0225b39da2e5c2d3b905f90a28051156127df5761233382826129d3565b610b46612a45565b5f6127f06128ad565b905080156122745761280381603c612db3565b60395f8282546128139190612e58565b90915550506039546040519081527f860f8d2f0c74dd487e89e2883e3b25b8159ce1e1b3433a291cba7b82c508f3bc90602001610720565b7ff0c57e16840df040f15088dc2f81fe391c3923bec73e23a9662efc9c229c6a0054600160401b900460ff1661226957604051631afcd79f60e31b815260040160405180910390fd5b61289c61284b565b61227481612a64565b61226961284b565b5f603c603954426128be9190612e92565b6108489190612e7f565b5f631f5405008211156128dd57631f54050091505b815f036128f35750670de0b6b3a7640000611448565b670de0b6b3a764000083835b600181111561296657612913600282612f9c565b5f03612937576129238283612a75565b9150612930600282612e7f565b90506128ff565b6129418284612a75565b925061294d8283612a75565b9150600261295c600183612e92565b6129309190612e7f565b6123d78284612a75565b806001600160a01b03163b5f036129a557604051634c9c8ce360e01b81526001600160a01b038216600482015260240161077b565b5f80516020612fd083398151915280546001600160a01b0319166001600160a01b0392909216919091179055565b60605f80846001600160a01b0316846040516129ef9190612f3b565b5f60405180830381855af49150503d805f8114612a27576040519150601f19603f3d011682016040523d82523d5f602084013e612a2c565b606091505b5091509150612a3c858383612aa1565b95945050505050565b34156122695760405163b398979f60e01b815260040160405180910390fd5b612a6c61284b565b612274816123e1565b5f80612a818385612db3565b9050670de0b6b3a7640000612a97600282612e7f565b6126209083612e58565b606082612ab657612ab182612afd565b61278b565b8151158015612acd57506001600160a01b0384163b155b15612af657604051639996b31560e01b81526001600160a01b038516600482015260240161077b565b5092915050565b805115612b0d5780518082602001fd5b604051630a12f52160e11b815260040160405180910390fd5b6001600160a01b0381168114612274575f80fd5b5f8060408385031215612b4b575f80fd5b823591506020830135612b5d81612b26565b809150509250929050565b5f60208284031215612b78575f80fd5b5035919050565b5f8060408385031215612b90575f80fd5b50508035926020909101359150565b634e487b7160e01b5f52604160045260245ffd5b5f8060408385031215612bc4575f80fd5b8235612bcf81612b26565b9150602083013567ffffffffffffffff80821115612beb575f80fd5b818501915085601f830112612bfe575f80fd5b813581811115612c1057612c10612b9f565b604051601f8201601f19908116603f01168101908382118183101715612c3857612c38612b9f565b81604052828152886020848701011115612c50575f80fd5b826020860160208301375f6020848301015280955050505050509250929050565b5f805f60608486031215612c83575f80fd5b8335612c8e81612b26565b92506020840135612c9e81612b26565b929592945050506040919091013590565b5f60208284031215612cbf575f80fd5b813561278b81612b26565b5f805f60608486031215612cdc575f80fd5b505081359360208301359350604090920135919050565b602081525f82518060208401528060208501604085015e5f604082850101526040601f19601f83011684010191505092915050565b5f805f60608486031215612d3a575f80fd5b8335612d4581612b26565b92506020840135612d5581612b26565b91506040840135612d6581612b26565b809150509250925092565b5f60208284031215612d80575f80fd5b815161278b81612b26565b634e487b7160e01b5f52603260045260245ffd5b634e487b7160e01b5f52601160045260245ffd5b808202811582820484141761144857611448612d9f565b5f60208284031215612dda575f80fd5b5051919050565b5f60ff821660ff8103612df657612df6612d9f565b60010192915050565b5f60018201612e1057612e10612d9f565b5060010190565b80518015158114610784575f80fd5b5f805f60608486031215612e38575f80fd5b8351925060208401519150612e4f60408501612e17565b90509250925092565b8082018082111561144857611448612d9f565b634e487b7160e01b5f52601260045260245ffd5b5f82612e8d57612e8d612e6b565b500490565b8181038181111561144857611448612d9f565b5f8085851115612eb3575f80fd5b83861115612ebf575f80fd5b5050820193919092039150565b6001600160e01b03198135818116916004851015612ef45780818660040360031b1b83161692505b505092915050565b6001600160a01b03841681526040602082018190528101829052818360608301375f818301606090810191909152601f909201601f1916010192915050565b5f82518060208501845e5f920191825250919050565b5f8060408385031215612f62575f80fd5b612f6b83612e17565b9150602083015163ffffffff81168114612b5d575f80fd5b5f60208284031215612f93575f80fd5b61278b82612e17565b5f82612faa57612faa612e6b565b50069056fef3177357ab46d8af007ab3fdb9af81da189e1068fefdc0073dca88a2cab40a00360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbca2646970667358221220d27cb72f85ee55a22c14eb8ff29e491de031712b6011498a7541b0ececc1d6f064736f6c63430008190033","source_code":"// SPDX-License-Identifier: BUSL-1.1\n\npragma solidity ^0.8.24;\n\nimport \"openzeppelin-contracts/contracts/token/ERC20/extensions/IERC20Metadata.sol\";\n\nimport \"./Interfaces/ITroveManager.sol\";\nimport \"./Interfaces/IBoldToken.sol\";\nimport \"./Quill/Interfaces/ISequencerSentinel.sol\";\nimport \"./Dependencies/Constants.sol\";\nimport \"./Dependencies/LiquityMath.sol\";\nimport {QuillUUPSUpgradeable} from \"./Quill/QuillUUPSUpgradeable.sol\";\n\nimport \"./Interfaces/ICollateralRegistry.sol\";\n\ncontract CollateralRegistry is QuillUUPSUpgradeable, ICollateralRegistry {\n    // See: https://github.com/ethereum/solidity/issues/12587\n    uint256 public totalCollaterals;\n\n    IERC20Metadata[] internal tokens;\n\n    ITroveManager[] internal troveManagers;\n\n    uint256[] internal tokenCaps;\n\n    IBoldToken public boldToken;\n    ISequencerSentinel sequencerSentinel;\n\n    uint256 public baseRate;\n\n    // The timestamp of the latest fee operation (redemption or new Bold issuance)\n    uint256 public lastFeeOperationTime;\n\n    event BaseRateUpdated(uint256 _baseRate);\n    event LastFeeOpTimeUpdated(uint256 _lastFeeOpTime);\n    event CollateralAdded(IERC20Metadata _token, ITroveManager _troveManager);\n    event BranchCapUpdated(uint256 _index, ITroveManager _troveManager, uint256 _maxCap);\n    event BranchShutdown(uint256 _index);\n\n    error InvalidIndex(uint256 index);\n    error InvalidCollateralList();\n    error NumberOfCollateralsExceeded();\n    error InvalidCollateral();\n    error InvalidTroveManagerAddresses();\n    error InvalidMaxCapUnder();\n\n    constructor() {\n        _disableInitializers();\n    }\n\n    function initialize(address _authority, IBoldToken _boldToken, ISequencerSentinel _sequencerSentinel)\n        public\n        initializer\n    {\n        __QuillUUPSUpgradeable_init(_authority);\n        lastFeeOperationTime = block.timestamp;\n        boldToken = _boldToken;\n        sequencerSentinel = _sequencerSentinel;\n\n        // Initialize the baseRate state variable\n        baseRate = INITIAL_BASE_RATE;\n        emit BaseRateUpdated(INITIAL_BASE_RATE);\n    }\n\n    struct RedemptionTotals {\n        uint256 numCollaterals;\n        uint256 boldSupplyAtStart;\n        uint256 unbacked;\n        uint256 redeemedAmount;\n    }\n\n    function redeemCollateral(uint256 _boldAmount, uint256 _maxIterationsPerCollateral, uint256 _maxFeePercentage)\n        external\n    {\n        _requireSequencerUpAndOverGracePeriod();\n        _requireValidMaxFeePercentage(_maxFeePercentage);\n        _requireAmountGreaterThanZero(_boldAmount);\n\n        RedemptionTotals memory totals;\n\n        totals.numCollaterals = totalCollaterals;\n        uint256[] memory unbackedPortions = new uint256[](totals.numCollaterals);\n        uint256[] memory prices = new uint256[](totals.numCollaterals);\n\n        // Gather and accumulate unbacked portions\n        for (uint256 index = 0; index < totals.numCollaterals; index++) {\n            ITroveManager troveManager = getTroveManager(index);\n            (uint256 unbackedPortion, uint256 price, bool redeemable) =\n                troveManager.getUnbackedPortionPriceAndRedeemability();\n            prices[index] = price;\n            if (redeemable) {\n                totals.unbacked += unbackedPortion;\n                unbackedPortions[index] = unbackedPortion;\n            }\n        }\n\n        // There’s an unlikely scenario where all the normally redeemable branches (i.e. having TCR > SCR) have 0 unbacked\n        // In that case, we redeem proportionally to branch size\n        if (totals.unbacked == 0) {\n            unbackedPortions = new uint256[](totals.numCollaterals);\n            for (uint256 index = 0; index < totals.numCollaterals; index++) {\n                ITroveManager troveManager = getTroveManager(index);\n                (,, bool redeemable) = troveManager.getUnbackedPortionPriceAndRedeemability();\n                if (redeemable) {\n                    uint256 unbackedPortion = troveManager.getEntireBranchDebt();\n                    totals.unbacked += unbackedPortion;\n                    unbackedPortions[index] = unbackedPortion;\n                }\n            }\n        } else {\n            // Don't allow redeeming more than the total unbacked in one go, as that would result in a disproportionate\n            // redemption (see CS-BOLD-013). Instead, truncate the redemption to total unbacked. If this happens, the\n            // redeemer can call `redeemCollateral()` a second time to redeem the remainder of their BOLD.\n            if (_boldAmount > totals.unbacked) {\n                _boldAmount = totals.unbacked;\n            }\n        }\n\n        totals.boldSupplyAtStart = boldToken.totalSupply();\n        // Decay the baseRate due to time passed, and then increase it according to the size of this redemption.\n        // Use the saved total Bold supply value, from before it was reduced by the redemption.\n        // We only compute it here, and update it at the end,\n        // because the final redeemed amount may be less than the requested amount\n        // Redeemers should take this into account in order to request the optimal amount to not overpay\n        uint256 redemptionRate =\n            _calcRedemptionRate(_getUpdatedBaseRateFromRedemption(_boldAmount, totals.boldSupplyAtStart));\n        require(redemptionRate <= _maxFeePercentage, \"CR: Fee exceeded provided maximum\");\n        // Implicit by the above and the _requireValidMaxFeePercentage checks\n        //require(newBaseRate < DECIMAL_PRECISION, \"CR: Fee would eat up all collateral\");\n\n        // Compute redemption amount for each collateral and redeem against the corresponding TroveManager\n        for (uint256 index = 0; index < totals.numCollaterals; index++) {\n            //uint256 unbackedPortion = unbackedPortions[index];\n            if (unbackedPortions[index] > 0) {\n                uint256 redeemAmount = _boldAmount * unbackedPortions[index] / totals.unbacked;\n                if (redeemAmount > 0) {\n                    ITroveManager troveManager = getTroveManager(index);\n                    uint256 redeemedAmount = troveManager.redeemCollateral(\n                        msg.sender, redeemAmount, prices[index], redemptionRate, _maxIterationsPerCollateral\n                    );\n                    totals.redeemedAmount += redeemedAmount;\n                }\n\n                // Ensure that per-branch redeems add up to `_boldAmount` exactly\n                _boldAmount -= redeemAmount;\n                totals.unbacked -= unbackedPortions[index];\n            }\n        }\n\n        _updateBaseRateAndGetRedemptionRate(totals.redeemedAmount, totals.boldSupplyAtStart);\n\n        // Burn the total Bold that is cancelled with debt\n        if (totals.redeemedAmount > 0) {\n            boldToken.burn(msg.sender, totals.redeemedAmount);\n        }\n    }\n\n    // --- Internal fee functions ---\n\n    // Update the last fee operation time only if time passed >= decay interval. This prevents base rate griefing.\n    function _updateLastFeeOpTime() internal {\n        uint256 minutesPassed = _minutesPassedSinceLastFeeOp();\n\n        if (minutesPassed > 0) {\n            lastFeeOperationTime += ONE_MINUTE * minutesPassed;\n            emit LastFeeOpTimeUpdated(lastFeeOperationTime);\n        }\n    }\n\n    function _minutesPassedSinceLastFeeOp() internal view returns (uint256) {\n        return (block.timestamp - lastFeeOperationTime) / ONE_MINUTE;\n    }\n\n    // Updates the `baseRate` state with math from `_getUpdatedBaseRateFromRedemption`\n    function _updateBaseRateAndGetRedemptionRate(uint256 _boldAmount, uint256 _totalBoldSupplyAtStart) internal {\n        uint256 newBaseRate = _getUpdatedBaseRateFromRedemption(_boldAmount, _totalBoldSupplyAtStart);\n\n        //assert(newBaseRate <= DECIMAL_PRECISION); // This is already enforced in `_getUpdatedBaseRateFromRedemption`\n\n        // Update the baseRate state variable\n        baseRate = newBaseRate;\n        emit BaseRateUpdated(newBaseRate);\n\n        _updateLastFeeOpTime();\n    }\n\n    /*\n     * This function calculates the new baseRate in the following way:\n     * 1) decays the baseRate based on time passed since last redemption or Bold borrowing operation.\n     * then,\n     * 2) increases the baseRate based on the amount redeemed, as a proportion of total supply\n     */\n    function _getUpdatedBaseRateFromRedemption(uint256 _redeemAmount, uint256 _totalBoldSupply)\n        internal\n        view\n        returns (uint256)\n    {\n        // decay the base rate\n        uint256 decayedBaseRate = _calcDecayedBaseRate();\n\n        // get the fraction of total supply that was redeemed\n        uint256 redeemedBoldFraction = _redeemAmount * DECIMAL_PRECISION / _totalBoldSupply;\n\n        uint256 newBaseRate = decayedBaseRate + redeemedBoldFraction / REDEMPTION_BETA;\n        newBaseRate = LiquityMath._min(newBaseRate, DECIMAL_PRECISION); // cap baseRate at a maximum of 100%\n\n        return newBaseRate;\n    }\n\n    function _calcDecayedBaseRate() internal view returns (uint256) {\n        uint256 minutesPassed = _minutesPassedSinceLastFeeOp();\n        uint256 decayFactor = LiquityMath._decPow(REDEMPTION_MINUTE_DECAY_FACTOR, minutesPassed);\n\n        return baseRate * decayFactor / DECIMAL_PRECISION;\n    }\n\n    function _calcRedemptionRate(uint256 _baseRate) internal pure returns (uint256) {\n        return LiquityMath._min(\n            REDEMPTION_FEE_FLOOR + _baseRate,\n            DECIMAL_PRECISION // cap at a maximum of 100%\n        );\n    }\n\n    function _calcRedemptionFee(uint256 _redemptionRate, uint256 _amount) internal pure returns (uint256) {\n        uint256 redemptionFee = _redemptionRate * _amount / DECIMAL_PRECISION;\n        return redemptionFee;\n    }\n\n    // external redemption rate/fee getters\n\n    function getRedemptionRate() external view override returns (uint256) {\n        return _calcRedemptionRate(baseRate);\n    }\n\n    function getRedemptionRateWithDecay() public view override returns (uint256) {\n        return _calcRedemptionRate(_calcDecayedBaseRate());\n    }\n\n    function getRedemptionRateForRedeemedAmount(uint256 _redeemAmount) external view returns (uint256) {\n        uint256 totalBoldSupply = boldToken.totalSupply();\n        uint256 newBaseRate = _getUpdatedBaseRateFromRedemption(_redeemAmount, totalBoldSupply);\n        return _calcRedemptionRate(newBaseRate);\n    }\n\n    function getRedemptionFeeWithDecay(uint256 _ETHDrawn) external view override returns (uint256) {\n        return _calcRedemptionFee(getRedemptionRateWithDecay(), _ETHDrawn);\n    }\n\n    function getEffectiveRedemptionFeeInBold(uint256 _redeemAmount) external view override returns (uint256) {\n        uint256 totalBoldSupply = boldToken.totalSupply();\n        uint256 newBaseRate = _getUpdatedBaseRateFromRedemption(_redeemAmount, totalBoldSupply);\n        return _calcRedemptionFee(_calcRedemptionRate(newBaseRate), _redeemAmount);\n    }\n\n    // getters\n\n    function getToken(uint256 _index) external view returns (IERC20Metadata) {\n        if (_index < totalCollaterals) return tokens[_index];\n        else revert InvalidIndex(_index);\n    }\n\n    function getTokenCap(uint256 _index) public view returns (uint256) {\n        if (_index < totalCollaterals) return tokenCaps[_index];\n        else revert InvalidIndex(_index);\n    }\n\n    function getTokenCapByAddress(address _troveManagerAddress) public view returns (uint256) {\n        for (uint256 i = 0; i < troveManagers.length; i++) {\n            if (address(troveManagers[i]) == _troveManagerAddress) {\n                return tokenCaps[i];\n            }\n        }\n\n        revert(\"CollateralRegistry: TroveManager not found\");\n    }\n\n    function getBranchCount() external view returns (uint256 branchCount) {\n        return troveManagers.length;\n    }\n\n    function getTroveManager(uint256 _index) public view returns (ITroveManager) {\n        if (_index < totalCollaterals) return troveManagers[_index];\n        else revert InvalidIndex(_index);\n    }\n\n    function getBorrowerOperations(uint256 _index) public view returns (IBorrowerOperations) {\n        return IBorrowerOperations(getTroveManager(_index).getBorrowerOperations());\n    }\n\n    // require functions\n\n    function _requireValidMaxFeePercentage(uint256 _maxFeePercentage) internal pure {\n        require(\n            _maxFeePercentage >= REDEMPTION_FEE_FLOOR && _maxFeePercentage <= DECIMAL_PRECISION,\n            \"Max fee percentage must be between 0.5% and 100%\"\n        );\n    }\n\n    function _requireAmountGreaterThanZero(uint256 _amount) internal pure {\n        require(_amount > 0, \"CollateralRegistry: Amount must be greater than zero\");\n    }\n\n    // Cuurently checks if sequencer is up and over a grace period\n    // If not, does not allow the current action (reverts)\n    function _requireSequencerUpAndOverGracePeriod() internal view {\n        sequencerSentinel.requireUpAndOverGracePeriod();\n    }\n\n    // Privileged functions\n    function addCollateral(IERC20Metadata _token, ITroveManager _troveManager, uint256 _maxCap) external restricted {\n        if (totalCollaterals == MAX_NUMBER_COLLATERALS) revert NumberOfCollateralsExceeded();\n        if (address(_token) == address(boldToken)) revert InvalidCollateral();\n        if (_maxCap < MINIMUM_MAX_CAP_PER_BRANCH) revert InvalidMaxCapUnder();\n\n        for (uint8 i = 0; i < troveManagers.length; i++) {\n            if (address(_troveManager) == address(troveManagers[i])) {\n                revert InvalidTroveManagerAddresses();\n            }\n        }\n\n        uint256 collIndex = tokens.length;\n        tokens.push(_token);\n        troveManagers.push(_troveManager);\n        tokenCaps.push(_maxCap);\n        totalCollaterals++;\n\n        boldToken.setBranchAddresses(\n            collIndex,\n            address(_token),\n            address(_troveManager),\n            address(_troveManager.stabilityPool()),\n            address(_troveManager.borrowerOperations()),\n            address(_troveManager.activePool())\n        );\n\n        emit CollateralAdded(_token, _troveManager);\n        emit BranchCapUpdated(collIndex, _troveManager, _maxCap);\n    }\n\n    function shutdownBranch(uint256 _index) external restricted {\n        getBorrowerOperations(_index).shutdownFromOracleFailureOrGovernance();\n        emit BranchShutdown(_index);\n    }\n\n    // TODO: add requirements to prevent misuse/ misconfiguration\n    // Issue URL: https://github.com/subvisual/quill/issues/110\n    // Stuff like:\n    // - Enforce SCR =< MCR < CCR after changes.\n    // also highly relevant: https://github.com/liquity/bold/issues/496\n    function setTroveCCR(uint256 _index, uint256 _newValue) external restricted {\n        ITroveManager troveManager = getTroveManager(_index);\n        troveManager.setNewBranchConfiguration(\n            troveManager.SCR(),\n            troveManager.MCR(),\n            _newValue,\n            troveManager.BCR(),\n            troveManager.liquidationPenaltySP(),\n            troveManager.liquidationPenaltyRedistribution(),\n            troveManager.minAnnualInterestRate()\n        );\n    }\n\n    function setTroveMCR(uint256 _index, uint256 _newValue) external restricted {\n        ITroveManager troveManager = getTroveManager(_index);\n        troveManager.setNewBranchConfiguration(\n            troveManager.SCR(),\n            _newValue,\n            troveManager.CCR(),\n            troveManager.BCR(),\n            troveManager.liquidationPenaltySP(),\n            troveManager.liquidationPenaltyRedistribution(),\n            troveManager.minAnnualInterestRate()\n        );\n    }\n\n    function setTroveSCR(uint256 _index, uint256 _newValue) external restricted {\n        ITroveManager troveManager = getTroveManager(_index);\n        troveManager.setNewBranchConfiguration(\n            _newValue,\n            troveManager.MCR(),\n            troveManager.CCR(),\n            troveManager.BCR(),\n            troveManager.liquidationPenaltySP(),\n            troveManager.liquidationPenaltyRedistribution(),\n            troveManager.minAnnualInterestRate()\n        );\n    }\n\n    function decreaseMinAnnualInterestRate(uint256 _index, uint256 _newValue) external restricted {\n        ITroveManager troveManager = getTroveManager(_index);\n        troveManager.setNewBranchConfiguration(\n            troveManager.SCR(),\n            troveManager.MCR(),\n            troveManager.CCR(),\n            troveManager.BCR(),\n            troveManager.liquidationPenaltySP(),\n            troveManager.liquidationPenaltyRedistribution(),\n            _newValue\n        );\n    }\n\n    function setSPYieldSplit(uint256 _index, uint256 _newValue) external restricted {\n        ITroveManager troveManager = getTroveManager(_index);\n        IActivePool activePool = troveManager.activePool();\n        activePool.mintAggInterest();\n        activePool.setSPYieldSplit(_newValue);\n    }\n\n    function setInterestRouter(uint256 _index, address _newInterestRouter) external restricted {\n        ITroveManager troveManager = getTroveManager(_index);\n        IActivePool activePool = troveManager.activePool();\n        activePool.setInterestRouter(_newInterestRouter);\n    }\n\n    function setTokenCap(uint256 _index, uint256 _newValue) external restricted {\n        if (_newValue < MINIMUM_MAX_CAP_PER_BRANCH) {\n            revert InvalidMaxCapUnder();\n        }\n        tokenCaps[_index] = _newValue;\n\n        emit BranchCapUpdated(_index, getTroveManager(_index), _newValue);\n    }\n}\n","creation_status":"success","file_path":"src/CollateralRegistry.sol"}