Source Code
| Transaction Hash |
|
Block
|
From
|
To
|
|||||
|---|---|---|---|---|---|---|---|---|---|
View more zero value Internal Transactions in Advanced View mode
Advanced mode:
Cross-Chain Transactions
Loading...
Loading
Contract Name:
VariableInterestRate
Compiler Version
v0.8.25+commit.b61c2a91
Optimization Enabled:
Yes with 1000 runs
Other Settings:
paris EvmVersion
Contract Source Code (Solidity Standard Json-Input format)
// SPDX-License-Identifier: ISC
pragma solidity ^0.8.19;
// ====================================================================
// | ______ _______ |
// | / _____________ __ __ / ____(_____ ____ _____ ________ |
// | / /_ / ___/ __ `| |/_/ / /_ / / __ \/ __ `/ __ \/ ___/ _ \ |
// | / __/ / / / /_/ _> < / __/ / / / / / /_/ / / / / /__/ __/ |
// | /_/ /_/ \__,_/_/|_| /_/ /_/_/ /_/\__,_/_/ /_/\___/\___/ |
// | |
// ====================================================================
// ====================== VariableInterestRate ========================
// ====================================================================
import { Strings } from "@openzeppelin/contracts/utils/Strings.sol";
import { IRateCalculatorV2 } from "./interfaces/IRateCalculatorV2.sol";
/// @title A formula for calculating interest rates as a function of utilization and time
/// @author Frax Finance (https://github.com/FraxFinance)
/// @notice A Contract for calculating interest rates as a function of utilization and time
contract VariableInterestRate is IRateCalculatorV2 {
using Strings for uint256;
/// @notice The name suffix for the interest rate calculator
string public suffix;
// Utilization Settings
/// @notice The minimum utilization wherein no adjustment to full utilization and vertex rates occurs
uint256 public immutable MIN_TARGET_UTIL;
/// @notice The maximum utilization wherein no adjustment to full utilization and vertex rates occurs
uint256 public immutable MAX_TARGET_UTIL;
/// @notice The utilization at which the slope increases
uint256 public immutable VERTEX_UTILIZATION;
/// @notice precision of utilization calculations
uint256 public constant UTIL_PREC = 1e5; // 5 decimals
// Interest Rate Settings (all rates are per second), 365.24 days per year
/// @notice The minimum interest rate (per second) when utilization is 100%
uint256 public immutable MIN_FULL_UTIL_RATE; // 18 decimals
/// @notice The maximum interest rate (per second) when utilization is 100%
uint256 public immutable MAX_FULL_UTIL_RATE; // 18 decimals
/// @notice The interest rate (per second) when utilization is 0%
uint256 public immutable ZERO_UTIL_RATE; // 18 decimals
/// @notice The interest rate half life in seconds, determines rate of adjustments to rate curve
uint256 public immutable RATE_HALF_LIFE; // 1 decimals
/// @notice The percent of the delta between max and min
uint256 public immutable VERTEX_RATE_PERCENT; // 18 decimals
/// @notice The precision of interest rate calculations
uint256 public constant RATE_PREC = 1e18; // 18 decimals
error MaxUtilizationTooLow();
error MaxFullUtilizationTooLow();
error DivideByZero();
error VertexUtilizationTooHigh();
error UtilizationRateTooHigh();
/// @param _suffix The suffix of the contract name
/// @param _vertexUtilization The utilization at which the slope increases
/// @param _vertexRatePercentOfDelta The percent of the delta between max and min, defines vertex rate
/// @param _minUtil The minimum utilization wherein no adjustment to full utilization and vertex rates occurs
/// @param _maxUtil The maximum utilization wherein no adjustment to full utilization and vertex rates occurs
/// @param _zeroUtilizationRate The interest rate (per second) when utilization is 0%
/// @param _minFullUtilizationRate The minimum interest rate at 100% utilization
/// @param _maxFullUtilizationRate The maximum interest rate at 100% utilization
/// @param _rateHalfLife The half life parameter for interest rate adjustments
constructor(
string memory _suffix,
uint256 _vertexUtilization,
uint256 _vertexRatePercentOfDelta,
uint256 _minUtil,
uint256 _maxUtil,
uint256 _zeroUtilizationRate,
uint256 _minFullUtilizationRate,
uint256 _maxFullUtilizationRate,
uint256 _rateHalfLife
) {
if (_maxUtil <= _minUtil) {
revert MaxUtilizationTooLow();
}
if (_maxFullUtilizationRate <= _minFullUtilizationRate) {
revert MaxFullUtilizationTooLow();
}
if (_vertexUtilization > UTIL_PREC) {
revert VertexUtilizationTooHigh();
}
if (
_minUtil == 0 ||
_rateHalfLife == 0 ||
_vertexUtilization == 0 ||
_vertexUtilization == UTIL_PREC ||
_maxUtil == UTIL_PREC
) {
revert DivideByZero();
}
if (_maxUtil > RATE_PREC || _maxFullUtilizationRate > RATE_PREC) {
revert UtilizationRateTooHigh();
}
suffix = _suffix;
MIN_TARGET_UTIL = _minUtil;
MAX_TARGET_UTIL = _maxUtil;
VERTEX_UTILIZATION = _vertexUtilization;
ZERO_UTIL_RATE = _zeroUtilizationRate;
MIN_FULL_UTIL_RATE = _minFullUtilizationRate;
MAX_FULL_UTIL_RATE = _maxFullUtilizationRate;
RATE_HALF_LIFE = _rateHalfLife;
VERTEX_RATE_PERCENT = _vertexRatePercentOfDelta;
}
/// @notice The ```name``` function returns the name of the rate contract
/// @return memory name of contract
function name() external view returns (string memory) {
return string(abi.encodePacked("Variable Rate V2 ", suffix));
}
/// @notice The ```version``` function returns the semantic version of the rate contract
/// @dev Follows semantic versioning
/// @return _major Major version
/// @return _minor Minor version
/// @return _patch Patch version
function version() external pure returns (uint256 _major, uint256 _minor, uint256 _patch) {
_major = 2;
_minor = 0;
_patch = 0;
}
/// @notice The ```getFullUtilizationInterest``` function calculate the new maximum interest rate, i.e. rate when utilization is 100%
/// @dev Given in interest per second
/// @param _deltaTime The elapsed time since last update given in seconds
/// @param _utilization The utilization %, given with 5 decimals of precision
/// @param _fullUtilizationInterest The interest value when utilization is 100%, given with 18 decimals of precision
/// @return _newFullUtilizationInterest The new maximum interest rate
function getFullUtilizationInterest(
uint256 _deltaTime,
uint256 _utilization,
uint64 _fullUtilizationInterest
) internal view returns (uint64 _newFullUtilizationInterest) {
if (_utilization < MIN_TARGET_UTIL) {
// 18 decimals
uint256 _deltaUtilization = ((MIN_TARGET_UTIL - _utilization) * 1e18) / MIN_TARGET_UTIL;
// 36 decimals
uint256 _decayGrowth = (RATE_HALF_LIFE * 1e36) + (_deltaUtilization * _deltaUtilization * _deltaTime);
// 18 decimals
_newFullUtilizationInterest = uint64((_fullUtilizationInterest * (RATE_HALF_LIFE * 1e36)) / _decayGrowth);
} else if (_utilization > MAX_TARGET_UTIL) {
// 18 decimals
uint256 _deltaUtilization = ((_utilization - MAX_TARGET_UTIL) * 1e18) / (UTIL_PREC - MAX_TARGET_UTIL);
// 36 decimals
uint256 _decayGrowth = (RATE_HALF_LIFE * 1e36) + (_deltaUtilization * _deltaUtilization * _deltaTime);
// 18 decimals
_newFullUtilizationInterest = uint64((_fullUtilizationInterest * _decayGrowth) / (RATE_HALF_LIFE * 1e36));
} else {
_newFullUtilizationInterest = _fullUtilizationInterest;
}
if (_newFullUtilizationInterest > MAX_FULL_UTIL_RATE) {
_newFullUtilizationInterest = uint64(MAX_FULL_UTIL_RATE);
} else if (_newFullUtilizationInterest < MIN_FULL_UTIL_RATE) {
_newFullUtilizationInterest = uint64(MIN_FULL_UTIL_RATE);
}
}
/// @notice The ```getNewRate``` function calculates interest rates using two linear functions f(utilization)
/// @param _deltaTime The elapsed time since last update, given in seconds
/// @param _utilization The utilization %, given with 5 decimals of precision
/// @param _oldFullUtilizationInterest The interest value when utilization is 100%, given with 18 decimals of precision
/// @return _newRatePerSec The new interest rate, 18 decimals of precision
/// @return _newFullUtilizationInterest The new max interest rate, 18 decimals of precision
function getNewRate(
uint256 _deltaTime,
uint256 _utilization,
uint64 _oldFullUtilizationInterest
) external view returns (uint64 _newRatePerSec, uint64 _newFullUtilizationInterest) {
_newFullUtilizationInterest = getFullUtilizationInterest(_deltaTime, _utilization, _oldFullUtilizationInterest);
// _vertexInterest is calculated as the percentage of the delta between min and max interest
uint256 _vertexInterest = (((_newFullUtilizationInterest - ZERO_UTIL_RATE) * VERTEX_RATE_PERCENT) / RATE_PREC) +
ZERO_UTIL_RATE;
if (_utilization < VERTEX_UTILIZATION) {
// For readability, the following formula is equivalent to:
// uint256 _slope = ((_vertexInterest - ZERO_UTIL_RATE) * UTIL_PREC) / VERTEX_UTILIZATION;
// _newRatePerSec = uint64(ZERO_UTIL_RATE + ((_utilization * _slope) / UTIL_PREC));
// 18 decimals
_newRatePerSec = uint64(
ZERO_UTIL_RATE + (_utilization * (_vertexInterest - ZERO_UTIL_RATE)) / VERTEX_UTILIZATION
);
} else {
// For readability, the following formula is equivalent to:
// uint256 _slope = (((_newFullUtilizationInterest - _vertexInterest) * UTIL_PREC) / (UTIL_PREC - VERTEX_UTILIZATION));
// _newRatePerSec = uint64(_vertexInterest + (((_utilization - VERTEX_UTILIZATION) * _slope) / UTIL_PREC));
// 18 decimals
_newRatePerSec = uint64(
_vertexInterest +
((_utilization - VERTEX_UTILIZATION) * (_newFullUtilizationInterest - _vertexInterest)) /
(UTIL_PREC - VERTEX_UTILIZATION)
);
}
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/Strings.sol)
pragma solidity ^0.8.20;
import {Math} from "./math/Math.sol";
import {SignedMath} from "./math/SignedMath.sol";
/**
* @dev String operations.
*/
library Strings {
bytes16 private constant HEX_DIGITS = "0123456789abcdef";
uint8 private constant ADDRESS_LENGTH = 20;
/**
* @dev The `value` string doesn't fit in the specified `length`.
*/
error StringsInsufficientHexLength(uint256 value, uint256 length);
/**
* @dev Converts a `uint256` to its ASCII `string` decimal representation.
*/
function toString(uint256 value) internal pure returns (string memory) {
unchecked {
uint256 length = Math.log10(value) + 1;
string memory buffer = new string(length);
uint256 ptr;
/// @solidity memory-safe-assembly
assembly {
ptr := add(buffer, add(32, length))
}
while (true) {
ptr--;
/// @solidity memory-safe-assembly
assembly {
mstore8(ptr, byte(mod(value, 10), HEX_DIGITS))
}
value /= 10;
if (value == 0) break;
}
return buffer;
}
}
/**
* @dev Converts a `int256` to its ASCII `string` decimal representation.
*/
function toStringSigned(int256 value) internal pure returns (string memory) {
return string.concat(value < 0 ? "-" : "", toString(SignedMath.abs(value)));
}
/**
* @dev Converts a `uint256` to its ASCII `string` hexadecimal representation.
*/
function toHexString(uint256 value) internal pure returns (string memory) {
unchecked {
return toHexString(value, Math.log256(value) + 1);
}
}
/**
* @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length.
*/
function toHexString(uint256 value, uint256 length) internal pure returns (string memory) {
uint256 localValue = value;
bytes memory buffer = new bytes(2 * length + 2);
buffer[0] = "0";
buffer[1] = "x";
for (uint256 i = 2 * length + 1; i > 1; --i) {
buffer[i] = HEX_DIGITS[localValue & 0xf];
localValue >>= 4;
}
if (localValue != 0) {
revert StringsInsufficientHexLength(value, length);
}
return string(buffer);
}
/**
* @dev Converts an `address` with fixed length of 20 bytes to its not checksummed ASCII `string` hexadecimal
* representation.
*/
function toHexString(address addr) internal pure returns (string memory) {
return toHexString(uint256(uint160(addr)), ADDRESS_LENGTH);
}
/**
* @dev Returns true if the two strings are equal.
*/
function equal(string memory a, string memory b) internal pure returns (bool) {
return bytes(a).length == bytes(b).length && keccak256(bytes(a)) == keccak256(bytes(b));
}
}// SPDX-License-Identifier: ISC
pragma solidity ^0.8.19;
interface IRateCalculatorV2 {
function name() external view returns (string memory);
function version() external view returns (uint256, uint256, uint256);
function getNewRate(
uint256 _deltaTime,
uint256 _utilization,
uint64 _maxInterest
) external view returns (uint64 _newRatePerSec, uint64 _newMaxInterest);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/math/Math.sol)
pragma solidity ^0.8.20;
/**
* @dev Standard math utilities missing in the Solidity language.
*/
library Math {
/**
* @dev Muldiv operation overflow.
*/
error MathOverflowedMulDiv();
enum Rounding {
Floor, // Toward negative infinity
Ceil, // Toward positive infinity
Trunc, // Toward zero
Expand // Away from zero
}
/**
* @dev Returns the addition of two unsigned integers, with an overflow flag.
*/
function tryAdd(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
uint256 c = a + b;
if (c < a) return (false, 0);
return (true, c);
}
}
/**
* @dev Returns the subtraction of two unsigned integers, with an overflow flag.
*/
function trySub(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
if (b > a) return (false, 0);
return (true, a - b);
}
}
/**
* @dev Returns the multiplication of two unsigned integers, with an overflow flag.
*/
function tryMul(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
// Gas optimization: this is cheaper than requiring 'a' not being zero, but the
// benefit is lost if 'b' is also tested.
// See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522
if (a == 0) return (true, 0);
uint256 c = a * b;
if (c / a != b) return (false, 0);
return (true, c);
}
}
/**
* @dev Returns the division of two unsigned integers, with a division by zero flag.
*/
function tryDiv(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
if (b == 0) return (false, 0);
return (true, a / b);
}
}
/**
* @dev Returns the remainder of dividing two unsigned integers, with a division by zero flag.
*/
function tryMod(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
if (b == 0) return (false, 0);
return (true, a % b);
}
}
/**
* @dev Returns the largest of two numbers.
*/
function max(uint256 a, uint256 b) internal pure returns (uint256) {
return a > b ? a : b;
}
/**
* @dev Returns the smallest of two numbers.
*/
function min(uint256 a, uint256 b) internal pure returns (uint256) {
return a < b ? a : b;
}
/**
* @dev Returns the average of two numbers. The result is rounded towards
* zero.
*/
function average(uint256 a, uint256 b) internal pure returns (uint256) {
// (a + b) / 2 can overflow.
return (a & b) + (a ^ b) / 2;
}
/**
* @dev Returns the ceiling of the division of two numbers.
*
* This differs from standard division with `/` in that it rounds towards infinity instead
* of rounding towards zero.
*/
function ceilDiv(uint256 a, uint256 b) internal pure returns (uint256) {
if (b == 0) {
// Guarantee the same behavior as in a regular Solidity division.
return a / b;
}
// (a + b - 1) / b can overflow on addition, so we distribute.
return a == 0 ? 0 : (a - 1) / b + 1;
}
/**
* @notice Calculates floor(x * y / denominator) with full precision. Throws if result overflows a uint256 or
* denominator == 0.
* @dev Original credit to Remco Bloemen under MIT license (https://xn--2-umb.com/21/muldiv) with further edits by
* Uniswap Labs also under MIT license.
*/
function mulDiv(uint256 x, uint256 y, uint256 denominator) internal pure returns (uint256 result) {
unchecked {
// 512-bit multiply [prod1 prod0] = x * y. Compute the product mod 2^256 and mod 2^256 - 1, then use
// use the Chinese Remainder Theorem to reconstruct the 512 bit result. The result is stored in two 256
// variables such that product = prod1 * 2^256 + prod0.
uint256 prod0 = x * y; // Least significant 256 bits of the product
uint256 prod1; // Most significant 256 bits of the product
assembly {
let mm := mulmod(x, y, not(0))
prod1 := sub(sub(mm, prod0), lt(mm, prod0))
}
// Handle non-overflow cases, 256 by 256 division.
if (prod1 == 0) {
// Solidity will revert if denominator == 0, unlike the div opcode on its own.
// The surrounding unchecked block does not change this fact.
// See https://docs.soliditylang.org/en/latest/control-structures.html#checked-or-unchecked-arithmetic.
return prod0 / denominator;
}
// Make sure the result is less than 2^256. Also prevents denominator == 0.
if (denominator <= prod1) {
revert MathOverflowedMulDiv();
}
///////////////////////////////////////////////
// 512 by 256 division.
///////////////////////////////////////////////
// Make division exact by subtracting the remainder from [prod1 prod0].
uint256 remainder;
assembly {
// Compute remainder using mulmod.
remainder := mulmod(x, y, denominator)
// Subtract 256 bit number from 512 bit number.
prod1 := sub(prod1, gt(remainder, prod0))
prod0 := sub(prod0, remainder)
}
// Factor powers of two out of denominator and compute largest power of two divisor of denominator.
// Always >= 1. See https://cs.stackexchange.com/q/138556/92363.
uint256 twos = denominator & (0 - denominator);
assembly {
// Divide denominator by twos.
denominator := div(denominator, twos)
// Divide [prod1 prod0] by twos.
prod0 := div(prod0, twos)
// Flip twos such that it is 2^256 / twos. If twos is zero, then it becomes one.
twos := add(div(sub(0, twos), twos), 1)
}
// Shift in bits from prod1 into prod0.
prod0 |= prod1 * twos;
// Invert denominator mod 2^256. Now that denominator is an odd number, it has an inverse modulo 2^256 such
// that denominator * inv = 1 mod 2^256. Compute the inverse by starting with a seed that is correct for
// four bits. That is, denominator * inv = 1 mod 2^4.
uint256 inverse = (3 * denominator) ^ 2;
// Use the Newton-Raphson iteration to improve the precision. Thanks to Hensel's lifting lemma, this also
// works in modular arithmetic, doubling the correct bits in each step.
inverse *= 2 - denominator * inverse; // inverse mod 2^8
inverse *= 2 - denominator * inverse; // inverse mod 2^16
inverse *= 2 - denominator * inverse; // inverse mod 2^32
inverse *= 2 - denominator * inverse; // inverse mod 2^64
inverse *= 2 - denominator * inverse; // inverse mod 2^128
inverse *= 2 - denominator * inverse; // inverse mod 2^256
// Because the division is now exact we can divide by multiplying with the modular inverse of denominator.
// This will give us the correct result modulo 2^256. Since the preconditions guarantee that the outcome is
// less than 2^256, this is the final result. We don't need to compute the high bits of the result and prod1
// is no longer required.
result = prod0 * inverse;
return result;
}
}
/**
* @notice Calculates x * y / denominator with full precision, following the selected rounding direction.
*/
function mulDiv(uint256 x, uint256 y, uint256 denominator, Rounding rounding) internal pure returns (uint256) {
uint256 result = mulDiv(x, y, denominator);
if (unsignedRoundsUp(rounding) && mulmod(x, y, denominator) > 0) {
result += 1;
}
return result;
}
/**
* @dev Returns the square root of a number. If the number is not a perfect square, the value is rounded
* towards zero.
*
* Inspired by Henry S. Warren, Jr.'s "Hacker's Delight" (Chapter 11).
*/
function sqrt(uint256 a) internal pure returns (uint256) {
if (a == 0) {
return 0;
}
// For our first guess, we get the biggest power of 2 which is smaller than the square root of the target.
//
// We know that the "msb" (most significant bit) of our target number `a` is a power of 2 such that we have
// `msb(a) <= a < 2*msb(a)`. This value can be written `msb(a)=2**k` with `k=log2(a)`.
//
// This can be rewritten `2**log2(a) <= a < 2**(log2(a) + 1)`
// → `sqrt(2**k) <= sqrt(a) < sqrt(2**(k+1))`
// → `2**(k/2) <= sqrt(a) < 2**((k+1)/2) <= 2**(k/2 + 1)`
//
// Consequently, `2**(log2(a) / 2)` is a good first approximation of `sqrt(a)` with at least 1 correct bit.
uint256 result = 1 << (log2(a) >> 1);
// At this point `result` is an estimation with one bit of precision. We know the true value is a uint128,
// since it is the square root of a uint256. Newton's method converges quadratically (precision doubles at
// every iteration). We thus need at most 7 iteration to turn our partial result with one bit of precision
// into the expected uint128 result.
unchecked {
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
return min(result, a / result);
}
}
/**
* @notice Calculates sqrt(a), following the selected rounding direction.
*/
function sqrt(uint256 a, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = sqrt(a);
return result + (unsignedRoundsUp(rounding) && result * result < a ? 1 : 0);
}
}
/**
* @dev Return the log in base 2 of a positive value rounded towards zero.
* Returns 0 if given 0.
*/
function log2(uint256 value) internal pure returns (uint256) {
uint256 result = 0;
unchecked {
if (value >> 128 > 0) {
value >>= 128;
result += 128;
}
if (value >> 64 > 0) {
value >>= 64;
result += 64;
}
if (value >> 32 > 0) {
value >>= 32;
result += 32;
}
if (value >> 16 > 0) {
value >>= 16;
result += 16;
}
if (value >> 8 > 0) {
value >>= 8;
result += 8;
}
if (value >> 4 > 0) {
value >>= 4;
result += 4;
}
if (value >> 2 > 0) {
value >>= 2;
result += 2;
}
if (value >> 1 > 0) {
result += 1;
}
}
return result;
}
/**
* @dev Return the log in base 2, following the selected rounding direction, of a positive value.
* Returns 0 if given 0.
*/
function log2(uint256 value, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = log2(value);
return result + (unsignedRoundsUp(rounding) && 1 << result < value ? 1 : 0);
}
}
/**
* @dev Return the log in base 10 of a positive value rounded towards zero.
* Returns 0 if given 0.
*/
function log10(uint256 value) internal pure returns (uint256) {
uint256 result = 0;
unchecked {
if (value >= 10 ** 64) {
value /= 10 ** 64;
result += 64;
}
if (value >= 10 ** 32) {
value /= 10 ** 32;
result += 32;
}
if (value >= 10 ** 16) {
value /= 10 ** 16;
result += 16;
}
if (value >= 10 ** 8) {
value /= 10 ** 8;
result += 8;
}
if (value >= 10 ** 4) {
value /= 10 ** 4;
result += 4;
}
if (value >= 10 ** 2) {
value /= 10 ** 2;
result += 2;
}
if (value >= 10 ** 1) {
result += 1;
}
}
return result;
}
/**
* @dev Return the log in base 10, following the selected rounding direction, of a positive value.
* Returns 0 if given 0.
*/
function log10(uint256 value, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = log10(value);
return result + (unsignedRoundsUp(rounding) && 10 ** result < value ? 1 : 0);
}
}
/**
* @dev Return the log in base 256 of a positive value rounded towards zero.
* Returns 0 if given 0.
*
* Adding one to the result gives the number of pairs of hex symbols needed to represent `value` as a hex string.
*/
function log256(uint256 value) internal pure returns (uint256) {
uint256 result = 0;
unchecked {
if (value >> 128 > 0) {
value >>= 128;
result += 16;
}
if (value >> 64 > 0) {
value >>= 64;
result += 8;
}
if (value >> 32 > 0) {
value >>= 32;
result += 4;
}
if (value >> 16 > 0) {
value >>= 16;
result += 2;
}
if (value >> 8 > 0) {
result += 1;
}
}
return result;
}
/**
* @dev Return the log in base 256, following the selected rounding direction, of a positive value.
* Returns 0 if given 0.
*/
function log256(uint256 value, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = log256(value);
return result + (unsignedRoundsUp(rounding) && 1 << (result << 3) < value ? 1 : 0);
}
}
/**
* @dev Returns whether a provided rounding mode is considered rounding up for unsigned integers.
*/
function unsignedRoundsUp(Rounding rounding) internal pure returns (bool) {
return uint8(rounding) % 2 == 1;
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/math/SignedMath.sol)
pragma solidity ^0.8.20;
/**
* @dev Standard signed math utilities missing in the Solidity language.
*/
library SignedMath {
/**
* @dev Returns the largest of two signed numbers.
*/
function max(int256 a, int256 b) internal pure returns (int256) {
return a > b ? a : b;
}
/**
* @dev Returns the smallest of two signed numbers.
*/
function min(int256 a, int256 b) internal pure returns (int256) {
return a < b ? a : b;
}
/**
* @dev Returns the average of two signed numbers without overflow.
* The result is rounded towards zero.
*/
function average(int256 a, int256 b) internal pure returns (int256) {
// Formula from the book "Hacker's Delight"
int256 x = (a & b) + ((a ^ b) >> 1);
return x + (int256(uint256(x) >> 255) & (a ^ b));
}
/**
* @dev Returns the absolute unsigned value of a signed value.
*/
function abs(int256 n) internal pure returns (uint256) {
unchecked {
// must be unchecked in order to support `n = type(int256).min`
return uint256(n >= 0 ? n : -n);
}
}
}{
"remappings": [
"frax-std/=node_modules/frax-standard-solidity/src/",
"@prb/test/=node_modules/@prb/test/",
"forge-std/=node_modules/forge-std/src/",
"ds-test/=node_modules/ds-test/src/",
"@openzeppelin/=node_modules/@openzeppelin/",
"@rari-capital/=node_modules/@rari-capital/",
"@uniswap/=node_modules/@uniswap/",
"dev-fraxswap/=node_modules/dev-fraxswap/",
"frax-standard-solidity/=node_modules/frax-standard-solidity/",
"solidity-bytes-utils/=node_modules/solidity-bytes-utils/"
],
"optimizer": {
"enabled": true,
"runs": 1000
},
"metadata": {
"useLiteralContent": false,
"bytecodeHash": "none",
"appendCBOR": false
},
"outputSelection": {
"*": {
"*": [
"evm.bytecode",
"evm.deployedBytecode",
"devdoc",
"userdoc",
"metadata",
"abi"
]
}
},
"evmVersion": "paris",
"viaIR": false,
"libraries": {}
}Contract Security Audit
- No Contract Security Audit Submitted- Submit Audit Here
Contract ABI
API[{"inputs":[{"internalType":"string","name":"_suffix","type":"string"},{"internalType":"uint256","name":"_vertexUtilization","type":"uint256"},{"internalType":"uint256","name":"_vertexRatePercentOfDelta","type":"uint256"},{"internalType":"uint256","name":"_minUtil","type":"uint256"},{"internalType":"uint256","name":"_maxUtil","type":"uint256"},{"internalType":"uint256","name":"_zeroUtilizationRate","type":"uint256"},{"internalType":"uint256","name":"_minFullUtilizationRate","type":"uint256"},{"internalType":"uint256","name":"_maxFullUtilizationRate","type":"uint256"},{"internalType":"uint256","name":"_rateHalfLife","type":"uint256"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[],"name":"DivideByZero","type":"error"},{"inputs":[],"name":"MaxFullUtilizationTooLow","type":"error"},{"inputs":[],"name":"MaxUtilizationTooLow","type":"error"},{"inputs":[],"name":"UtilizationRateTooHigh","type":"error"},{"inputs":[],"name":"VertexUtilizationTooHigh","type":"error"},{"inputs":[],"name":"MAX_FULL_UTIL_RATE","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"MAX_TARGET_UTIL","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"MIN_FULL_UTIL_RATE","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"MIN_TARGET_UTIL","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"RATE_HALF_LIFE","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"RATE_PREC","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"UTIL_PREC","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"VERTEX_RATE_PERCENT","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"VERTEX_UTILIZATION","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"ZERO_UTIL_RATE","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_deltaTime","type":"uint256"},{"internalType":"uint256","name":"_utilization","type":"uint256"},{"internalType":"uint64","name":"_oldFullUtilizationInterest","type":"uint64"}],"name":"getNewRate","outputs":[{"internalType":"uint64","name":"_newRatePerSec","type":"uint64"},{"internalType":"uint64","name":"_newFullUtilizationInterest","type":"uint64"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"name","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"suffix","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"version","outputs":[{"internalType":"uint256","name":"_major","type":"uint256"},{"internalType":"uint256","name":"_minor","type":"uint256"},{"internalType":"uint256","name":"_patch","type":"uint256"}],"stateMutability":"pure","type":"function"}]Contract Creation Code
61018060405234801561001157600080fd5b50604051610f70380380610f7083398101604081905261003091610172565b858511610050576040516356a3535960e11b815260040160405180910390fd5b82821161007057604051631c3c204560e11b815260040160405180910390fd5b620186a088111561009457604051631173807760e31b815260040160405180910390fd5b85158061009f575080155b806100a8575087155b806100b55750620186a088145b806100c25750620186a085145b156100e0576040516301de42a960e41b815260040160405180910390fd5b670de0b6b3a76400008511806100fd5750670de0b6b3a764000082115b1561011b576040516369fb55ab60e11b815260040160405180910390fd5b60006101278a82610314565b5060809590955260a09390935260c0959095526101205260e093909352610100929092526101409190915261016052506103d3565b634e487b7160e01b600052604160045260246000fd5b60008060008060008060008060006101208a8c03121561019157600080fd5b89516001600160401b03808211156101a857600080fd5b818c0191508c601f8301126101bc57600080fd5b8151818111156101ce576101ce61015c565b604051601f8201601f19908116603f011681019083821181831017156101f6576101f661015c565b81604052828152602093508f8484870101111561021257600080fd5b600091505b828210156102345784820184015181830185015290830190610217565b6000848483010152809d50505050808c01519950505060408a0151965060608a0151955060808a0151945060a08a0151935060c08a0151925060e08a015191506101008a015190509295985092959850929598565b600181811c9082168061029d57607f821691505b6020821081036102bd57634e487b7160e01b600052602260045260246000fd5b50919050565b601f82111561030f576000816000526020600020601f850160051c810160208610156102ec5750805b601f850160051c820191505b8181101561030b578281556001016102f8565b5050505b505050565b81516001600160401b0381111561032d5761032d61015c565b6103418161033b8454610289565b846102c3565b602080601f831160018114610376576000841561035e5750858301515b600019600386901b1c1916600185901b17855561030b565b600085815260208120601f198616915b828110156103a557888601518255948401946001909101908401610386565b50858210156103c35787850151600019600388901b60f8161c191681555b5050505050600190811b01905550565b60805160a05160c05160e05161010051610120516101405161016051610aa66104ca600039600081816102170152610329015260008181610142015281816105e80152818161062e0152818161074401526107890152600081816101e1015281816102ff015281816103ca015261040901526000818160f3015281816107d601526108090152600081816101690152818161082f01526108620152600081816102650152818161037e015281816103a601528181610439015261047a0152600081816101900152818161068b015281816106b801526106e501526000818161023e0152818161055b01526105850152610aa66000f3fe608060405234801561001057600080fd5b50600436106100e95760003560e01c80638e75618c1161008c5780639c073270116100665780639c07327014610239578063c416812514610260578063cd3181d514610287578063f7073c3a146102bb57600080fd5b80638e75618c146101dc57806391474c491461020357806395da99fc1461021257600080fd5b806331bf879d116100c857806331bf879d1461016457806340797eda1461018b57806354fd4d50146101b25780636cd3cc77146101d257600080fd5b80624c98af146100ee57806306fdde031461012857806317784ca41461013d575b600080fd5b6101157f000000000000000000000000000000000000000000000000000000000000000081565b6040519081526020015b60405180910390f35b6101306102c3565b60405161011f9190610889565b6101157f000000000000000000000000000000000000000000000000000000000000000081565b6101157f000000000000000000000000000000000000000000000000000000000000000081565b6101157f000000000000000000000000000000000000000000000000000000000000000081565b60026000806040805193845260208401929092529082015260600161011f565b610115620186a081565b6101157f000000000000000000000000000000000000000000000000000000000000000081565b610115670de0b6b3a764000081565b6101157f000000000000000000000000000000000000000000000000000000000000000081565b6101157f000000000000000000000000000000000000000000000000000000000000000081565b6101157f000000000000000000000000000000000000000000000000000000000000000081565b61029a6102953660046108d8565b6102eb565b6040805167ffffffffffffffff93841681529290911660208301520161011f565b6101306104c9565b606060006040516020016102d79190610958565b604051602081830303815290604052905090565b6000806102f9858585610557565b905060007f0000000000000000000000000000000000000000000000000000000000000000670de0b6b3a76400007f000000000000000000000000000000000000000000000000000000000000000061035c8367ffffffffffffffff8716610a41565b6103669190610a5a565b6103709190610a71565b61037a9190610a93565b90507f0000000000000000000000000000000000000000000000000000000000000000851015610434577f00000000000000000000000000000000000000000000000000000000000000006103ef7f000000000000000000000000000000000000000000000000000000000000000083610a41565b6103f99087610a5a565b6104039190610a71565b61042d907f0000000000000000000000000000000000000000000000000000000000000000610a93565b92506104c0565b6104617f0000000000000000000000000000000000000000000000000000000000000000620186a0610a41565b6104758267ffffffffffffffff8516610a41565b61049f7f000000000000000000000000000000000000000000000000000000000000000088610a41565b6104a99190610a5a565b6104b39190610a71565b6104bd9082610a93565b92505b50935093915050565b600080546104d69061091e565b80601f01602080910402602001604051908101604052809291908181526020018280546105029061091e565b801561054f5780601f106105245761010080835404028352916020019161054f565b820191906000526020600020905b81548152906001019060200180831161053257829003601f168201915b505050505081565b60007f00000000000000000000000000000000000000000000000000000000000000008310156106895760007f00000000000000000000000000000000000000000000000000000000000000006105ae8582610a41565b6105c090670de0b6b3a7640000610a5a565b6105ca9190610a71565b90506000856105d98380610a5a565b6105e39190610a5a565b61061c7f00000000000000000000000000000000000000000000000000000000000000006ec097ce7bc90715b34b9f1000000000610a5a565b6106269190610a93565b9050806106627f00000000000000000000000000000000000000000000000000000000000000006ec097ce7bc90715b34b9f1000000000610a5a565b6106769067ffffffffffffffff8716610a5a565b6106809190610a71565b925050506107d4565b7f00000000000000000000000000000000000000000000000000000000000000008311156107d15760006106e07f0000000000000000000000000000000000000000000000000000000000000000620186a0610a41565b61070a7f000000000000000000000000000000000000000000000000000000000000000086610a41565b61071c90670de0b6b3a7640000610a5a565b6107269190610a71565b90506000856107358380610a5a565b61073f9190610a5a565b6107787f00000000000000000000000000000000000000000000000000000000000000006ec097ce7bc90715b34b9f1000000000610a5a565b6107829190610a93565b90506107bd7f00000000000000000000000000000000000000000000000000000000000000006ec097ce7bc90715b34b9f1000000000610a5a565b6106768267ffffffffffffffff8716610a5a565b50805b7f00000000000000000000000000000000000000000000000000000000000000008167ffffffffffffffff16111561082d57507f0000000000000000000000000000000000000000000000000000000000000000610882565b7f00000000000000000000000000000000000000000000000000000000000000008167ffffffffffffffff16101561088257507f00000000000000000000000000000000000000000000000000000000000000005b9392505050565b60006020808352835180602085015260005b818110156108b75785810183015185820160400152820161089b565b506000604082860101526040601f19601f8301168501019250505092915050565b6000806000606084860312156108ed57600080fd5b8335925060208401359150604084013567ffffffffffffffff8116811461091357600080fd5b809150509250925092565b600181811c9082168061093257607f821691505b60208210810361095257634e487b7160e01b600052602260045260246000fd5b50919050565b7f5661726961626c65205261746520563220000000000000000000000000000000815260006011600084548160018260011c9150600183168061099c57607f831692505b602080841082036109bb57634e487b7160e01b86526022600452602486fd5b8180156109cf57600181146109ea57610a1c565b60ff19861660118b0152601185151586028b01019650610a1c565b60008b81526020902060005b86811015610a115781548c82018b01529085019083016109f6565b50506011858b010196505b50949998505050505050505050565b634e487b7160e01b600052601160045260246000fd5b81810381811115610a5457610a54610a2b565b92915050565b8082028115828204841417610a5457610a54610a2b565b600082610a8e57634e487b7160e01b600052601260045260246000fd5b500490565b80820180821115610a5457610a54610a2b560000000000000000000000000000000000000000000000000000000000000120000000000000000000000000000000000000000000000000000000000001117000000000000000000000000000000000000000000000000006f05b59d3b200000000000000000000000000000000000000000000000000000000000000011b3400000000000000000000000000000000000000000000000000000000000142440000000000000000000000000000000000000000000000000000000012dd510c000000000000000000000000000000000000000000000000000000011af7bfb400000000000000000000000000000000000000000000000000000035cb191c38000000000000000000000000000000000000000000000000000000000002a300000000000000000000000000000000000000000000000000000000000000002242616d6d205b2e31352d372e33305d2032206461797320282e3732352d2e38323529000000000000000000000000000000000000000000000000000000000000
Deployed Bytecode
0x608060405234801561001057600080fd5b50600436106100e95760003560e01c80638e75618c1161008c5780639c073270116100665780639c07327014610239578063c416812514610260578063cd3181d514610287578063f7073c3a146102bb57600080fd5b80638e75618c146101dc57806391474c491461020357806395da99fc1461021257600080fd5b806331bf879d116100c857806331bf879d1461016457806340797eda1461018b57806354fd4d50146101b25780636cd3cc77146101d257600080fd5b80624c98af146100ee57806306fdde031461012857806317784ca41461013d575b600080fd5b6101157f00000000000000000000000000000000000000000000000000000035cb191c3881565b6040519081526020015b60405180910390f35b6101306102c3565b60405161011f9190610889565b6101157f000000000000000000000000000000000000000000000000000000000002a30081565b6101157f000000000000000000000000000000000000000000000000000000011af7bfb481565b6101157f000000000000000000000000000000000000000000000000000000000001424481565b60026000806040805193845260208401929092529082015260600161011f565b610115620186a081565b6101157f0000000000000000000000000000000000000000000000000000000012dd510c81565b610115670de0b6b3a764000081565b6101157f00000000000000000000000000000000000000000000000006f05b59d3b2000081565b6101157f0000000000000000000000000000000000000000000000000000000000011b3481565b6101157f000000000000000000000000000000000000000000000000000000000001117081565b61029a6102953660046108d8565b6102eb565b6040805167ffffffffffffffff93841681529290911660208301520161011f565b6101306104c9565b606060006040516020016102d79190610958565b604051602081830303815290604052905090565b6000806102f9858585610557565b905060007f0000000000000000000000000000000000000000000000000000000012dd510c670de0b6b3a76400007f00000000000000000000000000000000000000000000000006f05b59d3b2000061035c8367ffffffffffffffff8716610a41565b6103669190610a5a565b6103709190610a71565b61037a9190610a93565b90507f0000000000000000000000000000000000000000000000000000000000011170851015610434577f00000000000000000000000000000000000000000000000000000000000111706103ef7f0000000000000000000000000000000000000000000000000000000012dd510c83610a41565b6103f99087610a5a565b6104039190610a71565b61042d907f0000000000000000000000000000000000000000000000000000000012dd510c610a93565b92506104c0565b6104617f0000000000000000000000000000000000000000000000000000000000011170620186a0610a41565b6104758267ffffffffffffffff8516610a41565b61049f7f000000000000000000000000000000000000000000000000000000000001117088610a41565b6104a99190610a5a565b6104b39190610a71565b6104bd9082610a93565b92505b50935093915050565b600080546104d69061091e565b80601f01602080910402602001604051908101604052809291908181526020018280546105029061091e565b801561054f5780601f106105245761010080835404028352916020019161054f565b820191906000526020600020905b81548152906001019060200180831161053257829003601f168201915b505050505081565b60007f0000000000000000000000000000000000000000000000000000000000011b348310156106895760007f0000000000000000000000000000000000000000000000000000000000011b346105ae8582610a41565b6105c090670de0b6b3a7640000610a5a565b6105ca9190610a71565b90506000856105d98380610a5a565b6105e39190610a5a565b61061c7f000000000000000000000000000000000000000000000000000000000002a3006ec097ce7bc90715b34b9f1000000000610a5a565b6106269190610a93565b9050806106627f000000000000000000000000000000000000000000000000000000000002a3006ec097ce7bc90715b34b9f1000000000610a5a565b6106769067ffffffffffffffff8716610a5a565b6106809190610a71565b925050506107d4565b7f00000000000000000000000000000000000000000000000000000000000142448311156107d15760006106e07f0000000000000000000000000000000000000000000000000000000000014244620186a0610a41565b61070a7f000000000000000000000000000000000000000000000000000000000001424486610a41565b61071c90670de0b6b3a7640000610a5a565b6107269190610a71565b90506000856107358380610a5a565b61073f9190610a5a565b6107787f000000000000000000000000000000000000000000000000000000000002a3006ec097ce7bc90715b34b9f1000000000610a5a565b6107829190610a93565b90506107bd7f000000000000000000000000000000000000000000000000000000000002a3006ec097ce7bc90715b34b9f1000000000610a5a565b6106768267ffffffffffffffff8716610a5a565b50805b7f00000000000000000000000000000000000000000000000000000035cb191c388167ffffffffffffffff16111561082d57507f00000000000000000000000000000000000000000000000000000035cb191c38610882565b7f000000000000000000000000000000000000000000000000000000011af7bfb48167ffffffffffffffff16101561088257507f000000000000000000000000000000000000000000000000000000011af7bfb45b9392505050565b60006020808352835180602085015260005b818110156108b75785810183015185820160400152820161089b565b506000604082860101526040601f19601f8301168501019250505092915050565b6000806000606084860312156108ed57600080fd5b8335925060208401359150604084013567ffffffffffffffff8116811461091357600080fd5b809150509250925092565b600181811c9082168061093257607f821691505b60208210810361095257634e487b7160e01b600052602260045260246000fd5b50919050565b7f5661726961626c65205261746520563220000000000000000000000000000000815260006011600084548160018260011c9150600183168061099c57607f831692505b602080841082036109bb57634e487b7160e01b86526022600452602486fd5b8180156109cf57600181146109ea57610a1c565b60ff19861660118b0152601185151586028b01019650610a1c565b60008b81526020902060005b86811015610a115781548c82018b01529085019083016109f6565b50506011858b010196505b50949998505050505050505050565b634e487b7160e01b600052601160045260246000fd5b81810381811115610a5457610a54610a2b565b92915050565b8082028115828204841417610a5457610a54610a2b565b600082610a8e57634e487b7160e01b600052601260045260246000fd5b500490565b80820180821115610a5457610a54610a2b56
Constructor Arguments (ABI-Encoded and is the last bytes of the Contract Creation Code above)
0000000000000000000000000000000000000000000000000000000000000120000000000000000000000000000000000000000000000000000000000001117000000000000000000000000000000000000000000000000006f05b59d3b200000000000000000000000000000000000000000000000000000000000000011b3400000000000000000000000000000000000000000000000000000000000142440000000000000000000000000000000000000000000000000000000012dd510c000000000000000000000000000000000000000000000000000000011af7bfb400000000000000000000000000000000000000000000000000000035cb191c38000000000000000000000000000000000000000000000000000000000002a300000000000000000000000000000000000000000000000000000000000000002242616d6d205b2e31352d372e33305d2032206461797320282e3732352d2e38323529000000000000000000000000000000000000000000000000000000000000
-----Decoded View---------------
Arg [0] : _suffix (string): Bamm [.15-7.30] 2 days (.725-.825)
Arg [1] : _vertexUtilization (uint256): 70000
Arg [2] : _vertexRatePercentOfDelta (uint256): 500000000000000000
Arg [3] : _minUtil (uint256): 72500
Arg [4] : _maxUtil (uint256): 82500
Arg [5] : _zeroUtilizationRate (uint256): 316494092
Arg [6] : _minFullUtilizationRate (uint256): 4747411380
Arg [7] : _maxFullUtilizationRate (uint256): 231040687160
Arg [8] : _rateHalfLife (uint256): 172800
-----Encoded View---------------
12 Constructor Arguments found :
Arg [0] : 0000000000000000000000000000000000000000000000000000000000000120
Arg [1] : 0000000000000000000000000000000000000000000000000000000000011170
Arg [2] : 00000000000000000000000000000000000000000000000006f05b59d3b20000
Arg [3] : 0000000000000000000000000000000000000000000000000000000000011b34
Arg [4] : 0000000000000000000000000000000000000000000000000000000000014244
Arg [5] : 0000000000000000000000000000000000000000000000000000000012dd510c
Arg [6] : 000000000000000000000000000000000000000000000000000000011af7bfb4
Arg [7] : 00000000000000000000000000000000000000000000000000000035cb191c38
Arg [8] : 000000000000000000000000000000000000000000000000000000000002a300
Arg [9] : 0000000000000000000000000000000000000000000000000000000000000022
Arg [10] : 42616d6d205b2e31352d372e33305d2032206461797320282e3732352d2e3832
Arg [11] : 3529000000000000000000000000000000000000000000000000000000000000
Loading...
Loading
Loading...
Loading
Loading...
Loading
Net Worth in USD
$0.00
Net Worth in FRAX
0
Multichain Portfolio | 35 Chains
| Chain | Token | Portfolio % | Price | Amount | Value |
|---|
Loading...
Loading
Loading...
Loading
Loading...
Loading
A contract address hosts a smart contract, which is a set of code stored on the blockchain that runs when predetermined conditions are met. Learn more about addresses in our Knowledge Base.