More Info
Private Name Tags
ContractCreator
TokenTracker
Latest 25 from a total of 302,750 transactions
| Transaction Hash |
|
Block
|
From
|
To
|
|||||
|---|---|---|---|---|---|---|---|---|---|
| Withdraw | 30195986 | 15 hrs ago | IN | 0 ETH | 0.00000149 | ||||
| Withdraw | 30195945 | 15 hrs ago | IN | 0 ETH | 0.00000171 | ||||
| Withdraw | 30195528 | 15 hrs ago | IN | 0 ETH | 0.00000249 | ||||
| Withdraw | 30195313 | 15 hrs ago | IN | 0 ETH | 0.00000091 | ||||
| Withdraw | 30189113 | 19 hrs ago | IN | 0 ETH | 0.00000293 | ||||
| Withdraw | 30189057 | 19 hrs ago | IN | 0 ETH | 0.00000327 | ||||
| Withdraw | 30174650 | 27 hrs ago | IN | 0 ETH | 0.00000019 | ||||
| Withdraw | 30152045 | 39 hrs ago | IN | 0 ETH | 0.0000002 | ||||
| Withdraw | 30143302 | 44 hrs ago | IN | 0 ETH | 0.00001777 | ||||
| Withdraw | 30143275 | 44 hrs ago | IN | 0 ETH | 0.00002029 | ||||
| Withdraw | 30143173 | 44 hrs ago | IN | 0 ETH | 0.0000256 | ||||
| Withdraw | 30136352 | 2 days ago | IN | 0 ETH | 0.00003848 | ||||
| Withdraw | 30133874 | 2 days ago | IN | 0 ETH | 0.0000001 | ||||
| Withdraw | 30130182 | 2 days ago | IN | 0 ETH | 0.00000019 | ||||
| Withdraw | 30129305 | 2 days ago | IN | 0 ETH | 0.00000021 | ||||
| Withdraw | 30125750 | 2 days ago | IN | 0 ETH | 0.00000073 | ||||
| Withdraw | 30120946 | 2 days ago | IN | 0 ETH | 0.00000238 | ||||
| Withdraw | 30096313 | 2 days ago | IN | 0 ETH | 0.00000173 | ||||
| Withdraw | 30090916 | 3 days ago | IN | 0 ETH | 0.0000013 | ||||
| Withdraw | 30087431 | 3 days ago | IN | 0 ETH | 0.00000241 | ||||
| Withdraw | 30084967 | 3 days ago | IN | 0 ETH | 0.00000082 | ||||
| Withdraw | 30080560 | 3 days ago | IN | 0 ETH | 0.00000083 | ||||
| Withdraw | 30077689 | 3 days ago | IN | 0 ETH | 0.00000023 | ||||
| Withdraw | 30071127 | 3 days ago | IN | 0 ETH | 0.00000089 | ||||
| Withdraw | 30066430 | 3 days ago | IN | 0 ETH | 0.00000032 |
Latest 3 internal transactions
Advanced mode:
| Parent Transaction Hash | Block | From | To | |||
|---|---|---|---|---|---|---|
| 526125 | 687 days ago | Contract Creation | 0 ETH | |||
| 526125 | 687 days ago | Contract Creation | 0 ETH | |||
| 526125 | 687 days ago | Contract Creation | 0 ETH |
Cross-Chain Transactions
Loading...
Loading
Contract Name:
JuiceLendingPool
Compiler Version
v0.8.24+commit.e11b9ed9
Contract Source Code (Solidity Standard Json-Input format)
// SPDX-License-Identifier: GPL-3.0
pragma solidity 0.8.24;
import { SafeERC20, IERC20 } from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import "../lendingPool/LendingPool.sol";
import { mulDiv } from "@prb/math/src/Common.sol";
import "./JuiceModule.sol";
import "../external/blast/IERC20Rebasing.sol";
import "../libraries/Errors.sol";
import "./periphery/BlastGas.sol";
import "./periphery/BlastPoints.sol";
/// @title Juice Lending Pool
/// @notice This contract extends LendingPool to account for Blast native features.
/// @dev Supports gas refunds as well as using either USDB or WETH as the lending asset.
contract JuiceLendingPool is LendingPool, JuiceModule, BlastGas, BlastPoints {
using SafeERC20 for IERC20;
uint256 public MINIMUM_COMPOUND_AMOUNT = 1e6;
struct InitParams {
address interestRateStrategy;
address blastPointsOperator;
string debtTokenName;
string debtTokenSymbol;
string liquidityTokenName;
string liquidityTokenSymbol;
uint256 minimumOpenBorrow;
bool isAutoCompounding;
}
bool public isAutoCompounding;
constructor(
address protocolGovernor_,
InitParams memory params
)
BlastGas(protocolGovernor_)
BlastPoints(protocolGovernor_, params.blastPointsOperator)
JuiceModule(protocolGovernor_)
LendingPool(
protocolGovernor_,
LendingPool.BaseInitParams({
interestRateStrategy: params.interestRateStrategy,
minimumOpenBorrow: params.minimumOpenBorrow,
debtTokenName: params.debtTokenName,
debtTokenSymbol: params.debtTokenSymbol,
liquidityTokenName: params.liquidityTokenName,
liquidityTokenSymbol: params.liquidityTokenSymbol
})
)
{
isAutoCompounding = params.isAutoCompounding;
IERC20Rebasing(address(reserve.asset)).configure(YieldMode.CLAIMABLE);
}
function toggleAutoCompounding() public onlyOwner {
isAutoCompounding = !isAutoCompounding;
}
function getNormalizedIncome() public view override returns (UD60x18) {
uint256 timestamp = reserve.lastUpdateTimestamp;
// slither-disable-next-line incorrect-equality
if (timestamp == block.timestamp) {
return reserve.liquidityIndex;
}
uint256 claimableYield = IERC20Rebasing(address(reserve.asset)).getClaimableAmount(address(this));
UD60x18 pendingYield = ud(reserve.assetBalance + claimableYield).div(ud(reserve.assetBalance));
return MathUtils.calculateCompoundedInterest(reserve.liquidityRate, timestamp).mul(reserve.liquidityIndex).mul(
pendingYield
);
}
/// @notice Accrue asset yield earned from idle reserve assets and distribute it to depositors.
function compound() external nonReentrant returns (uint256 earned) {
earned = _compound();
}
/// @notice Pull asset yield from some address and distribute it to depositors.
function sendYield(uint256 amount) external onlyLendYieldSender {
uint256 reserveBalanceBefore = reserve.assetBalance;
IERC20(reserve.asset).safeTransferFrom(msg.sender, address(this), amount);
_accrueYield(reserveBalanceBefore, amount);
}
function _compound() internal returns (uint256 earned) {
IERC20Rebasing asset = IERC20Rebasing(address(reserve.asset));
earned = asset.getClaimableAmount(address(this));
// Avoid compounding dust.
if (earned >= MINIMUM_COMPOUND_AMOUNT) {
uint256 reserveBalanceBefore = reserve.assetBalance;
earned = asset.claim(address(this), earned);
_accrueYield(reserveBalanceBefore, earned);
}
}
function _beforeAction() internal override {
_accrueInterest();
if (isAutoCompounding) {
_compound();
}
}
/// @notice Accrues yield into liquidityIndex.
function _accrueYield(uint256 assetBalanceBefore, uint256 yieldClaimed) internal {
reserve.assetBalance += yieldClaimed;
reserve.liquidityIndex = (ud(reserve.assetBalance).mul(reserve.liquidityIndex)).div(ud(assetBalanceBefore));
emit LiquidityIndexUpdated(reserve.liquidityIndex);
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (access/Ownable.sol)
pragma solidity ^0.8.20;
import {Context} from "../utils/Context.sol";
/**
* @dev Contract module which provides a basic access control mechanism, where
* there is an account (an owner) that can be granted exclusive access to
* specific functions.
*
* The initial owner is set to the address provided by the deployer. This can
* later be changed with {transferOwnership}.
*
* This module is used through inheritance. It will make available the modifier
* `onlyOwner`, which can be applied to your functions to restrict their use to
* the owner.
*/
abstract contract Ownable is Context {
address private _owner;
/**
* @dev The caller account is not authorized to perform an operation.
*/
error OwnableUnauthorizedAccount(address account);
/**
* @dev The owner is not a valid owner account. (eg. `address(0)`)
*/
error OwnableInvalidOwner(address owner);
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
/**
* @dev Initializes the contract setting the address provided by the deployer as the initial owner.
*/
constructor(address initialOwner) {
if (initialOwner == address(0)) {
revert OwnableInvalidOwner(address(0));
}
_transferOwnership(initialOwner);
}
/**
* @dev Throws if called by any account other than the owner.
*/
modifier onlyOwner() {
_checkOwner();
_;
}
/**
* @dev Returns the address of the current owner.
*/
function owner() public view virtual returns (address) {
return _owner;
}
/**
* @dev Throws if the sender is not the owner.
*/
function _checkOwner() internal view virtual {
if (owner() != _msgSender()) {
revert OwnableUnauthorizedAccount(_msgSender());
}
}
/**
* @dev Leaves the contract without owner. It will not be possible to call
* `onlyOwner` functions. Can only be called by the current owner.
*
* NOTE: Renouncing ownership will leave the contract without an owner,
* thereby disabling any functionality that is only available to the owner.
*/
function renounceOwnership() public virtual onlyOwner {
_transferOwnership(address(0));
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Can only be called by the current owner.
*/
function transferOwnership(address newOwner) public virtual onlyOwner {
if (newOwner == address(0)) {
revert OwnableInvalidOwner(address(0));
}
_transferOwnership(newOwner);
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Internal function without access restriction.
*/
function _transferOwnership(address newOwner) internal virtual {
address oldOwner = _owner;
_owner = newOwner;
emit OwnershipTransferred(oldOwner, newOwner);
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (access/Ownable2Step.sol)
pragma solidity ^0.8.20;
import {Ownable} from "./Ownable.sol";
/**
* @dev Contract module which provides access control mechanism, where
* there is an account (an owner) that can be granted exclusive access to
* specific functions.
*
* The initial owner is specified at deployment time in the constructor for `Ownable`. This
* can later be changed with {transferOwnership} and {acceptOwnership}.
*
* This module is used through inheritance. It will make available all functions
* from parent (Ownable).
*/
abstract contract Ownable2Step is Ownable {
address private _pendingOwner;
event OwnershipTransferStarted(address indexed previousOwner, address indexed newOwner);
/**
* @dev Returns the address of the pending owner.
*/
function pendingOwner() public view virtual returns (address) {
return _pendingOwner;
}
/**
* @dev Starts the ownership transfer of the contract to a new account. Replaces the pending transfer if there is one.
* Can only be called by the current owner.
*/
function transferOwnership(address newOwner) public virtual override onlyOwner {
_pendingOwner = newOwner;
emit OwnershipTransferStarted(owner(), newOwner);
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`) and deletes any pending owner.
* Internal function without access restriction.
*/
function _transferOwnership(address newOwner) internal virtual override {
delete _pendingOwner;
super._transferOwnership(newOwner);
}
/**
* @dev The new owner accepts the ownership transfer.
*/
function acceptOwnership() public virtual {
address sender = _msgSender();
if (pendingOwner() != sender) {
revert OwnableUnauthorizedAccount(sender);
}
_transferOwnership(sender);
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC20/IERC20.sol)
pragma solidity ^0.8.20;
/**
* @dev Interface of the ERC20 standard as defined in the EIP.
*/
interface IERC20 {
/**
* @dev Emitted when `value` tokens are moved from one account (`from`) to
* another (`to`).
*
* Note that `value` may be zero.
*/
event Transfer(address indexed from, address indexed to, uint256 value);
/**
* @dev Emitted when the allowance of a `spender` for an `owner` is set by
* a call to {approve}. `value` is the new allowance.
*/
event Approval(address indexed owner, address indexed spender, uint256 value);
/**
* @dev Returns the value of tokens in existence.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns the value of tokens owned by `account`.
*/
function balanceOf(address account) external view returns (uint256);
/**
* @dev Moves a `value` amount of tokens from the caller's account to `to`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transfer(address to, uint256 value) external returns (bool);
/**
* @dev Returns the remaining number of tokens that `spender` will be
* allowed to spend on behalf of `owner` through {transferFrom}. This is
* zero by default.
*
* This value changes when {approve} or {transferFrom} are called.
*/
function allowance(address owner, address spender) external view returns (uint256);
/**
* @dev Sets a `value` amount of tokens as the allowance of `spender` over the
* caller's tokens.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* IMPORTANT: Beware that changing an allowance with this method brings the risk
* that someone may use both the old and the new allowance by unfortunate
* transaction ordering. One possible solution to mitigate this race
* condition is to first reduce the spender's allowance to 0 and set the
* desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
*
* Emits an {Approval} event.
*/
function approve(address spender, uint256 value) external returns (bool);
/**
* @dev Moves a `value` amount of tokens from `from` to `to` using the
* allowance mechanism. `value` is then deducted from the caller's
* allowance.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transferFrom(address from, address to, uint256 value) external returns (bool);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC20/extensions/IERC20Metadata.sol)
pragma solidity ^0.8.20;
import {IERC20} from "../IERC20.sol";
/**
* @dev Interface for the optional metadata functions from the ERC20 standard.
*/
interface IERC20Metadata is IERC20 {
/**
* @dev Returns the name of the token.
*/
function name() external view returns (string memory);
/**
* @dev Returns the symbol of the token.
*/
function symbol() external view returns (string memory);
/**
* @dev Returns the decimals places of the token.
*/
function decimals() external view returns (uint8);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC20/extensions/IERC20Permit.sol)
pragma solidity ^0.8.20;
/**
* @dev Interface of the ERC20 Permit extension allowing approvals to be made via signatures, as defined in
* https://eips.ethereum.org/EIPS/eip-2612[EIP-2612].
*
* Adds the {permit} method, which can be used to change an account's ERC20 allowance (see {IERC20-allowance}) by
* presenting a message signed by the account. By not relying on {IERC20-approve}, the token holder account doesn't
* need to send a transaction, and thus is not required to hold Ether at all.
*
* ==== Security Considerations
*
* There are two important considerations concerning the use of `permit`. The first is that a valid permit signature
* expresses an allowance, and it should not be assumed to convey additional meaning. In particular, it should not be
* considered as an intention to spend the allowance in any specific way. The second is that because permits have
* built-in replay protection and can be submitted by anyone, they can be frontrun. A protocol that uses permits should
* take this into consideration and allow a `permit` call to fail. Combining these two aspects, a pattern that may be
* generally recommended is:
*
* ```solidity
* function doThingWithPermit(..., uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s) public {
* try token.permit(msg.sender, address(this), value, deadline, v, r, s) {} catch {}
* doThing(..., value);
* }
*
* function doThing(..., uint256 value) public {
* token.safeTransferFrom(msg.sender, address(this), value);
* ...
* }
* ```
*
* Observe that: 1) `msg.sender` is used as the owner, leaving no ambiguity as to the signer intent, and 2) the use of
* `try/catch` allows the permit to fail and makes the code tolerant to frontrunning. (See also
* {SafeERC20-safeTransferFrom}).
*
* Additionally, note that smart contract wallets (such as Argent or Safe) are not able to produce permit signatures, so
* contracts should have entry points that don't rely on permit.
*/
interface IERC20Permit {
/**
* @dev Sets `value` as the allowance of `spender` over ``owner``'s tokens,
* given ``owner``'s signed approval.
*
* IMPORTANT: The same issues {IERC20-approve} has related to transaction
* ordering also apply here.
*
* Emits an {Approval} event.
*
* Requirements:
*
* - `spender` cannot be the zero address.
* - `deadline` must be a timestamp in the future.
* - `v`, `r` and `s` must be a valid `secp256k1` signature from `owner`
* over the EIP712-formatted function arguments.
* - the signature must use ``owner``'s current nonce (see {nonces}).
*
* For more information on the signature format, see the
* https://eips.ethereum.org/EIPS/eip-2612#specification[relevant EIP
* section].
*
* CAUTION: See Security Considerations above.
*/
function permit(
address owner,
address spender,
uint256 value,
uint256 deadline,
uint8 v,
bytes32 r,
bytes32 s
) external;
/**
* @dev Returns the current nonce for `owner`. This value must be
* included whenever a signature is generated for {permit}.
*
* Every successful call to {permit} increases ``owner``'s nonce by one. This
* prevents a signature from being used multiple times.
*/
function nonces(address owner) external view returns (uint256);
/**
* @dev Returns the domain separator used in the encoding of the signature for {permit}, as defined by {EIP712}.
*/
// solhint-disable-next-line func-name-mixedcase
function DOMAIN_SEPARATOR() external view returns (bytes32);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC20/utils/SafeERC20.sol)
pragma solidity ^0.8.20;
import {IERC20} from "../IERC20.sol";
import {IERC20Permit} from "../extensions/IERC20Permit.sol";
import {Address} from "../../../utils/Address.sol";
/**
* @title SafeERC20
* @dev Wrappers around ERC20 operations that throw on failure (when the token
* contract returns false). Tokens that return no value (and instead revert or
* throw on failure) are also supported, non-reverting calls are assumed to be
* successful.
* To use this library you can add a `using SafeERC20 for IERC20;` statement to your contract,
* which allows you to call the safe operations as `token.safeTransfer(...)`, etc.
*/
library SafeERC20 {
using Address for address;
/**
* @dev An operation with an ERC20 token failed.
*/
error SafeERC20FailedOperation(address token);
/**
* @dev Indicates a failed `decreaseAllowance` request.
*/
error SafeERC20FailedDecreaseAllowance(address spender, uint256 currentAllowance, uint256 requestedDecrease);
/**
* @dev Transfer `value` amount of `token` from the calling contract to `to`. If `token` returns no value,
* non-reverting calls are assumed to be successful.
*/
function safeTransfer(IERC20 token, address to, uint256 value) internal {
_callOptionalReturn(token, abi.encodeCall(token.transfer, (to, value)));
}
/**
* @dev Transfer `value` amount of `token` from `from` to `to`, spending the approval given by `from` to the
* calling contract. If `token` returns no value, non-reverting calls are assumed to be successful.
*/
function safeTransferFrom(IERC20 token, address from, address to, uint256 value) internal {
_callOptionalReturn(token, abi.encodeCall(token.transferFrom, (from, to, value)));
}
/**
* @dev Increase the calling contract's allowance toward `spender` by `value`. If `token` returns no value,
* non-reverting calls are assumed to be successful.
*/
function safeIncreaseAllowance(IERC20 token, address spender, uint256 value) internal {
uint256 oldAllowance = token.allowance(address(this), spender);
forceApprove(token, spender, oldAllowance + value);
}
/**
* @dev Decrease the calling contract's allowance toward `spender` by `requestedDecrease`. If `token` returns no
* value, non-reverting calls are assumed to be successful.
*/
function safeDecreaseAllowance(IERC20 token, address spender, uint256 requestedDecrease) internal {
unchecked {
uint256 currentAllowance = token.allowance(address(this), spender);
if (currentAllowance < requestedDecrease) {
revert SafeERC20FailedDecreaseAllowance(spender, currentAllowance, requestedDecrease);
}
forceApprove(token, spender, currentAllowance - requestedDecrease);
}
}
/**
* @dev Set the calling contract's allowance toward `spender` to `value`. If `token` returns no value,
* non-reverting calls are assumed to be successful. Meant to be used with tokens that require the approval
* to be set to zero before setting it to a non-zero value, such as USDT.
*/
function forceApprove(IERC20 token, address spender, uint256 value) internal {
bytes memory approvalCall = abi.encodeCall(token.approve, (spender, value));
if (!_callOptionalReturnBool(token, approvalCall)) {
_callOptionalReturn(token, abi.encodeCall(token.approve, (spender, 0)));
_callOptionalReturn(token, approvalCall);
}
}
/**
* @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
* on the return value: the return value is optional (but if data is returned, it must not be false).
* @param token The token targeted by the call.
* @param data The call data (encoded using abi.encode or one of its variants).
*/
function _callOptionalReturn(IERC20 token, bytes memory data) private {
// We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since
// we're implementing it ourselves. We use {Address-functionCall} to perform this call, which verifies that
// the target address contains contract code and also asserts for success in the low-level call.
bytes memory returndata = address(token).functionCall(data);
if (returndata.length != 0 && !abi.decode(returndata, (bool))) {
revert SafeERC20FailedOperation(address(token));
}
}
/**
* @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
* on the return value: the return value is optional (but if data is returned, it must not be false).
* @param token The token targeted by the call.
* @param data The call data (encoded using abi.encode or one of its variants).
*
* This is a variant of {_callOptionalReturn} that silents catches all reverts and returns a bool instead.
*/
function _callOptionalReturnBool(IERC20 token, bytes memory data) private returns (bool) {
// We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since
// we're implementing it ourselves. We cannot use {Address-functionCall} here since this should return false
// and not revert is the subcall reverts.
(bool success, bytes memory returndata) = address(token).call(data);
return success && (returndata.length == 0 || abi.decode(returndata, (bool))) && address(token).code.length > 0;
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/Address.sol)
pragma solidity ^0.8.20;
/**
* @dev Collection of functions related to the address type
*/
library Address {
/**
* @dev The ETH balance of the account is not enough to perform the operation.
*/
error AddressInsufficientBalance(address account);
/**
* @dev There's no code at `target` (it is not a contract).
*/
error AddressEmptyCode(address target);
/**
* @dev A call to an address target failed. The target may have reverted.
*/
error FailedInnerCall();
/**
* @dev Replacement for Solidity's `transfer`: sends `amount` wei to
* `recipient`, forwarding all available gas and reverting on errors.
*
* https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
* of certain opcodes, possibly making contracts go over the 2300 gas limit
* imposed by `transfer`, making them unable to receive funds via
* `transfer`. {sendValue} removes this limitation.
*
* https://consensys.net/diligence/blog/2019/09/stop-using-soliditys-transfer-now/[Learn more].
*
* IMPORTANT: because control is transferred to `recipient`, care must be
* taken to not create reentrancy vulnerabilities. Consider using
* {ReentrancyGuard} or the
* https://solidity.readthedocs.io/en/v0.8.20/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
*/
function sendValue(address payable recipient, uint256 amount) internal {
if (address(this).balance < amount) {
revert AddressInsufficientBalance(address(this));
}
(bool success, ) = recipient.call{value: amount}("");
if (!success) {
revert FailedInnerCall();
}
}
/**
* @dev Performs a Solidity function call using a low level `call`. A
* plain `call` is an unsafe replacement for a function call: use this
* function instead.
*
* If `target` reverts with a revert reason or custom error, it is bubbled
* up by this function (like regular Solidity function calls). However, if
* the call reverted with no returned reason, this function reverts with a
* {FailedInnerCall} error.
*
* Returns the raw returned data. To convert to the expected return value,
* use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
*
* Requirements:
*
* - `target` must be a contract.
* - calling `target` with `data` must not revert.
*/
function functionCall(address target, bytes memory data) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but also transferring `value` wei to `target`.
*
* Requirements:
*
* - the calling contract must have an ETH balance of at least `value`.
* - the called Solidity function must be `payable`.
*/
function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {
if (address(this).balance < value) {
revert AddressInsufficientBalance(address(this));
}
(bool success, bytes memory returndata) = target.call{value: value}(data);
return verifyCallResultFromTarget(target, success, returndata);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a static call.
*/
function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
(bool success, bytes memory returndata) = target.staticcall(data);
return verifyCallResultFromTarget(target, success, returndata);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a delegate call.
*/
function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {
(bool success, bytes memory returndata) = target.delegatecall(data);
return verifyCallResultFromTarget(target, success, returndata);
}
/**
* @dev Tool to verify that a low level call to smart-contract was successful, and reverts if the target
* was not a contract or bubbling up the revert reason (falling back to {FailedInnerCall}) in case of an
* unsuccessful call.
*/
function verifyCallResultFromTarget(
address target,
bool success,
bytes memory returndata
) internal view returns (bytes memory) {
if (!success) {
_revert(returndata);
} else {
// only check if target is a contract if the call was successful and the return data is empty
// otherwise we already know that it was a contract
if (returndata.length == 0 && target.code.length == 0) {
revert AddressEmptyCode(target);
}
return returndata;
}
}
/**
* @dev Tool to verify that a low level call was successful, and reverts if it wasn't, either by bubbling the
* revert reason or with a default {FailedInnerCall} error.
*/
function verifyCallResult(bool success, bytes memory returndata) internal pure returns (bytes memory) {
if (!success) {
_revert(returndata);
} else {
return returndata;
}
}
/**
* @dev Reverts with returndata if present. Otherwise reverts with {FailedInnerCall}.
*/
function _revert(bytes memory returndata) private pure {
// Look for revert reason and bubble it up if present
if (returndata.length > 0) {
// The easiest way to bubble the revert reason is using memory via assembly
/// @solidity memory-safe-assembly
assembly {
let returndata_size := mload(returndata)
revert(add(32, returndata), returndata_size)
}
} else {
revert FailedInnerCall();
}
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.1) (utils/Context.sol)
pragma solidity ^0.8.20;
/**
* @dev Provides information about the current execution context, including the
* sender of the transaction and its data. While these are generally available
* via msg.sender and msg.data, they should not be accessed in such a direct
* manner, since when dealing with meta-transactions the account sending and
* paying for execution may not be the actual sender (as far as an application
* is concerned).
*
* This contract is only required for intermediate, library-like contracts.
*/
abstract contract Context {
function _msgSender() internal view virtual returns (address) {
return msg.sender;
}
function _msgData() internal view virtual returns (bytes calldata) {
return msg.data;
}
function _contextSuffixLength() internal view virtual returns (uint256) {
return 0;
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/Pausable.sol)
pragma solidity ^0.8.20;
import {Context} from "../utils/Context.sol";
/**
* @dev Contract module which allows children to implement an emergency stop
* mechanism that can be triggered by an authorized account.
*
* This module is used through inheritance. It will make available the
* modifiers `whenNotPaused` and `whenPaused`, which can be applied to
* the functions of your contract. Note that they will not be pausable by
* simply including this module, only once the modifiers are put in place.
*/
abstract contract Pausable is Context {
bool private _paused;
/**
* @dev Emitted when the pause is triggered by `account`.
*/
event Paused(address account);
/**
* @dev Emitted when the pause is lifted by `account`.
*/
event Unpaused(address account);
/**
* @dev The operation failed because the contract is paused.
*/
error EnforcedPause();
/**
* @dev The operation failed because the contract is not paused.
*/
error ExpectedPause();
/**
* @dev Initializes the contract in unpaused state.
*/
constructor() {
_paused = false;
}
/**
* @dev Modifier to make a function callable only when the contract is not paused.
*
* Requirements:
*
* - The contract must not be paused.
*/
modifier whenNotPaused() {
_requireNotPaused();
_;
}
/**
* @dev Modifier to make a function callable only when the contract is paused.
*
* Requirements:
*
* - The contract must be paused.
*/
modifier whenPaused() {
_requirePaused();
_;
}
/**
* @dev Returns true if the contract is paused, and false otherwise.
*/
function paused() public view virtual returns (bool) {
return _paused;
}
/**
* @dev Throws if the contract is paused.
*/
function _requireNotPaused() internal view virtual {
if (paused()) {
revert EnforcedPause();
}
}
/**
* @dev Throws if the contract is not paused.
*/
function _requirePaused() internal view virtual {
if (!paused()) {
revert ExpectedPause();
}
}
/**
* @dev Triggers stopped state.
*
* Requirements:
*
* - The contract must not be paused.
*/
function _pause() internal virtual whenNotPaused {
_paused = true;
emit Paused(_msgSender());
}
/**
* @dev Returns to normal state.
*
* Requirements:
*
* - The contract must be paused.
*/
function _unpause() internal virtual whenPaused {
_paused = false;
emit Unpaused(_msgSender());
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/ReentrancyGuard.sol)
pragma solidity ^0.8.20;
/**
* @dev Contract module that helps prevent reentrant calls to a function.
*
* Inheriting from `ReentrancyGuard` will make the {nonReentrant} modifier
* available, which can be applied to functions to make sure there are no nested
* (reentrant) calls to them.
*
* Note that because there is a single `nonReentrant` guard, functions marked as
* `nonReentrant` may not call one another. This can be worked around by making
* those functions `private`, and then adding `external` `nonReentrant` entry
* points to them.
*
* TIP: If you would like to learn more about reentrancy and alternative ways
* to protect against it, check out our blog post
* https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul].
*/
abstract contract ReentrancyGuard {
// Booleans are more expensive than uint256 or any type that takes up a full
// word because each write operation emits an extra SLOAD to first read the
// slot's contents, replace the bits taken up by the boolean, and then write
// back. This is the compiler's defense against contract upgrades and
// pointer aliasing, and it cannot be disabled.
// The values being non-zero value makes deployment a bit more expensive,
// but in exchange the refund on every call to nonReentrant will be lower in
// amount. Since refunds are capped to a percentage of the total
// transaction's gas, it is best to keep them low in cases like this one, to
// increase the likelihood of the full refund coming into effect.
uint256 private constant NOT_ENTERED = 1;
uint256 private constant ENTERED = 2;
uint256 private _status;
/**
* @dev Unauthorized reentrant call.
*/
error ReentrancyGuardReentrantCall();
constructor() {
_status = NOT_ENTERED;
}
/**
* @dev Prevents a contract from calling itself, directly or indirectly.
* Calling a `nonReentrant` function from another `nonReentrant`
* function is not supported. It is possible to prevent this from happening
* by making the `nonReentrant` function external, and making it call a
* `private` function that does the actual work.
*/
modifier nonReentrant() {
_nonReentrantBefore();
_;
_nonReentrantAfter();
}
function _nonReentrantBefore() private {
// On the first call to nonReentrant, _status will be NOT_ENTERED
if (_status == ENTERED) {
revert ReentrancyGuardReentrantCall();
}
// Any calls to nonReentrant after this point will fail
_status = ENTERED;
}
function _nonReentrantAfter() private {
// By storing the original value once again, a refund is triggered (see
// https://eips.ethereum.org/EIPS/eip-2200)
_status = NOT_ENTERED;
}
/**
* @dev Returns true if the reentrancy guard is currently set to "entered", which indicates there is a
* `nonReentrant` function in the call stack.
*/
function _reentrancyGuardEntered() internal view returns (bool) {
return _status == ENTERED;
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/structs/EnumerableSet.sol)
// This file was procedurally generated from scripts/generate/templates/EnumerableSet.js.
pragma solidity ^0.8.20;
/**
* @dev Library for managing
* https://en.wikipedia.org/wiki/Set_(abstract_data_type)[sets] of primitive
* types.
*
* Sets have the following properties:
*
* - Elements are added, removed, and checked for existence in constant time
* (O(1)).
* - Elements are enumerated in O(n). No guarantees are made on the ordering.
*
* ```solidity
* contract Example {
* // Add the library methods
* using EnumerableSet for EnumerableSet.AddressSet;
*
* // Declare a set state variable
* EnumerableSet.AddressSet private mySet;
* }
* ```
*
* As of v3.3.0, sets of type `bytes32` (`Bytes32Set`), `address` (`AddressSet`)
* and `uint256` (`UintSet`) are supported.
*
* [WARNING]
* ====
* Trying to delete such a structure from storage will likely result in data corruption, rendering the structure
* unusable.
* See https://github.com/ethereum/solidity/pull/11843[ethereum/solidity#11843] for more info.
*
* In order to clean an EnumerableSet, you can either remove all elements one by one or create a fresh instance using an
* array of EnumerableSet.
* ====
*/
library EnumerableSet {
// To implement this library for multiple types with as little code
// repetition as possible, we write it in terms of a generic Set type with
// bytes32 values.
// The Set implementation uses private functions, and user-facing
// implementations (such as AddressSet) are just wrappers around the
// underlying Set.
// This means that we can only create new EnumerableSets for types that fit
// in bytes32.
struct Set {
// Storage of set values
bytes32[] _values;
// Position is the index of the value in the `values` array plus 1.
// Position 0 is used to mean a value is not in the set.
mapping(bytes32 value => uint256) _positions;
}
/**
* @dev Add a value to a set. O(1).
*
* Returns true if the value was added to the set, that is if it was not
* already present.
*/
function _add(Set storage set, bytes32 value) private returns (bool) {
if (!_contains(set, value)) {
set._values.push(value);
// The value is stored at length-1, but we add 1 to all indexes
// and use 0 as a sentinel value
set._positions[value] = set._values.length;
return true;
} else {
return false;
}
}
/**
* @dev Removes a value from a set. O(1).
*
* Returns true if the value was removed from the set, that is if it was
* present.
*/
function _remove(Set storage set, bytes32 value) private returns (bool) {
// We cache the value's position to prevent multiple reads from the same storage slot
uint256 position = set._positions[value];
if (position != 0) {
// Equivalent to contains(set, value)
// To delete an element from the _values array in O(1), we swap the element to delete with the last one in
// the array, and then remove the last element (sometimes called as 'swap and pop').
// This modifies the order of the array, as noted in {at}.
uint256 valueIndex = position - 1;
uint256 lastIndex = set._values.length - 1;
if (valueIndex != lastIndex) {
bytes32 lastValue = set._values[lastIndex];
// Move the lastValue to the index where the value to delete is
set._values[valueIndex] = lastValue;
// Update the tracked position of the lastValue (that was just moved)
set._positions[lastValue] = position;
}
// Delete the slot where the moved value was stored
set._values.pop();
// Delete the tracked position for the deleted slot
delete set._positions[value];
return true;
} else {
return false;
}
}
/**
* @dev Returns true if the value is in the set. O(1).
*/
function _contains(Set storage set, bytes32 value) private view returns (bool) {
return set._positions[value] != 0;
}
/**
* @dev Returns the number of values on the set. O(1).
*/
function _length(Set storage set) private view returns (uint256) {
return set._values.length;
}
/**
* @dev Returns the value stored at position `index` in the set. O(1).
*
* Note that there are no guarantees on the ordering of values inside the
* array, and it may change when more values are added or removed.
*
* Requirements:
*
* - `index` must be strictly less than {length}.
*/
function _at(Set storage set, uint256 index) private view returns (bytes32) {
return set._values[index];
}
/**
* @dev Return the entire set in an array
*
* WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
* to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
* this function has an unbounded cost, and using it as part of a state-changing function may render the function
* uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
*/
function _values(Set storage set) private view returns (bytes32[] memory) {
return set._values;
}
// Bytes32Set
struct Bytes32Set {
Set _inner;
}
/**
* @dev Add a value to a set. O(1).
*
* Returns true if the value was added to the set, that is if it was not
* already present.
*/
function add(Bytes32Set storage set, bytes32 value) internal returns (bool) {
return _add(set._inner, value);
}
/**
* @dev Removes a value from a set. O(1).
*
* Returns true if the value was removed from the set, that is if it was
* present.
*/
function remove(Bytes32Set storage set, bytes32 value) internal returns (bool) {
return _remove(set._inner, value);
}
/**
* @dev Returns true if the value is in the set. O(1).
*/
function contains(Bytes32Set storage set, bytes32 value) internal view returns (bool) {
return _contains(set._inner, value);
}
/**
* @dev Returns the number of values in the set. O(1).
*/
function length(Bytes32Set storage set) internal view returns (uint256) {
return _length(set._inner);
}
/**
* @dev Returns the value stored at position `index` in the set. O(1).
*
* Note that there are no guarantees on the ordering of values inside the
* array, and it may change when more values are added or removed.
*
* Requirements:
*
* - `index` must be strictly less than {length}.
*/
function at(Bytes32Set storage set, uint256 index) internal view returns (bytes32) {
return _at(set._inner, index);
}
/**
* @dev Return the entire set in an array
*
* WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
* to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
* this function has an unbounded cost, and using it as part of a state-changing function may render the function
* uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
*/
function values(Bytes32Set storage set) internal view returns (bytes32[] memory) {
bytes32[] memory store = _values(set._inner);
bytes32[] memory result;
/// @solidity memory-safe-assembly
assembly {
result := store
}
return result;
}
// AddressSet
struct AddressSet {
Set _inner;
}
/**
* @dev Add a value to a set. O(1).
*
* Returns true if the value was added to the set, that is if it was not
* already present.
*/
function add(AddressSet storage set, address value) internal returns (bool) {
return _add(set._inner, bytes32(uint256(uint160(value))));
}
/**
* @dev Removes a value from a set. O(1).
*
* Returns true if the value was removed from the set, that is if it was
* present.
*/
function remove(AddressSet storage set, address value) internal returns (bool) {
return _remove(set._inner, bytes32(uint256(uint160(value))));
}
/**
* @dev Returns true if the value is in the set. O(1).
*/
function contains(AddressSet storage set, address value) internal view returns (bool) {
return _contains(set._inner, bytes32(uint256(uint160(value))));
}
/**
* @dev Returns the number of values in the set. O(1).
*/
function length(AddressSet storage set) internal view returns (uint256) {
return _length(set._inner);
}
/**
* @dev Returns the value stored at position `index` in the set. O(1).
*
* Note that there are no guarantees on the ordering of values inside the
* array, and it may change when more values are added or removed.
*
* Requirements:
*
* - `index` must be strictly less than {length}.
*/
function at(AddressSet storage set, uint256 index) internal view returns (address) {
return address(uint160(uint256(_at(set._inner, index))));
}
/**
* @dev Return the entire set in an array
*
* WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
* to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
* this function has an unbounded cost, and using it as part of a state-changing function may render the function
* uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
*/
function values(AddressSet storage set) internal view returns (address[] memory) {
bytes32[] memory store = _values(set._inner);
address[] memory result;
/// @solidity memory-safe-assembly
assembly {
result := store
}
return result;
}
// UintSet
struct UintSet {
Set _inner;
}
/**
* @dev Add a value to a set. O(1).
*
* Returns true if the value was added to the set, that is if it was not
* already present.
*/
function add(UintSet storage set, uint256 value) internal returns (bool) {
return _add(set._inner, bytes32(value));
}
/**
* @dev Removes a value from a set. O(1).
*
* Returns true if the value was removed from the set, that is if it was
* present.
*/
function remove(UintSet storage set, uint256 value) internal returns (bool) {
return _remove(set._inner, bytes32(value));
}
/**
* @dev Returns true if the value is in the set. O(1).
*/
function contains(UintSet storage set, uint256 value) internal view returns (bool) {
return _contains(set._inner, bytes32(value));
}
/**
* @dev Returns the number of values in the set. O(1).
*/
function length(UintSet storage set) internal view returns (uint256) {
return _length(set._inner);
}
/**
* @dev Returns the value stored at position `index` in the set. O(1).
*
* Note that there are no guarantees on the ordering of values inside the
* array, and it may change when more values are added or removed.
*
* Requirements:
*
* - `index` must be strictly less than {length}.
*/
function at(UintSet storage set, uint256 index) internal view returns (uint256) {
return uint256(_at(set._inner, index));
}
/**
* @dev Return the entire set in an array
*
* WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
* to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
* this function has an unbounded cost, and using it as part of a state-changing function may render the function
* uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
*/
function values(UintSet storage set) internal view returns (uint256[] memory) {
bytes32[] memory store = _values(set._inner);
uint256[] memory result;
/// @solidity memory-safe-assembly
assembly {
result := store
}
return result;
}
}// SPDX-License-Identifier: MIT
pragma solidity >=0.8.19;
// Common.sol
//
// Common mathematical functions used in both SD59x18 and UD60x18. Note that these global functions do not
// always operate with SD59x18 and UD60x18 numbers.
/*//////////////////////////////////////////////////////////////////////////
CUSTOM ERRORS
//////////////////////////////////////////////////////////////////////////*/
/// @notice Thrown when the resultant value in {mulDiv} overflows uint256.
error PRBMath_MulDiv_Overflow(uint256 x, uint256 y, uint256 denominator);
/// @notice Thrown when the resultant value in {mulDiv18} overflows uint256.
error PRBMath_MulDiv18_Overflow(uint256 x, uint256 y);
/// @notice Thrown when one of the inputs passed to {mulDivSigned} is `type(int256).min`.
error PRBMath_MulDivSigned_InputTooSmall();
/// @notice Thrown when the resultant value in {mulDivSigned} overflows int256.
error PRBMath_MulDivSigned_Overflow(int256 x, int256 y);
/*//////////////////////////////////////////////////////////////////////////
CONSTANTS
//////////////////////////////////////////////////////////////////////////*/
/// @dev The maximum value a uint128 number can have.
uint128 constant MAX_UINT128 = type(uint128).max;
/// @dev The maximum value a uint40 number can have.
uint40 constant MAX_UINT40 = type(uint40).max;
/// @dev The unit number, which the decimal precision of the fixed-point types.
uint256 constant UNIT = 1e18;
/// @dev The unit number inverted mod 2^256.
uint256 constant UNIT_INVERSE = 78156646155174841979727994598816262306175212592076161876661_508869554232690281;
/// @dev The the largest power of two that divides the decimal value of `UNIT`. The logarithm of this value is the least significant
/// bit in the binary representation of `UNIT`.
uint256 constant UNIT_LPOTD = 262144;
/*//////////////////////////////////////////////////////////////////////////
FUNCTIONS
//////////////////////////////////////////////////////////////////////////*/
/// @notice Calculates the binary exponent of x using the binary fraction method.
/// @dev Has to use 192.64-bit fixed-point numbers. See https://ethereum.stackexchange.com/a/96594/24693.
/// @param x The exponent as an unsigned 192.64-bit fixed-point number.
/// @return result The result as an unsigned 60.18-decimal fixed-point number.
/// @custom:smtchecker abstract-function-nondet
function exp2(uint256 x) pure returns (uint256 result) {
unchecked {
// Start from 0.5 in the 192.64-bit fixed-point format.
result = 0x800000000000000000000000000000000000000000000000;
// The following logic multiplies the result by $\sqrt{2^{-i}}$ when the bit at position i is 1. Key points:
//
// 1. Intermediate results will not overflow, as the starting point is 2^191 and all magic factors are under 2^65.
// 2. The rationale for organizing the if statements into groups of 8 is gas savings. If the result of performing
// a bitwise AND operation between x and any value in the array [0x80; 0x40; 0x20; 0x10; 0x08; 0x04; 0x02; 0x01] is 1,
// we know that `x & 0xFF` is also 1.
if (x & 0xFF00000000000000 > 0) {
if (x & 0x8000000000000000 > 0) {
result = (result * 0x16A09E667F3BCC909) >> 64;
}
if (x & 0x4000000000000000 > 0) {
result = (result * 0x1306FE0A31B7152DF) >> 64;
}
if (x & 0x2000000000000000 > 0) {
result = (result * 0x1172B83C7D517ADCE) >> 64;
}
if (x & 0x1000000000000000 > 0) {
result = (result * 0x10B5586CF9890F62A) >> 64;
}
if (x & 0x800000000000000 > 0) {
result = (result * 0x1059B0D31585743AE) >> 64;
}
if (x & 0x400000000000000 > 0) {
result = (result * 0x102C9A3E778060EE7) >> 64;
}
if (x & 0x200000000000000 > 0) {
result = (result * 0x10163DA9FB33356D8) >> 64;
}
if (x & 0x100000000000000 > 0) {
result = (result * 0x100B1AFA5ABCBED61) >> 64;
}
}
if (x & 0xFF000000000000 > 0) {
if (x & 0x80000000000000 > 0) {
result = (result * 0x10058C86DA1C09EA2) >> 64;
}
if (x & 0x40000000000000 > 0) {
result = (result * 0x1002C605E2E8CEC50) >> 64;
}
if (x & 0x20000000000000 > 0) {
result = (result * 0x100162F3904051FA1) >> 64;
}
if (x & 0x10000000000000 > 0) {
result = (result * 0x1000B175EFFDC76BA) >> 64;
}
if (x & 0x8000000000000 > 0) {
result = (result * 0x100058BA01FB9F96D) >> 64;
}
if (x & 0x4000000000000 > 0) {
result = (result * 0x10002C5CC37DA9492) >> 64;
}
if (x & 0x2000000000000 > 0) {
result = (result * 0x1000162E525EE0547) >> 64;
}
if (x & 0x1000000000000 > 0) {
result = (result * 0x10000B17255775C04) >> 64;
}
}
if (x & 0xFF0000000000 > 0) {
if (x & 0x800000000000 > 0) {
result = (result * 0x1000058B91B5BC9AE) >> 64;
}
if (x & 0x400000000000 > 0) {
result = (result * 0x100002C5C89D5EC6D) >> 64;
}
if (x & 0x200000000000 > 0) {
result = (result * 0x10000162E43F4F831) >> 64;
}
if (x & 0x100000000000 > 0) {
result = (result * 0x100000B1721BCFC9A) >> 64;
}
if (x & 0x80000000000 > 0) {
result = (result * 0x10000058B90CF1E6E) >> 64;
}
if (x & 0x40000000000 > 0) {
result = (result * 0x1000002C5C863B73F) >> 64;
}
if (x & 0x20000000000 > 0) {
result = (result * 0x100000162E430E5A2) >> 64;
}
if (x & 0x10000000000 > 0) {
result = (result * 0x1000000B172183551) >> 64;
}
}
if (x & 0xFF00000000 > 0) {
if (x & 0x8000000000 > 0) {
result = (result * 0x100000058B90C0B49) >> 64;
}
if (x & 0x4000000000 > 0) {
result = (result * 0x10000002C5C8601CC) >> 64;
}
if (x & 0x2000000000 > 0) {
result = (result * 0x1000000162E42FFF0) >> 64;
}
if (x & 0x1000000000 > 0) {
result = (result * 0x10000000B17217FBB) >> 64;
}
if (x & 0x800000000 > 0) {
result = (result * 0x1000000058B90BFCE) >> 64;
}
if (x & 0x400000000 > 0) {
result = (result * 0x100000002C5C85FE3) >> 64;
}
if (x & 0x200000000 > 0) {
result = (result * 0x10000000162E42FF1) >> 64;
}
if (x & 0x100000000 > 0) {
result = (result * 0x100000000B17217F8) >> 64;
}
}
if (x & 0xFF000000 > 0) {
if (x & 0x80000000 > 0) {
result = (result * 0x10000000058B90BFC) >> 64;
}
if (x & 0x40000000 > 0) {
result = (result * 0x1000000002C5C85FE) >> 64;
}
if (x & 0x20000000 > 0) {
result = (result * 0x100000000162E42FF) >> 64;
}
if (x & 0x10000000 > 0) {
result = (result * 0x1000000000B17217F) >> 64;
}
if (x & 0x8000000 > 0) {
result = (result * 0x100000000058B90C0) >> 64;
}
if (x & 0x4000000 > 0) {
result = (result * 0x10000000002C5C860) >> 64;
}
if (x & 0x2000000 > 0) {
result = (result * 0x1000000000162E430) >> 64;
}
if (x & 0x1000000 > 0) {
result = (result * 0x10000000000B17218) >> 64;
}
}
if (x & 0xFF0000 > 0) {
if (x & 0x800000 > 0) {
result = (result * 0x1000000000058B90C) >> 64;
}
if (x & 0x400000 > 0) {
result = (result * 0x100000000002C5C86) >> 64;
}
if (x & 0x200000 > 0) {
result = (result * 0x10000000000162E43) >> 64;
}
if (x & 0x100000 > 0) {
result = (result * 0x100000000000B1721) >> 64;
}
if (x & 0x80000 > 0) {
result = (result * 0x10000000000058B91) >> 64;
}
if (x & 0x40000 > 0) {
result = (result * 0x1000000000002C5C8) >> 64;
}
if (x & 0x20000 > 0) {
result = (result * 0x100000000000162E4) >> 64;
}
if (x & 0x10000 > 0) {
result = (result * 0x1000000000000B172) >> 64;
}
}
if (x & 0xFF00 > 0) {
if (x & 0x8000 > 0) {
result = (result * 0x100000000000058B9) >> 64;
}
if (x & 0x4000 > 0) {
result = (result * 0x10000000000002C5D) >> 64;
}
if (x & 0x2000 > 0) {
result = (result * 0x1000000000000162E) >> 64;
}
if (x & 0x1000 > 0) {
result = (result * 0x10000000000000B17) >> 64;
}
if (x & 0x800 > 0) {
result = (result * 0x1000000000000058C) >> 64;
}
if (x & 0x400 > 0) {
result = (result * 0x100000000000002C6) >> 64;
}
if (x & 0x200 > 0) {
result = (result * 0x10000000000000163) >> 64;
}
if (x & 0x100 > 0) {
result = (result * 0x100000000000000B1) >> 64;
}
}
if (x & 0xFF > 0) {
if (x & 0x80 > 0) {
result = (result * 0x10000000000000059) >> 64;
}
if (x & 0x40 > 0) {
result = (result * 0x1000000000000002C) >> 64;
}
if (x & 0x20 > 0) {
result = (result * 0x10000000000000016) >> 64;
}
if (x & 0x10 > 0) {
result = (result * 0x1000000000000000B) >> 64;
}
if (x & 0x8 > 0) {
result = (result * 0x10000000000000006) >> 64;
}
if (x & 0x4 > 0) {
result = (result * 0x10000000000000003) >> 64;
}
if (x & 0x2 > 0) {
result = (result * 0x10000000000000001) >> 64;
}
if (x & 0x1 > 0) {
result = (result * 0x10000000000000001) >> 64;
}
}
// In the code snippet below, two operations are executed simultaneously:
//
// 1. The result is multiplied by $(2^n + 1)$, where $2^n$ represents the integer part, and the additional 1
// accounts for the initial guess of 0.5. This is achieved by subtracting from 191 instead of 192.
// 2. The result is then converted to an unsigned 60.18-decimal fixed-point format.
//
// The underlying logic is based on the relationship $2^{191-ip} = 2^{ip} / 2^{191}$, where $ip$ denotes the,
// integer part, $2^n$.
result *= UNIT;
result >>= (191 - (x >> 64));
}
}
/// @notice Finds the zero-based index of the first 1 in the binary representation of x.
///
/// @dev See the note on "msb" in this Wikipedia article: https://en.wikipedia.org/wiki/Find_first_set
///
/// Each step in this implementation is equivalent to this high-level code:
///
/// ```solidity
/// if (x >= 2 ** 128) {
/// x >>= 128;
/// result += 128;
/// }
/// ```
///
/// Where 128 is replaced with each respective power of two factor. See the full high-level implementation here:
/// https://gist.github.com/PaulRBerg/f932f8693f2733e30c4d479e8e980948
///
/// The Yul instructions used below are:
///
/// - "gt" is "greater than"
/// - "or" is the OR bitwise operator
/// - "shl" is "shift left"
/// - "shr" is "shift right"
///
/// @param x The uint256 number for which to find the index of the most significant bit.
/// @return result The index of the most significant bit as a uint256.
/// @custom:smtchecker abstract-function-nondet
function msb(uint256 x) pure returns (uint256 result) {
// 2^128
assembly ("memory-safe") {
let factor := shl(7, gt(x, 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF))
x := shr(factor, x)
result := or(result, factor)
}
// 2^64
assembly ("memory-safe") {
let factor := shl(6, gt(x, 0xFFFFFFFFFFFFFFFF))
x := shr(factor, x)
result := or(result, factor)
}
// 2^32
assembly ("memory-safe") {
let factor := shl(5, gt(x, 0xFFFFFFFF))
x := shr(factor, x)
result := or(result, factor)
}
// 2^16
assembly ("memory-safe") {
let factor := shl(4, gt(x, 0xFFFF))
x := shr(factor, x)
result := or(result, factor)
}
// 2^8
assembly ("memory-safe") {
let factor := shl(3, gt(x, 0xFF))
x := shr(factor, x)
result := or(result, factor)
}
// 2^4
assembly ("memory-safe") {
let factor := shl(2, gt(x, 0xF))
x := shr(factor, x)
result := or(result, factor)
}
// 2^2
assembly ("memory-safe") {
let factor := shl(1, gt(x, 0x3))
x := shr(factor, x)
result := or(result, factor)
}
// 2^1
// No need to shift x any more.
assembly ("memory-safe") {
let factor := gt(x, 0x1)
result := or(result, factor)
}
}
/// @notice Calculates x*y÷denominator with 512-bit precision.
///
/// @dev Credits to Remco Bloemen under MIT license https://xn--2-umb.com/21/muldiv.
///
/// Notes:
/// - The result is rounded toward zero.
///
/// Requirements:
/// - The denominator must not be zero.
/// - The result must fit in uint256.
///
/// @param x The multiplicand as a uint256.
/// @param y The multiplier as a uint256.
/// @param denominator The divisor as a uint256.
/// @return result The result as a uint256.
/// @custom:smtchecker abstract-function-nondet
function mulDiv(uint256 x, uint256 y, uint256 denominator) pure returns (uint256 result) {
// 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; // Least significant 256 bits of the product
uint256 prod1; // Most significant 256 bits of the product
assembly ("memory-safe") {
let mm := mulmod(x, y, not(0))
prod0 := mul(x, y)
prod1 := sub(sub(mm, prod0), lt(mm, prod0))
}
// Handle non-overflow cases, 256 by 256 division.
if (prod1 == 0) {
unchecked {
return prod0 / denominator;
}
}
// Make sure the result is less than 2^256. Also prevents denominator == 0.
if (prod1 >= denominator) {
revert PRBMath_MulDiv_Overflow(x, y, denominator);
}
////////////////////////////////////////////////////////////////////////////
// 512 by 256 division
////////////////////////////////////////////////////////////////////////////
// Make division exact by subtracting the remainder from [prod1 prod0].
uint256 remainder;
assembly ("memory-safe") {
// Compute remainder using the mulmod Yul instruction.
remainder := mulmod(x, y, denominator)
// Subtract 256 bit number from 512-bit number.
prod1 := sub(prod1, gt(remainder, prod0))
prod0 := sub(prod0, remainder)
}
unchecked {
// Calculate the largest power of two divisor of the denominator using the unary operator ~. This operation cannot overflow
// because the denominator cannot be zero at this point in the function execution. The result is always >= 1.
// For more detail, see https://cs.stackexchange.com/q/138556/92363.
uint256 lpotdod = denominator & (~denominator + 1);
uint256 flippedLpotdod;
assembly ("memory-safe") {
// Factor powers of two out of denominator.
denominator := div(denominator, lpotdod)
// Divide [prod1 prod0] by lpotdod.
prod0 := div(prod0, lpotdod)
// Get the flipped value `2^256 / lpotdod`. If the `lpotdod` is zero, the flipped value is one.
// `sub(0, lpotdod)` produces the two's complement version of `lpotdod`, which is equivalent to flipping all the bits.
// However, `div` interprets this value as an unsigned value: https://ethereum.stackexchange.com/q/147168/24693
flippedLpotdod := add(div(sub(0, lpotdod), lpotdod), 1)
}
// Shift in bits from prod1 into prod0.
prod0 |= prod1 * flippedLpotdod;
// 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;
}
}
/// @notice Calculates x*y÷1e18 with 512-bit precision.
///
/// @dev A variant of {mulDiv} with constant folding, i.e. in which the denominator is hard coded to 1e18.
///
/// Notes:
/// - The body is purposely left uncommented; to understand how this works, see the documentation in {mulDiv}.
/// - The result is rounded toward zero.
/// - We take as an axiom that the result cannot be `MAX_UINT256` when x and y solve the following system of equations:
///
/// $$
/// \begin{cases}
/// x * y = MAX\_UINT256 * UNIT \\
/// (x * y) \% UNIT \geq \frac{UNIT}{2}
/// \end{cases}
/// $$
///
/// Requirements:
/// - Refer to the requirements in {mulDiv}.
/// - The result must fit in uint256.
///
/// @param x The multiplicand as an unsigned 60.18-decimal fixed-point number.
/// @param y The multiplier as an unsigned 60.18-decimal fixed-point number.
/// @return result The result as an unsigned 60.18-decimal fixed-point number.
/// @custom:smtchecker abstract-function-nondet
function mulDiv18(uint256 x, uint256 y) pure returns (uint256 result) {
uint256 prod0;
uint256 prod1;
assembly ("memory-safe") {
let mm := mulmod(x, y, not(0))
prod0 := mul(x, y)
prod1 := sub(sub(mm, prod0), lt(mm, prod0))
}
if (prod1 == 0) {
unchecked {
return prod0 / UNIT;
}
}
if (prod1 >= UNIT) {
revert PRBMath_MulDiv18_Overflow(x, y);
}
uint256 remainder;
assembly ("memory-safe") {
remainder := mulmod(x, y, UNIT)
result :=
mul(
or(
div(sub(prod0, remainder), UNIT_LPOTD),
mul(sub(prod1, gt(remainder, prod0)), add(div(sub(0, UNIT_LPOTD), UNIT_LPOTD), 1))
),
UNIT_INVERSE
)
}
}
/// @notice Calculates x*y÷denominator with 512-bit precision.
///
/// @dev This is an extension of {mulDiv} for signed numbers, which works by computing the signs and the absolute values separately.
///
/// Notes:
/// - The result is rounded toward zero.
///
/// Requirements:
/// - Refer to the requirements in {mulDiv}.
/// - None of the inputs can be `type(int256).min`.
/// - The result must fit in int256.
///
/// @param x The multiplicand as an int256.
/// @param y The multiplier as an int256.
/// @param denominator The divisor as an int256.
/// @return result The result as an int256.
/// @custom:smtchecker abstract-function-nondet
function mulDivSigned(int256 x, int256 y, int256 denominator) pure returns (int256 result) {
if (x == type(int256).min || y == type(int256).min || denominator == type(int256).min) {
revert PRBMath_MulDivSigned_InputTooSmall();
}
// Get hold of the absolute values of x, y and the denominator.
uint256 xAbs;
uint256 yAbs;
uint256 dAbs;
unchecked {
xAbs = x < 0 ? uint256(-x) : uint256(x);
yAbs = y < 0 ? uint256(-y) : uint256(y);
dAbs = denominator < 0 ? uint256(-denominator) : uint256(denominator);
}
// Compute the absolute value of x*y÷denominator. The result must fit in int256.
uint256 resultAbs = mulDiv(xAbs, yAbs, dAbs);
if (resultAbs > uint256(type(int256).max)) {
revert PRBMath_MulDivSigned_Overflow(x, y);
}
// Get the signs of x, y and the denominator.
uint256 sx;
uint256 sy;
uint256 sd;
assembly ("memory-safe") {
// "sgt" is the "signed greater than" assembly instruction and "sub(0,1)" is -1 in two's complement.
sx := sgt(x, sub(0, 1))
sy := sgt(y, sub(0, 1))
sd := sgt(denominator, sub(0, 1))
}
// XOR over sx, sy and sd. What this does is to check whether there are 1 or 3 negative signs in the inputs.
// If there are, the result should be negative. Otherwise, it should be positive.
unchecked {
result = sx ^ sy ^ sd == 0 ? -int256(resultAbs) : int256(resultAbs);
}
}
/// @notice Calculates the square root of x using the Babylonian method.
///
/// @dev See https://en.wikipedia.org/wiki/Methods_of_computing_square_roots#Babylonian_method.
///
/// Notes:
/// - If x is not a perfect square, the result is rounded down.
/// - Credits to OpenZeppelin for the explanations in comments below.
///
/// @param x The uint256 number for which to calculate the square root.
/// @return result The result as a uint256.
/// @custom:smtchecker abstract-function-nondet
function sqrt(uint256 x) pure returns (uint256 result) {
if (x == 0) {
return 0;
}
// For our first guess, we calculate the biggest power of 2 which is smaller than the square root of x.
//
// We know that the "msb" (most significant bit) of x is a power of 2 such that we have:
//
// $$
// msb(x) <= x <= 2*msb(x)$
// $$
//
// We write $msb(x)$ as $2^k$, and we get:
//
// $$
// k = log_2(x)
// $$
//
// Thus, we can write the initial inequality as:
//
// $$
// 2^{log_2(x)} <= x <= 2*2^{log_2(x)+1} \\
// sqrt(2^k) <= sqrt(x) < sqrt(2^{k+1}) \\
// 2^{k/2} <= sqrt(x) < 2^{(k+1)/2} <= 2^{(k/2)+1}
// $$
//
// Consequently, $2^{log_2(x) /2} is a good first approximation of sqrt(x) with at least one correct bit.
uint256 xAux = uint256(x);
result = 1;
if (xAux >= 2 ** 128) {
xAux >>= 128;
result <<= 64;
}
if (xAux >= 2 ** 64) {
xAux >>= 64;
result <<= 32;
}
if (xAux >= 2 ** 32) {
xAux >>= 32;
result <<= 16;
}
if (xAux >= 2 ** 16) {
xAux >>= 16;
result <<= 8;
}
if (xAux >= 2 ** 8) {
xAux >>= 8;
result <<= 4;
}
if (xAux >= 2 ** 4) {
xAux >>= 4;
result <<= 2;
}
if (xAux >= 2 ** 2) {
result <<= 1;
}
// At this point, `result` is an estimation with at least one bit of precision. We know the true value has at
// most 128 bits, 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 + x / result) >> 1;
result = (result + x / result) >> 1;
result = (result + x / result) >> 1;
result = (result + x / result) >> 1;
result = (result + x / result) >> 1;
result = (result + x / result) >> 1;
result = (result + x / result) >> 1;
// If x is not a perfect square, round the result toward zero.
uint256 roundedResult = x / result;
if (result >= roundedResult) {
result = roundedResult;
}
}
}// SPDX-License-Identifier: MIT pragma solidity >=0.8.19; /* ██████╗ ██████╗ ██████╗ ███╗ ███╗ █████╗ ████████╗██╗ ██╗ ██╔══██╗██╔══██╗██╔══██╗████╗ ████║██╔══██╗╚══██╔══╝██║ ██║ ██████╔╝██████╔╝██████╔╝██╔████╔██║███████║ ██║ ███████║ ██╔═══╝ ██╔══██╗██╔══██╗██║╚██╔╝██║██╔══██║ ██║ ██╔══██║ ██║ ██║ ██║██████╔╝██║ ╚═╝ ██║██║ ██║ ██║ ██║ ██║ ╚═╝ ╚═╝ ╚═╝╚═════╝ ╚═╝ ╚═╝╚═╝ ╚═╝ ╚═╝ ╚═╝ ╚═╝ ██╗ ██╗██████╗ ██████╗ ██████╗ ██╗ ██╗ ██╗ █████╗ ██║ ██║██╔══██╗██╔════╝ ██╔═████╗╚██╗██╔╝███║██╔══██╗ ██║ ██║██║ ██║███████╗ ██║██╔██║ ╚███╔╝ ╚██║╚█████╔╝ ██║ ██║██║ ██║██╔═══██╗████╔╝██║ ██╔██╗ ██║██╔══██╗ ╚██████╔╝██████╔╝╚██████╔╝╚██████╔╝██╔╝ ██╗ ██║╚█████╔╝ ╚═════╝ ╚═════╝ ╚═════╝ ╚═════╝ ╚═╝ ╚═╝ ╚═╝ ╚════╝ */ import "./ud60x18/Casting.sol"; import "./ud60x18/Constants.sol"; import "./ud60x18/Conversions.sol"; import "./ud60x18/Errors.sol"; import "./ud60x18/Helpers.sol"; import "./ud60x18/Math.sol"; import "./ud60x18/ValueType.sol";
// SPDX-License-Identifier: MIT
pragma solidity >=0.8.19;
import "../Common.sol" as Common;
import "./Errors.sol" as CastingErrors;
import { SD59x18 } from "../sd59x18/ValueType.sol";
import { UD2x18 } from "../ud2x18/ValueType.sol";
import { UD60x18 } from "../ud60x18/ValueType.sol";
import { SD1x18 } from "./ValueType.sol";
/// @notice Casts an SD1x18 number into SD59x18.
/// @dev There is no overflow check because the domain of SD1x18 is a subset of SD59x18.
function intoSD59x18(SD1x18 x) pure returns (SD59x18 result) {
result = SD59x18.wrap(int256(SD1x18.unwrap(x)));
}
/// @notice Casts an SD1x18 number into UD2x18.
/// - x must be positive.
function intoUD2x18(SD1x18 x) pure returns (UD2x18 result) {
int64 xInt = SD1x18.unwrap(x);
if (xInt < 0) {
revert CastingErrors.PRBMath_SD1x18_ToUD2x18_Underflow(x);
}
result = UD2x18.wrap(uint64(xInt));
}
/// @notice Casts an SD1x18 number into UD60x18.
/// @dev Requirements:
/// - x must be positive.
function intoUD60x18(SD1x18 x) pure returns (UD60x18 result) {
int64 xInt = SD1x18.unwrap(x);
if (xInt < 0) {
revert CastingErrors.PRBMath_SD1x18_ToUD60x18_Underflow(x);
}
result = UD60x18.wrap(uint64(xInt));
}
/// @notice Casts an SD1x18 number into uint256.
/// @dev Requirements:
/// - x must be positive.
function intoUint256(SD1x18 x) pure returns (uint256 result) {
int64 xInt = SD1x18.unwrap(x);
if (xInt < 0) {
revert CastingErrors.PRBMath_SD1x18_ToUint256_Underflow(x);
}
result = uint256(uint64(xInt));
}
/// @notice Casts an SD1x18 number into uint128.
/// @dev Requirements:
/// - x must be positive.
function intoUint128(SD1x18 x) pure returns (uint128 result) {
int64 xInt = SD1x18.unwrap(x);
if (xInt < 0) {
revert CastingErrors.PRBMath_SD1x18_ToUint128_Underflow(x);
}
result = uint128(uint64(xInt));
}
/// @notice Casts an SD1x18 number into uint40.
/// @dev Requirements:
/// - x must be positive.
/// - x must be less than or equal to `MAX_UINT40`.
function intoUint40(SD1x18 x) pure returns (uint40 result) {
int64 xInt = SD1x18.unwrap(x);
if (xInt < 0) {
revert CastingErrors.PRBMath_SD1x18_ToUint40_Underflow(x);
}
if (xInt > int64(uint64(Common.MAX_UINT40))) {
revert CastingErrors.PRBMath_SD1x18_ToUint40_Overflow(x);
}
result = uint40(uint64(xInt));
}
/// @notice Alias for {wrap}.
function sd1x18(int64 x) pure returns (SD1x18 result) {
result = SD1x18.wrap(x);
}
/// @notice Unwraps an SD1x18 number into int64.
function unwrap(SD1x18 x) pure returns (int64 result) {
result = SD1x18.unwrap(x);
}
/// @notice Wraps an int64 number into SD1x18.
function wrap(int64 x) pure returns (SD1x18 result) {
result = SD1x18.wrap(x);
}// SPDX-License-Identifier: MIT
pragma solidity >=0.8.19;
import { SD1x18 } from "./ValueType.sol";
/// @dev Euler's number as an SD1x18 number.
SD1x18 constant E = SD1x18.wrap(2_718281828459045235);
/// @dev The maximum value an SD1x18 number can have.
int64 constant uMAX_SD1x18 = 9_223372036854775807;
SD1x18 constant MAX_SD1x18 = SD1x18.wrap(uMAX_SD1x18);
/// @dev The maximum value an SD1x18 number can have.
int64 constant uMIN_SD1x18 = -9_223372036854775808;
SD1x18 constant MIN_SD1x18 = SD1x18.wrap(uMIN_SD1x18);
/// @dev PI as an SD1x18 number.
SD1x18 constant PI = SD1x18.wrap(3_141592653589793238);
/// @dev The unit number, which gives the decimal precision of SD1x18.
SD1x18 constant UNIT = SD1x18.wrap(1e18);
int256 constant uUNIT = 1e18;// SPDX-License-Identifier: MIT
pragma solidity >=0.8.19;
import { SD1x18 } from "./ValueType.sol";
/// @notice Thrown when trying to cast a SD1x18 number that doesn't fit in UD2x18.
error PRBMath_SD1x18_ToUD2x18_Underflow(SD1x18 x);
/// @notice Thrown when trying to cast a SD1x18 number that doesn't fit in UD60x18.
error PRBMath_SD1x18_ToUD60x18_Underflow(SD1x18 x);
/// @notice Thrown when trying to cast a SD1x18 number that doesn't fit in uint128.
error PRBMath_SD1x18_ToUint128_Underflow(SD1x18 x);
/// @notice Thrown when trying to cast a SD1x18 number that doesn't fit in uint256.
error PRBMath_SD1x18_ToUint256_Underflow(SD1x18 x);
/// @notice Thrown when trying to cast a SD1x18 number that doesn't fit in uint40.
error PRBMath_SD1x18_ToUint40_Overflow(SD1x18 x);
/// @notice Thrown when trying to cast a SD1x18 number that doesn't fit in uint40.
error PRBMath_SD1x18_ToUint40_Underflow(SD1x18 x);// SPDX-License-Identifier: MIT
pragma solidity >=0.8.19;
import "./Casting.sol" as Casting;
/// @notice The signed 1.18-decimal fixed-point number representation, which can have up to 1 digit and up to 18
/// decimals. The values of this are bound by the minimum and the maximum values permitted by the underlying Solidity
/// type int64. This is useful when end users want to use int64 to save gas, e.g. with tight variable packing in contract
/// storage.
type SD1x18 is int64;
/*//////////////////////////////////////////////////////////////////////////
CASTING
//////////////////////////////////////////////////////////////////////////*/
using {
Casting.intoSD59x18,
Casting.intoUD2x18,
Casting.intoUD60x18,
Casting.intoUint256,
Casting.intoUint128,
Casting.intoUint40,
Casting.unwrap
} for SD1x18 global;// SPDX-License-Identifier: MIT
pragma solidity >=0.8.19;
import "./Errors.sol" as CastingErrors;
import { MAX_UINT128, MAX_UINT40 } from "../Common.sol";
import { uMAX_SD1x18, uMIN_SD1x18 } from "../sd1x18/Constants.sol";
import { SD1x18 } from "../sd1x18/ValueType.sol";
import { uMAX_UD2x18 } from "../ud2x18/Constants.sol";
import { UD2x18 } from "../ud2x18/ValueType.sol";
import { UD60x18 } from "../ud60x18/ValueType.sol";
import { SD59x18 } from "./ValueType.sol";
/// @notice Casts an SD59x18 number into int256.
/// @dev This is basically a functional alias for {unwrap}.
function intoInt256(SD59x18 x) pure returns (int256 result) {
result = SD59x18.unwrap(x);
}
/// @notice Casts an SD59x18 number into SD1x18.
/// @dev Requirements:
/// - x must be greater than or equal to `uMIN_SD1x18`.
/// - x must be less than or equal to `uMAX_SD1x18`.
function intoSD1x18(SD59x18 x) pure returns (SD1x18 result) {
int256 xInt = SD59x18.unwrap(x);
if (xInt < uMIN_SD1x18) {
revert CastingErrors.PRBMath_SD59x18_IntoSD1x18_Underflow(x);
}
if (xInt > uMAX_SD1x18) {
revert CastingErrors.PRBMath_SD59x18_IntoSD1x18_Overflow(x);
}
result = SD1x18.wrap(int64(xInt));
}
/// @notice Casts an SD59x18 number into UD2x18.
/// @dev Requirements:
/// - x must be positive.
/// - x must be less than or equal to `uMAX_UD2x18`.
function intoUD2x18(SD59x18 x) pure returns (UD2x18 result) {
int256 xInt = SD59x18.unwrap(x);
if (xInt < 0) {
revert CastingErrors.PRBMath_SD59x18_IntoUD2x18_Underflow(x);
}
if (xInt > int256(uint256(uMAX_UD2x18))) {
revert CastingErrors.PRBMath_SD59x18_IntoUD2x18_Overflow(x);
}
result = UD2x18.wrap(uint64(uint256(xInt)));
}
/// @notice Casts an SD59x18 number into UD60x18.
/// @dev Requirements:
/// - x must be positive.
function intoUD60x18(SD59x18 x) pure returns (UD60x18 result) {
int256 xInt = SD59x18.unwrap(x);
if (xInt < 0) {
revert CastingErrors.PRBMath_SD59x18_IntoUD60x18_Underflow(x);
}
result = UD60x18.wrap(uint256(xInt));
}
/// @notice Casts an SD59x18 number into uint256.
/// @dev Requirements:
/// - x must be positive.
function intoUint256(SD59x18 x) pure returns (uint256 result) {
int256 xInt = SD59x18.unwrap(x);
if (xInt < 0) {
revert CastingErrors.PRBMath_SD59x18_IntoUint256_Underflow(x);
}
result = uint256(xInt);
}
/// @notice Casts an SD59x18 number into uint128.
/// @dev Requirements:
/// - x must be positive.
/// - x must be less than or equal to `uMAX_UINT128`.
function intoUint128(SD59x18 x) pure returns (uint128 result) {
int256 xInt = SD59x18.unwrap(x);
if (xInt < 0) {
revert CastingErrors.PRBMath_SD59x18_IntoUint128_Underflow(x);
}
if (xInt > int256(uint256(MAX_UINT128))) {
revert CastingErrors.PRBMath_SD59x18_IntoUint128_Overflow(x);
}
result = uint128(uint256(xInt));
}
/// @notice Casts an SD59x18 number into uint40.
/// @dev Requirements:
/// - x must be positive.
/// - x must be less than or equal to `MAX_UINT40`.
function intoUint40(SD59x18 x) pure returns (uint40 result) {
int256 xInt = SD59x18.unwrap(x);
if (xInt < 0) {
revert CastingErrors.PRBMath_SD59x18_IntoUint40_Underflow(x);
}
if (xInt > int256(uint256(MAX_UINT40))) {
revert CastingErrors.PRBMath_SD59x18_IntoUint40_Overflow(x);
}
result = uint40(uint256(xInt));
}
/// @notice Alias for {wrap}.
function sd(int256 x) pure returns (SD59x18 result) {
result = SD59x18.wrap(x);
}
/// @notice Alias for {wrap}.
function sd59x18(int256 x) pure returns (SD59x18 result) {
result = SD59x18.wrap(x);
}
/// @notice Unwraps an SD59x18 number into int256.
function unwrap(SD59x18 x) pure returns (int256 result) {
result = SD59x18.unwrap(x);
}
/// @notice Wraps an int256 number into SD59x18.
function wrap(int256 x) pure returns (SD59x18 result) {
result = SD59x18.wrap(x);
}// SPDX-License-Identifier: MIT
pragma solidity >=0.8.19;
import { SD59x18 } from "./ValueType.sol";
// NOTICE: the "u" prefix stands for "unwrapped".
/// @dev Euler's number as an SD59x18 number.
SD59x18 constant E = SD59x18.wrap(2_718281828459045235);
/// @dev The maximum input permitted in {exp}.
int256 constant uEXP_MAX_INPUT = 133_084258667509499440;
SD59x18 constant EXP_MAX_INPUT = SD59x18.wrap(uEXP_MAX_INPUT);
/// @dev The maximum input permitted in {exp2}.
int256 constant uEXP2_MAX_INPUT = 192e18 - 1;
SD59x18 constant EXP2_MAX_INPUT = SD59x18.wrap(uEXP2_MAX_INPUT);
/// @dev Half the UNIT number.
int256 constant uHALF_UNIT = 0.5e18;
SD59x18 constant HALF_UNIT = SD59x18.wrap(uHALF_UNIT);
/// @dev $log_2(10)$ as an SD59x18 number.
int256 constant uLOG2_10 = 3_321928094887362347;
SD59x18 constant LOG2_10 = SD59x18.wrap(uLOG2_10);
/// @dev $log_2(e)$ as an SD59x18 number.
int256 constant uLOG2_E = 1_442695040888963407;
SD59x18 constant LOG2_E = SD59x18.wrap(uLOG2_E);
/// @dev The maximum value an SD59x18 number can have.
int256 constant uMAX_SD59x18 = 57896044618658097711785492504343953926634992332820282019728_792003956564819967;
SD59x18 constant MAX_SD59x18 = SD59x18.wrap(uMAX_SD59x18);
/// @dev The maximum whole value an SD59x18 number can have.
int256 constant uMAX_WHOLE_SD59x18 = 57896044618658097711785492504343953926634992332820282019728_000000000000000000;
SD59x18 constant MAX_WHOLE_SD59x18 = SD59x18.wrap(uMAX_WHOLE_SD59x18);
/// @dev The minimum value an SD59x18 number can have.
int256 constant uMIN_SD59x18 = -57896044618658097711785492504343953926634992332820282019728_792003956564819968;
SD59x18 constant MIN_SD59x18 = SD59x18.wrap(uMIN_SD59x18);
/// @dev The minimum whole value an SD59x18 number can have.
int256 constant uMIN_WHOLE_SD59x18 = -57896044618658097711785492504343953926634992332820282019728_000000000000000000;
SD59x18 constant MIN_WHOLE_SD59x18 = SD59x18.wrap(uMIN_WHOLE_SD59x18);
/// @dev PI as an SD59x18 number.
SD59x18 constant PI = SD59x18.wrap(3_141592653589793238);
/// @dev The unit number, which gives the decimal precision of SD59x18.
int256 constant uUNIT = 1e18;
SD59x18 constant UNIT = SD59x18.wrap(1e18);
/// @dev The unit number squared.
int256 constant uUNIT_SQUARED = 1e36;
SD59x18 constant UNIT_SQUARED = SD59x18.wrap(uUNIT_SQUARED);
/// @dev Zero as an SD59x18 number.
SD59x18 constant ZERO = SD59x18.wrap(0);// SPDX-License-Identifier: MIT
pragma solidity >=0.8.19;
import { SD59x18 } from "./ValueType.sol";
/// @notice Thrown when taking the absolute value of `MIN_SD59x18`.
error PRBMath_SD59x18_Abs_MinSD59x18();
/// @notice Thrown when ceiling a number overflows SD59x18.
error PRBMath_SD59x18_Ceil_Overflow(SD59x18 x);
/// @notice Thrown when converting a basic integer to the fixed-point format overflows SD59x18.
error PRBMath_SD59x18_Convert_Overflow(int256 x);
/// @notice Thrown when converting a basic integer to the fixed-point format underflows SD59x18.
error PRBMath_SD59x18_Convert_Underflow(int256 x);
/// @notice Thrown when dividing two numbers and one of them is `MIN_SD59x18`.
error PRBMath_SD59x18_Div_InputTooSmall();
/// @notice Thrown when dividing two numbers and one of the intermediary unsigned results overflows SD59x18.
error PRBMath_SD59x18_Div_Overflow(SD59x18 x, SD59x18 y);
/// @notice Thrown when taking the natural exponent of a base greater than 133_084258667509499441.
error PRBMath_SD59x18_Exp_InputTooBig(SD59x18 x);
/// @notice Thrown when taking the binary exponent of a base greater than 192e18.
error PRBMath_SD59x18_Exp2_InputTooBig(SD59x18 x);
/// @notice Thrown when flooring a number underflows SD59x18.
error PRBMath_SD59x18_Floor_Underflow(SD59x18 x);
/// @notice Thrown when taking the geometric mean of two numbers and their product is negative.
error PRBMath_SD59x18_Gm_NegativeProduct(SD59x18 x, SD59x18 y);
/// @notice Thrown when taking the geometric mean of two numbers and multiplying them overflows SD59x18.
error PRBMath_SD59x18_Gm_Overflow(SD59x18 x, SD59x18 y);
/// @notice Thrown when trying to cast a UD60x18 number that doesn't fit in SD1x18.
error PRBMath_SD59x18_IntoSD1x18_Overflow(SD59x18 x);
/// @notice Thrown when trying to cast a UD60x18 number that doesn't fit in SD1x18.
error PRBMath_SD59x18_IntoSD1x18_Underflow(SD59x18 x);
/// @notice Thrown when trying to cast a UD60x18 number that doesn't fit in UD2x18.
error PRBMath_SD59x18_IntoUD2x18_Overflow(SD59x18 x);
/// @notice Thrown when trying to cast a UD60x18 number that doesn't fit in UD2x18.
error PRBMath_SD59x18_IntoUD2x18_Underflow(SD59x18 x);
/// @notice Thrown when trying to cast a UD60x18 number that doesn't fit in UD60x18.
error PRBMath_SD59x18_IntoUD60x18_Underflow(SD59x18 x);
/// @notice Thrown when trying to cast a UD60x18 number that doesn't fit in uint128.
error PRBMath_SD59x18_IntoUint128_Overflow(SD59x18 x);
/// @notice Thrown when trying to cast a UD60x18 number that doesn't fit in uint128.
error PRBMath_SD59x18_IntoUint128_Underflow(SD59x18 x);
/// @notice Thrown when trying to cast a UD60x18 number that doesn't fit in uint256.
error PRBMath_SD59x18_IntoUint256_Underflow(SD59x18 x);
/// @notice Thrown when trying to cast a UD60x18 number that doesn't fit in uint40.
error PRBMath_SD59x18_IntoUint40_Overflow(SD59x18 x);
/// @notice Thrown when trying to cast a UD60x18 number that doesn't fit in uint40.
error PRBMath_SD59x18_IntoUint40_Underflow(SD59x18 x);
/// @notice Thrown when taking the logarithm of a number less than or equal to zero.
error PRBMath_SD59x18_Log_InputTooSmall(SD59x18 x);
/// @notice Thrown when multiplying two numbers and one of the inputs is `MIN_SD59x18`.
error PRBMath_SD59x18_Mul_InputTooSmall();
/// @notice Thrown when multiplying two numbers and the intermediary absolute result overflows SD59x18.
error PRBMath_SD59x18_Mul_Overflow(SD59x18 x, SD59x18 y);
/// @notice Thrown when raising a number to a power and the intermediary absolute result overflows SD59x18.
error PRBMath_SD59x18_Powu_Overflow(SD59x18 x, uint256 y);
/// @notice Thrown when taking the square root of a negative number.
error PRBMath_SD59x18_Sqrt_NegativeInput(SD59x18 x);
/// @notice Thrown when the calculating the square root overflows SD59x18.
error PRBMath_SD59x18_Sqrt_Overflow(SD59x18 x);// SPDX-License-Identifier: MIT
pragma solidity >=0.8.19;
import { wrap } from "./Casting.sol";
import { SD59x18 } from "./ValueType.sol";
/// @notice Implements the checked addition operation (+) in the SD59x18 type.
function add(SD59x18 x, SD59x18 y) pure returns (SD59x18 result) {
return wrap(x.unwrap() + y.unwrap());
}
/// @notice Implements the AND (&) bitwise operation in the SD59x18 type.
function and(SD59x18 x, int256 bits) pure returns (SD59x18 result) {
return wrap(x.unwrap() & bits);
}
/// @notice Implements the AND (&) bitwise operation in the SD59x18 type.
function and2(SD59x18 x, SD59x18 y) pure returns (SD59x18 result) {
return wrap(x.unwrap() & y.unwrap());
}
/// @notice Implements the equal (=) operation in the SD59x18 type.
function eq(SD59x18 x, SD59x18 y) pure returns (bool result) {
result = x.unwrap() == y.unwrap();
}
/// @notice Implements the greater than operation (>) in the SD59x18 type.
function gt(SD59x18 x, SD59x18 y) pure returns (bool result) {
result = x.unwrap() > y.unwrap();
}
/// @notice Implements the greater than or equal to operation (>=) in the SD59x18 type.
function gte(SD59x18 x, SD59x18 y) pure returns (bool result) {
result = x.unwrap() >= y.unwrap();
}
/// @notice Implements a zero comparison check function in the SD59x18 type.
function isZero(SD59x18 x) pure returns (bool result) {
result = x.unwrap() == 0;
}
/// @notice Implements the left shift operation (<<) in the SD59x18 type.
function lshift(SD59x18 x, uint256 bits) pure returns (SD59x18 result) {
result = wrap(x.unwrap() << bits);
}
/// @notice Implements the lower than operation (<) in the SD59x18 type.
function lt(SD59x18 x, SD59x18 y) pure returns (bool result) {
result = x.unwrap() < y.unwrap();
}
/// @notice Implements the lower than or equal to operation (<=) in the SD59x18 type.
function lte(SD59x18 x, SD59x18 y) pure returns (bool result) {
result = x.unwrap() <= y.unwrap();
}
/// @notice Implements the unchecked modulo operation (%) in the SD59x18 type.
function mod(SD59x18 x, SD59x18 y) pure returns (SD59x18 result) {
result = wrap(x.unwrap() % y.unwrap());
}
/// @notice Implements the not equal operation (!=) in the SD59x18 type.
function neq(SD59x18 x, SD59x18 y) pure returns (bool result) {
result = x.unwrap() != y.unwrap();
}
/// @notice Implements the NOT (~) bitwise operation in the SD59x18 type.
function not(SD59x18 x) pure returns (SD59x18 result) {
result = wrap(~x.unwrap());
}
/// @notice Implements the OR (|) bitwise operation in the SD59x18 type.
function or(SD59x18 x, SD59x18 y) pure returns (SD59x18 result) {
result = wrap(x.unwrap() | y.unwrap());
}
/// @notice Implements the right shift operation (>>) in the SD59x18 type.
function rshift(SD59x18 x, uint256 bits) pure returns (SD59x18 result) {
result = wrap(x.unwrap() >> bits);
}
/// @notice Implements the checked subtraction operation (-) in the SD59x18 type.
function sub(SD59x18 x, SD59x18 y) pure returns (SD59x18 result) {
result = wrap(x.unwrap() - y.unwrap());
}
/// @notice Implements the checked unary minus operation (-) in the SD59x18 type.
function unary(SD59x18 x) pure returns (SD59x18 result) {
result = wrap(-x.unwrap());
}
/// @notice Implements the unchecked addition operation (+) in the SD59x18 type.
function uncheckedAdd(SD59x18 x, SD59x18 y) pure returns (SD59x18 result) {
unchecked {
result = wrap(x.unwrap() + y.unwrap());
}
}
/// @notice Implements the unchecked subtraction operation (-) in the SD59x18 type.
function uncheckedSub(SD59x18 x, SD59x18 y) pure returns (SD59x18 result) {
unchecked {
result = wrap(x.unwrap() - y.unwrap());
}
}
/// @notice Implements the unchecked unary minus operation (-) in the SD59x18 type.
function uncheckedUnary(SD59x18 x) pure returns (SD59x18 result) {
unchecked {
result = wrap(-x.unwrap());
}
}
/// @notice Implements the XOR (^) bitwise operation in the SD59x18 type.
function xor(SD59x18 x, SD59x18 y) pure returns (SD59x18 result) {
result = wrap(x.unwrap() ^ y.unwrap());
}// SPDX-License-Identifier: MIT
pragma solidity >=0.8.19;
import "../Common.sol" as Common;
import "./Errors.sol" as Errors;
import {
uEXP_MAX_INPUT,
uEXP2_MAX_INPUT,
uHALF_UNIT,
uLOG2_10,
uLOG2_E,
uMAX_SD59x18,
uMAX_WHOLE_SD59x18,
uMIN_SD59x18,
uMIN_WHOLE_SD59x18,
UNIT,
uUNIT,
uUNIT_SQUARED,
ZERO
} from "./Constants.sol";
import { wrap } from "./Helpers.sol";
import { SD59x18 } from "./ValueType.sol";
/// @notice Calculates the absolute value of x.
///
/// @dev Requirements:
/// - x must be greater than `MIN_SD59x18`.
///
/// @param x The SD59x18 number for which to calculate the absolute value.
/// @param result The absolute value of x as an SD59x18 number.
/// @custom:smtchecker abstract-function-nondet
function abs(SD59x18 x) pure returns (SD59x18 result) {
int256 xInt = x.unwrap();
if (xInt == uMIN_SD59x18) {
revert Errors.PRBMath_SD59x18_Abs_MinSD59x18();
}
result = xInt < 0 ? wrap(-xInt) : x;
}
/// @notice Calculates the arithmetic average of x and y.
///
/// @dev Notes:
/// - The result is rounded toward zero.
///
/// @param x The first operand as an SD59x18 number.
/// @param y The second operand as an SD59x18 number.
/// @return result The arithmetic average as an SD59x18 number.
/// @custom:smtchecker abstract-function-nondet
function avg(SD59x18 x, SD59x18 y) pure returns (SD59x18 result) {
int256 xInt = x.unwrap();
int256 yInt = y.unwrap();
unchecked {
// This operation is equivalent to `x / 2 + y / 2`, and it can never overflow.
int256 sum = (xInt >> 1) + (yInt >> 1);
if (sum < 0) {
// If at least one of x and y is odd, add 1 to the result, because shifting negative numbers to the right
// rounds toward negative infinity. The right part is equivalent to `sum + (x % 2 == 1 || y % 2 == 1)`.
assembly ("memory-safe") {
result := add(sum, and(or(xInt, yInt), 1))
}
} else {
// Add 1 if both x and y are odd to account for the double 0.5 remainder truncated after shifting.
result = wrap(sum + (xInt & yInt & 1));
}
}
}
/// @notice Yields the smallest whole number greater than or equal to x.
///
/// @dev Optimized for fractional value inputs, because every whole value has (1e18 - 1) fractional counterparts.
/// See https://en.wikipedia.org/wiki/Floor_and_ceiling_functions.
///
/// Requirements:
/// - x must be less than or equal to `MAX_WHOLE_SD59x18`.
///
/// @param x The SD59x18 number to ceil.
/// @param result The smallest whole number greater than or equal to x, as an SD59x18 number.
/// @custom:smtchecker abstract-function-nondet
function ceil(SD59x18 x) pure returns (SD59x18 result) {
int256 xInt = x.unwrap();
if (xInt > uMAX_WHOLE_SD59x18) {
revert Errors.PRBMath_SD59x18_Ceil_Overflow(x);
}
int256 remainder = xInt % uUNIT;
if (remainder == 0) {
result = x;
} else {
unchecked {
// Solidity uses C fmod style, which returns a modulus with the same sign as x.
int256 resultInt = xInt - remainder;
if (xInt > 0) {
resultInt += uUNIT;
}
result = wrap(resultInt);
}
}
}
/// @notice Divides two SD59x18 numbers, returning a new SD59x18 number.
///
/// @dev This is an extension of {Common.mulDiv} for signed numbers, which works by computing the signs and the absolute
/// values separately.
///
/// Notes:
/// - Refer to the notes in {Common.mulDiv}.
/// - The result is rounded toward zero.
///
/// Requirements:
/// - Refer to the requirements in {Common.mulDiv}.
/// - None of the inputs can be `MIN_SD59x18`.
/// - The denominator must not be zero.
/// - The result must fit in SD59x18.
///
/// @param x The numerator as an SD59x18 number.
/// @param y The denominator as an SD59x18 number.
/// @param result The quotient as an SD59x18 number.
/// @custom:smtchecker abstract-function-nondet
function div(SD59x18 x, SD59x18 y) pure returns (SD59x18 result) {
int256 xInt = x.unwrap();
int256 yInt = y.unwrap();
if (xInt == uMIN_SD59x18 || yInt == uMIN_SD59x18) {
revert Errors.PRBMath_SD59x18_Div_InputTooSmall();
}
// Get hold of the absolute values of x and y.
uint256 xAbs;
uint256 yAbs;
unchecked {
xAbs = xInt < 0 ? uint256(-xInt) : uint256(xInt);
yAbs = yInt < 0 ? uint256(-yInt) : uint256(yInt);
}
// Compute the absolute value (x*UNIT÷y). The resulting value must fit in SD59x18.
uint256 resultAbs = Common.mulDiv(xAbs, uint256(uUNIT), yAbs);
if (resultAbs > uint256(uMAX_SD59x18)) {
revert Errors.PRBMath_SD59x18_Div_Overflow(x, y);
}
// Check if x and y have the same sign using two's complement representation. The left-most bit represents the sign (1 for
// negative, 0 for positive or zero).
bool sameSign = (xInt ^ yInt) > -1;
// If the inputs have the same sign, the result should be positive. Otherwise, it should be negative.
unchecked {
result = wrap(sameSign ? int256(resultAbs) : -int256(resultAbs));
}
}
/// @notice Calculates the natural exponent of x using the following formula:
///
/// $$
/// e^x = 2^{x * log_2{e}}
/// $$
///
/// @dev Notes:
/// - Refer to the notes in {exp2}.
///
/// Requirements:
/// - Refer to the requirements in {exp2}.
/// - x must be less than 133_084258667509499441.
///
/// @param x The exponent as an SD59x18 number.
/// @return result The result as an SD59x18 number.
/// @custom:smtchecker abstract-function-nondet
function exp(SD59x18 x) pure returns (SD59x18 result) {
int256 xInt = x.unwrap();
// This check prevents values greater than 192e18 from being passed to {exp2}.
if (xInt > uEXP_MAX_INPUT) {
revert Errors.PRBMath_SD59x18_Exp_InputTooBig(x);
}
unchecked {
// Inline the fixed-point multiplication to save gas.
int256 doubleUnitProduct = xInt * uLOG2_E;
result = exp2(wrap(doubleUnitProduct / uUNIT));
}
}
/// @notice Calculates the binary exponent of x using the binary fraction method using the following formula:
///
/// $$
/// 2^{-x} = \frac{1}{2^x}
/// $$
///
/// @dev See https://ethereum.stackexchange.com/q/79903/24693.
///
/// Notes:
/// - If x is less than -59_794705707972522261, the result is zero.
///
/// Requirements:
/// - x must be less than 192e18.
/// - The result must fit in SD59x18.
///
/// @param x The exponent as an SD59x18 number.
/// @return result The result as an SD59x18 number.
/// @custom:smtchecker abstract-function-nondet
function exp2(SD59x18 x) pure returns (SD59x18 result) {
int256 xInt = x.unwrap();
if (xInt < 0) {
// The inverse of any number less than this is truncated to zero.
if (xInt < -59_794705707972522261) {
return ZERO;
}
unchecked {
// Inline the fixed-point inversion to save gas.
result = wrap(uUNIT_SQUARED / exp2(wrap(-xInt)).unwrap());
}
} else {
// Numbers greater than or equal to 192e18 don't fit in the 192.64-bit format.
if (xInt > uEXP2_MAX_INPUT) {
revert Errors.PRBMath_SD59x18_Exp2_InputTooBig(x);
}
unchecked {
// Convert x to the 192.64-bit fixed-point format.
uint256 x_192x64 = uint256((xInt << 64) / uUNIT);
// It is safe to cast the result to int256 due to the checks above.
result = wrap(int256(Common.exp2(x_192x64)));
}
}
}
/// @notice Yields the greatest whole number less than or equal to x.
///
/// @dev Optimized for fractional value inputs, because for every whole value there are (1e18 - 1) fractional
/// counterparts. See https://en.wikipedia.org/wiki/Floor_and_ceiling_functions.
///
/// Requirements:
/// - x must be greater than or equal to `MIN_WHOLE_SD59x18`.
///
/// @param x The SD59x18 number to floor.
/// @param result The greatest whole number less than or equal to x, as an SD59x18 number.
/// @custom:smtchecker abstract-function-nondet
function floor(SD59x18 x) pure returns (SD59x18 result) {
int256 xInt = x.unwrap();
if (xInt < uMIN_WHOLE_SD59x18) {
revert Errors.PRBMath_SD59x18_Floor_Underflow(x);
}
int256 remainder = xInt % uUNIT;
if (remainder == 0) {
result = x;
} else {
unchecked {
// Solidity uses C fmod style, which returns a modulus with the same sign as x.
int256 resultInt = xInt - remainder;
if (xInt < 0) {
resultInt -= uUNIT;
}
result = wrap(resultInt);
}
}
}
/// @notice Yields the excess beyond the floor of x for positive numbers and the part of the number to the right.
/// of the radix point for negative numbers.
/// @dev Based on the odd function definition. https://en.wikipedia.org/wiki/Fractional_part
/// @param x The SD59x18 number to get the fractional part of.
/// @param result The fractional part of x as an SD59x18 number.
function frac(SD59x18 x) pure returns (SD59x18 result) {
result = wrap(x.unwrap() % uUNIT);
}
/// @notice Calculates the geometric mean of x and y, i.e. $\sqrt{x * y}$.
///
/// @dev Notes:
/// - The result is rounded toward zero.
///
/// Requirements:
/// - x * y must fit in SD59x18.
/// - x * y must not be negative, since complex numbers are not supported.
///
/// @param x The first operand as an SD59x18 number.
/// @param y The second operand as an SD59x18 number.
/// @return result The result as an SD59x18 number.
/// @custom:smtchecker abstract-function-nondet
function gm(SD59x18 x, SD59x18 y) pure returns (SD59x18 result) {
int256 xInt = x.unwrap();
int256 yInt = y.unwrap();
if (xInt == 0 || yInt == 0) {
return ZERO;
}
unchecked {
// Equivalent to `xy / x != y`. Checking for overflow this way is faster than letting Solidity do it.
int256 xyInt = xInt * yInt;
if (xyInt / xInt != yInt) {
revert Errors.PRBMath_SD59x18_Gm_Overflow(x, y);
}
// The product must not be negative, since complex numbers are not supported.
if (xyInt < 0) {
revert Errors.PRBMath_SD59x18_Gm_NegativeProduct(x, y);
}
// We don't need to multiply the result by `UNIT` here because the x*y product picked up a factor of `UNIT`
// during multiplication. See the comments in {Common.sqrt}.
uint256 resultUint = Common.sqrt(uint256(xyInt));
result = wrap(int256(resultUint));
}
}
/// @notice Calculates the inverse of x.
///
/// @dev Notes:
/// - The result is rounded toward zero.
///
/// Requirements:
/// - x must not be zero.
///
/// @param x The SD59x18 number for which to calculate the inverse.
/// @return result The inverse as an SD59x18 number.
/// @custom:smtchecker abstract-function-nondet
function inv(SD59x18 x) pure returns (SD59x18 result) {
result = wrap(uUNIT_SQUARED / x.unwrap());
}
/// @notice Calculates the natural logarithm of x using the following formula:
///
/// $$
/// ln{x} = log_2{x} / log_2{e}
/// $$
///
/// @dev Notes:
/// - Refer to the notes in {log2}.
/// - The precision isn't sufficiently fine-grained to return exactly `UNIT` when the input is `E`.
///
/// Requirements:
/// - Refer to the requirements in {log2}.
///
/// @param x The SD59x18 number for which to calculate the natural logarithm.
/// @return result The natural logarithm as an SD59x18 number.
/// @custom:smtchecker abstract-function-nondet
function ln(SD59x18 x) pure returns (SD59x18 result) {
// Inline the fixed-point multiplication to save gas. This is overflow-safe because the maximum value that
// {log2} can return is ~195_205294292027477728.
result = wrap(log2(x).unwrap() * uUNIT / uLOG2_E);
}
/// @notice Calculates the common logarithm of x using the following formula:
///
/// $$
/// log_{10}{x} = log_2{x} / log_2{10}
/// $$
///
/// However, if x is an exact power of ten, a hard coded value is returned.
///
/// @dev Notes:
/// - Refer to the notes in {log2}.
///
/// Requirements:
/// - Refer to the requirements in {log2}.
///
/// @param x The SD59x18 number for which to calculate the common logarithm.
/// @return result The common logarithm as an SD59x18 number.
/// @custom:smtchecker abstract-function-nondet
function log10(SD59x18 x) pure returns (SD59x18 result) {
int256 xInt = x.unwrap();
if (xInt < 0) {
revert Errors.PRBMath_SD59x18_Log_InputTooSmall(x);
}
// Note that the `mul` in this block is the standard multiplication operation, not {SD59x18.mul}.
// prettier-ignore
assembly ("memory-safe") {
switch x
case 1 { result := mul(uUNIT, sub(0, 18)) }
case 10 { result := mul(uUNIT, sub(1, 18)) }
case 100 { result := mul(uUNIT, sub(2, 18)) }
case 1000 { result := mul(uUNIT, sub(3, 18)) }
case 10000 { result := mul(uUNIT, sub(4, 18)) }
case 100000 { result := mul(uUNIT, sub(5, 18)) }
case 1000000 { result := mul(uUNIT, sub(6, 18)) }
case 10000000 { result := mul(uUNIT, sub(7, 18)) }
case 100000000 { result := mul(uUNIT, sub(8, 18)) }
case 1000000000 { result := mul(uUNIT, sub(9, 18)) }
case 10000000000 { result := mul(uUNIT, sub(10, 18)) }
case 100000000000 { result := mul(uUNIT, sub(11, 18)) }
case 1000000000000 { result := mul(uUNIT, sub(12, 18)) }
case 10000000000000 { result := mul(uUNIT, sub(13, 18)) }
case 100000000000000 { result := mul(uUNIT, sub(14, 18)) }
case 1000000000000000 { result := mul(uUNIT, sub(15, 18)) }
case 10000000000000000 { result := mul(uUNIT, sub(16, 18)) }
case 100000000000000000 { result := mul(uUNIT, sub(17, 18)) }
case 1000000000000000000 { result := 0 }
case 10000000000000000000 { result := uUNIT }
case 100000000000000000000 { result := mul(uUNIT, 2) }
case 1000000000000000000000 { result := mul(uUNIT, 3) }
case 10000000000000000000000 { result := mul(uUNIT, 4) }
case 100000000000000000000000 { result := mul(uUNIT, 5) }
case 1000000000000000000000000 { result := mul(uUNIT, 6) }
case 10000000000000000000000000 { result := mul(uUNIT, 7) }
case 100000000000000000000000000 { result := mul(uUNIT, 8) }
case 1000000000000000000000000000 { result := mul(uUNIT, 9) }
case 10000000000000000000000000000 { result := mul(uUNIT, 10) }
case 100000000000000000000000000000 { result := mul(uUNIT, 11) }
case 1000000000000000000000000000000 { result := mul(uUNIT, 12) }
case 10000000000000000000000000000000 { result := mul(uUNIT, 13) }
case 100000000000000000000000000000000 { result := mul(uUNIT, 14) }
case 1000000000000000000000000000000000 { result := mul(uUNIT, 15) }
case 10000000000000000000000000000000000 { result := mul(uUNIT, 16) }
case 100000000000000000000000000000000000 { result := mul(uUNIT, 17) }
case 1000000000000000000000000000000000000 { result := mul(uUNIT, 18) }
case 10000000000000000000000000000000000000 { result := mul(uUNIT, 19) }
case 100000000000000000000000000000000000000 { result := mul(uUNIT, 20) }
case 1000000000000000000000000000000000000000 { result := mul(uUNIT, 21) }
case 10000000000000000000000000000000000000000 { result := mul(uUNIT, 22) }
case 100000000000000000000000000000000000000000 { result := mul(uUNIT, 23) }
case 1000000000000000000000000000000000000000000 { result := mul(uUNIT, 24) }
case 10000000000000000000000000000000000000000000 { result := mul(uUNIT, 25) }
case 100000000000000000000000000000000000000000000 { result := mul(uUNIT, 26) }
case 1000000000000000000000000000000000000000000000 { result := mul(uUNIT, 27) }
case 10000000000000000000000000000000000000000000000 { result := mul(uUNIT, 28) }
case 100000000000000000000000000000000000000000000000 { result := mul(uUNIT, 29) }
case 1000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 30) }
case 10000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 31) }
case 100000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 32) }
case 1000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 33) }
case 10000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 34) }
case 100000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 35) }
case 1000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 36) }
case 10000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 37) }
case 100000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 38) }
case 1000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 39) }
case 10000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 40) }
case 100000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 41) }
case 1000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 42) }
case 10000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 43) }
case 100000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 44) }
case 1000000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 45) }
case 10000000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 46) }
case 100000000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 47) }
case 1000000000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 48) }
case 10000000000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 49) }
case 100000000000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 50) }
case 1000000000000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 51) }
case 10000000000000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 52) }
case 100000000000000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 53) }
case 1000000000000000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 54) }
case 10000000000000000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 55) }
case 100000000000000000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 56) }
case 1000000000000000000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 57) }
case 10000000000000000000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 58) }
default { result := uMAX_SD59x18 }
}
if (result.unwrap() == uMAX_SD59x18) {
unchecked {
// Inline the fixed-point division to save gas.
result = wrap(log2(x).unwrap() * uUNIT / uLOG2_10);
}
}
}
/// @notice Calculates the binary logarithm of x using the iterative approximation algorithm:
///
/// $$
/// log_2{x} = n + log_2{y}, \text{ where } y = x*2^{-n}, \ y \in [1, 2)
/// $$
///
/// For $0 \leq x \lt 1$, the input is inverted:
///
/// $$
/// log_2{x} = -log_2{\frac{1}{x}}
/// $$
///
/// @dev See https://en.wikipedia.org/wiki/Binary_logarithm#Iterative_approximation.
///
/// Notes:
/// - Due to the lossy precision of the iterative approximation, the results are not perfectly accurate to the last decimal.
///
/// Requirements:
/// - x must be greater than zero.
///
/// @param x The SD59x18 number for which to calculate the binary logarithm.
/// @return result The binary logarithm as an SD59x18 number.
/// @custom:smtchecker abstract-function-nondet
function log2(SD59x18 x) pure returns (SD59x18 result) {
int256 xInt = x.unwrap();
if (xInt <= 0) {
revert Errors.PRBMath_SD59x18_Log_InputTooSmall(x);
}
unchecked {
int256 sign;
if (xInt >= uUNIT) {
sign = 1;
} else {
sign = -1;
// Inline the fixed-point inversion to save gas.
xInt = uUNIT_SQUARED / xInt;
}
// Calculate the integer part of the logarithm.
uint256 n = Common.msb(uint256(xInt / uUNIT));
// This is the integer part of the logarithm as an SD59x18 number. The operation can't overflow
// because n is at most 255, `UNIT` is 1e18, and the sign is either 1 or -1.
int256 resultInt = int256(n) * uUNIT;
// Calculate $y = x * 2^{-n}$.
int256 y = xInt >> n;
// If y is the unit number, the fractional part is zero.
if (y == uUNIT) {
return wrap(resultInt * sign);
}
// Calculate the fractional part via the iterative approximation.
// The `delta >>= 1` part is equivalent to `delta /= 2`, but shifting bits is more gas efficient.
int256 DOUBLE_UNIT = 2e18;
for (int256 delta = uHALF_UNIT; delta > 0; delta >>= 1) {
y = (y * y) / uUNIT;
// Is y^2 >= 2e18 and so in the range [2e18, 4e18)?
if (y >= DOUBLE_UNIT) {
// Add the 2^{-m} factor to the logarithm.
resultInt = resultInt + delta;
// Halve y, which corresponds to z/2 in the Wikipedia article.
y >>= 1;
}
}
resultInt *= sign;
result = wrap(resultInt);
}
}
/// @notice Multiplies two SD59x18 numbers together, returning a new SD59x18 number.
///
/// @dev Notes:
/// - Refer to the notes in {Common.mulDiv18}.
///
/// Requirements:
/// - Refer to the requirements in {Common.mulDiv18}.
/// - None of the inputs can be `MIN_SD59x18`.
/// - The result must fit in SD59x18.
///
/// @param x The multiplicand as an SD59x18 number.
/// @param y The multiplier as an SD59x18 number.
/// @return result The product as an SD59x18 number.
/// @custom:smtchecker abstract-function-nondet
function mul(SD59x18 x, SD59x18 y) pure returns (SD59x18 result) {
int256 xInt = x.unwrap();
int256 yInt = y.unwrap();
if (xInt == uMIN_SD59x18 || yInt == uMIN_SD59x18) {
revert Errors.PRBMath_SD59x18_Mul_InputTooSmall();
}
// Get hold of the absolute values of x and y.
uint256 xAbs;
uint256 yAbs;
unchecked {
xAbs = xInt < 0 ? uint256(-xInt) : uint256(xInt);
yAbs = yInt < 0 ? uint256(-yInt) : uint256(yInt);
}
// Compute the absolute value (x*y÷UNIT). The resulting value must fit in SD59x18.
uint256 resultAbs = Common.mulDiv18(xAbs, yAbs);
if (resultAbs > uint256(uMAX_SD59x18)) {
revert Errors.PRBMath_SD59x18_Mul_Overflow(x, y);
}
// Check if x and y have the same sign using two's complement representation. The left-most bit represents the sign (1 for
// negative, 0 for positive or zero).
bool sameSign = (xInt ^ yInt) > -1;
// If the inputs have the same sign, the result should be positive. Otherwise, it should be negative.
unchecked {
result = wrap(sameSign ? int256(resultAbs) : -int256(resultAbs));
}
}
/// @notice Raises x to the power of y using the following formula:
///
/// $$
/// x^y = 2^{log_2{x} * y}
/// $$
///
/// @dev Notes:
/// - Refer to the notes in {exp2}, {log2}, and {mul}.
/// - Returns `UNIT` for 0^0.
///
/// Requirements:
/// - Refer to the requirements in {exp2}, {log2}, and {mul}.
///
/// @param x The base as an SD59x18 number.
/// @param y Exponent to raise x to, as an SD59x18 number
/// @return result x raised to power y, as an SD59x18 number.
/// @custom:smtchecker abstract-function-nondet
function pow(SD59x18 x, SD59x18 y) pure returns (SD59x18 result) {
int256 xInt = x.unwrap();
int256 yInt = y.unwrap();
// If both x and y are zero, the result is `UNIT`. If just x is zero, the result is always zero.
if (xInt == 0) {
return yInt == 0 ? UNIT : ZERO;
}
// If x is `UNIT`, the result is always `UNIT`.
else if (xInt == uUNIT) {
return UNIT;
}
// If y is zero, the result is always `UNIT`.
if (yInt == 0) {
return UNIT;
}
// If y is `UNIT`, the result is always x.
else if (yInt == uUNIT) {
return x;
}
// Calculate the result using the formula.
result = exp2(mul(log2(x), y));
}
/// @notice Raises x (an SD59x18 number) to the power y (an unsigned basic integer) using the well-known
/// algorithm "exponentiation by squaring".
///
/// @dev See https://en.wikipedia.org/wiki/Exponentiation_by_squaring.
///
/// Notes:
/// - Refer to the notes in {Common.mulDiv18}.
/// - Returns `UNIT` for 0^0.
///
/// Requirements:
/// - Refer to the requirements in {abs} and {Common.mulDiv18}.
/// - The result must fit in SD59x18.
///
/// @param x The base as an SD59x18 number.
/// @param y The exponent as a uint256.
/// @return result The result as an SD59x18 number.
/// @custom:smtchecker abstract-function-nondet
function powu(SD59x18 x, uint256 y) pure returns (SD59x18 result) {
uint256 xAbs = uint256(abs(x).unwrap());
// Calculate the first iteration of the loop in advance.
uint256 resultAbs = y & 1 > 0 ? xAbs : uint256(uUNIT);
// Equivalent to `for(y /= 2; y > 0; y /= 2)`.
uint256 yAux = y;
for (yAux >>= 1; yAux > 0; yAux >>= 1) {
xAbs = Common.mulDiv18(xAbs, xAbs);
// Equivalent to `y % 2 == 1`.
if (yAux & 1 > 0) {
resultAbs = Common.mulDiv18(resultAbs, xAbs);
}
}
// The result must fit in SD59x18.
if (resultAbs > uint256(uMAX_SD59x18)) {
revert Errors.PRBMath_SD59x18_Powu_Overflow(x, y);
}
unchecked {
// Is the base negative and the exponent odd? If yes, the result should be negative.
int256 resultInt = int256(resultAbs);
bool isNegative = x.unwrap() < 0 && y & 1 == 1;
if (isNegative) {
resultInt = -resultInt;
}
result = wrap(resultInt);
}
}
/// @notice Calculates the square root of x using the Babylonian method.
///
/// @dev See https://en.wikipedia.org/wiki/Methods_of_computing_square_roots#Babylonian_method.
///
/// Notes:
/// - Only the positive root is returned.
/// - The result is rounded toward zero.
///
/// Requirements:
/// - x cannot be negative, since complex numbers are not supported.
/// - x must be less than `MAX_SD59x18 / UNIT`.
///
/// @param x The SD59x18 number for which to calculate the square root.
/// @return result The result as an SD59x18 number.
/// @custom:smtchecker abstract-function-nondet
function sqrt(SD59x18 x) pure returns (SD59x18 result) {
int256 xInt = x.unwrap();
if (xInt < 0) {
revert Errors.PRBMath_SD59x18_Sqrt_NegativeInput(x);
}
if (xInt > uMAX_SD59x18 / uUNIT) {
revert Errors.PRBMath_SD59x18_Sqrt_Overflow(x);
}
unchecked {
// Multiply x by `UNIT` to account for the factor of `UNIT` picked up when multiplying two SD59x18 numbers.
// In this case, the two numbers are both the square root.
uint256 resultUint = Common.sqrt(uint256(xInt * uUNIT));
result = wrap(int256(resultUint));
}
}// SPDX-License-Identifier: MIT
pragma solidity >=0.8.19;
import "./Casting.sol" as Casting;
import "./Helpers.sol" as Helpers;
import "./Math.sol" as Math;
/// @notice The signed 59.18-decimal fixed-point number representation, which can have up to 59 digits and up to 18
/// decimals. The values of this are bound by the minimum and the maximum values permitted by the underlying Solidity
/// type int256.
type SD59x18 is int256;
/*//////////////////////////////////////////////////////////////////////////
CASTING
//////////////////////////////////////////////////////////////////////////*/
using {
Casting.intoInt256,
Casting.intoSD1x18,
Casting.intoUD2x18,
Casting.intoUD60x18,
Casting.intoUint256,
Casting.intoUint128,
Casting.intoUint40,
Casting.unwrap
} for SD59x18 global;
/*//////////////////////////////////////////////////////////////////////////
MATHEMATICAL FUNCTIONS
//////////////////////////////////////////////////////////////////////////*/
using {
Math.abs,
Math.avg,
Math.ceil,
Math.div,
Math.exp,
Math.exp2,
Math.floor,
Math.frac,
Math.gm,
Math.inv,
Math.log10,
Math.log2,
Math.ln,
Math.mul,
Math.pow,
Math.powu,
Math.sqrt
} for SD59x18 global;
/*//////////////////////////////////////////////////////////////////////////
HELPER FUNCTIONS
//////////////////////////////////////////////////////////////////////////*/
using {
Helpers.add,
Helpers.and,
Helpers.eq,
Helpers.gt,
Helpers.gte,
Helpers.isZero,
Helpers.lshift,
Helpers.lt,
Helpers.lte,
Helpers.mod,
Helpers.neq,
Helpers.not,
Helpers.or,
Helpers.rshift,
Helpers.sub,
Helpers.uncheckedAdd,
Helpers.uncheckedSub,
Helpers.uncheckedUnary,
Helpers.xor
} for SD59x18 global;
/*//////////////////////////////////////////////////////////////////////////
OPERATORS
//////////////////////////////////////////////////////////////////////////*/
// The global "using for" directive makes it possible to use these operators on the SD59x18 type.
using {
Helpers.add as +,
Helpers.and2 as &,
Math.div as /,
Helpers.eq as ==,
Helpers.gt as >,
Helpers.gte as >=,
Helpers.lt as <,
Helpers.lte as <=,
Helpers.mod as %,
Math.mul as *,
Helpers.neq as !=,
Helpers.not as ~,
Helpers.or as |,
Helpers.sub as -,
Helpers.unary as -,
Helpers.xor as ^
} for SD59x18 global;// SPDX-License-Identifier: MIT
pragma solidity >=0.8.19;
import "../Common.sol" as Common;
import "./Errors.sol" as Errors;
import { uMAX_SD1x18 } from "../sd1x18/Constants.sol";
import { SD1x18 } from "../sd1x18/ValueType.sol";
import { SD59x18 } from "../sd59x18/ValueType.sol";
import { UD60x18 } from "../ud60x18/ValueType.sol";
import { UD2x18 } from "./ValueType.sol";
/// @notice Casts a UD2x18 number into SD1x18.
/// - x must be less than or equal to `uMAX_SD1x18`.
function intoSD1x18(UD2x18 x) pure returns (SD1x18 result) {
uint64 xUint = UD2x18.unwrap(x);
if (xUint > uint64(uMAX_SD1x18)) {
revert Errors.PRBMath_UD2x18_IntoSD1x18_Overflow(x);
}
result = SD1x18.wrap(int64(xUint));
}
/// @notice Casts a UD2x18 number into SD59x18.
/// @dev There is no overflow check because the domain of UD2x18 is a subset of SD59x18.
function intoSD59x18(UD2x18 x) pure returns (SD59x18 result) {
result = SD59x18.wrap(int256(uint256(UD2x18.unwrap(x))));
}
/// @notice Casts a UD2x18 number into UD60x18.
/// @dev There is no overflow check because the domain of UD2x18 is a subset of UD60x18.
function intoUD60x18(UD2x18 x) pure returns (UD60x18 result) {
result = UD60x18.wrap(UD2x18.unwrap(x));
}
/// @notice Casts a UD2x18 number into uint128.
/// @dev There is no overflow check because the domain of UD2x18 is a subset of uint128.
function intoUint128(UD2x18 x) pure returns (uint128 result) {
result = uint128(UD2x18.unwrap(x));
}
/// @notice Casts a UD2x18 number into uint256.
/// @dev There is no overflow check because the domain of UD2x18 is a subset of uint256.
function intoUint256(UD2x18 x) pure returns (uint256 result) {
result = uint256(UD2x18.unwrap(x));
}
/// @notice Casts a UD2x18 number into uint40.
/// @dev Requirements:
/// - x must be less than or equal to `MAX_UINT40`.
function intoUint40(UD2x18 x) pure returns (uint40 result) {
uint64 xUint = UD2x18.unwrap(x);
if (xUint > uint64(Common.MAX_UINT40)) {
revert Errors.PRBMath_UD2x18_IntoUint40_Overflow(x);
}
result = uint40(xUint);
}
/// @notice Alias for {wrap}.
function ud2x18(uint64 x) pure returns (UD2x18 result) {
result = UD2x18.wrap(x);
}
/// @notice Unwrap a UD2x18 number into uint64.
function unwrap(UD2x18 x) pure returns (uint64 result) {
result = UD2x18.unwrap(x);
}
/// @notice Wraps a uint64 number into UD2x18.
function wrap(uint64 x) pure returns (UD2x18 result) {
result = UD2x18.wrap(x);
}// SPDX-License-Identifier: MIT
pragma solidity >=0.8.19;
import { UD2x18 } from "./ValueType.sol";
/// @dev Euler's number as a UD2x18 number.
UD2x18 constant E = UD2x18.wrap(2_718281828459045235);
/// @dev The maximum value a UD2x18 number can have.
uint64 constant uMAX_UD2x18 = 18_446744073709551615;
UD2x18 constant MAX_UD2x18 = UD2x18.wrap(uMAX_UD2x18);
/// @dev PI as a UD2x18 number.
UD2x18 constant PI = UD2x18.wrap(3_141592653589793238);
/// @dev The unit number, which gives the decimal precision of UD2x18.
uint256 constant uUNIT = 1e18;
UD2x18 constant UNIT = UD2x18.wrap(1e18);// SPDX-License-Identifier: MIT
pragma solidity >=0.8.19;
import { UD2x18 } from "./ValueType.sol";
/// @notice Thrown when trying to cast a UD2x18 number that doesn't fit in SD1x18.
error PRBMath_UD2x18_IntoSD1x18_Overflow(UD2x18 x);
/// @notice Thrown when trying to cast a UD2x18 number that doesn't fit in uint40.
error PRBMath_UD2x18_IntoUint40_Overflow(UD2x18 x);// SPDX-License-Identifier: MIT
pragma solidity >=0.8.19;
import "./Casting.sol" as Casting;
/// @notice The unsigned 2.18-decimal fixed-point number representation, which can have up to 2 digits and up to 18
/// decimals. The values of this are bound by the minimum and the maximum values permitted by the underlying Solidity
/// type uint64. This is useful when end users want to use uint64 to save gas, e.g. with tight variable packing in contract
/// storage.
type UD2x18 is uint64;
/*//////////////////////////////////////////////////////////////////////////
CASTING
//////////////////////////////////////////////////////////////////////////*/
using {
Casting.intoSD1x18,
Casting.intoSD59x18,
Casting.intoUD60x18,
Casting.intoUint256,
Casting.intoUint128,
Casting.intoUint40,
Casting.unwrap
} for UD2x18 global;// SPDX-License-Identifier: MIT
pragma solidity >=0.8.19;
import "./Errors.sol" as CastingErrors;
import { MAX_UINT128, MAX_UINT40 } from "../Common.sol";
import { uMAX_SD1x18 } from "../sd1x18/Constants.sol";
import { SD1x18 } from "../sd1x18/ValueType.sol";
import { uMAX_SD59x18 } from "../sd59x18/Constants.sol";
import { SD59x18 } from "../sd59x18/ValueType.sol";
import { uMAX_UD2x18 } from "../ud2x18/Constants.sol";
import { UD2x18 } from "../ud2x18/ValueType.sol";
import { UD60x18 } from "./ValueType.sol";
/// @notice Casts a UD60x18 number into SD1x18.
/// @dev Requirements:
/// - x must be less than or equal to `uMAX_SD1x18`.
function intoSD1x18(UD60x18 x) pure returns (SD1x18 result) {
uint256 xUint = UD60x18.unwrap(x);
if (xUint > uint256(int256(uMAX_SD1x18))) {
revert CastingErrors.PRBMath_UD60x18_IntoSD1x18_Overflow(x);
}
result = SD1x18.wrap(int64(uint64(xUint)));
}
/// @notice Casts a UD60x18 number into UD2x18.
/// @dev Requirements:
/// - x must be less than or equal to `uMAX_UD2x18`.
function intoUD2x18(UD60x18 x) pure returns (UD2x18 result) {
uint256 xUint = UD60x18.unwrap(x);
if (xUint > uMAX_UD2x18) {
revert CastingErrors.PRBMath_UD60x18_IntoUD2x18_Overflow(x);
}
result = UD2x18.wrap(uint64(xUint));
}
/// @notice Casts a UD60x18 number into SD59x18.
/// @dev Requirements:
/// - x must be less than or equal to `uMAX_SD59x18`.
function intoSD59x18(UD60x18 x) pure returns (SD59x18 result) {
uint256 xUint = UD60x18.unwrap(x);
if (xUint > uint256(uMAX_SD59x18)) {
revert CastingErrors.PRBMath_UD60x18_IntoSD59x18_Overflow(x);
}
result = SD59x18.wrap(int256(xUint));
}
/// @notice Casts a UD60x18 number into uint128.
/// @dev This is basically an alias for {unwrap}.
function intoUint256(UD60x18 x) pure returns (uint256 result) {
result = UD60x18.unwrap(x);
}
/// @notice Casts a UD60x18 number into uint128.
/// @dev Requirements:
/// - x must be less than or equal to `MAX_UINT128`.
function intoUint128(UD60x18 x) pure returns (uint128 result) {
uint256 xUint = UD60x18.unwrap(x);
if (xUint > MAX_UINT128) {
revert CastingErrors.PRBMath_UD60x18_IntoUint128_Overflow(x);
}
result = uint128(xUint);
}
/// @notice Casts a UD60x18 number into uint40.
/// @dev Requirements:
/// - x must be less than or equal to `MAX_UINT40`.
function intoUint40(UD60x18 x) pure returns (uint40 result) {
uint256 xUint = UD60x18.unwrap(x);
if (xUint > MAX_UINT40) {
revert CastingErrors.PRBMath_UD60x18_IntoUint40_Overflow(x);
}
result = uint40(xUint);
}
/// @notice Alias for {wrap}.
function ud(uint256 x) pure returns (UD60x18 result) {
result = UD60x18.wrap(x);
}
/// @notice Alias for {wrap}.
function ud60x18(uint256 x) pure returns (UD60x18 result) {
result = UD60x18.wrap(x);
}
/// @notice Unwraps a UD60x18 number into uint256.
function unwrap(UD60x18 x) pure returns (uint256 result) {
result = UD60x18.unwrap(x);
}
/// @notice Wraps a uint256 number into the UD60x18 value type.
function wrap(uint256 x) pure returns (UD60x18 result) {
result = UD60x18.wrap(x);
}// SPDX-License-Identifier: MIT
pragma solidity >=0.8.19;
import { UD60x18 } from "./ValueType.sol";
// NOTICE: the "u" prefix stands for "unwrapped".
/// @dev Euler's number as a UD60x18 number.
UD60x18 constant E = UD60x18.wrap(2_718281828459045235);
/// @dev The maximum input permitted in {exp}.
uint256 constant uEXP_MAX_INPUT = 133_084258667509499440;
UD60x18 constant EXP_MAX_INPUT = UD60x18.wrap(uEXP_MAX_INPUT);
/// @dev The maximum input permitted in {exp2}.
uint256 constant uEXP2_MAX_INPUT = 192e18 - 1;
UD60x18 constant EXP2_MAX_INPUT = UD60x18.wrap(uEXP2_MAX_INPUT);
/// @dev Half the UNIT number.
uint256 constant uHALF_UNIT = 0.5e18;
UD60x18 constant HALF_UNIT = UD60x18.wrap(uHALF_UNIT);
/// @dev $log_2(10)$ as a UD60x18 number.
uint256 constant uLOG2_10 = 3_321928094887362347;
UD60x18 constant LOG2_10 = UD60x18.wrap(uLOG2_10);
/// @dev $log_2(e)$ as a UD60x18 number.
uint256 constant uLOG2_E = 1_442695040888963407;
UD60x18 constant LOG2_E = UD60x18.wrap(uLOG2_E);
/// @dev The maximum value a UD60x18 number can have.
uint256 constant uMAX_UD60x18 = 115792089237316195423570985008687907853269984665640564039457_584007913129639935;
UD60x18 constant MAX_UD60x18 = UD60x18.wrap(uMAX_UD60x18);
/// @dev The maximum whole value a UD60x18 number can have.
uint256 constant uMAX_WHOLE_UD60x18 = 115792089237316195423570985008687907853269984665640564039457_000000000000000000;
UD60x18 constant MAX_WHOLE_UD60x18 = UD60x18.wrap(uMAX_WHOLE_UD60x18);
/// @dev PI as a UD60x18 number.
UD60x18 constant PI = UD60x18.wrap(3_141592653589793238);
/// @dev The unit number, which gives the decimal precision of UD60x18.
uint256 constant uUNIT = 1e18;
UD60x18 constant UNIT = UD60x18.wrap(uUNIT);
/// @dev The unit number squared.
uint256 constant uUNIT_SQUARED = 1e36;
UD60x18 constant UNIT_SQUARED = UD60x18.wrap(uUNIT_SQUARED);
/// @dev Zero as a UD60x18 number.
UD60x18 constant ZERO = UD60x18.wrap(0);// SPDX-License-Identifier: MIT
pragma solidity >=0.8.19;
import { uMAX_UD60x18, uUNIT } from "./Constants.sol";
import { PRBMath_UD60x18_Convert_Overflow } from "./Errors.sol";
import { UD60x18 } from "./ValueType.sol";
/// @notice Converts a UD60x18 number to a simple integer by dividing it by `UNIT`.
/// @dev The result is rounded toward zero.
/// @param x The UD60x18 number to convert.
/// @return result The same number in basic integer form.
function convert(UD60x18 x) pure returns (uint256 result) {
result = UD60x18.unwrap(x) / uUNIT;
}
/// @notice Converts a simple integer to UD60x18 by multiplying it by `UNIT`.
///
/// @dev Requirements:
/// - x must be less than or equal to `MAX_UD60x18 / UNIT`.
///
/// @param x The basic integer to convert.
/// @param result The same number converted to UD60x18.
function convert(uint256 x) pure returns (UD60x18 result) {
if (x > uMAX_UD60x18 / uUNIT) {
revert PRBMath_UD60x18_Convert_Overflow(x);
}
unchecked {
result = UD60x18.wrap(x * uUNIT);
}
}// SPDX-License-Identifier: MIT
pragma solidity >=0.8.19;
import { UD60x18 } from "./ValueType.sol";
/// @notice Thrown when ceiling a number overflows UD60x18.
error PRBMath_UD60x18_Ceil_Overflow(UD60x18 x);
/// @notice Thrown when converting a basic integer to the fixed-point format overflows UD60x18.
error PRBMath_UD60x18_Convert_Overflow(uint256 x);
/// @notice Thrown when taking the natural exponent of a base greater than 133_084258667509499441.
error PRBMath_UD60x18_Exp_InputTooBig(UD60x18 x);
/// @notice Thrown when taking the binary exponent of a base greater than 192e18.
error PRBMath_UD60x18_Exp2_InputTooBig(UD60x18 x);
/// @notice Thrown when taking the geometric mean of two numbers and multiplying them overflows UD60x18.
error PRBMath_UD60x18_Gm_Overflow(UD60x18 x, UD60x18 y);
/// @notice Thrown when trying to cast a UD60x18 number that doesn't fit in SD1x18.
error PRBMath_UD60x18_IntoSD1x18_Overflow(UD60x18 x);
/// @notice Thrown when trying to cast a UD60x18 number that doesn't fit in SD59x18.
error PRBMath_UD60x18_IntoSD59x18_Overflow(UD60x18 x);
/// @notice Thrown when trying to cast a UD60x18 number that doesn't fit in UD2x18.
error PRBMath_UD60x18_IntoUD2x18_Overflow(UD60x18 x);
/// @notice Thrown when trying to cast a UD60x18 number that doesn't fit in uint128.
error PRBMath_UD60x18_IntoUint128_Overflow(UD60x18 x);
/// @notice Thrown when trying to cast a UD60x18 number that doesn't fit in uint40.
error PRBMath_UD60x18_IntoUint40_Overflow(UD60x18 x);
/// @notice Thrown when taking the logarithm of a number less than 1.
error PRBMath_UD60x18_Log_InputTooSmall(UD60x18 x);
/// @notice Thrown when calculating the square root overflows UD60x18.
error PRBMath_UD60x18_Sqrt_Overflow(UD60x18 x);// SPDX-License-Identifier: MIT
pragma solidity >=0.8.19;
import { wrap } from "./Casting.sol";
import { UD60x18 } from "./ValueType.sol";
/// @notice Implements the checked addition operation (+) in the UD60x18 type.
function add(UD60x18 x, UD60x18 y) pure returns (UD60x18 result) {
result = wrap(x.unwrap() + y.unwrap());
}
/// @notice Implements the AND (&) bitwise operation in the UD60x18 type.
function and(UD60x18 x, uint256 bits) pure returns (UD60x18 result) {
result = wrap(x.unwrap() & bits);
}
/// @notice Implements the AND (&) bitwise operation in the UD60x18 type.
function and2(UD60x18 x, UD60x18 y) pure returns (UD60x18 result) {
result = wrap(x.unwrap() & y.unwrap());
}
/// @notice Implements the equal operation (==) in the UD60x18 type.
function eq(UD60x18 x, UD60x18 y) pure returns (bool result) {
result = x.unwrap() == y.unwrap();
}
/// @notice Implements the greater than operation (>) in the UD60x18 type.
function gt(UD60x18 x, UD60x18 y) pure returns (bool result) {
result = x.unwrap() > y.unwrap();
}
/// @notice Implements the greater than or equal to operation (>=) in the UD60x18 type.
function gte(UD60x18 x, UD60x18 y) pure returns (bool result) {
result = x.unwrap() >= y.unwrap();
}
/// @notice Implements a zero comparison check function in the UD60x18 type.
function isZero(UD60x18 x) pure returns (bool result) {
// This wouldn't work if x could be negative.
result = x.unwrap() == 0;
}
/// @notice Implements the left shift operation (<<) in the UD60x18 type.
function lshift(UD60x18 x, uint256 bits) pure returns (UD60x18 result) {
result = wrap(x.unwrap() << bits);
}
/// @notice Implements the lower than operation (<) in the UD60x18 type.
function lt(UD60x18 x, UD60x18 y) pure returns (bool result) {
result = x.unwrap() < y.unwrap();
}
/// @notice Implements the lower than or equal to operation (<=) in the UD60x18 type.
function lte(UD60x18 x, UD60x18 y) pure returns (bool result) {
result = x.unwrap() <= y.unwrap();
}
/// @notice Implements the checked modulo operation (%) in the UD60x18 type.
function mod(UD60x18 x, UD60x18 y) pure returns (UD60x18 result) {
result = wrap(x.unwrap() % y.unwrap());
}
/// @notice Implements the not equal operation (!=) in the UD60x18 type.
function neq(UD60x18 x, UD60x18 y) pure returns (bool result) {
result = x.unwrap() != y.unwrap();
}
/// @notice Implements the NOT (~) bitwise operation in the UD60x18 type.
function not(UD60x18 x) pure returns (UD60x18 result) {
result = wrap(~x.unwrap());
}
/// @notice Implements the OR (|) bitwise operation in the UD60x18 type.
function or(UD60x18 x, UD60x18 y) pure returns (UD60x18 result) {
result = wrap(x.unwrap() | y.unwrap());
}
/// @notice Implements the right shift operation (>>) in the UD60x18 type.
function rshift(UD60x18 x, uint256 bits) pure returns (UD60x18 result) {
result = wrap(x.unwrap() >> bits);
}
/// @notice Implements the checked subtraction operation (-) in the UD60x18 type.
function sub(UD60x18 x, UD60x18 y) pure returns (UD60x18 result) {
result = wrap(x.unwrap() - y.unwrap());
}
/// @notice Implements the unchecked addition operation (+) in the UD60x18 type.
function uncheckedAdd(UD60x18 x, UD60x18 y) pure returns (UD60x18 result) {
unchecked {
result = wrap(x.unwrap() + y.unwrap());
}
}
/// @notice Implements the unchecked subtraction operation (-) in the UD60x18 type.
function uncheckedSub(UD60x18 x, UD60x18 y) pure returns (UD60x18 result) {
unchecked {
result = wrap(x.unwrap() - y.unwrap());
}
}
/// @notice Implements the XOR (^) bitwise operation in the UD60x18 type.
function xor(UD60x18 x, UD60x18 y) pure returns (UD60x18 result) {
result = wrap(x.unwrap() ^ y.unwrap());
}// SPDX-License-Identifier: MIT
pragma solidity >=0.8.19;
import "../Common.sol" as Common;
import "./Errors.sol" as Errors;
import { wrap } from "./Casting.sol";
import {
uEXP_MAX_INPUT,
uEXP2_MAX_INPUT,
uHALF_UNIT,
uLOG2_10,
uLOG2_E,
uMAX_UD60x18,
uMAX_WHOLE_UD60x18,
UNIT,
uUNIT,
uUNIT_SQUARED,
ZERO
} from "./Constants.sol";
import { UD60x18 } from "./ValueType.sol";
/*//////////////////////////////////////////////////////////////////////////
MATHEMATICAL FUNCTIONS
//////////////////////////////////////////////////////////////////////////*/
/// @notice Calculates the arithmetic average of x and y using the following formula:
///
/// $$
/// avg(x, y) = (x & y) + ((xUint ^ yUint) / 2)
/// $$
///
/// In English, this is what this formula does:
///
/// 1. AND x and y.
/// 2. Calculate half of XOR x and y.
/// 3. Add the two results together.
///
/// This technique is known as SWAR, which stands for "SIMD within a register". You can read more about it here:
/// https://devblogs.microsoft.com/oldnewthing/20220207-00/?p=106223
///
/// @dev Notes:
/// - The result is rounded toward zero.
///
/// @param x The first operand as a UD60x18 number.
/// @param y The second operand as a UD60x18 number.
/// @return result The arithmetic average as a UD60x18 number.
/// @custom:smtchecker abstract-function-nondet
function avg(UD60x18 x, UD60x18 y) pure returns (UD60x18 result) {
uint256 xUint = x.unwrap();
uint256 yUint = y.unwrap();
unchecked {
result = wrap((xUint & yUint) + ((xUint ^ yUint) >> 1));
}
}
/// @notice Yields the smallest whole number greater than or equal to x.
///
/// @dev This is optimized for fractional value inputs, because for every whole value there are (1e18 - 1) fractional
/// counterparts. See https://en.wikipedia.org/wiki/Floor_and_ceiling_functions.
///
/// Requirements:
/// - x must be less than or equal to `MAX_WHOLE_UD60x18`.
///
/// @param x The UD60x18 number to ceil.
/// @param result The smallest whole number greater than or equal to x, as a UD60x18 number.
/// @custom:smtchecker abstract-function-nondet
function ceil(UD60x18 x) pure returns (UD60x18 result) {
uint256 xUint = x.unwrap();
if (xUint > uMAX_WHOLE_UD60x18) {
revert Errors.PRBMath_UD60x18_Ceil_Overflow(x);
}
assembly ("memory-safe") {
// Equivalent to `x % UNIT`.
let remainder := mod(x, uUNIT)
// Equivalent to `UNIT - remainder`.
let delta := sub(uUNIT, remainder)
// Equivalent to `x + remainder > 0 ? delta : 0`.
result := add(x, mul(delta, gt(remainder, 0)))
}
}
/// @notice Divides two UD60x18 numbers, returning a new UD60x18 number.
///
/// @dev Uses {Common.mulDiv} to enable overflow-safe multiplication and division.
///
/// Notes:
/// - Refer to the notes in {Common.mulDiv}.
///
/// Requirements:
/// - Refer to the requirements in {Common.mulDiv}.
///
/// @param x The numerator as a UD60x18 number.
/// @param y The denominator as a UD60x18 number.
/// @param result The quotient as a UD60x18 number.
/// @custom:smtchecker abstract-function-nondet
function div(UD60x18 x, UD60x18 y) pure returns (UD60x18 result) {
result = wrap(Common.mulDiv(x.unwrap(), uUNIT, y.unwrap()));
}
/// @notice Calculates the natural exponent of x using the following formula:
///
/// $$
/// e^x = 2^{x * log_2{e}}
/// $$
///
/// @dev Requirements:
/// - x must be less than 133_084258667509499441.
///
/// @param x The exponent as a UD60x18 number.
/// @return result The result as a UD60x18 number.
/// @custom:smtchecker abstract-function-nondet
function exp(UD60x18 x) pure returns (UD60x18 result) {
uint256 xUint = x.unwrap();
// This check prevents values greater than 192e18 from being passed to {exp2}.
if (xUint > uEXP_MAX_INPUT) {
revert Errors.PRBMath_UD60x18_Exp_InputTooBig(x);
}
unchecked {
// Inline the fixed-point multiplication to save gas.
uint256 doubleUnitProduct = xUint * uLOG2_E;
result = exp2(wrap(doubleUnitProduct / uUNIT));
}
}
/// @notice Calculates the binary exponent of x using the binary fraction method.
///
/// @dev See https://ethereum.stackexchange.com/q/79903/24693
///
/// Requirements:
/// - x must be less than 192e18.
/// - The result must fit in UD60x18.
///
/// @param x The exponent as a UD60x18 number.
/// @return result The result as a UD60x18 number.
/// @custom:smtchecker abstract-function-nondet
function exp2(UD60x18 x) pure returns (UD60x18 result) {
uint256 xUint = x.unwrap();
// Numbers greater than or equal to 192e18 don't fit in the 192.64-bit format.
if (xUint > uEXP2_MAX_INPUT) {
revert Errors.PRBMath_UD60x18_Exp2_InputTooBig(x);
}
// Convert x to the 192.64-bit fixed-point format.
uint256 x_192x64 = (xUint << 64) / uUNIT;
// Pass x to the {Common.exp2} function, which uses the 192.64-bit fixed-point number representation.
result = wrap(Common.exp2(x_192x64));
}
/// @notice Yields the greatest whole number less than or equal to x.
/// @dev Optimized for fractional value inputs, because every whole value has (1e18 - 1) fractional counterparts.
/// See https://en.wikipedia.org/wiki/Floor_and_ceiling_functions.
/// @param x The UD60x18 number to floor.
/// @param result The greatest whole number less than or equal to x, as a UD60x18 number.
/// @custom:smtchecker abstract-function-nondet
function floor(UD60x18 x) pure returns (UD60x18 result) {
assembly ("memory-safe") {
// Equivalent to `x % UNIT`.
let remainder := mod(x, uUNIT)
// Equivalent to `x - remainder > 0 ? remainder : 0)`.
result := sub(x, mul(remainder, gt(remainder, 0)))
}
}
/// @notice Yields the excess beyond the floor of x using the odd function definition.
/// @dev See https://en.wikipedia.org/wiki/Fractional_part.
/// @param x The UD60x18 number to get the fractional part of.
/// @param result The fractional part of x as a UD60x18 number.
/// @custom:smtchecker abstract-function-nondet
function frac(UD60x18 x) pure returns (UD60x18 result) {
assembly ("memory-safe") {
result := mod(x, uUNIT)
}
}
/// @notice Calculates the geometric mean of x and y, i.e. $\sqrt{x * y}$, rounding down.
///
/// @dev Requirements:
/// - x * y must fit in UD60x18.
///
/// @param x The first operand as a UD60x18 number.
/// @param y The second operand as a UD60x18 number.
/// @return result The result as a UD60x18 number.
/// @custom:smtchecker abstract-function-nondet
function gm(UD60x18 x, UD60x18 y) pure returns (UD60x18 result) {
uint256 xUint = x.unwrap();
uint256 yUint = y.unwrap();
if (xUint == 0 || yUint == 0) {
return ZERO;
}
unchecked {
// Checking for overflow this way is faster than letting Solidity do it.
uint256 xyUint = xUint * yUint;
if (xyUint / xUint != yUint) {
revert Errors.PRBMath_UD60x18_Gm_Overflow(x, y);
}
// We don't need to multiply the result by `UNIT` here because the x*y product picked up a factor of `UNIT`
// during multiplication. See the comments in {Common.sqrt}.
result = wrap(Common.sqrt(xyUint));
}
}
/// @notice Calculates the inverse of x.
///
/// @dev Notes:
/// - The result is rounded toward zero.
///
/// Requirements:
/// - x must not be zero.
///
/// @param x The UD60x18 number for which to calculate the inverse.
/// @return result The inverse as a UD60x18 number.
/// @custom:smtchecker abstract-function-nondet
function inv(UD60x18 x) pure returns (UD60x18 result) {
unchecked {
result = wrap(uUNIT_SQUARED / x.unwrap());
}
}
/// @notice Calculates the natural logarithm of x using the following formula:
///
/// $$
/// ln{x} = log_2{x} / log_2{e}
/// $$
///
/// @dev Notes:
/// - Refer to the notes in {log2}.
/// - The precision isn't sufficiently fine-grained to return exactly `UNIT` when the input is `E`.
///
/// Requirements:
/// - Refer to the requirements in {log2}.
///
/// @param x The UD60x18 number for which to calculate the natural logarithm.
/// @return result The natural logarithm as a UD60x18 number.
/// @custom:smtchecker abstract-function-nondet
function ln(UD60x18 x) pure returns (UD60x18 result) {
unchecked {
// Inline the fixed-point multiplication to save gas. This is overflow-safe because the maximum value that
// {log2} can return is ~196_205294292027477728.
result = wrap(log2(x).unwrap() * uUNIT / uLOG2_E);
}
}
/// @notice Calculates the common logarithm of x using the following formula:
///
/// $$
/// log_{10}{x} = log_2{x} / log_2{10}
/// $$
///
/// However, if x is an exact power of ten, a hard coded value is returned.
///
/// @dev Notes:
/// - Refer to the notes in {log2}.
///
/// Requirements:
/// - Refer to the requirements in {log2}.
///
/// @param x The UD60x18 number for which to calculate the common logarithm.
/// @return result The common logarithm as a UD60x18 number.
/// @custom:smtchecker abstract-function-nondet
function log10(UD60x18 x) pure returns (UD60x18 result) {
uint256 xUint = x.unwrap();
if (xUint < uUNIT) {
revert Errors.PRBMath_UD60x18_Log_InputTooSmall(x);
}
// Note that the `mul` in this assembly block is the standard multiplication operation, not {UD60x18.mul}.
// prettier-ignore
assembly ("memory-safe") {
switch x
case 1 { result := mul(uUNIT, sub(0, 18)) }
case 10 { result := mul(uUNIT, sub(1, 18)) }
case 100 { result := mul(uUNIT, sub(2, 18)) }
case 1000 { result := mul(uUNIT, sub(3, 18)) }
case 10000 { result := mul(uUNIT, sub(4, 18)) }
case 100000 { result := mul(uUNIT, sub(5, 18)) }
case 1000000 { result := mul(uUNIT, sub(6, 18)) }
case 10000000 { result := mul(uUNIT, sub(7, 18)) }
case 100000000 { result := mul(uUNIT, sub(8, 18)) }
case 1000000000 { result := mul(uUNIT, sub(9, 18)) }
case 10000000000 { result := mul(uUNIT, sub(10, 18)) }
case 100000000000 { result := mul(uUNIT, sub(11, 18)) }
case 1000000000000 { result := mul(uUNIT, sub(12, 18)) }
case 10000000000000 { result := mul(uUNIT, sub(13, 18)) }
case 100000000000000 { result := mul(uUNIT, sub(14, 18)) }
case 1000000000000000 { result := mul(uUNIT, sub(15, 18)) }
case 10000000000000000 { result := mul(uUNIT, sub(16, 18)) }
case 100000000000000000 { result := mul(uUNIT, sub(17, 18)) }
case 1000000000000000000 { result := 0 }
case 10000000000000000000 { result := uUNIT }
case 100000000000000000000 { result := mul(uUNIT, 2) }
case 1000000000000000000000 { result := mul(uUNIT, 3) }
case 10000000000000000000000 { result := mul(uUNIT, 4) }
case 100000000000000000000000 { result := mul(uUNIT, 5) }
case 1000000000000000000000000 { result := mul(uUNIT, 6) }
case 10000000000000000000000000 { result := mul(uUNIT, 7) }
case 100000000000000000000000000 { result := mul(uUNIT, 8) }
case 1000000000000000000000000000 { result := mul(uUNIT, 9) }
case 10000000000000000000000000000 { result := mul(uUNIT, 10) }
case 100000000000000000000000000000 { result := mul(uUNIT, 11) }
case 1000000000000000000000000000000 { result := mul(uUNIT, 12) }
case 10000000000000000000000000000000 { result := mul(uUNIT, 13) }
case 100000000000000000000000000000000 { result := mul(uUNIT, 14) }
case 1000000000000000000000000000000000 { result := mul(uUNIT, 15) }
case 10000000000000000000000000000000000 { result := mul(uUNIT, 16) }
case 100000000000000000000000000000000000 { result := mul(uUNIT, 17) }
case 1000000000000000000000000000000000000 { result := mul(uUNIT, 18) }
case 10000000000000000000000000000000000000 { result := mul(uUNIT, 19) }
case 100000000000000000000000000000000000000 { result := mul(uUNIT, 20) }
case 1000000000000000000000000000000000000000 { result := mul(uUNIT, 21) }
case 10000000000000000000000000000000000000000 { result := mul(uUNIT, 22) }
case 100000000000000000000000000000000000000000 { result := mul(uUNIT, 23) }
case 1000000000000000000000000000000000000000000 { result := mul(uUNIT, 24) }
case 10000000000000000000000000000000000000000000 { result := mul(uUNIT, 25) }
case 100000000000000000000000000000000000000000000 { result := mul(uUNIT, 26) }
case 1000000000000000000000000000000000000000000000 { result := mul(uUNIT, 27) }
case 10000000000000000000000000000000000000000000000 { result := mul(uUNIT, 28) }
case 100000000000000000000000000000000000000000000000 { result := mul(uUNIT, 29) }
case 1000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 30) }
case 10000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 31) }
case 100000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 32) }
case 1000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 33) }
case 10000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 34) }
case 100000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 35) }
case 1000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 36) }
case 10000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 37) }
case 100000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 38) }
case 1000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 39) }
case 10000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 40) }
case 100000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 41) }
case 1000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 42) }
case 10000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 43) }
case 100000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 44) }
case 1000000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 45) }
case 10000000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 46) }
case 100000000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 47) }
case 1000000000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 48) }
case 10000000000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 49) }
case 100000000000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 50) }
case 1000000000000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 51) }
case 10000000000000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 52) }
case 100000000000000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 53) }
case 1000000000000000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 54) }
case 10000000000000000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 55) }
case 100000000000000000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 56) }
case 1000000000000000000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 57) }
case 10000000000000000000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 58) }
case 100000000000000000000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 59) }
default { result := uMAX_UD60x18 }
}
if (result.unwrap() == uMAX_UD60x18) {
unchecked {
// Inline the fixed-point division to save gas.
result = wrap(log2(x).unwrap() * uUNIT / uLOG2_10);
}
}
}
/// @notice Calculates the binary logarithm of x using the iterative approximation algorithm:
///
/// $$
/// log_2{x} = n + log_2{y}, \text{ where } y = x*2^{-n}, \ y \in [1, 2)
/// $$
///
/// For $0 \leq x \lt 1$, the input is inverted:
///
/// $$
/// log_2{x} = -log_2{\frac{1}{x}}
/// $$
///
/// @dev See https://en.wikipedia.org/wiki/Binary_logarithm#Iterative_approximation
///
/// Notes:
/// - Due to the lossy precision of the iterative approximation, the results are not perfectly accurate to the last decimal.
///
/// Requirements:
/// - x must be greater than zero.
///
/// @param x The UD60x18 number for which to calculate the binary logarithm.
/// @return result The binary logarithm as a UD60x18 number.
/// @custom:smtchecker abstract-function-nondet
function log2(UD60x18 x) pure returns (UD60x18 result) {
uint256 xUint = x.unwrap();
if (xUint < uUNIT) {
revert Errors.PRBMath_UD60x18_Log_InputTooSmall(x);
}
unchecked {
// Calculate the integer part of the logarithm.
uint256 n = Common.msb(xUint / uUNIT);
// This is the integer part of the logarithm as a UD60x18 number. The operation can't overflow because n
// n is at most 255 and UNIT is 1e18.
uint256 resultUint = n * uUNIT;
// Calculate $y = x * 2^{-n}$.
uint256 y = xUint >> n;
// If y is the unit number, the fractional part is zero.
if (y == uUNIT) {
return wrap(resultUint);
}
// Calculate the fractional part via the iterative approximation.
// The `delta >>= 1` part is equivalent to `delta /= 2`, but shifting bits is more gas efficient.
uint256 DOUBLE_UNIT = 2e18;
for (uint256 delta = uHALF_UNIT; delta > 0; delta >>= 1) {
y = (y * y) / uUNIT;
// Is y^2 >= 2e18 and so in the range [2e18, 4e18)?
if (y >= DOUBLE_UNIT) {
// Add the 2^{-m} factor to the logarithm.
resultUint += delta;
// Halve y, which corresponds to z/2 in the Wikipedia article.
y >>= 1;
}
}
result = wrap(resultUint);
}
}
/// @notice Multiplies two UD60x18 numbers together, returning a new UD60x18 number.
///
/// @dev Uses {Common.mulDiv} to enable overflow-safe multiplication and division.
///
/// Notes:
/// - Refer to the notes in {Common.mulDiv}.
///
/// Requirements:
/// - Refer to the requirements in {Common.mulDiv}.
///
/// @dev See the documentation in {Common.mulDiv18}.
/// @param x The multiplicand as a UD60x18 number.
/// @param y The multiplier as a UD60x18 number.
/// @return result The product as a UD60x18 number.
/// @custom:smtchecker abstract-function-nondet
function mul(UD60x18 x, UD60x18 y) pure returns (UD60x18 result) {
result = wrap(Common.mulDiv18(x.unwrap(), y.unwrap()));
}
/// @notice Raises x to the power of y.
///
/// For $1 \leq x \leq \infty$, the following standard formula is used:
///
/// $$
/// x^y = 2^{log_2{x} * y}
/// $$
///
/// For $0 \leq x \lt 1$, since the unsigned {log2} is undefined, an equivalent formula is used:
///
/// $$
/// i = \frac{1}{x}
/// w = 2^{log_2{i} * y}
/// x^y = \frac{1}{w}
/// $$
///
/// @dev Notes:
/// - Refer to the notes in {log2} and {mul}.
/// - Returns `UNIT` for 0^0.
/// - It may not perform well with very small values of x. Consider using SD59x18 as an alternative.
///
/// Requirements:
/// - Refer to the requirements in {exp2}, {log2}, and {mul}.
///
/// @param x The base as a UD60x18 number.
/// @param y The exponent as a UD60x18 number.
/// @return result The result as a UD60x18 number.
/// @custom:smtchecker abstract-function-nondet
function pow(UD60x18 x, UD60x18 y) pure returns (UD60x18 result) {
uint256 xUint = x.unwrap();
uint256 yUint = y.unwrap();
// If both x and y are zero, the result is `UNIT`. If just x is zero, the result is always zero.
if (xUint == 0) {
return yUint == 0 ? UNIT : ZERO;
}
// If x is `UNIT`, the result is always `UNIT`.
else if (xUint == uUNIT) {
return UNIT;
}
// If y is zero, the result is always `UNIT`.
if (yUint == 0) {
return UNIT;
}
// If y is `UNIT`, the result is always x.
else if (yUint == uUNIT) {
return x;
}
// If x is greater than `UNIT`, use the standard formula.
if (xUint > uUNIT) {
result = exp2(mul(log2(x), y));
}
// Conversely, if x is less than `UNIT`, use the equivalent formula.
else {
UD60x18 i = wrap(uUNIT_SQUARED / xUint);
UD60x18 w = exp2(mul(log2(i), y));
result = wrap(uUNIT_SQUARED / w.unwrap());
}
}
/// @notice Raises x (a UD60x18 number) to the power y (an unsigned basic integer) using the well-known
/// algorithm "exponentiation by squaring".
///
/// @dev See https://en.wikipedia.org/wiki/Exponentiation_by_squaring.
///
/// Notes:
/// - Refer to the notes in {Common.mulDiv18}.
/// - Returns `UNIT` for 0^0.
///
/// Requirements:
/// - The result must fit in UD60x18.
///
/// @param x The base as a UD60x18 number.
/// @param y The exponent as a uint256.
/// @return result The result as a UD60x18 number.
/// @custom:smtchecker abstract-function-nondet
function powu(UD60x18 x, uint256 y) pure returns (UD60x18 result) {
// Calculate the first iteration of the loop in advance.
uint256 xUint = x.unwrap();
uint256 resultUint = y & 1 > 0 ? xUint : uUNIT;
// Equivalent to `for(y /= 2; y > 0; y /= 2)`.
for (y >>= 1; y > 0; y >>= 1) {
xUint = Common.mulDiv18(xUint, xUint);
// Equivalent to `y % 2 == 1`.
if (y & 1 > 0) {
resultUint = Common.mulDiv18(resultUint, xUint);
}
}
result = wrap(resultUint);
}
/// @notice Calculates the square root of x using the Babylonian method.
///
/// @dev See https://en.wikipedia.org/wiki/Methods_of_computing_square_roots#Babylonian_method.
///
/// Notes:
/// - The result is rounded toward zero.
///
/// Requirements:
/// - x must be less than `MAX_UD60x18 / UNIT`.
///
/// @param x The UD60x18 number for which to calculate the square root.
/// @return result The result as a UD60x18 number.
/// @custom:smtchecker abstract-function-nondet
function sqrt(UD60x18 x) pure returns (UD60x18 result) {
uint256 xUint = x.unwrap();
unchecked {
if (xUint > uMAX_UD60x18 / uUNIT) {
revert Errors.PRBMath_UD60x18_Sqrt_Overflow(x);
}
// Multiply x by `UNIT` to account for the factor of `UNIT` picked up when multiplying two UD60x18 numbers.
// In this case, the two numbers are both the square root.
result = wrap(Common.sqrt(xUint * uUNIT));
}
}// SPDX-License-Identifier: MIT
pragma solidity >=0.8.19;
import "./Casting.sol" as Casting;
import "./Helpers.sol" as Helpers;
import "./Math.sol" as Math;
/// @notice The unsigned 60.18-decimal fixed-point number representation, which can have up to 60 digits and up to 18
/// decimals. The values of this are bound by the minimum and the maximum values permitted by the Solidity type uint256.
/// @dev The value type is defined here so it can be imported in all other files.
type UD60x18 is uint256;
/*//////////////////////////////////////////////////////////////////////////
CASTING
//////////////////////////////////////////////////////////////////////////*/
using {
Casting.intoSD1x18,
Casting.intoUD2x18,
Casting.intoSD59x18,
Casting.intoUint128,
Casting.intoUint256,
Casting.intoUint40,
Casting.unwrap
} for UD60x18 global;
/*//////////////////////////////////////////////////////////////////////////
MATHEMATICAL FUNCTIONS
//////////////////////////////////////////////////////////////////////////*/
// The global "using for" directive makes the functions in this library callable on the UD60x18 type.
using {
Math.avg,
Math.ceil,
Math.div,
Math.exp,
Math.exp2,
Math.floor,
Math.frac,
Math.gm,
Math.inv,
Math.ln,
Math.log10,
Math.log2,
Math.mul,
Math.pow,
Math.powu,
Math.sqrt
} for UD60x18 global;
/*//////////////////////////////////////////////////////////////////////////
HELPER FUNCTIONS
//////////////////////////////////////////////////////////////////////////*/
// The global "using for" directive makes the functions in this library callable on the UD60x18 type.
using {
Helpers.add,
Helpers.and,
Helpers.eq,
Helpers.gt,
Helpers.gte,
Helpers.isZero,
Helpers.lshift,
Helpers.lt,
Helpers.lte,
Helpers.mod,
Helpers.neq,
Helpers.not,
Helpers.or,
Helpers.rshift,
Helpers.sub,
Helpers.uncheckedAdd,
Helpers.uncheckedSub,
Helpers.xor
} for UD60x18 global;
/*//////////////////////////////////////////////////////////////////////////
OPERATORS
//////////////////////////////////////////////////////////////////////////*/
// The global "using for" directive makes it possible to use these operators on the UD60x18 type.
using {
Helpers.add as +,
Helpers.and2 as &,
Math.div as /,
Helpers.eq as ==,
Helpers.gt as >,
Helpers.gte as >=,
Helpers.lt as <,
Helpers.lte as <=,
Helpers.or as |,
Helpers.mod as %,
Math.mul as *,
Helpers.neq as !=,
Helpers.not as ~,
Helpers.sub as -,
Helpers.xor as ^
} for UD60x18 global;// SPDX-License-Identifier: Apache-2.0
pragma solidity ^0.8.0;
import "./PythStructs.sol";
import "./IPythEvents.sol";
/// @title Consume prices from the Pyth Network (https://pyth.network/).
/// @dev Please refer to the guidance at https://docs.pyth.network/documentation/pythnet-price-feeds/best-practices for how to consume prices safely.
/// @author Pyth Data Association
interface IPyth is IPythEvents {
/// @notice Returns the period (in seconds) that a price feed is considered valid since its publish time
function getValidTimePeriod() external view returns (uint validTimePeriod);
/// @notice Returns the price and confidence interval.
/// @dev Reverts if the price has not been updated within the last `getValidTimePeriod()` seconds.
/// @param id The Pyth Price Feed ID of which to fetch the price and confidence interval.
/// @return price - please read the documentation of PythStructs.Price to understand how to use this safely.
function getPrice(
bytes32 id
) external view returns (PythStructs.Price memory price);
/// @notice Returns the exponentially-weighted moving average price and confidence interval.
/// @dev Reverts if the EMA price is not available.
/// @param id The Pyth Price Feed ID of which to fetch the EMA price and confidence interval.
/// @return price - please read the documentation of PythStructs.Price to understand how to use this safely.
function getEmaPrice(
bytes32 id
) external view returns (PythStructs.Price memory price);
/// @notice Returns the price of a price feed without any sanity checks.
/// @dev This function returns the most recent price update in this contract without any recency checks.
/// This function is unsafe as the returned price update may be arbitrarily far in the past.
///
/// Users of this function should check the `publishTime` in the price to ensure that the returned price is
/// sufficiently recent for their application. If you are considering using this function, it may be
/// safer / easier to use either `getPrice` or `getPriceNoOlderThan`.
/// @return price - please read the documentation of PythStructs.Price to understand how to use this safely.
function getPriceUnsafe(
bytes32 id
) external view returns (PythStructs.Price memory price);
/// @notice Returns the price that is no older than `age` seconds of the current time.
/// @dev This function is a sanity-checked version of `getPriceUnsafe` which is useful in
/// applications that require a sufficiently-recent price. Reverts if the price wasn't updated sufficiently
/// recently.
/// @return price - please read the documentation of PythStructs.Price to understand how to use this safely.
function getPriceNoOlderThan(
bytes32 id,
uint age
) external view returns (PythStructs.Price memory price);
/// @notice Returns the exponentially-weighted moving average price of a price feed without any sanity checks.
/// @dev This function returns the same price as `getEmaPrice` in the case where the price is available.
/// However, if the price is not recent this function returns the latest available price.
///
/// The returned price can be from arbitrarily far in the past; this function makes no guarantees that
/// the returned price is recent or useful for any particular application.
///
/// Users of this function should check the `publishTime` in the price to ensure that the returned price is
/// sufficiently recent for their application. If you are considering using this function, it may be
/// safer / easier to use either `getEmaPrice` or `getEmaPriceNoOlderThan`.
/// @return price - please read the documentation of PythStructs.Price to understand how to use this safely.
function getEmaPriceUnsafe(
bytes32 id
) external view returns (PythStructs.Price memory price);
/// @notice Returns the exponentially-weighted moving average price that is no older than `age` seconds
/// of the current time.
/// @dev This function is a sanity-checked version of `getEmaPriceUnsafe` which is useful in
/// applications that require a sufficiently-recent price. Reverts if the price wasn't updated sufficiently
/// recently.
/// @return price - please read the documentation of PythStructs.Price to understand how to use this safely.
function getEmaPriceNoOlderThan(
bytes32 id,
uint age
) external view returns (PythStructs.Price memory price);
/// @notice Update price feeds with given update messages.
/// This method requires the caller to pay a fee in wei; the required fee can be computed by calling
/// `getUpdateFee` with the length of the `updateData` array.
/// Prices will be updated if they are more recent than the current stored prices.
/// The call will succeed even if the update is not the most recent.
/// @dev Reverts if the transferred fee is not sufficient or the updateData is invalid.
/// @param updateData Array of price update data.
function updatePriceFeeds(bytes[] calldata updateData) external payable;
/// @notice Wrapper around updatePriceFeeds that rejects fast if a price update is not necessary. A price update is
/// necessary if the current on-chain publishTime is older than the given publishTime. It relies solely on the
/// given `publishTimes` for the price feeds and does not read the actual price update publish time within `updateData`.
///
/// This method requires the caller to pay a fee in wei; the required fee can be computed by calling
/// `getUpdateFee` with the length of the `updateData` array.
///
/// `priceIds` and `publishTimes` are two arrays with the same size that correspond to senders known publishTime
/// of each priceId when calling this method. If all of price feeds within `priceIds` have updated and have
/// a newer or equal publish time than the given publish time, it will reject the transaction to save gas.
/// Otherwise, it calls updatePriceFeeds method to update the prices.
///
/// @dev Reverts if update is not needed or the transferred fee is not sufficient or the updateData is invalid.
/// @param updateData Array of price update data.
/// @param priceIds Array of price ids.
/// @param publishTimes Array of publishTimes. `publishTimes[i]` corresponds to known `publishTime` of `priceIds[i]`
function updatePriceFeedsIfNecessary(
bytes[] calldata updateData,
bytes32[] calldata priceIds,
uint64[] calldata publishTimes
) external payable;
/// @notice Returns the required fee to update an array of price updates.
/// @param updateData Array of price update data.
/// @return feeAmount The required fee in Wei.
function getUpdateFee(
bytes[] calldata updateData
) external view returns (uint feeAmount);
/// @notice Parse `updateData` and return price feeds of the given `priceIds` if they are all published
/// within `minPublishTime` and `maxPublishTime`.
///
/// You can use this method if you want to use a Pyth price at a fixed time and not the most recent price;
/// otherwise, please consider using `updatePriceFeeds`. This method may store the price updates on-chain, if they
/// are more recent than the current stored prices.
///
/// This method requires the caller to pay a fee in wei; the required fee can be computed by calling
/// `getUpdateFee` with the length of the `updateData` array.
///
///
/// @dev Reverts if the transferred fee is not sufficient or the updateData is invalid or there is
/// no update for any of the given `priceIds` within the given time range.
/// @param updateData Array of price update data.
/// @param priceIds Array of price ids.
/// @param minPublishTime minimum acceptable publishTime for the given `priceIds`.
/// @param maxPublishTime maximum acceptable publishTime for the given `priceIds`.
/// @return priceFeeds Array of the price feeds corresponding to the given `priceIds` (with the same order).
function parsePriceFeedUpdates(
bytes[] calldata updateData,
bytes32[] calldata priceIds,
uint64 minPublishTime,
uint64 maxPublishTime
) external payable returns (PythStructs.PriceFeed[] memory priceFeeds);
/// @notice Similar to `parsePriceFeedUpdates` but ensures the updates returned are
/// the first updates published in minPublishTime. That is, if there are multiple updates for a given timestamp,
/// this method will return the first update. This method may store the price updates on-chain, if they
/// are more recent than the current stored prices.
///
///
/// @dev Reverts if the transferred fee is not sufficient or the updateData is invalid or there is
/// no update for any of the given `priceIds` within the given time range and uniqueness condition.
/// @param updateData Array of price update data.
/// @param priceIds Array of price ids.
/// @param minPublishTime minimum acceptable publishTime for the given `priceIds`.
/// @param maxPublishTime maximum acceptable publishTime for the given `priceIds`.
/// @return priceFeeds Array of the price feeds corresponding to the given `priceIds` (with the same order).
function parsePriceFeedUpdatesUnique(
bytes[] calldata updateData,
bytes32[] calldata priceIds,
uint64 minPublishTime,
uint64 maxPublishTime
) external payable returns (PythStructs.PriceFeed[] memory priceFeeds);
}// SPDX-License-Identifier: Apache-2.0
pragma solidity ^0.8.0;
/// @title IPythEvents contains the events that Pyth contract emits.
/// @dev This interface can be used for listening to the updates for off-chain and testing purposes.
interface IPythEvents {
/// @dev Emitted when the price feed with `id` has received a fresh update.
/// @param id The Pyth Price Feed ID.
/// @param publishTime Publish time of the given price update.
/// @param price Price of the given price update.
/// @param conf Confidence interval of the given price update.
event PriceFeedUpdate(
bytes32 indexed id,
uint64 publishTime,
int64 price,
uint64 conf
);
/// @dev Emitted when a batch price update is processed successfully.
/// @param chainId ID of the source chain that the batch price update comes from.
/// @param sequenceNumber Sequence number of the batch price update.
event BatchPriceFeedUpdate(uint16 chainId, uint64 sequenceNumber);
}// SPDX-License-Identifier: Apache-2.0
pragma solidity ^0.8.0;
contract PythStructs {
// A price with a degree of uncertainty, represented as a price +- a confidence interval.
//
// The confidence interval roughly corresponds to the standard error of a normal distribution.
// Both the price and confidence are stored in a fixed-point numeric representation,
// `x * (10^expo)`, where `expo` is the exponent.
//
// Please refer to the documentation at https://docs.pyth.network/documentation/pythnet-price-feeds/best-practices for how
// to how this price safely.
struct Price {
// Price
int64 price;
// Confidence interval around the price
uint64 conf;
// Price exponent
int32 expo;
// Unix timestamp describing when the price was published
uint publishTime;
}
// PriceFeed represents a current aggregate price from pyth publisher feeds.
struct PriceFeed {
// The price ID.
bytes32 id;
// Latest available price
Price price;
// Latest available exponentially-weighted moving average price
Price emaPrice;
}
}// SPDX-License-Identifier: GPL-3.0
pragma solidity 0.8.24;
enum YieldMode {
AUTOMATIC,
VOID,
CLAIMABLE
}
enum GasMode {
VOID,
CLAIMABLE
}
interface IBlastPoints {
function configurePointsOperator(address operator) external;
function configurePointsOperatorOnBehalf(address operator, address contractAddress) external;
function operators(address contractAddress) external view returns (address);
function readStatus(address contractAddress) external view returns (address, bool, uint256);
}
interface IBlast {
// configure
function configureContract(address contractAddress, YieldMode _yield, GasMode gasMode, address governor) external;
function configure(YieldMode _yield, GasMode gasMode, address governor) external;
// base configuration options
function configureClaimableYield() external;
function configureClaimableYieldOnBehalf(address contractAddress) external;
function configureAutomaticYield() external;
function configureAutomaticYieldOnBehalf(address contractAddress) external;
function configureVoidYield() external;
function configureVoidYieldOnBehalf(address contractAddress) external;
function configureClaimableGas() external;
function configureClaimableGasOnBehalf(address contractAddress) external;
function configureVoidGas() external;
function configureVoidGasOnBehalf(address contractAddress) external;
function configureGovernor(address _governor) external;
function configureGovernorOnBehalf(address _newGovernor, address contractAddress) external;
// claim yield
function claimYield(address contractAddress, address recipientOfYield, uint256 amount) external returns (uint256);
function claimAllYield(address contractAddress, address recipientOfYield) external returns (uint256);
// claim gas
function claimAllGas(address contractAddress, address recipientOfGas) external returns (uint256);
function claimGasAtMinClaimRate(
address contractAddress,
address recipientOfGas,
uint256 minClaimRateBips
)
external
returns (uint256);
function claimMaxGas(address contractAddress, address recipientOfGas) external returns (uint256);
function claimGas(
address contractAddress,
address recipientOfGas,
uint256 gasToClaim,
uint256 gasSecondsToConsume
)
external
returns (uint256);
// read functions
function readClaimableYield(address contractAddress) external view returns (uint256);
function readYieldConfiguration(address contractAddress) external view returns (uint8);
function readGasParams(address contractAddress)
external
view
returns (uint256 etherSeconds, uint256 etherBalance, uint256 lastUpdated, GasMode);
}// SPDX-License-Identifier: GPL-3.0
pragma solidity 0.8.24;
import "./IBlast.sol";
interface IERC20Rebasing {
// changes the yield mode of the caller and update the balance
// to reflect the configuration
function configure(YieldMode) external returns (uint256);
// "claimable" yield mode accounts can call this this claim their yield
// to another address
function claim(address recipient, uint256 amount) external returns (uint256);
// read the claimable amount for an account
function getClaimableAmount(address account) external view returns (uint256);
function transferFrom(address sender, address recipient, uint256 amount) external returns (bool);
function transfer(address recipient, uint256 amount) external returns (bool);
function approve(address spender, uint256 amount) external returns (bool);
function getConfiguration(address contractAddress) external view returns (uint8);
}// SPDX-License-Identifier: GPL-3.0
pragma solidity 0.8.24;
import "solady/src/tokens/ERC20.sol";
import "../libraries/accounts/AccountLib.sol";
import "../interfaces/IAccountManager.sol";
interface IAccount {
/// @notice How much was borrowed from the lending pool
event Borrow(uint256 amount);
/// @notice How much debt was paid back to the lending pool
event Repay(uint256 amount);
function asset() external view returns (IERC20);
function owner() external view returns (address);
/// @dev Returns a unique identifier distinguishing this type of account
function getKind() external view returns (bytes32);
function getManager() external view returns (IAccountManager);
function initialize(address owner_) external;
function pause() external;
function unpause() external;
/// Owner interactions
function borrow(uint256 amount) external payable;
function repay(uint256 amount) external payable;
function claim(uint256 amount) external payable;
function claim(uint256 amount, address recipient) external payable;
}// SPDX-License-Identifier: GPL-3.0
pragma solidity 0.8.24;
import "@openzeppelin/contracts/utils/structs/EnumerableSet.sol";
import { IERC20 } from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import { UD60x18, ud } from "@prb/math/src/UD60x18.sol";
import "../libraries/accounts/AccountLib.sol";
import "./ILiquidationReceiver.sol";
interface IAccountManager {
function lendingPool() external view returns (address);
function isCreatedAccount(address) external view returns (bool);
function accountCount() external view returns (uint256);
function isApprovedStrategy(address strategy) external view returns (bool);
function isLiquidationReceiver(address receiver) external view returns (bool);
function pauseAccount(address account) external;
function unpauseAccount(address account) external;
function getFeeCollector() external view returns (address);
function getLiquidationReceiver(
address account,
address liquidationFeeTo
)
external
view
returns (ILiquidationReceiver);
function getLiquidationFee() external returns (AccountLib.LiquidationFee memory);
function getAccountOwner(address account) external returns (address owner);
// Following three functions are only callable by the target Account itself.
function borrow(uint256 amount) external returns (uint256 borrowedAmount);
function repay(address account, uint256 amount) external returns (uint256 repaidAmount);
function claim(uint256 amount, address recipient) external;
function liquidate(address account, address liquidationFeeTo) external returns (ILiquidationReceiver);
/// @notice Deposits assets into a strategy on behalf of msg.sender, which must be an Account.
function strategyDeposit(
address owner,
address strategy,
uint256 assets,
bytes memory data
)
external
payable
returns (uint256 shares);
function strategyWithdrawal(address owner, address strategy, uint256 assets) external;
function setAllowedAccountsMode(bool status) external;
function setAllowedAccountStatus(address account, bool status) external;
/// @dev Some strategies have an execution fee that needs to be paid for withdrawal so that must be sent to this
/// function.
function liquidateStrategy(
address account,
address liquidationFeeTo,
address strategy,
bytes memory data
)
external
payable
returns (ILiquidationReceiver);
function emitLiquidationFeeEvent(
address feeCollector,
address liquidationFeeTo,
uint256 protocolShare,
uint256 liquidatorShare
)
external;
function getLendAsset() external view returns (IERC20);
function getDebtAmount(address account) external view returns (uint256);
function getTotalCollateralValue(address account) external view returns (uint256 totalValue);
function getAccountLoan(address account) external view returns (AccountLib.Loan memory loan);
function getAccountHealth(address account) external view returns (AccountLib.Health memory health);
/// @notice Returns whether or not an account is liquidatable. If true, return the timestamp its liquidation started
/// at.
function getAccountLiquidationStatus(address account) external view returns (AccountLib.LiquidationStatus memory);
}// SPDX-License-Identifier: GPL-3.0
pragma solidity 0.8.24;
/// @notice Interface for a price oracle preconfigured to return the price of an asset.
/// @dev Price can be in any denomination, depending on the preconfiguration.
interface IAssetPriceOracle {
function getPrice() external view returns (uint256 price);
}// SPDX-License-Identifier: GPL-3.0
pragma solidity 0.8.24;
import { IAssetPriceOracle } from "./IAssetPriceOracle.sol";
/**
* @title IAssetPriceProvider interface
* @notice Interface for the collateral price provider.
*
*/
interface IAssetPriceProvider {
/**
* @dev returns the asset price
* @param asset the address of the asset
* @return price of the asset
*
*/
function getAssetPrice(address asset) external view returns (uint256);
}// SPDX-License-Identifier: GPL-3.0
pragma solidity 0.8.24;
/// @notice Provides aggregated information about collateral supported by the system.
interface ICollateralAggregator {
function getTotalCollateralValue(address account) external view returns (uint256 totalValue);
function getCollateralAmount(address account, address asset) external view returns (uint256 amount);
function getSupportedCollateralAssets() external view returns (address[] memory assets);
function isCollateralAsset(address asset) external view returns (bool);
}// SPDX-License-Identifier: GPL-3.0
pragma solidity 0.8.24;
import { SafeERC20, IERC20 } from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
interface IFlashLoanLender {
/**
* @dev When `flashLoanSimple` is called on the Lender, it invokes the `receiveFlashLoanSimple` hook on the
* recipient.
*
* At the time of the call, the Lending Pool will have transferred `amount` for `token` to the recipient. Before
* this call returns, the recipient must have transferred `amount` plus `feeAmount` for the token back to the
* Lender, or else the entire flash loan will revert.
*
* `userData` is the same value passed in the `ILendingPool.flashLoanSimple` call.
*
* The flash loan lender forwards the initiator of the loan.
* It also expects back some call data from the receiver and returns it to the initiator.
*/
function flashLoanSimple(
address receiverAddress,
address asset,
uint256 amount,
bytes memory userData
)
external
returns (bytes memory);
}// SPDX-License-Identifier: GPL-3.0
pragma solidity 0.8.24;
import { SafeERC20, IERC20 } from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
interface IFlashLoanRecipient {
/**
* @dev When `flashLoanSimple` is called on the Lending Pool, it invokes the `receiveFlashLoanSimple` hook on the
* recipient.
*
* At the time of the call, the Lending Pool will have transferred `amount` for `token` to the recipient. Before
* this
* call returns, the recipient must have transferred `amount` plus `feeAmount` for the token back to the
* Lending Pool, or else the entire flash loan will revert.
*
* `userData` is the same value passed in the `ILendingPool.flashLoanSimple` call.
*
* The flash loan lender forwards the initiator of the loan.
* It also expects back the call data that it forwards to the initiator.
* @return success True if the execution of the operation succeeds, false otherwise
* @return data Any callback data that the initiator needs
*/
function receiveFlashLoanSimple(
address initiator,
IERC20 token,
uint256 amount,
uint256 feeAmount,
bytes memory userData
)
external
returns (bool success, bytes memory data);
}// SPDX-License-Identifier: GPL-3.0
pragma solidity 0.8.24;
interface IGasTank {
function allowList(address user) external returns (bool allowed);
function accessControllers(address controller) external returns (bool allowed);
function deposit() external payable;
function withdraw(uint256 amount) external;
function allowListUpdate(address contractAddress, bool allowed) external;
function accessControllerUpdate(address accessController, bool allowed) external;
function reimburseGas(address receiver, uint256 amount) external;
}// SPDX-License-Identifier: GPL-3.0
pragma solidity 0.8.24;
import { UD60x18 } from "@prb/math/src/UD60x18.sol";
interface IInterestRateStrategy {
function calculateInterestRate(UD60x18 utilization)
external
view
returns (UD60x18 liquidityRate, UD60x18 borrowRate);
}// SPDX-License-Identifier: GPL-3.0
pragma solidity 0.8.24;
import { IERC20 } from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import { UD60x18, ud } from "@prb/math/src/UD60x18.sol";
interface ILendingPool {
function allowedLenders(address lender) external view returns (bool);
function deposit(uint256 amount) external returns (uint256);
function withdraw(uint256 amount) external returns (uint256);
function getMinimumOpenBorrow() external view returns (uint256);
function setMinimumOpenBorrow(uint256 amount) external;
function setInterestRateStrategy(address newStrategy) external;
function getDebtAmount(address borrower) external view returns (uint256);
function getDepositAmount(address lender) external view returns (uint256);
function getTotalSupply() external view returns (uint256);
function getTotalBorrow() external view returns (uint256);
function getAsset() external view returns (IERC20);
function getNormalizedIncome() external view returns (UD60x18);
function getNormalizedDebt() external view returns (UD60x18);
function accrueInterest() external;
// PermissionedLendingPool Only
function updateLenderStatus(address lender, bool status) external;
// AccountManager
function borrow(uint256 amount, address onBehalfOf) external returns (uint256);
///@dev Repays loan of `onBehalfOf`, transferring funds from `onBehalfOf`
function repay(uint256 amount, address onBehalfOf) external returns (uint256);
///@dev Repays loan of `onBehalfOf`, transferring funds from `from`
function repay(uint256 amount, address onBehalfOf, address from) external returns (uint256);
}// SPDX-License-Identifier: GPL-3.0
pragma solidity 0.8.24;
import { SafeERC20, IERC20 } from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import { IAccount } from "./IAccount.sol";
import { IAccountManager } from "./IAccountManager.sol";
interface ILiquidationReceiver {
struct Props {
IERC20 asset;
IAccountManager manager;
IAccount account;
address liquidationFeeTo;
}
function initialize(Props memory props_) external;
function repay() external;
}// SPDX-License-Identifier: GPL-3.0
pragma solidity 0.8.24;
import { UD60x18 } from "@prb/math/src/UD60x18.sol";
interface IProtocolGovernor {
function getOwner() external view returns (address);
function getAddress(bytes32 id) external view returns (address);
function getImmutableAddress(bytes32 id) external view returns (address);
function setFee(bytes32 id, UD60x18 newFee) external;
function getFee(bytes32 id) external view returns (UD60x18);
function isProtocolDeprecated() external view returns (bool);
// Accounts Managers can open loans on behalf of Accounts they create.
function updateAccountManagerStatus(address manager, bool active) external;
function isAccountManager(address manager) external view returns (bool);
// RBAC
function grantRole(bytes32 role, address account) external;
function revokeRole(bytes32 role, address account) external;
function hasRole(bytes32 role, address account) external view returns (bool);
}// SPDX-License-Identifier: GPL-3.0
pragma solidity 0.8.24;
import { UD60x18 } from "@prb/math/src/UD60x18.sol";
// TODO: in the future, we will adjust this based off how long the account has been in liquidation
// Note: This slippage tolerance might be better to increase as a function of elapse
// time. That is, the slippage is higher the longer the account is in liquidation.
// A static slippage like this means we'd need to manually increase the value if the
// position can't be liquidate with the set slippage tolerance.
/// @notice This contract returns the slippageTolerance for a strategy liquidation as a function of how long that
/// strategy has been in
/// liquidation mode.
interface IStrategySlippageModel {
function calculateSlippage(uint256 timeSinceLiquidationStarted) external view returns (UD60x18 slippageTolerance);
}// SPDX-License-Identifier: GPL-3.0
pragma solidity 0.8.24;
import "../system/ProtocolGovernor.sol";
import "../external/blast/IBlast.sol";
/**
* @title JuiceGovernor
* @dev Allows for storing and management of protocol data related to our Blast deployment.
*/
contract JuiceGovernor is ProtocolGovernor {
constructor(
InitParams memory params,
address blast,
address blastPoints
)
ProtocolGovernor(params)
nonZeroAddressAndContract(blast)
nonZeroAddressAndContract(blastPoints)
{
_setImmutableAddress(GovernorLib.BLAST, blast);
_setImmutableAddress(GovernorLib.BLAST_POINTS, blastPoints);
}
}// SPDX-License-Identifier: GPL-3.0
pragma solidity 0.8.24;
import "./JuiceGovernor.sol";
import "../system/ProtocolModule.sol";
import "../libraries/Roles.sol";
/**
* @title JuiceModule
*/
abstract contract JuiceModule is AddressCheckerTrait {
using Roles for IProtocolGovernor;
IProtocolGovernor private _protocolGovernor;
/**
* @dev Constructor that initializes the Juice Governor for this contract.
*
* @param juiceGovernor_ The contract instance to use as the Juice Governor.
*/
constructor(address juiceGovernor_) nonZeroAddressAndContract(juiceGovernor_) {
_protocolGovernor = IProtocolGovernor(juiceGovernor_);
}
modifier onlyLendYieldSender() {
_protocolGovernor._validateRole(msg.sender, Roles.LEND_YIELD_SENDER, "LEND_YIELD_SENDER");
_;
}
function _getBlast() internal view returns (IBlast) {
return IBlast(_protocolGovernor.getImmutableAddress(GovernorLib.BLAST));
}
function _getBlastPoints() internal view returns (IBlastPoints) {
return IBlastPoints(_protocolGovernor.getImmutableAddress(GovernorLib.BLAST_POINTS));
}
}// SPDX-License-Identifier: GPL-3.0
pragma solidity 0.8.24;
import "../JuiceModule.sol";
/// @title BlastGas
/// @notice Exposes a method to claim gas refunds from the contract and send them to the protocol.
contract BlastGas {
IProtocolGovernor private _protocolGovernor;
event GasRefundClaimed(address indexed recipient, uint256 gasClaimed);
constructor(address protocolGovernor_) {
_protocolGovernor = IProtocolGovernor(protocolGovernor_);
IBlast blast = IBlast(_protocolGovernor.getImmutableAddress(GovernorLib.BLAST));
blast.configureClaimableGas();
}
/// @notice Claims the maximum possible gas from the contract with some recipient.
/// @dev This is permissionless because funds will go to the protocol gasFeeWallet and the maximum possible gas will
/// be claimed each time.
/// @dev IBlast.claimMaxGas guarnatees a 100% claim rate, but not all pending gas fees will be claimed.
/// @dev To check the current gas fee information of a contract, call IBlast.readGasParams(contractAddress).
function claimMaxGas() external returns (uint256 gasClaimed) {
IBlast blast = IBlast(_protocolGovernor.getImmutableAddress(GovernorLib.BLAST));
address _feeCollector = _protocolGovernor.getAddress(GovernorLib.FEE_COLLECTOR);
gasClaimed = blast.claimMaxGas(address(this), _feeCollector);
emit GasRefundClaimed(_feeCollector, gasClaimed);
}
}// SPDX-License-Identifier: GPL-3.0
pragma solidity 0.8.24;
import "../JuiceModule.sol";
/// @title BlastPoints
/// @notice Configures a hot wallet that operates the points API for this contract.
contract BlastPoints {
IProtocolGovernor private _protocolGovernor;
event PointsOperatorConfigured(address indexed operator);
constructor(address protocolGovernor_, address pointsOperator_) {
_protocolGovernor = IProtocolGovernor(protocolGovernor_);
IBlastPoints blast = IBlastPoints(_protocolGovernor.getImmutableAddress(GovernorLib.BLAST_POINTS));
blast.configurePointsOperator(pointsOperator_);
}
}// SPDX-License-Identifier: GPL-3.0
pragma solidity 0.8.24;
import { ProtocolModule, ProtocolGovernor } from "../system/ProtocolModule.sol";
import { Pausable } from "@openzeppelin/contracts/utils/Pausable.sol";
import { IERC20Metadata } from "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol";
import { SafeERC20, IERC20 } from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import { ReentrancyGuard } from "@openzeppelin/contracts/utils/ReentrancyGuard.sol";
import { MathUtils } from "../libraries/math/MathUtils.sol";
import { UD60x18, ud, UNIT, ZERO } from "@prb/math/src/UD60x18.sol";
import { IInterestRateStrategy } from "../interfaces/IInterestRateStrategy.sol";
import { ICollateralAggregator } from "../interfaces/ICollateralAggregator.sol";
import { IAccount } from "../interfaces/IAccount.sol";
import { OmegaDebtToken } from "./OmegaDebtToken.sol";
import { OmegaLiquidityToken } from "./OmegaLiquidityToken.sol";
import "../libraries/LendingLib.sol";
import "../libraries/Errors.sol";
import "../interfaces/IFlashLoanLender.sol";
import "../interfaces/ILendingPool.sol";
import "../interfaces/IFlashLoanRecipient.sol";
// Note: Areas for improvement
// 1. Compound interest, need to understand how debt amount and utilization contribute to linear interest
// 2. Unit, what should be way/ray/percentage
// a. Make a table for this or document it better inline
// 3. LTV vs liquidation threshold, maybe use threshold be consistent with aave
/// @notice Lending Pool Events
/// @dev Place all events used by the LendingPool contract here
abstract contract LendingPoolEvents {
/// @notice A `lender` has deposited `amount` of assets into the pool
event Deposit(address indexed lender, uint256 amount);
/// @notice A `lender` has withdrawn `amount` of assets from the pool
event Withdraw(address indexed lender, uint256 amount);
/// @notice A `borrower` has borrowed `amount` of assets from the pool
event Borrow(address indexed borrower, uint256 amount);
/// @notice A `borrower` has repaid `amount` of assets to the pool
event Repay(address indexed borrower, uint256 amount);
/// @notice The borrow rate has been updated to `rate`, indicating a change in the interest rate for borrowers
event BorrowRateUpdated(UD60x18 rate);
/// @notice The borrow index has been updated to `index`, indicating the interest accrued on borrowers debt
event BorrowIndexUpdated(UD60x18 index);
/// @notice The liquidity rate has been updated to `rate`, indicating a change in the interest rate for lenders
event LiquidityRateUpdated(UD60x18 rate);
/// @notice The liquidity index has been updated to `index`, indicating the interest accrued on lenders deposits
event LiquidityIndexUpdated(UD60x18 index);
/// @notice The interest rate strategy has been updated to `newStrategy`
event InterestRateStrategyUpdated(address newStrategy);
/// @notice The deposit cap has been updated to `newDepositCap`
event DepositCapUpdated(uint256 newDepositCap);
/// @notice Event when a flash loan has occurred
event FlashLoan(IERC20 indexed initiator, uint256 amount, uint256 fee);
/// @notice Minimum borrow has been updated to `newMinimumBorrow`
event MinimumBorrowUpdated(uint256 newMinimumBorrow);
}
/// @title Lending Pool
/// @notice The LendingPool contract manages the depositing and borrowing of assets
contract LendingPool is Pausable, ILendingPool, IFlashLoanLender, ProtocolModule, LendingPoolEvents, ReentrancyGuard {
using SafeERC20 for IERC20;
/// @notice The debt token
OmegaDebtToken public immutable debtToken;
/// @notice The liquidity token
OmegaLiquidityToken public immutable liquidityToken;
/// @notice Contract that calculates the interest rate
IInterestRateStrategy public strategy;
/// @notice The reserve state
LendingLib.Reserve public reserve;
/// @notice The cap to apply to deposits
uint256 public depositCap;
/// @notice Minimum amount of fees that can be collected
uint256 private _minimumFeeCollectionAmount;
/// @notice Minimum open borrow a user can have.
uint256 internal _minimumOpenBorrow;
struct BaseInitParams {
address interestRateStrategy;
string debtTokenName;
string debtTokenSymbol;
string liquidityTokenName;
string liquidityTokenSymbol;
uint256 minimumOpenBorrow;
}
constructor(
address protocolGovernor_,
BaseInitParams memory params
)
nonZeroAddress(_getLendAsset())
nonZeroAddress(params.interestRateStrategy)
ProtocolModule(protocolGovernor_)
nonZeroAddress(_getFeeCollector())
{
reserve = LendingLib.Reserve({
asset: IERC20(_getLendAsset()),
assetBalance: 0,
borrowRate: ZERO,
liquidityRate: ZERO,
liquidityIndex: UNIT,
borrowIndex: UNIT,
lastUpdateTimestamp: block.timestamp
});
/// TODO: create params struct and tune these params
uint8 decimals = IERC20Metadata(address(reserve.asset)).decimals();
_minimumFeeCollectionAmount = 10 ** decimals;
debtToken = new OmegaDebtToken(address(this), params.debtTokenName, params.debtTokenSymbol, decimals);
liquidityToken =
new OmegaLiquidityToken(address(this), params.liquidityTokenName, params.liquidityTokenSymbol, decimals);
strategy = IInterestRateStrategy(params.interestRateStrategy);
_minimumOpenBorrow = params.minimumOpenBorrow;
// The initial deposit cap is set ot the max
depositCap = type(uint256).max;
}
////////////////////
// Administrative functions
////////////////////
/// @notice Change the contract defining how interest rates respond to utilization
/// @param newStrategy Address of interest rate strategy to update to
function setInterestRateStrategy(address newStrategy) external nonZeroAddress(newStrategy) onlyOwner {
strategy = IInterestRateStrategy(newStrategy);
(UD60x18 liquidityRate, UD60x18 borrowRate) = strategy.calculateInterestRate(ud(0.5e18));
// strategy address can't be zero and at 50% utilization, borrow rate must be greater than liquidity rate
if (borrowRate <= liquidityRate) revert Errors.InvalidParams();
// Accrue interest
_accrueInterest();
// Update interest rate
_updateInterestRate();
emit InterestRateStrategyUpdated(newStrategy);
}
function getMinimumOpenBorrow() external view returns (uint256) {
return _minimumOpenBorrow;
}
function setMinimumOpenBorrow(uint256 minimumOpenBorrow) external onlyOwner {
_minimumOpenBorrow = minimumOpenBorrow;
}
function updateLenderStatus(address lender, bool status) external virtual override { }
function setDepositCap(uint256 newDepositCap) external onlyOwner {
depositCap = newDepositCap;
emit DepositCapUpdated(newDepositCap);
}
/// @notice Let the owner pause deposits and borrows
function pause() external onlyOwner {
_pause();
}
/// @notice Let the owner unpause deposits and borrows
function unpause() external onlyOwner {
_unpause();
}
////////////////////
// Lending Methods
////////////////////
/// @notice Public function for accruing interest rate so that users don't have to perform actions to update
/// indices.
function accrueInterest() public {
_accrueInterest();
_updateInterestRate();
}
/// @notice Deposit underlying assets into the pool
/// @param amount The amount of underlying assets to deposit
function deposit(uint256 amount)
public
virtual
whenProtocolNotDeprecated
whenNotPaused
nonReentrant
returns (uint256)
{
if (depositCap != type(uint256).max && amount + getTotalSupply() > depositCap) {
revert Errors.DepositCapExceeded();
}
_beforeAction();
reserve.assetBalance += amount;
IERC20(reserve.asset).safeTransferFrom(msg.sender, address(this), amount);
liquidityToken.mint(msg.sender, amount, reserve.liquidityIndex, MathUtils.ROUNDING.DOWN);
_mintToTreasury();
_updateInterestRate();
emit Deposit(msg.sender, amount);
return amount;
}
/// @notice Withdraw underlying assets from the pool. If argument is uint256 max, then withdraw everything.
/// @param amount The amount of underlying assets to withdraw
function withdraw(uint256 amount) public virtual whenNotPaused nonReentrant returns (uint256) {
uint256 amountToWithdraw = amount;
_beforeAction();
bool isMaxWithdraw = false;
uint256 userBalance = liquidityToken.balanceOf(msg.sender);
if (amount >= userBalance) {
amountToWithdraw = userBalance;
isMaxWithdraw = true;
}
reserve.assetBalance -= amountToWithdraw;
liquidityToken.burn(msg.sender, amountToWithdraw, reserve.liquidityIndex, isMaxWithdraw, MathUtils.ROUNDING.UP);
IERC20(reserve.asset).safeTransfer(msg.sender, amountToWithdraw);
_mintToTreasury();
_updateInterestRate();
emit Withdraw(msg.sender, amountToWithdraw);
return amountToWithdraw;
}
function flashLoanSimple(
address receiverAddress,
address asset,
uint256 amount,
bytes memory userData
)
external
virtual
nonZeroAddress(receiverAddress)
whenNotPaused
nonReentrant
returns (bytes memory)
{
if (asset != address(reserve.asset)) {
revert Errors.InvalidFlashLoanAsset();
}
uint256 balanceBefore = reserve.asset.balanceOf(address(this));
uint256 expectedFee = ud(amount).mul(_flashLoanFee()).unwrap();
if (amount > balanceBefore) {
revert Errors.InvalidFlashLoanBalance();
}
reserve.asset.safeTransfer(receiverAddress, amount);
(bool success, bytes memory result) = IFlashLoanRecipient(receiverAddress).receiveFlashLoanSimple(
msg.sender, reserve.asset, amount, expectedFee, userData
);
if (!success) {
revert Errors.InvalidFlashLoanRecipientReturn();
}
uint256 balanceAfter = reserve.asset.balanceOf(address(this));
if (balanceBefore > balanceAfter) {
revert Errors.InvalidPostFlashLoanBalance();
}
uint256 fee = balanceAfter - balanceBefore;
if (expectedFee > fee) {
revert Errors.InsufficientFlashLoanFeeAmount();
}
if (fee > 0) {
reserve.asset.safeTransfer(_getFeeCollector(), fee);
}
emit FlashLoan(reserve.asset, amount, fee);
return result;
}
//////////////////////////
// Account Managers only
//////////////////////////
function borrow(
uint256 amount,
address onBehalfOf
)
external
whenProtocolNotDeprecated
whenNotPaused
onlyAccountManager
nonReentrant
returns (uint256)
{
if (amount > reserve.asset.balanceOf(address(this))) {
revert Errors.InsufficientLiquidity();
}
_beforeAction();
reserve.assetBalance -= amount;
debtToken.mint(onBehalfOf, amount, reserve.borrowIndex, MathUtils.ROUNDING.UP);
reserve.asset.safeTransfer(onBehalfOf, amount);
_mintToTreasury();
_updateInterestRate();
if (amount < _minimumOpenBorrow) {
revert Errors.InvalidMinimumOpenBorrow();
}
emit Borrow(onBehalfOf, amount);
return amount;
}
function repay(
uint256 amount,
address onBehalfOf
)
external
whenNotPaused
onlyAccountManager
nonReentrant
returns (uint256)
{
return _repay(amount, onBehalfOf, onBehalfOf);
}
function repay(
uint256 amount,
address onBehalfOf,
address from
)
public
virtual
whenNotPaused
onlyAccountManager
nonReentrant
returns (uint256)
{
return _repay(amount, onBehalfOf, from);
}
////////////////////////
// Tokenization Methods
////////////////////////
/// @notice Get the borrower's debt balance
/// @param borrower The address of the borrower
/// @return debt The amount of debt the borrower has
function getDebtAmount(address borrower) external view returns (uint256 debt) {
debt = debtToken.balanceOf(borrower);
}
/// @notice Get the lender's deposit balance
/// @param lender The address of the lender
/// @return balance The amount of the lender's deposit
function getDepositAmount(address lender) external view returns (uint256 balance) {
balance = liquidityToken.balanceOf(lender);
}
/// @notice Get the total amount of liquidity
function getTotalSupply() public view returns (uint256) {
return ud(liquidityToken.scaledTotalSupply()).mul(reserve.liquidityIndex).unwrap();
}
/// @notice Get the total amount of outstanding debt
function getTotalBorrow() public view returns (uint256) {
return ud(debtToken.scaledTotalSupply()).mul(reserve.borrowIndex).unwrap();
}
//////////////////////////
// Views
//////////////////////////
/// @notice Returns the asset used for deposits/borrows
function getAsset() public view returns (IERC20) {
return reserve.asset;
}
/// @notice Returns the current liquidity rate
function getLiquidityRate() public view returns (UD60x18) {
return reserve.liquidityRate;
}
/// @notice Returns the current borrow rate
function getBorrowRate() public view returns (UD60x18) {
return reserve.borrowRate;
}
/// @notice Returns the ongoing normalized income for the reserve
/// A value of 1e18 means there is no income. As time passes, the income is accrued
/// A value of 2*1e18 means for each unit of asset one unit of income has been accrued
/// @return normalizedIncome The normalized income.
function getNormalizedIncome() public view virtual returns (UD60x18) {
uint256 timestamp = reserve.lastUpdateTimestamp;
// slither-disable-next-line incorrect-equality
if (timestamp == block.timestamp) {
return reserve.liquidityIndex;
}
return MathUtils.calculateCompoundedInterest(reserve.liquidityRate, timestamp).mul(reserve.liquidityIndex);
}
/// @notice Returns the ongoing normalized variable debt for the reserve
/// A value of 1e18 means there is no debt. As time passes, the income is accrued
/// A value of 2*1e18 means that for each unit of debt, one unit worth of interest has been accumulated
/// @return normalizedDebt The normalized variable debt.
function getNormalizedDebt() public view returns (UD60x18) {
uint256 timestamp = reserve.lastUpdateTimestamp;
// slither-disable-next-line incorrect-equality
if (timestamp == block.timestamp) {
return reserve.borrowIndex;
}
return MathUtils.calculateCompoundedInterest(reserve.borrowRate, timestamp).mul(reserve.borrowIndex);
}
function allowedLenders(address lender) external view virtual override returns (bool) { }
/////////////
// Internal
/////////////
/// @notice Repay `amount` of assets to the pool for a `borrower`
/// @param amount The amount of underlying assets to repay
/// @param borrower The borrower to repay for
/// @param from The address from which to transfer the funds
function _repay(uint256 amount, address borrower, address from) internal returns (uint256) {
_beforeAction();
uint256 paybackAmount = amount;
// Repay rest of debt
uint256 debtAmount = debtToken.balanceOf(borrower);
bool isMaxRepay = false;
if (paybackAmount >= debtAmount) {
paybackAmount = debtAmount;
isMaxRepay = true;
}
reserve.assetBalance += paybackAmount;
debtToken.burn(borrower, paybackAmount, reserve.borrowIndex, isMaxRepay, MathUtils.ROUNDING.DOWN);
reserve.asset.safeTransferFrom(from, address(this), paybackAmount);
_mintToTreasury();
_updateInterestRate();
uint256 remainingDebt = debtToken.balanceOf(borrower);
if (remainingDebt > 0 && remainingDebt < _minimumOpenBorrow) {
revert Errors.InvalidMinimumOpenBorrow();
}
emit Repay(borrower, paybackAmount);
return paybackAmount;
}
/// @notice Update the liquidity and borrow indices based off the last interest rates.
/// @dev This function should be called before any deposit, withdraw, borrow, or repay
/// @dev This mirrors Aave Protocol's update index functions
function _accrueInterest() internal {
// Get the current interest rate
if (reserve.liquidityRate > ZERO) {
// Calculate cumulative liquidity interest since last update
UD60x18 cumulatedLiquidityInterest =
MathUtils.calculateCompoundedInterest(reserve.liquidityRate, reserve.lastUpdateTimestamp);
// Accumulate interest into the liquidity index
reserve.liquidityIndex = cumulatedLiquidityInterest.mul(reserve.liquidityIndex);
// Calculate cumulative borrow interest since last update
UD60x18 cumulatedBorrowInterest =
MathUtils.calculateCompoundedInterest(reserve.borrowRate, reserve.lastUpdateTimestamp);
reserve.borrowIndex = cumulatedBorrowInterest.mul(reserve.borrowIndex);
emit LiquidityIndexUpdated(reserve.liquidityIndex);
emit BorrowIndexUpdated(reserve.borrowIndex);
}
reserve.lastUpdateTimestamp = block.timestamp;
}
/**
* @dev Update the current interest rate based on the strategy
*/
function _updateInterestRate() internal {
// Calculate the current interest rate
// Available liquidity is the amount current balance left in the reserve
uint256 totalDebt = getTotalBorrow();
uint256 availableLiquidity = reserve.assetBalance;
// Utilization is: debt / (available liquidity + debt)
UD60x18 utilization = ZERO;
if (totalDebt > 0) {
utilization = ud(totalDebt).div(ud(availableLiquidity + totalDebt));
}
UD60x18 baseLiquidityRate;
(baseLiquidityRate, reserve.borrowRate) = strategy.calculateInterestRate(utilization);
// The effective liquidity rate is the liquidity rate minus the lending fee
// If lenders should earn 10% and lending fee is 10%, then they should earn 10% * (100% - 10%) or 9%.
reserve.liquidityRate = baseLiquidityRate.mul(UNIT.sub(_lendingFee()));
emit BorrowRateUpdated(reserve.borrowRate);
emit LiquidityRateUpdated(reserve.liquidityRate);
}
function _mintToTreasury() internal {
uint256 totalLiquidityTokens = liquidityToken.totalSupply();
uint256 totalDebtAndUnusedTokens = debtToken.totalSupply() + reserve.assetBalance;
if (totalDebtAndUnusedTokens > totalLiquidityTokens) {
uint256 liquidityTokensToMint = totalDebtAndUnusedTokens - totalLiquidityTokens;
// Because the math rounds down, dust will be accumulated in pool. This ensures we aren't pulling that dust
// every time.
if (liquidityTokensToMint > _minimumFeeCollectionAmount) {
liquidityToken.mint(
_getFeeCollector(), liquidityTokensToMint, reserve.liquidityIndex, MathUtils.ROUNDING.DOWN
);
}
}
}
function _beforeAction() internal virtual {
_accrueInterest();
}
}// SPDX-License-Identifier: GPL-3.0
pragma solidity 0.8.24;
import "solady/src/tokens/ERC20.sol";
import { ILendingPool } from "../interfaces/ILendingPool.sol";
import { UD60x18 } from "@prb/math/src/UD60x18.sol";
import "solady/src/utils/FixedPointMathLib.sol";
import "../libraries/traits/AddressCheckerTrait.sol";
import "../libraries/Errors.sol";
import "../libraries/math/MathUtils.sol";
/// @title LendingToken
/// @notice ERC20 token representing the Lending pool positions
/// - Extends ERC20 by adding scaledBalanceOf() and scaledTotalSupply()
/// - Overrides balanceOf() and totalSupply() to return scaled values
/// - Disables transfers other than mint and burn
///
/// @dev The underlying tokens minted and burned are scaled by the normalized income index.
/// In this way, as the income index increases, the amount of the tokens increases and user
/// balances increase. This approach closely follows the approach used by the Aave Protocol.
abstract contract LendingToken is ERC20, AddressCheckerTrait {
using FixedPointMathLib for uint256;
ILendingPool internal immutable _pool;
uint8 private immutable _decimals;
string private _name;
string private _symbol;
constructor(address pool_, uint8 decimals_, string memory name_, string memory symbol_) nonZeroAddress(pool_) {
_pool = ILendingPool(pool_);
_decimals = decimals_;
_name = name_;
_symbol = symbol_;
}
modifier onlyLendingPool() {
if (msg.sender != address(_pool)) revert Errors.OnlyLendingPool();
_;
}
function name() public view override returns (string memory) {
return _name;
}
function symbol() public view override returns (string memory) {
return _symbol;
}
function decimals() public view override returns (uint8) {
return _decimals;
}
/// @notice The total supply unscaled
function scaledTotalSupply() public view returns (uint256) {
return super.totalSupply();
}
/// @notice The balance of an account unscaled
function scaledBalanceOf(address account) public view returns (uint256) {
return super.balanceOf(account);
}
/// @notice Mint the token to an account, the amount of tokens to mint is scaled down
/// based on the normalized debt index.
/// @param account The account to mint the tokens to
/// @param amount The scaled amount of tokens to mint
/// @param index The normalized debt index
function mint(address account, uint256 amount, UD60x18 index, MathUtils.ROUNDING mode) external onlyLendingPool {
uint256 amountScaled = _scaleAmount(amount, index, mode);
_mint(account, amountScaled);
}
/// @notice Burn the token from an account, the amount of tokens to burn is scaled down
/// based on the normalized debt index.
/// @param account The account to burn the tokens from
/// @param amount The scaled amount of tokens to burn)
/// @param index The normalized debt index
/// @param max Whether or not to burn the maximum amount
function burn(
address account,
uint256 amount,
UD60x18 index,
bool max,
MathUtils.ROUNDING mode
)
external
onlyLendingPool
{
uint256 burnAmount;
if (max) {
burnAmount = scaledBalanceOf(account);
} else {
burnAmount = _scaleAmount(amount, index, mode);
}
_burn(account, burnAmount);
}
function _scaleAmount(uint256 amount, UD60x18 index, MathUtils.ROUNDING mode) internal pure returns (uint256) {
uint256 _index = index.unwrap();
return mode == MathUtils.ROUNDING.UP ? amount.divWadUp(_index) : amount.divWad(_index);
}
/// @notice Disables transfers other than mint and burn
/// @dev Done explicitly because solady transfers do not prevent transferring to zero address.
function transfer(address, uint256) public pure override returns (bool) {
revert Errors.TransferDisabled();
}
function transferFrom(address, address, uint256) public pure override returns (bool) {
revert Errors.TransferDisabled();
}
}// SPDX-License-Identifier: GPL-3.0
pragma solidity 0.8.24;
import "./LendingToken.sol";
/// @title OmegaDebtToken
/// @notice ERC20 token representing the Lending pool deposits and debt
/// - Extends ERC20 by adding scaledBalanceOf() and scaledTotalSupply()
/// - Overrides balanceOf() and totalSupply() to return scaled values
/// - Disables transfers other than mint and burn
///
/// @dev The underlying tokens minted and burned are scaled by the normalized debt index.
/// In this way, as the debt index increases, the amount of the tokens increases and user
/// balances increase. This approach closely follows the approach used by the Aave Protocol.
contract OmegaDebtToken is LendingToken {
constructor(
address pool_,
string memory name_,
string memory symbol_,
uint8 decimals_
)
nonZeroAddress(pool_)
LendingToken(pool_, decimals_, name_, symbol_)
{ }
/// @notice The total supply of the token scaled by the normalized debt index
function totalSupply() public view override returns (uint256) {
return ud(scaledTotalSupply()).mul(_pool.getNormalizedDebt()).unwrap();
}
/// @notice The balance of an account scaled by the normalized debt index
function balanceOf(address account) public view override returns (uint256) {
uint256 accountBalance = super.balanceOf(account);
if (accountBalance == 0) {
return 0;
}
return ud(accountBalance).mul(_pool.getNormalizedDebt()).unwrap();
}
}// SPDX-License-Identifier: GPL-3.0
pragma solidity 0.8.24;
import "./LendingToken.sol";
/// @title OmegaLiquidityToken
/// @notice ERC20 token representing the Lending pool deposits
/// - Extends ERC20 by adding scaledBalanceOf() and scaledTotalSupply()
/// - Overrides balanceOf() and totalSupply() to return scaled values
/// - Disables transfers other than mint and burn
///
/// @dev The underlying tokens minted and burned are scaled by the normalized income index.
/// In this way, as the income index increases, the amount of the tokens increases and user
/// balances increase. This approach closely follows the approach used by the Aave Protocol.
contract OmegaLiquidityToken is LendingToken {
constructor(
address pool_,
string memory name_,
string memory symbol_,
uint8 decimals_
)
nonZeroAddress(pool_)
LendingToken(pool_, decimals_, name_, symbol_)
{ }
/// @notice The total supply of the token scaled by the normalized debt index
function totalSupply() public view override returns (uint256) {
return ud(scaledTotalSupply()).mul(_pool.getNormalizedIncome()).unwrap();
}
/// @notice The balance of an account scaled by the normalized debt index
function balanceOf(address account) public view override returns (uint256) {
uint256 accountBalance = super.balanceOf(account);
if (accountBalance == 0) {
return 0;
}
return ud(accountBalance).mul(_pool.getNormalizedIncome()).unwrap();
}
}// SPDX-License-Identifier: GPL-3.0
pragma solidity 0.8.24;
import "forge-std/src/console2.sol";
// @notice Collections of protocol error messages.
library Errors {
// GENERAL
/// @notice Unauthorized access
error Unauthorized();
/// @notice Disabled functionality
error FunctionalityDisabled();
/// @notice Functionality not supported
error FunctionalityNotSupported();
/// @notice Invalid parameters passed to function
error InvalidParams();
/// @notice ZeroAddress
error ZeroAddress();
/// @notice Contract does not exist
error ContractDoesNotExist();
/// @notice Invalid amount requested by caller
error InvalidAmount();
/// @notice when parameter cannot be equal to zero
error ParamCannotBeZero();
/// @notice ERC20 is not transferrable
error TransferDisabled();
/// @notice Address doesn't have role
error UnauthorizedRole(address account, string role);
/// @notice Action disabled because contract is deprecated
error Deprecated();
// ACCESS
// NOTE: maybe this should be refactored into a generic Errors
/// @notice Only the lending pool can call this function
error OnlyLendingPool();
// COLLATERAL
/// @notice Invalid collateral monitor update
error InvalidCollateralMonitorUpdate();
error NoTellorValueRetrieved(uint256 timestamp);
error StaleTellorValue(uint256 value, uint256 timestamp);
error StaleTellorEVMCallTimestamp(uint256 callTimestamp);
error CannotGoBackInTime();
error InvalidYieldClaimed(uint256 expectedYield, uint256 actualYield);
// LENDING
/// @notice Insufficient liquidity to fulfill action
error InsufficientLiquidity();
/// @notice User doesn't have enough collateral backing their position
error InsufficientCollateral();
/// @notice Requested borrow is not greater than minimum open borrow amount
error InvalidMinimumOpenBorrow();
/// @notice Deposit cap exceeded
error DepositCapExceeded();
/// @notice Max deposit per account exceeded
error MaxDepositPerAccountExceeded();
// FLASH LOANS
/// @notice Invalid flash loan balance
error InvalidFlashLoanBalance();
/// @notice Invalid flash loan asset
error InvalidFlashLoanAsset();
/// @notice Flash loan unpaid
error InvalidPostFlashLoanBalance();
/// @notice Invalid flash loan fee
error InsufficientFlashLoanFeeAmount();
/// @notice Flash loan recipient doesn't return success
error InvalidFlashLoanRecipientReturn();
// ACCOUNTS
/// @notice Account failed solvency check after some action.
/// @dev The account's debt isn't sufficiently collateralized and/or the account is liquidatable.
error AccountInsolvent();
/// @dev Account cannot be liquidated
error AccountHealthy();
/// @notice Account is being liquidated
error AccountBeingLiquidated();
/// @notice Account is not being liquidated
error AccountNotBeingLiquidated();
/// @notice Account hasn't been created yet
error AccountNotCreated();
// INVESTMENT
/// @notice Account is not liquidatable
error NotLiquidatable();
/// @notice Account is not repayable
error NotRepayable();
/// @notice Account type invalid
error InvalidAccountType();
/// @notice Interaction with a strategy that is not approved
error StrategyNotApproved();
/// @notice Liquidator has no funds to repay
error NoLiquidatorFunds();
/// @notice Requested profit is not claimable from account (if account has debt or not enough profit to fill request
/// amount)
error NotClaimableProfit();
/// @notice Used when Gelato automation task was already started
error AlreadyStartedTask();
/// @notice Assets not received
error WithdrawnAssetsNotReceived();
///////////////////////////
// Multi-step Strategies
///////////////////////////
/// @notice Account is attempting to withdraw more strategy shares than their unlocked share balance.
/// @dev An account's balanceOf(strategyShareToken) is their totalShareBalance.
/// Since some strategies are multi-step, when a account withdraws, those shares are added to a separate variable
/// known
/// as their lockedShareBalance.
/// A account's unlocked share balance when it comes to withdrawals is their totalShareBalance - lockedShareBalance.
error PendingStrategyWithdrawal(address account);
/// @notice Account cannot deposit into the same multi-step strategy until their previous deposit has cleared.
error PendingStrategyDeposit(address account);
//////////////////////////
/// OmegaGMXStrategyVault
//////////////////////////
/// @notice When already exist a depositKey in the vault
error MustNotHavePendingValue();
/// @notice When not sending eth to pay for the fee in a deposit or withdrawal
error MustSendETHForExecutionFee();
/// Pyth
error PythPriceFeedNotFound(address asset);
error PythInvalidNonPositivePrice(address asset);
// Particle
error ExistingPosition();
error NoPosition();
}
library BlastErrors {
/// @dev For contracts that need to compound claimable yield onto themselves, they cannot claim with themselves as
/// the recipient.
/// To get around this, they claim to another contract that reflects the yield back to them.
error InvalidReflection(uint256 expected, uint256 actual);
}// SPDX-License-Identifier: GPL-3.0
pragma solidity 0.8.24;
/// @notice Store keys used by stores in a Governor contract (ProtocolGovernor, etc).
library GovernorLib {
///////////////
// COMMON
///////////////
/// @notice Returns price of an asset given some address. Prices are denominated in the lending pool loan asset.
bytes32 public constant PRICE_PROVIDER = keccak256(abi.encode("PRICE_PROVIDER"));
/// @notice Address that receives fee generated by lending, accounts, and strategies
bytes32 public constant FEE_COLLECTOR = keccak256(abi.encode("FEE_COLLECTOR"));
/// @notice Address that is responsible for issuing gas reimbursements to protocol contracts
bytes32 public constant GAS_TANK = keccak256(abi.encode("GAS_TANK"));
/// @notice Lending Pool
bytes32 public constant LENDING_POOL = keccak256(abi.encode("LENDING_POOL"));
/// @notice Gelato Automate
bytes32 public constant GELATO_AUTOMATE = keccak256(abi.encode("GELATO_AUTOMATE"));
/// @notice Pyth Stable
bytes32 public constant PYTH = keccak256(abi.encode("PYTH"));
/// @notice Asset used to facilitate lending and borrowing.
bytes32 public constant LEND_ASSET = keccak256(abi.encode("LEND_ASSET"));
/// @notice Blast native contract implementing IBlast interface for configuring gas refunds and native ETH rebasing.
bytes32 public constant BLAST = keccak256(abi.encode("BLAST"));
/// @notice Blast native contract used on contract initialization to assign an operator that configures points
/// received by that smart contract.
bytes32 public constant BLAST_POINTS = keccak256(abi.encode("BLAST_POINTS"));
///////////////
// FEES
///////////////
bytes32 public constant LENDING_FEE = keccak256(abi.encode("LENDING_FEE"));
bytes32 public constant FLASH_LOAN_FEE = keccak256(abi.encode("FLASH_LOAN_FEE"));
/// @notice % taken from any funds used to repay debt during liquidating state.
/*
If an Account with 100 USDB Strategy position gets liquidated with protocolShare of 4%, liquidatorShare of 1%.
If no slippage, 100 USDB is received by Repayment contract.
Repayment contract is executed with:
- 4 USDB going to protocol
- 1 USDB going to liquidator
- 95 USDB going to repay Account debt
*/
bytes32 public constant PROTOCOL_LIQUIDATION_SHARE = keccak256(abi.encode("PROTOCOL_LIQUIDATION_SHARE"));
bytes32 public constant LIQUIDATOR_SHARE = keccak256(abi.encode("LIQUIDATOR_SHARE"));
}// SPDX-License-Identifier: GPL-3.0
pragma solidity 0.8.24;
import { SafeERC20, IERC20 } from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import { UD60x18 } from "@prb/math/src/UD60x18.sol";
library LendingLib {
/// @notice The reserve state
struct Reserve {
/// @notice The address of the underlying asset used for deposits/borrows
IERC20 asset;
/// @notice The current balance of the asset in the pool
uint256 assetBalance;
/// @notice The current interest rate on borrowing
UD60x18 borrowRate;
/// @notice The liquidity rate, as defined in Aave Protocol white paper
UD60x18 liquidityRate;
/// @notice Liquidity Index as defined in Aave Protocol white paper
UD60x18 liquidityIndex;
/// @notice Borrow Index as defined in Aave Protocol white paper
UD60x18 borrowIndex;
/// @notice The last time the reserves state was updated
uint256 lastUpdateTimestamp;
}
}// SPDX-License-Identifier: GPL-3.0
pragma solidity 0.8.24;
import "./Errors.sol";
import "../interfaces/IProtocolGovernor.sol";
/// @notice List of permissions that can be granted to addresses.
library Roles {
/// @notice Can call the `sendYield` function on the JuiceLendingPool to redirect yield back to senders.
bytes32 public constant LEND_YIELD_SENDER = keccak256(abi.encode("LEND_YIELD_SENDER"));
/// @notice Gas tank depositor
bytes32 public constant GAS_TANK_DEPOSITOR = keccak256(abi.encode("GAS_TANK_DEPOSITOR"));
function _validateRole(
IProtocolGovernor governor,
address account,
bytes32 role,
string memory roleName
)
internal
view
{
if (!governor.hasRole(role, account)) {
revert Errors.UnauthorizedRole(account, roleName);
}
}
}// SPDX-License-Identifier: GPL-3.0
pragma solidity 0.8.24;
import { UD60x18, ud } from "@prb/math/src/UD60x18.sol";
library AccountLib {
/// @notice The type of account that can be created
enum Type {
EXTERNAL, // Accounts that allow taking funds out of the protocol
INTERNAL // Accounts that require funds remain in the protocol
}
/// @notice The health of the account
/// The collateral and equity values are all denominated in the debt amount.
struct Health {
uint256 debtAmount;
uint256 collateralValue;
uint256 investmentValue;
bool isLiquidatable;
bool hasBadDebt;
}
/// @notice Expected values resulting from a collateral liquidation.
/// @param actualDebtToLiquidate the amount of debt to cover for the account
/// @param collateralAmount the amount of collateral to receive
/// @param bonusCollateral the amount of bonus collateral included in the collateralAmount
struct CollateralLiquidation {
uint256 actualDebtToLiquidate;
uint256 collateralAmount;
uint256 bonusCollateral;
}
/// @notice The state of an account's lending pool loan
struct Loan {
/// @notice The amount of debt the borrower has
uint256 debtAmount;
/// @notice The value of the borrowers collateral in debt token
uint256 collateralValue;
/// @notice The current loan to value ratio of the borrower
UD60x18 ltv;
/// @notice Borrower cannot perform a borrow if it puts their ltv over this amount
UD60x18 maxLtv;
}
struct LiquidationStatus {
bool isLiquidating;
uint256 liquidationStartTime;
}
/* @notice Liquidator fee.
@dev protocolShare + liquidatorShare = liquidationFee.
liquidationFee is % deducted from liquidated funds before they are used towards repayment.
*/
struct LiquidationFee {
UD60x18 protocolShare;
UD60x18 liquidatorShare;
}
/// @notice
struct CreateAccountProps {
address owner;
AccountLib.Type accountType;
}
/// @notice Custom meta txn for creating an account
struct CreateAccountData {
address owner;
uint256 accountType;
bytes signature;
}
/// @notice Data to sign when creating an account gaslessly
struct CreateAccount {
address owner;
uint256 accountType;
}
}// SPDX-License-Identifier: GPL-3.0
// Source: Aave V3 Core Protocol
// Permalink:
// https://github.com/aave/aave-v3-core/blob/6070e82d962d9b12835c88e68210d0e63f08d035/contracts/protocol/libraries/math/MathUtils.sol
// Modifications:
// - Added Slither comments to silence warnings from divide-before-multiply
pragma solidity 0.8.24;
import { UD60x18, ud, UNIT, uUNIT, ZERO } from "@prb/math/src/UD60x18.sol";
/**
* @title MathUtils library
* @notice Provides functions to perform linear and compounded interest calculations
*/
library MathUtils {
/// @dev Used in token math to document rounding method being used.
/// This is useful when we always want to round in favor of the protocol to disallow users to steal funds.
enum ROUNDING {
UP,
DOWN
}
/// @dev Ignoring leap years
uint256 public constant ONE_YEAR = 365 days;
/**
* @notice FV = P*e^(r*t) where P is 1
* @dev Function to calculate the interest using a compounded interest rate formula
* @param rate The interest rate per anum, 1e18 precision
* @param lastUpdateTimestamp The timestamp of the last update of the interest
* @param currentTimestamp The current timestamp
* @return The interest rate compounded during the timeDelta
*/
function calculateCompoundedInterest(
UD60x18 rate,
uint256 lastUpdateTimestamp,
uint256 currentTimestamp
)
internal
pure
returns (UD60x18)
{
UD60x18 principal = UNIT;
uint256 elapsed = currentTimestamp - lastUpdateTimestamp;
if (elapsed == 0) {
return principal;
}
uint256 exponent = (elapsed * rate.unwrap()) / ONE_YEAR;
return principal.mul(ud(exponent).exp());
}
/**
* @dev Calculates the compounded interest between the timestamp of the last update and the current block timestamp
* @param rate The interest rate
* @param lastUpdateTimestamp The timestamp from which the interest accumulation needs to be calculated
* @return The interest rate compounded between lastUpdateTimestamp and current block timestamp
*
*/
function calculateCompoundedInterest(UD60x18 rate, uint256 lastUpdateTimestamp) internal view returns (UD60x18) {
return calculateCompoundedInterest(rate, lastUpdateTimestamp, block.timestamp);
}
/// @notice Converts a number with `inputDecimals`, to a number with given amount of decimals
/// @param value The value to convert
/// @param inputDecimals The amount of decimals the input value has
/// @param targetDecimals The amount of decimals to convert to
/// @return The converted value
function scaleDecimals(uint256 value, uint8 inputDecimals, uint8 targetDecimals) internal pure returns (uint256) {
if (targetDecimals == inputDecimals) return value;
if (targetDecimals > inputDecimals) return value * (10 ** (targetDecimals - inputDecimals));
return value / (10 ** (inputDecimals - targetDecimals));
}
/// @notice Converts a number with `inputDecimals`, to a number with given amount of decimals
/// @param value The value to convert
/// @param inputDecimals The amount of decimals the input value has
/// @param targetDecimals The amount of decimals to convert to
/// @return The converted value
function scaleDecimals(int256 value, uint8 inputDecimals, uint8 targetDecimals) internal pure returns (int256) {
if (targetDecimals == inputDecimals) return value;
if (targetDecimals > inputDecimals) return value * int256(10 ** (targetDecimals - inputDecimals));
return value / int256(10 ** (inputDecimals - targetDecimals));
}
/// @notice Converts a number with `decimals`, to a UD60x18 type
/// @param value The value to convert
/// @param decimals The amount of decimals the value has
/// @return The number as a UD60x18
function fromTokenDecimals(uint256 value, uint8 decimals) internal pure returns (UD60x18) {
return ud(scaleDecimals(value, decimals, 18));
}
/// @notice Converts a UD60x18 number with `decimals`, to it's uint256 type scaled down.
/// @param value The value to convert
/// @param decimals The amount of decimals the value has
/// @return The number as a scaled down uint256
function toTokenDecimals(UD60x18 value, uint8 decimals) internal pure returns (uint256) {
return scaleDecimals(value.unwrap(), 18, decimals);
}
/// @notice Truncates a UD60x18 number down to the correct precision.
/// @param value The value to convert
/// @param decimals The amount of decimals the value has
/// @return The truncated UD60x18 number
function truncate(UD60x18 value, uint8 decimals) internal pure returns (UD60x18) {
return fromTokenDecimals(toTokenDecimals(value, decimals), decimals);
}
}// SPDX-License-Identifier: GPL-3.0
pragma solidity 0.8.24;
import "../Errors.sol";
/// @title Address checker trait
/// @notice Introduces methods and modifiers for checking addresses
abstract contract AddressCheckerTrait {
/// @dev Prevents a contract using an address if it is a zero address
modifier nonZeroAddress(address _address) {
if (_address == address(0)) {
revert Errors.ZeroAddress();
}
_;
}
/// @dev Prevents a contract using an address if it is either a zero address or is not an existing contract
modifier nonZeroAddressAndContract(address _address) {
if (_address == address(0)) {
revert Errors.ZeroAddress();
}
if (!_contractExists(_address)) {
revert Errors.ContractDoesNotExist();
}
_;
}
/// @notice Returns true if addr is a contract address
/// @param addr The address to check
function _contractExists(address addr) internal view returns (bool) {
return addr.code.length > 0;
}
}// SPDX-License-Identifier: GPL-3.0
pragma solidity 0.8.24;
import { UD60x18, ud, UNIT, ZERO } from "@prb/math/src/UD60x18.sol";
import "@openzeppelin/contracts/utils/structs/EnumerableSet.sol";
import "@openzeppelin/contracts/access/Ownable2Step.sol";
import "../libraries/Errors.sol";
import "../libraries/traits/AddressCheckerTrait.sol";
import "../libraries/GovernorLib.sol";
import "../interfaces/IProtocolGovernor.sol";
import "../libraries/Roles.sol";
abstract contract ProtocolGovernorEvents {
event FeeUpdated(bytes32 indexed id, UD60x18 newLiquidationFee);
event AddressSet(bytes32 indexed id, address newAddress);
event ImmutableAddressSet(bytes32 indexed id, address newAddress);
event ManagerStatusUpdated(address indexed manager, bool status);
event InvestmentAccountRegistered(address indexed account);
event InvestmentAccountCreditIncreased(address indexed account, uint256 amount);
event InvestmentAccountCreditDecreased(address indexed account, uint256 amount);
event RoleSet(bytes32 indexed role, address indexed account, bool status);
}
/**
* @title ProtocolGovernor
* @dev Allows for storing and management of common protocol data (roles, addresses, configuration).
*/
contract ProtocolGovernor is Ownable2Step, AddressCheckerTrait, ProtocolGovernorEvents, IProtocolGovernor {
/// @notice Map of contract names to their contract addresses.
mapping(bytes32 => address) internal _addresses;
/// @notice Immutable map of contract names to their contract addresses.
mapping(bytes32 => address) internal _immutableAddresses;
/// @notice Map of fee IDs to their fees.
/// @dev Fees cannot be greater than or equal to 100%.
mapping(bytes32 => UD60x18) internal _fees;
/// @notice Managers that can register accounts.
mapping(address => bool) internal _managers;
/// @notice Tracking roles granted to addresses.
mapping(address => mapping(bytes32 => bool)) internal _roles;
/// @notice If true, the protocol is deprecated and no longer accepting inflows (lending pool deposit, borrow,
/// strategy deposit should be disabled).
bool private _isProtocolDeprecated;
/// @dev Parameters for initializing the Protocol Governor
struct InitParams {
address lendAsset; // Address of the asset
address feeCollector;
address pyth;
}
constructor(InitParams memory params)
Ownable(msg.sender)
nonZeroAddress(params.feeCollector)
nonZeroAddressAndContract(params.lendAsset)
nonZeroAddressAndContract(params.pyth)
{
_setImmutableAddress(GovernorLib.LEND_ASSET, params.lendAsset);
_setImmutableAddress(GovernorLib.PYTH, params.pyth);
_setAddress(GovernorLib.FEE_COLLECTOR, params.feeCollector);
_fees[GovernorLib.LENDING_FEE] = ud(0.1e18);
_fees[GovernorLib.PROTOCOL_LIQUIDATION_SHARE] = ud(0.05e18);
_fees[GovernorLib.LIQUIDATOR_SHARE] = ZERO;
_fees[GovernorLib.FLASH_LOAN_FEE] = ud(0);
}
/**
* @dev Only allows addresses that are the protocol admin to call the function.
*/
modifier onlyProtocolOwner() {
if (owner() != _msgSender()) {
revert Errors.UnauthorizedRole(_msgSender(), "PROTOCOL_ADMIN");
}
_;
}
modifier onlyManager() {
if (!_managers[_msgSender()]) {
revert Errors.UnauthorizedRole(_msgSender(), "ACCOUNT_MANAGER");
}
_;
}
function getOwner() external view returns (address) {
return Ownable.owner();
}
function setProtocolDeprecatedStatus(bool status) external onlyProtocolOwner {
_isProtocolDeprecated = status;
}
function isProtocolDeprecated() external view returns (bool) {
return _isProtocolDeprecated;
}
////////////////////
// ADDRESS PROVIDER
//////////////////////
/// @dev Sets an address by id
function setAddress(bytes32 id, address addr) public onlyProtocolOwner {
_setAddress(id, addr);
}
function _setAddress(bytes32 id, address addr) internal nonZeroAddress(addr) {
_addresses[id] = addr;
emit AddressSet(id, addr);
}
// @dev Initialize an address by id, this cannot be changed after being set.
function setImmutableAddress(bytes32 id, address addr) public onlyProtocolOwner {
_setImmutableAddress(id, addr);
}
function _setImmutableAddress(bytes32 id, address addr) internal nonZeroAddress(addr) {
if (_immutableAddresses[id] != address(0)) {
revert Errors.InvalidParams();
}
_immutableAddresses[id] = addr;
emit ImmutableAddressSet(id, addr);
}
/// @dev Returns an address by id
function getAddress(bytes32 id) external view returns (address) {
return _addresses[id];
}
/// @dev Returns an immutable address by id
function getImmutableAddress(bytes32 id) external view returns (address) {
return _immutableAddresses[id];
}
///////////////////////
// FEE CONFIGURATION
///////////////////////
/// @notice newFee cannot be 100% (it must be < 1e18)
function setFee(bytes32 id, UD60x18 newFee) external onlyProtocolOwner {
if (newFee >= UNIT) {
revert Errors.InvalidParams();
}
_fees[id] = newFee;
emit FeeUpdated(id, newFee);
}
function getFee(bytes32 id) external view returns (UD60x18) {
return _fees[id];
}
/////////////////////
// Protocol wide ACL
/////////////////////
function grantRole(bytes32 role, address account) external onlyProtocolOwner {
_roles[account][role] = true;
emit RoleSet(role, account, true);
}
function revokeRole(bytes32 role, address account) external onlyProtocolOwner {
_roles[account][role] = false;
emit RoleSet(role, account, false);
}
function hasRole(bytes32 role, address account) external view returns (bool) {
return _roles[account][role];
}
function updateAccountManagerStatus(address manager, bool status) external onlyProtocolOwner {
_managers[manager] = status;
emit ManagerStatusUpdated(manager, status);
}
function isAccountManager(address manager) external view returns (bool) {
return _managers[manager];
}
}// SPDX-License-Identifier: GPL-3.0
pragma solidity 0.8.24;
import "./ProtocolGovernor.sol";
import { Context } from "@openzeppelin/contracts/utils/Context.sol";
import "@pythnetwork/pyth-sdk-solidity/IPyth.sol";
import { Errors } from "../libraries/Errors.sol";
import "../libraries/traits/AddressCheckerTrait.sol";
import { UD60x18, ud } from "@prb/math/src/UD60x18.sol";
import "../interfaces/IGasTank.sol";
import "../interfaces/IAssetPriceProvider.sol";
import "../interfaces/IProtocolGovernor.sol";
import "../interfaces/IStrategySlippageModel.sol";
import "../libraries/GovernorLib.sol";
import "../libraries/Roles.sol";
/**
* @title ProtocolModule
* @dev Contract for shared protocol functionality
*/
abstract contract ProtocolModule is Context, AddressCheckerTrait {
using Roles for IProtocolGovernor;
IProtocolGovernor internal immutable _protocolGovernor;
/**
* @dev Constructor that initializes the role store for this contract.
* @param protocolGovernor_ The contract instance to use as the role store.
*/
constructor(address protocolGovernor_) {
_protocolGovernor = IProtocolGovernor(protocolGovernor_);
}
/////////////////
/// PERMISSIONS
/////////////////
modifier whenProtocolNotDeprecated() {
require(!_protocolGovernor.isProtocolDeprecated(), "PROTOCOL_DEPRECATED");
_;
}
/**
* @dev Only allows the contract's own address to call the function.
*/
modifier onlySelf() {
if (msg.sender != address(this)) {
revert Errors.UnauthorizedRole(msg.sender, "SELF");
}
_;
}
modifier onlyAccountManager() {
if (!_protocolGovernor.isAccountManager(_msgSender())) {
revert Errors.UnauthorizedRole(_msgSender(), "ACCOUNT_MANAGER");
}
_;
}
modifier onlyGasTankDepositor() {
_protocolGovernor._validateRole(msg.sender, Roles.GAS_TANK_DEPOSITOR, "GAS_TANK_DEPOSITOR");
_;
}
/**
* @dev Only allows addresses that are the protocol admin to call the function.
*/
modifier onlyOwner() {
if (!_isOwner(_msgSender())) {
revert Errors.UnauthorizedRole(_msgSender(), "PROTOCOL_ADMIN");
}
_;
}
function _isOwner(address account) internal view returns (bool) {
if (_protocolGovernor.getOwner() != account) {
return false;
}
return true;
}
/////////////////////
// ADDRESS PROVIDER
/////////////////////
function getProtocolGovernor() external view virtual returns (address) {
return address(_protocolGovernor);
}
/// @notice Returns fee collector
function _getFeeCollector() internal view returns (address) {
return _protocolGovernor.getAddress(GovernorLib.FEE_COLLECTOR);
}
/// @notice Returns asset price provider address.
/// @dev This price provider MUST return the asset prices denominated in lend asset.
/// @dev If lend asset is USDC, asset prices must be in USDC.
function _getPriceProvider() internal view returns (IAssetPriceProvider) {
return IAssetPriceProvider(_protocolGovernor.getAddress(GovernorLib.PRICE_PROVIDER));
}
/// @notice Gas Tank
function _getGasTank() internal view returns (IGasTank) {
return IGasTank(_protocolGovernor.getAddress(GovernorLib.GAS_TANK));
}
function _getPyth() internal view returns (IPyth) {
return IPyth(_protocolGovernor.getImmutableAddress(GovernorLib.PYTH));
}
function _getLendAsset() internal view returns (address) {
return _protocolGovernor.getImmutableAddress(GovernorLib.LEND_ASSET);
}
function _getLendingPool() internal view returns (address) {
return _protocolGovernor.getImmutableAddress(GovernorLib.LENDING_POOL);
}
// FEE CONFIGURATION
//////////////////////
function _lendingFee() internal view returns (UD60x18) {
return _protocolGovernor.getFee(GovernorLib.LENDING_FEE);
}
function _flashLoanFee() internal view returns (UD60x18) {
return _protocolGovernor.getFee(GovernorLib.FLASH_LOAN_FEE);
}
function _protocolLiquidationShare() internal view returns (UD60x18) {
return _protocolGovernor.getFee(GovernorLib.PROTOCOL_LIQUIDATION_SHARE);
}
function _liquidatorShare() internal view returns (UD60x18) {
return _protocolGovernor.getFee(GovernorLib.LIQUIDATOR_SHARE);
}
}// SPDX-License-Identifier: MIT
pragma solidity >=0.4.22 <0.9.0;
/// @dev The original console.sol uses `int` and `uint` for computing function selectors, but it should
/// use `int256` and `uint256`. This modified version fixes that. This version is recommended
/// over `console.sol` if you don't need compatibility with Hardhat as the logs will show up in
/// forge stack traces. If you do need compatibility with Hardhat, you must use `console.sol`.
/// Reference: https://github.com/NomicFoundation/hardhat/issues/2178
library console2 {
address constant CONSOLE_ADDRESS = address(0x000000000000000000636F6e736F6c652e6c6f67);
function _castLogPayloadViewToPure(
function(bytes memory) internal view fnIn
) internal pure returns (function(bytes memory) internal pure fnOut) {
assembly {
fnOut := fnIn
}
}
function _sendLogPayload(bytes memory payload) internal pure {
_castLogPayloadViewToPure(_sendLogPayloadView)(payload);
}
function _sendLogPayloadView(bytes memory payload) private view {
uint256 payloadLength = payload.length;
address consoleAddress = CONSOLE_ADDRESS;
/// @solidity memory-safe-assembly
assembly {
let payloadStart := add(payload, 32)
let r := staticcall(gas(), consoleAddress, payloadStart, payloadLength, 0, 0)
}
}
function log() internal pure {
_sendLogPayload(abi.encodeWithSignature("log()"));
}
function logInt(int256 p0) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(int256)", p0));
}
function logUint(uint256 p0) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256)", p0));
}
function logString(string memory p0) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string)", p0));
}
function logBool(bool p0) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool)", p0));
}
function logAddress(address p0) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address)", p0));
}
function logBytes(bytes memory p0) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bytes)", p0));
}
function logBytes1(bytes1 p0) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bytes1)", p0));
}
function logBytes2(bytes2 p0) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bytes2)", p0));
}
function logBytes3(bytes3 p0) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bytes3)", p0));
}
function logBytes4(bytes4 p0) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bytes4)", p0));
}
function logBytes5(bytes5 p0) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bytes5)", p0));
}
function logBytes6(bytes6 p0) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bytes6)", p0));
}
function logBytes7(bytes7 p0) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bytes7)", p0));
}
function logBytes8(bytes8 p0) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bytes8)", p0));
}
function logBytes9(bytes9 p0) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bytes9)", p0));
}
function logBytes10(bytes10 p0) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bytes10)", p0));
}
function logBytes11(bytes11 p0) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bytes11)", p0));
}
function logBytes12(bytes12 p0) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bytes12)", p0));
}
function logBytes13(bytes13 p0) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bytes13)", p0));
}
function logBytes14(bytes14 p0) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bytes14)", p0));
}
function logBytes15(bytes15 p0) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bytes15)", p0));
}
function logBytes16(bytes16 p0) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bytes16)", p0));
}
function logBytes17(bytes17 p0) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bytes17)", p0));
}
function logBytes18(bytes18 p0) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bytes18)", p0));
}
function logBytes19(bytes19 p0) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bytes19)", p0));
}
function logBytes20(bytes20 p0) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bytes20)", p0));
}
function logBytes21(bytes21 p0) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bytes21)", p0));
}
function logBytes22(bytes22 p0) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bytes22)", p0));
}
function logBytes23(bytes23 p0) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bytes23)", p0));
}
function logBytes24(bytes24 p0) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bytes24)", p0));
}
function logBytes25(bytes25 p0) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bytes25)", p0));
}
function logBytes26(bytes26 p0) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bytes26)", p0));
}
function logBytes27(bytes27 p0) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bytes27)", p0));
}
function logBytes28(bytes28 p0) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bytes28)", p0));
}
function logBytes29(bytes29 p0) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bytes29)", p0));
}
function logBytes30(bytes30 p0) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bytes30)", p0));
}
function logBytes31(bytes31 p0) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bytes31)", p0));
}
function logBytes32(bytes32 p0) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bytes32)", p0));
}
function log(uint256 p0) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256)", p0));
}
function log(int256 p0) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(int256)", p0));
}
function log(string memory p0) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string)", p0));
}
function log(bool p0) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool)", p0));
}
function log(address p0) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address)", p0));
}
function log(uint256 p0, uint256 p1) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,uint256)", p0, p1));
}
function log(uint256 p0, string memory p1) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,string)", p0, p1));
}
function log(uint256 p0, bool p1) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,bool)", p0, p1));
}
function log(uint256 p0, address p1) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,address)", p0, p1));
}
function log(string memory p0, uint256 p1) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,uint256)", p0, p1));
}
function log(string memory p0, int256 p1) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,int256)", p0, p1));
}
function log(string memory p0, string memory p1) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,string)", p0, p1));
}
function log(string memory p0, bool p1) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,bool)", p0, p1));
}
function log(string memory p0, address p1) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,address)", p0, p1));
}
function log(bool p0, uint256 p1) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,uint256)", p0, p1));
}
function log(bool p0, string memory p1) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,string)", p0, p1));
}
function log(bool p0, bool p1) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,bool)", p0, p1));
}
function log(bool p0, address p1) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,address)", p0, p1));
}
function log(address p0, uint256 p1) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,uint256)", p0, p1));
}
function log(address p0, string memory p1) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,string)", p0, p1));
}
function log(address p0, bool p1) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,bool)", p0, p1));
}
function log(address p0, address p1) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,address)", p0, p1));
}
function log(uint256 p0, uint256 p1, uint256 p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,uint256,uint256)", p0, p1, p2));
}
function log(uint256 p0, uint256 p1, string memory p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,uint256,string)", p0, p1, p2));
}
function log(uint256 p0, uint256 p1, bool p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,uint256,bool)", p0, p1, p2));
}
function log(uint256 p0, uint256 p1, address p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,uint256,address)", p0, p1, p2));
}
function log(uint256 p0, string memory p1, uint256 p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,string,uint256)", p0, p1, p2));
}
function log(uint256 p0, string memory p1, string memory p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,string,string)", p0, p1, p2));
}
function log(uint256 p0, string memory p1, bool p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,string,bool)", p0, p1, p2));
}
function log(uint256 p0, string memory p1, address p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,string,address)", p0, p1, p2));
}
function log(uint256 p0, bool p1, uint256 p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,bool,uint256)", p0, p1, p2));
}
function log(uint256 p0, bool p1, string memory p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,bool,string)", p0, p1, p2));
}
function log(uint256 p0, bool p1, bool p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,bool,bool)", p0, p1, p2));
}
function log(uint256 p0, bool p1, address p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,bool,address)", p0, p1, p2));
}
function log(uint256 p0, address p1, uint256 p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,address,uint256)", p0, p1, p2));
}
function log(uint256 p0, address p1, string memory p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,address,string)", p0, p1, p2));
}
function log(uint256 p0, address p1, bool p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,address,bool)", p0, p1, p2));
}
function log(uint256 p0, address p1, address p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,address,address)", p0, p1, p2));
}
function log(string memory p0, uint256 p1, uint256 p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,uint256,uint256)", p0, p1, p2));
}
function log(string memory p0, uint256 p1, string memory p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,uint256,string)", p0, p1, p2));
}
function log(string memory p0, uint256 p1, bool p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,uint256,bool)", p0, p1, p2));
}
function log(string memory p0, uint256 p1, address p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,uint256,address)", p0, p1, p2));
}
function log(string memory p0, string memory p1, uint256 p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,string,uint256)", p0, p1, p2));
}
function log(string memory p0, string memory p1, string memory p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,string,string)", p0, p1, p2));
}
function log(string memory p0, string memory p1, bool p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,string,bool)", p0, p1, p2));
}
function log(string memory p0, string memory p1, address p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,string,address)", p0, p1, p2));
}
function log(string memory p0, bool p1, uint256 p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,bool,uint256)", p0, p1, p2));
}
function log(string memory p0, bool p1, string memory p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,bool,string)", p0, p1, p2));
}
function log(string memory p0, bool p1, bool p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,bool,bool)", p0, p1, p2));
}
function log(string memory p0, bool p1, address p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,bool,address)", p0, p1, p2));
}
function log(string memory p0, address p1, uint256 p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,address,uint256)", p0, p1, p2));
}
function log(string memory p0, address p1, string memory p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,address,string)", p0, p1, p2));
}
function log(string memory p0, address p1, bool p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,address,bool)", p0, p1, p2));
}
function log(string memory p0, address p1, address p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,address,address)", p0, p1, p2));
}
function log(bool p0, uint256 p1, uint256 p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,uint256,uint256)", p0, p1, p2));
}
function log(bool p0, uint256 p1, string memory p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,uint256,string)", p0, p1, p2));
}
function log(bool p0, uint256 p1, bool p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,uint256,bool)", p0, p1, p2));
}
function log(bool p0, uint256 p1, address p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,uint256,address)", p0, p1, p2));
}
function log(bool p0, string memory p1, uint256 p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,string,uint256)", p0, p1, p2));
}
function log(bool p0, string memory p1, string memory p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,string,string)", p0, p1, p2));
}
function log(bool p0, string memory p1, bool p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,string,bool)", p0, p1, p2));
}
function log(bool p0, string memory p1, address p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,string,address)", p0, p1, p2));
}
function log(bool p0, bool p1, uint256 p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,bool,uint256)", p0, p1, p2));
}
function log(bool p0, bool p1, string memory p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,bool,string)", p0, p1, p2));
}
function log(bool p0, bool p1, bool p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,bool,bool)", p0, p1, p2));
}
function log(bool p0, bool p1, address p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,bool,address)", p0, p1, p2));
}
function log(bool p0, address p1, uint256 p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,address,uint256)", p0, p1, p2));
}
function log(bool p0, address p1, string memory p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,address,string)", p0, p1, p2));
}
function log(bool p0, address p1, bool p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,address,bool)", p0, p1, p2));
}
function log(bool p0, address p1, address p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,address,address)", p0, p1, p2));
}
function log(address p0, uint256 p1, uint256 p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,uint256,uint256)", p0, p1, p2));
}
function log(address p0, uint256 p1, string memory p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,uint256,string)", p0, p1, p2));
}
function log(address p0, uint256 p1, bool p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,uint256,bool)", p0, p1, p2));
}
function log(address p0, uint256 p1, address p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,uint256,address)", p0, p1, p2));
}
function log(address p0, string memory p1, uint256 p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,string,uint256)", p0, p1, p2));
}
function log(address p0, string memory p1, string memory p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,string,string)", p0, p1, p2));
}
function log(address p0, string memory p1, bool p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,string,bool)", p0, p1, p2));
}
function log(address p0, string memory p1, address p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,string,address)", p0, p1, p2));
}
function log(address p0, bool p1, uint256 p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,bool,uint256)", p0, p1, p2));
}
function log(address p0, bool p1, string memory p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,bool,string)", p0, p1, p2));
}
function log(address p0, bool p1, bool p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,bool,bool)", p0, p1, p2));
}
function log(address p0, bool p1, address p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,bool,address)", p0, p1, p2));
}
function log(address p0, address p1, uint256 p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,address,uint256)", p0, p1, p2));
}
function log(address p0, address p1, string memory p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,address,string)", p0, p1, p2));
}
function log(address p0, address p1, bool p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,address,bool)", p0, p1, p2));
}
function log(address p0, address p1, address p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,address,address)", p0, p1, p2));
}
function log(uint256 p0, uint256 p1, uint256 p2, uint256 p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,uint256,uint256,uint256)", p0, p1, p2, p3));
}
function log(uint256 p0, uint256 p1, uint256 p2, string memory p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,uint256,uint256,string)", p0, p1, p2, p3));
}
function log(uint256 p0, uint256 p1, uint256 p2, bool p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,uint256,uint256,bool)", p0, p1, p2, p3));
}
function log(uint256 p0, uint256 p1, uint256 p2, address p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,uint256,uint256,address)", p0, p1, p2, p3));
}
function log(uint256 p0, uint256 p1, string memory p2, uint256 p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,uint256,string,uint256)", p0, p1, p2, p3));
}
function log(uint256 p0, uint256 p1, string memory p2, string memory p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,uint256,string,string)", p0, p1, p2, p3));
}
function log(uint256 p0, uint256 p1, string memory p2, bool p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,uint256,string,bool)", p0, p1, p2, p3));
}
function log(uint256 p0, uint256 p1, string memory p2, address p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,uint256,string,address)", p0, p1, p2, p3));
}
function log(uint256 p0, uint256 p1, bool p2, uint256 p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,uint256,bool,uint256)", p0, p1, p2, p3));
}
function log(uint256 p0, uint256 p1, bool p2, string memory p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,uint256,bool,string)", p0, p1, p2, p3));
}
function log(uint256 p0, uint256 p1, bool p2, bool p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,uint256,bool,bool)", p0, p1, p2, p3));
}
function log(uint256 p0, uint256 p1, bool p2, address p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,uint256,bool,address)", p0, p1, p2, p3));
}
function log(uint256 p0, uint256 p1, address p2, uint256 p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,uint256,address,uint256)", p0, p1, p2, p3));
}
function log(uint256 p0, uint256 p1, address p2, string memory p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,uint256,address,string)", p0, p1, p2, p3));
}
function log(uint256 p0, uint256 p1, address p2, bool p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,uint256,address,bool)", p0, p1, p2, p3));
}
function log(uint256 p0, uint256 p1, address p2, address p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,uint256,address,address)", p0, p1, p2, p3));
}
function log(uint256 p0, string memory p1, uint256 p2, uint256 p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,string,uint256,uint256)", p0, p1, p2, p3));
}
function log(uint256 p0, string memory p1, uint256 p2, string memory p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,string,uint256,string)", p0, p1, p2, p3));
}
function log(uint256 p0, string memory p1, uint256 p2, bool p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,string,uint256,bool)", p0, p1, p2, p3));
}
function log(uint256 p0, string memory p1, uint256 p2, address p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,string,uint256,address)", p0, p1, p2, p3));
}
function log(uint256 p0, string memory p1, string memory p2, uint256 p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,string,string,uint256)", p0, p1, p2, p3));
}
function log(uint256 p0, string memory p1, string memory p2, string memory p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,string,string,string)", p0, p1, p2, p3));
}
function log(uint256 p0, string memory p1, string memory p2, bool p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,string,string,bool)", p0, p1, p2, p3));
}
function log(uint256 p0, string memory p1, string memory p2, address p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,string,string,address)", p0, p1, p2, p3));
}
function log(uint256 p0, string memory p1, bool p2, uint256 p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,string,bool,uint256)", p0, p1, p2, p3));
}
function log(uint256 p0, string memory p1, bool p2, string memory p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,string,bool,string)", p0, p1, p2, p3));
}
function log(uint256 p0, string memory p1, bool p2, bool p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,string,bool,bool)", p0, p1, p2, p3));
}
function log(uint256 p0, string memory p1, bool p2, address p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,string,bool,address)", p0, p1, p2, p3));
}
function log(uint256 p0, string memory p1, address p2, uint256 p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,string,address,uint256)", p0, p1, p2, p3));
}
function log(uint256 p0, string memory p1, address p2, string memory p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,string,address,string)", p0, p1, p2, p3));
}
function log(uint256 p0, string memory p1, address p2, bool p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,string,address,bool)", p0, p1, p2, p3));
}
function log(uint256 p0, string memory p1, address p2, address p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,string,address,address)", p0, p1, p2, p3));
}
function log(uint256 p0, bool p1, uint256 p2, uint256 p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,bool,uint256,uint256)", p0, p1, p2, p3));
}
function log(uint256 p0, bool p1, uint256 p2, string memory p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,bool,uint256,string)", p0, p1, p2, p3));
}
function log(uint256 p0, bool p1, uint256 p2, bool p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,bool,uint256,bool)", p0, p1, p2, p3));
}
function log(uint256 p0, bool p1, uint256 p2, address p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,bool,uint256,address)", p0, p1, p2, p3));
}
function log(uint256 p0, bool p1, string memory p2, uint256 p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,bool,string,uint256)", p0, p1, p2, p3));
}
function log(uint256 p0, bool p1, string memory p2, string memory p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,bool,string,string)", p0, p1, p2, p3));
}
function log(uint256 p0, bool p1, string memory p2, bool p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,bool,string,bool)", p0, p1, p2, p3));
}
function log(uint256 p0, bool p1, string memory p2, address p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,bool,string,address)", p0, p1, p2, p3));
}
function log(uint256 p0, bool p1, bool p2, uint256 p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,bool,bool,uint256)", p0, p1, p2, p3));
}
function log(uint256 p0, bool p1, bool p2, string memory p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,bool,bool,string)", p0, p1, p2, p3));
}
function log(uint256 p0, bool p1, bool p2, bool p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,bool,bool,bool)", p0, p1, p2, p3));
}
function log(uint256 p0, bool p1, bool p2, address p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,bool,bool,address)", p0, p1, p2, p3));
}
function log(uint256 p0, bool p1, address p2, uint256 p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,bool,address,uint256)", p0, p1, p2, p3));
}
function log(uint256 p0, bool p1, address p2, string memory p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,bool,address,string)", p0, p1, p2, p3));
}
function log(uint256 p0, bool p1, address p2, bool p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,bool,address,bool)", p0, p1, p2, p3));
}
function log(uint256 p0, bool p1, address p2, address p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,bool,address,address)", p0, p1, p2, p3));
}
function log(uint256 p0, address p1, uint256 p2, uint256 p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,address,uint256,uint256)", p0, p1, p2, p3));
}
function log(uint256 p0, address p1, uint256 p2, string memory p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,address,uint256,string)", p0, p1, p2, p3));
}
function log(uint256 p0, address p1, uint256 p2, bool p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,address,uint256,bool)", p0, p1, p2, p3));
}
function log(uint256 p0, address p1, uint256 p2, address p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,address,uint256,address)", p0, p1, p2, p3));
}
function log(uint256 p0, address p1, string memory p2, uint256 p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,address,string,uint256)", p0, p1, p2, p3));
}
function log(uint256 p0, address p1, string memory p2, string memory p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,address,string,string)", p0, p1, p2, p3));
}
function log(uint256 p0, address p1, string memory p2, bool p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,address,string,bool)", p0, p1, p2, p3));
}
function log(uint256 p0, address p1, string memory p2, address p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,address,string,address)", p0, p1, p2, p3));
}
function log(uint256 p0, address p1, bool p2, uint256 p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,address,bool,uint256)", p0, p1, p2, p3));
}
function log(uint256 p0, address p1, bool p2, string memory p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,address,bool,string)", p0, p1, p2, p3));
}
function log(uint256 p0, address p1, bool p2, bool p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,address,bool,bool)", p0, p1, p2, p3));
}
function log(uint256 p0, address p1, bool p2, address p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,address,bool,address)", p0, p1, p2, p3));
}
function log(uint256 p0, address p1, address p2, uint256 p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,address,address,uint256)", p0, p1, p2, p3));
}
function log(uint256 p0, address p1, address p2, string memory p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,address,address,string)", p0, p1, p2, p3));
}
function log(uint256 p0, address p1, address p2, bool p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,address,address,bool)", p0, p1, p2, p3));
}
function log(uint256 p0, address p1, address p2, address p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,address,address,address)", p0, p1, p2, p3));
}
function log(string memory p0, uint256 p1, uint256 p2, uint256 p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,uint256,uint256,uint256)", p0, p1, p2, p3));
}
function log(string memory p0, uint256 p1, uint256 p2, string memory p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,uint256,uint256,string)", p0, p1, p2, p3));
}
function log(string memory p0, uint256 p1, uint256 p2, bool p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,uint256,uint256,bool)", p0, p1, p2, p3));
}
function log(string memory p0, uint256 p1, uint256 p2, address p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,uint256,uint256,address)", p0, p1, p2, p3));
}
function log(string memory p0, uint256 p1, string memory p2, uint256 p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,uint256,string,uint256)", p0, p1, p2, p3));
}
function log(string memory p0, uint256 p1, string memory p2, string memory p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,uint256,string,string)", p0, p1, p2, p3));
}
function log(string memory p0, uint256 p1, string memory p2, bool p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,uint256,string,bool)", p0, p1, p2, p3));
}
function log(string memory p0, uint256 p1, string memory p2, address p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,uint256,string,address)", p0, p1, p2, p3));
}
function log(string memory p0, uint256 p1, bool p2, uint256 p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,uint256,bool,uint256)", p0, p1, p2, p3));
}
function log(string memory p0, uint256 p1, bool p2, string memory p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,uint256,bool,string)", p0, p1, p2, p3));
}
function log(string memory p0, uint256 p1, bool p2, bool p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,uint256,bool,bool)", p0, p1, p2, p3));
}
function log(string memory p0, uint256 p1, bool p2, address p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,uint256,bool,address)", p0, p1, p2, p3));
}
function log(string memory p0, uint256 p1, address p2, uint256 p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,uint256,address,uint256)", p0, p1, p2, p3));
}
function log(string memory p0, uint256 p1, address p2, string memory p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,uint256,address,string)", p0, p1, p2, p3));
}
function log(string memory p0, uint256 p1, address p2, bool p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,uint256,address,bool)", p0, p1, p2, p3));
}
function log(string memory p0, uint256 p1, address p2, address p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,uint256,address,address)", p0, p1, p2, p3));
}
function log(string memory p0, string memory p1, uint256 p2, uint256 p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,string,uint256,uint256)", p0, p1, p2, p3));
}
function log(string memory p0, string memory p1, uint256 p2, string memory p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,string,uint256,string)", p0, p1, p2, p3));
}
function log(string memory p0, string memory p1, uint256 p2, bool p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,string,uint256,bool)", p0, p1, p2, p3));
}
function log(string memory p0, string memory p1, uint256 p2, address p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,string,uint256,address)", p0, p1, p2, p3));
}
function log(string memory p0, string memory p1, string memory p2, uint256 p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,string,string,uint256)", p0, p1, p2, p3));
}
function log(string memory p0, string memory p1, string memory p2, string memory p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,string,string,string)", p0, p1, p2, p3));
}
function log(string memory p0, string memory p1, string memory p2, bool p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,string,string,bool)", p0, p1, p2, p3));
}
function log(string memory p0, string memory p1, string memory p2, address p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,string,string,address)", p0, p1, p2, p3));
}
function log(string memory p0, string memory p1, bool p2, uint256 p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,string,bool,uint256)", p0, p1, p2, p3));
}
function log(string memory p0, string memory p1, bool p2, string memory p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,string,bool,string)", p0, p1, p2, p3));
}
function log(string memory p0, string memory p1, bool p2, bool p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,string,bool,bool)", p0, p1, p2, p3));
}
function log(string memory p0, string memory p1, bool p2, address p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,string,bool,address)", p0, p1, p2, p3));
}
function log(string memory p0, string memory p1, address p2, uint256 p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,string,address,uint256)", p0, p1, p2, p3));
}
function log(string memory p0, string memory p1, address p2, string memory p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,string,address,string)", p0, p1, p2, p3));
}
function log(string memory p0, string memory p1, address p2, bool p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,string,address,bool)", p0, p1, p2, p3));
}
function log(string memory p0, string memory p1, address p2, address p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,string,address,address)", p0, p1, p2, p3));
}
function log(string memory p0, bool p1, uint256 p2, uint256 p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,bool,uint256,uint256)", p0, p1, p2, p3));
}
function log(string memory p0, bool p1, uint256 p2, string memory p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,bool,uint256,string)", p0, p1, p2, p3));
}
function log(string memory p0, bool p1, uint256 p2, bool p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,bool,uint256,bool)", p0, p1, p2, p3));
}
function log(string memory p0, bool p1, uint256 p2, address p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,bool,uint256,address)", p0, p1, p2, p3));
}
function log(string memory p0, bool p1, string memory p2, uint256 p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,bool,string,uint256)", p0, p1, p2, p3));
}
function log(string memory p0, bool p1, string memory p2, string memory p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,bool,string,string)", p0, p1, p2, p3));
}
function log(string memory p0, bool p1, string memory p2, bool p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,bool,string,bool)", p0, p1, p2, p3));
}
function log(string memory p0, bool p1, string memory p2, address p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,bool,string,address)", p0, p1, p2, p3));
}
function log(string memory p0, bool p1, bool p2, uint256 p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,bool,bool,uint256)", p0, p1, p2, p3));
}
function log(string memory p0, bool p1, bool p2, string memory p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,bool,bool,string)", p0, p1, p2, p3));
}
function log(string memory p0, bool p1, bool p2, bool p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,bool,bool,bool)", p0, p1, p2, p3));
}
function log(string memory p0, bool p1, bool p2, address p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,bool,bool,address)", p0, p1, p2, p3));
}
function log(string memory p0, bool p1, address p2, uint256 p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,bool,address,uint256)", p0, p1, p2, p3));
}
function log(string memory p0, bool p1, address p2, string memory p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,bool,address,string)", p0, p1, p2, p3));
}
function log(string memory p0, bool p1, address p2, bool p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,bool,address,bool)", p0, p1, p2, p3));
}
function log(string memory p0, bool p1, address p2, address p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,bool,address,address)", p0, p1, p2, p3));
}
function log(string memory p0, address p1, uint256 p2, uint256 p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,address,uint256,uint256)", p0, p1, p2, p3));
}
function log(string memory p0, address p1, uint256 p2, string memory p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,address,uint256,string)", p0, p1, p2, p3));
}
function log(string memory p0, address p1, uint256 p2, bool p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,address,uint256,bool)", p0, p1, p2, p3));
}
function log(string memory p0, address p1, uint256 p2, address p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,address,uint256,address)", p0, p1, p2, p3));
}
function log(string memory p0, address p1, string memory p2, uint256 p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,address,string,uint256)", p0, p1, p2, p3));
}
function log(string memory p0, address p1, string memory p2, string memory p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,address,string,string)", p0, p1, p2, p3));
}
function log(string memory p0, address p1, string memory p2, bool p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,address,string,bool)", p0, p1, p2, p3));
}
function log(string memory p0, address p1, string memory p2, address p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,address,string,address)", p0, p1, p2, p3));
}
function log(string memory p0, address p1, bool p2, uint256 p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,address,bool,uint256)", p0, p1, p2, p3));
}
function log(string memory p0, address p1, bool p2, string memory p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,address,bool,string)", p0, p1, p2, p3));
}
function log(string memory p0, address p1, bool p2, bool p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,address,bool,bool)", p0, p1, p2, p3));
}
function log(string memory p0, address p1, bool p2, address p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,address,bool,address)", p0, p1, p2, p3));
}
function log(string memory p0, address p1, address p2, uint256 p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,address,address,uint256)", p0, p1, p2, p3));
}
function log(string memory p0, address p1, address p2, string memory p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,address,address,string)", p0, p1, p2, p3));
}
function log(string memory p0, address p1, address p2, bool p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,address,address,bool)", p0, p1, p2, p3));
}
function log(string memory p0, address p1, address p2, address p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,address,address,address)", p0, p1, p2, p3));
}
function log(bool p0, uint256 p1, uint256 p2, uint256 p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,uint256,uint256,uint256)", p0, p1, p2, p3));
}
function log(bool p0, uint256 p1, uint256 p2, string memory p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,uint256,uint256,string)", p0, p1, p2, p3));
}
function log(bool p0, uint256 p1, uint256 p2, bool p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,uint256,uint256,bool)", p0, p1, p2, p3));
}
function log(bool p0, uint256 p1, uint256 p2, address p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,uint256,uint256,address)", p0, p1, p2, p3));
}
function log(bool p0, uint256 p1, string memory p2, uint256 p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,uint256,string,uint256)", p0, p1, p2, p3));
}
function log(bool p0, uint256 p1, string memory p2, string memory p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,uint256,string,string)", p0, p1, p2, p3));
}
function log(bool p0, uint256 p1, string memory p2, bool p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,uint256,string,bool)", p0, p1, p2, p3));
}
function log(bool p0, uint256 p1, string memory p2, address p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,uint256,string,address)", p0, p1, p2, p3));
}
function log(bool p0, uint256 p1, bool p2, uint256 p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,uint256,bool,uint256)", p0, p1, p2, p3));
}
function log(bool p0, uint256 p1, bool p2, string memory p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,uint256,bool,string)", p0, p1, p2, p3));
}
function log(bool p0, uint256 p1, bool p2, bool p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,uint256,bool,bool)", p0, p1, p2, p3));
}
function log(bool p0, uint256 p1, bool p2, address p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,uint256,bool,address)", p0, p1, p2, p3));
}
function log(bool p0, uint256 p1, address p2, uint256 p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,uint256,address,uint256)", p0, p1, p2, p3));
}
function log(bool p0, uint256 p1, address p2, string memory p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,uint256,address,string)", p0, p1, p2, p3));
}
function log(bool p0, uint256 p1, address p2, bool p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,uint256,address,bool)", p0, p1, p2, p3));
}
function log(bool p0, uint256 p1, address p2, address p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,uint256,address,address)", p0, p1, p2, p3));
}
function log(bool p0, string memory p1, uint256 p2, uint256 p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,string,uint256,uint256)", p0, p1, p2, p3));
}
function log(bool p0, string memory p1, uint256 p2, string memory p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,string,uint256,string)", p0, p1, p2, p3));
}
function log(bool p0, string memory p1, uint256 p2, bool p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,string,uint256,bool)", p0, p1, p2, p3));
}
function log(bool p0, string memory p1, uint256 p2, address p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,string,uint256,address)", p0, p1, p2, p3));
}
function log(bool p0, string memory p1, string memory p2, uint256 p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,string,string,uint256)", p0, p1, p2, p3));
}
function log(bool p0, string memory p1, string memory p2, string memory p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,string,string,string)", p0, p1, p2, p3));
}
function log(bool p0, string memory p1, string memory p2, bool p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,string,string,bool)", p0, p1, p2, p3));
}
function log(bool p0, string memory p1, string memory p2, address p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,string,string,address)", p0, p1, p2, p3));
}
function log(bool p0, string memory p1, bool p2, uint256 p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,string,bool,uint256)", p0, p1, p2, p3));
}
function log(bool p0, string memory p1, bool p2, string memory p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,string,bool,string)", p0, p1, p2, p3));
}
function log(bool p0, string memory p1, bool p2, bool p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,string,bool,bool)", p0, p1, p2, p3));
}
function log(bool p0, string memory p1, bool p2, address p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,string,bool,address)", p0, p1, p2, p3));
}
function log(bool p0, string memory p1, address p2, uint256 p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,string,address,uint256)", p0, p1, p2, p3));
}
function log(bool p0, string memory p1, address p2, string memory p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,string,address,string)", p0, p1, p2, p3));
}
function log(bool p0, string memory p1, address p2, bool p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,string,address,bool)", p0, p1, p2, p3));
}
function log(bool p0, string memory p1, address p2, address p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,string,address,address)", p0, p1, p2, p3));
}
function log(bool p0, bool p1, uint256 p2, uint256 p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,bool,uint256,uint256)", p0, p1, p2, p3));
}
function log(bool p0, bool p1, uint256 p2, string memory p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,bool,uint256,string)", p0, p1, p2, p3));
}
function log(bool p0, bool p1, uint256 p2, bool p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,bool,uint256,bool)", p0, p1, p2, p3));
}
function log(bool p0, bool p1, uint256 p2, address p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,bool,uint256,address)", p0, p1, p2, p3));
}
function log(bool p0, bool p1, string memory p2, uint256 p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,bool,string,uint256)", p0, p1, p2, p3));
}
function log(bool p0, bool p1, string memory p2, string memory p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,bool,string,string)", p0, p1, p2, p3));
}
function log(bool p0, bool p1, string memory p2, bool p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,bool,string,bool)", p0, p1, p2, p3));
}
function log(bool p0, bool p1, string memory p2, address p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,bool,string,address)", p0, p1, p2, p3));
}
function log(bool p0, bool p1, bool p2, uint256 p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,bool,bool,uint256)", p0, p1, p2, p3));
}
function log(bool p0, bool p1, bool p2, string memory p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,bool,bool,string)", p0, p1, p2, p3));
}
function log(bool p0, bool p1, bool p2, bool p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,bool,bool,bool)", p0, p1, p2, p3));
}
function log(bool p0, bool p1, bool p2, address p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,bool,bool,address)", p0, p1, p2, p3));
}
function log(bool p0, bool p1, address p2, uint256 p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,bool,address,uint256)", p0, p1, p2, p3));
}
function log(bool p0, bool p1, address p2, string memory p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,bool,address,string)", p0, p1, p2, p3));
}
function log(bool p0, bool p1, address p2, bool p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,bool,address,bool)", p0, p1, p2, p3));
}
function log(bool p0, bool p1, address p2, address p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,bool,address,address)", p0, p1, p2, p3));
}
function log(bool p0, address p1, uint256 p2, uint256 p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,address,uint256,uint256)", p0, p1, p2, p3));
}
function log(bool p0, address p1, uint256 p2, string memory p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,address,uint256,string)", p0, p1, p2, p3));
}
function log(bool p0, address p1, uint256 p2, bool p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,address,uint256,bool)", p0, p1, p2, p3));
}
function log(bool p0, address p1, uint256 p2, address p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,address,uint256,address)", p0, p1, p2, p3));
}
function log(bool p0, address p1, string memory p2, uint256 p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,address,string,uint256)", p0, p1, p2, p3));
}
function log(bool p0, address p1, string memory p2, string memory p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,address,string,string)", p0, p1, p2, p3));
}
function log(bool p0, address p1, string memory p2, bool p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,address,string,bool)", p0, p1, p2, p3));
}
function log(bool p0, address p1, string memory p2, address p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,address,string,address)", p0, p1, p2, p3));
}
function log(bool p0, address p1, bool p2, uint256 p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,address,bool,uint256)", p0, p1, p2, p3));
}
function log(bool p0, address p1, bool p2, string memory p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,address,bool,string)", p0, p1, p2, p3));
}
function log(bool p0, address p1, bool p2, bool p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,address,bool,bool)", p0, p1, p2, p3));
}
function log(bool p0, address p1, bool p2, address p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,address,bool,address)", p0, p1, p2, p3));
}
function log(bool p0, address p1, address p2, uint256 p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,address,address,uint256)", p0, p1, p2, p3));
}
function log(bool p0, address p1, address p2, string memory p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,address,address,string)", p0, p1, p2, p3));
}
function log(bool p0, address p1, address p2, bool p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,address,address,bool)", p0, p1, p2, p3));
}
function log(bool p0, address p1, address p2, address p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,address,address,address)", p0, p1, p2, p3));
}
function log(address p0, uint256 p1, uint256 p2, uint256 p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,uint256,uint256,uint256)", p0, p1, p2, p3));
}
function log(address p0, uint256 p1, uint256 p2, string memory p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,uint256,uint256,string)", p0, p1, p2, p3));
}
function log(address p0, uint256 p1, uint256 p2, bool p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,uint256,uint256,bool)", p0, p1, p2, p3));
}
function log(address p0, uint256 p1, uint256 p2, address p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,uint256,uint256,address)", p0, p1, p2, p3));
}
function log(address p0, uint256 p1, string memory p2, uint256 p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,uint256,string,uint256)", p0, p1, p2, p3));
}
function log(address p0, uint256 p1, string memory p2, string memory p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,uint256,string,string)", p0, p1, p2, p3));
}
function log(address p0, uint256 p1, string memory p2, bool p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,uint256,string,bool)", p0, p1, p2, p3));
}
function log(address p0, uint256 p1, string memory p2, address p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,uint256,string,address)", p0, p1, p2, p3));
}
function log(address p0, uint256 p1, bool p2, uint256 p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,uint256,bool,uint256)", p0, p1, p2, p3));
}
function log(address p0, uint256 p1, bool p2, string memory p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,uint256,bool,string)", p0, p1, p2, p3));
}
function log(address p0, uint256 p1, bool p2, bool p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,uint256,bool,bool)", p0, p1, p2, p3));
}
function log(address p0, uint256 p1, bool p2, address p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,uint256,bool,address)", p0, p1, p2, p3));
}
function log(address p0, uint256 p1, address p2, uint256 p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,uint256,address,uint256)", p0, p1, p2, p3));
}
function log(address p0, uint256 p1, address p2, string memory p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,uint256,address,string)", p0, p1, p2, p3));
}
function log(address p0, uint256 p1, address p2, bool p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,uint256,address,bool)", p0, p1, p2, p3));
}
function log(address p0, uint256 p1, address p2, address p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,uint256,address,address)", p0, p1, p2, p3));
}
function log(address p0, string memory p1, uint256 p2, uint256 p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,string,uint256,uint256)", p0, p1, p2, p3));
}
function log(address p0, string memory p1, uint256 p2, string memory p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,string,uint256,string)", p0, p1, p2, p3));
}
function log(address p0, string memory p1, uint256 p2, bool p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,string,uint256,bool)", p0, p1, p2, p3));
}
function log(address p0, string memory p1, uint256 p2, address p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,string,uint256,address)", p0, p1, p2, p3));
}
function log(address p0, string memory p1, string memory p2, uint256 p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,string,string,uint256)", p0, p1, p2, p3));
}
function log(address p0, string memory p1, string memory p2, string memory p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,string,string,string)", p0, p1, p2, p3));
}
function log(address p0, string memory p1, string memory p2, bool p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,string,string,bool)", p0, p1, p2, p3));
}
function log(address p0, string memory p1, string memory p2, address p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,string,string,address)", p0, p1, p2, p3));
}
function log(address p0, string memory p1, bool p2, uint256 p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,string,bool,uint256)", p0, p1, p2, p3));
}
function log(address p0, string memory p1, bool p2, string memory p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,string,bool,string)", p0, p1, p2, p3));
}
function log(address p0, string memory p1, bool p2, bool p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,string,bool,bool)", p0, p1, p2, p3));
}
function log(address p0, string memory p1, bool p2, address p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,string,bool,address)", p0, p1, p2, p3));
}
function log(address p0, string memory p1, address p2, uint256 p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,string,address,uint256)", p0, p1, p2, p3));
}
function log(address p0, string memory p1, address p2, string memory p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,string,address,string)", p0, p1, p2, p3));
}
function log(address p0, string memory p1, address p2, bool p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,string,address,bool)", p0, p1, p2, p3));
}
function log(address p0, string memory p1, address p2, address p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,string,address,address)", p0, p1, p2, p3));
}
function log(address p0, bool p1, uint256 p2, uint256 p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,bool,uint256,uint256)", p0, p1, p2, p3));
}
function log(address p0, bool p1, uint256 p2, string memory p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,bool,uint256,string)", p0, p1, p2, p3));
}
function log(address p0, bool p1, uint256 p2, bool p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,bool,uint256,bool)", p0, p1, p2, p3));
}
function log(address p0, bool p1, uint256 p2, address p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,bool,uint256,address)", p0, p1, p2, p3));
}
function log(address p0, bool p1, string memory p2, uint256 p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,bool,string,uint256)", p0, p1, p2, p3));
}
function log(address p0, bool p1, string memory p2, string memory p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,bool,string,string)", p0, p1, p2, p3));
}
function log(address p0, bool p1, string memory p2, bool p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,bool,string,bool)", p0, p1, p2, p3));
}
function log(address p0, bool p1, string memory p2, address p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,bool,string,address)", p0, p1, p2, p3));
}
function log(address p0, bool p1, bool p2, uint256 p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,bool,bool,uint256)", p0, p1, p2, p3));
}
function log(address p0, bool p1, bool p2, string memory p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,bool,bool,string)", p0, p1, p2, p3));
}
function log(address p0, bool p1, bool p2, bool p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,bool,bool,bool)", p0, p1, p2, p3));
}
function log(address p0, bool p1, bool p2, address p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,bool,bool,address)", p0, p1, p2, p3));
}
function log(address p0, bool p1, address p2, uint256 p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,bool,address,uint256)", p0, p1, p2, p3));
}
function log(address p0, bool p1, address p2, string memory p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,bool,address,string)", p0, p1, p2, p3));
}
function log(address p0, bool p1, address p2, bool p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,bool,address,bool)", p0, p1, p2, p3));
}
function log(address p0, bool p1, address p2, address p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,bool,address,address)", p0, p1, p2, p3));
}
function log(address p0, address p1, uint256 p2, uint256 p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,address,uint256,uint256)", p0, p1, p2, p3));
}
function log(address p0, address p1, uint256 p2, string memory p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,address,uint256,string)", p0, p1, p2, p3));
}
function log(address p0, address p1, uint256 p2, bool p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,address,uint256,bool)", p0, p1, p2, p3));
}
function log(address p0, address p1, uint256 p2, address p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,address,uint256,address)", p0, p1, p2, p3));
}
function log(address p0, address p1, string memory p2, uint256 p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,address,string,uint256)", p0, p1, p2, p3));
}
function log(address p0, address p1, string memory p2, string memory p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,address,string,string)", p0, p1, p2, p3));
}
function log(address p0, address p1, string memory p2, bool p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,address,string,bool)", p0, p1, p2, p3));
}
function log(address p0, address p1, string memory p2, address p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,address,string,address)", p0, p1, p2, p3));
}
function log(address p0, address p1, bool p2, uint256 p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,address,bool,uint256)", p0, p1, p2, p3));
}
function log(address p0, address p1, bool p2, string memory p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,address,bool,string)", p0, p1, p2, p3));
}
function log(address p0, address p1, bool p2, bool p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,address,bool,bool)", p0, p1, p2, p3));
}
function log(address p0, address p1, bool p2, address p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,address,bool,address)", p0, p1, p2, p3));
}
function log(address p0, address p1, address p2, uint256 p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,address,address,uint256)", p0, p1, p2, p3));
}
function log(address p0, address p1, address p2, string memory p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,address,address,string)", p0, p1, p2, p3));
}
function log(address p0, address p1, address p2, bool p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,address,address,bool)", p0, p1, p2, p3));
}
function log(address p0, address p1, address p2, address p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,address,address,address)", p0, p1, p2, p3));
}
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.4;
/// @notice Simple ERC20 + EIP-2612 implementation.
/// @author Solady (https://github.com/vectorized/solady/blob/main/src/tokens/ERC20.sol)
/// @author Modified from Solmate (https://github.com/transmissions11/solmate/blob/main/src/tokens/ERC20.sol)
/// @author Modified from OpenZeppelin (https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC20/ERC20.sol)
///
/// @dev Note:
/// - The ERC20 standard allows minting and transferring to and from the zero address,
/// minting and transferring zero tokens, as well as self-approvals.
/// For performance, this implementation WILL NOT revert for such actions.
/// Please add any checks with overrides if desired.
/// - The `permit` function uses the ecrecover precompile (0x1).
///
/// If you are overriding:
/// - NEVER violate the ERC20 invariant:
/// the total sum of all balances must be equal to `totalSupply()`.
/// - Check that the overridden function is actually used in the function you want to
/// change the behavior of. Much of the code has been manually inlined for performance.
abstract contract ERC20 {
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
/* CUSTOM ERRORS */
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
/// @dev The total supply has overflowed.
error TotalSupplyOverflow();
/// @dev The allowance has overflowed.
error AllowanceOverflow();
/// @dev The allowance has underflowed.
error AllowanceUnderflow();
/// @dev Insufficient balance.
error InsufficientBalance();
/// @dev Insufficient allowance.
error InsufficientAllowance();
/// @dev The permit is invalid.
error InvalidPermit();
/// @dev The permit has expired.
error PermitExpired();
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
/* EVENTS */
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
/// @dev Emitted when `amount` tokens is transferred from `from` to `to`.
event Transfer(address indexed from, address indexed to, uint256 amount);
/// @dev Emitted when `amount` tokens is approved by `owner` to be used by `spender`.
event Approval(address indexed owner, address indexed spender, uint256 amount);
/// @dev `keccak256(bytes("Transfer(address,address,uint256)"))`.
uint256 private constant _TRANSFER_EVENT_SIGNATURE =
0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef;
/// @dev `keccak256(bytes("Approval(address,address,uint256)"))`.
uint256 private constant _APPROVAL_EVENT_SIGNATURE =
0x8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925;
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
/* STORAGE */
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
/// @dev The storage slot for the total supply.
uint256 private constant _TOTAL_SUPPLY_SLOT = 0x05345cdf77eb68f44c;
/// @dev The balance slot of `owner` is given by:
/// ```
/// mstore(0x0c, _BALANCE_SLOT_SEED)
/// mstore(0x00, owner)
/// let balanceSlot := keccak256(0x0c, 0x20)
/// ```
uint256 private constant _BALANCE_SLOT_SEED = 0x87a211a2;
/// @dev The allowance slot of (`owner`, `spender`) is given by:
/// ```
/// mstore(0x20, spender)
/// mstore(0x0c, _ALLOWANCE_SLOT_SEED)
/// mstore(0x00, owner)
/// let allowanceSlot := keccak256(0x0c, 0x34)
/// ```
uint256 private constant _ALLOWANCE_SLOT_SEED = 0x7f5e9f20;
/// @dev The nonce slot of `owner` is given by:
/// ```
/// mstore(0x0c, _NONCES_SLOT_SEED)
/// mstore(0x00, owner)
/// let nonceSlot := keccak256(0x0c, 0x20)
/// ```
uint256 private constant _NONCES_SLOT_SEED = 0x38377508;
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
/* CONSTANTS */
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
/// @dev `(_NONCES_SLOT_SEED << 16) | 0x1901`.
uint256 private constant _NONCES_SLOT_SEED_WITH_SIGNATURE_PREFIX = 0x383775081901;
/// @dev `keccak256("EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)")`.
bytes32 private constant _DOMAIN_TYPEHASH =
0x8b73c3c69bb8fe3d512ecc4cf759cc79239f7b179b0ffacaa9a75d522b39400f;
/// @dev `keccak256("1")`.
bytes32 private constant _VERSION_HASH =
0xc89efdaa54c0f20c7adf612882df0950f5a951637e0307cdcb4c672f298b8bc6;
/// @dev `keccak256("Permit(address owner,address spender,uint256 value,uint256 nonce,uint256 deadline)")`.
bytes32 private constant _PERMIT_TYPEHASH =
0x6e71edae12b1b97f4d1f60370fef10105fa2faae0126114a169c64845d6126c9;
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
/* ERC20 METADATA */
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
/// @dev Returns the name of the token.
function name() public view virtual returns (string memory);
/// @dev Returns the symbol of the token.
function symbol() public view virtual returns (string memory);
/// @dev Returns the decimals places of the token.
function decimals() public view virtual returns (uint8) {
return 18;
}
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
/* ERC20 */
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
/// @dev Returns the amount of tokens in existence.
function totalSupply() public view virtual returns (uint256 result) {
/// @solidity memory-safe-assembly
assembly {
result := sload(_TOTAL_SUPPLY_SLOT)
}
}
/// @dev Returns the amount of tokens owned by `owner`.
function balanceOf(address owner) public view virtual returns (uint256 result) {
/// @solidity memory-safe-assembly
assembly {
mstore(0x0c, _BALANCE_SLOT_SEED)
mstore(0x00, owner)
result := sload(keccak256(0x0c, 0x20))
}
}
/// @dev Returns the amount of tokens that `spender` can spend on behalf of `owner`.
function allowance(address owner, address spender)
public
view
virtual
returns (uint256 result)
{
/// @solidity memory-safe-assembly
assembly {
mstore(0x20, spender)
mstore(0x0c, _ALLOWANCE_SLOT_SEED)
mstore(0x00, owner)
result := sload(keccak256(0x0c, 0x34))
}
}
/// @dev Sets `amount` as the allowance of `spender` over the caller's tokens.
///
/// Emits a {Approval} event.
function approve(address spender, uint256 amount) public virtual returns (bool) {
/// @solidity memory-safe-assembly
assembly {
// Compute the allowance slot and store the amount.
mstore(0x20, spender)
mstore(0x0c, _ALLOWANCE_SLOT_SEED)
mstore(0x00, caller())
sstore(keccak256(0x0c, 0x34), amount)
// Emit the {Approval} event.
mstore(0x00, amount)
log3(0x00, 0x20, _APPROVAL_EVENT_SIGNATURE, caller(), shr(96, mload(0x2c)))
}
return true;
}
/// @dev Transfer `amount` tokens from the caller to `to`.
///
/// Requirements:
/// - `from` must at least have `amount`.
///
/// Emits a {Transfer} event.
function transfer(address to, uint256 amount) public virtual returns (bool) {
_beforeTokenTransfer(msg.sender, to, amount);
/// @solidity memory-safe-assembly
assembly {
// Compute the balance slot and load its value.
mstore(0x0c, _BALANCE_SLOT_SEED)
mstore(0x00, caller())
let fromBalanceSlot := keccak256(0x0c, 0x20)
let fromBalance := sload(fromBalanceSlot)
// Revert if insufficient balance.
if gt(amount, fromBalance) {
mstore(0x00, 0xf4d678b8) // `InsufficientBalance()`.
revert(0x1c, 0x04)
}
// Subtract and store the updated balance.
sstore(fromBalanceSlot, sub(fromBalance, amount))
// Compute the balance slot of `to`.
mstore(0x00, to)
let toBalanceSlot := keccak256(0x0c, 0x20)
// Add and store the updated balance of `to`.
// Will not overflow because the sum of all user balances
// cannot exceed the maximum uint256 value.
sstore(toBalanceSlot, add(sload(toBalanceSlot), amount))
// Emit the {Transfer} event.
mstore(0x20, amount)
log3(0x20, 0x20, _TRANSFER_EVENT_SIGNATURE, caller(), shr(96, mload(0x0c)))
}
_afterTokenTransfer(msg.sender, to, amount);
return true;
}
/// @dev Transfers `amount` tokens from `from` to `to`.
///
/// Note: Does not update the allowance if it is the maximum uint256 value.
///
/// Requirements:
/// - `from` must at least have `amount`.
/// - The caller must have at least `amount` of allowance to transfer the tokens of `from`.
///
/// Emits a {Transfer} event.
function transferFrom(address from, address to, uint256 amount) public virtual returns (bool) {
_beforeTokenTransfer(from, to, amount);
/// @solidity memory-safe-assembly
assembly {
let from_ := shl(96, from)
// Compute the allowance slot and load its value.
mstore(0x20, caller())
mstore(0x0c, or(from_, _ALLOWANCE_SLOT_SEED))
let allowanceSlot := keccak256(0x0c, 0x34)
let allowance_ := sload(allowanceSlot)
// If the allowance is not the maximum uint256 value.
if add(allowance_, 1) {
// Revert if the amount to be transferred exceeds the allowance.
if gt(amount, allowance_) {
mstore(0x00, 0x13be252b) // `InsufficientAllowance()`.
revert(0x1c, 0x04)
}
// Subtract and store the updated allowance.
sstore(allowanceSlot, sub(allowance_, amount))
}
// Compute the balance slot and load its value.
mstore(0x0c, or(from_, _BALANCE_SLOT_SEED))
let fromBalanceSlot := keccak256(0x0c, 0x20)
let fromBalance := sload(fromBalanceSlot)
// Revert if insufficient balance.
if gt(amount, fromBalance) {
mstore(0x00, 0xf4d678b8) // `InsufficientBalance()`.
revert(0x1c, 0x04)
}
// Subtract and store the updated balance.
sstore(fromBalanceSlot, sub(fromBalance, amount))
// Compute the balance slot of `to`.
mstore(0x00, to)
let toBalanceSlot := keccak256(0x0c, 0x20)
// Add and store the updated balance of `to`.
// Will not overflow because the sum of all user balances
// cannot exceed the maximum uint256 value.
sstore(toBalanceSlot, add(sload(toBalanceSlot), amount))
// Emit the {Transfer} event.
mstore(0x20, amount)
log3(0x20, 0x20, _TRANSFER_EVENT_SIGNATURE, shr(96, from_), shr(96, mload(0x0c)))
}
_afterTokenTransfer(from, to, amount);
return true;
}
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
/* EIP-2612 */
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
/// @dev For more performance, override to return the constant value
/// of `keccak256(bytes(name()))` if `name()` will never change.
function _constantNameHash() internal view virtual returns (bytes32 result) {}
/// @dev Returns the current nonce for `owner`.
/// This value is used to compute the signature for EIP-2612 permit.
function nonces(address owner) public view virtual returns (uint256 result) {
/// @solidity memory-safe-assembly
assembly {
// Compute the nonce slot and load its value.
mstore(0x0c, _NONCES_SLOT_SEED)
mstore(0x00, owner)
result := sload(keccak256(0x0c, 0x20))
}
}
/// @dev Sets `value` as the allowance of `spender` over the tokens of `owner`,
/// authorized by a signed approval by `owner`.
///
/// Emits a {Approval} event.
function permit(
address owner,
address spender,
uint256 value,
uint256 deadline,
uint8 v,
bytes32 r,
bytes32 s
) public virtual {
bytes32 nameHash = _constantNameHash();
// We simply calculate it on-the-fly to allow for cases where the `name` may change.
if (nameHash == bytes32(0)) nameHash = keccak256(bytes(name()));
/// @solidity memory-safe-assembly
assembly {
// Revert if the block timestamp is greater than `deadline`.
if gt(timestamp(), deadline) {
mstore(0x00, 0x1a15a3cc) // `PermitExpired()`.
revert(0x1c, 0x04)
}
let m := mload(0x40) // Grab the free memory pointer.
// Clean the upper 96 bits.
owner := shr(96, shl(96, owner))
spender := shr(96, shl(96, spender))
// Compute the nonce slot and load its value.
mstore(0x0e, _NONCES_SLOT_SEED_WITH_SIGNATURE_PREFIX)
mstore(0x00, owner)
let nonceSlot := keccak256(0x0c, 0x20)
let nonceValue := sload(nonceSlot)
// Prepare the domain separator.
mstore(m, _DOMAIN_TYPEHASH)
mstore(add(m, 0x20), nameHash)
mstore(add(m, 0x40), _VERSION_HASH)
mstore(add(m, 0x60), chainid())
mstore(add(m, 0x80), address())
mstore(0x2e, keccak256(m, 0xa0))
// Prepare the struct hash.
mstore(m, _PERMIT_TYPEHASH)
mstore(add(m, 0x20), owner)
mstore(add(m, 0x40), spender)
mstore(add(m, 0x60), value)
mstore(add(m, 0x80), nonceValue)
mstore(add(m, 0xa0), deadline)
mstore(0x4e, keccak256(m, 0xc0))
// Prepare the ecrecover calldata.
mstore(0x00, keccak256(0x2c, 0x42))
mstore(0x20, and(0xff, v))
mstore(0x40, r)
mstore(0x60, s)
let t := staticcall(gas(), 1, 0, 0x80, 0x20, 0x20)
// If the ecrecover fails, the returndatasize will be 0x00,
// `owner` will be checked if it equals the hash at 0x00,
// which evaluates to false (i.e. 0), and we will revert.
// If the ecrecover succeeds, the returndatasize will be 0x20,
// `owner` will be compared against the returned address at 0x20.
if iszero(eq(mload(returndatasize()), owner)) {
mstore(0x00, 0xddafbaef) // `InvalidPermit()`.
revert(0x1c, 0x04)
}
// Increment and store the updated nonce.
sstore(nonceSlot, add(nonceValue, t)) // `t` is 1 if ecrecover succeeds.
// Compute the allowance slot and store the value.
// The `owner` is already at slot 0x20.
mstore(0x40, or(shl(160, _ALLOWANCE_SLOT_SEED), spender))
sstore(keccak256(0x2c, 0x34), value)
// Emit the {Approval} event.
log3(add(m, 0x60), 0x20, _APPROVAL_EVENT_SIGNATURE, owner, spender)
mstore(0x40, m) // Restore the free memory pointer.
mstore(0x60, 0) // Restore the zero pointer.
}
}
/// @dev Returns the EIP-712 domain separator for the EIP-2612 permit.
function DOMAIN_SEPARATOR() public view virtual returns (bytes32 result) {
bytes32 nameHash = _constantNameHash();
// We simply calculate it on-the-fly to allow for cases where the `name` may change.
if (nameHash == bytes32(0)) nameHash = keccak256(bytes(name()));
/// @solidity memory-safe-assembly
assembly {
let m := mload(0x40) // Grab the free memory pointer.
mstore(m, _DOMAIN_TYPEHASH)
mstore(add(m, 0x20), nameHash)
mstore(add(m, 0x40), _VERSION_HASH)
mstore(add(m, 0x60), chainid())
mstore(add(m, 0x80), address())
result := keccak256(m, 0xa0)
}
}
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
/* INTERNAL MINT FUNCTIONS */
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
/// @dev Mints `amount` tokens to `to`, increasing the total supply.
///
/// Emits a {Transfer} event.
function _mint(address to, uint256 amount) internal virtual {
_beforeTokenTransfer(address(0), to, amount);
/// @solidity memory-safe-assembly
assembly {
let totalSupplyBefore := sload(_TOTAL_SUPPLY_SLOT)
let totalSupplyAfter := add(totalSupplyBefore, amount)
// Revert if the total supply overflows.
if lt(totalSupplyAfter, totalSupplyBefore) {
mstore(0x00, 0xe5cfe957) // `TotalSupplyOverflow()`.
revert(0x1c, 0x04)
}
// Store the updated total supply.
sstore(_TOTAL_SUPPLY_SLOT, totalSupplyAfter)
// Compute the balance slot and load its value.
mstore(0x0c, _BALANCE_SLOT_SEED)
mstore(0x00, to)
let toBalanceSlot := keccak256(0x0c, 0x20)
// Add and store the updated balance.
sstore(toBalanceSlot, add(sload(toBalanceSlot), amount))
// Emit the {Transfer} event.
mstore(0x20, amount)
log3(0x20, 0x20, _TRANSFER_EVENT_SIGNATURE, 0, shr(96, mload(0x0c)))
}
_afterTokenTransfer(address(0), to, amount);
}
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
/* INTERNAL BURN FUNCTIONS */
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
/// @dev Burns `amount` tokens from `from`, reducing the total supply.
///
/// Emits a {Transfer} event.
function _burn(address from, uint256 amount) internal virtual {
_beforeTokenTransfer(from, address(0), amount);
/// @solidity memory-safe-assembly
assembly {
// Compute the balance slot and load its value.
mstore(0x0c, _BALANCE_SLOT_SEED)
mstore(0x00, from)
let fromBalanceSlot := keccak256(0x0c, 0x20)
let fromBalance := sload(fromBalanceSlot)
// Revert if insufficient balance.
if gt(amount, fromBalance) {
mstore(0x00, 0xf4d678b8) // `InsufficientBalance()`.
revert(0x1c, 0x04)
}
// Subtract and store the updated balance.
sstore(fromBalanceSlot, sub(fromBalance, amount))
// Subtract and store the updated total supply.
sstore(_TOTAL_SUPPLY_SLOT, sub(sload(_TOTAL_SUPPLY_SLOT), amount))
// Emit the {Transfer} event.
mstore(0x00, amount)
log3(0x00, 0x20, _TRANSFER_EVENT_SIGNATURE, shr(96, shl(96, from)), 0)
}
_afterTokenTransfer(from, address(0), amount);
}
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
/* INTERNAL TRANSFER FUNCTIONS */
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
/// @dev Moves `amount` of tokens from `from` to `to`.
function _transfer(address from, address to, uint256 amount) internal virtual {
_beforeTokenTransfer(from, to, amount);
/// @solidity memory-safe-assembly
assembly {
let from_ := shl(96, from)
// Compute the balance slot and load its value.
mstore(0x0c, or(from_, _BALANCE_SLOT_SEED))
let fromBalanceSlot := keccak256(0x0c, 0x20)
let fromBalance := sload(fromBalanceSlot)
// Revert if insufficient balance.
if gt(amount, fromBalance) {
mstore(0x00, 0xf4d678b8) // `InsufficientBalance()`.
revert(0x1c, 0x04)
}
// Subtract and store the updated balance.
sstore(fromBalanceSlot, sub(fromBalance, amount))
// Compute the balance slot of `to`.
mstore(0x00, to)
let toBalanceSlot := keccak256(0x0c, 0x20)
// Add and store the updated balance of `to`.
// Will not overflow because the sum of all user balances
// cannot exceed the maximum uint256 value.
sstore(toBalanceSlot, add(sload(toBalanceSlot), amount))
// Emit the {Transfer} event.
mstore(0x20, amount)
log3(0x20, 0x20, _TRANSFER_EVENT_SIGNATURE, shr(96, from_), shr(96, mload(0x0c)))
}
_afterTokenTransfer(from, to, amount);
}
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
/* INTERNAL ALLOWANCE FUNCTIONS */
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
/// @dev Updates the allowance of `owner` for `spender` based on spent `amount`.
function _spendAllowance(address owner, address spender, uint256 amount) internal virtual {
/// @solidity memory-safe-assembly
assembly {
// Compute the allowance slot and load its value.
mstore(0x20, spender)
mstore(0x0c, _ALLOWANCE_SLOT_SEED)
mstore(0x00, owner)
let allowanceSlot := keccak256(0x0c, 0x34)
let allowance_ := sload(allowanceSlot)
// If the allowance is not the maximum uint256 value.
if add(allowance_, 1) {
// Revert if the amount to be transferred exceeds the allowance.
if gt(amount, allowance_) {
mstore(0x00, 0x13be252b) // `InsufficientAllowance()`.
revert(0x1c, 0x04)
}
// Subtract and store the updated allowance.
sstore(allowanceSlot, sub(allowance_, amount))
}
}
}
/// @dev Sets `amount` as the allowance of `spender` over the tokens of `owner`.
///
/// Emits a {Approval} event.
function _approve(address owner, address spender, uint256 amount) internal virtual {
/// @solidity memory-safe-assembly
assembly {
let owner_ := shl(96, owner)
// Compute the allowance slot and store the amount.
mstore(0x20, spender)
mstore(0x0c, or(owner_, _ALLOWANCE_SLOT_SEED))
sstore(keccak256(0x0c, 0x34), amount)
// Emit the {Approval} event.
mstore(0x00, amount)
log3(0x00, 0x20, _APPROVAL_EVENT_SIGNATURE, shr(96, owner_), shr(96, mload(0x2c)))
}
}
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
/* HOOKS TO OVERRIDE */
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
/// @dev Hook that is called before any transfer of tokens.
/// This includes minting and burning.
function _beforeTokenTransfer(address from, address to, uint256 amount) internal virtual {}
/// @dev Hook that is called after any transfer of tokens.
/// This includes minting and burning.
function _afterTokenTransfer(address from, address to, uint256 amount) internal virtual {}
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.4;
/// @notice Arithmetic library with operations for fixed-point numbers.
/// @author Solady (https://github.com/vectorized/solady/blob/main/src/utils/FixedPointMathLib.sol)
/// @author Modified from Solmate (https://github.com/transmissions11/solmate/blob/main/src/utils/FixedPointMathLib.sol)
library FixedPointMathLib {
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
/* CUSTOM ERRORS */
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
/// @dev The operation failed, as the output exceeds the maximum value of uint256.
error ExpOverflow();
/// @dev The operation failed, as the output exceeds the maximum value of uint256.
error FactorialOverflow();
/// @dev The operation failed, due to an overflow.
error RPowOverflow();
/// @dev The mantissa is too big to fit.
error MantissaOverflow();
/// @dev The operation failed, due to an multiplication overflow.
error MulWadFailed();
/// @dev The operation failed, due to an multiplication overflow.
error SMulWadFailed();
/// @dev The operation failed, either due to a multiplication overflow, or a division by a zero.
error DivWadFailed();
/// @dev The operation failed, either due to a multiplication overflow, or a division by a zero.
error SDivWadFailed();
/// @dev The operation failed, either due to a multiplication overflow, or a division by a zero.
error MulDivFailed();
/// @dev The division failed, as the denominator is zero.
error DivFailed();
/// @dev The full precision multiply-divide operation failed, either due
/// to the result being larger than 256 bits, or a division by a zero.
error FullMulDivFailed();
/// @dev The output is undefined, as the input is less-than-or-equal to zero.
error LnWadUndefined();
/// @dev The input outside the acceptable domain.
error OutOfDomain();
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
/* CONSTANTS */
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
/// @dev The scalar of ETH and most ERC20s.
uint256 internal constant WAD = 1e18;
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
/* SIMPLIFIED FIXED POINT OPERATIONS */
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
/// @dev Equivalent to `(x * y) / WAD` rounded down.
function mulWad(uint256 x, uint256 y) internal pure returns (uint256 z) {
/// @solidity memory-safe-assembly
assembly {
// Equivalent to `require(y == 0 || x <= type(uint256).max / y)`.
if mul(y, gt(x, div(not(0), y))) {
mstore(0x00, 0xbac65e5b) // `MulWadFailed()`.
revert(0x1c, 0x04)
}
z := div(mul(x, y), WAD)
}
}
/// @dev Equivalent to `(x * y) / WAD` rounded down.
function sMulWad(int256 x, int256 y) internal pure returns (int256 z) {
/// @solidity memory-safe-assembly
assembly {
z := mul(x, y)
// Equivalent to `require((x == 0 || z / x == y) && !(x == -1 && y == type(int256).min))`.
if iszero(gt(or(iszero(x), eq(sdiv(z, x), y)), lt(not(x), eq(y, shl(255, 1))))) {
mstore(0x00, 0xedcd4dd4) // `SMulWadFailed()`.
revert(0x1c, 0x04)
}
z := sdiv(z, WAD)
}
}
/// @dev Equivalent to `(x * y) / WAD` rounded down, but without overflow checks.
function rawMulWad(uint256 x, uint256 y) internal pure returns (uint256 z) {
/// @solidity memory-safe-assembly
assembly {
z := div(mul(x, y), WAD)
}
}
/// @dev Equivalent to `(x * y) / WAD` rounded down, but without overflow checks.
function rawSMulWad(int256 x, int256 y) internal pure returns (int256 z) {
/// @solidity memory-safe-assembly
assembly {
z := sdiv(mul(x, y), WAD)
}
}
/// @dev Equivalent to `(x * y) / WAD` rounded up.
function mulWadUp(uint256 x, uint256 y) internal pure returns (uint256 z) {
/// @solidity memory-safe-assembly
assembly {
// Equivalent to `require(y == 0 || x <= type(uint256).max / y)`.
if mul(y, gt(x, div(not(0), y))) {
mstore(0x00, 0xbac65e5b) // `MulWadFailed()`.
revert(0x1c, 0x04)
}
z := add(iszero(iszero(mod(mul(x, y), WAD))), div(mul(x, y), WAD))
}
}
/// @dev Equivalent to `(x * y) / WAD` rounded up, but without overflow checks.
function rawMulWadUp(uint256 x, uint256 y) internal pure returns (uint256 z) {
/// @solidity memory-safe-assembly
assembly {
z := add(iszero(iszero(mod(mul(x, y), WAD))), div(mul(x, y), WAD))
}
}
/// @dev Equivalent to `(x * WAD) / y` rounded down.
function divWad(uint256 x, uint256 y) internal pure returns (uint256 z) {
/// @solidity memory-safe-assembly
assembly {
// Equivalent to `require(y != 0 && (WAD == 0 || x <= type(uint256).max / WAD))`.
if iszero(mul(y, iszero(mul(WAD, gt(x, div(not(0), WAD)))))) {
mstore(0x00, 0x7c5f487d) // `DivWadFailed()`.
revert(0x1c, 0x04)
}
z := div(mul(x, WAD), y)
}
}
/// @dev Equivalent to `(x * WAD) / y` rounded down.
function sDivWad(int256 x, int256 y) internal pure returns (int256 z) {
/// @solidity memory-safe-assembly
assembly {
z := mul(x, WAD)
// Equivalent to `require(y != 0 && ((x * WAD) / WAD == x))`.
if iszero(and(iszero(iszero(y)), eq(sdiv(z, WAD), x))) {
mstore(0x00, 0x5c43740d) // `SDivWadFailed()`.
revert(0x1c, 0x04)
}
z := sdiv(mul(x, WAD), y)
}
}
/// @dev Equivalent to `(x * WAD) / y` rounded down, but without overflow and divide by zero checks.
function rawDivWad(uint256 x, uint256 y) internal pure returns (uint256 z) {
/// @solidity memory-safe-assembly
assembly {
z := div(mul(x, WAD), y)
}
}
/// @dev Equivalent to `(x * WAD) / y` rounded down, but without overflow and divide by zero checks.
function rawSDivWad(int256 x, int256 y) internal pure returns (int256 z) {
/// @solidity memory-safe-assembly
assembly {
z := sdiv(mul(x, WAD), y)
}
}
/// @dev Equivalent to `(x * WAD) / y` rounded up.
function divWadUp(uint256 x, uint256 y) internal pure returns (uint256 z) {
/// @solidity memory-safe-assembly
assembly {
// Equivalent to `require(y != 0 && (WAD == 0 || x <= type(uint256).max / WAD))`.
if iszero(mul(y, iszero(mul(WAD, gt(x, div(not(0), WAD)))))) {
mstore(0x00, 0x7c5f487d) // `DivWadFailed()`.
revert(0x1c, 0x04)
}
z := add(iszero(iszero(mod(mul(x, WAD), y))), div(mul(x, WAD), y))
}
}
/// @dev Equivalent to `(x * WAD) / y` rounded up, but without overflow and divide by zero checks.
function rawDivWadUp(uint256 x, uint256 y) internal pure returns (uint256 z) {
/// @solidity memory-safe-assembly
assembly {
z := add(iszero(iszero(mod(mul(x, WAD), y))), div(mul(x, WAD), y))
}
}
/// @dev Equivalent to `x` to the power of `y`.
/// because `x ** y = (e ** ln(x)) ** y = e ** (ln(x) * y)`.
function powWad(int256 x, int256 y) internal pure returns (int256) {
// Using `ln(x)` means `x` must be greater than 0.
return expWad((lnWad(x) * y) / int256(WAD));
}
/// @dev Returns `exp(x)`, denominated in `WAD`.
/// Credit to Remco Bloemen under MIT license: https://2π.com/22/exp-ln
function expWad(int256 x) internal pure returns (int256 r) {
unchecked {
// When the result is less than 0.5 we return zero.
// This happens when `x <= (log(1e-18) * 1e18) ~ -4.15e19`.
if (x <= -41446531673892822313) return r;
/// @solidity memory-safe-assembly
assembly {
// When the result is greater than `(2**255 - 1) / 1e18` we can not represent it as
// an int. This happens when `x >= floor(log((2**255 - 1) / 1e18) * 1e18) ≈ 135`.
if iszero(slt(x, 135305999368893231589)) {
mstore(0x00, 0xa37bfec9) // `ExpOverflow()`.
revert(0x1c, 0x04)
}
}
// `x` is now in the range `(-42, 136) * 1e18`. Convert to `(-42, 136) * 2**96`
// for more intermediate precision and a binary basis. This base conversion
// is a multiplication by 1e18 / 2**96 = 5**18 / 2**78.
x = (x << 78) / 5 ** 18;
// Reduce range of x to (-½ ln 2, ½ ln 2) * 2**96 by factoring out powers
// of two such that exp(x) = exp(x') * 2**k, where k is an integer.
// Solving this gives k = round(x / log(2)) and x' = x - k * log(2).
int256 k = ((x << 96) / 54916777467707473351141471128 + 2 ** 95) >> 96;
x = x - k * 54916777467707473351141471128;
// `k` is in the range `[-61, 195]`.
// Evaluate using a (6, 7)-term rational approximation.
// `p` is made monic, we'll multiply by a scale factor later.
int256 y = x + 1346386616545796478920950773328;
y = ((y * x) >> 96) + 57155421227552351082224309758442;
int256 p = y + x - 94201549194550492254356042504812;
p = ((p * y) >> 96) + 28719021644029726153956944680412240;
p = p * x + (4385272521454847904659076985693276 << 96);
// We leave `p` in `2**192` basis so we don't need to scale it back up for the division.
int256 q = x - 2855989394907223263936484059900;
q = ((q * x) >> 96) + 50020603652535783019961831881945;
q = ((q * x) >> 96) - 533845033583426703283633433725380;
q = ((q * x) >> 96) + 3604857256930695427073651918091429;
q = ((q * x) >> 96) - 14423608567350463180887372962807573;
q = ((q * x) >> 96) + 26449188498355588339934803723976023;
/// @solidity memory-safe-assembly
assembly {
// Div in assembly because solidity adds a zero check despite the unchecked.
// The q polynomial won't have zeros in the domain as all its roots are complex.
// No scaling is necessary because p is already `2**96` too large.
r := sdiv(p, q)
}
// r should be in the range `(0.09, 0.25) * 2**96`.
// We now need to multiply r by:
// - The scale factor `s ≈ 6.031367120`.
// - The `2**k` factor from the range reduction.
// - The `1e18 / 2**96` factor for base conversion.
// We do this all at once, with an intermediate result in `2**213`
// basis, so the final right shift is always by a positive amount.
r = int256(
(uint256(r) * 3822833074963236453042738258902158003155416615667) >> uint256(195 - k)
);
}
}
/// @dev Returns `ln(x)`, denominated in `WAD`.
/// Credit to Remco Bloemen under MIT license: https://2π.com/22/exp-ln
function lnWad(int256 x) internal pure returns (int256 r) {
/// @solidity memory-safe-assembly
assembly {
// We want to convert `x` from `10**18` fixed point to `2**96` fixed point.
// We do this by multiplying by `2**96 / 10**18`. But since
// `ln(x * C) = ln(x) + ln(C)`, we can simply do nothing here
// and add `ln(2**96 / 10**18)` at the end.
// Compute `k = log2(x) - 96`, `r = 159 - k = 255 - log2(x) = 255 ^ log2(x)`.
r := shl(7, lt(0xffffffffffffffffffffffffffffffff, x))
r := or(r, shl(6, lt(0xffffffffffffffff, shr(r, x))))
r := or(r, shl(5, lt(0xffffffff, shr(r, x))))
r := or(r, shl(4, lt(0xffff, shr(r, x))))
r := or(r, shl(3, lt(0xff, shr(r, x))))
// We place the check here for more optimal stack operations.
if iszero(sgt(x, 0)) {
mstore(0x00, 0x1615e638) // `LnWadUndefined()`.
revert(0x1c, 0x04)
}
// forgefmt: disable-next-item
r := xor(r, byte(and(0x1f, shr(shr(r, x), 0x8421084210842108cc6318c6db6d54be)),
0xf8f9f9faf9fdfafbf9fdfcfdfafbfcfef9fafdfafcfcfbfefafafcfbffffffff))
// Reduce range of x to (1, 2) * 2**96
// ln(2^k * x) = k * ln(2) + ln(x)
x := shr(159, shl(r, x))
// Evaluate using a (8, 8)-term rational approximation.
// `p` is made monic, we will multiply by a scale factor later.
// forgefmt: disable-next-item
let p := sub( // This heavily nested expression is to avoid stack-too-deep for via-ir.
sar(96, mul(add(43456485725739037958740375743393,
sar(96, mul(add(24828157081833163892658089445524,
sar(96, mul(add(3273285459638523848632254066296,
x), x))), x))), x)), 11111509109440967052023855526967)
p := sub(sar(96, mul(p, x)), 45023709667254063763336534515857)
p := sub(sar(96, mul(p, x)), 14706773417378608786704636184526)
p := sub(mul(p, x), shl(96, 795164235651350426258249787498))
// We leave `p` in `2**192` basis so we don't need to scale it back up for the division.
// `q` is monic by convention.
let q := add(5573035233440673466300451813936, x)
q := add(71694874799317883764090561454958, sar(96, mul(x, q)))
q := add(283447036172924575727196451306956, sar(96, mul(x, q)))
q := add(401686690394027663651624208769553, sar(96, mul(x, q)))
q := add(204048457590392012362485061816622, sar(96, mul(x, q)))
q := add(31853899698501571402653359427138, sar(96, mul(x, q)))
q := add(909429971244387300277376558375, sar(96, mul(x, q)))
// `p / q` is in the range `(0, 0.125) * 2**96`.
// Finalization, we need to:
// - Multiply by the scale factor `s = 5.549…`.
// - Add `ln(2**96 / 10**18)`.
// - Add `k * ln(2)`.
// - Multiply by `10**18 / 2**96 = 5**18 >> 78`.
// The q polynomial is known not to have zeros in the domain.
// No scaling required because p is already `2**96` too large.
p := sdiv(p, q)
// Multiply by the scaling factor: `s * 5**18 * 2**96`, base is now `5**18 * 2**192`.
p := mul(1677202110996718588342820967067443963516166, p)
// Add `ln(2) * k * 5**18 * 2**192`.
// forgefmt: disable-next-item
p := add(mul(16597577552685614221487285958193947469193820559219878177908093499208371, sub(159, r)), p)
// Add `ln(2**96 / 10**18) * 5**18 * 2**192`.
p := add(600920179829731861736702779321621459595472258049074101567377883020018308, p)
// Base conversion: mul `2**18 / 2**192`.
r := sar(174, p)
}
}
/// @dev Returns `W_0(x)`, denominated in `WAD`.
/// See: https://en.wikipedia.org/wiki/Lambert_W_function
/// a.k.a. Product log function. This is an approximation of the principal branch.
function lambertW0Wad(int256 x) internal pure returns (int256 w) {
// forgefmt: disable-next-item
unchecked {
if ((w = x) <= -367879441171442322) revert OutOfDomain(); // `x` less than `-1/e`.
int256 wad = int256(WAD);
int256 p = x;
uint256 c; // Whether we need to avoid catastrophic cancellation.
uint256 i = 4; // Number of iterations.
if (w <= 0x1ffffffffffff) {
if (-0x4000000000000 <= w) {
i = 1; // Inputs near zero only take one step to converge.
} else if (w <= -0x3ffffffffffffff) {
i = 32; // Inputs near `-1/e` take very long to converge.
}
} else if (w >> 63 == 0) {
/// @solidity memory-safe-assembly
assembly {
// Inline log2 for more performance, since the range is small.
let v := shr(49, w)
let l := shl(3, lt(0xff, v))
l := add(or(l, byte(and(0x1f, shr(shr(l, v), 0x8421084210842108cc6318c6db6d54be)),
0x0706060506020504060203020504030106050205030304010505030400000000)), 49)
w := sdiv(shl(l, 7), byte(sub(l, 31), 0x0303030303030303040506080c13))
c := gt(l, 60)
i := add(2, add(gt(l, 53), c))
}
} else {
int256 ll = lnWad(w = lnWad(w));
/// @solidity memory-safe-assembly
assembly {
// `w = ln(x) - ln(ln(x)) + b * ln(ln(x)) / ln(x)`.
w := add(sdiv(mul(ll, 1023715080943847266), w), sub(w, ll))
i := add(3, iszero(shr(68, x)))
c := iszero(shr(143, x))
}
if (c == 0) {
do { // If `x` is big, use Newton's so that intermediate values won't overflow.
int256 e = expWad(w);
/// @solidity memory-safe-assembly
assembly {
let t := mul(w, div(e, wad))
w := sub(w, sdiv(sub(t, x), div(add(e, t), wad)))
}
if (p <= w) break;
p = w;
} while (--i != 0);
/// @solidity memory-safe-assembly
assembly {
w := sub(w, sgt(w, 2))
}
return w;
}
}
do { // Otherwise, use Halley's for faster convergence.
int256 e = expWad(w);
/// @solidity memory-safe-assembly
assembly {
let t := add(w, wad)
let s := sub(mul(w, e), mul(x, wad))
w := sub(w, sdiv(mul(s, wad), sub(mul(e, t), sdiv(mul(add(t, wad), s), add(t, t)))))
}
if (p <= w) break;
p = w;
} while (--i != c);
/// @solidity memory-safe-assembly
assembly {
w := sub(w, sgt(w, 2))
}
// For certain ranges of `x`, we'll use the quadratic-rate recursive formula of
// R. Iacono and J.P. Boyd for the last iteration, to avoid catastrophic cancellation.
if (c != 0) {
int256 t = w | 1;
/// @solidity memory-safe-assembly
assembly {
x := sdiv(mul(x, wad), t)
}
x = (t * (wad + lnWad(x)));
/// @solidity memory-safe-assembly
assembly {
w := sdiv(x, add(wad, t))
}
}
}
}
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
/* GENERAL NUMBER UTILITIES */
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
/// @dev Calculates `floor(x * y / d)` with full precision.
/// Throws if result overflows a uint256 or when `d` is zero.
/// Credit to Remco Bloemen under MIT license: https://2π.com/21/muldiv
function fullMulDiv(uint256 x, uint256 y, uint256 d) internal pure returns (uint256 result) {
/// @solidity memory-safe-assembly
assembly {
for {} 1 {} {
// 512-bit multiply `[p1 p0] = x * y`.
// Compute the product mod `2**256` and mod `2**256 - 1`
// then use the Chinese Remainder Theorem to reconstruct
// the 512 bit result. The result is stored in two 256
// variables such that `product = p1 * 2**256 + p0`.
// Least significant 256 bits of the product.
result := mul(x, y) // Temporarily use `result` as `p0` to save gas.
let mm := mulmod(x, y, not(0))
// Most significant 256 bits of the product.
let p1 := sub(mm, add(result, lt(mm, result)))
// Handle non-overflow cases, 256 by 256 division.
if iszero(p1) {
if iszero(d) {
mstore(0x00, 0xae47f702) // `FullMulDivFailed()`.
revert(0x1c, 0x04)
}
result := div(result, d)
break
}
// Make sure the result is less than `2**256`. Also prevents `d == 0`.
if iszero(gt(d, p1)) {
mstore(0x00, 0xae47f702) // `FullMulDivFailed()`.
revert(0x1c, 0x04)
}
/*------------------- 512 by 256 division --------------------*/
// Make division exact by subtracting the remainder from `[p1 p0]`.
// Compute remainder using mulmod.
let r := mulmod(x, y, d)
// `t` is the least significant bit of `d`.
// Always greater or equal to 1.
let t := and(d, sub(0, d))
// Divide `d` by `t`, which is a power of two.
d := div(d, t)
// Invert `d mod 2**256`
// Now that `d` is an odd number, it has an inverse
// modulo `2**256` such that `d * inv = 1 mod 2**256`.
// Compute the inverse by starting with a seed that is correct
// correct for four bits. That is, `d * inv = 1 mod 2**4`.
let inv := xor(2, mul(3, d))
// Now use 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.
inv := mul(inv, sub(2, mul(d, inv))) // inverse mod 2**8
inv := mul(inv, sub(2, mul(d, inv))) // inverse mod 2**16
inv := mul(inv, sub(2, mul(d, inv))) // inverse mod 2**32
inv := mul(inv, sub(2, mul(d, inv))) // inverse mod 2**64
inv := mul(inv, sub(2, mul(d, inv))) // inverse mod 2**128
result :=
mul(
// Divide [p1 p0] by the factors of two.
// Shift in bits from `p1` into `p0`. For this we need
// to flip `t` such that it is `2**256 / t`.
or(
mul(sub(p1, gt(r, result)), add(div(sub(0, t), t), 1)),
div(sub(result, r), t)
),
// inverse mod 2**256
mul(inv, sub(2, mul(d, inv)))
)
break
}
}
}
/// @dev Calculates `floor(x * y / d)` with full precision, rounded up.
/// Throws if result overflows a uint256 or when `d` is zero.
/// Credit to Uniswap-v3-core under MIT license:
/// https://github.com/Uniswap/v3-core/blob/main/contracts/libraries/FullMath.sol
function fullMulDivUp(uint256 x, uint256 y, uint256 d) internal pure returns (uint256 result) {
result = fullMulDiv(x, y, d);
/// @solidity memory-safe-assembly
assembly {
if mulmod(x, y, d) {
result := add(result, 1)
if iszero(result) {
mstore(0x00, 0xae47f702) // `FullMulDivFailed()`.
revert(0x1c, 0x04)
}
}
}
}
/// @dev Returns `floor(x * y / d)`.
/// Reverts if `x * y` overflows, or `d` is zero.
function mulDiv(uint256 x, uint256 y, uint256 d) internal pure returns (uint256 z) {
/// @solidity memory-safe-assembly
assembly {
// Equivalent to require(d != 0 && (y == 0 || x <= type(uint256).max / y))
if iszero(mul(d, iszero(mul(y, gt(x, div(not(0), y)))))) {
mstore(0x00, 0xad251c27) // `MulDivFailed()`.
revert(0x1c, 0x04)
}
z := div(mul(x, y), d)
}
}
/// @dev Returns `ceil(x * y / d)`.
/// Reverts if `x * y` overflows, or `d` is zero.
function mulDivUp(uint256 x, uint256 y, uint256 d) internal pure returns (uint256 z) {
/// @solidity memory-safe-assembly
assembly {
// Equivalent to require(d != 0 && (y == 0 || x <= type(uint256).max / y))
if iszero(mul(d, iszero(mul(y, gt(x, div(not(0), y)))))) {
mstore(0x00, 0xad251c27) // `MulDivFailed()`.
revert(0x1c, 0x04)
}
z := add(iszero(iszero(mod(mul(x, y), d))), div(mul(x, y), d))
}
}
/// @dev Returns `ceil(x / d)`.
/// Reverts if `d` is zero.
function divUp(uint256 x, uint256 d) internal pure returns (uint256 z) {
/// @solidity memory-safe-assembly
assembly {
if iszero(d) {
mstore(0x00, 0x65244e4e) // `DivFailed()`.
revert(0x1c, 0x04)
}
z := add(iszero(iszero(mod(x, d))), div(x, d))
}
}
/// @dev Returns `max(0, x - y)`.
function zeroFloorSub(uint256 x, uint256 y) internal pure returns (uint256 z) {
/// @solidity memory-safe-assembly
assembly {
z := mul(gt(x, y), sub(x, y))
}
}
/// @dev Exponentiate `x` to `y` by squaring, denominated in base `b`.
/// Reverts if the computation overflows.
function rpow(uint256 x, uint256 y, uint256 b) internal pure returns (uint256 z) {
/// @solidity memory-safe-assembly
assembly {
z := mul(b, iszero(y)) // `0 ** 0 = 1`. Otherwise, `0 ** n = 0`.
if x {
z := xor(b, mul(xor(b, x), and(y, 1))) // `z = isEven(y) ? scale : x`
let half := shr(1, b) // Divide `b` by 2.
// Divide `y` by 2 every iteration.
for { y := shr(1, y) } y { y := shr(1, y) } {
let xx := mul(x, x) // Store x squared.
let xxRound := add(xx, half) // Round to the nearest number.
// Revert if `xx + half` overflowed, or if `x ** 2` overflows.
if or(lt(xxRound, xx), shr(128, x)) {
mstore(0x00, 0x49f7642b) // `RPowOverflow()`.
revert(0x1c, 0x04)
}
x := div(xxRound, b) // Set `x` to scaled `xxRound`.
// If `y` is odd:
if and(y, 1) {
let zx := mul(z, x) // Compute `z * x`.
let zxRound := add(zx, half) // Round to the nearest number.
// If `z * x` overflowed or `zx + half` overflowed:
if or(xor(div(zx, x), z), lt(zxRound, zx)) {
// Revert if `x` is non-zero.
if iszero(iszero(x)) {
mstore(0x00, 0x49f7642b) // `RPowOverflow()`.
revert(0x1c, 0x04)
}
}
z := div(zxRound, b) // Return properly scaled `zxRound`.
}
}
}
}
}
/// @dev Returns the square root of `x`.
function sqrt(uint256 x) internal pure returns (uint256 z) {
/// @solidity memory-safe-assembly
assembly {
// `floor(sqrt(2**15)) = 181`. `sqrt(2**15) - 181 = 2.84`.
z := 181 // The "correct" value is 1, but this saves a multiplication later.
// This segment is to get a reasonable initial estimate for the Babylonian method. With a bad
// start, the correct # of bits increases ~linearly each iteration instead of ~quadratically.
// Let `y = x / 2**r`. We check `y >= 2**(k + 8)`
// but shift right by `k` bits to ensure that if `x >= 256`, then `y >= 256`.
let r := shl(7, lt(0xffffffffffffffffffffffffffffffffff, x))
r := or(r, shl(6, lt(0xffffffffffffffffff, shr(r, x))))
r := or(r, shl(5, lt(0xffffffffff, shr(r, x))))
r := or(r, shl(4, lt(0xffffff, shr(r, x))))
z := shl(shr(1, r), z)
// Goal was to get `z*z*y` within a small factor of `x`. More iterations could
// get y in a tighter range. Currently, we will have y in `[256, 256*(2**16))`.
// We ensured `y >= 256` so that the relative difference between `y` and `y+1` is small.
// That's not possible if `x < 256` but we can just verify those cases exhaustively.
// Now, `z*z*y <= x < z*z*(y+1)`, and `y <= 2**(16+8)`, and either `y >= 256`, or `x < 256`.
// Correctness can be checked exhaustively for `x < 256`, so we assume `y >= 256`.
// Then `z*sqrt(y)` is within `sqrt(257)/sqrt(256)` of `sqrt(x)`, or about 20bps.
// For `s` in the range `[1/256, 256]`, the estimate `f(s) = (181/1024) * (s+1)`
// is in the range `(1/2.84 * sqrt(s), 2.84 * sqrt(s))`,
// with largest error when `s = 1` and when `s = 256` or `1/256`.
// Since `y` is in `[256, 256*(2**16))`, let `a = y/65536`, so that `a` is in `[1/256, 256)`.
// Then we can estimate `sqrt(y)` using
// `sqrt(65536) * 181/1024 * (a + 1) = 181/4 * (y + 65536)/65536 = 181 * (y + 65536)/2**18`.
// There is no overflow risk here since `y < 2**136` after the first branch above.
z := shr(18, mul(z, add(shr(r, x), 65536))) // A `mul()` is saved from starting `z` at 181.
// Given the worst case multiplicative error of 2.84 above, 7 iterations should be enough.
z := shr(1, add(z, div(x, z)))
z := shr(1, add(z, div(x, z)))
z := shr(1, add(z, div(x, z)))
z := shr(1, add(z, div(x, z)))
z := shr(1, add(z, div(x, z)))
z := shr(1, add(z, div(x, z)))
z := shr(1, add(z, div(x, z)))
// If `x+1` is a perfect square, the Babylonian method cycles between
// `floor(sqrt(x))` and `ceil(sqrt(x))`. This statement ensures we return floor.
// See: https://en.wikipedia.org/wiki/Integer_square_root#Using_only_integer_division
z := sub(z, lt(div(x, z), z))
}
}
/// @dev Returns the cube root of `x`.
/// Credit to bout3fiddy and pcaversaccio under AGPLv3 license:
/// https://github.com/pcaversaccio/snekmate/blob/main/src/utils/Math.vy
function cbrt(uint256 x) internal pure returns (uint256 z) {
/// @solidity memory-safe-assembly
assembly {
let r := shl(7, lt(0xffffffffffffffffffffffffffffffff, x))
r := or(r, shl(6, lt(0xffffffffffffffff, shr(r, x))))
r := or(r, shl(5, lt(0xffffffff, shr(r, x))))
r := or(r, shl(4, lt(0xffff, shr(r, x))))
r := or(r, shl(3, lt(0xff, shr(r, x))))
z := div(shl(div(r, 3), shl(lt(0xf, shr(r, x)), 0xf)), xor(7, mod(r, 3)))
z := div(add(add(div(x, mul(z, z)), z), z), 3)
z := div(add(add(div(x, mul(z, z)), z), z), 3)
z := div(add(add(div(x, mul(z, z)), z), z), 3)
z := div(add(add(div(x, mul(z, z)), z), z), 3)
z := div(add(add(div(x, mul(z, z)), z), z), 3)
z := div(add(add(div(x, mul(z, z)), z), z), 3)
z := div(add(add(div(x, mul(z, z)), z), z), 3)
z := sub(z, lt(div(x, mul(z, z)), z))
}
}
/// @dev Returns the square root of `x`, denominated in `WAD`.
function sqrtWad(uint256 x) internal pure returns (uint256 z) {
unchecked {
z = 10 ** 9;
if (x <= type(uint256).max / 10 ** 36 - 1) {
x *= 10 ** 18;
z = 1;
}
z *= sqrt(x);
}
}
/// @dev Returns the cube root of `x`, denominated in `WAD`.
function cbrtWad(uint256 x) internal pure returns (uint256 z) {
unchecked {
z = 10 ** 12;
if (x <= (type(uint256).max / 10 ** 36) * 10 ** 18 - 1) {
if (x >= type(uint256).max / 10 ** 36) {
x *= 10 ** 18;
z = 10 ** 6;
} else {
x *= 10 ** 36;
z = 1;
}
}
z *= cbrt(x);
}
}
/// @dev Returns the factorial of `x`.
function factorial(uint256 x) internal pure returns (uint256 result) {
/// @solidity memory-safe-assembly
assembly {
if iszero(lt(x, 58)) {
mstore(0x00, 0xaba0f2a2) // `FactorialOverflow()`.
revert(0x1c, 0x04)
}
for { result := 1 } x { x := sub(x, 1) } { result := mul(result, x) }
}
}
/// @dev Returns the log2 of `x`.
/// Equivalent to computing the index of the most significant bit (MSB) of `x`.
/// Returns 0 if `x` is zero.
function log2(uint256 x) internal pure returns (uint256 r) {
/// @solidity memory-safe-assembly
assembly {
r := shl(7, lt(0xffffffffffffffffffffffffffffffff, x))
r := or(r, shl(6, lt(0xffffffffffffffff, shr(r, x))))
r := or(r, shl(5, lt(0xffffffff, shr(r, x))))
r := or(r, shl(4, lt(0xffff, shr(r, x))))
r := or(r, shl(3, lt(0xff, shr(r, x))))
// forgefmt: disable-next-item
r := or(r, byte(and(0x1f, shr(shr(r, x), 0x8421084210842108cc6318c6db6d54be)),
0x0706060506020504060203020504030106050205030304010505030400000000))
}
}
/// @dev Returns the log2 of `x`, rounded up.
/// Returns 0 if `x` is zero.
function log2Up(uint256 x) internal pure returns (uint256 r) {
r = log2(x);
/// @solidity memory-safe-assembly
assembly {
r := add(r, lt(shl(r, 1), x))
}
}
/// @dev Returns the log10 of `x`.
/// Returns 0 if `x` is zero.
function log10(uint256 x) internal pure returns (uint256 r) {
/// @solidity memory-safe-assembly
assembly {
if iszero(lt(x, 100000000000000000000000000000000000000)) {
x := div(x, 100000000000000000000000000000000000000)
r := 38
}
if iszero(lt(x, 100000000000000000000)) {
x := div(x, 100000000000000000000)
r := add(r, 20)
}
if iszero(lt(x, 10000000000)) {
x := div(x, 10000000000)
r := add(r, 10)
}
if iszero(lt(x, 100000)) {
x := div(x, 100000)
r := add(r, 5)
}
r := add(r, add(gt(x, 9), add(gt(x, 99), add(gt(x, 999), gt(x, 9999)))))
}
}
/// @dev Returns the log10 of `x`, rounded up.
/// Returns 0 if `x` is zero.
function log10Up(uint256 x) internal pure returns (uint256 r) {
r = log10(x);
/// @solidity memory-safe-assembly
assembly {
r := add(r, lt(exp(10, r), x))
}
}
/// @dev Returns the log256 of `x`.
/// Returns 0 if `x` is zero.
function log256(uint256 x) internal pure returns (uint256 r) {
/// @solidity memory-safe-assembly
assembly {
r := shl(7, lt(0xffffffffffffffffffffffffffffffff, x))
r := or(r, shl(6, lt(0xffffffffffffffff, shr(r, x))))
r := or(r, shl(5, lt(0xffffffff, shr(r, x))))
r := or(r, shl(4, lt(0xffff, shr(r, x))))
r := or(shr(3, r), lt(0xff, shr(r, x)))
}
}
/// @dev Returns the log256 of `x`, rounded up.
/// Returns 0 if `x` is zero.
function log256Up(uint256 x) internal pure returns (uint256 r) {
r = log256(x);
/// @solidity memory-safe-assembly
assembly {
r := add(r, lt(shl(shl(3, r), 1), x))
}
}
/// @dev Returns the scientific notation format `mantissa * 10 ** exponent` of `x`.
/// Useful for compressing prices (e.g. using 25 bit mantissa and 7 bit exponent).
function sci(uint256 x) internal pure returns (uint256 mantissa, uint256 exponent) {
/// @solidity memory-safe-assembly
assembly {
mantissa := x
if mantissa {
if iszero(mod(mantissa, 1000000000000000000000000000000000)) {
mantissa := div(mantissa, 1000000000000000000000000000000000)
exponent := 33
}
if iszero(mod(mantissa, 10000000000000000000)) {
mantissa := div(mantissa, 10000000000000000000)
exponent := add(exponent, 19)
}
if iszero(mod(mantissa, 1000000000000)) {
mantissa := div(mantissa, 1000000000000)
exponent := add(exponent, 12)
}
if iszero(mod(mantissa, 1000000)) {
mantissa := div(mantissa, 1000000)
exponent := add(exponent, 6)
}
if iszero(mod(mantissa, 10000)) {
mantissa := div(mantissa, 10000)
exponent := add(exponent, 4)
}
if iszero(mod(mantissa, 100)) {
mantissa := div(mantissa, 100)
exponent := add(exponent, 2)
}
if iszero(mod(mantissa, 10)) {
mantissa := div(mantissa, 10)
exponent := add(exponent, 1)
}
}
}
}
/// @dev Convenience function for packing `x` into a smaller number using `sci`.
/// The `mantissa` will be in bits [7..255] (the upper 249 bits).
/// The `exponent` will be in bits [0..6] (the lower 7 bits).
/// Use `SafeCastLib` to safely ensure that the `packed` number is small
/// enough to fit in the desired unsigned integer type:
/// ```
/// uint32 packed = SafeCastLib.toUint32(FixedPointMathLib.packSci(777 ether));
/// ```
function packSci(uint256 x) internal pure returns (uint256 packed) {
(x, packed) = sci(x); // Reuse for `mantissa` and `exponent`.
/// @solidity memory-safe-assembly
assembly {
if shr(249, x) {
mstore(0x00, 0xce30380c) // `MantissaOverflow()`.
revert(0x1c, 0x04)
}
packed := or(shl(7, x), packed)
}
}
/// @dev Convenience function for unpacking a packed number from `packSci`.
function unpackSci(uint256 packed) internal pure returns (uint256 unpacked) {
unchecked {
unpacked = (packed >> 7) * 10 ** (packed & 0x7f);
}
}
/// @dev Returns the average of `x` and `y`.
function avg(uint256 x, uint256 y) internal pure returns (uint256 z) {
unchecked {
z = (x & y) + ((x ^ y) >> 1);
}
}
/// @dev Returns the average of `x` and `y`.
function avg(int256 x, int256 y) internal pure returns (int256 z) {
unchecked {
z = (x >> 1) + (y >> 1) + (x & y & 1);
}
}
/// @dev Returns the absolute value of `x`.
function abs(int256 x) internal pure returns (uint256 z) {
/// @solidity memory-safe-assembly
assembly {
z := xor(sub(0, shr(255, x)), add(sub(0, shr(255, x)), x))
}
}
/// @dev Returns the absolute distance between `x` and `y`.
function dist(int256 x, int256 y) internal pure returns (uint256 z) {
/// @solidity memory-safe-assembly
assembly {
z := xor(mul(xor(sub(y, x), sub(x, y)), sgt(x, y)), sub(y, x))
}
}
/// @dev Returns the minimum of `x` and `y`.
function min(uint256 x, uint256 y) internal pure returns (uint256 z) {
/// @solidity memory-safe-assembly
assembly {
z := xor(x, mul(xor(x, y), lt(y, x)))
}
}
/// @dev Returns the minimum of `x` and `y`.
function min(int256 x, int256 y) internal pure returns (int256 z) {
/// @solidity memory-safe-assembly
assembly {
z := xor(x, mul(xor(x, y), slt(y, x)))
}
}
/// @dev Returns the maximum of `x` and `y`.
function max(uint256 x, uint256 y) internal pure returns (uint256 z) {
/// @solidity memory-safe-assembly
assembly {
z := xor(x, mul(xor(x, y), gt(y, x)))
}
}
/// @dev Returns the maximum of `x` and `y`.
function max(int256 x, int256 y) internal pure returns (int256 z) {
/// @solidity memory-safe-assembly
assembly {
z := xor(x, mul(xor(x, y), sgt(y, x)))
}
}
/// @dev Returns `x`, bounded to `minValue` and `maxValue`.
function clamp(uint256 x, uint256 minValue, uint256 maxValue)
internal
pure
returns (uint256 z)
{
/// @solidity memory-safe-assembly
assembly {
z := xor(x, mul(xor(x, minValue), gt(minValue, x)))
z := xor(z, mul(xor(z, maxValue), lt(maxValue, z)))
}
}
/// @dev Returns `x`, bounded to `minValue` and `maxValue`.
function clamp(int256 x, int256 minValue, int256 maxValue) internal pure returns (int256 z) {
/// @solidity memory-safe-assembly
assembly {
z := xor(x, mul(xor(x, minValue), sgt(minValue, x)))
z := xor(z, mul(xor(z, maxValue), slt(maxValue, z)))
}
}
/// @dev Returns greatest common divisor of `x` and `y`.
function gcd(uint256 x, uint256 y) internal pure returns (uint256 z) {
/// @solidity memory-safe-assembly
assembly {
for { z := x } y {} {
let t := y
y := mod(z, y)
z := t
}
}
}
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
/* RAW NUMBER OPERATIONS */
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
/// @dev Returns `x + y`, without checking for overflow.
function rawAdd(uint256 x, uint256 y) internal pure returns (uint256 z) {
unchecked {
z = x + y;
}
}
/// @dev Returns `x + y`, without checking for overflow.
function rawAdd(int256 x, int256 y) internal pure returns (int256 z) {
unchecked {
z = x + y;
}
}
/// @dev Returns `x - y`, without checking for underflow.
function rawSub(uint256 x, uint256 y) internal pure returns (uint256 z) {
unchecked {
z = x - y;
}
}
/// @dev Returns `x - y`, without checking for underflow.
function rawSub(int256 x, int256 y) internal pure returns (int256 z) {
unchecked {
z = x - y;
}
}
/// @dev Returns `x * y`, without checking for overflow.
function rawMul(uint256 x, uint256 y) internal pure returns (uint256 z) {
unchecked {
z = x * y;
}
}
/// @dev Returns `x * y`, without checking for overflow.
function rawMul(int256 x, int256 y) internal pure returns (int256 z) {
unchecked {
z = x * y;
}
}
/// @dev Returns `x / y`, returning 0 if `y` is zero.
function rawDiv(uint256 x, uint256 y) internal pure returns (uint256 z) {
/// @solidity memory-safe-assembly
assembly {
z := div(x, y)
}
}
/// @dev Returns `x / y`, returning 0 if `y` is zero.
function rawSDiv(int256 x, int256 y) internal pure returns (int256 z) {
/// @solidity memory-safe-assembly
assembly {
z := sdiv(x, y)
}
}
/// @dev Returns `x % y`, returning 0 if `y` is zero.
function rawMod(uint256 x, uint256 y) internal pure returns (uint256 z) {
/// @solidity memory-safe-assembly
assembly {
z := mod(x, y)
}
}
/// @dev Returns `x % y`, returning 0 if `y` is zero.
function rawSMod(int256 x, int256 y) internal pure returns (int256 z) {
/// @solidity memory-safe-assembly
assembly {
z := smod(x, y)
}
}
/// @dev Returns `(x + y) % d`, return 0 if `d` if zero.
function rawAddMod(uint256 x, uint256 y, uint256 d) internal pure returns (uint256 z) {
/// @solidity memory-safe-assembly
assembly {
z := addmod(x, y, d)
}
}
/// @dev Returns `(x * y) % d`, return 0 if `d` if zero.
function rawMulMod(uint256 x, uint256 y, uint256 d) internal pure returns (uint256 z) {
/// @solidity memory-safe-assembly
assembly {
z := mulmod(x, y, d)
}
}
}{
"evmVersion": "paris",
"libraries": {},
"metadata": {
"bytecodeHash": "ipfs",
"useLiteralContent": true
},
"optimizer": {
"enabled": true,
"runs": 50
},
"remappings": [],
"outputSelection": {
"*": {
"*": [
"evm.bytecode",
"evm.deployedBytecode",
"devdoc",
"userdoc",
"metadata",
"abi"
]
}
}
}Contract Security Audit
- No Contract Security Audit Submitted- Submit Audit Here
Contract ABI
API[{"inputs":[{"internalType":"address","name":"protocolGovernor_","type":"address"},{"components":[{"internalType":"address","name":"interestRateStrategy","type":"address"},{"internalType":"address","name":"blastPointsOperator","type":"address"},{"internalType":"string","name":"debtTokenName","type":"string"},{"internalType":"string","name":"debtTokenSymbol","type":"string"},{"internalType":"string","name":"liquidityTokenName","type":"string"},{"internalType":"string","name":"liquidityTokenSymbol","type":"string"},{"internalType":"uint256","name":"minimumOpenBorrow","type":"uint256"},{"internalType":"bool","name":"isAutoCompounding","type":"bool"}],"internalType":"struct JuiceLendingPool.InitParams","name":"params","type":"tuple"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[{"internalType":"address","name":"target","type":"address"}],"name":"AddressEmptyCode","type":"error"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"AddressInsufficientBalance","type":"error"},{"inputs":[],"name":"ContractDoesNotExist","type":"error"},{"inputs":[],"name":"DepositCapExceeded","type":"error"},{"inputs":[],"name":"EnforcedPause","type":"error"},{"inputs":[],"name":"ExpectedPause","type":"error"},{"inputs":[],"name":"FailedInnerCall","type":"error"},{"inputs":[],"name":"InsufficientFlashLoanFeeAmount","type":"error"},{"inputs":[],"name":"InsufficientLiquidity","type":"error"},{"inputs":[],"name":"InvalidFlashLoanAsset","type":"error"},{"inputs":[],"name":"InvalidFlashLoanBalance","type":"error"},{"inputs":[],"name":"InvalidFlashLoanRecipientReturn","type":"error"},{"inputs":[],"name":"InvalidMinimumOpenBorrow","type":"error"},{"inputs":[],"name":"InvalidParams","type":"error"},{"inputs":[],"name":"InvalidPostFlashLoanBalance","type":"error"},{"inputs":[{"internalType":"uint256","name":"x","type":"uint256"},{"internalType":"uint256","name":"y","type":"uint256"}],"name":"PRBMath_MulDiv18_Overflow","type":"error"},{"inputs":[{"internalType":"uint256","name":"x","type":"uint256"},{"internalType":"uint256","name":"y","type":"uint256"},{"internalType":"uint256","name":"denominator","type":"uint256"}],"name":"PRBMath_MulDiv_Overflow","type":"error"},{"inputs":[{"internalType":"UD60x18","name":"x","type":"uint256"}],"name":"PRBMath_UD60x18_Exp2_InputTooBig","type":"error"},{"inputs":[{"internalType":"UD60x18","name":"x","type":"uint256"}],"name":"PRBMath_UD60x18_Exp_InputTooBig","type":"error"},{"inputs":[],"name":"ReentrancyGuardReentrantCall","type":"error"},{"inputs":[{"internalType":"address","name":"token","type":"address"}],"name":"SafeERC20FailedOperation","type":"error"},{"inputs":[{"internalType":"address","name":"account","type":"address"},{"internalType":"string","name":"role","type":"string"}],"name":"UnauthorizedRole","type":"error"},{"inputs":[],"name":"ZeroAddress","type":"error"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"borrower","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"Borrow","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"UD60x18","name":"index","type":"uint256"}],"name":"BorrowIndexUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"UD60x18","name":"rate","type":"uint256"}],"name":"BorrowRateUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"lender","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"Deposit","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"newDepositCap","type":"uint256"}],"name":"DepositCapUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"contract IERC20","name":"initiator","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"fee","type":"uint256"}],"name":"FlashLoan","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"recipient","type":"address"},{"indexed":false,"internalType":"uint256","name":"gasClaimed","type":"uint256"}],"name":"GasRefundClaimed","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"newStrategy","type":"address"}],"name":"InterestRateStrategyUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"UD60x18","name":"index","type":"uint256"}],"name":"LiquidityIndexUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"UD60x18","name":"rate","type":"uint256"}],"name":"LiquidityRateUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"newMinimumBorrow","type":"uint256"}],"name":"MinimumBorrowUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"account","type":"address"}],"name":"Paused","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"operator","type":"address"}],"name":"PointsOperatorConfigured","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"borrower","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"Repay","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"account","type":"address"}],"name":"Unpaused","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"lender","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"Withdraw","type":"event"},{"inputs":[],"name":"MINIMUM_COMPOUND_AMOUNT","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"accrueInterest","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"lender","type":"address"}],"name":"allowedLenders","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"address","name":"onBehalfOf","type":"address"}],"name":"borrow","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"claimMaxGas","outputs":[{"internalType":"uint256","name":"gasClaimed","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"compound","outputs":[{"internalType":"uint256","name":"earned","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"debtToken","outputs":[{"internalType":"contract OmegaDebtToken","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"deposit","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"depositCap","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"receiverAddress","type":"address"},{"internalType":"address","name":"asset","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"bytes","name":"userData","type":"bytes"}],"name":"flashLoanSimple","outputs":[{"internalType":"bytes","name":"","type":"bytes"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"getAsset","outputs":[{"internalType":"contract IERC20","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getBorrowRate","outputs":[{"internalType":"UD60x18","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"borrower","type":"address"}],"name":"getDebtAmount","outputs":[{"internalType":"uint256","name":"debt","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"lender","type":"address"}],"name":"getDepositAmount","outputs":[{"internalType":"uint256","name":"balance","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getLiquidityRate","outputs":[{"internalType":"UD60x18","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getMinimumOpenBorrow","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getNormalizedDebt","outputs":[{"internalType":"UD60x18","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getNormalizedIncome","outputs":[{"internalType":"UD60x18","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getProtocolGovernor","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getTotalBorrow","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getTotalSupply","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"isAutoCompounding","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"liquidityToken","outputs":[{"internalType":"contract OmegaLiquidityToken","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"pause","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"paused","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"address","name":"onBehalfOf","type":"address"}],"name":"repay","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"address","name":"onBehalfOf","type":"address"},{"internalType":"address","name":"from","type":"address"}],"name":"repay","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"reserve","outputs":[{"internalType":"contract IERC20","name":"asset","type":"address"},{"internalType":"uint256","name":"assetBalance","type":"uint256"},{"internalType":"UD60x18","name":"borrowRate","type":"uint256"},{"internalType":"UD60x18","name":"liquidityRate","type":"uint256"},{"internalType":"UD60x18","name":"liquidityIndex","type":"uint256"},{"internalType":"UD60x18","name":"borrowIndex","type":"uint256"},{"internalType":"uint256","name":"lastUpdateTimestamp","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"sendYield","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"newDepositCap","type":"uint256"}],"name":"setDepositCap","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newStrategy","type":"address"}],"name":"setInterestRateStrategy","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"minimumOpenBorrow","type":"uint256"}],"name":"setMinimumOpenBorrow","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"strategy","outputs":[{"internalType":"contract IInterestRateStrategy","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"toggleAutoCompounding","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"unpause","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"lender","type":"address"},{"internalType":"bool","name":"status","type":"bool"}],"name":"updateLenderStatus","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"withdraw","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"}]Contract Creation Code
60e0604052620f42406010553480156200001857600080fd5b5060405162006622380380620066228339810160408190526200003b91620008c6565b6020808201516040805160c0808201835285516001600160a01b0390811683528387015195830195909552606080870151938301939093526080808701519383019390935260a0808701518484015290860151908201526000805460ff191690559285169052600180558391829081908190620000b76200067e565b6001600160a01b038116620000df5760405163d92e233d60e01b815260040160405180910390fd5b81516001600160a01b038116620001095760405163d92e233d60e01b815260040160405180910390fd5b620001136200073e565b6001600160a01b0381166200013b5760405163d92e233d60e01b815260040160405180910390fd5b6040518060e00160405280620001566200067e60201b60201c565b6001600160a01b0390811682526000602080840182905260408085018390526060808601849052670de0b6b3a7640000608080880182905260a0808901929092524260c0988901528851600380546001600160a01b0319169190981690811790975588850151600490815589850151600555928901516006558801516007558701516008559590940151600955835163313ce56760e01b815293519194929363313ce5679381810193918290030181865afa1580156200021a573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019062000240919062000a09565b90506200024f81600a62000b4a565b600b819055503085602001518660400151836040516200026f9062000783565b6200027e949392919062000b89565b604051809103906000f0801580156200029b573d6000803e3d6000fd5b506001600160a01b031660a05260608501516080860151604051309291908490620002c69062000791565b620002d5949392919062000b89565b604051809103906000f080158015620002f2573d6000803e3d6000fd5b506001600160a01b0390811660c0528551600280546001600160a01b03191691831691909117905560a090950151600c555050600019600a5550839250508116620003505760405163d92e233d60e01b815260040160405180910390fd5b6001600160a01b0381163b6200037957604051630b0f2dd560e31b815260040160405180910390fd5b50600d80546001600160a01b039283166001600160a01b031991821617909155600e805492841692909116821790556040516000919063c824e15790620003dc9060200160208082526005908201526410931054d560da1b604082015260600190565b604051602081830303815290604052805190602001206040518263ffffffff1660e01b81526004016200041191815260200190565b602060405180830381865afa1580156200042f573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019062000455919062000bd8565b9050806001600160a01b0316634e606c476040518163ffffffff1660e01b8152600401600060405180830381600087803b1580156200049357600080fd5b505af1158015620004a8573d6000803e3d6000fd5b5050600f80546001600160a01b0388166001600160a01b031990911681179091556040516000955090935063c824e15792506200050991506020016020808252600c908201526b424c4153545f504f494e545360a01b604082015260600190565b604051602081830303815290604052805190602001206040518263ffffffff1660e01b81526004016200053e91815260200190565b602060405180830381865afa1580156200055c573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019062000582919062000bd8565b6040516336b91f2b60e01b81526001600160a01b038481166004830152919250908216906336b91f2b90602401600060405180830381600087803b158015620005ca57600080fd5b505af1158015620005df573d6000803e3d6000fd5b5050505060e08401516011805460ff19169115159190911790555050600354604051631a33757d60e01b81526001600160a01b039091169150631a33757d906200062f9060029060040162000bf6565b6020604051808303816000875af11580156200064f573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019062000675919062000c1f565b50505062000c39565b60006080516001600160a01b031663c824e157604051602001620006c0906020808252600a90820152691311539117d054d4d15560b21b604082015260600190565b604051602081830303815290604052805190602001206040518263ffffffff1660e01b8152600401620006f591815260200190565b602060405180830381865afa15801562000713573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019062000739919062000bd8565b905090565b60006080516001600160a01b03166321f8a721604051602001620006c0906020808252600d908201526c2322a2afa1a7a62622a1aa27a960991b604082015260600190565b61113a80620043ae83390190565b61113a80620054e883390190565b80516001600160a01b0381168114620007b757600080fd5b919050565b634e487b7160e01b600052604160045260246000fd5b60405161010081016001600160401b0381118282101715620007f857620007f8620007bc565b60405290565b60005b838110156200081b57818101518382015260200162000801565b50506000910152565b600082601f8301126200083657600080fd5b81516001600160401b0380821115620008535762000853620007bc565b604051601f8301601f19908116603f011681019082821181831017156200087e576200087e620007bc565b816040528381528660208588010111156200089857600080fd5b620008ab846020830160208901620007fe565b9695505050505050565b80518015158114620007b757600080fd5b60008060408385031215620008da57600080fd5b620008e5836200079f565b60208401519092506001600160401b03808211156200090357600080fd5b9084019061010082870312156200091957600080fd5b62000923620007d2565b6200092e836200079f565b81526200093e602084016200079f565b60208201526040830151828111156200095657600080fd5b620009648882860162000824565b6040830152506060830151828111156200097d57600080fd5b6200098b8882860162000824565b606083015250608083015182811115620009a457600080fd5b620009b28882860162000824565b60808301525060a083015182811115620009cb57600080fd5b620009d98882860162000824565b60a08301525060c083015160c0820152620009f760e08401620008b5565b60e08201528093505050509250929050565b60006020828403121562000a1c57600080fd5b815160ff8116811462000a2e57600080fd5b9392505050565b634e487b7160e01b600052601160045260246000fd5b600181815b8085111562000a8c57816000190482111562000a705762000a7062000a35565b8085161562000a7e57918102915b93841c939080029062000a50565b509250929050565b60008262000aa55750600162000b44565b8162000ab45750600062000b44565b816001811462000acd576002811462000ad85762000af8565b600191505062000b44565b60ff84111562000aec5762000aec62000a35565b50506001821b62000b44565b5060208310610133831016604e8410600b841016171562000b1d575081810a62000b44565b62000b29838362000a4b565b806000190482111562000b405762000b4062000a35565b0290505b92915050565b600062000a2e60ff84168362000a94565b6000815180845262000b75816020860160208601620007fe565b601f01601f19169290920160200192915050565b6001600160a01b038516815260806020820181905260009062000baf9083018662000b5b565b828103604084015262000bc3818662000b5b565b91505060ff8316606083015295945050505050565b60006020828403121562000beb57600080fd5b62000a2e826200079f565b602081016003831062000c1957634e487b7160e01b600052602160045260246000fd5b91905290565b60006020828403121562000c3257600080fd5b5051919050565b60805160a05160c0516136a462000d0a60003960008181610260015281816106a401528181610774015281816115c60152818161169d015281816116e501528181611c650152611d9f01526000818161049f01528181610ac901528181610e050152818161185b01528181611cf101528181612037015281816120f301526121a5015260008181610319015281816108720152818161092601528181610ea40152818161148101528181611783015281816118fe0152818161229f01528181612377015261264b01526136a46000f3fe608060405234801561001057600080fd5b50600436106101e75760003560e01c8063a6afed9511610110578063c883b2e5116100a8578063c883b2e5146103dc578063cbd00152146103ef578063cd3293de146103f7578063d8cab31814610461578063dbd5edc71461046e578063df6ce56014610477578063e37f8a7e1461048a578063f69e204614610492578063f8d898981461049a578063fd5668bf146104c157600080fd5b8063a6afed9514610350578063a8c62e7614610358578063acb708151461036b578063b2b8c93f1461037e578063b36d5e8b14610386578063b6b55f25146103a6578063b8ba16fd146103b9578063ba1c5e80146103cc578063c4e41b22146103d457600080fd5b80635c222bad116101835780635c222bad146102c75780635c975abb146102d85780636856728e146102e35780636a11d0b2146102eb5780638456cb59146102f457806386651203146102fc578063883c6b241461030f57806389dbb85714610317578063a612ce2b1461033d57600080fd5b80630ab30d8a146101ec5780632a5ad159146102075780632e1a7d4d1461021c578063366d8f3d1461022f5780633f4ba83a1461025357806343cd8f7e1461025b5780634b3fd1481461028f57806356d9e9a8146102a257806357bb1a62146102b5575b600080fd5b6101f46104c9565b6040519081526020015b60405180910390f35b61021a6102153660046130fa565b6104ff565b005b6101f461022a366004613117565b610684565b61024361023d3660046130fa565b50600090565b60405190151581526020016101fe565b61021a610851565b6102827f000000000000000000000000000000000000000000000000000000000000000081565b6040516101fe9190613130565b6101f461029d366004613144565b61086e565b61021a6102b0366004613117565b610bd5565b61021a6102c3366004613182565b5050565b6003546001600160a01b0316610282565b60005460ff16610243565b61021a610c81565b6101f460105481565b61021a610ca8565b61021a61030a366004613117565b610cc3565b6101f4610d11565b7f0000000000000000000000000000000000000000000000000000000000000000610282565b6101f461034b3660046130fa565b610deb565b61021a610e7b565b600254610282906001600160a01b031681565b6101f4610379366004613144565b610e8b565b6101f4610f4a565b61039961039436600461321d565b611161565b6040516101fe919061331b565b6101f46103b4366004613117565b61147d565b6101f46103c73660046130fa565b611683565b6005546101f4565b6101f46116d2565b6101f46103ea36600461332e565b61176a565b600c546101f4565b600354600454600554600654600754600854600954610422966001600160a01b031695949392919087565b604080516001600160a01b0390981688526020880196909652948601939093526060850191909152608084015260a083015260c082015260e0016101fe565b6011546102439060ff1681565b6101f4600a5481565b61021a610485366004613117565b611830565b6101f4611848565b6101f46118b7565b6102827f000000000000000000000000000000000000000000000000000000000000000081565b6006546101f4565b6009546000904281036104de57505060085490565b6008546005546104f991906104f390846118d4565b906118e1565b91505090565b806001600160a01b0381166105275760405163d92e233d60e01b815260040160405180910390fd5b610530336118f0565b61058457335b60408051637974da6f60e01b81526001600160a01b0390921660048301526024820152600e60448201526d282927aa27a1a7a62fa0a226a4a760911b60648201526084015b60405180910390fd5b600280546001600160a01b0319166001600160a01b0384169081179091556040516390d3b37960e01b81526706f05b59d3b20000600482015260009182916390d3b379906024016040805180830381865afa1580156105e7573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061060b9190613370565b915091506106198183101590565b1561063757604051635435b28960e11b815260040160405180910390fd5b61063f61199c565b610647611a65565b7f5a0a75b7511650dda977e2523dc8c695cb60b246d3a71314fa44e029e7453928846040516106769190613130565b60405180910390a150505050565b600061068e611b98565b610696611bbc565b8161069f611be6565b6000807f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03166370a08231336040518263ffffffff1660e01b81526004016106ee9190613130565b602060405180830381865afa15801561070b573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061072f9190613394565b905080851061074057809250600191505b826003600101600082825461075591906133c3565b90915550506007546040516313452f7360e01b81526001600160a01b037f000000000000000000000000000000000000000000000000000000000000000016916313452f73916107b191339188919088906000906004016133f8565b600060405180830381600087803b1580156107cb57600080fd5b505af11580156107df573d6000803e3d6000fd5b50506003546107fb92506001600160a01b031690503385611c04565b610803611c61565b61080b611a65565b60405183815233907f884edad9ce6fa2440d8a54cc123490eb96d2768479d49ff9c7366125a94243649060200160405180910390a250506001805592915050565b919050565b61085a336118f0565b6108645733610536565b61086c611e34565b565b60007f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316634295cbe76040518163ffffffff1660e01b8152600401602060405180830381865afa1580156108ce573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906108f2919061342b565b1561090f5760405162461bcd60e51b815260040161057b90613448565b610917611b98565b6040516311d8765360e31b81527f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031690638ec3b29890610963903390600401613130565b602060405180830381865afa158015610980573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906109a4919061342b565b6109f457335b60408051637974da6f60e01b81526001600160a01b0390921660048301526024820152600f60448201526e20a1a1a7aaa72a2fa6a0a720a3a2a960891b606482015260840161057b565b6109fc611bbc565b6003546040516370a0823160e01b81526001600160a01b03909116906370a0823190610a2c903090600401613130565b602060405180830381865afa158015610a49573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610a6d9190613394565b831115610a8d5760405163bb55fd2760e01b815260040160405180910390fd5b610a95611be6565b8260036001016000828254610aaa91906133c3565b9091555050600854604051630d6b960560e41b81526001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000169163d6b9605091610b04918691889190600090600401613475565b600060405180830381600087803b158015610b1e57600080fd5b505af1158015610b32573d6000803e3d6000fd5b5050600354610b4e92506001600160a01b031690508385611c04565b610b56611c61565b610b5e611a65565b600c54831015610b815760405163024f8afb60e51b815260040160405180910390fd5b816001600160a01b03167fcbc04eca7e9da35cb1393a6135a199ca52e450d5e9251cbd99f7847d33a3675084604051610bbc91815260200190565b60405180910390a25081610bcf60018055565b92915050565b610c5c33604051602001610c0e906020808252601190820152702622a7222faca4a2a6222fa9a2a72222a960791b604082015260600190565b60408051601f19818403018152828252805160209182012083830190925260118352702622a7222faca4a2a6222fa9a2a72222a960791b90830152600d546001600160a01b03169291611e80565b600454600354610c77906001600160a01b0316333085611f18565b6102c38183611f51565b610c8a336118f0565b610c945733610536565b6011805460ff19811660ff90911615179055565b610cb1336118f0565b610cbb5733610536565b61086c611fbc565b610ccc336118f0565b610cd65733610536565b600a8190556040518181527f333b26cca69716ad4680ddb07663f5bfb4f06045671f336af9a83690a3ae00f99060200160405180910390a150565b600954600090428103610d2657505060075490565b60035460405163e12f3a6160e01b81526000916001600160a01b03169063e12f3a6190610d57903090600401613130565b602060405180830381865afa158015610d74573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610d989190613394565b90506000610dc6610dab60036001015490565b600454610dc090610dbd9086906134a9565b90565b90611ff9565b9050610de3816104f36003600401546104f36003800154886118d4565b935050505090565b6040516370a0823160e01b81526000906001600160a01b037f000000000000000000000000000000000000000000000000000000000000000016906370a0823190610e3a908590600401613130565b602060405180830381865afa158015610e57573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610bcf9190613394565b610e8361199c565b61086c611a65565b6000610e95611b98565b6040516311d8765360e31b81527f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031690638ec3b29890610ee1903390600401613130565b602060405180830381865afa158015610efe573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610f22919061342b565b610f2c57336109aa565b610f34611bbc565b610f3f838384612011565b9050610bcf60018055565b600e5460405160009182916001600160a01b039091169063c824e15790610f8d9060200160208082526005908201526410931054d560da1b604082015260600190565b604051602081830303815290604052805190602001206040518263ffffffff1660e01b8152600401610fc191815260200190565b602060405180830381865afa158015610fde573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061100291906134bc565b600e546040519192506000916001600160a01b03909116906321f8a7219061102c906020016134d9565b604051602081830303815290604052805190602001206040518263ffffffff1660e01b815260040161106091815260200190565b602060405180830381865afa15801561107d573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906110a191906134bc565b60405163662aa11d60e01b81523060048201526001600160a01b0380831660248301529192509083169063662aa11d906044016020604051808303816000875af11580156110f3573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906111179190613394565b9250806001600160a01b03167f9c3c39d0eedd3d18612a0e8e76cc7bc873815d3e19206dbbf9825989b1c95e6b8460405161115491815260200190565b60405180910390a2505090565b6060846001600160a01b03811661118b5760405163d92e233d60e01b815260040160405180910390fd5b611193611b98565b61119b611bbc565b6003546001600160a01b038681169116146111c957604051633c4edfcd60e21b815260040160405180910390fd5b6003546040516370a0823160e01b81526000916001600160a01b0316906370a08231906111fa903090600401613130565b602060405180830381865afa158015611217573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061123b9190613394565b90506000611253610dbd61124d61229b565b886104f3565b90508186111561127657604051633ee39f9d60e01b815260040160405180910390fd5b60035461128d906001600160a01b03168988611c04565b60035460405163feea07eb60e01b815260009182916001600160a01b03808d169263feea07eb926112ca92339216908d9089908e90600401613500565b6000604051808303816000875af11580156112e9573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f19168201604052611311919081019061353a565b91509150816113335760405163a155965d60e01b815260040160405180910390fd5b6003546040516370a0823160e01b81526000916001600160a01b0316906370a0823190611364903090600401613130565b602060405180830381865afa158015611381573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906113a59190613394565b9050808511156113c8576040516323c758a760e11b815260040160405180910390fd5b60006113d486836133c3565b9050808511156113f757604051636174404560e01b815260040160405180910390fd5b801561141b5761141b611408612373565b6003546001600160a01b03169083611c04565b600354604080518c8152602081018490526001600160a01b03909216917f31aaad38f00845a242d16ae90d7bd72fc68f0e22581470f9dc0de241210c2886910160405180910390a2509095505050505061147460018055565b50949350505050565b60007f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316634295cbe76040518163ffffffff1660e01b8152600401602060405180830381865afa1580156114dd573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611501919061342b565b1561151e5760405162461bcd60e51b815260040161057b90613448565b611526611b98565b61152e611bbc565b600019600a54141580156115545750600a546115486116d2565b61155290846134a9565b115b15611572576040516324d758c360e21b815260040160405180910390fd5b61157a611be6565b816003600101600082825461158f91906134a9565b90915550506003546115ac906001600160a01b0316333085611f18565b600754604051630d6b960560e41b81526001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000169163d6b9605091611601913391879190600190600401613475565b600060405180830381600087803b15801561161b57600080fd5b505af115801561162f573d6000803e3d6000fd5b5050505061163b611c61565b611643611a65565b60405182815233907fe1fffcc4923d04b559f4d29a8bfc6cda04eb5b0d3c460751c2402c5c5cc9109c9060200160405180910390a2508061084c60018055565b6040516370a0823160e01b81526000906001600160a01b037f000000000000000000000000000000000000000000000000000000000000000016906370a0823190610e3a908590600401613130565b6000611765610dbd6003600401546104f37f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663b1bf962d6040518163ffffffff1660e01b8152600401602060405180830381865afa158015611741573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610dbd9190613394565b905090565b6000611774611b98565b6040516311d8765360e31b81527f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031690638ec3b298906117c0903390600401613130565b602060405180830381865afa1580156117dd573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611801919061342b565b61180b57336109aa565b611813611bbc565b61181e848484612011565b905061182960018055565b9392505050565b611839336118f0565b6118435733610536565b600c55565b6000611765610dbd6003600501546104f37f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663b1bf962d6040518163ffffffff1660e01b8152600401602060405180830381865afa158015611741573d6000803e3d6000fd5b60006118c1611bbc565b6118c9612428565b9050610dbd60018055565b600061182983834261252e565b6000611829610dbd8484612591565b6000816001600160a01b03167f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663893d20e86040518163ffffffff1660e01b8152600401602060405180830381865afa15801561195a573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061197e91906134bc565b6001600160a01b03161461199457506000919050565b506001919050565b60065415611a5f576006546009546000916119b6916118d4565b6007549091506119c79082906118e1565b6007556005546009546000916119dc916118d4565b6008549091506119ed9082906118e1565b6008556007546040519081527f98c7d87cc1242fd0802e2cc1c048bab3a03309350b0e8af0c06f6110b7aa16869060200160405180910390a16008546040519081527f3d78dc9bb9d0a317106d49b366e60f1b7995cfc4df04348c4ffe939f4540b5ae9060200160405180910390a150505b42600955565b6000611a6f611848565b60045490915060008215611a9657611a93611a8d610dbd85856134a9565b84610dc0565b90505b6002546040516390d3b37960e01b8152600481018390526000916001600160a01b0316906390d3b379906024016040805180830381865afa158015611adf573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611b039190613370565b6005559050611b2c611b25611b16612647565b670de0b6b3a7640000906126a7565b82906118e1565b6006556005546040519081527f578adda73f5b431118629e4fc78f890d645ad2613a5260bddc23fa48065b940a9060200160405180910390a16006546040519081527fbaa019247a3ef5fbd10fa058e87b444fe8cd8f5d48494dc3e5756e509a34134990602001610676565b60005460ff161561086c5760405163d93c066560e01b815260040160405180910390fd5b600260015403611bdf57604051633ee5aeb560e01b815260040160405180910390fd5b6002600155565b611bee61199c565b60115460ff161561086c57611c01612428565b50565b611c5c83846001600160a01b031663a9059cbb8585604051602401611c2a9291906135c6565b604051602081830303815290604052915060e01b6020820180516001600160e01b0383818316178352505050506126b6565b505050565b60007f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03166318160ddd6040518163ffffffff1660e01b8152600401602060405180830381865afa158015611cc1573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611ce59190613394565b905060006003600101547f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03166318160ddd6040518163ffffffff1660e01b8152600401602060405180830381865afa158015611d4d573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611d719190613394565b611d7b91906134a9565b9050818111156102c3576000611d9183836133c3565b9050600b54811115611c5c577f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663d6b96050611dd4612373565b6007546040516001600160e01b031960e085901b168152611dfd92918691600190600401613475565b600060405180830381600087803b158015611e1757600080fd5b505af1158015611e2b573d6000803e3d6000fd5b50505050505050565b611e3c612710565b6000805460ff191690557f5db9ee0a495bf2e6ff9c91a7834c1ba4fdd244a5e8aa4e537bd38aeae4b073aa335b604051611e769190613130565b60405180910390a1565b604051632474521560e21b8152600481018390526001600160a01b0384811660248301528516906391d1485490604401602060405180830381865afa158015611ecd573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611ef1919061342b565b611f12578281604051637974da6f60e01b815260040161057b9291906135df565b50505050565b6040516001600160a01b038481166024830152838116604483015260648201839052611f129186918216906323b872dd90608401611c2a565b8060036001016000828254611f6691906134a9565b90915550611f80905082600754600454610dc091906104f3565b60078190556040519081527f98c7d87cc1242fd0802e2cc1c048bab3a03309350b0e8af0c06f6110b7aa16869060200160405180910390a15050565b611fc4611b98565b6000805460ff191660011790557f62e78cea01bee320cd4e420270b5ea74000d11b0c9f74754ebdbfc544b05a258611e693390565b6000611829610dbd84670de0b6b3a764000085612733565b600061201b611be6565b6040516370a0823160e01b815284906000906001600160a01b037f000000000000000000000000000000000000000000000000000000000000000016906370a082319061206c908890600401613130565b602060405180830381865afa158015612089573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906120ad9190613394565b905060008183106120bf575090508060015b82600360010160008282546120d491906134a9565b90915550506008546040516313452f7360e01b81526001600160a01b037f000000000000000000000000000000000000000000000000000000000000000016916313452f7391612130918a9188919087906001906004016133f8565b600060405180830381600087803b15801561214a57600080fd5b505af115801561215e573d6000803e3d6000fd5b505060035461217b92506001600160a01b03169050863086611f18565b612183611c61565b61218b611a65565b6040516370a0823160e01b81526000906001600160a01b037f000000000000000000000000000000000000000000000000000000000000000016906370a08231906121da908a90600401613130565b602060405180830381865afa1580156121f7573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061221b9190613394565b905060008111801561222e5750600c5481105b1561224c5760405163024f8afb60e51b815260040160405180910390fd5b866001600160a01b03167f5c16de4f8b59bd9caf0f49a545f25819a895ed223294290b408242e72a5942318560405161228791815260200190565b60405180910390a250919695505050505050565b60007f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663e5f3d3a56040516020016122fe906020808252600e908201526d464c4153485f4c4f414e5f46454560901b604082015260600190565b604051602081830303815290604052805190602001206040518263ffffffff1660e01b815260040161233291815260200190565b602060405180830381865afa15801561234f573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906117659190613394565b60007f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03166321f8a7216040516020016123b3906134d9565b604051602081830303815290604052805190602001206040518263ffffffff1660e01b81526004016123e791815260200190565b602060405180830381865afa158015612404573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061176591906134bc565b60035460405163e12f3a6160e01b81526000916001600160a01b031690819063e12f3a619061245b903090600401613130565b602060405180830381865afa158015612478573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061249c9190613394565b9150601054821061252a5760048054604051635569f64b60e11b815290916001600160a01b0384169163aad3ec96916124d99130918891016135c6565b6020604051808303816000875af11580156124f8573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061251c9190613394565b92506125288184611f51565b505b5090565b6000670de0b6b3a76400008161254485856133c3565b90508060000361255657509050611829565b60006301e133806125678884613603565b6125719190613630565b905061258661257f82612807565b84906118e1565b979650505050505050565b60008080600019848609848602925082811083820303915050806000036125c55750670de0b6b3a764000090049050610bcf565b670de0b6b3a764000081106125f757604051635173648d60e01b8152600481018690526024810185905260440161057b565b6000670de0b6b3a764000085870962040000818503049310909103600160ee1b02919091177faccb18165bd6fe31ae1cf318dc5b51eee0e1ba569b88cd74c1773b91fac106690291505092915050565b60007f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663e5f3d3a56040516020016122fe906020808252600b908201526a4c454e44494e475f46454560a81b604082015260600190565b6000611829610dbd83856133c3565b60006126cb6001600160a01b0384168361285d565b905080516000141580156126f05750808060200190518101906126ee919061342b565b155b15611c5c5782604051635274afe760e01b815260040161057b9190613130565b60005460ff1661086c57604051638dfc202b60e01b815260040160405180910390fd5b600080806000198587098587029250828110838203039150508060000361276d578382816127635761276361361a565b0492505050611829565b83811061279e57604051630c740aef60e31b815260048101879052602481018690526044810185905260640161057b565b60008486880960026001871981018816978890046003810283188082028403028082028403028082028403028082028403028082028403029081029092039091026000889003889004909101858311909403939093029303949094049190911702949350505050565b600081680736ea4425c11ac63081111561283757604051630d7b1d6560e11b81526004810184905260240161057b565b6714057b7ef767814f8102612855670de0b6b3a7640000820461286b565b949350505050565b6060611829838360006128c1565b600081680a688906bd8affffff81111561289b5760405163b3b6ba1f60e01b81526004810184905260240161057b565b60006128b3670de0b6b3a7640000604084901b613630565b9050612855610dbd8261295e565b6060814710156128e6573060405163cd78605960e01b815260040161057b9190613130565b600080856001600160a01b031684866040516129029190613652565b60006040518083038185875af1925050503d806000811461293f576040519150601f19603f3d011682016040523d82523d6000602084013e612944565b606091505b5091509150612954868383613069565b9695505050505050565b600160bf1b60ff60381b821615612a47576001603f1b82161561298a5768016a09e667f3bcc9090260401c5b6001603e1b8216156129a5576801306fe0a31b7152df0260401c5b6001603d1b8216156129c0576801172b83c7d517adce0260401c5b6001603c1b8216156129db5768010b5586cf9890f62a0260401c5b6001603b1b8216156129f6576801059b0d31585743ae0260401c5b6001603a1b821615612a1157680102c9a3e778060ee70260401c5b600160391b821615612a2c5768010163da9fb33356d80260401c5b600160381b821615612a4757680100b1afa5abcbed610260401c5b60ff60301b821615612b2b57600160371b821615612a6e5768010058c86da1c09ea20260401c5b600160361b821615612a89576801002c605e2e8cec500260401c5b600160351b821615612aa457680100162f3904051fa10260401c5b600160341b821615612abf576801000b175effdc76ba0260401c5b600160331b821615612ada57680100058ba01fb9f96d0260401c5b600160321b821615612af55768010002c5cc37da94920260401c5b600160311b821615612b10576801000162e525ee05470260401c5b600160301b821615612b2b5768010000b17255775c040260401c5b60ff60281b821615612c0f576001602f1b821615612b52576801000058b91b5bc9ae0260401c5b6001602e1b821615612b6d57680100002c5c89d5ec6d0260401c5b6001602d1b821615612b885768010000162e43f4f8310260401c5b6001602c1b821615612ba357680100000b1721bcfc9a0260401c5b6001602b1b821615612bbe5768010000058b90cf1e6e0260401c5b6001602a1b821615612bd9576801000002c5c863b73f0260401c5b600160291b821615612bf457680100000162e430e5a20260401c5b600160281b821615612c0f576801000000b1721835510260401c5b64ff00000000821615612cfc57648000000000821615612c3857680100000058b90c0b490260401c5b644000000000821615612c545768010000002c5c8601cc0260401c5b642000000000821615612c70576801000000162e42fff00260401c5b641000000000821615612c8c5768010000000b17217fbb0260401c5b640800000000821615612ca8576801000000058b90bfce0260401c5b640400000000821615612cc457680100000002c5c85fe30260401c5b640200000000821615612ce05768010000000162e42ff10260401c5b640100000000821615612cfc57680100000000b17217f80260401c5b63ff000000821615612de0576380000000821615612d235768010000000058b90bfc0260401c5b6340000000821615612d3e576801000000002c5c85fe0260401c5b6320000000821615612d5957680100000000162e42ff0260401c5b6310000000821615612d74576801000000000b17217f0260401c5b6308000000821615612d8f57680100000000058b90c00260401c5b6304000000821615612daa5768010000000002c5c8600260401c5b6302000000821615612dc5576801000000000162e4300260401c5b6301000000821615612de05768010000000000b172180260401c5b62ff0000821615612ebb5762800000821615612e05576801000000000058b90c0260401c5b62400000821615612e1f57680100000000002c5c860260401c5b62200000821615612e395768010000000000162e430260401c5b62100000821615612e5357680100000000000b17210260401c5b62080000821615612e6d5768010000000000058b910260401c5b62040000821615612e87576801000000000002c5c80260401c5b62020000821615612ea157680100000000000162e40260401c5b62010000821615612ebb576801000000000000b1720260401c5b61ff00821615612f8d57618000821615612ede57680100000000000058b90260401c5b614000821615612ef75768010000000000002c5d0260401c5b612000821615612f10576801000000000000162e0260401c5b611000821615612f295768010000000000000b170260401c5b610800821615612f42576801000000000000058c0260401c5b610400821615612f5b57680100000000000002c60260401c5b610200821615612f7457680100000000000001630260401c5b610100821615612f8d57680100000000000000b10260401c5b60ff821615613052576080821615612fae57680100000000000000590260401c5b6040821615612fc6576801000000000000002c0260401c5b6020821615612fde57680100000000000000160260401c5b6010821615612ff6576801000000000000000b0260401c5b600882161561300e57680100000000000000060260401c5b600482161561302657680100000000000000030260401c5b600282161561303c576001600160401b010260401c5b6001821615613052576001600160401b010260401c5b670de0b6b3a76400000260409190911c60bf031c90565b60608261307e57613079826130bc565b611829565b815115801561309557506001600160a01b0384163b155b156130b55783604051639996b31560e01b815260040161057b9190613130565b5080611829565b8051156130cc5780518082602001fd5b604051630a12f52160e11b815260040160405180910390fd5b6001600160a01b0381168114611c0157600080fd5b60006020828403121561310c57600080fd5b8135611829816130e5565b60006020828403121561312957600080fd5b5035919050565b6001600160a01b0391909116815260200190565b6000806040838503121561315757600080fd5b823591506020830135613169816130e5565b809150509250929050565b8015158114611c0157600080fd5b6000806040838503121561319557600080fd5b82356131a0816130e5565b9150602083013561316981613174565b634e487b7160e01b600052604160045260246000fd5b604051601f8201601f191681016001600160401b03811182821017156131ee576131ee6131b0565b604052919050565b60006001600160401b0382111561320f5761320f6131b0565b50601f01601f191660200190565b6000806000806080858703121561323357600080fd5b843561323e816130e5565b9350602085013561324e816130e5565b92506040850135915060608501356001600160401b0381111561327057600080fd5b8501601f8101871361328157600080fd5b803561329461328f826131f6565b6131c6565b8181528860208385010111156132a957600080fd5b8160208401602083013760006020838301015280935050505092959194509250565b60005b838110156132e65781810151838201526020016132ce565b50506000910152565b600081518084526133078160208601602086016132cb565b601f01601f19169290920160200192915050565b60208152600061182960208301846132ef565b60008060006060848603121561334357600080fd5b833592506020840135613355816130e5565b91506040840135613365816130e5565b809150509250925092565b6000806040838503121561338357600080fd5b505080516020909101519092909150565b6000602082840312156133a657600080fd5b5051919050565b634e487b7160e01b600052601160045260246000fd5b81810381811115610bcf57610bcf6133ad565b600281106133f457634e487b7160e01b600052602160045260246000fd5b9052565b6001600160a01b03861681526020810185905260408101849052821515606082015260a0810161295460808301846133d6565b60006020828403121561343d57600080fd5b815161182981613174565b602080825260139082015272141493d513d0d3d317d11154149150d0551151606a1b604082015260600190565b6001600160a01b03851681526020810184905260408101839052608081016134a060608301846133d6565b95945050505050565b80820180821115610bcf57610bcf6133ad565b6000602082840312156134ce57600080fd5b8151611829816130e5565b6020808252600d908201526c2322a2afa1a7a62622a1aa27a960991b604082015260600190565b6001600160a01b03868116825285166020820152604081018490526060810183905260a060808201819052600090612586908301846132ef565b6000806040838503121561354d57600080fd5b825161355881613174565b60208401519092506001600160401b0381111561357457600080fd5b8301601f8101851361358557600080fd5b805161359361328f826131f6565b8181528660208385010111156135a857600080fd5b6135b98260208301602086016132cb565b8093505050509250929050565b6001600160a01b03929092168252602082015260400190565b6001600160a01b0383168152604060208201819052600090612855908301846132ef565b8082028115828204841417610bcf57610bcf6133ad565b634e487b7160e01b600052601260045260246000fd5b60008261364d57634e487b7160e01b600052601260045260246000fd5b500490565b600082516136648184602087016132cb565b919091019291505056fea26469706673582212209b7c00e846267f90bef20f6209406950dce2ee6a1de500fafba4078aec8d893364736f6c6343000818003360c06040523480156200001157600080fd5b506040516200113a3803806200113a833981016040819052620000349162000197565b83818484836001600160a01b038116620000615760405163d92e233d60e01b815260040160405180910390fd5b6001600160a01b03851660805260ff841660a0526000620000838482620002cc565b506001620000928382620002cc565b50889450506001600160a01b0384169250620000c49150505760405163d92e233d60e01b815260040160405180910390fd5b505050505062000398565b634e487b7160e01b600052604160045260246000fd5b600082601f830112620000f757600080fd5b81516001600160401b0380821115620001145762000114620000cf565b604051601f8301601f19908116603f011681019082821181831017156200013f576200013f620000cf565b81604052838152602092508660208588010111156200015d57600080fd5b600091505b8382101562000181578582018301518183018401529082019062000162565b6000602085830101528094505050505092915050565b60008060008060808587031215620001ae57600080fd5b84516001600160a01b0381168114620001c657600080fd5b60208601519094506001600160401b0380821115620001e457600080fd5b620001f288838901620000e5565b945060408701519150808211156200020957600080fd5b506200021887828801620000e5565b925050606085015160ff811681146200023057600080fd5b939692955090935050565b600181811c908216806200025057607f821691505b6020821081036200027157634e487b7160e01b600052602260045260246000fd5b50919050565b601f821115620002c7576000816000526020600020601f850160051c81016020861015620002a25750805b601f850160051c820191505b81811015620002c357828155600101620002ae565b5050505b505050565b81516001600160401b03811115620002e857620002e8620000cf565b6200030081620002f984546200023b565b8462000277565b602080601f8311600181146200033857600084156200031f5750858301515b600019600386901b1c1916600185901b178555620002c3565b600085815260208120601f198616915b82811015620003695788860151825594840194600190910190840162000348565b5085821015620003885787850151600019600388901b60f8161c191681555b5050505050600190811b01905550565b60805160a051610d67620003d3600039600061017e015260008181610347015281816103c70152818161054001526107830152610d676000f3fe608060405234801561001057600080fd5b50600436106100e05760003560e01c806370a082311161008757806370a08231146101b05780637ecebe00146101c357806395d89b41146101e9578063a9059cbb146101f1578063b1bf962d146101ff578063d505accf14610207578063d6b960501461021a578063dd62ed3e1461022d57600080fd5b806306fdde03146100e5578063095ea7b31461010357806313452f731461012657806318160ddd1461013b5780631da24f3e1461015157806323b872dd14610164578063313ce567146101775780633644e515146101a8575b600080fd5b6100ed610256565b6040516100fa9190610a83565b60405180910390f35b610116610111366004610aee565b6102e8565b60405190151581526020016100fa565b610139610134366004610b27565b61033c565b005b6101436103bd565b6040519081526020016100fa565b61014361015f366004610b85565b610460565b610116610172366004610ba0565b61047a565b60405160ff7f00000000000000000000000000000000000000000000000000000000000000001681526020016100fa565b610143610495565b6101436101be366004610b85565b610512565b6101436101d1366004610b85565b6338377508600c908152600091909152602090205490565b6100ed6105cd565b610116610172366004610aee565b6101436105dc565b610139610215366004610bdc565b6105ef565b610139610228366004610c4f565b610778565b61014361023b366004610c95565b602052637f5e9f20600c908152600091909152603490205490565b60606000805461026590610cc8565b80601f016020809104026020016040519081016040528092919081815260200182805461029190610cc8565b80156102de5780601f106102b3576101008083540402835291602001916102de565b820191906000526020600020905b8154815290600101906020018083116102c157829003601f168201915b5050505050905090565b600082602052637f5e9f20600c5233600052816034600c205581600052602c5160601c337f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b92560206000a35060015b92915050565b336001600160a01b037f00000000000000000000000000000000000000000000000000000000000000001614610385576040516323f09b3960e21b815260040160405180910390fd5b6000821561039d5761039686610460565b90506103ab565b6103a88585846107e1565b90505b6103b5868261081e565b505050505050565b600061045b6104527f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316630ab30d8a6040518163ffffffff1660e01b8152600401602060405180830381865afa158015610423573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906104479190610d02565b6104556104526105dc565b90565b90610895565b905090565b6387a211a2600c9081526000828152602090912054610336565b600060405163a24e573d60e01b815260040160405180910390fd5b6000806104a0610256565b8051906020012090506040517f8b73c3c69bb8fe3d512ecc4cf759cc79239f7b179b0ffacaa9a75d522b39400f81528160208201527fc89efdaa54c0f20c7adf612882df0950f5a951637e0307cdcb4c672f298b8bc6604082015246606082015230608082015260a081209250505090565b6387a211a2600c9081526000828152602090912054806000036105385750600092915050565b6105c66104527f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316630ab30d8a6040518163ffffffff1660e01b8152600401602060405180830381865afa15801561059c573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906105c09190610d02565b83610455565b9392505050565b60606001805461026590610cc8565b600061045b6805345cdf77eb68f44c5490565b60006105f9610256565b8051906020012090508442111561061857631a15a3cc6000526004601cfd5b6040518860601b60601c98508760601b60601c975065383775081901600e52886000526020600c2080547f8b73c3c69bb8fe3d512ecc4cf759cc79239f7b179b0ffacaa9a75d522b39400f83528360208401527fc89efdaa54c0f20c7adf612882df0950f5a951637e0307cdcb4c672f298b8bc6604084015246606084015230608084015260a08320602e527f6e71edae12b1b97f4d1f60370fef10105fa2faae0126114a169c64845d6126c983528a60208401528960408401528860608401528060808401528760a084015260c08320604e526042602c206000528660ff1660205285604052846060526020806080600060015afa8b3d51146107245763ddafbaef6000526004601cfd5b0190556303faf4f960a51b88176040526034602c2087905587897f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925602060608501a360405250506000606052505050505050565b336001600160a01b037f000000000000000000000000000000000000000000000000000000000000000016146107c1576040516323f09b3960e21b815260040160405180910390fd5b60006107ce8484846107e1565b90506107da85826108a4565b5050505050565b600082818360018111156107f7576107f7610d1b565b1461080b576108068582610923565b610815565b6108158582610972565b95945050505050565b6387a211a2600c52816000526020600c208054808311156108475763f4d678b86000526004601cfd5b82900390556805345cdf77eb68f44c8054829003905560008181526001600160a01b0383167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef602083a35050565b60006105c661045284846109c9565b6805345cdf77eb68f44c54818101818110156108c85763e5cfe9576000526004601cfd5b806805345cdf77eb68f44c5550506387a211a2600c52816000526020600c208181540181555080602052600c5160601c60007fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef602080a35050565b60007812725dd1d243aba0e75fe645cc4873f9e65afe688c928e1f218311670de0b6b3a76400000215820261096057637c5f487d6000526004601cfd5b50670de0b6b3a7640000919091020490565b60007812725dd1d243aba0e75fe645cc4873f9e65afe688c928e1f218311670de0b6b3a7640000021582026109af57637c5f487d6000526004601cfd5b50670de0b6b3a76400009190910281810615159190040190565b60008080600019848609848602925082811083820303915050806000036109fd5750670de0b6b3a764000090049050610336565b670de0b6b3a76400008110610a3357604051635173648d60e01b8152600481018690526024810185905260440160405180910390fd5b6000670de0b6b3a764000085870962040000818503049310909103600160ee1b02919091177faccb18165bd6fe31ae1cf318dc5b51eee0e1ba569b88cd74c1773b91fac106690291505092915050565b60006020808352835180602085015260005b81811015610ab157858101830151858201604001528201610a95565b506000604082860101526040601f19601f8301168501019250505092915050565b80356001600160a01b0381168114610ae957600080fd5b919050565b60008060408385031215610b0157600080fd5b610b0a83610ad2565b946020939093013593505050565b803560028110610ae957600080fd5b600080600080600060a08688031215610b3f57600080fd5b610b4886610ad2565b9450602086013593506040860135925060608601358015158114610b6b57600080fd5b9150610b7960808701610b18565b90509295509295909350565b600060208284031215610b9757600080fd5b6105c682610ad2565b600080600060608486031215610bb557600080fd5b610bbe84610ad2565b9250610bcc60208501610ad2565b9150604084013590509250925092565b600080600080600080600060e0888a031215610bf757600080fd5b610c0088610ad2565b9650610c0e60208901610ad2565b95506040880135945060608801359350608088013560ff81168114610c3257600080fd5b9699959850939692959460a0840135945060c09093013592915050565b60008060008060808587031215610c6557600080fd5b610c6e85610ad2565b93506020850135925060408501359150610c8a60608601610b18565b905092959194509250565b60008060408385031215610ca857600080fd5b610cb183610ad2565b9150610cbf60208401610ad2565b90509250929050565b600181811c90821680610cdc57607f821691505b602082108103610cfc57634e487b7160e01b600052602260045260246000fd5b50919050565b600060208284031215610d1457600080fd5b5051919050565b634e487b7160e01b600052602160045260246000fdfea26469706673582212208709bb7fa22a166cc73be0879e5e5c4acd95dab067eef24b9169a46460ad441064736f6c6343000818003360c06040523480156200001157600080fd5b506040516200113a3803806200113a833981016040819052620000349162000197565b83818484836001600160a01b038116620000615760405163d92e233d60e01b815260040160405180910390fd5b6001600160a01b03851660805260ff841660a0526000620000838482620002cc565b506001620000928382620002cc565b50889450506001600160a01b0384169250620000c49150505760405163d92e233d60e01b815260040160405180910390fd5b505050505062000398565b634e487b7160e01b600052604160045260246000fd5b600082601f830112620000f757600080fd5b81516001600160401b0380821115620001145762000114620000cf565b604051601f8301601f19908116603f011681019082821181831017156200013f576200013f620000cf565b81604052838152602092508660208588010111156200015d57600080fd5b600091505b8382101562000181578582018301518183018401529082019062000162565b6000602085830101528094505050505092915050565b60008060008060808587031215620001ae57600080fd5b84516001600160a01b0381168114620001c657600080fd5b60208601519094506001600160401b0380821115620001e457600080fd5b620001f288838901620000e5565b945060408701519150808211156200020957600080fd5b506200021887828801620000e5565b925050606085015160ff811681146200023057600080fd5b939692955090935050565b600181811c908216806200025057607f821691505b6020821081036200027157634e487b7160e01b600052602260045260246000fd5b50919050565b601f821115620002c7576000816000526020600020601f850160051c81016020861015620002a25750805b601f850160051c820191505b81811015620002c357828155600101620002ae565b5050505b505050565b81516001600160401b03811115620002e857620002e8620000cf565b6200030081620002f984546200023b565b8462000277565b602080601f8311600181146200033857600084156200031f5750858301515b600019600386901b1c1916600185901b178555620002c3565b600085815260208120601f198616915b82811015620003695788860151825594840194600190910190840162000348565b5085821015620003885787850151600019600388901b60f8161c191681555b5050505050600190811b01905550565b60805160a051610d67620003d3600039600061017e015260008181610347015281816103c70152818161054001526107830152610d676000f3fe608060405234801561001057600080fd5b50600436106100e05760003560e01c806370a082311161008757806370a08231146101b05780637ecebe00146101c357806395d89b41146101e9578063a9059cbb146101f1578063b1bf962d146101ff578063d505accf14610207578063d6b960501461021a578063dd62ed3e1461022d57600080fd5b806306fdde03146100e5578063095ea7b31461010357806313452f731461012657806318160ddd1461013b5780631da24f3e1461015157806323b872dd14610164578063313ce567146101775780633644e515146101a8575b600080fd5b6100ed610256565b6040516100fa9190610a83565b60405180910390f35b610116610111366004610aee565b6102e8565b60405190151581526020016100fa565b610139610134366004610b27565b61033c565b005b6101436103bd565b6040519081526020016100fa565b61014361015f366004610b85565b610460565b610116610172366004610ba0565b61047a565b60405160ff7f00000000000000000000000000000000000000000000000000000000000000001681526020016100fa565b610143610495565b6101436101be366004610b85565b610512565b6101436101d1366004610b85565b6338377508600c908152600091909152602090205490565b6100ed6105cd565b610116610172366004610aee565b6101436105dc565b610139610215366004610bdc565b6105ef565b610139610228366004610c4f565b610778565b61014361023b366004610c95565b602052637f5e9f20600c908152600091909152603490205490565b60606000805461026590610cc8565b80601f016020809104026020016040519081016040528092919081815260200182805461029190610cc8565b80156102de5780601f106102b3576101008083540402835291602001916102de565b820191906000526020600020905b8154815290600101906020018083116102c157829003601f168201915b5050505050905090565b600082602052637f5e9f20600c5233600052816034600c205581600052602c5160601c337f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b92560206000a35060015b92915050565b336001600160a01b037f00000000000000000000000000000000000000000000000000000000000000001614610385576040516323f09b3960e21b815260040160405180910390fd5b6000821561039d5761039686610460565b90506103ab565b6103a88585846107e1565b90505b6103b5868261081e565b505050505050565b600061045b6104527f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663883c6b246040518163ffffffff1660e01b8152600401602060405180830381865afa158015610423573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906104479190610d02565b6104556104526105dc565b90565b90610895565b905090565b6387a211a2600c9081526000828152602090912054610336565b600060405163a24e573d60e01b815260040160405180910390fd5b6000806104a0610256565b8051906020012090506040517f8b73c3c69bb8fe3d512ecc4cf759cc79239f7b179b0ffacaa9a75d522b39400f81528160208201527fc89efdaa54c0f20c7adf612882df0950f5a951637e0307cdcb4c672f298b8bc6604082015246606082015230608082015260a081209250505090565b6387a211a2600c9081526000828152602090912054806000036105385750600092915050565b6105c66104527f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663883c6b246040518163ffffffff1660e01b8152600401602060405180830381865afa15801561059c573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906105c09190610d02565b83610455565b9392505050565b60606001805461026590610cc8565b600061045b6805345cdf77eb68f44c5490565b60006105f9610256565b8051906020012090508442111561061857631a15a3cc6000526004601cfd5b6040518860601b60601c98508760601b60601c975065383775081901600e52886000526020600c2080547f8b73c3c69bb8fe3d512ecc4cf759cc79239f7b179b0ffacaa9a75d522b39400f83528360208401527fc89efdaa54c0f20c7adf612882df0950f5a951637e0307cdcb4c672f298b8bc6604084015246606084015230608084015260a08320602e527f6e71edae12b1b97f4d1f60370fef10105fa2faae0126114a169c64845d6126c983528a60208401528960408401528860608401528060808401528760a084015260c08320604e526042602c206000528660ff1660205285604052846060526020806080600060015afa8b3d51146107245763ddafbaef6000526004601cfd5b0190556303faf4f960a51b88176040526034602c2087905587897f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925602060608501a360405250506000606052505050505050565b336001600160a01b037f000000000000000000000000000000000000000000000000000000000000000016146107c1576040516323f09b3960e21b815260040160405180910390fd5b60006107ce8484846107e1565b90506107da85826108a4565b5050505050565b600082818360018111156107f7576107f7610d1b565b1461080b576108068582610923565b610815565b6108158582610972565b95945050505050565b6387a211a2600c52816000526020600c208054808311156108475763f4d678b86000526004601cfd5b82900390556805345cdf77eb68f44c8054829003905560008181526001600160a01b0383167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef602083a35050565b60006105c661045284846109c9565b6805345cdf77eb68f44c54818101818110156108c85763e5cfe9576000526004601cfd5b806805345cdf77eb68f44c5550506387a211a2600c52816000526020600c208181540181555080602052600c5160601c60007fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef602080a35050565b60007812725dd1d243aba0e75fe645cc4873f9e65afe688c928e1f218311670de0b6b3a76400000215820261096057637c5f487d6000526004601cfd5b50670de0b6b3a7640000919091020490565b60007812725dd1d243aba0e75fe645cc4873f9e65afe688c928e1f218311670de0b6b3a7640000021582026109af57637c5f487d6000526004601cfd5b50670de0b6b3a76400009190910281810615159190040190565b60008080600019848609848602925082811083820303915050806000036109fd5750670de0b6b3a764000090049050610336565b670de0b6b3a76400008110610a3357604051635173648d60e01b8152600481018690526024810185905260440160405180910390fd5b6000670de0b6b3a764000085870962040000818503049310909103600160ee1b02919091177faccb18165bd6fe31ae1cf318dc5b51eee0e1ba569b88cd74c1773b91fac106690291505092915050565b60006020808352835180602085015260005b81811015610ab157858101830151858201604001528201610a95565b506000604082860101526040601f19601f8301168501019250505092915050565b80356001600160a01b0381168114610ae957600080fd5b919050565b60008060408385031215610b0157600080fd5b610b0a83610ad2565b946020939093013593505050565b803560028110610ae957600080fd5b600080600080600060a08688031215610b3f57600080fd5b610b4886610ad2565b9450602086013593506040860135925060608601358015158114610b6b57600080fd5b9150610b7960808701610b18565b90509295509295909350565b600060208284031215610b9757600080fd5b6105c682610ad2565b600080600060608486031215610bb557600080fd5b610bbe84610ad2565b9250610bcc60208501610ad2565b9150604084013590509250925092565b600080600080600080600060e0888a031215610bf757600080fd5b610c0088610ad2565b9650610c0e60208901610ad2565b95506040880135945060608801359350608088013560ff81168114610c3257600080fd5b9699959850939692959460a0840135945060c09093013592915050565b60008060008060808587031215610c6557600080fd5b610c6e85610ad2565b93506020850135925060408501359150610c8a60608601610b18565b905092959194509250565b60008060408385031215610ca857600080fd5b610cb183610ad2565b9150610cbf60208401610ad2565b90509250929050565b600181811c90821680610cdc57607f821691505b602082108103610cfc57634e487b7160e01b600052602260045260246000fd5b50919050565b600060208284031215610d1457600080fd5b5051919050565b634e487b7160e01b600052602160045260246000fdfea2646970667358221220b2996254354190a91bf9d0d104655ce4d46acaa5a59ac9930b8990d1b9e9749564736f6c6343000818003300000000000000000000000021d1887a5dd441dc8c01713713035dd171cd30d20000000000000000000000000000000000000000000000000000000000000040000000000000000000000000400424737001484b4478ef6403d9e615a03c4bd400000000000000000000000002f6eeb4e33bba64bcbea18bd149b9031c2735f700000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000140000000000000000000000000000000000000000000000000000000000000018000000000000000000000000000000000000000000000000000000000000001c00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000154a756963652057455448204465627420546f6b656e000000000000000000000000000000000000000000000000000000000000000000000000000000000000076a64745745544800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001a4a756963652057455448204c697175696469747920546f6b656e00000000000000000000000000000000000000000000000000000000000000000000000000076a6c745745544800000000000000000000000000000000000000000000000000
Deployed Bytecode
0x608060405234801561001057600080fd5b50600436106101e75760003560e01c8063a6afed9511610110578063c883b2e5116100a8578063c883b2e5146103dc578063cbd00152146103ef578063cd3293de146103f7578063d8cab31814610461578063dbd5edc71461046e578063df6ce56014610477578063e37f8a7e1461048a578063f69e204614610492578063f8d898981461049a578063fd5668bf146104c157600080fd5b8063a6afed9514610350578063a8c62e7614610358578063acb708151461036b578063b2b8c93f1461037e578063b36d5e8b14610386578063b6b55f25146103a6578063b8ba16fd146103b9578063ba1c5e80146103cc578063c4e41b22146103d457600080fd5b80635c222bad116101835780635c222bad146102c75780635c975abb146102d85780636856728e146102e35780636a11d0b2146102eb5780638456cb59146102f457806386651203146102fc578063883c6b241461030f57806389dbb85714610317578063a612ce2b1461033d57600080fd5b80630ab30d8a146101ec5780632a5ad159146102075780632e1a7d4d1461021c578063366d8f3d1461022f5780633f4ba83a1461025357806343cd8f7e1461025b5780634b3fd1481461028f57806356d9e9a8146102a257806357bb1a62146102b5575b600080fd5b6101f46104c9565b6040519081526020015b60405180910390f35b61021a6102153660046130fa565b6104ff565b005b6101f461022a366004613117565b610684565b61024361023d3660046130fa565b50600090565b60405190151581526020016101fe565b61021a610851565b6102827f000000000000000000000000dd67f29f01fd351a4b206ceb3fe0e7b9061d5bc281565b6040516101fe9190613130565b6101f461029d366004613144565b61086e565b61021a6102b0366004613117565b610bd5565b61021a6102c3366004613182565b5050565b6003546001600160a01b0316610282565b60005460ff16610243565b61021a610c81565b6101f460105481565b61021a610ca8565b61021a61030a366004613117565b610cc3565b6101f4610d11565b7f00000000000000000000000021d1887a5dd441dc8c01713713035dd171cd30d2610282565b6101f461034b3660046130fa565b610deb565b61021a610e7b565b600254610282906001600160a01b031681565b6101f4610379366004613144565b610e8b565b6101f4610f4a565b61039961039436600461321d565b611161565b6040516101fe919061331b565b6101f46103b4366004613117565b61147d565b6101f46103c73660046130fa565b611683565b6005546101f4565b6101f46116d2565b6101f46103ea36600461332e565b61176a565b600c546101f4565b600354600454600554600654600754600854600954610422966001600160a01b031695949392919087565b604080516001600160a01b0390981688526020880196909652948601939093526060850191909152608084015260a083015260c082015260e0016101fe565b6011546102439060ff1681565b6101f4600a5481565b61021a610485366004613117565b611830565b6101f4611848565b6101f46118b7565b6102827f000000000000000000000000e2e453b31aa354e26a2510891949e95c85113b4381565b6006546101f4565b6009546000904281036104de57505060085490565b6008546005546104f991906104f390846118d4565b906118e1565b91505090565b806001600160a01b0381166105275760405163d92e233d60e01b815260040160405180910390fd5b610530336118f0565b61058457335b60408051637974da6f60e01b81526001600160a01b0390921660048301526024820152600e60448201526d282927aa27a1a7a62fa0a226a4a760911b60648201526084015b60405180910390fd5b600280546001600160a01b0319166001600160a01b0384169081179091556040516390d3b37960e01b81526706f05b59d3b20000600482015260009182916390d3b379906024016040805180830381865afa1580156105e7573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061060b9190613370565b915091506106198183101590565b1561063757604051635435b28960e11b815260040160405180910390fd5b61063f61199c565b610647611a65565b7f5a0a75b7511650dda977e2523dc8c695cb60b246d3a71314fa44e029e7453928846040516106769190613130565b60405180910390a150505050565b600061068e611b98565b610696611bbc565b8161069f611be6565b6000807f000000000000000000000000dd67f29f01fd351a4b206ceb3fe0e7b9061d5bc26001600160a01b03166370a08231336040518263ffffffff1660e01b81526004016106ee9190613130565b602060405180830381865afa15801561070b573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061072f9190613394565b905080851061074057809250600191505b826003600101600082825461075591906133c3565b90915550506007546040516313452f7360e01b81526001600160a01b037f000000000000000000000000dd67f29f01fd351a4b206ceb3fe0e7b9061d5bc216916313452f73916107b191339188919088906000906004016133f8565b600060405180830381600087803b1580156107cb57600080fd5b505af11580156107df573d6000803e3d6000fd5b50506003546107fb92506001600160a01b031690503385611c04565b610803611c61565b61080b611a65565b60405183815233907f884edad9ce6fa2440d8a54cc123490eb96d2768479d49ff9c7366125a94243649060200160405180910390a250506001805592915050565b919050565b61085a336118f0565b6108645733610536565b61086c611e34565b565b60007f00000000000000000000000021d1887a5dd441dc8c01713713035dd171cd30d26001600160a01b0316634295cbe76040518163ffffffff1660e01b8152600401602060405180830381865afa1580156108ce573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906108f2919061342b565b1561090f5760405162461bcd60e51b815260040161057b90613448565b610917611b98565b6040516311d8765360e31b81527f00000000000000000000000021d1887a5dd441dc8c01713713035dd171cd30d26001600160a01b031690638ec3b29890610963903390600401613130565b602060405180830381865afa158015610980573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906109a4919061342b565b6109f457335b60408051637974da6f60e01b81526001600160a01b0390921660048301526024820152600f60448201526e20a1a1a7aaa72a2fa6a0a720a3a2a960891b606482015260840161057b565b6109fc611bbc565b6003546040516370a0823160e01b81526001600160a01b03909116906370a0823190610a2c903090600401613130565b602060405180830381865afa158015610a49573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610a6d9190613394565b831115610a8d5760405163bb55fd2760e01b815260040160405180910390fd5b610a95611be6565b8260036001016000828254610aaa91906133c3565b9091555050600854604051630d6b960560e41b81526001600160a01b037f000000000000000000000000e2e453b31aa354e26a2510891949e95c85113b43169163d6b9605091610b04918691889190600090600401613475565b600060405180830381600087803b158015610b1e57600080fd5b505af1158015610b32573d6000803e3d6000fd5b5050600354610b4e92506001600160a01b031690508385611c04565b610b56611c61565b610b5e611a65565b600c54831015610b815760405163024f8afb60e51b815260040160405180910390fd5b816001600160a01b03167fcbc04eca7e9da35cb1393a6135a199ca52e450d5e9251cbd99f7847d33a3675084604051610bbc91815260200190565b60405180910390a25081610bcf60018055565b92915050565b610c5c33604051602001610c0e906020808252601190820152702622a7222faca4a2a6222fa9a2a72222a960791b604082015260600190565b60408051601f19818403018152828252805160209182012083830190925260118352702622a7222faca4a2a6222fa9a2a72222a960791b90830152600d546001600160a01b03169291611e80565b600454600354610c77906001600160a01b0316333085611f18565b6102c38183611f51565b610c8a336118f0565b610c945733610536565b6011805460ff19811660ff90911615179055565b610cb1336118f0565b610cbb5733610536565b61086c611fbc565b610ccc336118f0565b610cd65733610536565b600a8190556040518181527f333b26cca69716ad4680ddb07663f5bfb4f06045671f336af9a83690a3ae00f99060200160405180910390a150565b600954600090428103610d2657505060075490565b60035460405163e12f3a6160e01b81526000916001600160a01b03169063e12f3a6190610d57903090600401613130565b602060405180830381865afa158015610d74573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610d989190613394565b90506000610dc6610dab60036001015490565b600454610dc090610dbd9086906134a9565b90565b90611ff9565b9050610de3816104f36003600401546104f36003800154886118d4565b935050505090565b6040516370a0823160e01b81526000906001600160a01b037f000000000000000000000000e2e453b31aa354e26a2510891949e95c85113b4316906370a0823190610e3a908590600401613130565b602060405180830381865afa158015610e57573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610bcf9190613394565b610e8361199c565b61086c611a65565b6000610e95611b98565b6040516311d8765360e31b81527f00000000000000000000000021d1887a5dd441dc8c01713713035dd171cd30d26001600160a01b031690638ec3b29890610ee1903390600401613130565b602060405180830381865afa158015610efe573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610f22919061342b565b610f2c57336109aa565b610f34611bbc565b610f3f838384612011565b9050610bcf60018055565b600e5460405160009182916001600160a01b039091169063c824e15790610f8d9060200160208082526005908201526410931054d560da1b604082015260600190565b604051602081830303815290604052805190602001206040518263ffffffff1660e01b8152600401610fc191815260200190565b602060405180830381865afa158015610fde573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061100291906134bc565b600e546040519192506000916001600160a01b03909116906321f8a7219061102c906020016134d9565b604051602081830303815290604052805190602001206040518263ffffffff1660e01b815260040161106091815260200190565b602060405180830381865afa15801561107d573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906110a191906134bc565b60405163662aa11d60e01b81523060048201526001600160a01b0380831660248301529192509083169063662aa11d906044016020604051808303816000875af11580156110f3573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906111179190613394565b9250806001600160a01b03167f9c3c39d0eedd3d18612a0e8e76cc7bc873815d3e19206dbbf9825989b1c95e6b8460405161115491815260200190565b60405180910390a2505090565b6060846001600160a01b03811661118b5760405163d92e233d60e01b815260040160405180910390fd5b611193611b98565b61119b611bbc565b6003546001600160a01b038681169116146111c957604051633c4edfcd60e21b815260040160405180910390fd5b6003546040516370a0823160e01b81526000916001600160a01b0316906370a08231906111fa903090600401613130565b602060405180830381865afa158015611217573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061123b9190613394565b90506000611253610dbd61124d61229b565b886104f3565b90508186111561127657604051633ee39f9d60e01b815260040160405180910390fd5b60035461128d906001600160a01b03168988611c04565b60035460405163feea07eb60e01b815260009182916001600160a01b03808d169263feea07eb926112ca92339216908d9089908e90600401613500565b6000604051808303816000875af11580156112e9573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f19168201604052611311919081019061353a565b91509150816113335760405163a155965d60e01b815260040160405180910390fd5b6003546040516370a0823160e01b81526000916001600160a01b0316906370a0823190611364903090600401613130565b602060405180830381865afa158015611381573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906113a59190613394565b9050808511156113c8576040516323c758a760e11b815260040160405180910390fd5b60006113d486836133c3565b9050808511156113f757604051636174404560e01b815260040160405180910390fd5b801561141b5761141b611408612373565b6003546001600160a01b03169083611c04565b600354604080518c8152602081018490526001600160a01b03909216917f31aaad38f00845a242d16ae90d7bd72fc68f0e22581470f9dc0de241210c2886910160405180910390a2509095505050505061147460018055565b50949350505050565b60007f00000000000000000000000021d1887a5dd441dc8c01713713035dd171cd30d26001600160a01b0316634295cbe76040518163ffffffff1660e01b8152600401602060405180830381865afa1580156114dd573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611501919061342b565b1561151e5760405162461bcd60e51b815260040161057b90613448565b611526611b98565b61152e611bbc565b600019600a54141580156115545750600a546115486116d2565b61155290846134a9565b115b15611572576040516324d758c360e21b815260040160405180910390fd5b61157a611be6565b816003600101600082825461158f91906134a9565b90915550506003546115ac906001600160a01b0316333085611f18565b600754604051630d6b960560e41b81526001600160a01b037f000000000000000000000000dd67f29f01fd351a4b206ceb3fe0e7b9061d5bc2169163d6b9605091611601913391879190600190600401613475565b600060405180830381600087803b15801561161b57600080fd5b505af115801561162f573d6000803e3d6000fd5b5050505061163b611c61565b611643611a65565b60405182815233907fe1fffcc4923d04b559f4d29a8bfc6cda04eb5b0d3c460751c2402c5c5cc9109c9060200160405180910390a2508061084c60018055565b6040516370a0823160e01b81526000906001600160a01b037f000000000000000000000000dd67f29f01fd351a4b206ceb3fe0e7b9061d5bc216906370a0823190610e3a908590600401613130565b6000611765610dbd6003600401546104f37f000000000000000000000000dd67f29f01fd351a4b206ceb3fe0e7b9061d5bc26001600160a01b031663b1bf962d6040518163ffffffff1660e01b8152600401602060405180830381865afa158015611741573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610dbd9190613394565b905090565b6000611774611b98565b6040516311d8765360e31b81527f00000000000000000000000021d1887a5dd441dc8c01713713035dd171cd30d26001600160a01b031690638ec3b298906117c0903390600401613130565b602060405180830381865afa1580156117dd573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611801919061342b565b61180b57336109aa565b611813611bbc565b61181e848484612011565b905061182960018055565b9392505050565b611839336118f0565b6118435733610536565b600c55565b6000611765610dbd6003600501546104f37f000000000000000000000000e2e453b31aa354e26a2510891949e95c85113b436001600160a01b031663b1bf962d6040518163ffffffff1660e01b8152600401602060405180830381865afa158015611741573d6000803e3d6000fd5b60006118c1611bbc565b6118c9612428565b9050610dbd60018055565b600061182983834261252e565b6000611829610dbd8484612591565b6000816001600160a01b03167f00000000000000000000000021d1887a5dd441dc8c01713713035dd171cd30d26001600160a01b031663893d20e86040518163ffffffff1660e01b8152600401602060405180830381865afa15801561195a573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061197e91906134bc565b6001600160a01b03161461199457506000919050565b506001919050565b60065415611a5f576006546009546000916119b6916118d4565b6007549091506119c79082906118e1565b6007556005546009546000916119dc916118d4565b6008549091506119ed9082906118e1565b6008556007546040519081527f98c7d87cc1242fd0802e2cc1c048bab3a03309350b0e8af0c06f6110b7aa16869060200160405180910390a16008546040519081527f3d78dc9bb9d0a317106d49b366e60f1b7995cfc4df04348c4ffe939f4540b5ae9060200160405180910390a150505b42600955565b6000611a6f611848565b60045490915060008215611a9657611a93611a8d610dbd85856134a9565b84610dc0565b90505b6002546040516390d3b37960e01b8152600481018390526000916001600160a01b0316906390d3b379906024016040805180830381865afa158015611adf573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611b039190613370565b6005559050611b2c611b25611b16612647565b670de0b6b3a7640000906126a7565b82906118e1565b6006556005546040519081527f578adda73f5b431118629e4fc78f890d645ad2613a5260bddc23fa48065b940a9060200160405180910390a16006546040519081527fbaa019247a3ef5fbd10fa058e87b444fe8cd8f5d48494dc3e5756e509a34134990602001610676565b60005460ff161561086c5760405163d93c066560e01b815260040160405180910390fd5b600260015403611bdf57604051633ee5aeb560e01b815260040160405180910390fd5b6002600155565b611bee61199c565b60115460ff161561086c57611c01612428565b50565b611c5c83846001600160a01b031663a9059cbb8585604051602401611c2a9291906135c6565b604051602081830303815290604052915060e01b6020820180516001600160e01b0383818316178352505050506126b6565b505050565b60007f000000000000000000000000dd67f29f01fd351a4b206ceb3fe0e7b9061d5bc26001600160a01b03166318160ddd6040518163ffffffff1660e01b8152600401602060405180830381865afa158015611cc1573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611ce59190613394565b905060006003600101547f000000000000000000000000e2e453b31aa354e26a2510891949e95c85113b436001600160a01b03166318160ddd6040518163ffffffff1660e01b8152600401602060405180830381865afa158015611d4d573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611d719190613394565b611d7b91906134a9565b9050818111156102c3576000611d9183836133c3565b9050600b54811115611c5c577f000000000000000000000000dd67f29f01fd351a4b206ceb3fe0e7b9061d5bc26001600160a01b031663d6b96050611dd4612373565b6007546040516001600160e01b031960e085901b168152611dfd92918691600190600401613475565b600060405180830381600087803b158015611e1757600080fd5b505af1158015611e2b573d6000803e3d6000fd5b50505050505050565b611e3c612710565b6000805460ff191690557f5db9ee0a495bf2e6ff9c91a7834c1ba4fdd244a5e8aa4e537bd38aeae4b073aa335b604051611e769190613130565b60405180910390a1565b604051632474521560e21b8152600481018390526001600160a01b0384811660248301528516906391d1485490604401602060405180830381865afa158015611ecd573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611ef1919061342b565b611f12578281604051637974da6f60e01b815260040161057b9291906135df565b50505050565b6040516001600160a01b038481166024830152838116604483015260648201839052611f129186918216906323b872dd90608401611c2a565b8060036001016000828254611f6691906134a9565b90915550611f80905082600754600454610dc091906104f3565b60078190556040519081527f98c7d87cc1242fd0802e2cc1c048bab3a03309350b0e8af0c06f6110b7aa16869060200160405180910390a15050565b611fc4611b98565b6000805460ff191660011790557f62e78cea01bee320cd4e420270b5ea74000d11b0c9f74754ebdbfc544b05a258611e693390565b6000611829610dbd84670de0b6b3a764000085612733565b600061201b611be6565b6040516370a0823160e01b815284906000906001600160a01b037f000000000000000000000000e2e453b31aa354e26a2510891949e95c85113b4316906370a082319061206c908890600401613130565b602060405180830381865afa158015612089573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906120ad9190613394565b905060008183106120bf575090508060015b82600360010160008282546120d491906134a9565b90915550506008546040516313452f7360e01b81526001600160a01b037f000000000000000000000000e2e453b31aa354e26a2510891949e95c85113b4316916313452f7391612130918a9188919087906001906004016133f8565b600060405180830381600087803b15801561214a57600080fd5b505af115801561215e573d6000803e3d6000fd5b505060035461217b92506001600160a01b03169050863086611f18565b612183611c61565b61218b611a65565b6040516370a0823160e01b81526000906001600160a01b037f000000000000000000000000e2e453b31aa354e26a2510891949e95c85113b4316906370a08231906121da908a90600401613130565b602060405180830381865afa1580156121f7573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061221b9190613394565b905060008111801561222e5750600c5481105b1561224c5760405163024f8afb60e51b815260040160405180910390fd5b866001600160a01b03167f5c16de4f8b59bd9caf0f49a545f25819a895ed223294290b408242e72a5942318560405161228791815260200190565b60405180910390a250919695505050505050565b60007f00000000000000000000000021d1887a5dd441dc8c01713713035dd171cd30d26001600160a01b031663e5f3d3a56040516020016122fe906020808252600e908201526d464c4153485f4c4f414e5f46454560901b604082015260600190565b604051602081830303815290604052805190602001206040518263ffffffff1660e01b815260040161233291815260200190565b602060405180830381865afa15801561234f573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906117659190613394565b60007f00000000000000000000000021d1887a5dd441dc8c01713713035dd171cd30d26001600160a01b03166321f8a7216040516020016123b3906134d9565b604051602081830303815290604052805190602001206040518263ffffffff1660e01b81526004016123e791815260200190565b602060405180830381865afa158015612404573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061176591906134bc565b60035460405163e12f3a6160e01b81526000916001600160a01b031690819063e12f3a619061245b903090600401613130565b602060405180830381865afa158015612478573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061249c9190613394565b9150601054821061252a5760048054604051635569f64b60e11b815290916001600160a01b0384169163aad3ec96916124d99130918891016135c6565b6020604051808303816000875af11580156124f8573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061251c9190613394565b92506125288184611f51565b505b5090565b6000670de0b6b3a76400008161254485856133c3565b90508060000361255657509050611829565b60006301e133806125678884613603565b6125719190613630565b905061258661257f82612807565b84906118e1565b979650505050505050565b60008080600019848609848602925082811083820303915050806000036125c55750670de0b6b3a764000090049050610bcf565b670de0b6b3a764000081106125f757604051635173648d60e01b8152600481018690526024810185905260440161057b565b6000670de0b6b3a764000085870962040000818503049310909103600160ee1b02919091177faccb18165bd6fe31ae1cf318dc5b51eee0e1ba569b88cd74c1773b91fac106690291505092915050565b60007f00000000000000000000000021d1887a5dd441dc8c01713713035dd171cd30d26001600160a01b031663e5f3d3a56040516020016122fe906020808252600b908201526a4c454e44494e475f46454560a81b604082015260600190565b6000611829610dbd83856133c3565b60006126cb6001600160a01b0384168361285d565b905080516000141580156126f05750808060200190518101906126ee919061342b565b155b15611c5c5782604051635274afe760e01b815260040161057b9190613130565b60005460ff1661086c57604051638dfc202b60e01b815260040160405180910390fd5b600080806000198587098587029250828110838203039150508060000361276d578382816127635761276361361a565b0492505050611829565b83811061279e57604051630c740aef60e31b815260048101879052602481018690526044810185905260640161057b565b60008486880960026001871981018816978890046003810283188082028403028082028403028082028403028082028403028082028403029081029092039091026000889003889004909101858311909403939093029303949094049190911702949350505050565b600081680736ea4425c11ac63081111561283757604051630d7b1d6560e11b81526004810184905260240161057b565b6714057b7ef767814f8102612855670de0b6b3a7640000820461286b565b949350505050565b6060611829838360006128c1565b600081680a688906bd8affffff81111561289b5760405163b3b6ba1f60e01b81526004810184905260240161057b565b60006128b3670de0b6b3a7640000604084901b613630565b9050612855610dbd8261295e565b6060814710156128e6573060405163cd78605960e01b815260040161057b9190613130565b600080856001600160a01b031684866040516129029190613652565b60006040518083038185875af1925050503d806000811461293f576040519150601f19603f3d011682016040523d82523d6000602084013e612944565b606091505b5091509150612954868383613069565b9695505050505050565b600160bf1b60ff60381b821615612a47576001603f1b82161561298a5768016a09e667f3bcc9090260401c5b6001603e1b8216156129a5576801306fe0a31b7152df0260401c5b6001603d1b8216156129c0576801172b83c7d517adce0260401c5b6001603c1b8216156129db5768010b5586cf9890f62a0260401c5b6001603b1b8216156129f6576801059b0d31585743ae0260401c5b6001603a1b821615612a1157680102c9a3e778060ee70260401c5b600160391b821615612a2c5768010163da9fb33356d80260401c5b600160381b821615612a4757680100b1afa5abcbed610260401c5b60ff60301b821615612b2b57600160371b821615612a6e5768010058c86da1c09ea20260401c5b600160361b821615612a89576801002c605e2e8cec500260401c5b600160351b821615612aa457680100162f3904051fa10260401c5b600160341b821615612abf576801000b175effdc76ba0260401c5b600160331b821615612ada57680100058ba01fb9f96d0260401c5b600160321b821615612af55768010002c5cc37da94920260401c5b600160311b821615612b10576801000162e525ee05470260401c5b600160301b821615612b2b5768010000b17255775c040260401c5b60ff60281b821615612c0f576001602f1b821615612b52576801000058b91b5bc9ae0260401c5b6001602e1b821615612b6d57680100002c5c89d5ec6d0260401c5b6001602d1b821615612b885768010000162e43f4f8310260401c5b6001602c1b821615612ba357680100000b1721bcfc9a0260401c5b6001602b1b821615612bbe5768010000058b90cf1e6e0260401c5b6001602a1b821615612bd9576801000002c5c863b73f0260401c5b600160291b821615612bf457680100000162e430e5a20260401c5b600160281b821615612c0f576801000000b1721835510260401c5b64ff00000000821615612cfc57648000000000821615612c3857680100000058b90c0b490260401c5b644000000000821615612c545768010000002c5c8601cc0260401c5b642000000000821615612c70576801000000162e42fff00260401c5b641000000000821615612c8c5768010000000b17217fbb0260401c5b640800000000821615612ca8576801000000058b90bfce0260401c5b640400000000821615612cc457680100000002c5c85fe30260401c5b640200000000821615612ce05768010000000162e42ff10260401c5b640100000000821615612cfc57680100000000b17217f80260401c5b63ff000000821615612de0576380000000821615612d235768010000000058b90bfc0260401c5b6340000000821615612d3e576801000000002c5c85fe0260401c5b6320000000821615612d5957680100000000162e42ff0260401c5b6310000000821615612d74576801000000000b17217f0260401c5b6308000000821615612d8f57680100000000058b90c00260401c5b6304000000821615612daa5768010000000002c5c8600260401c5b6302000000821615612dc5576801000000000162e4300260401c5b6301000000821615612de05768010000000000b172180260401c5b62ff0000821615612ebb5762800000821615612e05576801000000000058b90c0260401c5b62400000821615612e1f57680100000000002c5c860260401c5b62200000821615612e395768010000000000162e430260401c5b62100000821615612e5357680100000000000b17210260401c5b62080000821615612e6d5768010000000000058b910260401c5b62040000821615612e87576801000000000002c5c80260401c5b62020000821615612ea157680100000000000162e40260401c5b62010000821615612ebb576801000000000000b1720260401c5b61ff00821615612f8d57618000821615612ede57680100000000000058b90260401c5b614000821615612ef75768010000000000002c5d0260401c5b612000821615612f10576801000000000000162e0260401c5b611000821615612f295768010000000000000b170260401c5b610800821615612f42576801000000000000058c0260401c5b610400821615612f5b57680100000000000002c60260401c5b610200821615612f7457680100000000000001630260401c5b610100821615612f8d57680100000000000000b10260401c5b60ff821615613052576080821615612fae57680100000000000000590260401c5b6040821615612fc6576801000000000000002c0260401c5b6020821615612fde57680100000000000000160260401c5b6010821615612ff6576801000000000000000b0260401c5b600882161561300e57680100000000000000060260401c5b600482161561302657680100000000000000030260401c5b600282161561303c576001600160401b010260401c5b6001821615613052576001600160401b010260401c5b670de0b6b3a76400000260409190911c60bf031c90565b60608261307e57613079826130bc565b611829565b815115801561309557506001600160a01b0384163b155b156130b55783604051639996b31560e01b815260040161057b9190613130565b5080611829565b8051156130cc5780518082602001fd5b604051630a12f52160e11b815260040160405180910390fd5b6001600160a01b0381168114611c0157600080fd5b60006020828403121561310c57600080fd5b8135611829816130e5565b60006020828403121561312957600080fd5b5035919050565b6001600160a01b0391909116815260200190565b6000806040838503121561315757600080fd5b823591506020830135613169816130e5565b809150509250929050565b8015158114611c0157600080fd5b6000806040838503121561319557600080fd5b82356131a0816130e5565b9150602083013561316981613174565b634e487b7160e01b600052604160045260246000fd5b604051601f8201601f191681016001600160401b03811182821017156131ee576131ee6131b0565b604052919050565b60006001600160401b0382111561320f5761320f6131b0565b50601f01601f191660200190565b6000806000806080858703121561323357600080fd5b843561323e816130e5565b9350602085013561324e816130e5565b92506040850135915060608501356001600160401b0381111561327057600080fd5b8501601f8101871361328157600080fd5b803561329461328f826131f6565b6131c6565b8181528860208385010111156132a957600080fd5b8160208401602083013760006020838301015280935050505092959194509250565b60005b838110156132e65781810151838201526020016132ce565b50506000910152565b600081518084526133078160208601602086016132cb565b601f01601f19169290920160200192915050565b60208152600061182960208301846132ef565b60008060006060848603121561334357600080fd5b833592506020840135613355816130e5565b91506040840135613365816130e5565b809150509250925092565b6000806040838503121561338357600080fd5b505080516020909101519092909150565b6000602082840312156133a657600080fd5b5051919050565b634e487b7160e01b600052601160045260246000fd5b81810381811115610bcf57610bcf6133ad565b600281106133f457634e487b7160e01b600052602160045260246000fd5b9052565b6001600160a01b03861681526020810185905260408101849052821515606082015260a0810161295460808301846133d6565b60006020828403121561343d57600080fd5b815161182981613174565b602080825260139082015272141493d513d0d3d317d11154149150d0551151606a1b604082015260600190565b6001600160a01b03851681526020810184905260408101839052608081016134a060608301846133d6565b95945050505050565b80820180821115610bcf57610bcf6133ad565b6000602082840312156134ce57600080fd5b8151611829816130e5565b6020808252600d908201526c2322a2afa1a7a62622a1aa27a960991b604082015260600190565b6001600160a01b03868116825285166020820152604081018490526060810183905260a060808201819052600090612586908301846132ef565b6000806040838503121561354d57600080fd5b825161355881613174565b60208401519092506001600160401b0381111561357457600080fd5b8301601f8101851361358557600080fd5b805161359361328f826131f6565b8181528660208385010111156135a857600080fd5b6135b98260208301602086016132cb565b8093505050509250929050565b6001600160a01b03929092168252602082015260400190565b6001600160a01b0383168152604060208201819052600090612855908301846132ef565b8082028115828204841417610bcf57610bcf6133ad565b634e487b7160e01b600052601260045260246000fd5b60008261364d57634e487b7160e01b600052601260045260246000fd5b500490565b600082516136648184602087016132cb565b919091019291505056fea26469706673582212209b7c00e846267f90bef20f6209406950dce2ee6a1de500fafba4078aec8d893364736f6c63430008180033
Constructor Arguments (ABI-Encoded and is the last bytes of the Contract Creation Code above)
00000000000000000000000021d1887a5dd441dc8c01713713035dd171cd30d20000000000000000000000000000000000000000000000000000000000000040000000000000000000000000400424737001484b4478ef6403d9e615a03c4bd400000000000000000000000002f6eeb4e33bba64bcbea18bd149b9031c2735f700000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000140000000000000000000000000000000000000000000000000000000000000018000000000000000000000000000000000000000000000000000000000000001c00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000154a756963652057455448204465627420546f6b656e000000000000000000000000000000000000000000000000000000000000000000000000000000000000076a64745745544800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001a4a756963652057455448204c697175696469747920546f6b656e00000000000000000000000000000000000000000000000000000000000000000000000000076a6c745745544800000000000000000000000000000000000000000000000000
-----Decoded View---------------
Arg [0] : protocolGovernor_ (address): 0x21d1887A5dd441dc8C01713713035dd171CD30D2
Arg [1] : params (tuple):
Arg [1] : interestRateStrategy (address): 0x400424737001484B4478EF6403d9E615A03c4bd4
Arg [2] : blastPointsOperator (address): 0x02F6EEb4E33bbA64bcBEA18bd149B9031C2735F7
Arg [3] : debtTokenName (string): Juice WETH Debt Token
Arg [4] : debtTokenSymbol (string): jdtWETH
Arg [5] : liquidityTokenName (string): Juice WETH Liquidity Token
Arg [6] : liquidityTokenSymbol (string): jltWETH
Arg [7] : minimumOpenBorrow (uint256): 0
Arg [8] : isAutoCompounding (bool): True
-----Encoded View---------------
18 Constructor Arguments found :
Arg [0] : 00000000000000000000000021d1887a5dd441dc8c01713713035dd171cd30d2
Arg [1] : 0000000000000000000000000000000000000000000000000000000000000040
Arg [2] : 000000000000000000000000400424737001484b4478ef6403d9e615a03c4bd4
Arg [3] : 00000000000000000000000002f6eeb4e33bba64bcbea18bd149b9031c2735f7
Arg [4] : 0000000000000000000000000000000000000000000000000000000000000100
Arg [5] : 0000000000000000000000000000000000000000000000000000000000000140
Arg [6] : 0000000000000000000000000000000000000000000000000000000000000180
Arg [7] : 00000000000000000000000000000000000000000000000000000000000001c0
Arg [8] : 0000000000000000000000000000000000000000000000000000000000000000
Arg [9] : 0000000000000000000000000000000000000000000000000000000000000001
Arg [10] : 0000000000000000000000000000000000000000000000000000000000000015
Arg [11] : 4a756963652057455448204465627420546f6b656e0000000000000000000000
Arg [12] : 0000000000000000000000000000000000000000000000000000000000000007
Arg [13] : 6a64745745544800000000000000000000000000000000000000000000000000
Arg [14] : 000000000000000000000000000000000000000000000000000000000000001a
Arg [15] : 4a756963652057455448204c697175696469747920546f6b656e000000000000
Arg [16] : 0000000000000000000000000000000000000000000000000000000000000007
Arg [17] : 6a6c745745544800000000000000000000000000000000000000000000000000
Loading...
Loading
Loading...
Loading
Loading...
Loading
Net Worth in USD
$1,003,416.23
Net Worth in ETH
339.368944
Token Allocations
WETH
100.00%
USDB
0.00%
ETH
0.00%
Multichain Portfolio | 35 Chains
Loading...
Loading
Loading...
Loading
Loading...
Loading
[ Download: CSV Export ]
[ Download: CSV Export ]
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.