Source Code
Overview
ETH Balance
0 ETH
ETH Value
$0.00| Transaction Hash |
Method
|
Block
|
From
|
To
|
|||||
|---|---|---|---|---|---|---|---|---|---|
Latest 1 internal transaction
Advanced mode:
| Parent Transaction Hash | Block | From | To | |||
|---|---|---|---|---|---|---|
| 4976860 | 156 days ago | Contract Creation | 0 ETH |
Cross-Chain Transactions
Loading...
Loading
Contract Name:
BoringOnChainQueue
Compiler Version
v0.8.21+commit.d9974bed
Contract Source Code (Solidity Standard Json-Input format)
// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.21;
import {ERC20} from "@solmate/tokens/ERC20.sol";
import {WETH} from "@solmate/tokens/WETH.sol";
import {BoringVault} from "../../../../src/base/BoringVault.sol";
import {AccountantWithRateProviders} from "../../../../src/base/Roles/AccountantWithRateProviders.sol";
import {FixedPointMathLib} from "@solmate/utils/FixedPointMathLib.sol";
import {SafeTransferLib} from "@solmate/utils/SafeTransferLib.sol";
import {BeforeTransferHook} from "../../../../src/interfaces/BeforeTransferHook.sol";
import {Auth, Authority} from "@solmate/auth/Auth.sol";
import {ReentrancyGuard} from "@solmate/utils/ReentrancyGuard.sol";
import {IPausable} from "../../../../src/interfaces/IPausable.sol";
import {EnumerableSet} from "@openzeppelin/contracts/utils/structs/EnumerableSet.sol";
import {IBoringSolver} from "../../../../src/base/Roles/BoringQueue/IBoringSolver.sol";
contract BoringOnChainQueue is Auth, ReentrancyGuard, IPausable {
using EnumerableSet for EnumerableSet.Bytes32Set;
using SafeTransferLib for BoringVault;
using SafeTransferLib for ERC20;
using FixedPointMathLib for uint256;
// ========================================= STRUCTS =========================================
/**
* @param allowWithdraws Whether or not withdraws are allowed for this asset.
* @param secondsToMaturity The time in seconds it takes for the asset to mature.
* @param minimumSecondsToDeadline The minimum time in seconds a withdraw request must be valid for before it is expired
* @param minDiscount The minimum discount allowed for a withdraw request.
* @param maxDiscount The maximum discount allowed for a withdraw request.
* @param minimumShares The minimum amount of shares that can be withdrawn.
*/
struct WithdrawAsset {
bool allowWithdraws;
uint24 secondsToMaturity;
uint24 minimumSecondsToDeadline;
uint16 minDiscount;
uint16 maxDiscount;
uint96 minimumShares;
}
/**
* @param nonce The nonce of the request, used to make it impossible for request Ids to be repeated.
* @param user The user that made the request.
* @param assetOut The asset that the user wants to withdraw.
* @param amountOfShares The amount of shares the user wants to withdraw.
* @param amountOfAssets The amount of assets the user will receive.
* @param creationTime The time the request was made.
* @param secondsToMaturity The time in seconds it takes for the asset to mature.
* @param secondsToDeadline The time in seconds the request is valid for.
*/
struct OnChainWithdraw {
uint96 nonce; // read from state, used to make it impossible for request Ids to be repeated.
address user; // msg.sender
address assetOut; // input sanitized
uint128 amountOfShares; // input transfered in
uint128 amountOfAssets; // derived from amountOfShares and price
uint40 creationTime; // time withdraw was made
uint24 secondsToMaturity; // in contract, from withdrawAsset?
uint24 secondsToDeadline; // in contract, from withdrawAsset? To get the deadline you take the creationTime add seconds to maturity, add the secondsToDeadline
}
// ========================================= CONSTANTS =========================================
/**
* @notice The maximum discount allowed for a withdraw asset.
*/
uint16 internal constant MAX_DISCOUNT = 0.3e4;
/**
* @notice The maximum time in seconds a withdraw asset can take to mature.
*/
uint24 internal constant MAXIMUM_SECONDS_TO_MATURITY = 30 days;
/**
* @notice Caps the minimum time in seconds a withdraw request must be valid for before it is expired.
*/
uint24 internal constant MAXIMUM_MINIMUM_SECONDS_TO_DEADLINE = 30 days;
// ========================================= MODIFIERS =========================================
/**
* @notice Ensure that the request user is the same as the message sender.
*/
modifier onlyRequestUser(address requestUser, address msgSender) {
if (requestUser != msgSender) revert BoringOnChainQueue__BadUser();
_;
}
// ========================================= GLOBAL STATE =========================================
/**
* @notice Open Zeppelin EnumerableSet to store all withdraw requests, by there request Id.
*/
EnumerableSet.Bytes32Set private _withdrawRequests;
/**
* @notice Mapping of asset addresses to WithdrawAssets.
*/
mapping(address => WithdrawAsset) public withdrawAssets;
/**
* @notice The nonce of the next request.
* @dev The purpose of this nonce is to prevent request Ids from being repeated.
* @dev Start at 1, since 0 is considered invalid.
* @dev When incrementing the nonce, an unchecked block is used to save gas.
* This is safe because you can not feasibly make a request, and then cause an overflow
* in the same block such that you can make 2 requests with the same request Id.
* And even if you did, the tx would revert with a keccak256 collision error.
*/
uint96 public nonce = 1;
/**
* @notice Whether or not the contract is paused.
*/
bool public isPaused;
//============================== ERRORS ===============================
error BoringOnChainQueue__Paused();
error BoringOnChainQueue__WithdrawsNotAllowedForAsset();
error BoringOnChainQueue__BadDiscount();
error BoringOnChainQueue__BadShareAmount();
error BoringOnChainQueue__BadDeadline();
error BoringOnChainQueue__BadUser();
error BoringOnChainQueue__DeadlinePassed();
error BoringOnChainQueue__NotMatured();
error BoringOnChainQueue__Keccak256Collision();
error BoringOnChainQueue__RequestNotFound();
error BoringOnChainQueue__PermitFailedAndAllowanceTooLow();
error BoringOnChainQueue__MAX_DISCOUNT();
error BoringOnChainQueue__MAXIMUM_MINIMUM_SECONDS_TO_DEADLINE();
error BoringOnChainQueue__SolveAssetMismatch();
error BoringOnChainQueue__Overflow();
error BoringOnChainQueue__MAXIMUM_SECONDS_TO_MATURITY();
error BoringOnChainQueue__BadInput();
error BoringOnChainQueue__RescueCannotTakeSharesFromActiveRequests();
//============================== EVENTS ===============================
event OnChainWithdrawRequested(
bytes32 indexed requestId,
address indexed user,
address indexed assetOut,
uint96 nonce,
uint128 amountOfShares,
uint128 amountOfAssets,
uint40 creationTime,
uint24 secondsToMaturity,
uint24 secondsToDeadline
);
event OnChainWithdrawCancelled(bytes32 indexed requestId, address indexed user, uint256 timestamp);
event OnChainWithdrawSolved(bytes32 indexed requestId, address indexed user, uint256 timestamp);
event WithdrawAssetSetup(
address indexed assetOut,
uint24 secondsToMaturity,
uint24 minimumSecondsToDeadline,
uint16 minDiscount,
uint16 maxDiscount,
uint96 minimumShares
);
event WithdrawAssetStopped(address indexed assetOut);
event WithdrawAssetUpdated(
address indexed assetOut,
uint24 minimumSecondsToDeadline,
uint24 secondsToMaturity,
uint16 minDiscount,
uint16 maxDiscount,
uint96 minimumShares
);
event Paused();
event Unpaused();
//============================== IMMUTABLES ===============================
/**
* @notice The BoringVault contract to withdraw from.
*/
BoringVault public immutable boringVault;
/**
* @notice The AccountantWithRateProviders contract to get rates from.
*/
AccountantWithRateProviders public immutable accountant;
/**
* @notice One BoringVault share.
*/
uint256 public immutable ONE_SHARE;
constructor(address _owner, address _auth, address payable _boringVault, address _accountant)
Auth(_owner, Authority(_auth))
{
boringVault = BoringVault(_boringVault);
ONE_SHARE = 10 ** boringVault.decimals();
accountant = AccountantWithRateProviders(_accountant);
}
//=============================== ADMIN FUNCTIONS ================================
/**
* @notice Allows the owner to rescue tokens from the contract.
* @dev The owner can only withdraw BoringVault shares if they are accidentally sent to this contract.
* Shares from active withdraw requests are not withdrawable.
* @param token The token to rescue.
* @param amount The amount to rescue.
* @param to The address to send the rescued tokens to.
* @param activeRequests The active withdraw requests, query `getWithdrawRequests`, or read events to get them.
* @dev Provided activeRequests must match the order of active requests in the queue.
*/
function rescueTokens(ERC20 token, uint256 amount, address to, OnChainWithdraw[] calldata activeRequests)
external
requiresAuth
{
if (address(token) == address(boringVault)) {
bytes32[] memory requestIds = _withdrawRequests.values();
uint256 requestIdsLength = requestIds.length;
if (activeRequests.length != requestIdsLength) revert BoringOnChainQueue__BadInput();
// Iterate through provided activeRequests, and hash each one to compare to the requestIds.
// Also track the sum of shares to make sure it is less than or equal to the amount.
uint256 activeRequestShareSum;
for (uint256 i = 0; i < requestIdsLength; ++i) {
if (keccak256(abi.encode(activeRequests[i])) != requestIds[i]) revert BoringOnChainQueue__BadInput();
activeRequestShareSum += activeRequests[i].amountOfShares;
}
uint256 freeShares = boringVault.balanceOf(address(this)) - activeRequestShareSum;
if (amount == type(uint256).max) amount = freeShares;
else if (amount > freeShares) revert BoringOnChainQueue__RescueCannotTakeSharesFromActiveRequests();
} else {
if (amount == type(uint256).max) amount = token.balanceOf(address(this));
}
token.safeTransfer(to, amount);
}
/**
* @notice Pause this contract, which prevents future calls to any functions that
* create new requests, or solve active requests.
* @dev Callable by MULTISIG_ROLE.
*/
function pause() external requiresAuth {
isPaused = true;
emit Paused();
}
/**
* @notice Unpause this contract, which allows future calls to any functions that
* create new requests, or solve active requests.
* @dev Callable by MULTISIG_ROLE.
*/
function unpause() external requiresAuth {
isPaused = false;
emit Unpaused();
}
/**
* @notice Update a new withdraw asset or existing.
* @dev Callable by MULTISIG_ROLE.
* @param assetOut The asset to withdraw.
* @param secondsToMaturity The time in seconds it takes for the withdraw to mature.
* @param minimumSecondsToDeadline The minimum time in seconds a withdraw request must be valid for before it is expired.
* @param minDiscount The minimum discount allowed for a withdraw request.
* @param maxDiscount The maximum discount allowed for a withdraw request.
* @param minimumShares The minimum amount of shares that can be withdrawn.
*/
function updateWithdrawAsset(
address assetOut,
uint24 secondsToMaturity,
uint24 minimumSecondsToDeadline,
uint16 minDiscount,
uint16 maxDiscount,
uint96 minimumShares
) external requiresAuth {
// Validate input.
if (maxDiscount > MAX_DISCOUNT) revert BoringOnChainQueue__MAX_DISCOUNT();
if (secondsToMaturity > MAXIMUM_SECONDS_TO_MATURITY) {
revert BoringOnChainQueue__MAXIMUM_SECONDS_TO_MATURITY();
}
if (minimumSecondsToDeadline > MAXIMUM_MINIMUM_SECONDS_TO_DEADLINE) {
revert BoringOnChainQueue__MAXIMUM_MINIMUM_SECONDS_TO_DEADLINE();
}
if (minDiscount > maxDiscount) revert BoringOnChainQueue__BadDiscount();
// Make sure accountant can price it.
accountant.getRateInQuoteSafe(ERC20(assetOut));
withdrawAssets[assetOut] = WithdrawAsset({
allowWithdraws: true,
secondsToMaturity: secondsToMaturity,
minimumSecondsToDeadline: minimumSecondsToDeadline,
minDiscount: minDiscount,
maxDiscount: maxDiscount,
minimumShares: minimumShares
});
emit WithdrawAssetUpdated(
assetOut, secondsToMaturity, minimumSecondsToDeadline, minDiscount, maxDiscount, minimumShares
);
}
/**
* @notice Stop withdraws in an asset.
* @dev Callable by MULTISIG_ROLE.
* @param assetOut The asset to stop withdraws in.
*/
function stopWithdrawsInAsset(address assetOut) external requiresAuth {
withdrawAssets[assetOut].allowWithdraws = false;
emit WithdrawAssetStopped(assetOut);
}
/**
* @notice Cancel multiple user withdraws.
* @dev Callable by STRATEGIST_MULTISIG_ROLE.
*/
function cancelUserWithdraws(OnChainWithdraw[] calldata requests)
external
requiresAuth
returns (bytes32[] memory canceledRequestIds)
{
uint256 requestsLength = requests.length;
canceledRequestIds = new bytes32[](requestsLength);
for (uint256 i = 0; i < requestsLength; ++i) {
canceledRequestIds[i] = _cancelOnChainWithdraw(requests[i]);
}
}
//=============================== USER FUNCTIONS ================================
/**
* @notice Request an on-chain withdraw.
* @param assetOut The asset to withdraw.
* @param amountOfShares The amount of shares to withdraw.
* @param discount The discount to apply to the withdraw in bps.
* @param secondsToDeadline The time in seconds the request is valid for.
* @return requestId The request Id.
*/
function requestOnChainWithdraw(address assetOut, uint128 amountOfShares, uint16 discount, uint24 secondsToDeadline)
external
virtual
requiresAuth
returns (bytes32 requestId)
{
WithdrawAsset memory withdrawAsset = withdrawAssets[assetOut];
_beforeNewRequest(withdrawAsset, amountOfShares, discount, secondsToDeadline);
boringVault.safeTransferFrom(msg.sender, address(this), amountOfShares);
(requestId,) = _queueOnChainWithdraw(
msg.sender, assetOut, amountOfShares, discount, withdrawAsset.secondsToMaturity, secondsToDeadline
);
}
/**
* @notice Request an on-chain withdraw with permit.
* @param assetOut The asset to withdraw.
* @param amountOfShares The amount of shares to withdraw.
* @param discount The discount to apply to the withdraw in bps.
* @param secondsToDeadline The time in seconds the request is valid for.
* @param permitDeadline The deadline for the permit.
* @param v The v value of the permit signature.
* @param r The r value of the permit signature.
* @param s The s value of the permit signature.
* @return requestId The request Id.
*/
function requestOnChainWithdrawWithPermit(
address assetOut,
uint128 amountOfShares,
uint16 discount,
uint24 secondsToDeadline,
uint256 permitDeadline,
uint8 v,
bytes32 r,
bytes32 s
) external virtual requiresAuth returns (bytes32 requestId) {
WithdrawAsset memory withdrawAsset = withdrawAssets[assetOut];
_beforeNewRequest(withdrawAsset, amountOfShares, discount, secondsToDeadline);
try boringVault.permit(msg.sender, address(this), amountOfShares, permitDeadline, v, r, s) {}
catch {
if (boringVault.allowance(msg.sender, address(this)) < amountOfShares) {
revert BoringOnChainQueue__PermitFailedAndAllowanceTooLow();
}
}
boringVault.safeTransferFrom(msg.sender, address(this), amountOfShares);
(requestId,) = _queueOnChainWithdraw(
msg.sender, assetOut, amountOfShares, discount, withdrawAsset.secondsToMaturity, secondsToDeadline
);
}
/**
* @notice Cancel an on-chain withdraw.
* @param request The request to cancel.
* @return requestId The request Id.
*/
function cancelOnChainWithdraw(OnChainWithdraw memory request)
external
virtual
requiresAuth
returns (bytes32 requestId)
{
requestId = _cancelOnChainWithdrawWithUserCheck(request);
}
/**
* @notice Replace an on-chain withdraw.
* @param oldRequest The request to replace.
* @param discount The discount to apply to the new withdraw request in bps.
* @param secondsToDeadline The time in seconds the new withdraw request is valid for.
* @return oldRequestId The request Id of the old withdraw request.
* @return newRequestId The request Id of the new withdraw request.
*/
function replaceOnChainWithdraw(OnChainWithdraw memory oldRequest, uint16 discount, uint24 secondsToDeadline)
external
virtual
requiresAuth
returns (bytes32 oldRequestId, bytes32 newRequestId)
{
(oldRequestId, newRequestId) = _replaceOnChainWithdrawWithUserCheck(oldRequest, discount, secondsToDeadline);
}
//============================== SOLVER FUNCTIONS ===============================
/**
* @notice Solve multiple on-chain withdraws.
* @dev If `solveData` is empty, this contract will skip the callback function.
* @param requests The requests to solve.
* @param solveData The data to use to solve the requests.
* @param solver The address of the solver.
*/
function solveOnChainWithdraws(OnChainWithdraw[] calldata requests, bytes calldata solveData, address solver)
external
requiresAuth
{
if (isPaused) revert BoringOnChainQueue__Paused();
ERC20 solveAsset = ERC20(requests[0].assetOut);
uint256 requiredAssets;
uint256 totalShares;
uint256 requestsLength = requests.length;
for (uint256 i = 0; i < requestsLength; ++i) {
if (address(solveAsset) != requests[i].assetOut) revert BoringOnChainQueue__SolveAssetMismatch();
uint256 maturity = requests[i].creationTime + requests[i].secondsToMaturity;
if (block.timestamp < maturity) revert BoringOnChainQueue__NotMatured();
uint256 deadline = maturity + requests[i].secondsToDeadline;
if (block.timestamp > deadline) revert BoringOnChainQueue__DeadlinePassed();
requiredAssets += requests[i].amountOfAssets;
totalShares += requests[i].amountOfShares;
bytes32 requestId = _dequeueOnChainWithdraw(requests[i]);
emit OnChainWithdrawSolved(requestId, requests[i].user, block.timestamp);
}
// Transfer shares to solver.
boringVault.safeTransfer(solver, totalShares);
// Run callback function if data is provided.
if (solveData.length > 0) {
IBoringSolver(solver).boringSolve(
msg.sender, address(boringVault), address(solveAsset), totalShares, requiredAssets, solveData
);
}
for (uint256 i = 0; i < requestsLength; ++i) {
solveAsset.safeTransferFrom(solver, requests[i].user, requests[i].amountOfAssets);
}
}
//============================== VIEW FUNCTIONS ===============================
/**
* @notice Get all request Ids currently in the queue.
* @dev Includes requests that are not mature, matured, and expired. But does not include requests that have been solved.
* @return requestIds The request Ids.
*/
function getRequestIds() public view returns (bytes32[] memory) {
return _withdrawRequests.values();
}
/**
* @notice Get the request Id for a request.
* @param request The request.
* @return requestId The request Id.
*/
function getRequestId(OnChainWithdraw calldata request) external pure returns (bytes32 requestId) {
return keccak256(abi.encode(request));
}
/**
* @notice Preview assets out from a withdraw request.
*/
function previewAssetsOut(address assetOut, uint128 amountOfShares, uint16 discount)
public
view
returns (uint128 amountOfAssets128)
{
uint256 price = accountant.getRateInQuoteSafe(ERC20(assetOut));
price = price.mulDivDown(1e4 - discount, 1e4);
uint256 amountOfAssets = uint256(amountOfShares).mulDivDown(price, ONE_SHARE);
if (amountOfAssets > type(uint128).max) revert BoringOnChainQueue__Overflow();
amountOfAssets128 = uint128(amountOfAssets);
}
//============================= INTERNAL FUNCTIONS ==============================
/**
* @notice Before a new request is made, validate the input.
* @param withdrawAsset The withdraw asset.
* @param amountOfShares The amount of shares to withdraw.
* @param discount The discount to apply to the withdraw in bps.
* @param secondsToDeadline The time in seconds the request is valid for.
*/
function _beforeNewRequest(
WithdrawAsset memory withdrawAsset,
uint128 amountOfShares,
uint16 discount,
uint24 secondsToDeadline
) internal view virtual {
if (isPaused) revert BoringOnChainQueue__Paused();
if (!withdrawAsset.allowWithdraws) revert BoringOnChainQueue__WithdrawsNotAllowedForAsset();
if (discount < withdrawAsset.minDiscount || discount > withdrawAsset.maxDiscount) {
revert BoringOnChainQueue__BadDiscount();
}
if (amountOfShares < withdrawAsset.minimumShares) revert BoringOnChainQueue__BadShareAmount();
if (secondsToDeadline < withdrawAsset.minimumSecondsToDeadline) revert BoringOnChainQueue__BadDeadline();
}
/**
* @notice Cancel an on-chain withdraw.
* @dev Verifies that the request user is the same as the msg.sender.
* @param request The request to cancel.
* @return requestId The request Id.
*/
function _cancelOnChainWithdrawWithUserCheck(OnChainWithdraw memory request)
internal
virtual
onlyRequestUser(request.user, msg.sender)
returns (bytes32 requestId)
{
requestId = _cancelOnChainWithdraw(request);
}
/**
* @notice Cancel an on-chain withdraw.
* @param request The request to cancel.
* @return requestId The request Id.
*/
function _cancelOnChainWithdraw(OnChainWithdraw memory request) internal virtual returns (bytes32 requestId) {
requestId = _dequeueOnChainWithdraw(request);
boringVault.safeTransfer(request.user, request.amountOfShares);
emit OnChainWithdrawCancelled(requestId, request.user, block.timestamp);
}
/**
* @notice Replace an on-chain withdraw.
* @dev Verifies that the request user is the same as the msg.sender.
* @param oldRequest The request to replace.
* @param discount The discount to apply to the new withdraw request in bps.
* @param secondsToDeadline The time in seconds the new withdraw request is valid for.
* @return oldRequestId The request Id of the old withdraw request.
* @return newRequestId The request Id of the new withdraw request.
*/
function _replaceOnChainWithdrawWithUserCheck(
OnChainWithdraw memory oldRequest,
uint16 discount,
uint24 secondsToDeadline
)
internal
virtual
onlyRequestUser(oldRequest.user, msg.sender)
returns (bytes32 oldRequestId, bytes32 newRequestId)
{
(oldRequestId, newRequestId) = _replaceOnChainWithdraw(oldRequest, discount, secondsToDeadline);
}
/**
* @notice Replace an on-chain withdraw.
* @param oldRequest The request to replace.
* @param discount The discount to apply to the new withdraw request in bps.
* @param secondsToDeadline The time in seconds the new withdraw request is valid for.
* @return oldRequestId The request Id of the old withdraw request.
* @return newRequestId The request Id of the new withdraw request.
*/
function _replaceOnChainWithdraw(OnChainWithdraw memory oldRequest, uint16 discount, uint24 secondsToDeadline)
internal
virtual
onlyRequestUser(oldRequest.user, msg.sender)
returns (bytes32 oldRequestId, bytes32 newRequestId)
{
WithdrawAsset memory withdrawAsset = withdrawAssets[oldRequest.assetOut];
_beforeNewRequest(withdrawAsset, oldRequest.amountOfShares, discount, secondsToDeadline);
oldRequestId = _dequeueOnChainWithdraw(oldRequest);
emit OnChainWithdrawCancelled(oldRequestId, oldRequest.user, block.timestamp);
// Create new request.
(newRequestId,) = _queueOnChainWithdraw(
oldRequest.user,
oldRequest.assetOut,
oldRequest.amountOfShares,
discount,
withdrawAsset.secondsToMaturity,
secondsToDeadline
);
}
/**
* @notice Queue an on-chain withdraw.
* @dev Reverts if the request is already in the queue. Though this should be impossible.
* @param user The user that made the request.
* @param assetOut The asset to withdraw.
* @param amountOfShares The amount of shares to withdraw.
* @param discount The discount to apply to the withdraw in bps.
* @param secondsToMaturity The time in seconds it takes for the asset to mature.
* @param secondsToDeadline The time in seconds the request is valid for.
* @return requestId The request Id.
*/
function _queueOnChainWithdraw(
address user,
address assetOut,
uint128 amountOfShares,
uint16 discount,
uint24 secondsToMaturity,
uint24 secondsToDeadline
) internal virtual returns (bytes32 requestId, OnChainWithdraw memory req) {
// Create new request.
uint96 requestNonce;
// See nonce definition for unchecked safety.
unchecked {
// Set request nonce as current nonce, then increment nonce.
requestNonce = nonce++;
}
uint128 amountOfAssets128 = previewAssetsOut(assetOut, amountOfShares, discount);
uint40 timeNow = uint40(block.timestamp); // Safe to cast to uint40 as it won't overflow for 10s of thousands of years
req = OnChainWithdraw({
nonce: requestNonce,
user: user,
assetOut: assetOut,
amountOfShares: amountOfShares,
amountOfAssets: amountOfAssets128,
creationTime: timeNow,
secondsToMaturity: secondsToMaturity,
secondsToDeadline: secondsToDeadline
});
requestId = keccak256(abi.encode(req));
bool addedToSet = _withdrawRequests.add(requestId);
if (!addedToSet) revert BoringOnChainQueue__Keccak256Collision();
emit OnChainWithdrawRequested(
requestId,
user,
assetOut,
requestNonce,
amountOfShares,
amountOfAssets128,
timeNow,
secondsToMaturity,
secondsToDeadline
);
}
/**
* @notice Dequeue an on-chain withdraw.
* @dev Reverts if the request is not in the queue.
* @dev Does not remove the request from the onChainWithdraws mapping, so that
* it can be referenced later by off-chain systems if needed.
* @param request The request to dequeue.
* @return requestId The request Id.
*/
function _dequeueOnChainWithdraw(OnChainWithdraw memory request) internal virtual returns (bytes32 requestId) {
// Remove request from queue.
requestId = keccak256(abi.encode(request));
bool removedFromSet = _withdrawRequests.remove(requestId);
if (!removedFromSet) revert BoringOnChainQueue__RequestNotFound();
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (token/ERC1155/IERC1155Receiver.sol)
pragma solidity ^0.8.20;
import {IERC165} from "../../utils/introspection/IERC165.sol";
/**
* @dev Interface that must be implemented by smart contracts in order to receive
* ERC-1155 token transfers.
*/
interface IERC1155Receiver is IERC165 {
/**
* @dev Handles the receipt of a single ERC-1155 token type. This function is
* called at the end of a `safeTransferFrom` after the balance has been updated.
*
* NOTE: To accept the transfer, this must return
* `bytes4(keccak256("onERC1155Received(address,address,uint256,uint256,bytes)"))`
* (i.e. 0xf23a6e61, or its own function selector).
*
* @param operator The address which initiated the transfer (i.e. msg.sender)
* @param from The address which previously owned the token
* @param id The ID of the token being transferred
* @param value The amount of tokens being transferred
* @param data Additional data with no specified format
* @return `bytes4(keccak256("onERC1155Received(address,address,uint256,uint256,bytes)"))` if transfer is allowed
*/
function onERC1155Received(
address operator,
address from,
uint256 id,
uint256 value,
bytes calldata data
) external returns (bytes4);
/**
* @dev Handles the receipt of a multiple ERC-1155 token types. This function
* is called at the end of a `safeBatchTransferFrom` after the balances have
* been updated.
*
* NOTE: To accept the transfer(s), this must return
* `bytes4(keccak256("onERC1155BatchReceived(address,address,uint256[],uint256[],bytes)"))`
* (i.e. 0xbc197c81, or its own function selector).
*
* @param operator The address which initiated the batch transfer (i.e. msg.sender)
* @param from The address which previously owned the token
* @param ids An array containing ids of each token being transferred (order and length must match values array)
* @param values An array containing amounts of each token being transferred (order and length must match ids array)
* @param data Additional data with no specified format
* @return `bytes4(keccak256("onERC1155BatchReceived(address,address,uint256[],uint256[],bytes)"))` if transfer is allowed
*/
function onERC1155BatchReceived(
address operator,
address from,
uint256[] calldata ids,
uint256[] calldata values,
bytes calldata data
) external returns (bytes4);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (token/ERC1155/utils/ERC1155Holder.sol)
pragma solidity ^0.8.20;
import {IERC165, ERC165} from "../../../utils/introspection/ERC165.sol";
import {IERC1155Receiver} from "../IERC1155Receiver.sol";
/**
* @dev Simple implementation of `IERC1155Receiver` that will allow a contract to hold ERC-1155 tokens.
*
* IMPORTANT: When inheriting this contract, you must include a way to use the received tokens, otherwise they will be
* stuck.
*/
abstract contract ERC1155Holder is ERC165, IERC1155Receiver {
/// @inheritdoc IERC165
function supportsInterface(bytes4 interfaceId) public view virtual override(ERC165, IERC165) returns (bool) {
return interfaceId == type(IERC1155Receiver).interfaceId || super.supportsInterface(interfaceId);
}
function onERC1155Received(
address,
address,
uint256,
uint256,
bytes memory
) public virtual override returns (bytes4) {
return this.onERC1155Received.selector;
}
function onERC1155BatchReceived(
address,
address,
uint256[] memory,
uint256[] memory,
bytes memory
) public virtual override returns (bytes4) {
return this.onERC1155BatchReceived.selector;
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (token/ERC721/IERC721Receiver.sol)
pragma solidity ^0.8.20;
/**
* @title ERC-721 token receiver interface
* @dev Interface for any contract that wants to support safeTransfers
* from ERC-721 asset contracts.
*/
interface IERC721Receiver {
/**
* @dev Whenever an {IERC721} `tokenId` token is transferred to this contract via {IERC721-safeTransferFrom}
* by `operator` from `from`, this function is called.
*
* It must return its Solidity selector to confirm the token transfer.
* If any other value is returned or the interface is not implemented by the recipient, the transfer will be
* reverted.
*
* The selector can be obtained in Solidity with `IERC721Receiver.onERC721Received.selector`.
*/
function onERC721Received(
address operator,
address from,
uint256 tokenId,
bytes calldata data
) external returns (bytes4);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC721/utils/ERC721Holder.sol)
pragma solidity ^0.8.20;
import {IERC721Receiver} from "../IERC721Receiver.sol";
/**
* @dev Implementation of the {IERC721Receiver} interface.
*
* Accepts all token transfers.
* Make sure the contract is able to use its token with {IERC721-safeTransferFrom}, {IERC721-approve} or
* {IERC721-setApprovalForAll}.
*/
abstract contract ERC721Holder is IERC721Receiver {
/**
* @dev See {IERC721Receiver-onERC721Received}.
*
* Always returns `IERC721Receiver.onERC721Received.selector`.
*/
function onERC721Received(address, address, uint256, bytes memory) public virtual returns (bytes4) {
return this.onERC721Received.selector;
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.2.0) (utils/Address.sol)
pragma solidity ^0.8.20;
import {Errors} from "./Errors.sol";
/**
* @dev Collection of functions related to the address type
*/
library Address {
/**
* @dev There's no code at `target` (it is not a contract).
*/
error AddressEmptyCode(address target);
/**
* @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 Errors.InsufficientBalance(address(this).balance, amount);
}
(bool success, bytes memory returndata) = recipient.call{value: amount}("");
if (!success) {
_revert(returndata);
}
}
/**
* @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
* {Errors.FailedCall} 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 Errors.InsufficientBalance(address(this).balance, value);
}
(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 {Errors.FailedCall}) 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 {Errors.FailedCall} 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 {Errors.FailedCall}.
*/
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
assembly ("memory-safe") {
revert(add(returndata, 0x20), mload(returndata))
}
} else {
revert Errors.FailedCall();
}
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.3.0) (utils/Arrays.sol)
// This file was procedurally generated from scripts/generate/templates/Arrays.js.
pragma solidity ^0.8.20;
import {Comparators} from "./Comparators.sol";
import {SlotDerivation} from "./SlotDerivation.sol";
import {StorageSlot} from "./StorageSlot.sol";
import {Math} from "./math/Math.sol";
/**
* @dev Collection of functions related to array types.
*/
library Arrays {
using SlotDerivation for bytes32;
using StorageSlot for bytes32;
/**
* @dev Sort an array of uint256 (in memory) following the provided comparator function.
*
* This function does the sorting "in place", meaning that it overrides the input. The object is returned for
* convenience, but that returned value can be discarded safely if the caller has a memory pointer to the array.
*
* NOTE: this function's cost is `O(n · log(n))` in average and `O(n²)` in the worst case, with n the length of the
* array. Using it in view functions that are executed through `eth_call` is safe, but one should be very careful
* when executing this as part of a transaction. If the array being sorted is too large, the sort operation may
* consume more gas than is available in a block, leading to potential DoS.
*
* IMPORTANT: Consider memory side-effects when using custom comparator functions that access memory in an unsafe way.
*/
function sort(
uint256[] memory array,
function(uint256, uint256) pure returns (bool) comp
) internal pure returns (uint256[] memory) {
_quickSort(_begin(array), _end(array), comp);
return array;
}
/**
* @dev Variant of {sort} that sorts an array of uint256 in increasing order.
*/
function sort(uint256[] memory array) internal pure returns (uint256[] memory) {
sort(array, Comparators.lt);
return array;
}
/**
* @dev Sort an array of address (in memory) following the provided comparator function.
*
* This function does the sorting "in place", meaning that it overrides the input. The object is returned for
* convenience, but that returned value can be discarded safely if the caller has a memory pointer to the array.
*
* NOTE: this function's cost is `O(n · log(n))` in average and `O(n²)` in the worst case, with n the length of the
* array. Using it in view functions that are executed through `eth_call` is safe, but one should be very careful
* when executing this as part of a transaction. If the array being sorted is too large, the sort operation may
* consume more gas than is available in a block, leading to potential DoS.
*
* IMPORTANT: Consider memory side-effects when using custom comparator functions that access memory in an unsafe way.
*/
function sort(
address[] memory array,
function(address, address) pure returns (bool) comp
) internal pure returns (address[] memory) {
sort(_castToUint256Array(array), _castToUint256Comp(comp));
return array;
}
/**
* @dev Variant of {sort} that sorts an array of address in increasing order.
*/
function sort(address[] memory array) internal pure returns (address[] memory) {
sort(_castToUint256Array(array), Comparators.lt);
return array;
}
/**
* @dev Sort an array of bytes32 (in memory) following the provided comparator function.
*
* This function does the sorting "in place", meaning that it overrides the input. The object is returned for
* convenience, but that returned value can be discarded safely if the caller has a memory pointer to the array.
*
* NOTE: this function's cost is `O(n · log(n))` in average and `O(n²)` in the worst case, with n the length of the
* array. Using it in view functions that are executed through `eth_call` is safe, but one should be very careful
* when executing this as part of a transaction. If the array being sorted is too large, the sort operation may
* consume more gas than is available in a block, leading to potential DoS.
*
* IMPORTANT: Consider memory side-effects when using custom comparator functions that access memory in an unsafe way.
*/
function sort(
bytes32[] memory array,
function(bytes32, bytes32) pure returns (bool) comp
) internal pure returns (bytes32[] memory) {
sort(_castToUint256Array(array), _castToUint256Comp(comp));
return array;
}
/**
* @dev Variant of {sort} that sorts an array of bytes32 in increasing order.
*/
function sort(bytes32[] memory array) internal pure returns (bytes32[] memory) {
sort(_castToUint256Array(array), Comparators.lt);
return array;
}
/**
* @dev Performs a quick sort of a segment of memory. The segment sorted starts at `begin` (inclusive), and stops
* at end (exclusive). Sorting follows the `comp` comparator.
*
* Invariant: `begin <= end`. This is the case when initially called by {sort} and is preserved in subcalls.
*
* IMPORTANT: Memory locations between `begin` and `end` are not validated/zeroed. This function should
* be used only if the limits are within a memory array.
*/
function _quickSort(uint256 begin, uint256 end, function(uint256, uint256) pure returns (bool) comp) private pure {
unchecked {
if (end - begin < 0x40) return;
// Use first element as pivot
uint256 pivot = _mload(begin);
// Position where the pivot should be at the end of the loop
uint256 pos = begin;
for (uint256 it = begin + 0x20; it < end; it += 0x20) {
if (comp(_mload(it), pivot)) {
// If the value stored at the iterator's position comes before the pivot, we increment the
// position of the pivot and move the value there.
pos += 0x20;
_swap(pos, it);
}
}
_swap(begin, pos); // Swap pivot into place
_quickSort(begin, pos, comp); // Sort the left side of the pivot
_quickSort(pos + 0x20, end, comp); // Sort the right side of the pivot
}
}
/**
* @dev Pointer to the memory location of the first element of `array`.
*/
function _begin(uint256[] memory array) private pure returns (uint256 ptr) {
assembly ("memory-safe") {
ptr := add(array, 0x20)
}
}
/**
* @dev Pointer to the memory location of the first memory word (32bytes) after `array`. This is the memory word
* that comes just after the last element of the array.
*/
function _end(uint256[] memory array) private pure returns (uint256 ptr) {
unchecked {
return _begin(array) + array.length * 0x20;
}
}
/**
* @dev Load memory word (as a uint256) at location `ptr`.
*/
function _mload(uint256 ptr) private pure returns (uint256 value) {
assembly {
value := mload(ptr)
}
}
/**
* @dev Swaps the elements memory location `ptr1` and `ptr2`.
*/
function _swap(uint256 ptr1, uint256 ptr2) private pure {
assembly {
let value1 := mload(ptr1)
let value2 := mload(ptr2)
mstore(ptr1, value2)
mstore(ptr2, value1)
}
}
/// @dev Helper: low level cast address memory array to uint256 memory array
function _castToUint256Array(address[] memory input) private pure returns (uint256[] memory output) {
assembly {
output := input
}
}
/// @dev Helper: low level cast bytes32 memory array to uint256 memory array
function _castToUint256Array(bytes32[] memory input) private pure returns (uint256[] memory output) {
assembly {
output := input
}
}
/// @dev Helper: low level cast address comp function to uint256 comp function
function _castToUint256Comp(
function(address, address) pure returns (bool) input
) private pure returns (function(uint256, uint256) pure returns (bool) output) {
assembly {
output := input
}
}
/// @dev Helper: low level cast bytes32 comp function to uint256 comp function
function _castToUint256Comp(
function(bytes32, bytes32) pure returns (bool) input
) private pure returns (function(uint256, uint256) pure returns (bool) output) {
assembly {
output := input
}
}
/**
* @dev Searches a sorted `array` and returns the first index that contains
* a value greater or equal to `element`. If no such index exists (i.e. all
* values in the array are strictly less than `element`), the array length is
* returned. Time complexity O(log n).
*
* NOTE: The `array` is expected to be sorted in ascending order, and to
* contain no repeated elements.
*
* IMPORTANT: Deprecated. This implementation behaves as {lowerBound} but lacks
* support for repeated elements in the array. The {lowerBound} function should
* be used instead.
*/
function findUpperBound(uint256[] storage array, uint256 element) internal view returns (uint256) {
uint256 low = 0;
uint256 high = array.length;
if (high == 0) {
return 0;
}
while (low < high) {
uint256 mid = Math.average(low, high);
// Note that mid will always be strictly less than high (i.e. it will be a valid array index)
// because Math.average rounds towards zero (it does integer division with truncation).
if (unsafeAccess(array, mid).value > element) {
high = mid;
} else {
low = mid + 1;
}
}
// At this point `low` is the exclusive upper bound. We will return the inclusive upper bound.
if (low > 0 && unsafeAccess(array, low - 1).value == element) {
return low - 1;
} else {
return low;
}
}
/**
* @dev Searches an `array` sorted in ascending order and returns the first
* index that contains a value greater or equal than `element`. If no such index
* exists (i.e. all values in the array are strictly less than `element`), the array
* length is returned. Time complexity O(log n).
*
* See C++'s https://en.cppreference.com/w/cpp/algorithm/lower_bound[lower_bound].
*/
function lowerBound(uint256[] storage array, uint256 element) internal view returns (uint256) {
uint256 low = 0;
uint256 high = array.length;
if (high == 0) {
return 0;
}
while (low < high) {
uint256 mid = Math.average(low, high);
// Note that mid will always be strictly less than high (i.e. it will be a valid array index)
// because Math.average rounds towards zero (it does integer division with truncation).
if (unsafeAccess(array, mid).value < element) {
// this cannot overflow because mid < high
unchecked {
low = mid + 1;
}
} else {
high = mid;
}
}
return low;
}
/**
* @dev Searches an `array` sorted in ascending order and returns the first
* index that contains a value strictly greater than `element`. If no such index
* exists (i.e. all values in the array are strictly less than `element`), the array
* length is returned. Time complexity O(log n).
*
* See C++'s https://en.cppreference.com/w/cpp/algorithm/upper_bound[upper_bound].
*/
function upperBound(uint256[] storage array, uint256 element) internal view returns (uint256) {
uint256 low = 0;
uint256 high = array.length;
if (high == 0) {
return 0;
}
while (low < high) {
uint256 mid = Math.average(low, high);
// Note that mid will always be strictly less than high (i.e. it will be a valid array index)
// because Math.average rounds towards zero (it does integer division with truncation).
if (unsafeAccess(array, mid).value > element) {
high = mid;
} else {
// this cannot overflow because mid < high
unchecked {
low = mid + 1;
}
}
}
return low;
}
/**
* @dev Same as {lowerBound}, but with an array in memory.
*/
function lowerBoundMemory(uint256[] memory array, uint256 element) internal pure returns (uint256) {
uint256 low = 0;
uint256 high = array.length;
if (high == 0) {
return 0;
}
while (low < high) {
uint256 mid = Math.average(low, high);
// Note that mid will always be strictly less than high (i.e. it will be a valid array index)
// because Math.average rounds towards zero (it does integer division with truncation).
if (unsafeMemoryAccess(array, mid) < element) {
// this cannot overflow because mid < high
unchecked {
low = mid + 1;
}
} else {
high = mid;
}
}
return low;
}
/**
* @dev Same as {upperBound}, but with an array in memory.
*/
function upperBoundMemory(uint256[] memory array, uint256 element) internal pure returns (uint256) {
uint256 low = 0;
uint256 high = array.length;
if (high == 0) {
return 0;
}
while (low < high) {
uint256 mid = Math.average(low, high);
// Note that mid will always be strictly less than high (i.e. it will be a valid array index)
// because Math.average rounds towards zero (it does integer division with truncation).
if (unsafeMemoryAccess(array, mid) > element) {
high = mid;
} else {
// this cannot overflow because mid < high
unchecked {
low = mid + 1;
}
}
}
return low;
}
/**
* @dev Access an array in an "unsafe" way. Skips solidity "index-out-of-range" check.
*
* WARNING: Only use if you are certain `pos` is lower than the array length.
*/
function unsafeAccess(address[] storage arr, uint256 pos) internal pure returns (StorageSlot.AddressSlot storage) {
bytes32 slot;
assembly ("memory-safe") {
slot := arr.slot
}
return slot.deriveArray().offset(pos).getAddressSlot();
}
/**
* @dev Access an array in an "unsafe" way. Skips solidity "index-out-of-range" check.
*
* WARNING: Only use if you are certain `pos` is lower than the array length.
*/
function unsafeAccess(bytes32[] storage arr, uint256 pos) internal pure returns (StorageSlot.Bytes32Slot storage) {
bytes32 slot;
assembly ("memory-safe") {
slot := arr.slot
}
return slot.deriveArray().offset(pos).getBytes32Slot();
}
/**
* @dev Access an array in an "unsafe" way. Skips solidity "index-out-of-range" check.
*
* WARNING: Only use if you are certain `pos` is lower than the array length.
*/
function unsafeAccess(uint256[] storage arr, uint256 pos) internal pure returns (StorageSlot.Uint256Slot storage) {
bytes32 slot;
assembly ("memory-safe") {
slot := arr.slot
}
return slot.deriveArray().offset(pos).getUint256Slot();
}
/**
* @dev Access an array in an "unsafe" way. Skips solidity "index-out-of-range" check.
*
* WARNING: Only use if you are certain `pos` is lower than the array length.
*/
function unsafeAccess(bytes[] storage arr, uint256 pos) internal pure returns (StorageSlot.BytesSlot storage) {
bytes32 slot;
assembly ("memory-safe") {
slot := arr.slot
}
return slot.deriveArray().offset(pos).getBytesSlot();
}
/**
* @dev Access an array in an "unsafe" way. Skips solidity "index-out-of-range" check.
*
* WARNING: Only use if you are certain `pos` is lower than the array length.
*/
function unsafeAccess(string[] storage arr, uint256 pos) internal pure returns (StorageSlot.StringSlot storage) {
bytes32 slot;
assembly ("memory-safe") {
slot := arr.slot
}
return slot.deriveArray().offset(pos).getStringSlot();
}
/**
* @dev Access an array in an "unsafe" way. Skips solidity "index-out-of-range" check.
*
* WARNING: Only use if you are certain `pos` is lower than the array length.
*/
function unsafeMemoryAccess(address[] memory arr, uint256 pos) internal pure returns (address res) {
assembly {
res := mload(add(add(arr, 0x20), mul(pos, 0x20)))
}
}
/**
* @dev Access an array in an "unsafe" way. Skips solidity "index-out-of-range" check.
*
* WARNING: Only use if you are certain `pos` is lower than the array length.
*/
function unsafeMemoryAccess(bytes32[] memory arr, uint256 pos) internal pure returns (bytes32 res) {
assembly {
res := mload(add(add(arr, 0x20), mul(pos, 0x20)))
}
}
/**
* @dev Access an array in an "unsafe" way. Skips solidity "index-out-of-range" check.
*
* WARNING: Only use if you are certain `pos` is lower than the array length.
*/
function unsafeMemoryAccess(uint256[] memory arr, uint256 pos) internal pure returns (uint256 res) {
assembly {
res := mload(add(add(arr, 0x20), mul(pos, 0x20)))
}
}
/**
* @dev Access an array in an "unsafe" way. Skips solidity "index-out-of-range" check.
*
* WARNING: Only use if you are certain `pos` is lower than the array length.
*/
function unsafeMemoryAccess(bytes[] memory arr, uint256 pos) internal pure returns (bytes memory res) {
assembly {
res := mload(add(add(arr, 0x20), mul(pos, 0x20)))
}
}
/**
* @dev Access an array in an "unsafe" way. Skips solidity "index-out-of-range" check.
*
* WARNING: Only use if you are certain `pos` is lower than the array length.
*/
function unsafeMemoryAccess(string[] memory arr, uint256 pos) internal pure returns (string memory res) {
assembly {
res := mload(add(add(arr, 0x20), mul(pos, 0x20)))
}
}
/**
* @dev Helper to set the length of a dynamic array. Directly writing to `.length` is forbidden.
*
* WARNING: this does not clear elements if length is reduced, of initialize elements if length is increased.
*/
function unsafeSetLength(address[] storage array, uint256 len) internal {
assembly ("memory-safe") {
sstore(array.slot, len)
}
}
/**
* @dev Helper to set the length of a dynamic array. Directly writing to `.length` is forbidden.
*
* WARNING: this does not clear elements if length is reduced, of initialize elements if length is increased.
*/
function unsafeSetLength(bytes32[] storage array, uint256 len) internal {
assembly ("memory-safe") {
sstore(array.slot, len)
}
}
/**
* @dev Helper to set the length of a dynamic array. Directly writing to `.length` is forbidden.
*
* WARNING: this does not clear elements if length is reduced, of initialize elements if length is increased.
*/
function unsafeSetLength(uint256[] storage array, uint256 len) internal {
assembly ("memory-safe") {
sstore(array.slot, len)
}
}
/**
* @dev Helper to set the length of a dynamic array. Directly writing to `.length` is forbidden.
*
* WARNING: this does not clear elements if length is reduced, of initialize elements if length is increased.
*/
function unsafeSetLength(bytes[] storage array, uint256 len) internal {
assembly ("memory-safe") {
sstore(array.slot, len)
}
}
/**
* @dev Helper to set the length of a dynamic array. Directly writing to `.length` is forbidden.
*
* WARNING: this does not clear elements if length is reduced, of initialize elements if length is increased.
*/
function unsafeSetLength(string[] storage array, uint256 len) internal {
assembly ("memory-safe") {
sstore(array.slot, len)
}
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (utils/Comparators.sol)
pragma solidity ^0.8.20;
/**
* @dev Provides a set of functions to compare values.
*
* _Available since v5.1._
*/
library Comparators {
function lt(uint256 a, uint256 b) internal pure returns (bool) {
return a < b;
}
function gt(uint256 a, uint256 b) internal pure returns (bool) {
return a > b;
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (utils/Errors.sol)
pragma solidity ^0.8.20;
/**
* @dev Collection of common custom errors used in multiple contracts
*
* IMPORTANT: Backwards compatibility is not guaranteed in future versions of the library.
* It is recommended to avoid relying on the error API for critical functionality.
*
* _Available since v5.1._
*/
library Errors {
/**
* @dev The ETH balance of the account is not enough to perform the operation.
*/
error InsufficientBalance(uint256 balance, uint256 needed);
/**
* @dev A call to an address target failed. The target may have reverted.
*/
error FailedCall();
/**
* @dev The deployment failed.
*/
error FailedDeployment();
/**
* @dev A necessary precompile is missing.
*/
error MissingPrecompile(address);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (utils/Panic.sol)
pragma solidity ^0.8.20;
/**
* @dev Helper library for emitting standardized panic codes.
*
* ```solidity
* contract Example {
* using Panic for uint256;
*
* // Use any of the declared internal constants
* function foo() { Panic.GENERIC.panic(); }
*
* // Alternatively
* function foo() { Panic.panic(Panic.GENERIC); }
* }
* ```
*
* Follows the list from https://github.com/ethereum/solidity/blob/v0.8.24/libsolutil/ErrorCodes.h[libsolutil].
*
* _Available since v5.1._
*/
// slither-disable-next-line unused-state
library Panic {
/// @dev generic / unspecified error
uint256 internal constant GENERIC = 0x00;
/// @dev used by the assert() builtin
uint256 internal constant ASSERT = 0x01;
/// @dev arithmetic underflow or overflow
uint256 internal constant UNDER_OVERFLOW = 0x11;
/// @dev division or modulo by zero
uint256 internal constant DIVISION_BY_ZERO = 0x12;
/// @dev enum conversion error
uint256 internal constant ENUM_CONVERSION_ERROR = 0x21;
/// @dev invalid encoding in storage
uint256 internal constant STORAGE_ENCODING_ERROR = 0x22;
/// @dev empty array pop
uint256 internal constant EMPTY_ARRAY_POP = 0x31;
/// @dev array out of bounds access
uint256 internal constant ARRAY_OUT_OF_BOUNDS = 0x32;
/// @dev resource error (too large allocation or too large array)
uint256 internal constant RESOURCE_ERROR = 0x41;
/// @dev calling invalid internal function
uint256 internal constant INVALID_INTERNAL_FUNCTION = 0x51;
/// @dev Reverts with a panic code. Recommended to use with
/// the internal constants with predefined codes.
function panic(uint256 code) internal pure {
assembly ("memory-safe") {
mstore(0x00, 0x4e487b71)
mstore(0x20, code)
revert(0x1c, 0x24)
}
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.3.0) (utils/SlotDerivation.sol)
// This file was procedurally generated from scripts/generate/templates/SlotDerivation.js.
pragma solidity ^0.8.20;
/**
* @dev Library for computing storage (and transient storage) locations from namespaces and deriving slots
* corresponding to standard patterns. The derivation method for array and mapping matches the storage layout used by
* the solidity language / compiler.
*
* See https://docs.soliditylang.org/en/v0.8.20/internals/layout_in_storage.html#mappings-and-dynamic-arrays[Solidity docs for mappings and dynamic arrays.].
*
* Example usage:
* ```solidity
* contract Example {
* // Add the library methods
* using StorageSlot for bytes32;
* using SlotDerivation for bytes32;
*
* // Declare a namespace
* string private constant _NAMESPACE = "<namespace>"; // eg. OpenZeppelin.Slot
*
* function setValueInNamespace(uint256 key, address newValue) internal {
* _NAMESPACE.erc7201Slot().deriveMapping(key).getAddressSlot().value = newValue;
* }
*
* function getValueInNamespace(uint256 key) internal view returns (address) {
* return _NAMESPACE.erc7201Slot().deriveMapping(key).getAddressSlot().value;
* }
* }
* ```
*
* TIP: Consider using this library along with {StorageSlot}.
*
* NOTE: This library provides a way to manipulate storage locations in a non-standard way. Tooling for checking
* upgrade safety will ignore the slots accessed through this library.
*
* _Available since v5.1._
*/
library SlotDerivation {
/**
* @dev Derive an ERC-7201 slot from a string (namespace).
*/
function erc7201Slot(string memory namespace) internal pure returns (bytes32 slot) {
assembly ("memory-safe") {
mstore(0x00, sub(keccak256(add(namespace, 0x20), mload(namespace)), 1))
slot := and(keccak256(0x00, 0x20), not(0xff))
}
}
/**
* @dev Add an offset to a slot to get the n-th element of a structure or an array.
*/
function offset(bytes32 slot, uint256 pos) internal pure returns (bytes32 result) {
unchecked {
return bytes32(uint256(slot) + pos);
}
}
/**
* @dev Derive the location of the first element in an array from the slot where the length is stored.
*/
function deriveArray(bytes32 slot) internal pure returns (bytes32 result) {
assembly ("memory-safe") {
mstore(0x00, slot)
result := keccak256(0x00, 0x20)
}
}
/**
* @dev Derive the location of a mapping element from the key.
*/
function deriveMapping(bytes32 slot, address key) internal pure returns (bytes32 result) {
assembly ("memory-safe") {
mstore(0x00, and(key, shr(96, not(0))))
mstore(0x20, slot)
result := keccak256(0x00, 0x40)
}
}
/**
* @dev Derive the location of a mapping element from the key.
*/
function deriveMapping(bytes32 slot, bool key) internal pure returns (bytes32 result) {
assembly ("memory-safe") {
mstore(0x00, iszero(iszero(key)))
mstore(0x20, slot)
result := keccak256(0x00, 0x40)
}
}
/**
* @dev Derive the location of a mapping element from the key.
*/
function deriveMapping(bytes32 slot, bytes32 key) internal pure returns (bytes32 result) {
assembly ("memory-safe") {
mstore(0x00, key)
mstore(0x20, slot)
result := keccak256(0x00, 0x40)
}
}
/**
* @dev Derive the location of a mapping element from the key.
*/
function deriveMapping(bytes32 slot, uint256 key) internal pure returns (bytes32 result) {
assembly ("memory-safe") {
mstore(0x00, key)
mstore(0x20, slot)
result := keccak256(0x00, 0x40)
}
}
/**
* @dev Derive the location of a mapping element from the key.
*/
function deriveMapping(bytes32 slot, int256 key) internal pure returns (bytes32 result) {
assembly ("memory-safe") {
mstore(0x00, key)
mstore(0x20, slot)
result := keccak256(0x00, 0x40)
}
}
/**
* @dev Derive the location of a mapping element from the key.
*/
function deriveMapping(bytes32 slot, string memory key) internal pure returns (bytes32 result) {
assembly ("memory-safe") {
let length := mload(key)
let begin := add(key, 0x20)
let end := add(begin, length)
let cache := mload(end)
mstore(end, slot)
result := keccak256(begin, add(length, 0x20))
mstore(end, cache)
}
}
/**
* @dev Derive the location of a mapping element from the key.
*/
function deriveMapping(bytes32 slot, bytes memory key) internal pure returns (bytes32 result) {
assembly ("memory-safe") {
let length := mload(key)
let begin := add(key, 0x20)
let end := add(begin, length)
let cache := mload(end)
mstore(end, slot)
result := keccak256(begin, add(length, 0x20))
mstore(end, cache)
}
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (utils/StorageSlot.sol)
// This file was procedurally generated from scripts/generate/templates/StorageSlot.js.
pragma solidity ^0.8.20;
/**
* @dev Library for reading and writing primitive types to specific storage slots.
*
* Storage slots are often used to avoid storage conflict when dealing with upgradeable contracts.
* This library helps with reading and writing to such slots without the need for inline assembly.
*
* The functions in this library return Slot structs that contain a `value` member that can be used to read or write.
*
* Example usage to set ERC-1967 implementation slot:
* ```solidity
* contract ERC1967 {
* // Define the slot. Alternatively, use the SlotDerivation library to derive the slot.
* bytes32 internal constant _IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc;
*
* function _getImplementation() internal view returns (address) {
* return StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value;
* }
*
* function _setImplementation(address newImplementation) internal {
* require(newImplementation.code.length > 0);
* StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value = newImplementation;
* }
* }
* ```
*
* TIP: Consider using this library along with {SlotDerivation}.
*/
library StorageSlot {
struct AddressSlot {
address value;
}
struct BooleanSlot {
bool value;
}
struct Bytes32Slot {
bytes32 value;
}
struct Uint256Slot {
uint256 value;
}
struct Int256Slot {
int256 value;
}
struct StringSlot {
string value;
}
struct BytesSlot {
bytes value;
}
/**
* @dev Returns an `AddressSlot` with member `value` located at `slot`.
*/
function getAddressSlot(bytes32 slot) internal pure returns (AddressSlot storage r) {
assembly ("memory-safe") {
r.slot := slot
}
}
/**
* @dev Returns a `BooleanSlot` with member `value` located at `slot`.
*/
function getBooleanSlot(bytes32 slot) internal pure returns (BooleanSlot storage r) {
assembly ("memory-safe") {
r.slot := slot
}
}
/**
* @dev Returns a `Bytes32Slot` with member `value` located at `slot`.
*/
function getBytes32Slot(bytes32 slot) internal pure returns (Bytes32Slot storage r) {
assembly ("memory-safe") {
r.slot := slot
}
}
/**
* @dev Returns a `Uint256Slot` with member `value` located at `slot`.
*/
function getUint256Slot(bytes32 slot) internal pure returns (Uint256Slot storage r) {
assembly ("memory-safe") {
r.slot := slot
}
}
/**
* @dev Returns a `Int256Slot` with member `value` located at `slot`.
*/
function getInt256Slot(bytes32 slot) internal pure returns (Int256Slot storage r) {
assembly ("memory-safe") {
r.slot := slot
}
}
/**
* @dev Returns a `StringSlot` with member `value` located at `slot`.
*/
function getStringSlot(bytes32 slot) internal pure returns (StringSlot storage r) {
assembly ("memory-safe") {
r.slot := slot
}
}
/**
* @dev Returns an `StringSlot` representation of the string storage pointer `store`.
*/
function getStringSlot(string storage store) internal pure returns (StringSlot storage r) {
assembly ("memory-safe") {
r.slot := store.slot
}
}
/**
* @dev Returns a `BytesSlot` with member `value` located at `slot`.
*/
function getBytesSlot(bytes32 slot) internal pure returns (BytesSlot storage r) {
assembly ("memory-safe") {
r.slot := slot
}
}
/**
* @dev Returns an `BytesSlot` representation of the bytes storage pointer `store`.
*/
function getBytesSlot(bytes storage store) internal pure returns (BytesSlot storage r) {
assembly ("memory-safe") {
r.slot := store.slot
}
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (utils/introspection/ERC165.sol)
pragma solidity ^0.8.20;
import {IERC165} from "./IERC165.sol";
/**
* @dev Implementation of the {IERC165} interface.
*
* Contracts that want to implement ERC-165 should inherit from this contract and override {supportsInterface} to check
* for the additional interface id that will be supported. For example:
*
* ```solidity
* function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
* return interfaceId == type(MyInterface).interfaceId || super.supportsInterface(interfaceId);
* }
* ```
*/
abstract contract ERC165 is IERC165 {
/// @inheritdoc IERC165
function supportsInterface(bytes4 interfaceId) public view virtual returns (bool) {
return interfaceId == type(IERC165).interfaceId;
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (utils/introspection/IERC165.sol)
pragma solidity ^0.8.20;
/**
* @dev Interface of the ERC-165 standard, as defined in the
* https://eips.ethereum.org/EIPS/eip-165[ERC].
*
* Implementers can declare support of contract interfaces, which can then be
* queried by others ({ERC165Checker}).
*
* For an implementation, see {ERC165}.
*/
interface IERC165 {
/**
* @dev Returns true if this contract implements the interface defined by
* `interfaceId`. See the corresponding
* https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[ERC section]
* to learn more about how these ids are created.
*
* This function call must use less than 30 000 gas.
*/
function supportsInterface(bytes4 interfaceId) external view returns (bool);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.3.0) (utils/math/Math.sol)
pragma solidity ^0.8.20;
import {Panic} from "../Panic.sol";
import {SafeCast} from "./SafeCast.sol";
/**
* @dev Standard math utilities missing in the Solidity language.
*/
library Math {
enum Rounding {
Floor, // Toward negative infinity
Ceil, // Toward positive infinity
Trunc, // Toward zero
Expand // Away from zero
}
/**
* @dev Return the 512-bit addition of two uint256.
*
* The result is stored in two 256 variables such that sum = high * 2²56 + low.
*/
function add512(uint256 a, uint256 b) internal pure returns (uint256 high, uint256 low) {
assembly ("memory-safe") {
low := add(a, b)
high := lt(low, a)
}
}
/**
* @dev Return the 512-bit multiplication of two uint256.
*
* The result is stored in two 256 variables such that product = high * 2²56 + low.
*/
function mul512(uint256 a, uint256 b) internal pure returns (uint256 high, uint256 low) {
// 512-bit multiply [high low] = x * y. Compute the product mod 2²56 and mod 2²56 - 1, then use
// the Chinese Remainder Theorem to reconstruct the 512 bit result. The result is stored in two 256
// variables such that product = high * 2²56 + low.
assembly ("memory-safe") {
let mm := mulmod(a, b, not(0))
low := mul(a, b)
high := sub(sub(mm, low), lt(mm, low))
}
}
/**
* @dev Returns the addition of two unsigned integers, with a success flag (no overflow).
*/
function tryAdd(uint256 a, uint256 b) internal pure returns (bool success, uint256 result) {
unchecked {
uint256 c = a + b;
success = c >= a;
result = c * SafeCast.toUint(success);
}
}
/**
* @dev Returns the subtraction of two unsigned integers, with a success flag (no overflow).
*/
function trySub(uint256 a, uint256 b) internal pure returns (bool success, uint256 result) {
unchecked {
uint256 c = a - b;
success = c <= a;
result = c * SafeCast.toUint(success);
}
}
/**
* @dev Returns the multiplication of two unsigned integers, with a success flag (no overflow).
*/
function tryMul(uint256 a, uint256 b) internal pure returns (bool success, uint256 result) {
unchecked {
uint256 c = a * b;
assembly ("memory-safe") {
// Only true when the multiplication doesn't overflow
// (c / a == b) || (a == 0)
success := or(eq(div(c, a), b), iszero(a))
}
// equivalent to: success ? c : 0
result = c * SafeCast.toUint(success);
}
}
/**
* @dev Returns the division of two unsigned integers, with a success flag (no division by zero).
*/
function tryDiv(uint256 a, uint256 b) internal pure returns (bool success, uint256 result) {
unchecked {
success = b > 0;
assembly ("memory-safe") {
// The `DIV` opcode returns zero when the denominator is 0.
result := div(a, b)
}
}
}
/**
* @dev Returns the remainder of dividing two unsigned integers, with a success flag (no division by zero).
*/
function tryMod(uint256 a, uint256 b) internal pure returns (bool success, uint256 result) {
unchecked {
success = b > 0;
assembly ("memory-safe") {
// The `MOD` opcode returns zero when the denominator is 0.
result := mod(a, b)
}
}
}
/**
* @dev Unsigned saturating addition, bounds to `2²56 - 1` instead of overflowing.
*/
function saturatingAdd(uint256 a, uint256 b) internal pure returns (uint256) {
(bool success, uint256 result) = tryAdd(a, b);
return ternary(success, result, type(uint256).max);
}
/**
* @dev Unsigned saturating subtraction, bounds to zero instead of overflowing.
*/
function saturatingSub(uint256 a, uint256 b) internal pure returns (uint256) {
(, uint256 result) = trySub(a, b);
return result;
}
/**
* @dev Unsigned saturating multiplication, bounds to `2²56 - 1` instead of overflowing.
*/
function saturatingMul(uint256 a, uint256 b) internal pure returns (uint256) {
(bool success, uint256 result) = tryMul(a, b);
return ternary(success, result, type(uint256).max);
}
/**
* @dev Branchless ternary evaluation for `a ? b : c`. Gas costs are constant.
*
* IMPORTANT: This function may reduce bytecode size and consume less gas when used standalone.
* However, the compiler may optimize Solidity ternary operations (i.e. `a ? b : c`) to only compute
* one branch when needed, making this function more expensive.
*/
function ternary(bool condition, uint256 a, uint256 b) internal pure returns (uint256) {
unchecked {
// branchless ternary works because:
// b ^ (a ^ b) == a
// b ^ 0 == b
return b ^ ((a ^ b) * SafeCast.toUint(condition));
}
}
/**
* @dev Returns the largest of two numbers.
*/
function max(uint256 a, uint256 b) internal pure returns (uint256) {
return ternary(a > b, a, b);
}
/**
* @dev Returns the smallest of two numbers.
*/
function min(uint256 a, uint256 b) internal pure returns (uint256) {
return ternary(a < b, a, b);
}
/**
* @dev Returns the average of two numbers. The result is rounded towards
* zero.
*/
function average(uint256 a, uint256 b) internal pure returns (uint256) {
// (a + b) / 2 can overflow.
return (a & b) + (a ^ b) / 2;
}
/**
* @dev Returns the ceiling of the division of two numbers.
*
* This differs from standard division with `/` in that it rounds towards infinity instead
* of rounding towards zero.
*/
function ceilDiv(uint256 a, uint256 b) internal pure returns (uint256) {
if (b == 0) {
// Guarantee the same behavior as in a regular Solidity division.
Panic.panic(Panic.DIVISION_BY_ZERO);
}
// The following calculation ensures accurate ceiling division without overflow.
// Since a is non-zero, (a - 1) / b will not overflow.
// The largest possible result occurs when (a - 1) / b is type(uint256).max,
// but the largest value we can obtain is type(uint256).max - 1, which happens
// when a = type(uint256).max and b = 1.
unchecked {
return SafeCast.toUint(a > 0) * ((a - 1) / b + 1);
}
}
/**
* @dev Calculates floor(x * y / denominator) with full precision. Throws if result overflows a uint256 or
* denominator == 0.
*
* Original credit to Remco Bloemen under MIT license (https://xn--2-umb.com/21/muldiv) with further edits by
* Uniswap Labs also under MIT license.
*/
function mulDiv(uint256 x, uint256 y, uint256 denominator) internal pure returns (uint256 result) {
unchecked {
(uint256 high, uint256 low) = mul512(x, y);
// Handle non-overflow cases, 256 by 256 division.
if (high == 0) {
// Solidity will revert if denominator == 0, unlike the div opcode on its own.
// The surrounding unchecked block does not change this fact.
// See https://docs.soliditylang.org/en/latest/control-structures.html#checked-or-unchecked-arithmetic.
return low / denominator;
}
// Make sure the result is less than 2²56. Also prevents denominator == 0.
if (denominator <= high) {
Panic.panic(ternary(denominator == 0, Panic.DIVISION_BY_ZERO, Panic.UNDER_OVERFLOW));
}
///////////////////////////////////////////////
// 512 by 256 division.
///////////////////////////////////////////////
// Make division exact by subtracting the remainder from [high low].
uint256 remainder;
assembly ("memory-safe") {
// Compute remainder using mulmod.
remainder := mulmod(x, y, denominator)
// Subtract 256 bit number from 512 bit number.
high := sub(high, gt(remainder, low))
low := sub(low, remainder)
}
// Factor powers of two out of denominator and compute largest power of two divisor of denominator.
// Always >= 1. See https://cs.stackexchange.com/q/138556/92363.
uint256 twos = denominator & (0 - denominator);
assembly ("memory-safe") {
// Divide denominator by twos.
denominator := div(denominator, twos)
// Divide [high low] by twos.
low := div(low, twos)
// Flip twos such that it is 2²56 / twos. If twos is zero, then it becomes one.
twos := add(div(sub(0, twos), twos), 1)
}
// Shift in bits from high into low.
low |= high * twos;
// Invert denominator mod 2²56. Now that denominator is an odd number, it has an inverse modulo 2²56 such
// that denominator * inv = 1 mod 2²56. Compute the inverse by starting with a seed that is correct for
// four bits. That is, denominator * inv = 1 mod 24.
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 28
inverse *= 2 - denominator * inverse; // inverse mod 2¹6
inverse *= 2 - denominator * inverse; // inverse mod 2³²
inverse *= 2 - denominator * inverse; // inverse mod 264
inverse *= 2 - denominator * inverse; // inverse mod 2¹²8
inverse *= 2 - denominator * inverse; // inverse mod 2²56
// 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²56. Since the preconditions guarantee that the outcome is
// less than 2²56, this is the final result. We don't need to compute the high bits of the result and high
// is no longer required.
result = low * inverse;
return result;
}
}
/**
* @dev Calculates x * y / denominator with full precision, following the selected rounding direction.
*/
function mulDiv(uint256 x, uint256 y, uint256 denominator, Rounding rounding) internal pure returns (uint256) {
return mulDiv(x, y, denominator) + SafeCast.toUint(unsignedRoundsUp(rounding) && mulmod(x, y, denominator) > 0);
}
/**
* @dev Calculates floor(x * y >> n) with full precision. Throws if result overflows a uint256.
*/
function mulShr(uint256 x, uint256 y, uint8 n) internal pure returns (uint256 result) {
unchecked {
(uint256 high, uint256 low) = mul512(x, y);
if (high >= 1 << n) {
Panic.panic(Panic.UNDER_OVERFLOW);
}
return (high << (256 - n)) | (low >> n);
}
}
/**
* @dev Calculates x * y >> n with full precision, following the selected rounding direction.
*/
function mulShr(uint256 x, uint256 y, uint8 n, Rounding rounding) internal pure returns (uint256) {
return mulShr(x, y, n) + SafeCast.toUint(unsignedRoundsUp(rounding) && mulmod(x, y, 1 << n) > 0);
}
/**
* @dev Calculate the modular multiplicative inverse of a number in Z/nZ.
*
* If n is a prime, then Z/nZ is a field. In that case all elements are inversible, except 0.
* If n is not a prime, then Z/nZ is not a field, and some elements might not be inversible.
*
* If the input value is not inversible, 0 is returned.
*
* NOTE: If you know for sure that n is (big) a prime, it may be cheaper to use Fermat's little theorem and get the
* inverse using `Math.modExp(a, n - 2, n)`. See {invModPrime}.
*/
function invMod(uint256 a, uint256 n) internal pure returns (uint256) {
unchecked {
if (n == 0) return 0;
// The inverse modulo is calculated using the Extended Euclidean Algorithm (iterative version)
// Used to compute integers x and y such that: ax + ny = gcd(a, n).
// When the gcd is 1, then the inverse of a modulo n exists and it's x.
// ax + ny = 1
// ax = 1 + (-y)n
// ax = 1 (mod n) # x is the inverse of a modulo n
// If the remainder is 0 the gcd is n right away.
uint256 remainder = a % n;
uint256 gcd = n;
// Therefore the initial coefficients are:
// ax + ny = gcd(a, n) = n
// 0a + 1n = n
int256 x = 0;
int256 y = 1;
while (remainder != 0) {
uint256 quotient = gcd / remainder;
(gcd, remainder) = (
// The old remainder is the next gcd to try.
remainder,
// Compute the next remainder.
// Can't overflow given that (a % gcd) * (gcd // (a % gcd)) <= gcd
// where gcd is at most n (capped to type(uint256).max)
gcd - remainder * quotient
);
(x, y) = (
// Increment the coefficient of a.
y,
// Decrement the coefficient of n.
// Can overflow, but the result is casted to uint256 so that the
// next value of y is "wrapped around" to a value between 0 and n - 1.
x - y * int256(quotient)
);
}
if (gcd != 1) return 0; // No inverse exists.
return ternary(x < 0, n - uint256(-x), uint256(x)); // Wrap the result if it's negative.
}
}
/**
* @dev Variant of {invMod}. More efficient, but only works if `p` is known to be a prime greater than `2`.
*
* From https://en.wikipedia.org/wiki/Fermat%27s_little_theorem[Fermat's little theorem], we know that if p is
* prime, then `a**(p-1) = 1 mod p`. As a consequence, we have `a * a**(p-2) = 1 mod p`, which means that
* `a**(p-2)` is the modular multiplicative inverse of a in Fp.
*
* NOTE: this function does NOT check that `p` is a prime greater than `2`.
*/
function invModPrime(uint256 a, uint256 p) internal view returns (uint256) {
unchecked {
return Math.modExp(a, p - 2, p);
}
}
/**
* @dev Returns the modular exponentiation of the specified base, exponent and modulus (b ** e % m)
*
* Requirements:
* - modulus can't be zero
* - underlying staticcall to precompile must succeed
*
* IMPORTANT: The result is only valid if the underlying call succeeds. When using this function, make
* sure the chain you're using it on supports the precompiled contract for modular exponentiation
* at address 0x05 as specified in https://eips.ethereum.org/EIPS/eip-198[EIP-198]. Otherwise,
* the underlying function will succeed given the lack of a revert, but the result may be incorrectly
* interpreted as 0.
*/
function modExp(uint256 b, uint256 e, uint256 m) internal view returns (uint256) {
(bool success, uint256 result) = tryModExp(b, e, m);
if (!success) {
Panic.panic(Panic.DIVISION_BY_ZERO);
}
return result;
}
/**
* @dev Returns the modular exponentiation of the specified base, exponent and modulus (b ** e % m).
* It includes a success flag indicating if the operation succeeded. Operation will be marked as failed if trying
* to operate modulo 0 or if the underlying precompile reverted.
*
* IMPORTANT: The result is only valid if the success flag is true. When using this function, make sure the chain
* you're using it on supports the precompiled contract for modular exponentiation at address 0x05 as specified in
* https://eips.ethereum.org/EIPS/eip-198[EIP-198]. Otherwise, the underlying function will succeed given the lack
* of a revert, but the result may be incorrectly interpreted as 0.
*/
function tryModExp(uint256 b, uint256 e, uint256 m) internal view returns (bool success, uint256 result) {
if (m == 0) return (false, 0);
assembly ("memory-safe") {
let ptr := mload(0x40)
// | Offset | Content | Content (Hex) |
// |-----------|------------|--------------------------------------------------------------------|
// | 0x00:0x1f | size of b | 0x0000000000000000000000000000000000000000000000000000000000000020 |
// | 0x20:0x3f | size of e | 0x0000000000000000000000000000000000000000000000000000000000000020 |
// | 0x40:0x5f | size of m | 0x0000000000000000000000000000000000000000000000000000000000000020 |
// | 0x60:0x7f | value of b | 0x<.............................................................b> |
// | 0x80:0x9f | value of e | 0x<.............................................................e> |
// | 0xa0:0xbf | value of m | 0x<.............................................................m> |
mstore(ptr, 0x20)
mstore(add(ptr, 0x20), 0x20)
mstore(add(ptr, 0x40), 0x20)
mstore(add(ptr, 0x60), b)
mstore(add(ptr, 0x80), e)
mstore(add(ptr, 0xa0), m)
// Given the result < m, it's guaranteed to fit in 32 bytes,
// so we can use the memory scratch space located at offset 0.
success := staticcall(gas(), 0x05, ptr, 0xc0, 0x00, 0x20)
result := mload(0x00)
}
}
/**
* @dev Variant of {modExp} that supports inputs of arbitrary length.
*/
function modExp(bytes memory b, bytes memory e, bytes memory m) internal view returns (bytes memory) {
(bool success, bytes memory result) = tryModExp(b, e, m);
if (!success) {
Panic.panic(Panic.DIVISION_BY_ZERO);
}
return result;
}
/**
* @dev Variant of {tryModExp} that supports inputs of arbitrary length.
*/
function tryModExp(
bytes memory b,
bytes memory e,
bytes memory m
) internal view returns (bool success, bytes memory result) {
if (_zeroBytes(m)) return (false, new bytes(0));
uint256 mLen = m.length;
// Encode call args in result and move the free memory pointer
result = abi.encodePacked(b.length, e.length, mLen, b, e, m);
assembly ("memory-safe") {
let dataPtr := add(result, 0x20)
// Write result on top of args to avoid allocating extra memory.
success := staticcall(gas(), 0x05, dataPtr, mload(result), dataPtr, mLen)
// Overwrite the length.
// result.length > returndatasize() is guaranteed because returndatasize() == m.length
mstore(result, mLen)
// Set the memory pointer after the returned data.
mstore(0x40, add(dataPtr, mLen))
}
}
/**
* @dev Returns whether the provided byte array is zero.
*/
function _zeroBytes(bytes memory byteArray) private pure returns (bool) {
for (uint256 i = 0; i < byteArray.length; ++i) {
if (byteArray[i] != 0) {
return false;
}
}
return true;
}
/**
* @dev Returns the square root of a number. If the number is not a perfect square, the value is rounded
* towards zero.
*
* This method is based on Newton's method for computing square roots; the algorithm is restricted to only
* using integer operations.
*/
function sqrt(uint256 a) internal pure returns (uint256) {
unchecked {
// Take care of easy edge cases when a == 0 or a == 1
if (a <= 1) {
return a;
}
// In this function, we use Newton's method to get a root of `f(x) := x² - a`. It involves building a
// sequence x_n that converges toward sqrt(a). For each iteration x_n, we also define the error between
// the current value as `e_n = | x_n - sqrt(a) |`.
//
// For our first estimation, we consider `e` the smallest power of 2 which is bigger than the square root
// of the target. (i.e. `2**(e-1) = sqrt(a) < 2**e`). We know that `e = 128` because `(2¹²8)² = 2²56` is
// bigger than any uint256.
//
// By noticing that
// `2**(e-1) = sqrt(a) < 2**e ? (2**(e-1))² = a < (2**e)² ? 2**(2*e-2) = a < 2**(2*e)`
// we can deduce that `e - 1` is `log2(a) / 2`. We can thus compute `x_n = 2**(e-1)` using a method similar
// to the msb function.
uint256 aa = a;
uint256 xn = 1;
if (aa >= (1 << 128)) {
aa >>= 128;
xn <<= 64;
}
if (aa >= (1 << 64)) {
aa >>= 64;
xn <<= 32;
}
if (aa >= (1 << 32)) {
aa >>= 32;
xn <<= 16;
}
if (aa >= (1 << 16)) {
aa >>= 16;
xn <<= 8;
}
if (aa >= (1 << 8)) {
aa >>= 8;
xn <<= 4;
}
if (aa >= (1 << 4)) {
aa >>= 4;
xn <<= 2;
}
if (aa >= (1 << 2)) {
xn <<= 1;
}
// We now have x_n such that `x_n = 2**(e-1) = sqrt(a) < 2**e = 2 * x_n`. This implies e_n = 2**(e-1).
//
// We can refine our estimation by noticing that the middle of that interval minimizes the error.
// If we move x_n to equal 2**(e-1) + 2**(e-2), then we reduce the error to e_n = 2**(e-2).
// This is going to be our x_0 (and e_0)
xn = (3 * xn) >> 1; // e_0 := | x_0 - sqrt(a) | = 2**(e-2)
// From here, Newton's method give us:
// x_{n+1} = (x_n + a / x_n) / 2
//
// One should note that:
// x_{n+1}² - a = ((x_n + a / x_n) / 2)² - a
// = ((x_n² + a) / (2 * x_n))² - a
// = (x_n4 + 2 * a * x_n² + a²) / (4 * x_n²) - a
// = (x_n4 + 2 * a * x_n² + a² - 4 * a * x_n²) / (4 * x_n²)
// = (x_n4 - 2 * a * x_n² + a²) / (4 * x_n²)
// = (x_n² - a)² / (2 * x_n)²
// = ((x_n² - a) / (2 * x_n))²
// = 0
// Which proves that for all n = 1, sqrt(a) = x_n
//
// This gives us the proof of quadratic convergence of the sequence:
// e_{n+1} = | x_{n+1} - sqrt(a) |
// = | (x_n + a / x_n) / 2 - sqrt(a) |
// = | (x_n² + a - 2*x_n*sqrt(a)) / (2 * x_n) |
// = | (x_n - sqrt(a))² / (2 * x_n) |
// = | e_n² / (2 * x_n) |
// = e_n² / | (2 * x_n) |
//
// For the first iteration, we have a special case where x_0 is known:
// e_1 = e_0² / | (2 * x_0) |
// = (2**(e-2))² / (2 * (2**(e-1) + 2**(e-2)))
// = 2**(2*e-4) / (3 * 2**(e-1))
// = 2**(e-3) / 3
// = 2**(e-3-log2(3))
// = 2**(e-4.5)
//
// For the following iterations, we use the fact that, 2**(e-1) = sqrt(a) = x_n:
// e_{n+1} = e_n² / | (2 * x_n) |
// = (2**(e-k))² / (2 * 2**(e-1))
// = 2**(2*e-2*k) / 2**e
// = 2**(e-2*k)
xn = (xn + a / xn) >> 1; // e_1 := | x_1 - sqrt(a) | = 2**(e-4.5) -- special case, see above
xn = (xn + a / xn) >> 1; // e_2 := | x_2 - sqrt(a) | = 2**(e-9) -- general case with k = 4.5
xn = (xn + a / xn) >> 1; // e_3 := | x_3 - sqrt(a) | = 2**(e-18) -- general case with k = 9
xn = (xn + a / xn) >> 1; // e_4 := | x_4 - sqrt(a) | = 2**(e-36) -- general case with k = 18
xn = (xn + a / xn) >> 1; // e_5 := | x_5 - sqrt(a) | = 2**(e-72) -- general case with k = 36
xn = (xn + a / xn) >> 1; // e_6 := | x_6 - sqrt(a) | = 2**(e-144) -- general case with k = 72
// Because e = 128 (as discussed during the first estimation phase), we know have reached a precision
// e_6 = 2**(e-144) < 1. Given we're operating on integers, then we can ensure that xn is now either
// sqrt(a) or sqrt(a) + 1.
return xn - SafeCast.toUint(xn > a / xn);
}
}
/**
* @dev Calculates sqrt(a), following the selected rounding direction.
*/
function sqrt(uint256 a, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = sqrt(a);
return result + SafeCast.toUint(unsignedRoundsUp(rounding) && result * result < a);
}
}
/**
* @dev Return the log in base 2 of a positive value rounded towards zero.
* Returns 0 if given 0.
*/
function log2(uint256 x) internal pure returns (uint256 r) {
// If value has upper 128 bits set, log2 result is at least 128
r = SafeCast.toUint(x > 0xffffffffffffffffffffffffffffffff) << 7;
// If upper 64 bits of 128-bit half set, add 64 to result
r |= SafeCast.toUint((x >> r) > 0xffffffffffffffff) << 6;
// If upper 32 bits of 64-bit half set, add 32 to result
r |= SafeCast.toUint((x >> r) > 0xffffffff) << 5;
// If upper 16 bits of 32-bit half set, add 16 to result
r |= SafeCast.toUint((x >> r) > 0xffff) << 4;
// If upper 8 bits of 16-bit half set, add 8 to result
r |= SafeCast.toUint((x >> r) > 0xff) << 3;
// If upper 4 bits of 8-bit half set, add 4 to result
r |= SafeCast.toUint((x >> r) > 0xf) << 2;
// Shifts value right by the current result and use it as an index into this lookup table:
//
// | x (4 bits) | index | table[index] = MSB position |
// |------------|---------|-----------------------------|
// | 0000 | 0 | table[0] = 0 |
// | 0001 | 1 | table[1] = 0 |
// | 0010 | 2 | table[2] = 1 |
// | 0011 | 3 | table[3] = 1 |
// | 0100 | 4 | table[4] = 2 |
// | 0101 | 5 | table[5] = 2 |
// | 0110 | 6 | table[6] = 2 |
// | 0111 | 7 | table[7] = 2 |
// | 1000 | 8 | table[8] = 3 |
// | 1001 | 9 | table[9] = 3 |
// | 1010 | 10 | table[10] = 3 |
// | 1011 | 11 | table[11] = 3 |
// | 1100 | 12 | table[12] = 3 |
// | 1101 | 13 | table[13] = 3 |
// | 1110 | 14 | table[14] = 3 |
// | 1111 | 15 | table[15] = 3 |
//
// The lookup table is represented as a 32-byte value with the MSB positions for 0-15 in the last 16 bytes.
assembly ("memory-safe") {
r := or(r, byte(shr(r, x), 0x0000010102020202030303030303030300000000000000000000000000000000))
}
}
/**
* @dev Return the log in base 2, following the selected rounding direction, of a positive value.
* Returns 0 if given 0.
*/
function log2(uint256 value, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = log2(value);
return result + SafeCast.toUint(unsignedRoundsUp(rounding) && 1 << result < value);
}
}
/**
* @dev Return the log in base 10 of a positive value rounded towards zero.
* Returns 0 if given 0.
*/
function log10(uint256 value) internal pure returns (uint256) {
uint256 result = 0;
unchecked {
if (value >= 10 ** 64) {
value /= 10 ** 64;
result += 64;
}
if (value >= 10 ** 32) {
value /= 10 ** 32;
result += 32;
}
if (value >= 10 ** 16) {
value /= 10 ** 16;
result += 16;
}
if (value >= 10 ** 8) {
value /= 10 ** 8;
result += 8;
}
if (value >= 10 ** 4) {
value /= 10 ** 4;
result += 4;
}
if (value >= 10 ** 2) {
value /= 10 ** 2;
result += 2;
}
if (value >= 10 ** 1) {
result += 1;
}
}
return result;
}
/**
* @dev Return the log in base 10, following the selected rounding direction, of a positive value.
* Returns 0 if given 0.
*/
function log10(uint256 value, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = log10(value);
return result + SafeCast.toUint(unsignedRoundsUp(rounding) && 10 ** result < value);
}
}
/**
* @dev Return the log in base 256 of a positive value rounded towards zero.
* Returns 0 if given 0.
*
* Adding one to the result gives the number of pairs of hex symbols needed to represent `value` as a hex string.
*/
function log256(uint256 x) internal pure returns (uint256 r) {
// If value has upper 128 bits set, log2 result is at least 128
r = SafeCast.toUint(x > 0xffffffffffffffffffffffffffffffff) << 7;
// If upper 64 bits of 128-bit half set, add 64 to result
r |= SafeCast.toUint((x >> r) > 0xffffffffffffffff) << 6;
// If upper 32 bits of 64-bit half set, add 32 to result
r |= SafeCast.toUint((x >> r) > 0xffffffff) << 5;
// If upper 16 bits of 32-bit half set, add 16 to result
r |= SafeCast.toUint((x >> r) > 0xffff) << 4;
// Add 1 if upper 8 bits of 16-bit half set, and divide accumulated result by 8
return (r >> 3) | SafeCast.toUint((x >> r) > 0xff);
}
/**
* @dev Return the log in base 256, following the selected rounding direction, of a positive value.
* Returns 0 if given 0.
*/
function log256(uint256 value, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = log256(value);
return result + SafeCast.toUint(unsignedRoundsUp(rounding) && 1 << (result << 3) < value);
}
}
/**
* @dev Returns whether a provided rounding mode is considered rounding up for unsigned integers.
*/
function unsignedRoundsUp(Rounding rounding) internal pure returns (bool) {
return uint8(rounding) % 2 == 1;
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (utils/math/SafeCast.sol)
// This file was procedurally generated from scripts/generate/templates/SafeCast.js.
pragma solidity ^0.8.20;
/**
* @dev Wrappers over Solidity's uintXX/intXX/bool casting operators with added overflow
* checks.
*
* Downcasting from uint256/int256 in Solidity does not revert on overflow. This can
* easily result in undesired exploitation or bugs, since developers usually
* assume that overflows raise errors. `SafeCast` restores this intuition by
* reverting the transaction when such an operation overflows.
*
* Using this library instead of the unchecked operations eliminates an entire
* class of bugs, so it's recommended to use it always.
*/
library SafeCast {
/**
* @dev Value doesn't fit in an uint of `bits` size.
*/
error SafeCastOverflowedUintDowncast(uint8 bits, uint256 value);
/**
* @dev An int value doesn't fit in an uint of `bits` size.
*/
error SafeCastOverflowedIntToUint(int256 value);
/**
* @dev Value doesn't fit in an int of `bits` size.
*/
error SafeCastOverflowedIntDowncast(uint8 bits, int256 value);
/**
* @dev An uint value doesn't fit in an int of `bits` size.
*/
error SafeCastOverflowedUintToInt(uint256 value);
/**
* @dev Returns the downcasted uint248 from uint256, reverting on
* overflow (when the input is greater than largest uint248).
*
* Counterpart to Solidity's `uint248` operator.
*
* Requirements:
*
* - input must fit into 248 bits
*/
function toUint248(uint256 value) internal pure returns (uint248) {
if (value > type(uint248).max) {
revert SafeCastOverflowedUintDowncast(248, value);
}
return uint248(value);
}
/**
* @dev Returns the downcasted uint240 from uint256, reverting on
* overflow (when the input is greater than largest uint240).
*
* Counterpart to Solidity's `uint240` operator.
*
* Requirements:
*
* - input must fit into 240 bits
*/
function toUint240(uint256 value) internal pure returns (uint240) {
if (value > type(uint240).max) {
revert SafeCastOverflowedUintDowncast(240, value);
}
return uint240(value);
}
/**
* @dev Returns the downcasted uint232 from uint256, reverting on
* overflow (when the input is greater than largest uint232).
*
* Counterpart to Solidity's `uint232` operator.
*
* Requirements:
*
* - input must fit into 232 bits
*/
function toUint232(uint256 value) internal pure returns (uint232) {
if (value > type(uint232).max) {
revert SafeCastOverflowedUintDowncast(232, value);
}
return uint232(value);
}
/**
* @dev Returns the downcasted uint224 from uint256, reverting on
* overflow (when the input is greater than largest uint224).
*
* Counterpart to Solidity's `uint224` operator.
*
* Requirements:
*
* - input must fit into 224 bits
*/
function toUint224(uint256 value) internal pure returns (uint224) {
if (value > type(uint224).max) {
revert SafeCastOverflowedUintDowncast(224, value);
}
return uint224(value);
}
/**
* @dev Returns the downcasted uint216 from uint256, reverting on
* overflow (when the input is greater than largest uint216).
*
* Counterpart to Solidity's `uint216` operator.
*
* Requirements:
*
* - input must fit into 216 bits
*/
function toUint216(uint256 value) internal pure returns (uint216) {
if (value > type(uint216).max) {
revert SafeCastOverflowedUintDowncast(216, value);
}
return uint216(value);
}
/**
* @dev Returns the downcasted uint208 from uint256, reverting on
* overflow (when the input is greater than largest uint208).
*
* Counterpart to Solidity's `uint208` operator.
*
* Requirements:
*
* - input must fit into 208 bits
*/
function toUint208(uint256 value) internal pure returns (uint208) {
if (value > type(uint208).max) {
revert SafeCastOverflowedUintDowncast(208, value);
}
return uint208(value);
}
/**
* @dev Returns the downcasted uint200 from uint256, reverting on
* overflow (when the input is greater than largest uint200).
*
* Counterpart to Solidity's `uint200` operator.
*
* Requirements:
*
* - input must fit into 200 bits
*/
function toUint200(uint256 value) internal pure returns (uint200) {
if (value > type(uint200).max) {
revert SafeCastOverflowedUintDowncast(200, value);
}
return uint200(value);
}
/**
* @dev Returns the downcasted uint192 from uint256, reverting on
* overflow (when the input is greater than largest uint192).
*
* Counterpart to Solidity's `uint192` operator.
*
* Requirements:
*
* - input must fit into 192 bits
*/
function toUint192(uint256 value) internal pure returns (uint192) {
if (value > type(uint192).max) {
revert SafeCastOverflowedUintDowncast(192, value);
}
return uint192(value);
}
/**
* @dev Returns the downcasted uint184 from uint256, reverting on
* overflow (when the input is greater than largest uint184).
*
* Counterpart to Solidity's `uint184` operator.
*
* Requirements:
*
* - input must fit into 184 bits
*/
function toUint184(uint256 value) internal pure returns (uint184) {
if (value > type(uint184).max) {
revert SafeCastOverflowedUintDowncast(184, value);
}
return uint184(value);
}
/**
* @dev Returns the downcasted uint176 from uint256, reverting on
* overflow (when the input is greater than largest uint176).
*
* Counterpart to Solidity's `uint176` operator.
*
* Requirements:
*
* - input must fit into 176 bits
*/
function toUint176(uint256 value) internal pure returns (uint176) {
if (value > type(uint176).max) {
revert SafeCastOverflowedUintDowncast(176, value);
}
return uint176(value);
}
/**
* @dev Returns the downcasted uint168 from uint256, reverting on
* overflow (when the input is greater than largest uint168).
*
* Counterpart to Solidity's `uint168` operator.
*
* Requirements:
*
* - input must fit into 168 bits
*/
function toUint168(uint256 value) internal pure returns (uint168) {
if (value > type(uint168).max) {
revert SafeCastOverflowedUintDowncast(168, value);
}
return uint168(value);
}
/**
* @dev Returns the downcasted uint160 from uint256, reverting on
* overflow (when the input is greater than largest uint160).
*
* Counterpart to Solidity's `uint160` operator.
*
* Requirements:
*
* - input must fit into 160 bits
*/
function toUint160(uint256 value) internal pure returns (uint160) {
if (value > type(uint160).max) {
revert SafeCastOverflowedUintDowncast(160, value);
}
return uint160(value);
}
/**
* @dev Returns the downcasted uint152 from uint256, reverting on
* overflow (when the input is greater than largest uint152).
*
* Counterpart to Solidity's `uint152` operator.
*
* Requirements:
*
* - input must fit into 152 bits
*/
function toUint152(uint256 value) internal pure returns (uint152) {
if (value > type(uint152).max) {
revert SafeCastOverflowedUintDowncast(152, value);
}
return uint152(value);
}
/**
* @dev Returns the downcasted uint144 from uint256, reverting on
* overflow (when the input is greater than largest uint144).
*
* Counterpart to Solidity's `uint144` operator.
*
* Requirements:
*
* - input must fit into 144 bits
*/
function toUint144(uint256 value) internal pure returns (uint144) {
if (value > type(uint144).max) {
revert SafeCastOverflowedUintDowncast(144, value);
}
return uint144(value);
}
/**
* @dev Returns the downcasted uint136 from uint256, reverting on
* overflow (when the input is greater than largest uint136).
*
* Counterpart to Solidity's `uint136` operator.
*
* Requirements:
*
* - input must fit into 136 bits
*/
function toUint136(uint256 value) internal pure returns (uint136) {
if (value > type(uint136).max) {
revert SafeCastOverflowedUintDowncast(136, value);
}
return uint136(value);
}
/**
* @dev Returns the downcasted uint128 from uint256, reverting on
* overflow (when the input is greater than largest uint128).
*
* Counterpart to Solidity's `uint128` operator.
*
* Requirements:
*
* - input must fit into 128 bits
*/
function toUint128(uint256 value) internal pure returns (uint128) {
if (value > type(uint128).max) {
revert SafeCastOverflowedUintDowncast(128, value);
}
return uint128(value);
}
/**
* @dev Returns the downcasted uint120 from uint256, reverting on
* overflow (when the input is greater than largest uint120).
*
* Counterpart to Solidity's `uint120` operator.
*
* Requirements:
*
* - input must fit into 120 bits
*/
function toUint120(uint256 value) internal pure returns (uint120) {
if (value > type(uint120).max) {
revert SafeCastOverflowedUintDowncast(120, value);
}
return uint120(value);
}
/**
* @dev Returns the downcasted uint112 from uint256, reverting on
* overflow (when the input is greater than largest uint112).
*
* Counterpart to Solidity's `uint112` operator.
*
* Requirements:
*
* - input must fit into 112 bits
*/
function toUint112(uint256 value) internal pure returns (uint112) {
if (value > type(uint112).max) {
revert SafeCastOverflowedUintDowncast(112, value);
}
return uint112(value);
}
/**
* @dev Returns the downcasted uint104 from uint256, reverting on
* overflow (when the input is greater than largest uint104).
*
* Counterpart to Solidity's `uint104` operator.
*
* Requirements:
*
* - input must fit into 104 bits
*/
function toUint104(uint256 value) internal pure returns (uint104) {
if (value > type(uint104).max) {
revert SafeCastOverflowedUintDowncast(104, value);
}
return uint104(value);
}
/**
* @dev Returns the downcasted uint96 from uint256, reverting on
* overflow (when the input is greater than largest uint96).
*
* Counterpart to Solidity's `uint96` operator.
*
* Requirements:
*
* - input must fit into 96 bits
*/
function toUint96(uint256 value) internal pure returns (uint96) {
if (value > type(uint96).max) {
revert SafeCastOverflowedUintDowncast(96, value);
}
return uint96(value);
}
/**
* @dev Returns the downcasted uint88 from uint256, reverting on
* overflow (when the input is greater than largest uint88).
*
* Counterpart to Solidity's `uint88` operator.
*
* Requirements:
*
* - input must fit into 88 bits
*/
function toUint88(uint256 value) internal pure returns (uint88) {
if (value > type(uint88).max) {
revert SafeCastOverflowedUintDowncast(88, value);
}
return uint88(value);
}
/**
* @dev Returns the downcasted uint80 from uint256, reverting on
* overflow (when the input is greater than largest uint80).
*
* Counterpart to Solidity's `uint80` operator.
*
* Requirements:
*
* - input must fit into 80 bits
*/
function toUint80(uint256 value) internal pure returns (uint80) {
if (value > type(uint80).max) {
revert SafeCastOverflowedUintDowncast(80, value);
}
return uint80(value);
}
/**
* @dev Returns the downcasted uint72 from uint256, reverting on
* overflow (when the input is greater than largest uint72).
*
* Counterpart to Solidity's `uint72` operator.
*
* Requirements:
*
* - input must fit into 72 bits
*/
function toUint72(uint256 value) internal pure returns (uint72) {
if (value > type(uint72).max) {
revert SafeCastOverflowedUintDowncast(72, value);
}
return uint72(value);
}
/**
* @dev Returns the downcasted uint64 from uint256, reverting on
* overflow (when the input is greater than largest uint64).
*
* Counterpart to Solidity's `uint64` operator.
*
* Requirements:
*
* - input must fit into 64 bits
*/
function toUint64(uint256 value) internal pure returns (uint64) {
if (value > type(uint64).max) {
revert SafeCastOverflowedUintDowncast(64, value);
}
return uint64(value);
}
/**
* @dev Returns the downcasted uint56 from uint256, reverting on
* overflow (when the input is greater than largest uint56).
*
* Counterpart to Solidity's `uint56` operator.
*
* Requirements:
*
* - input must fit into 56 bits
*/
function toUint56(uint256 value) internal pure returns (uint56) {
if (value > type(uint56).max) {
revert SafeCastOverflowedUintDowncast(56, value);
}
return uint56(value);
}
/**
* @dev Returns the downcasted uint48 from uint256, reverting on
* overflow (when the input is greater than largest uint48).
*
* Counterpart to Solidity's `uint48` operator.
*
* Requirements:
*
* - input must fit into 48 bits
*/
function toUint48(uint256 value) internal pure returns (uint48) {
if (value > type(uint48).max) {
revert SafeCastOverflowedUintDowncast(48, value);
}
return uint48(value);
}
/**
* @dev Returns the downcasted uint40 from uint256, reverting on
* overflow (when the input is greater than largest uint40).
*
* Counterpart to Solidity's `uint40` operator.
*
* Requirements:
*
* - input must fit into 40 bits
*/
function toUint40(uint256 value) internal pure returns (uint40) {
if (value > type(uint40).max) {
revert SafeCastOverflowedUintDowncast(40, value);
}
return uint40(value);
}
/**
* @dev Returns the downcasted uint32 from uint256, reverting on
* overflow (when the input is greater than largest uint32).
*
* Counterpart to Solidity's `uint32` operator.
*
* Requirements:
*
* - input must fit into 32 bits
*/
function toUint32(uint256 value) internal pure returns (uint32) {
if (value > type(uint32).max) {
revert SafeCastOverflowedUintDowncast(32, value);
}
return uint32(value);
}
/**
* @dev Returns the downcasted uint24 from uint256, reverting on
* overflow (when the input is greater than largest uint24).
*
* Counterpart to Solidity's `uint24` operator.
*
* Requirements:
*
* - input must fit into 24 bits
*/
function toUint24(uint256 value) internal pure returns (uint24) {
if (value > type(uint24).max) {
revert SafeCastOverflowedUintDowncast(24, value);
}
return uint24(value);
}
/**
* @dev Returns the downcasted uint16 from uint256, reverting on
* overflow (when the input is greater than largest uint16).
*
* Counterpart to Solidity's `uint16` operator.
*
* Requirements:
*
* - input must fit into 16 bits
*/
function toUint16(uint256 value) internal pure returns (uint16) {
if (value > type(uint16).max) {
revert SafeCastOverflowedUintDowncast(16, value);
}
return uint16(value);
}
/**
* @dev Returns the downcasted uint8 from uint256, reverting on
* overflow (when the input is greater than largest uint8).
*
* Counterpart to Solidity's `uint8` operator.
*
* Requirements:
*
* - input must fit into 8 bits
*/
function toUint8(uint256 value) internal pure returns (uint8) {
if (value > type(uint8).max) {
revert SafeCastOverflowedUintDowncast(8, value);
}
return uint8(value);
}
/**
* @dev Converts a signed int256 into an unsigned uint256.
*
* Requirements:
*
* - input must be greater than or equal to 0.
*/
function toUint256(int256 value) internal pure returns (uint256) {
if (value < 0) {
revert SafeCastOverflowedIntToUint(value);
}
return uint256(value);
}
/**
* @dev Returns the downcasted int248 from int256, reverting on
* overflow (when the input is less than smallest int248 or
* greater than largest int248).
*
* Counterpart to Solidity's `int248` operator.
*
* Requirements:
*
* - input must fit into 248 bits
*/
function toInt248(int256 value) internal pure returns (int248 downcasted) {
downcasted = int248(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(248, value);
}
}
/**
* @dev Returns the downcasted int240 from int256, reverting on
* overflow (when the input is less than smallest int240 or
* greater than largest int240).
*
* Counterpart to Solidity's `int240` operator.
*
* Requirements:
*
* - input must fit into 240 bits
*/
function toInt240(int256 value) internal pure returns (int240 downcasted) {
downcasted = int240(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(240, value);
}
}
/**
* @dev Returns the downcasted int232 from int256, reverting on
* overflow (when the input is less than smallest int232 or
* greater than largest int232).
*
* Counterpart to Solidity's `int232` operator.
*
* Requirements:
*
* - input must fit into 232 bits
*/
function toInt232(int256 value) internal pure returns (int232 downcasted) {
downcasted = int232(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(232, value);
}
}
/**
* @dev Returns the downcasted int224 from int256, reverting on
* overflow (when the input is less than smallest int224 or
* greater than largest int224).
*
* Counterpart to Solidity's `int224` operator.
*
* Requirements:
*
* - input must fit into 224 bits
*/
function toInt224(int256 value) internal pure returns (int224 downcasted) {
downcasted = int224(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(224, value);
}
}
/**
* @dev Returns the downcasted int216 from int256, reverting on
* overflow (when the input is less than smallest int216 or
* greater than largest int216).
*
* Counterpart to Solidity's `int216` operator.
*
* Requirements:
*
* - input must fit into 216 bits
*/
function toInt216(int256 value) internal pure returns (int216 downcasted) {
downcasted = int216(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(216, value);
}
}
/**
* @dev Returns the downcasted int208 from int256, reverting on
* overflow (when the input is less than smallest int208 or
* greater than largest int208).
*
* Counterpart to Solidity's `int208` operator.
*
* Requirements:
*
* - input must fit into 208 bits
*/
function toInt208(int256 value) internal pure returns (int208 downcasted) {
downcasted = int208(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(208, value);
}
}
/**
* @dev Returns the downcasted int200 from int256, reverting on
* overflow (when the input is less than smallest int200 or
* greater than largest int200).
*
* Counterpart to Solidity's `int200` operator.
*
* Requirements:
*
* - input must fit into 200 bits
*/
function toInt200(int256 value) internal pure returns (int200 downcasted) {
downcasted = int200(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(200, value);
}
}
/**
* @dev Returns the downcasted int192 from int256, reverting on
* overflow (when the input is less than smallest int192 or
* greater than largest int192).
*
* Counterpart to Solidity's `int192` operator.
*
* Requirements:
*
* - input must fit into 192 bits
*/
function toInt192(int256 value) internal pure returns (int192 downcasted) {
downcasted = int192(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(192, value);
}
}
/**
* @dev Returns the downcasted int184 from int256, reverting on
* overflow (when the input is less than smallest int184 or
* greater than largest int184).
*
* Counterpart to Solidity's `int184` operator.
*
* Requirements:
*
* - input must fit into 184 bits
*/
function toInt184(int256 value) internal pure returns (int184 downcasted) {
downcasted = int184(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(184, value);
}
}
/**
* @dev Returns the downcasted int176 from int256, reverting on
* overflow (when the input is less than smallest int176 or
* greater than largest int176).
*
* Counterpart to Solidity's `int176` operator.
*
* Requirements:
*
* - input must fit into 176 bits
*/
function toInt176(int256 value) internal pure returns (int176 downcasted) {
downcasted = int176(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(176, value);
}
}
/**
* @dev Returns the downcasted int168 from int256, reverting on
* overflow (when the input is less than smallest int168 or
* greater than largest int168).
*
* Counterpart to Solidity's `int168` operator.
*
* Requirements:
*
* - input must fit into 168 bits
*/
function toInt168(int256 value) internal pure returns (int168 downcasted) {
downcasted = int168(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(168, value);
}
}
/**
* @dev Returns the downcasted int160 from int256, reverting on
* overflow (when the input is less than smallest int160 or
* greater than largest int160).
*
* Counterpart to Solidity's `int160` operator.
*
* Requirements:
*
* - input must fit into 160 bits
*/
function toInt160(int256 value) internal pure returns (int160 downcasted) {
downcasted = int160(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(160, value);
}
}
/**
* @dev Returns the downcasted int152 from int256, reverting on
* overflow (when the input is less than smallest int152 or
* greater than largest int152).
*
* Counterpart to Solidity's `int152` operator.
*
* Requirements:
*
* - input must fit into 152 bits
*/
function toInt152(int256 value) internal pure returns (int152 downcasted) {
downcasted = int152(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(152, value);
}
}
/**
* @dev Returns the downcasted int144 from int256, reverting on
* overflow (when the input is less than smallest int144 or
* greater than largest int144).
*
* Counterpart to Solidity's `int144` operator.
*
* Requirements:
*
* - input must fit into 144 bits
*/
function toInt144(int256 value) internal pure returns (int144 downcasted) {
downcasted = int144(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(144, value);
}
}
/**
* @dev Returns the downcasted int136 from int256, reverting on
* overflow (when the input is less than smallest int136 or
* greater than largest int136).
*
* Counterpart to Solidity's `int136` operator.
*
* Requirements:
*
* - input must fit into 136 bits
*/
function toInt136(int256 value) internal pure returns (int136 downcasted) {
downcasted = int136(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(136, value);
}
}
/**
* @dev Returns the downcasted int128 from int256, reverting on
* overflow (when the input is less than smallest int128 or
* greater than largest int128).
*
* Counterpart to Solidity's `int128` operator.
*
* Requirements:
*
* - input must fit into 128 bits
*/
function toInt128(int256 value) internal pure returns (int128 downcasted) {
downcasted = int128(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(128, value);
}
}
/**
* @dev Returns the downcasted int120 from int256, reverting on
* overflow (when the input is less than smallest int120 or
* greater than largest int120).
*
* Counterpart to Solidity's `int120` operator.
*
* Requirements:
*
* - input must fit into 120 bits
*/
function toInt120(int256 value) internal pure returns (int120 downcasted) {
downcasted = int120(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(120, value);
}
}
/**
* @dev Returns the downcasted int112 from int256, reverting on
* overflow (when the input is less than smallest int112 or
* greater than largest int112).
*
* Counterpart to Solidity's `int112` operator.
*
* Requirements:
*
* - input must fit into 112 bits
*/
function toInt112(int256 value) internal pure returns (int112 downcasted) {
downcasted = int112(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(112, value);
}
}
/**
* @dev Returns the downcasted int104 from int256, reverting on
* overflow (when the input is less than smallest int104 or
* greater than largest int104).
*
* Counterpart to Solidity's `int104` operator.
*
* Requirements:
*
* - input must fit into 104 bits
*/
function toInt104(int256 value) internal pure returns (int104 downcasted) {
downcasted = int104(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(104, value);
}
}
/**
* @dev Returns the downcasted int96 from int256, reverting on
* overflow (when the input is less than smallest int96 or
* greater than largest int96).
*
* Counterpart to Solidity's `int96` operator.
*
* Requirements:
*
* - input must fit into 96 bits
*/
function toInt96(int256 value) internal pure returns (int96 downcasted) {
downcasted = int96(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(96, value);
}
}
/**
* @dev Returns the downcasted int88 from int256, reverting on
* overflow (when the input is less than smallest int88 or
* greater than largest int88).
*
* Counterpart to Solidity's `int88` operator.
*
* Requirements:
*
* - input must fit into 88 bits
*/
function toInt88(int256 value) internal pure returns (int88 downcasted) {
downcasted = int88(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(88, value);
}
}
/**
* @dev Returns the downcasted int80 from int256, reverting on
* overflow (when the input is less than smallest int80 or
* greater than largest int80).
*
* Counterpart to Solidity's `int80` operator.
*
* Requirements:
*
* - input must fit into 80 bits
*/
function toInt80(int256 value) internal pure returns (int80 downcasted) {
downcasted = int80(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(80, value);
}
}
/**
* @dev Returns the downcasted int72 from int256, reverting on
* overflow (when the input is less than smallest int72 or
* greater than largest int72).
*
* Counterpart to Solidity's `int72` operator.
*
* Requirements:
*
* - input must fit into 72 bits
*/
function toInt72(int256 value) internal pure returns (int72 downcasted) {
downcasted = int72(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(72, value);
}
}
/**
* @dev Returns the downcasted int64 from int256, reverting on
* overflow (when the input is less than smallest int64 or
* greater than largest int64).
*
* Counterpart to Solidity's `int64` operator.
*
* Requirements:
*
* - input must fit into 64 bits
*/
function toInt64(int256 value) internal pure returns (int64 downcasted) {
downcasted = int64(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(64, value);
}
}
/**
* @dev Returns the downcasted int56 from int256, reverting on
* overflow (when the input is less than smallest int56 or
* greater than largest int56).
*
* Counterpart to Solidity's `int56` operator.
*
* Requirements:
*
* - input must fit into 56 bits
*/
function toInt56(int256 value) internal pure returns (int56 downcasted) {
downcasted = int56(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(56, value);
}
}
/**
* @dev Returns the downcasted int48 from int256, reverting on
* overflow (when the input is less than smallest int48 or
* greater than largest int48).
*
* Counterpart to Solidity's `int48` operator.
*
* Requirements:
*
* - input must fit into 48 bits
*/
function toInt48(int256 value) internal pure returns (int48 downcasted) {
downcasted = int48(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(48, value);
}
}
/**
* @dev Returns the downcasted int40 from int256, reverting on
* overflow (when the input is less than smallest int40 or
* greater than largest int40).
*
* Counterpart to Solidity's `int40` operator.
*
* Requirements:
*
* - input must fit into 40 bits
*/
function toInt40(int256 value) internal pure returns (int40 downcasted) {
downcasted = int40(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(40, value);
}
}
/**
* @dev Returns the downcasted int32 from int256, reverting on
* overflow (when the input is less than smallest int32 or
* greater than largest int32).
*
* Counterpart to Solidity's `int32` operator.
*
* Requirements:
*
* - input must fit into 32 bits
*/
function toInt32(int256 value) internal pure returns (int32 downcasted) {
downcasted = int32(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(32, value);
}
}
/**
* @dev Returns the downcasted int24 from int256, reverting on
* overflow (when the input is less than smallest int24 or
* greater than largest int24).
*
* Counterpart to Solidity's `int24` operator.
*
* Requirements:
*
* - input must fit into 24 bits
*/
function toInt24(int256 value) internal pure returns (int24 downcasted) {
downcasted = int24(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(24, value);
}
}
/**
* @dev Returns the downcasted int16 from int256, reverting on
* overflow (when the input is less than smallest int16 or
* greater than largest int16).
*
* Counterpart to Solidity's `int16` operator.
*
* Requirements:
*
* - input must fit into 16 bits
*/
function toInt16(int256 value) internal pure returns (int16 downcasted) {
downcasted = int16(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(16, value);
}
}
/**
* @dev Returns the downcasted int8 from int256, reverting on
* overflow (when the input is less than smallest int8 or
* greater than largest int8).
*
* Counterpart to Solidity's `int8` operator.
*
* Requirements:
*
* - input must fit into 8 bits
*/
function toInt8(int256 value) internal pure returns (int8 downcasted) {
downcasted = int8(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(8, value);
}
}
/**
* @dev Converts an unsigned uint256 into a signed int256.
*
* Requirements:
*
* - input must be less than or equal to maxInt256.
*/
function toInt256(uint256 value) internal pure returns (int256) {
// Note: Unsafe cast below is okay because `type(int256).max` is guaranteed to be positive
if (value > uint256(type(int256).max)) {
revert SafeCastOverflowedUintToInt(value);
}
return int256(value);
}
/**
* @dev Cast a boolean (false or true) to a uint256 (0 or 1) with no jump.
*/
function toUint(bool b) internal pure returns (uint256 u) {
assembly ("memory-safe") {
u := iszero(iszero(b))
}
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.3.0) (utils/structs/EnumerableSet.sol)
// This file was procedurally generated from scripts/generate/templates/EnumerableSet.js.
pragma solidity ^0.8.20;
import {Arrays} from "../Arrays.sol";
/**
* @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.
* - Set can be cleared (all elements removed) in O(n).
*
* ```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 Removes all the values from a set. O(n).
*
* WARNING: Developers should keep in mind that this function has an unbounded cost and using it may render the
* function uncallable if the set grows to the point where clearing it consumes too much gas to fit in a block.
*/
function _clear(Set storage set) private {
uint256 len = _length(set);
for (uint256 i = 0; i < len; ++i) {
delete set._positions[set._values[i]];
}
Arrays.unsafeSetLength(set._values, 0);
}
/**
* @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 Removes all the values from a set. O(n).
*
* WARNING: Developers should keep in mind that this function has an unbounded cost and using it may render the
* function uncallable if the set grows to the point where clearing it consumes too much gas to fit in a block.
*/
function clear(Bytes32Set storage set) internal {
_clear(set._inner);
}
/**
* @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;
assembly ("memory-safe") {
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 Removes all the values from a set. O(n).
*
* WARNING: Developers should keep in mind that this function has an unbounded cost and using it may render the
* function uncallable if the set grows to the point where clearing it consumes too much gas to fit in a block.
*/
function clear(AddressSet storage set) internal {
_clear(set._inner);
}
/**
* @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;
assembly ("memory-safe") {
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 Removes all the values from a set. O(n).
*
* WARNING: Developers should keep in mind that this function has an unbounded cost and using it may render the
* function uncallable if the set grows to the point where clearing it consumes too much gas to fit in a block.
*/
function clear(UintSet storage set) internal {
_clear(set._inner);
}
/**
* @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;
assembly ("memory-safe") {
result := store
}
return result;
}
}// SPDX-License-Identifier: AGPL-3.0-only
pragma solidity >=0.8.0;
/// @notice Provides a flexible and updatable auth pattern which is completely separate from application logic.
/// @author Solmate (https://github.com/transmissions11/solmate/blob/main/src/auth/Auth.sol)
/// @author Modified from Dappsys (https://github.com/dapphub/ds-auth/blob/master/src/auth.sol)
abstract contract Auth {
event OwnershipTransferred(address indexed user, address indexed newOwner);
event AuthorityUpdated(address indexed user, Authority indexed newAuthority);
address public owner;
Authority public authority;
constructor(address _owner, Authority _authority) {
owner = _owner;
authority = _authority;
emit OwnershipTransferred(msg.sender, _owner);
emit AuthorityUpdated(msg.sender, _authority);
}
modifier requiresAuth() virtual {
require(isAuthorized(msg.sender, msg.sig), "UNAUTHORIZED");
_;
}
function isAuthorized(address user, bytes4 functionSig) internal view virtual returns (bool) {
Authority auth = authority; // Memoizing authority saves us a warm SLOAD, around 100 gas.
// Checking if the caller is the owner only after calling the authority saves gas in most cases, but be
// aware that this makes protected functions uncallable even to the owner if the authority is out of order.
return (address(auth) != address(0) && auth.canCall(user, address(this), functionSig)) || user == owner;
}
function setAuthority(Authority newAuthority) public virtual {
// We check if the caller is the owner first because we want to ensure they can
// always swap out the authority even if it's reverting or using up a lot of gas.
require(msg.sender == owner || authority.canCall(msg.sender, address(this), msg.sig));
authority = newAuthority;
emit AuthorityUpdated(msg.sender, newAuthority);
}
function transferOwnership(address newOwner) public virtual requiresAuth {
owner = newOwner;
emit OwnershipTransferred(msg.sender, newOwner);
}
}
/// @notice A generic interface for a contract which provides authorization data to an Auth instance.
/// @author Solmate (https://github.com/transmissions11/solmate/blob/main/src/auth/Auth.sol)
/// @author Modified from Dappsys (https://github.com/dapphub/ds-auth/blob/master/src/auth.sol)
interface Authority {
function canCall(
address user,
address target,
bytes4 functionSig
) external view returns (bool);
}// SPDX-License-Identifier: AGPL-3.0-only
pragma solidity >=0.8.0;
/// @notice Modern and gas efficient ERC20 + EIP-2612 implementation.
/// @author Solmate (https://github.com/transmissions11/solmate/blob/main/src/tokens/ERC20.sol)
/// @author Modified from Uniswap (https://github.com/Uniswap/uniswap-v2-core/blob/master/contracts/UniswapV2ERC20.sol)
/// @dev Do not manually set balances without updating totalSupply, as the sum of all user balances must not exceed it.
abstract contract ERC20 {
/*//////////////////////////////////////////////////////////////
EVENTS
//////////////////////////////////////////////////////////////*/
event Transfer(address indexed from, address indexed to, uint256 amount);
event Approval(address indexed owner, address indexed spender, uint256 amount);
/*//////////////////////////////////////////////////////////////
METADATA STORAGE
//////////////////////////////////////////////////////////////*/
string public name;
string public symbol;
uint8 public immutable decimals;
/*//////////////////////////////////////////////////////////////
ERC20 STORAGE
//////////////////////////////////////////////////////////////*/
uint256 public totalSupply;
mapping(address => uint256) public balanceOf;
mapping(address => mapping(address => uint256)) public allowance;
/*//////////////////////////////////////////////////////////////
EIP-2612 STORAGE
//////////////////////////////////////////////////////////////*/
uint256 internal immutable INITIAL_CHAIN_ID;
bytes32 internal immutable INITIAL_DOMAIN_SEPARATOR;
mapping(address => uint256) public nonces;
/*//////////////////////////////////////////////////////////////
CONSTRUCTOR
//////////////////////////////////////////////////////////////*/
constructor(
string memory _name,
string memory _symbol,
uint8 _decimals
) {
name = _name;
symbol = _symbol;
decimals = _decimals;
INITIAL_CHAIN_ID = block.chainid;
INITIAL_DOMAIN_SEPARATOR = computeDomainSeparator();
}
/*//////////////////////////////////////////////////////////////
ERC20 LOGIC
//////////////////////////////////////////////////////////////*/
function approve(address spender, uint256 amount) public virtual returns (bool) {
allowance[msg.sender][spender] = amount;
emit Approval(msg.sender, spender, amount);
return true;
}
function transfer(address to, uint256 amount) public virtual returns (bool) {
balanceOf[msg.sender] -= amount;
// Cannot overflow because the sum of all user
// balances can't exceed the max uint256 value.
unchecked {
balanceOf[to] += amount;
}
emit Transfer(msg.sender, to, amount);
return true;
}
function transferFrom(
address from,
address to,
uint256 amount
) public virtual returns (bool) {
uint256 allowed = allowance[from][msg.sender]; // Saves gas for limited approvals.
if (allowed != type(uint256).max) allowance[from][msg.sender] = allowed - amount;
balanceOf[from] -= amount;
// Cannot overflow because the sum of all user
// balances can't exceed the max uint256 value.
unchecked {
balanceOf[to] += amount;
}
emit Transfer(from, to, amount);
return true;
}
/*//////////////////////////////////////////////////////////////
EIP-2612 LOGIC
//////////////////////////////////////////////////////////////*/
function permit(
address owner,
address spender,
uint256 value,
uint256 deadline,
uint8 v,
bytes32 r,
bytes32 s
) public virtual {
require(deadline >= block.timestamp, "PERMIT_DEADLINE_EXPIRED");
// Unchecked because the only math done is incrementing
// the owner's nonce which cannot realistically overflow.
unchecked {
address recoveredAddress = ecrecover(
keccak256(
abi.encodePacked(
"\x19\x01",
DOMAIN_SEPARATOR(),
keccak256(
abi.encode(
keccak256(
"Permit(address owner,address spender,uint256 value,uint256 nonce,uint256 deadline)"
),
owner,
spender,
value,
nonces[owner]++,
deadline
)
)
)
),
v,
r,
s
);
require(recoveredAddress != address(0) && recoveredAddress == owner, "INVALID_SIGNER");
allowance[recoveredAddress][spender] = value;
}
emit Approval(owner, spender, value);
}
function DOMAIN_SEPARATOR() public view virtual returns (bytes32) {
return block.chainid == INITIAL_CHAIN_ID ? INITIAL_DOMAIN_SEPARATOR : computeDomainSeparator();
}
function computeDomainSeparator() internal view virtual returns (bytes32) {
return
keccak256(
abi.encode(
keccak256("EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)"),
keccak256(bytes(name)),
keccak256("1"),
block.chainid,
address(this)
)
);
}
/*//////////////////////////////////////////////////////////////
INTERNAL MINT/BURN LOGIC
//////////////////////////////////////////////////////////////*/
function _mint(address to, uint256 amount) internal virtual {
totalSupply += amount;
// Cannot overflow because the sum of all user
// balances can't exceed the max uint256 value.
unchecked {
balanceOf[to] += amount;
}
emit Transfer(address(0), to, amount);
}
function _burn(address from, uint256 amount) internal virtual {
balanceOf[from] -= amount;
// Cannot underflow because a user's balance
// will never be larger than the total supply.
unchecked {
totalSupply -= amount;
}
emit Transfer(from, address(0), amount);
}
}// SPDX-License-Identifier: AGPL-3.0-only
pragma solidity >=0.8.0;
import {ERC20} from "./ERC20.sol";
import {SafeTransferLib} from "../utils/SafeTransferLib.sol";
/// @notice Minimalist and modern Wrapped Ether implementation.
/// @author Solmate (https://github.com/transmissions11/solmate/blob/main/src/tokens/WETH.sol)
/// @author Inspired by WETH9 (https://github.com/dapphub/ds-weth/blob/master/src/weth9.sol)
contract WETH is ERC20("Wrapped Ether", "WETH", 18) {
using SafeTransferLib for address;
event Deposit(address indexed from, uint256 amount);
event Withdrawal(address indexed to, uint256 amount);
function deposit() public payable virtual {
_mint(msg.sender, msg.value);
emit Deposit(msg.sender, msg.value);
}
function withdraw(uint256 amount) public virtual {
_burn(msg.sender, amount);
emit Withdrawal(msg.sender, amount);
msg.sender.safeTransferETH(amount);
}
receive() external payable virtual {
deposit();
}
}// SPDX-License-Identifier: AGPL-3.0-only
pragma solidity >=0.8.0;
/// @notice Arithmetic library with operations for fixed-point numbers.
/// @author Solmate (https://github.com/transmissions11/solmate/blob/main/src/utils/FixedPointMathLib.sol)
/// @author Inspired by USM (https://github.com/usmfum/USM/blob/master/contracts/WadMath.sol)
library FixedPointMathLib {
/*//////////////////////////////////////////////////////////////
SIMPLIFIED FIXED POINT OPERATIONS
//////////////////////////////////////////////////////////////*/
uint256 internal constant MAX_UINT256 = 2**256 - 1;
uint256 internal constant WAD = 1e18; // The scalar of ETH and most ERC20s.
function mulWadDown(uint256 x, uint256 y) internal pure returns (uint256) {
return mulDivDown(x, y, WAD); // Equivalent to (x * y) / WAD rounded down.
}
function mulWadUp(uint256 x, uint256 y) internal pure returns (uint256) {
return mulDivUp(x, y, WAD); // Equivalent to (x * y) / WAD rounded up.
}
function divWadDown(uint256 x, uint256 y) internal pure returns (uint256) {
return mulDivDown(x, WAD, y); // Equivalent to (x * WAD) / y rounded down.
}
function divWadUp(uint256 x, uint256 y) internal pure returns (uint256) {
return mulDivUp(x, WAD, y); // Equivalent to (x * WAD) / y rounded up.
}
/*//////////////////////////////////////////////////////////////
LOW LEVEL FIXED POINT OPERATIONS
//////////////////////////////////////////////////////////////*/
function mulDivDown(
uint256 x,
uint256 y,
uint256 denominator
) internal pure returns (uint256 z) {
/// @solidity memory-safe-assembly
assembly {
// Equivalent to require(denominator != 0 && (y == 0 || x <= type(uint256).max / y))
if iszero(mul(denominator, iszero(mul(y, gt(x, div(MAX_UINT256, y)))))) {
revert(0, 0)
}
// Divide x * y by the denominator.
z := div(mul(x, y), denominator)
}
}
function mulDivUp(
uint256 x,
uint256 y,
uint256 denominator
) internal pure returns (uint256 z) {
/// @solidity memory-safe-assembly
assembly {
// Equivalent to require(denominator != 0 && (y == 0 || x <= type(uint256).max / y))
if iszero(mul(denominator, iszero(mul(y, gt(x, div(MAX_UINT256, y)))))) {
revert(0, 0)
}
// If x * y modulo the denominator is strictly greater than 0,
// 1 is added to round up the division of x * y by the denominator.
z := add(gt(mod(mul(x, y), denominator), 0), div(mul(x, y), denominator))
}
}
function rpow(
uint256 x,
uint256 n,
uint256 scalar
) internal pure returns (uint256 z) {
/// @solidity memory-safe-assembly
assembly {
switch x
case 0 {
switch n
case 0 {
// 0 ** 0 = 1
z := scalar
}
default {
// 0 ** n = 0
z := 0
}
}
default {
switch mod(n, 2)
case 0 {
// If n is even, store scalar in z for now.
z := scalar
}
default {
// If n is odd, store x in z for now.
z := x
}
// Shifting right by 1 is like dividing by 2.
let half := shr(1, scalar)
for {
// Shift n right by 1 before looping to halve it.
n := shr(1, n)
} n {
// Shift n right by 1 each iteration to halve it.
n := shr(1, n)
} {
// Revert immediately if x ** 2 would overflow.
// Equivalent to iszero(eq(div(xx, x), x)) here.
if shr(128, x) {
revert(0, 0)
}
// Store x squared.
let xx := mul(x, x)
// Round to the nearest number.
let xxRound := add(xx, half)
// Revert if xx + half overflowed.
if lt(xxRound, xx) {
revert(0, 0)
}
// Set x to scaled xxRound.
x := div(xxRound, scalar)
// If n is even:
if mod(n, 2) {
// Compute z * x.
let zx := mul(z, x)
// If z * x overflowed:
if iszero(eq(div(zx, x), z)) {
// Revert if x is non-zero.
if iszero(iszero(x)) {
revert(0, 0)
}
}
// Round to the nearest number.
let zxRound := add(zx, half)
// Revert if zx + half overflowed.
if lt(zxRound, zx) {
revert(0, 0)
}
// Return properly scaled zxRound.
z := div(zxRound, scalar)
}
}
}
}
}
/*//////////////////////////////////////////////////////////////
GENERAL NUMBER UTILITIES
//////////////////////////////////////////////////////////////*/
function sqrt(uint256 x) internal pure returns (uint256 z) {
/// @solidity memory-safe-assembly
assembly {
let y := x // We start y at x, which will help us make our initial estimate.
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.
// We check y >= 2^(k + 8) but shift right by k bits
// each branch to ensure that if x >= 256, then y >= 256.
if iszero(lt(y, 0x10000000000000000000000000000000000)) {
y := shr(128, y)
z := shl(64, z)
}
if iszero(lt(y, 0x1000000000000000000)) {
y := shr(64, y)
z := shl(32, z)
}
if iszero(lt(y, 0x10000000000)) {
y := shr(32, y)
z := shl(16, z)
}
if iszero(lt(y, 0x1000000)) {
y := shr(16, y)
z := shl(8, 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(y, 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
// Since the ceil is rare, we save gas on the assignment and repeat division in the rare case.
// If you don't care whether the floor or ceil square root is returned, you can remove this statement.
z := sub(z, lt(div(x, z), z))
}
}
function unsafeMod(uint256 x, uint256 y) internal pure returns (uint256 z) {
/// @solidity memory-safe-assembly
assembly {
// Mod x by y. Note this will return
// 0 instead of reverting if y is zero.
z := mod(x, y)
}
}
function unsafeDiv(uint256 x, uint256 y) internal pure returns (uint256 r) {
/// @solidity memory-safe-assembly
assembly {
// Divide x by y. Note this will return
// 0 instead of reverting if y is zero.
r := div(x, y)
}
}
function unsafeDivUp(uint256 x, uint256 y) internal pure returns (uint256 z) {
/// @solidity memory-safe-assembly
assembly {
// Add 1 to x * y if x % y > 0. Note this will
// return 0 instead of reverting if y is zero.
z := add(gt(mod(x, y), 0), div(x, y))
}
}
}// SPDX-License-Identifier: AGPL-3.0-only
pragma solidity >=0.8.0;
/// @notice Gas optimized reentrancy protection for smart contracts.
/// @author Solmate (https://github.com/transmissions11/solmate/blob/main/src/utils/ReentrancyGuard.sol)
/// @author Modified from OpenZeppelin (https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/security/ReentrancyGuard.sol)
abstract contract ReentrancyGuard {
uint256 private locked = 1;
modifier nonReentrant() virtual {
require(locked == 1, "REENTRANCY");
locked = 2;
_;
locked = 1;
}
}// SPDX-License-Identifier: AGPL-3.0-only
pragma solidity >=0.8.0;
import {ERC20} from "../tokens/ERC20.sol";
/// @notice Safe ETH and ERC20 transfer library that gracefully handles missing return values.
/// @author Solmate (https://github.com/transmissions11/solmate/blob/main/src/utils/SafeTransferLib.sol)
/// @dev Use with caution! Some functions in this library knowingly create dirty bits at the destination of the free memory pointer.
library SafeTransferLib {
/*//////////////////////////////////////////////////////////////
ETH OPERATIONS
//////////////////////////////////////////////////////////////*/
function safeTransferETH(address to, uint256 amount) internal {
bool success;
/// @solidity memory-safe-assembly
assembly {
// Transfer the ETH and store if it succeeded or not.
success := call(gas(), to, amount, 0, 0, 0, 0)
}
require(success, "ETH_TRANSFER_FAILED");
}
/*//////////////////////////////////////////////////////////////
ERC20 OPERATIONS
//////////////////////////////////////////////////////////////*/
function safeTransferFrom(
ERC20 token,
address from,
address to,
uint256 amount
) internal {
bool success;
/// @solidity memory-safe-assembly
assembly {
// Get a pointer to some free memory.
let freeMemoryPointer := mload(0x40)
// Write the abi-encoded calldata into memory, beginning with the function selector.
mstore(freeMemoryPointer, 0x23b872dd00000000000000000000000000000000000000000000000000000000)
mstore(add(freeMemoryPointer, 4), and(from, 0xffffffffffffffffffffffffffffffffffffffff)) // Append and mask the "from" argument.
mstore(add(freeMemoryPointer, 36), and(to, 0xffffffffffffffffffffffffffffffffffffffff)) // Append and mask the "to" argument.
mstore(add(freeMemoryPointer, 68), amount) // Append the "amount" argument. Masking not required as it's a full 32 byte type.
// We use 100 because the length of our calldata totals up like so: 4 + 32 * 3.
// We use 0 and 32 to copy up to 32 bytes of return data into the scratch space.
success := call(gas(), token, 0, freeMemoryPointer, 100, 0, 32)
// Set success to whether the call reverted, if not we check it either
// returned exactly 1 (can't just be non-zero data), or had no return data and token has code.
if and(iszero(and(eq(mload(0), 1), gt(returndatasize(), 31))), success) {
success := iszero(or(iszero(extcodesize(token)), returndatasize()))
}
}
require(success, "TRANSFER_FROM_FAILED");
}
function safeTransfer(
ERC20 token,
address to,
uint256 amount
) internal {
bool success;
/// @solidity memory-safe-assembly
assembly {
// Get a pointer to some free memory.
let freeMemoryPointer := mload(0x40)
// Write the abi-encoded calldata into memory, beginning with the function selector.
mstore(freeMemoryPointer, 0xa9059cbb00000000000000000000000000000000000000000000000000000000)
mstore(add(freeMemoryPointer, 4), and(to, 0xffffffffffffffffffffffffffffffffffffffff)) // Append and mask the "to" argument.
mstore(add(freeMemoryPointer, 36), amount) // Append the "amount" argument. Masking not required as it's a full 32 byte type.
// We use 68 because the length of our calldata totals up like so: 4 + 32 * 2.
// We use 0 and 32 to copy up to 32 bytes of return data into the scratch space.
success := call(gas(), token, 0, freeMemoryPointer, 68, 0, 32)
// Set success to whether the call reverted, if not we check it either
// returned exactly 1 (can't just be non-zero data), or had no return data and token has code.
if and(iszero(and(eq(mload(0), 1), gt(returndatasize(), 31))), success) {
success := iszero(or(iszero(extcodesize(token)), returndatasize()))
}
}
require(success, "TRANSFER_FAILED");
}
function safeApprove(
ERC20 token,
address to,
uint256 amount
) internal {
bool success;
/// @solidity memory-safe-assembly
assembly {
// Get a pointer to some free memory.
let freeMemoryPointer := mload(0x40)
// Write the abi-encoded calldata into memory, beginning with the function selector.
mstore(freeMemoryPointer, 0x095ea7b300000000000000000000000000000000000000000000000000000000)
mstore(add(freeMemoryPointer, 4), and(to, 0xffffffffffffffffffffffffffffffffffffffff)) // Append and mask the "to" argument.
mstore(add(freeMemoryPointer, 36), amount) // Append the "amount" argument. Masking not required as it's a full 32 byte type.
// We use 68 because the length of our calldata totals up like so: 4 + 32 * 2.
// We use 0 and 32 to copy up to 32 bytes of return data into the scratch space.
success := call(gas(), token, 0, freeMemoryPointer, 68, 0, 32)
// Set success to whether the call reverted, if not we check it either
// returned exactly 1 (can't just be non-zero data), or had no return data and token has code.
if and(iszero(and(eq(mload(0), 1), gt(returndatasize(), 31))), success) {
success := iszero(or(iszero(extcodesize(token)), returndatasize()))
}
}
require(success, "APPROVE_FAILED");
}
}// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.21;
import {Address} from "@openzeppelin/contracts/utils/Address.sol";
import {ERC721Holder} from "@openzeppelin/contracts/token/ERC721/utils/ERC721Holder.sol";
import {ERC1155Holder} from "@openzeppelin/contracts/token/ERC1155/utils/ERC1155Holder.sol";
import {FixedPointMathLib} from "@solmate/utils/FixedPointMathLib.sol";
import {SafeTransferLib} from "@solmate/utils/SafeTransferLib.sol";
import {ERC20} from "@solmate/tokens/ERC20.sol";
import {BeforeTransferHook} from "../../src/interfaces/BeforeTransferHook.sol";
import {Auth, Authority} from "@solmate/auth/Auth.sol";
contract BoringVault is ERC20, Auth, ERC721Holder, ERC1155Holder {
using Address for address;
using SafeTransferLib for ERC20;
using FixedPointMathLib for uint256;
// ========================================= STATE =========================================
/**
* @notice Contract responsbile for implementing `beforeTransfer`.
*/
BeforeTransferHook public hook;
//============================== EVENTS ===============================
event Enter(address indexed from, address indexed asset, uint256 amount, address indexed to, uint256 shares);
event Exit(address indexed to, address indexed asset, uint256 amount, address indexed from, uint256 shares);
//============================== CONSTRUCTOR ===============================
constructor(address _owner, string memory _name, string memory _symbol, uint8 _decimals)
ERC20(_name, _symbol, _decimals)
Auth(_owner, Authority(address(0)))
{}
//============================== MANAGE ===============================
/**
* @notice Allows manager to make an arbitrary function call from this contract.
* @dev Callable by MANAGER_ROLE.
*/
function manage(address target, bytes calldata data, uint256 value)
external
requiresAuth
returns (bytes memory result)
{
result = target.functionCallWithValue(data, value);
}
/**
* @notice Allows manager to make arbitrary function calls from this contract.
* @dev Callable by MANAGER_ROLE.
*/
function manage(address[] calldata targets, bytes[] calldata data, uint256[] calldata values)
external
requiresAuth
returns (bytes[] memory results)
{
uint256 targetsLength = targets.length;
results = new bytes[](targetsLength);
for (uint256 i; i < targetsLength; ++i) {
results[i] = targets[i].functionCallWithValue(data[i], values[i]);
}
}
//============================== ENTER ===============================
/**
* @notice Allows minter to mint shares, in exchange for assets.
* @dev If assetAmount is zero, no assets are transferred in.
* @dev Callable by MINTER_ROLE.
*/
function enter(address from, ERC20 asset, uint256 assetAmount, address to, uint256 shareAmount)
external
requiresAuth
{
// Transfer assets in
if (assetAmount > 0) asset.safeTransferFrom(from, address(this), assetAmount);
// Mint shares.
_mint(to, shareAmount);
emit Enter(from, address(asset), assetAmount, to, shareAmount);
}
//============================== EXIT ===============================
/**
* @notice Allows burner to burn shares, in exchange for assets.
* @dev If assetAmount is zero, no assets are transferred out.
* @dev Callable by BURNER_ROLE.
*/
function exit(address to, ERC20 asset, uint256 assetAmount, address from, uint256 shareAmount)
external
requiresAuth
{
// Burn shares.
_burn(from, shareAmount);
// Transfer assets out.
if (assetAmount > 0) asset.safeTransfer(to, assetAmount);
emit Exit(to, address(asset), assetAmount, from, shareAmount);
}
//============================== BEFORE TRANSFER HOOK ===============================
/**
* @notice Sets the share locker.
* @notice If set to zero address, the share locker logic is disabled.
* @dev Callable by OWNER_ROLE.
*/
function setBeforeTransferHook(address _hook) external requiresAuth {
hook = BeforeTransferHook(_hook);
}
/**
* @notice Call `beforeTransferHook` passing in `from` `to`, and `msg.sender`.
*/
function _callBeforeTransfer(address from, address to) internal view {
if (address(hook) != address(0)) hook.beforeTransfer(from, to, msg.sender);
}
function transfer(address to, uint256 amount) public override returns (bool) {
_callBeforeTransfer(msg.sender, to);
return super.transfer(to, amount);
}
function transferFrom(address from, address to, uint256 amount) public override returns (bool) {
_callBeforeTransfer(from, to);
return super.transferFrom(from, to, amount);
}
//============================== RECEIVE ===============================
receive() external payable {}
}// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.21;
import {FixedPointMathLib} from "@solmate/utils/FixedPointMathLib.sol";
import {IRateProvider} from "../../../src/interfaces/IRateProvider.sol";
import {ERC20} from "@solmate/tokens/ERC20.sol";
import {SafeTransferLib} from "@solmate/utils/SafeTransferLib.sol";
import {BoringVault} from "../../../src/base/BoringVault.sol";
import {Auth, Authority} from "@solmate/auth/Auth.sol";
import {IPausable} from "../../../src/interfaces/IPausable.sol";
contract AccountantWithRateProviders is Auth, IRateProvider, IPausable {
using FixedPointMathLib for uint256;
using SafeTransferLib for ERC20;
// ========================================= STRUCTS =========================================
/**
* @param payoutAddress the address `claimFees` sends fees to
* @param highwaterMark the highest value of the BoringVault's share price
* @param feesOwedInBase total pending fees owed in terms of base
* @param totalSharesLastUpdate total amount of shares the last exchange rate update
* @param exchangeRate the current exchange rate in terms of base
* @param allowedExchangeRateChangeUpper the max allowed change to exchange rate from an update
* @param allowedExchangeRateChangeLower the min allowed change to exchange rate from an update
* @param lastUpdateTimestamp the block timestamp of the last exchange rate update
* @param isPaused whether or not this contract is paused
* @param minimumUpdateDelayInSeconds the minimum amount of time that must pass between
* exchange rate updates, such that the update won't trigger the contract to be paused
* @param platformFee the platform fee
* @param performanceFee the performance fee
*/
struct AccountantState {
address payoutAddress;
uint96 highwaterMark;
uint128 feesOwedInBase;
uint128 totalSharesLastUpdate;
uint96 exchangeRate;
uint16 allowedExchangeRateChangeUpper;
uint16 allowedExchangeRateChangeLower;
uint64 lastUpdateTimestamp;
bool isPaused;
uint24 minimumUpdateDelayInSeconds;
uint16 platformFee;
uint16 performanceFee;
}
/**
* @param isPeggedToBase whether or not the asset is 1:1 with the base asset
* @param rateProvider the rate provider for this asset if `isPeggedToBase` is false
*/
struct RateProviderData {
bool isPeggedToBase;
IRateProvider rateProvider;
}
// ========================================= STATE =========================================
/**
* @notice Store the accountant state in 3 packed slots.
*/
AccountantState public accountantState;
/**
* @notice Maps ERC20s to their RateProviderData.
*/
mapping(ERC20 => RateProviderData) public rateProviderData;
//============================== ERRORS ===============================
error AccountantWithRateProviders__UpperBoundTooSmall();
error AccountantWithRateProviders__LowerBoundTooLarge();
error AccountantWithRateProviders__PlatformFeeTooLarge();
error AccountantWithRateProviders__PerformanceFeeTooLarge();
error AccountantWithRateProviders__Paused();
error AccountantWithRateProviders__ZeroFeesOwed();
error AccountantWithRateProviders__OnlyCallableByBoringVault();
error AccountantWithRateProviders__UpdateDelayTooLarge();
error AccountantWithRateProviders__ExchangeRateAboveHighwaterMark();
//============================== EVENTS ===============================
event Paused();
event Unpaused();
event DelayInSecondsUpdated(uint24 oldDelay, uint24 newDelay);
event UpperBoundUpdated(uint16 oldBound, uint16 newBound);
event LowerBoundUpdated(uint16 oldBound, uint16 newBound);
event PlatformFeeUpdated(uint16 oldFee, uint16 newFee);
event PerformanceFeeUpdated(uint16 oldFee, uint16 newFee);
event PayoutAddressUpdated(address oldPayout, address newPayout);
event RateProviderUpdated(address asset, bool isPegged, address rateProvider);
event ExchangeRateUpdated(uint96 oldRate, uint96 newRate, uint64 currentTime);
event FeesClaimed(address indexed feeAsset, uint256 amount);
event HighwaterMarkReset();
//============================== IMMUTABLES ===============================
/**
* @notice The base asset rates are provided in.
*/
ERC20 public immutable base;
/**
* @notice The decimals rates are provided in.
*/
uint8 public immutable decimals;
/**
* @notice The BoringVault this accountant is working with.
* Used to determine share supply for fee calculation.
*/
BoringVault public immutable vault;
/**
* @notice One share of the BoringVault.
*/
uint256 internal immutable ONE_SHARE;
constructor(
address _owner,
address _vault,
address payoutAddress,
uint96 startingExchangeRate,
address _base,
uint16 allowedExchangeRateChangeUpper,
uint16 allowedExchangeRateChangeLower,
uint24 minimumUpdateDelayInSeconds,
uint16 platformFee,
uint16 performanceFee
) Auth(_owner, Authority(address(0))) {
base = ERC20(_base);
decimals = ERC20(_base).decimals();
vault = BoringVault(payable(_vault));
ONE_SHARE = 10 ** vault.decimals();
accountantState = AccountantState({
payoutAddress: payoutAddress,
highwaterMark: startingExchangeRate,
feesOwedInBase: 0,
totalSharesLastUpdate: uint128(vault.totalSupply()),
exchangeRate: startingExchangeRate,
allowedExchangeRateChangeUpper: allowedExchangeRateChangeUpper,
allowedExchangeRateChangeLower: allowedExchangeRateChangeLower,
lastUpdateTimestamp: uint64(block.timestamp),
isPaused: false,
minimumUpdateDelayInSeconds: minimumUpdateDelayInSeconds,
platformFee: platformFee,
performanceFee: performanceFee
});
}
// ========================================= ADMIN FUNCTIONS =========================================
/**
* @notice Pause this contract, which prevents future calls to `updateExchangeRate`, and any safe rate
* calls will revert.
* @dev Callable by MULTISIG_ROLE.
*/
function pause() external requiresAuth {
accountantState.isPaused = true;
emit Paused();
}
/**
* @notice Unpause this contract, which allows future calls to `updateExchangeRate`, and any safe rate
* calls will stop reverting.
* @dev Callable by MULTISIG_ROLE.
*/
function unpause() external requiresAuth {
accountantState.isPaused = false;
emit Unpaused();
}
/**
* @notice Update the minimum time delay between `updateExchangeRate` calls.
* @dev There are no input requirements, as it is possible the admin would want
* the exchange rate updated as frequently as needed.
* @dev Callable by OWNER_ROLE.
*/
function updateDelay(uint24 minimumUpdateDelayInSeconds) external requiresAuth {
if (minimumUpdateDelayInSeconds > 14 days) revert AccountantWithRateProviders__UpdateDelayTooLarge();
uint24 oldDelay = accountantState.minimumUpdateDelayInSeconds;
accountantState.minimumUpdateDelayInSeconds = minimumUpdateDelayInSeconds;
emit DelayInSecondsUpdated(oldDelay, minimumUpdateDelayInSeconds);
}
/**
* @notice Update the allowed upper bound change of exchange rate between `updateExchangeRateCalls`.
* @dev Callable by OWNER_ROLE.
*/
function updateUpper(uint16 allowedExchangeRateChangeUpper) external requiresAuth {
if (allowedExchangeRateChangeUpper < 1e4) revert AccountantWithRateProviders__UpperBoundTooSmall();
uint16 oldBound = accountantState.allowedExchangeRateChangeUpper;
accountantState.allowedExchangeRateChangeUpper = allowedExchangeRateChangeUpper;
emit UpperBoundUpdated(oldBound, allowedExchangeRateChangeUpper);
}
/**
* @notice Update the allowed lower bound change of exchange rate between `updateExchangeRateCalls`.
* @dev Callable by OWNER_ROLE.
*/
function updateLower(uint16 allowedExchangeRateChangeLower) external requiresAuth {
if (allowedExchangeRateChangeLower > 1e4) revert AccountantWithRateProviders__LowerBoundTooLarge();
uint16 oldBound = accountantState.allowedExchangeRateChangeLower;
accountantState.allowedExchangeRateChangeLower = allowedExchangeRateChangeLower;
emit LowerBoundUpdated(oldBound, allowedExchangeRateChangeLower);
}
/**
* @notice Update the platform fee to a new value.
* @dev Callable by OWNER_ROLE.
*/
function updatePlatformFee(uint16 platformFee) external requiresAuth {
if (platformFee > 0.2e4) revert AccountantWithRateProviders__PlatformFeeTooLarge();
uint16 oldFee = accountantState.platformFee;
accountantState.platformFee = platformFee;
emit PlatformFeeUpdated(oldFee, platformFee);
}
/**
* @notice Update the performance fee to a new value.
* @dev Callable by OWNER_ROLE.
*/
function updatePerformanceFee(uint16 performanceFee) external requiresAuth {
if (performanceFee > 0.5e4) revert AccountantWithRateProviders__PerformanceFeeTooLarge();
uint16 oldFee = accountantState.performanceFee;
accountantState.performanceFee = performanceFee;
emit PerformanceFeeUpdated(oldFee, performanceFee);
}
/**
* @notice Update the payout address fees are sent to.
* @dev Callable by OWNER_ROLE.
*/
function updatePayoutAddress(address payoutAddress) external requiresAuth {
address oldPayout = accountantState.payoutAddress;
accountantState.payoutAddress = payoutAddress;
emit PayoutAddressUpdated(oldPayout, payoutAddress);
}
/**
* @notice Update the rate provider data for a specific `asset`.
* @dev Rate providers must return rates in terms of `base` or
* an asset pegged to base and they must use the same decimals
* as `asset`.
* @dev Callable by OWNER_ROLE.
*/
function setRateProviderData(ERC20 asset, bool isPeggedToBase, address rateProvider) external requiresAuth {
rateProviderData[asset] =
RateProviderData({isPeggedToBase: isPeggedToBase, rateProvider: IRateProvider(rateProvider)});
emit RateProviderUpdated(address(asset), isPeggedToBase, rateProvider);
}
/**
* @notice Reset the highwater mark to the current exchange rate.
* @dev Callable by OWNER_ROLE.
*/
function resetHighwaterMark() external virtual requiresAuth {
AccountantState storage state = accountantState;
if (state.exchangeRate > state.highwaterMark) {
revert AccountantWithRateProviders__ExchangeRateAboveHighwaterMark();
}
uint64 currentTime = uint64(block.timestamp);
uint256 currentTotalShares = vault.totalSupply();
_calculateFeesOwed(state, state.exchangeRate, state.exchangeRate, currentTotalShares, currentTime);
state.totalSharesLastUpdate = uint128(currentTotalShares);
state.highwaterMark = accountantState.exchangeRate;
state.lastUpdateTimestamp = currentTime;
emit HighwaterMarkReset();
}
// ========================================= UPDATE EXCHANGE RATE/FEES FUNCTIONS =========================================
/**
* @notice Updates this contract exchangeRate.
* @dev If new exchange rate is outside of accepted bounds, or if not enough time has passed, this
* will pause the contract, and this function will NOT calculate fees owed.
* @dev Callable by UPDATE_EXCHANGE_RATE_ROLE.
*/
function updateExchangeRate(uint96 newExchangeRate) external virtual requiresAuth {
(
bool shouldPause,
AccountantState storage state,
uint64 currentTime,
uint256 currentExchangeRate,
uint256 currentTotalShares
) = _beforeUpdateExchangeRate(newExchangeRate);
if (shouldPause) {
// Instead of reverting, pause the contract. This way the exchange rate updater is able to update the exchange rate
// to a better value, and pause it.
state.isPaused = true;
} else {
_calculateFeesOwed(state, newExchangeRate, currentExchangeRate, currentTotalShares, currentTime);
}
newExchangeRate = _setExchangeRate(newExchangeRate, state);
state.totalSharesLastUpdate = uint128(currentTotalShares);
state.lastUpdateTimestamp = currentTime;
emit ExchangeRateUpdated(uint96(currentExchangeRate), newExchangeRate, currentTime);
}
/**
* @notice Claim pending fees.
* @dev This function must be called by the BoringVault.
* @dev This function will lose precision if the exchange rate
* decimals is greater than the feeAsset's decimals.
*/
function claimFees(ERC20 feeAsset) external {
if (msg.sender != address(vault)) revert AccountantWithRateProviders__OnlyCallableByBoringVault();
AccountantState storage state = accountantState;
if (state.isPaused) revert AccountantWithRateProviders__Paused();
if (state.feesOwedInBase == 0) revert AccountantWithRateProviders__ZeroFeesOwed();
// Determine amount of fees owed in feeAsset.
uint256 feesOwedInFeeAsset;
RateProviderData memory data = rateProviderData[feeAsset];
if (address(feeAsset) == address(base)) {
feesOwedInFeeAsset = state.feesOwedInBase;
} else {
uint8 feeAssetDecimals = ERC20(feeAsset).decimals();
uint256 feesOwedInBaseUsingFeeAssetDecimals =
_changeDecimals(state.feesOwedInBase, decimals, feeAssetDecimals);
if (data.isPeggedToBase) {
feesOwedInFeeAsset = feesOwedInBaseUsingFeeAssetDecimals;
} else {
uint256 rate = data.rateProvider.getRate();
feesOwedInFeeAsset = feesOwedInBaseUsingFeeAssetDecimals.mulDivDown(10 ** feeAssetDecimals, rate);
}
}
// Zero out fees owed.
state.feesOwedInBase = 0;
// Transfer fee asset to payout address.
feeAsset.safeTransferFrom(msg.sender, state.payoutAddress, feesOwedInFeeAsset);
emit FeesClaimed(address(feeAsset), feesOwedInFeeAsset);
}
// ========================================= VIEW FUNCTIONS =========================================
/**
* @notice Get this BoringVault's current rate in the base.
*/
function getRate() public view returns (uint256 rate) {
rate = accountantState.exchangeRate;
}
/**
* @notice Get this BoringVault's current rate in the base.
* @dev Revert if paused.
*/
function getRateSafe() external view returns (uint256 rate) {
if (accountantState.isPaused) revert AccountantWithRateProviders__Paused();
rate = getRate();
}
/**
* @notice Get this BoringVault's current rate in the provided quote.
* @dev `quote` must have its RateProviderData set, else this will revert.
* @dev This function will lose precision if the exchange rate
* decimals is greater than the quote's decimals.
*/
function getRateInQuote(ERC20 quote) public view returns (uint256 rateInQuote) {
if (address(quote) == address(base)) {
rateInQuote = accountantState.exchangeRate;
} else {
RateProviderData memory data = rateProviderData[quote];
uint8 quoteDecimals = ERC20(quote).decimals();
uint256 exchangeRateInQuoteDecimals = _changeDecimals(accountantState.exchangeRate, decimals, quoteDecimals);
if (data.isPeggedToBase) {
rateInQuote = exchangeRateInQuoteDecimals;
} else {
uint256 quoteRate = data.rateProvider.getRate();
uint256 oneQuote = 10 ** quoteDecimals;
rateInQuote = oneQuote.mulDivDown(exchangeRateInQuoteDecimals, quoteRate);
}
}
}
/**
* @notice Get this BoringVault's current rate in the provided quote.
* @dev `quote` must have its RateProviderData set, else this will revert.
* @dev Revert if paused.
*/
function getRateInQuoteSafe(ERC20 quote) external view returns (uint256 rateInQuote) {
if (accountantState.isPaused) revert AccountantWithRateProviders__Paused();
rateInQuote = getRateInQuote(quote);
}
/**
* @notice Preview the result of an update to the exchange rate.
* @return updateWillPause Whether the update will pause the contract.
* @return newFeesOwedInBase The new fees owed in base.
* @return totalFeesOwedInBase The total fees owed in base.
*/
function previewUpdateExchangeRate(uint96 newExchangeRate)
external
view
virtual
returns (bool updateWillPause, uint256 newFeesOwedInBase, uint256 totalFeesOwedInBase)
{
(
bool shouldPause,
AccountantState storage state,
uint64 currentTime,
uint256 currentExchangeRate,
uint256 currentTotalShares
) = _beforeUpdateExchangeRate(newExchangeRate);
updateWillPause = shouldPause;
totalFeesOwedInBase = state.feesOwedInBase;
if (!shouldPause) {
(uint256 platformFeesOwedInBase, uint256 shareSupplyToUse) = _calculatePlatformFee(
state.totalSharesLastUpdate,
state.lastUpdateTimestamp,
state.platformFee,
newExchangeRate,
currentExchangeRate,
currentTotalShares,
currentTime
);
uint256 performanceFeesOwedInBase;
if (newExchangeRate > state.highwaterMark) {
(performanceFeesOwedInBase,) = _calculatePerformanceFee(
newExchangeRate, shareSupplyToUse, state.highwaterMark, state.performanceFee
);
}
newFeesOwedInBase = platformFeesOwedInBase + performanceFeesOwedInBase;
totalFeesOwedInBase += newFeesOwedInBase;
}
}
// ========================================= INTERNAL HELPER FUNCTIONS =========================================
/**
* @notice Used to change the decimals of precision used for an amount.
*/
function _changeDecimals(uint256 amount, uint8 fromDecimals, uint8 toDecimals) internal pure returns (uint256) {
if (fromDecimals == toDecimals) {
return amount;
} else if (fromDecimals < toDecimals) {
return amount * 10 ** (toDecimals - fromDecimals);
} else {
return amount / 10 ** (fromDecimals - toDecimals);
}
}
/**
* @notice Check if the new exchange rate is outside of the allowed bounds or if not enough time has passed.
*/
function _beforeUpdateExchangeRate(uint96 newExchangeRate)
internal
view
returns (
bool shouldPause,
AccountantState storage state,
uint64 currentTime,
uint256 currentExchangeRate,
uint256 currentTotalShares
)
{
state = accountantState;
if (state.isPaused) revert AccountantWithRateProviders__Paused();
currentTime = uint64(block.timestamp);
currentExchangeRate = state.exchangeRate;
currentTotalShares = vault.totalSupply();
shouldPause = currentTime < state.lastUpdateTimestamp + state.minimumUpdateDelayInSeconds
|| newExchangeRate > currentExchangeRate.mulDivDown(state.allowedExchangeRateChangeUpper, 1e4)
|| newExchangeRate < currentExchangeRate.mulDivDown(state.allowedExchangeRateChangeLower, 1e4);
}
/**
* @notice Set the exchange rate.
*/
function _setExchangeRate(uint96 newExchangeRate, AccountantState storage state)
internal
virtual
returns (uint96)
{
state.exchangeRate = newExchangeRate;
return newExchangeRate;
}
/**
* @notice Calculate platform fees.
*/
function _calculatePlatformFee(
uint128 totalSharesLastUpdate,
uint64 lastUpdateTimestamp,
uint16 platformFee,
uint96 newExchangeRate,
uint256 currentExchangeRate,
uint256 currentTotalShares,
uint64 currentTime
) internal view returns (uint256 platformFeesOwedInBase, uint256 shareSupplyToUse) {
shareSupplyToUse = currentTotalShares;
// Use the minimum between current total supply and total supply for last update.
if (totalSharesLastUpdate < shareSupplyToUse) {
shareSupplyToUse = totalSharesLastUpdate;
}
// Determine platform fees owned.
if (platformFee > 0) {
uint256 timeDelta = currentTime - lastUpdateTimestamp;
uint256 minimumAssets = newExchangeRate > currentExchangeRate
? shareSupplyToUse.mulDivDown(currentExchangeRate, ONE_SHARE)
: shareSupplyToUse.mulDivDown(newExchangeRate, ONE_SHARE);
uint256 platformFeesAnnual = minimumAssets.mulDivDown(platformFee, 1e4);
platformFeesOwedInBase = platformFeesAnnual.mulDivDown(timeDelta, 365 days);
}
}
/**
* @notice Calculate performance fees.
*/
function _calculatePerformanceFee(
uint96 newExchangeRate,
uint256 shareSupplyToUse,
uint96 datum,
uint16 performanceFee
) internal view returns (uint256 performanceFeesOwedInBase, uint256 yieldEarned) {
uint256 changeInExchangeRate = newExchangeRate - datum;
yieldEarned = changeInExchangeRate.mulDivDown(shareSupplyToUse, ONE_SHARE);
if (performanceFee > 0) {
performanceFeesOwedInBase = yieldEarned.mulDivDown(performanceFee, 1e4);
}
}
/**
* @notice Calculate fees owed in base.
* @dev This function will update the highwater mark if the new exchange rate is higher.
*/
function _calculateFeesOwed(
AccountantState storage state,
uint96 newExchangeRate,
uint256 currentExchangeRate,
uint256 currentTotalShares,
uint64 currentTime
) internal virtual {
// Only update fees if we are not paused.
// Update fee accounting.
(uint256 newFeesOwedInBase, uint256 shareSupplyToUse) = _calculatePlatformFee(
state.totalSharesLastUpdate,
state.lastUpdateTimestamp,
state.platformFee,
newExchangeRate,
currentExchangeRate,
currentTotalShares,
currentTime
);
// Account for performance fees.
if (newExchangeRate > state.highwaterMark) {
(uint256 performanceFeesOwedInBase,) =
_calculatePerformanceFee(newExchangeRate, shareSupplyToUse, state.highwaterMark, state.performanceFee);
// Add performance fees to fees owed.
newFeesOwedInBase += performanceFeesOwedInBase;
// Always update the highwater mark if the new exchange rate is higher.
// This way if we are not iniitiall taking performance fees, we can start taking them
// without back charging them on past performance.
state.highwaterMark = newExchangeRate;
}
state.feesOwedInBase += uint128(newFeesOwedInBase);
}
}// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.21;
interface IBoringSolver {
function boringSolve(
address initiator,
address boringVault,
address solveAsset,
uint256 totalShares,
uint256 requiredAssets,
bytes calldata solveData
) external;
}// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.21;
interface BeforeTransferHook {
function beforeTransfer(address from, address to, address operator) external view;
}// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.21;
interface IPausable {
function pause() external;
function unpause() external;
}// SPDX-License-Identifier: UNLICENSED
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
pragma solidity ^0.8.0;
interface IRateProvider {
function getRate() external view returns (uint256);
}{
"evmVersion": "shanghai",
"metadata": {
"appendCBOR": true,
"bytecodeHash": "ipfs",
"useLiteralContent": false
},
"optimizer": {
"enabled": true,
"runs": 200
},
"outputSelection": {
"*": {
"*": [
"evm.bytecode",
"evm.deployedBytecode",
"abi"
]
}
},
"remappings": [
"@ccip/=lib/boring-vault/lib/ccip/",
"@devtools-oapp-evm/=lib/boring-vault/lib/OAppAuth/lib/devtools/packages/oapp-evm/contracts/oapp/",
"@ds-test/=lib/boring-vault/lib/forge-std/lib/ds-test/src/",
"@forge-std/=lib/boring-vault/lib/forge-std/src/",
"@layerzerolabs/lz-evm-messagelib-v2/=lib/boring-vault/lib/OAppAuth/node_modules/@layerzerolabs/lz-evm-messagelib-v2/",
"@layerzerolabs/lz-evm-protocol-v2/=lib/boring-vault/lib/OAppAuth/lib/LayerZero-V2/packages/layerzero-v2/evm/protocol/",
"@layerzerolabs/oapp-evm/=lib/boring-vault/lib/OAppAuth/lib/devtools/packages/oapp-evm/",
"@lz-oapp-evm/=lib/boring-vault/lib/OAppAuth/lib/LayerZero-V2/packages/layerzero-v2/evm/oapp/contracts/oapp/",
"@oapp-auth/=lib/boring-vault/lib/OAppAuth/src/",
"@openzeppelin/=lib/boring-vault/lib/openzeppelin-contracts/",
"@solmate/=lib/boring-vault/lib/solmate/src/",
"LayerZero-V2/=lib/boring-vault/lib/OAppAuth/lib/",
"OAppAuth/=lib/boring-vault/lib/OAppAuth/",
"boring-vault/=lib/boring-vault/",
"ccip/=lib/boring-vault/lib/ccip/contracts/",
"ds-test/=lib/solmate/lib/ds-test/src/",
"erc4626-tests/=lib/boring-vault/lib/openzeppelin-contracts/lib/erc4626-tests/",
"forge-std/=lib/forge-std/src/",
"halmos-cheatcodes/=lib/boring-vault/lib/OAppAuth/lib/openzeppelin-contracts/lib/halmos-cheatcodes/src/",
"openzeppelin-contracts/=lib/boring-vault/lib/openzeppelin-contracts/",
"solady/=lib/solady/src/",
"solidity-bytes-utils/=lib/boring-vault/lib/OAppAuth/node_modules/solidity-bytes-utils/",
"solmate/=lib/solmate/src/",
"yearn-vaults/=lib/yearn-vaults/contracts/",
"@sbu/=lib/boring-vault/lib/OAppAuth/lib/solidity-bytes-utils/",
"morpho-blue/=lib/boring-vault/lib/morpho-blue/"
],
"viaIR": false
}Contract Security Audit
- No Contract Security Audit Submitted- Submit Audit Here
Contract ABI
API[{"inputs":[{"internalType":"address","name":"_owner","type":"address"},{"internalType":"address","name":"_auth","type":"address"},{"internalType":"address payable","name":"_boringVault","type":"address"},{"internalType":"address","name":"_accountant","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[],"name":"BoringOnChainQueue__BadDeadline","type":"error"},{"inputs":[],"name":"BoringOnChainQueue__BadDiscount","type":"error"},{"inputs":[],"name":"BoringOnChainQueue__BadInput","type":"error"},{"inputs":[],"name":"BoringOnChainQueue__BadShareAmount","type":"error"},{"inputs":[],"name":"BoringOnChainQueue__BadUser","type":"error"},{"inputs":[],"name":"BoringOnChainQueue__DeadlinePassed","type":"error"},{"inputs":[],"name":"BoringOnChainQueue__Keccak256Collision","type":"error"},{"inputs":[],"name":"BoringOnChainQueue__MAXIMUM_MINIMUM_SECONDS_TO_DEADLINE","type":"error"},{"inputs":[],"name":"BoringOnChainQueue__MAXIMUM_SECONDS_TO_MATURITY","type":"error"},{"inputs":[],"name":"BoringOnChainQueue__MAX_DISCOUNT","type":"error"},{"inputs":[],"name":"BoringOnChainQueue__NotMatured","type":"error"},{"inputs":[],"name":"BoringOnChainQueue__Overflow","type":"error"},{"inputs":[],"name":"BoringOnChainQueue__Paused","type":"error"},{"inputs":[],"name":"BoringOnChainQueue__PermitFailedAndAllowanceTooLow","type":"error"},{"inputs":[],"name":"BoringOnChainQueue__RequestNotFound","type":"error"},{"inputs":[],"name":"BoringOnChainQueue__RescueCannotTakeSharesFromActiveRequests","type":"error"},{"inputs":[],"name":"BoringOnChainQueue__SolveAssetMismatch","type":"error"},{"inputs":[],"name":"BoringOnChainQueue__WithdrawsNotAllowedForAsset","type":"error"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"user","type":"address"},{"indexed":true,"internalType":"contract Authority","name":"newAuthority","type":"address"}],"name":"AuthorityUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"requestId","type":"bytes32"},{"indexed":true,"internalType":"address","name":"user","type":"address"},{"indexed":false,"internalType":"uint256","name":"timestamp","type":"uint256"}],"name":"OnChainWithdrawCancelled","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"requestId","type":"bytes32"},{"indexed":true,"internalType":"address","name":"user","type":"address"},{"indexed":true,"internalType":"address","name":"assetOut","type":"address"},{"indexed":false,"internalType":"uint96","name":"nonce","type":"uint96"},{"indexed":false,"internalType":"uint128","name":"amountOfShares","type":"uint128"},{"indexed":false,"internalType":"uint128","name":"amountOfAssets","type":"uint128"},{"indexed":false,"internalType":"uint40","name":"creationTime","type":"uint40"},{"indexed":false,"internalType":"uint24","name":"secondsToMaturity","type":"uint24"},{"indexed":false,"internalType":"uint24","name":"secondsToDeadline","type":"uint24"}],"name":"OnChainWithdrawRequested","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"requestId","type":"bytes32"},{"indexed":true,"internalType":"address","name":"user","type":"address"},{"indexed":false,"internalType":"uint256","name":"timestamp","type":"uint256"}],"name":"OnChainWithdrawSolved","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"user","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"anonymous":false,"inputs":[],"name":"Paused","type":"event"},{"anonymous":false,"inputs":[],"name":"Unpaused","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"assetOut","type":"address"},{"indexed":false,"internalType":"uint24","name":"secondsToMaturity","type":"uint24"},{"indexed":false,"internalType":"uint24","name":"minimumSecondsToDeadline","type":"uint24"},{"indexed":false,"internalType":"uint16","name":"minDiscount","type":"uint16"},{"indexed":false,"internalType":"uint16","name":"maxDiscount","type":"uint16"},{"indexed":false,"internalType":"uint96","name":"minimumShares","type":"uint96"}],"name":"WithdrawAssetSetup","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"assetOut","type":"address"}],"name":"WithdrawAssetStopped","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"assetOut","type":"address"},{"indexed":false,"internalType":"uint24","name":"minimumSecondsToDeadline","type":"uint24"},{"indexed":false,"internalType":"uint24","name":"secondsToMaturity","type":"uint24"},{"indexed":false,"internalType":"uint16","name":"minDiscount","type":"uint16"},{"indexed":false,"internalType":"uint16","name":"maxDiscount","type":"uint16"},{"indexed":false,"internalType":"uint96","name":"minimumShares","type":"uint96"}],"name":"WithdrawAssetUpdated","type":"event"},{"inputs":[],"name":"ONE_SHARE","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"accountant","outputs":[{"internalType":"contract AccountantWithRateProviders","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"authority","outputs":[{"internalType":"contract Authority","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"boringVault","outputs":[{"internalType":"contract BoringVault","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"components":[{"internalType":"uint96","name":"nonce","type":"uint96"},{"internalType":"address","name":"user","type":"address"},{"internalType":"address","name":"assetOut","type":"address"},{"internalType":"uint128","name":"amountOfShares","type":"uint128"},{"internalType":"uint128","name":"amountOfAssets","type":"uint128"},{"internalType":"uint40","name":"creationTime","type":"uint40"},{"internalType":"uint24","name":"secondsToMaturity","type":"uint24"},{"internalType":"uint24","name":"secondsToDeadline","type":"uint24"}],"internalType":"struct BoringOnChainQueue.OnChainWithdraw","name":"request","type":"tuple"}],"name":"cancelOnChainWithdraw","outputs":[{"internalType":"bytes32","name":"requestId","type":"bytes32"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"components":[{"internalType":"uint96","name":"nonce","type":"uint96"},{"internalType":"address","name":"user","type":"address"},{"internalType":"address","name":"assetOut","type":"address"},{"internalType":"uint128","name":"amountOfShares","type":"uint128"},{"internalType":"uint128","name":"amountOfAssets","type":"uint128"},{"internalType":"uint40","name":"creationTime","type":"uint40"},{"internalType":"uint24","name":"secondsToMaturity","type":"uint24"},{"internalType":"uint24","name":"secondsToDeadline","type":"uint24"}],"internalType":"struct BoringOnChainQueue.OnChainWithdraw[]","name":"requests","type":"tuple[]"}],"name":"cancelUserWithdraws","outputs":[{"internalType":"bytes32[]","name":"canceledRequestIds","type":"bytes32[]"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"components":[{"internalType":"uint96","name":"nonce","type":"uint96"},{"internalType":"address","name":"user","type":"address"},{"internalType":"address","name":"assetOut","type":"address"},{"internalType":"uint128","name":"amountOfShares","type":"uint128"},{"internalType":"uint128","name":"amountOfAssets","type":"uint128"},{"internalType":"uint40","name":"creationTime","type":"uint40"},{"internalType":"uint24","name":"secondsToMaturity","type":"uint24"},{"internalType":"uint24","name":"secondsToDeadline","type":"uint24"}],"internalType":"struct BoringOnChainQueue.OnChainWithdraw","name":"request","type":"tuple"}],"name":"getRequestId","outputs":[{"internalType":"bytes32","name":"requestId","type":"bytes32"}],"stateMutability":"pure","type":"function"},{"inputs":[],"name":"getRequestIds","outputs":[{"internalType":"bytes32[]","name":"","type":"bytes32[]"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"isPaused","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"nonce","outputs":[{"internalType":"uint96","name":"","type":"uint96"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"pause","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"assetOut","type":"address"},{"internalType":"uint128","name":"amountOfShares","type":"uint128"},{"internalType":"uint16","name":"discount","type":"uint16"}],"name":"previewAssetsOut","outputs":[{"internalType":"uint128","name":"amountOfAssets128","type":"uint128"}],"stateMutability":"view","type":"function"},{"inputs":[{"components":[{"internalType":"uint96","name":"nonce","type":"uint96"},{"internalType":"address","name":"user","type":"address"},{"internalType":"address","name":"assetOut","type":"address"},{"internalType":"uint128","name":"amountOfShares","type":"uint128"},{"internalType":"uint128","name":"amountOfAssets","type":"uint128"},{"internalType":"uint40","name":"creationTime","type":"uint40"},{"internalType":"uint24","name":"secondsToMaturity","type":"uint24"},{"internalType":"uint24","name":"secondsToDeadline","type":"uint24"}],"internalType":"struct BoringOnChainQueue.OnChainWithdraw","name":"oldRequest","type":"tuple"},{"internalType":"uint16","name":"discount","type":"uint16"},{"internalType":"uint24","name":"secondsToDeadline","type":"uint24"}],"name":"replaceOnChainWithdraw","outputs":[{"internalType":"bytes32","name":"oldRequestId","type":"bytes32"},{"internalType":"bytes32","name":"newRequestId","type":"bytes32"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"assetOut","type":"address"},{"internalType":"uint128","name":"amountOfShares","type":"uint128"},{"internalType":"uint16","name":"discount","type":"uint16"},{"internalType":"uint24","name":"secondsToDeadline","type":"uint24"}],"name":"requestOnChainWithdraw","outputs":[{"internalType":"bytes32","name":"requestId","type":"bytes32"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"assetOut","type":"address"},{"internalType":"uint128","name":"amountOfShares","type":"uint128"},{"internalType":"uint16","name":"discount","type":"uint16"},{"internalType":"uint24","name":"secondsToDeadline","type":"uint24"},{"internalType":"uint256","name":"permitDeadline","type":"uint256"},{"internalType":"uint8","name":"v","type":"uint8"},{"internalType":"bytes32","name":"r","type":"bytes32"},{"internalType":"bytes32","name":"s","type":"bytes32"}],"name":"requestOnChainWithdrawWithPermit","outputs":[{"internalType":"bytes32","name":"requestId","type":"bytes32"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"contract ERC20","name":"token","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"address","name":"to","type":"address"},{"components":[{"internalType":"uint96","name":"nonce","type":"uint96"},{"internalType":"address","name":"user","type":"address"},{"internalType":"address","name":"assetOut","type":"address"},{"internalType":"uint128","name":"amountOfShares","type":"uint128"},{"internalType":"uint128","name":"amountOfAssets","type":"uint128"},{"internalType":"uint40","name":"creationTime","type":"uint40"},{"internalType":"uint24","name":"secondsToMaturity","type":"uint24"},{"internalType":"uint24","name":"secondsToDeadline","type":"uint24"}],"internalType":"struct BoringOnChainQueue.OnChainWithdraw[]","name":"activeRequests","type":"tuple[]"}],"name":"rescueTokens","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"contract Authority","name":"newAuthority","type":"address"}],"name":"setAuthority","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"components":[{"internalType":"uint96","name":"nonce","type":"uint96"},{"internalType":"address","name":"user","type":"address"},{"internalType":"address","name":"assetOut","type":"address"},{"internalType":"uint128","name":"amountOfShares","type":"uint128"},{"internalType":"uint128","name":"amountOfAssets","type":"uint128"},{"internalType":"uint40","name":"creationTime","type":"uint40"},{"internalType":"uint24","name":"secondsToMaturity","type":"uint24"},{"internalType":"uint24","name":"secondsToDeadline","type":"uint24"}],"internalType":"struct BoringOnChainQueue.OnChainWithdraw[]","name":"requests","type":"tuple[]"},{"internalType":"bytes","name":"solveData","type":"bytes"},{"internalType":"address","name":"solver","type":"address"}],"name":"solveOnChainWithdraws","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"assetOut","type":"address"}],"name":"stopWithdrawsInAsset","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"unpause","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"assetOut","type":"address"},{"internalType":"uint24","name":"secondsToMaturity","type":"uint24"},{"internalType":"uint24","name":"minimumSecondsToDeadline","type":"uint24"},{"internalType":"uint16","name":"minDiscount","type":"uint16"},{"internalType":"uint16","name":"maxDiscount","type":"uint16"},{"internalType":"uint96","name":"minimumShares","type":"uint96"}],"name":"updateWithdrawAsset","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"withdrawAssets","outputs":[{"internalType":"bool","name":"allowWithdraws","type":"bool"},{"internalType":"uint24","name":"secondsToMaturity","type":"uint24"},{"internalType":"uint24","name":"minimumSecondsToDeadline","type":"uint24"},{"internalType":"uint16","name":"minDiscount","type":"uint16"},{"internalType":"uint16","name":"maxDiscount","type":"uint16"},{"internalType":"uint96","name":"minimumShares","type":"uint96"}],"stateMutability":"view","type":"function"}]Contract Creation Code
60e060405260016002819055600680546001600160601b03191690911790553480156200002a575f80fd5b5060405162002de938038062002de98339810160408190526200004d916200018b565b5f80546001600160a01b03199081166001600160a01b0387811691821784556001805490931690871617909155604051869286929133917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e091a36040516001600160a01b0382169033907fa3396fd7f6e0a21b50e5089d2da70d5ac0a3bbbd1f617a93f134b76389980198905f90a350506001600160a01b03821660808190526040805163313ce56760e01b8152905163313ce567916004808201926020929091908290030181865afa15801562000127573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906200014d9190620001f0565b6200015a90600a62000328565b60c0526001600160a01b031660a0525062000338915050565b6001600160a01b038116811462000188575f80fd5b50565b5f805f80608085870312156200019f575f80fd5b8451620001ac8162000173565b6020860151909450620001bf8162000173565b6040860151909350620001d28162000173565b6060860151909250620001e58162000173565b939692955090935050565b5f6020828403121562000201575f80fd5b815160ff8116811462000212575f80fd5b9392505050565b634e487b7160e01b5f52601160045260245ffd5b600181815b808511156200026d57815f190482111562000251576200025162000219565b808516156200025f57918102915b93841c939080029062000232565b509250929050565b5f82620002855750600162000322565b816200029357505f62000322565b8160018114620002ac5760028114620002b757620002d7565b600191505062000322565b60ff841115620002cb57620002cb62000219565b50506001821b62000322565b5060208310610133831016604e8410600b8410161715620002fc575081810a62000322565b6200030883836200022d565b805f19048211156200031e576200031e62000219565b0290505b92915050565b5f6200021260ff84168362000275565b60805160a05160c051612a32620003b75f395f81816103b501526113e801525f81816101b20152818161134d015261153101525f81816104400152818161049e015281816105f901528181610ac101528181610b1401528181610d5b01528181610ddf01528181610e7c01528181610f9e0152611d570152612a325ff3fe608060405234801561000f575f80fd5b5060043610610153575f3560e01c8063a5672fd7116100bf578063b7d122b511610079578063b7d122b5146103b0578063bf7e214f146103d7578063e69a31c2146103ea578063eed4b3f814610415578063f2fde38b14610428578063f3b977841461043b575f80fd5b8063a5672fd714610272578063aa5a0ffd1461029a578063ac33a27314610346578063affed0e01461034e578063b187bd2614610379578063b22ed42a1461039d575f80fd5b80636bb3b476116101105780636bb3b476146101ff57806374732728146102125780637a9e5e4b146102255780638456cb59146102385780638da5cb5b146102405780639fff7e2a14610252575f80fd5b80630bf6cab7146101575780633f4ba83a1461016c578063412638dc146101745780634a2dc5e4146101875780634fb3ccc5146101ad578063581b4920146101ec575b5f80fd5b61016a6101653660046121b8565b610462565b005b61016a610734565b61016a610182366004612226565b61079c565b61019a610195366004612407565b610c0f565b6040519081526020015b60405180910390f35b6101d47f000000000000000000000000000000000000000000000000000000000000000081565b6040516001600160a01b0390911681526020016101a4565b61019a6101fa366004612433565b610c50565b61019a61020d3660046124b9565b610ece565b61016a61022036600461250c565b610fec565b61016a61023336600461250c565b611065565b61016a611149565b5f546101d4906001600160a01b031681565b610265610260366004612527565b6111b7565b6040516101a4919061255a565b61028561028036600461259d565b6112a0565b604080519283526020830191909152016101a4565b6102ff6102a836600461250c565b60056020525f908152604090205460ff81169062ffffff610100820481169164010000000081049091169061ffff600160381b8204811691600160481b8104909116906001600160601b03600160581b9091041686565b60408051961515875262ffffff9586166020880152939094169285019290925261ffff90811660608501521660808301526001600160601b031660a082015260c0016101a4565b6102656112ea565b600654610361906001600160601b031681565b6040516001600160601b0390911681526020016101a4565b60065461038d90600160601b900460ff1681565b60405190151581526020016101a4565b61019a6103ab3660046125e1565b6112fb565b61019a7f000000000000000000000000000000000000000000000000000000000000000081565b6001546101d4906001600160a01b031681565b6103fd6103f83660046125f2565b61132a565b6040516001600160801b0390911681526020016101a4565b61016a61042336600461262b565b61143f565b61016a61043636600461250c565b611767565b6101d47f000000000000000000000000000000000000000000000000000000000000000081565b610477335f356001600160e01b0319166117e2565b61049c5760405162461bcd60e51b81526004016104939061269d565b60405180910390fd5b7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316856001600160a01b0316036106a8575f6104e06003611888565b8051909150828114610505576040516312ed8d4160e21b815260040160405180910390fd5b5f805b828110156105d757838181518110610522576105226126c3565b602002602001015186868381811061053c5761053c6126c3565b9050610100020160405160200161055391906126d7565b6040516020818303038152906040528051906020012014610587576040516312ed8d4160e21b815260040160405180910390fd5b858582818110610599576105996126c3565b9050610100020160600160208101906105b291906127a1565b6105c5906001600160801b0316836127ce565b91506105d0816127e1565b9050610508565b506040516370a0823160e01b81523060048201525f9082906001600160a01b037f000000000000000000000000000000000000000000000000000000000000000016906370a0823190602401602060405180830381865afa15801561063e573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061066291906127f9565b61066c9190612810565b90505f19880361067e5780975061069f565b8088111561069f5760405163fbeb452f60e01b815260040160405180910390fd5b50505050610719565b5f198403610719576040516370a0823160e01b81523060048201526001600160a01b038616906370a0823190602401602060405180830381865afa1580156106f2573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061071691906127f9565b93505b61072d6001600160a01b038616848661189b565b5050505050565b610749335f356001600160e01b0319166117e2565b6107655760405162461bcd60e51b81526004016104939061269d565b6006805460ff60601b191690556040517fa45f47fdea8a1efdd9029a5691c7f759c32b7c698632b563573e155625d16933905f90a1565b6107b1335f356001600160e01b0319166117e2565b6107cd5760405162461bcd60e51b81526004016104939061269d565b600654600160601b900460ff16156107f85760405163158b17e360e11b815260040160405180910390fd5b5f85855f81811061080b5761080b6126c3565b905061010002016040016020810190610824919061250c565b90505f8086815b81811015610ab357898982818110610845576108456126c3565b90506101000201604001602081019061085e919061250c565b6001600160a01b0316856001600160a01b03161461088f576040516331f59b5960e21b815260040160405180910390fd5b5f8a8a838181106108a2576108a26126c3565b9050610100020160c00160208101906108bb9190612823565b62ffffff168b8b848181106108d2576108d26126c3565b9050610100020160a00160208101906108eb919061283c565b6108f59190612855565b64ffffffffff1690508042101561091f576040516332924a4960e01b815260040160405180910390fd5b5f8b8b84818110610932576109326126c3565b9050610100020160e001602081019061094b9190612823565b61095a9062ffffff16836127ce565b90508042111561097d576040516378b2b00760e01b815260040160405180910390fd5b8b8b8481811061098f5761098f6126c3565b9050610100020160800160208101906109a891906127a1565b6109bb906001600160801b0316876127ce565b95508b8b848181106109cf576109cf6126c3565b9050610100020160600160208101906109e891906127a1565b6109fb906001600160801b0316866127ce565b94505f610a2f8d8d86818110610a1357610a136126c3565b90506101000201803603810190610a2a9190612407565b61192a565b90508c8c85818110610a4357610a436126c3565b905061010002016020016020810190610a5c919061250c565b6001600160a01b0316817fd94fc49a6578873ff851671d19cacb1809887f7a9128867ee4306dc3ffc93c2642604051610a9791815260200190565b60405180910390a350505080610aac906127e1565b905061082b565b50610ae86001600160a01b037f000000000000000000000000000000000000000000000000000000000000000016868461189b565b8515610b74576040516333d5020b60e11b81526001600160a01b038616906367aa041690610b469033907f000000000000000000000000000000000000000000000000000000000000000090899088908a908f908f90600401612873565b5f604051808303815f87803b158015610b5d575f80fd5b505af1158015610b6f573d5f803e3d5ffd5b505050505b5f5b81811015610c0357610bf3868b8b84818110610b9457610b946126c3565b905061010002016020016020810190610bad919061250c565b8c8c85818110610bbf57610bbf6126c3565b905061010002016080016020810190610bd891906127a1565b6001600160a01b0389169291906001600160801b0316611988565b610bfc816127e1565b9050610b76565b50505050505050505050565b5f610c25335f356001600160e01b0319166117e2565b610c415760405162461bcd60e51b81526004016104939061269d565b610c4a82611a25565b92915050565b5f610c66335f356001600160e01b0319166117e2565b610c825760405162461bcd60e51b81526004016104939061269d565b6001600160a01b0389165f90815260056020908152604091829020825160c081018452905460ff81161515825262ffffff610100820481169383019390935264010000000081049092169281019290925261ffff600160381b820481166060840152600160481b82041660808301526001600160601b03600160581b9091041660a0820152610d13818a8a8a611a5f565b60405163d505accf60e01b81523360048201523060248201526001600160801b038a1660448201526064810187905260ff8616608482015260a4810185905260c481018490527f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03169063d505accf9060e4015f604051808303815f87803b158015610da4575f80fd5b505af1925050508015610db5575060015b610e6f57604051636eb1769f60e11b81523360048201523060248201526001600160801b038a16907f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03169063dd62ed3e90604401602060405180830381865afa158015610e2c573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610e5091906127f9565b1015610e6f57604051634bfd8d1d60e01b815260040160405180910390fd5b610ead6001600160a01b037f00000000000000000000000000000000000000000000000000000000000000001633306001600160801b038d16611988565b610ebf338b8b8b85602001518c611b52565b509a9950505050505050505050565b5f610ee4335f356001600160e01b0319166117e2565b610f005760405162461bcd60e51b81526004016104939061269d565b6001600160a01b0385165f90815260056020908152604091829020825160c081018452905460ff81161515825262ffffff610100820481169383019390935264010000000081049092169281019290925261ffff600160381b820481166060840152600160481b82041660808301526001600160601b03600160581b9091041660a0820152610f9181868686611a5f565b610fcf6001600160a01b037f00000000000000000000000000000000000000000000000000000000000000001633306001600160801b038916611988565b610fe133878787856020015188611b52565b509695505050505050565b611001335f356001600160e01b0319166117e2565b61101d5760405162461bcd60e51b81526004016104939061269d565b6001600160a01b0381165f81815260056020526040808220805460ff19169055517ff1abf38a870f414456542524a2b679c0ece751691e36f4feee2ca7826c99e4629190a250565b5f546001600160a01b03163314806110f6575060015460405163b700961360e01b81526001600160a01b039091169063b7009613906110b790339030906001600160e01b03195f3516906004016128d6565b602060405180830381865afa1580156110d2573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906110f69190612903565b6110fe575f80fd5b600180546001600160a01b0319166001600160a01b03831690811790915560405133907fa3396fd7f6e0a21b50e5089d2da70d5ac0a3bbbd1f617a93f134b76389980198905f90a350565b61115e335f356001600160e01b0319166117e2565b61117a5760405162461bcd60e51b81526004016104939061269d565b6006805460ff60601b1916600160601b1790556040517f9e87fac88ff661f02d44f95383c817fece4bce600a3dab7a54406878b965e752905f90a1565b60606111ce335f356001600160e01b0319166117e2565b6111ea5760405162461bcd60e51b81526004016104939061269d565b818067ffffffffffffffff811115611204576112046122cf565b60405190808252806020026020018201604052801561122d578160200160208202803683370190505b5091505f5b818110156112985761126b85858381811061124f5761124f6126c3565b905061010002018036038101906112669190612407565b611d33565b83828151811061127d5761127d6126c3565b6020908102919091010152611291816127e1565b9050611232565b505092915050565b5f806112b7335f356001600160e01b0319166117e2565b6112d35760405162461bcd60e51b81526004016104939061269d565b6112de858585611ddb565b90969095509350505050565b60606112f66003611888565b905090565b5f8160405160200161130d91906126d7565b604051602081830303815290604052805190602001209050919050565b604051634104b9ed60e11b81526001600160a01b0384811660048301525f9182917f0000000000000000000000000000000000000000000000000000000000000000169063820973da90602401602060405180830381865afa158015611392573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906113b691906127f9565b90506113d56113c784612710612922565b829061ffff16612710611e2e565b90505f61140c6001600160801b038616837f0000000000000000000000000000000000000000000000000000000000000000611e2e565b90506001600160801b0381111561143657604051635637123160e01b815260040160405180910390fd5b95945050505050565b611454335f356001600160e01b0319166117e2565b6114705760405162461bcd60e51b81526004016104939061269d565b610bb861ffff831611156114975760405163daf4c27560e01b815260040160405180910390fd5b62278d0062ffffff861611156114c0576040516341e2834f60e11b815260040160405180910390fd5b62278d0062ffffff851611156114e957604051632496e55f60e21b815260040160405180910390fd5b8161ffff168361ffff1611156115125760405163a800f19560e01b815260040160405180910390fd5b604051634104b9ed60e11b81526001600160a01b0387811660048301527f0000000000000000000000000000000000000000000000000000000000000000169063820973da90602401602060405180830381865afa158015611576573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061159a91906127f9565b506040518060c001604052806001151581526020018662ffffff1681526020018562ffffff1681526020018461ffff1681526020018361ffff168152602001826001600160601b031681525060055f886001600160a01b03166001600160a01b031681526020019081526020015f205f820151815f015f6101000a81548160ff0219169083151502179055506020820151815f0160016101000a81548162ffffff021916908362ffffff1602179055506040820151815f0160046101000a81548162ffffff021916908362ffffff1602179055506060820151815f0160076101000a81548161ffff021916908361ffff1602179055506080820151815f0160096101000a81548161ffff021916908361ffff16021790555060a0820151815f01600b6101000a8154816001600160601b0302191690836001600160601b03160217905550905050856001600160a01b03167f6ece44744f1fe676735f115da497fe130c7acf43fcd142fe92e20df15788797e868686868660405161175795949392919062ffffff958616815293909416602084015261ffff91821660408401521660608201526001600160601b0391909116608082015260a00190565b60405180910390a2505050505050565b61177c335f356001600160e01b0319166117e2565b6117985760405162461bcd60e51b81526004016104939061269d565b5f80546001600160a01b0319166001600160a01b0383169081178255604051909133917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09190a350565b6001545f906001600160a01b03168015801590611869575060405163b700961360e01b81526001600160a01b0382169063b70096139061182a908790309088906004016128d6565b602060405180830381865afa158015611845573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906118699190612903565b8061188057505f546001600160a01b038581169116145b949350505050565b60605f61189483611e49565b9392505050565b5f60405163a9059cbb60e01b81526001600160a01b038416600482015282602482015260205f6044835f895af191505080601f3d1160015f5114161516156118e55750823b153d17155b806119245760405162461bcd60e51b815260206004820152600f60248201526e1514905394d1915497d19052531151608a1b6044820152606401610493565b50505050565b5f8160405160200161193c919061293d565b60408051601f19818403018152919052805160209091012090505f611962600383611ea2565b90508061198257604051630ba52cdd60e11b815260040160405180910390fd5b50919050565b5f6040516323b872dd60e01b81526001600160a01b03851660048201526001600160a01b038416602482015282604482015260205f6064835f8a5af191505080601f3d1160015f5114161516156119e15750833b153d17155b8061072d5760405162461bcd60e51b81526020600482015260146024820152731514905394d1915497d19493d357d1905253115160621b6044820152606401610493565b60208101515f90336001600160a01b0382168114611a56576040516322583d4960e21b815260040160405180910390fd5b61188084611d33565b600654600160601b900460ff1615611a8a5760405163158b17e360e11b815260040160405180910390fd5b8351611aa9576040516312baa4e960e11b815260040160405180910390fd5b836060015161ffff168261ffff161080611ace5750836080015161ffff168261ffff16115b15611aec5760405163a800f19560e01b815260040160405180910390fd5b8360a001516001600160601b0316836001600160801b03161015611b235760405163030510d560e11b815260040160405180910390fd5b836040015162ffffff168162ffffff161015611924576040516394fb53cb60e01b815260040160405180910390fd5b60408051610100810182525f80825260208201819052918101829052606081018290526080810182905260a0810182905260c0810182905260e08101829052600680546bffffffffffffffffffffffff19811660016001600160601b03928316908101909216179091555f611bc889898961132a565b90505f429050604051806101000160405280846001600160601b031681526020018c6001600160a01b031681526020018b6001600160a01b031681526020018a6001600160801b03168152602001836001600160801b031681526020018264ffffffffff1681526020018862ffffff1681526020018762ffffff16815250935083604051602001611c59919061293d565b60408051601f19818403018152919052805160209091012094505f611c7f600387611ead565b905080611c9f57604051635028981b60e11b815260040160405180910390fd5b604080516001600160601b03861681526001600160801b038c8116602083015285168183015264ffffffffff8416606082015262ffffff8a81166080830152891660a082015290516001600160a01b038d811692908f169189917f2eb08ebdb4d68b4a37e3b424927f3363e1d799ca7e56e7b2c59cc6c1778d33f5919081900360c00190a450505050965096945050505050565b5f611d3d8261192a565b9050611d8e826020015183606001516001600160801b03167f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031661189b9092919063ffffffff16565b81602001516001600160a01b0316817f114ef421aef557f2e4086396789e7fb532b1133ff2982c9d948daa73d0691e3642604051611dce91815260200190565b60405180910390a3919050565b5f80846020015133806001600160a01b0316826001600160a01b031614611e15576040516322583d4960e21b815260040160405180910390fd5b611e20878787611eb8565b909890975095505050505050565b5f825f190484118302158202611e42575f80fd5b5091020490565b6060815f01805480602002602001604051908101604052809291908181526020018280548015611e9657602002820191905f5260205f20905b815481526020019060010190808311611e82575b50505050509050919050565b5f6118948383612013565b5f61189483836120fd565b5f80846020015133806001600160a01b0316826001600160a01b031614611ef2576040516322583d4960e21b815260040160405180910390fd5b6040878101516001600160a01b03165f9081526005602090815290829020825160c081018452905460ff811615158252610100810462ffffff90811693830193909352640100000000810490921692810192909252600160381b810461ffff908116606080850191909152600160481b83049091166080840152600160581b9091046001600160601b031660a0830152880151611f929082908989611a5f565b611f9b8861192a565b945087602001516001600160a01b0316857f114ef421aef557f2e4086396789e7fb532b1133ff2982c9d948daa73d0691e3642604051611fdd91815260200190565b60405180910390a3612003886020015189604001518a606001518a85602001518b611b52565b5080945050505050935093915050565b5f81815260018301602052604081205480156120ed575f612035600183612810565b85549091505f9061204890600190612810565b90508082146120a7575f865f018281548110612066576120666126c3565b905f5260205f200154905080875f018481548110612086576120866126c3565b5f918252602080832090910192909255918252600188019052604090208390555b85548690806120b8576120b86129e8565b600190038181905f5260205f20015f90559055856001015f8681526020019081526020015f205f905560019350505050610c4a565b5f915050610c4a565b5092915050565b5f81815260018301602052604081205461214257508154600181810184555f848152602080822090930184905584548482528286019093526040902091909155610c4a565b505f610c4a565b6001600160a01b038116811461215d575f80fd5b50565b803561216b81612149565b919050565b5f8083601f840112612180575f80fd5b50813567ffffffffffffffff811115612197575f80fd5b6020830191508360208260081b85010111156121b1575f80fd5b9250929050565b5f805f805f608086880312156121cc575f80fd5b85356121d781612149565b94506020860135935060408601356121ee81612149565b9250606086013567ffffffffffffffff811115612209575f80fd5b61221588828901612170565b969995985093965092949392505050565b5f805f805f6060868803121561223a575f80fd5b853567ffffffffffffffff80821115612251575f80fd5b61225d89838a01612170565b90975095506020880135915080821115612275575f80fd5b818801915088601f830112612288575f80fd5b813581811115612296575f80fd5b8960208285010111156122a7575f80fd5b60208301955080945050505060408601356122c181612149565b809150509295509295909350565b634e487b7160e01b5f52604160045260245ffd5b80356001600160601b038116811461216b575f80fd5b80356001600160801b038116811461216b575f80fd5b803564ffffffffff8116811461216b575f80fd5b803562ffffff8116811461216b575f80fd5b5f610100808385031215612347575f80fd5b6040519081019067ffffffffffffffff8211818310171561237657634e487b7160e01b5f52604160045260245ffd5b81604052809250612386846122e3565b815261239460208501612160565b60208201526123a560408501612160565b60408201526123b6606085016122f9565b60608201526123c7608085016122f9565b60808201526123d860a0850161230f565b60a08201526123e960c08501612323565b60c08201526123fa60e08501612323565b60e0820152505092915050565b5f6101008284031215612418575f80fd5b6118948383612335565b803561ffff8116811461216b575f80fd5b5f805f805f805f80610100898b03121561244b575f80fd5b883561245681612149565b975061246460208a016122f9565b965061247260408a01612422565b955061248060608a01612323565b94506080890135935060a089013560ff8116811461249c575f80fd5b979a969950949793969295929450505060c08201359160e0013590565b5f805f80608085870312156124cc575f80fd5b84356124d781612149565b93506124e5602086016122f9565b92506124f360408601612422565b915061250160608601612323565b905092959194509250565b5f6020828403121561251c575f80fd5b813561189481612149565b5f8060208385031215612538575f80fd5b823567ffffffffffffffff81111561254e575f80fd5b6112de85828601612170565b602080825282518282018190525f9190848201906040850190845b8181101561259157835183529284019291840191600101612575565b50909695505050505050565b5f805f61014084860312156125b0575f80fd5b6125ba8585612335565b92506125c96101008501612422565b91506125d86101208501612323565b90509250925092565b5f6101008284031215611982575f80fd5b5f805f60608486031215612604575f80fd5b833561260f81612149565b925061261d602085016122f9565b91506125d860408501612422565b5f805f805f8060c08789031215612640575f80fd5b863561264b81612149565b955061265960208801612323565b945061266760408801612323565b935061267560608801612422565b925061268360808801612422565b915061269160a088016122e3565b90509295509295509295565b6020808252600c908201526b15539055551213d49256915160a21b604082015260600190565b634e487b7160e01b5f52603260045260245ffd5b61010081016001600160601b036126ed846122e3565b16825260208301356126fe81612149565b6001600160a01b03908116602084015260408401359061271d82612149565b16604083015261272f606084016122f9565b6001600160801b03166060830152612749608084016122f9565b6001600160801b0316608083015261276360a0840161230f565b64ffffffffff1660a083015261277b60c08401612323565b62ffffff1660c083015261279160e08401612323565b62ffffff811660e08401526120f6565b5f602082840312156127b1575f80fd5b611894826122f9565b634e487b7160e01b5f52601160045260245ffd5b80820180821115610c4a57610c4a6127ba565b5f600182016127f2576127f26127ba565b5060010190565b5f60208284031215612809575f80fd5b5051919050565b81810381811115610c4a57610c4a6127ba565b5f60208284031215612833575f80fd5b61189482612323565b5f6020828403121561284c575f80fd5b6118948261230f565b64ffffffffff8181168382160190808211156120f6576120f66127ba565b6001600160a01b038881168252878116602083015286166040820152606081018590526080810184905260c060a0820181905281018290525f828460e08401375f60e0848401015260e0601f19601f850116830101905098975050505050505050565b6001600160a01b0393841681529190921660208201526001600160e01b0319909116604082015260600190565b5f60208284031215612913575f80fd5b81518015158114611894575f80fd5b61ffff8281168282160390808211156120f6576120f66127ba565b5f610100820190506001600160601b038351168252602083015160018060a01b03808216602085015280604086015116604085015250506001600160801b03606084015116606083015260808301516129a160808401826001600160801b03169052565b5060a08301516129ba60a084018264ffffffffff169052565b5060c08301516129d160c084018262ffffff169052565b5060e08301516120f660e084018262ffffff169052565b634e487b7160e01b5f52603160045260245ffdfea2646970667358221220be42bf19826951e506069d854684cfeb145629976172fd41247f2d74df8c5bab64736f6c63430008150033000000000000000000000000771263e3bc6acda5ae388a3f8a0c2dd7a17275fc0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000279cad277447965af3d24a78197aad1b02a2c58900000000000000000000000003d9a9ce13d16c7cfce564f41bd7e85e5cde8da6
Deployed Bytecode
0x608060405234801561000f575f80fd5b5060043610610153575f3560e01c8063a5672fd7116100bf578063b7d122b511610079578063b7d122b5146103b0578063bf7e214f146103d7578063e69a31c2146103ea578063eed4b3f814610415578063f2fde38b14610428578063f3b977841461043b575f80fd5b8063a5672fd714610272578063aa5a0ffd1461029a578063ac33a27314610346578063affed0e01461034e578063b187bd2614610379578063b22ed42a1461039d575f80fd5b80636bb3b476116101105780636bb3b476146101ff57806374732728146102125780637a9e5e4b146102255780638456cb59146102385780638da5cb5b146102405780639fff7e2a14610252575f80fd5b80630bf6cab7146101575780633f4ba83a1461016c578063412638dc146101745780634a2dc5e4146101875780634fb3ccc5146101ad578063581b4920146101ec575b5f80fd5b61016a6101653660046121b8565b610462565b005b61016a610734565b61016a610182366004612226565b61079c565b61019a610195366004612407565b610c0f565b6040519081526020015b60405180910390f35b6101d47f00000000000000000000000003d9a9ce13d16c7cfce564f41bd7e85e5cde8da681565b6040516001600160a01b0390911681526020016101a4565b61019a6101fa366004612433565b610c50565b61019a61020d3660046124b9565b610ece565b61016a61022036600461250c565b610fec565b61016a61023336600461250c565b611065565b61016a611149565b5f546101d4906001600160a01b031681565b610265610260366004612527565b6111b7565b6040516101a4919061255a565b61028561028036600461259d565b6112a0565b604080519283526020830191909152016101a4565b6102ff6102a836600461250c565b60056020525f908152604090205460ff81169062ffffff610100820481169164010000000081049091169061ffff600160381b8204811691600160481b8104909116906001600160601b03600160581b9091041686565b60408051961515875262ffffff9586166020880152939094169285019290925261ffff90811660608501521660808301526001600160601b031660a082015260c0016101a4565b6102656112ea565b600654610361906001600160601b031681565b6040516001600160601b0390911681526020016101a4565b60065461038d90600160601b900460ff1681565b60405190151581526020016101a4565b61019a6103ab3660046125e1565b6112fb565b61019a7f00000000000000000000000000000000000000000000000000000000000f424081565b6001546101d4906001600160a01b031681565b6103fd6103f83660046125f2565b61132a565b6040516001600160801b0390911681526020016101a4565b61016a61042336600461262b565b61143f565b61016a61043636600461250c565b611767565b6101d47f000000000000000000000000279cad277447965af3d24a78197aad1b02a2c58981565b610477335f356001600160e01b0319166117e2565b61049c5760405162461bcd60e51b81526004016104939061269d565b60405180910390fd5b7f000000000000000000000000279cad277447965af3d24a78197aad1b02a2c5896001600160a01b0316856001600160a01b0316036106a8575f6104e06003611888565b8051909150828114610505576040516312ed8d4160e21b815260040160405180910390fd5b5f805b828110156105d757838181518110610522576105226126c3565b602002602001015186868381811061053c5761053c6126c3565b9050610100020160405160200161055391906126d7565b6040516020818303038152906040528051906020012014610587576040516312ed8d4160e21b815260040160405180910390fd5b858582818110610599576105996126c3565b9050610100020160600160208101906105b291906127a1565b6105c5906001600160801b0316836127ce565b91506105d0816127e1565b9050610508565b506040516370a0823160e01b81523060048201525f9082906001600160a01b037f000000000000000000000000279cad277447965af3d24a78197aad1b02a2c58916906370a0823190602401602060405180830381865afa15801561063e573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061066291906127f9565b61066c9190612810565b90505f19880361067e5780975061069f565b8088111561069f5760405163fbeb452f60e01b815260040160405180910390fd5b50505050610719565b5f198403610719576040516370a0823160e01b81523060048201526001600160a01b038616906370a0823190602401602060405180830381865afa1580156106f2573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061071691906127f9565b93505b61072d6001600160a01b038616848661189b565b5050505050565b610749335f356001600160e01b0319166117e2565b6107655760405162461bcd60e51b81526004016104939061269d565b6006805460ff60601b191690556040517fa45f47fdea8a1efdd9029a5691c7f759c32b7c698632b563573e155625d16933905f90a1565b6107b1335f356001600160e01b0319166117e2565b6107cd5760405162461bcd60e51b81526004016104939061269d565b600654600160601b900460ff16156107f85760405163158b17e360e11b815260040160405180910390fd5b5f85855f81811061080b5761080b6126c3565b905061010002016040016020810190610824919061250c565b90505f8086815b81811015610ab357898982818110610845576108456126c3565b90506101000201604001602081019061085e919061250c565b6001600160a01b0316856001600160a01b03161461088f576040516331f59b5960e21b815260040160405180910390fd5b5f8a8a838181106108a2576108a26126c3565b9050610100020160c00160208101906108bb9190612823565b62ffffff168b8b848181106108d2576108d26126c3565b9050610100020160a00160208101906108eb919061283c565b6108f59190612855565b64ffffffffff1690508042101561091f576040516332924a4960e01b815260040160405180910390fd5b5f8b8b84818110610932576109326126c3565b9050610100020160e001602081019061094b9190612823565b61095a9062ffffff16836127ce565b90508042111561097d576040516378b2b00760e01b815260040160405180910390fd5b8b8b8481811061098f5761098f6126c3565b9050610100020160800160208101906109a891906127a1565b6109bb906001600160801b0316876127ce565b95508b8b848181106109cf576109cf6126c3565b9050610100020160600160208101906109e891906127a1565b6109fb906001600160801b0316866127ce565b94505f610a2f8d8d86818110610a1357610a136126c3565b90506101000201803603810190610a2a9190612407565b61192a565b90508c8c85818110610a4357610a436126c3565b905061010002016020016020810190610a5c919061250c565b6001600160a01b0316817fd94fc49a6578873ff851671d19cacb1809887f7a9128867ee4306dc3ffc93c2642604051610a9791815260200190565b60405180910390a350505080610aac906127e1565b905061082b565b50610ae86001600160a01b037f000000000000000000000000279cad277447965af3d24a78197aad1b02a2c58916868461189b565b8515610b74576040516333d5020b60e11b81526001600160a01b038616906367aa041690610b469033907f000000000000000000000000279cad277447965af3d24a78197aad1b02a2c58990899088908a908f908f90600401612873565b5f604051808303815f87803b158015610b5d575f80fd5b505af1158015610b6f573d5f803e3d5ffd5b505050505b5f5b81811015610c0357610bf3868b8b84818110610b9457610b946126c3565b905061010002016020016020810190610bad919061250c565b8c8c85818110610bbf57610bbf6126c3565b905061010002016080016020810190610bd891906127a1565b6001600160a01b0389169291906001600160801b0316611988565b610bfc816127e1565b9050610b76565b50505050505050505050565b5f610c25335f356001600160e01b0319166117e2565b610c415760405162461bcd60e51b81526004016104939061269d565b610c4a82611a25565b92915050565b5f610c66335f356001600160e01b0319166117e2565b610c825760405162461bcd60e51b81526004016104939061269d565b6001600160a01b0389165f90815260056020908152604091829020825160c081018452905460ff81161515825262ffffff610100820481169383019390935264010000000081049092169281019290925261ffff600160381b820481166060840152600160481b82041660808301526001600160601b03600160581b9091041660a0820152610d13818a8a8a611a5f565b60405163d505accf60e01b81523360048201523060248201526001600160801b038a1660448201526064810187905260ff8616608482015260a4810185905260c481018490527f000000000000000000000000279cad277447965af3d24a78197aad1b02a2c5896001600160a01b03169063d505accf9060e4015f604051808303815f87803b158015610da4575f80fd5b505af1925050508015610db5575060015b610e6f57604051636eb1769f60e11b81523360048201523060248201526001600160801b038a16907f000000000000000000000000279cad277447965af3d24a78197aad1b02a2c5896001600160a01b03169063dd62ed3e90604401602060405180830381865afa158015610e2c573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610e5091906127f9565b1015610e6f57604051634bfd8d1d60e01b815260040160405180910390fd5b610ead6001600160a01b037f000000000000000000000000279cad277447965af3d24a78197aad1b02a2c5891633306001600160801b038d16611988565b610ebf338b8b8b85602001518c611b52565b509a9950505050505050505050565b5f610ee4335f356001600160e01b0319166117e2565b610f005760405162461bcd60e51b81526004016104939061269d565b6001600160a01b0385165f90815260056020908152604091829020825160c081018452905460ff81161515825262ffffff610100820481169383019390935264010000000081049092169281019290925261ffff600160381b820481166060840152600160481b82041660808301526001600160601b03600160581b9091041660a0820152610f9181868686611a5f565b610fcf6001600160a01b037f000000000000000000000000279cad277447965af3d24a78197aad1b02a2c5891633306001600160801b038916611988565b610fe133878787856020015188611b52565b509695505050505050565b611001335f356001600160e01b0319166117e2565b61101d5760405162461bcd60e51b81526004016104939061269d565b6001600160a01b0381165f81815260056020526040808220805460ff19169055517ff1abf38a870f414456542524a2b679c0ece751691e36f4feee2ca7826c99e4629190a250565b5f546001600160a01b03163314806110f6575060015460405163b700961360e01b81526001600160a01b039091169063b7009613906110b790339030906001600160e01b03195f3516906004016128d6565b602060405180830381865afa1580156110d2573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906110f69190612903565b6110fe575f80fd5b600180546001600160a01b0319166001600160a01b03831690811790915560405133907fa3396fd7f6e0a21b50e5089d2da70d5ac0a3bbbd1f617a93f134b76389980198905f90a350565b61115e335f356001600160e01b0319166117e2565b61117a5760405162461bcd60e51b81526004016104939061269d565b6006805460ff60601b1916600160601b1790556040517f9e87fac88ff661f02d44f95383c817fece4bce600a3dab7a54406878b965e752905f90a1565b60606111ce335f356001600160e01b0319166117e2565b6111ea5760405162461bcd60e51b81526004016104939061269d565b818067ffffffffffffffff811115611204576112046122cf565b60405190808252806020026020018201604052801561122d578160200160208202803683370190505b5091505f5b818110156112985761126b85858381811061124f5761124f6126c3565b905061010002018036038101906112669190612407565b611d33565b83828151811061127d5761127d6126c3565b6020908102919091010152611291816127e1565b9050611232565b505092915050565b5f806112b7335f356001600160e01b0319166117e2565b6112d35760405162461bcd60e51b81526004016104939061269d565b6112de858585611ddb565b90969095509350505050565b60606112f66003611888565b905090565b5f8160405160200161130d91906126d7565b604051602081830303815290604052805190602001209050919050565b604051634104b9ed60e11b81526001600160a01b0384811660048301525f9182917f00000000000000000000000003d9a9ce13d16c7cfce564f41bd7e85e5cde8da6169063820973da90602401602060405180830381865afa158015611392573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906113b691906127f9565b90506113d56113c784612710612922565b829061ffff16612710611e2e565b90505f61140c6001600160801b038616837f00000000000000000000000000000000000000000000000000000000000f4240611e2e565b90506001600160801b0381111561143657604051635637123160e01b815260040160405180910390fd5b95945050505050565b611454335f356001600160e01b0319166117e2565b6114705760405162461bcd60e51b81526004016104939061269d565b610bb861ffff831611156114975760405163daf4c27560e01b815260040160405180910390fd5b62278d0062ffffff861611156114c0576040516341e2834f60e11b815260040160405180910390fd5b62278d0062ffffff851611156114e957604051632496e55f60e21b815260040160405180910390fd5b8161ffff168361ffff1611156115125760405163a800f19560e01b815260040160405180910390fd5b604051634104b9ed60e11b81526001600160a01b0387811660048301527f00000000000000000000000003d9a9ce13d16c7cfce564f41bd7e85e5cde8da6169063820973da90602401602060405180830381865afa158015611576573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061159a91906127f9565b506040518060c001604052806001151581526020018662ffffff1681526020018562ffffff1681526020018461ffff1681526020018361ffff168152602001826001600160601b031681525060055f886001600160a01b03166001600160a01b031681526020019081526020015f205f820151815f015f6101000a81548160ff0219169083151502179055506020820151815f0160016101000a81548162ffffff021916908362ffffff1602179055506040820151815f0160046101000a81548162ffffff021916908362ffffff1602179055506060820151815f0160076101000a81548161ffff021916908361ffff1602179055506080820151815f0160096101000a81548161ffff021916908361ffff16021790555060a0820151815f01600b6101000a8154816001600160601b0302191690836001600160601b03160217905550905050856001600160a01b03167f6ece44744f1fe676735f115da497fe130c7acf43fcd142fe92e20df15788797e868686868660405161175795949392919062ffffff958616815293909416602084015261ffff91821660408401521660608201526001600160601b0391909116608082015260a00190565b60405180910390a2505050505050565b61177c335f356001600160e01b0319166117e2565b6117985760405162461bcd60e51b81526004016104939061269d565b5f80546001600160a01b0319166001600160a01b0383169081178255604051909133917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09190a350565b6001545f906001600160a01b03168015801590611869575060405163b700961360e01b81526001600160a01b0382169063b70096139061182a908790309088906004016128d6565b602060405180830381865afa158015611845573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906118699190612903565b8061188057505f546001600160a01b038581169116145b949350505050565b60605f61189483611e49565b9392505050565b5f60405163a9059cbb60e01b81526001600160a01b038416600482015282602482015260205f6044835f895af191505080601f3d1160015f5114161516156118e55750823b153d17155b806119245760405162461bcd60e51b815260206004820152600f60248201526e1514905394d1915497d19052531151608a1b6044820152606401610493565b50505050565b5f8160405160200161193c919061293d565b60408051601f19818403018152919052805160209091012090505f611962600383611ea2565b90508061198257604051630ba52cdd60e11b815260040160405180910390fd5b50919050565b5f6040516323b872dd60e01b81526001600160a01b03851660048201526001600160a01b038416602482015282604482015260205f6064835f8a5af191505080601f3d1160015f5114161516156119e15750833b153d17155b8061072d5760405162461bcd60e51b81526020600482015260146024820152731514905394d1915497d19493d357d1905253115160621b6044820152606401610493565b60208101515f90336001600160a01b0382168114611a56576040516322583d4960e21b815260040160405180910390fd5b61188084611d33565b600654600160601b900460ff1615611a8a5760405163158b17e360e11b815260040160405180910390fd5b8351611aa9576040516312baa4e960e11b815260040160405180910390fd5b836060015161ffff168261ffff161080611ace5750836080015161ffff168261ffff16115b15611aec5760405163a800f19560e01b815260040160405180910390fd5b8360a001516001600160601b0316836001600160801b03161015611b235760405163030510d560e11b815260040160405180910390fd5b836040015162ffffff168162ffffff161015611924576040516394fb53cb60e01b815260040160405180910390fd5b60408051610100810182525f80825260208201819052918101829052606081018290526080810182905260a0810182905260c0810182905260e08101829052600680546bffffffffffffffffffffffff19811660016001600160601b03928316908101909216179091555f611bc889898961132a565b90505f429050604051806101000160405280846001600160601b031681526020018c6001600160a01b031681526020018b6001600160a01b031681526020018a6001600160801b03168152602001836001600160801b031681526020018264ffffffffff1681526020018862ffffff1681526020018762ffffff16815250935083604051602001611c59919061293d565b60408051601f19818403018152919052805160209091012094505f611c7f600387611ead565b905080611c9f57604051635028981b60e11b815260040160405180910390fd5b604080516001600160601b03861681526001600160801b038c8116602083015285168183015264ffffffffff8416606082015262ffffff8a81166080830152891660a082015290516001600160a01b038d811692908f169189917f2eb08ebdb4d68b4a37e3b424927f3363e1d799ca7e56e7b2c59cc6c1778d33f5919081900360c00190a450505050965096945050505050565b5f611d3d8261192a565b9050611d8e826020015183606001516001600160801b03167f000000000000000000000000279cad277447965af3d24a78197aad1b02a2c5896001600160a01b031661189b9092919063ffffffff16565b81602001516001600160a01b0316817f114ef421aef557f2e4086396789e7fb532b1133ff2982c9d948daa73d0691e3642604051611dce91815260200190565b60405180910390a3919050565b5f80846020015133806001600160a01b0316826001600160a01b031614611e15576040516322583d4960e21b815260040160405180910390fd5b611e20878787611eb8565b909890975095505050505050565b5f825f190484118302158202611e42575f80fd5b5091020490565b6060815f01805480602002602001604051908101604052809291908181526020018280548015611e9657602002820191905f5260205f20905b815481526020019060010190808311611e82575b50505050509050919050565b5f6118948383612013565b5f61189483836120fd565b5f80846020015133806001600160a01b0316826001600160a01b031614611ef2576040516322583d4960e21b815260040160405180910390fd5b6040878101516001600160a01b03165f9081526005602090815290829020825160c081018452905460ff811615158252610100810462ffffff90811693830193909352640100000000810490921692810192909252600160381b810461ffff908116606080850191909152600160481b83049091166080840152600160581b9091046001600160601b031660a0830152880151611f929082908989611a5f565b611f9b8861192a565b945087602001516001600160a01b0316857f114ef421aef557f2e4086396789e7fb532b1133ff2982c9d948daa73d0691e3642604051611fdd91815260200190565b60405180910390a3612003886020015189604001518a606001518a85602001518b611b52565b5080945050505050935093915050565b5f81815260018301602052604081205480156120ed575f612035600183612810565b85549091505f9061204890600190612810565b90508082146120a7575f865f018281548110612066576120666126c3565b905f5260205f200154905080875f018481548110612086576120866126c3565b5f918252602080832090910192909255918252600188019052604090208390555b85548690806120b8576120b86129e8565b600190038181905f5260205f20015f90559055856001015f8681526020019081526020015f205f905560019350505050610c4a565b5f915050610c4a565b5092915050565b5f81815260018301602052604081205461214257508154600181810184555f848152602080822090930184905584548482528286019093526040902091909155610c4a565b505f610c4a565b6001600160a01b038116811461215d575f80fd5b50565b803561216b81612149565b919050565b5f8083601f840112612180575f80fd5b50813567ffffffffffffffff811115612197575f80fd5b6020830191508360208260081b85010111156121b1575f80fd5b9250929050565b5f805f805f608086880312156121cc575f80fd5b85356121d781612149565b94506020860135935060408601356121ee81612149565b9250606086013567ffffffffffffffff811115612209575f80fd5b61221588828901612170565b969995985093965092949392505050565b5f805f805f6060868803121561223a575f80fd5b853567ffffffffffffffff80821115612251575f80fd5b61225d89838a01612170565b90975095506020880135915080821115612275575f80fd5b818801915088601f830112612288575f80fd5b813581811115612296575f80fd5b8960208285010111156122a7575f80fd5b60208301955080945050505060408601356122c181612149565b809150509295509295909350565b634e487b7160e01b5f52604160045260245ffd5b80356001600160601b038116811461216b575f80fd5b80356001600160801b038116811461216b575f80fd5b803564ffffffffff8116811461216b575f80fd5b803562ffffff8116811461216b575f80fd5b5f610100808385031215612347575f80fd5b6040519081019067ffffffffffffffff8211818310171561237657634e487b7160e01b5f52604160045260245ffd5b81604052809250612386846122e3565b815261239460208501612160565b60208201526123a560408501612160565b60408201526123b6606085016122f9565b60608201526123c7608085016122f9565b60808201526123d860a0850161230f565b60a08201526123e960c08501612323565b60c08201526123fa60e08501612323565b60e0820152505092915050565b5f6101008284031215612418575f80fd5b6118948383612335565b803561ffff8116811461216b575f80fd5b5f805f805f805f80610100898b03121561244b575f80fd5b883561245681612149565b975061246460208a016122f9565b965061247260408a01612422565b955061248060608a01612323565b94506080890135935060a089013560ff8116811461249c575f80fd5b979a969950949793969295929450505060c08201359160e0013590565b5f805f80608085870312156124cc575f80fd5b84356124d781612149565b93506124e5602086016122f9565b92506124f360408601612422565b915061250160608601612323565b905092959194509250565b5f6020828403121561251c575f80fd5b813561189481612149565b5f8060208385031215612538575f80fd5b823567ffffffffffffffff81111561254e575f80fd5b6112de85828601612170565b602080825282518282018190525f9190848201906040850190845b8181101561259157835183529284019291840191600101612575565b50909695505050505050565b5f805f61014084860312156125b0575f80fd5b6125ba8585612335565b92506125c96101008501612422565b91506125d86101208501612323565b90509250925092565b5f6101008284031215611982575f80fd5b5f805f60608486031215612604575f80fd5b833561260f81612149565b925061261d602085016122f9565b91506125d860408501612422565b5f805f805f8060c08789031215612640575f80fd5b863561264b81612149565b955061265960208801612323565b945061266760408801612323565b935061267560608801612422565b925061268360808801612422565b915061269160a088016122e3565b90509295509295509295565b6020808252600c908201526b15539055551213d49256915160a21b604082015260600190565b634e487b7160e01b5f52603260045260245ffd5b61010081016001600160601b036126ed846122e3565b16825260208301356126fe81612149565b6001600160a01b03908116602084015260408401359061271d82612149565b16604083015261272f606084016122f9565b6001600160801b03166060830152612749608084016122f9565b6001600160801b0316608083015261276360a0840161230f565b64ffffffffff1660a083015261277b60c08401612323565b62ffffff1660c083015261279160e08401612323565b62ffffff811660e08401526120f6565b5f602082840312156127b1575f80fd5b611894826122f9565b634e487b7160e01b5f52601160045260245ffd5b80820180821115610c4a57610c4a6127ba565b5f600182016127f2576127f26127ba565b5060010190565b5f60208284031215612809575f80fd5b5051919050565b81810381811115610c4a57610c4a6127ba565b5f60208284031215612833575f80fd5b61189482612323565b5f6020828403121561284c575f80fd5b6118948261230f565b64ffffffffff8181168382160190808211156120f6576120f66127ba565b6001600160a01b038881168252878116602083015286166040820152606081018590526080810184905260c060a0820181905281018290525f828460e08401375f60e0848401015260e0601f19601f850116830101905098975050505050505050565b6001600160a01b0393841681529190921660208201526001600160e01b0319909116604082015260600190565b5f60208284031215612913575f80fd5b81518015158114611894575f80fd5b61ffff8281168282160390808211156120f6576120f66127ba565b5f610100820190506001600160601b038351168252602083015160018060a01b03808216602085015280604086015116604085015250506001600160801b03606084015116606083015260808301516129a160808401826001600160801b03169052565b5060a08301516129ba60a084018264ffffffffff169052565b5060c08301516129d160c084018262ffffff169052565b5060e08301516120f660e084018262ffffff169052565b634e487b7160e01b5f52603160045260245ffdfea2646970667358221220be42bf19826951e506069d854684cfeb145629976172fd41247f2d74df8c5bab64736f6c63430008150033
Constructor Arguments (ABI-Encoded and is the last bytes of the Contract Creation Code above)
000000000000000000000000771263e3bc6acda5ae388a3f8a0c2dd7a17275fc0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000279cad277447965af3d24a78197aad1b02a2c58900000000000000000000000003d9a9ce13d16c7cfce564f41bd7e85e5cde8da6
-----Decoded View---------------
Arg [0] : _owner (address): 0x771263e3Bc6aCDa5aE388A3F8A0c2dd7A17275FC
Arg [1] : _auth (address): 0x0000000000000000000000000000000000000000
Arg [2] : _boringVault (address): 0x279CAD277447965AF3d24a78197aad1B02a2c589
Arg [3] : _accountant (address): 0x03D9a9cE13D16C7cFCE564f41bd7E85E5cde8Da6
-----Encoded View---------------
4 Constructor Arguments found :
Arg [0] : 000000000000000000000000771263e3bc6acda5ae388a3f8a0c2dd7a17275fc
Arg [1] : 0000000000000000000000000000000000000000000000000000000000000000
Arg [2] : 000000000000000000000000279cad277447965af3d24a78197aad1b02a2c589
Arg [3] : 00000000000000000000000003d9a9ce13d16c7cfce564f41bd7e85e5cde8da6
Deployed Bytecode Sourcemap
924:27456:24:-:0;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;8990:1374;;;;;;:::i;:::-;;:::i;:::-;;10876:99;;;:::i;18073:1694::-;;;;;;:::i;:::-;;:::i;16657:230::-;;;;;;:::i;:::-;;:::i;:::-;;;4976:25:29;;;4964:2;4949:18;16657:230:24;;;;;;;;7821:55;;;;;;;;-1:-1:-1;;;;;5212:32:29;;;5194:51;;5182:2;5167:18;7821:55:24;5012:239:29;15473:1032:24;;;;;;:::i;:::-;;:::i;14252:628::-;;;;;;:::i;:::-;;:::i;13086:179::-;;;;;;:::i;:::-;;:::i;1523:434:16:-;;;;;;:::i;:::-;;:::i;10573:94:24:-;;;:::i;562:20:16:-;;;;;-1:-1:-1;;;;;562:20:16;;;13384:417:24;;;;;;:::i;:::-;;:::i;:::-;;;;;;;:::i;17319:354::-;;;;;;:::i;:::-;;:::i;:::-;;;;9200:25:29;;;9256:2;9241:18;;9234:34;;;;9173:18;17319:354:24;9026:248:29;4603:55:24;;;;;;:::i;:::-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;-1:-1:-1;;;4603:55:24;;;;;-1:-1:-1;;;4603:55:24;;;;;;-1:-1:-1;;;;;;;;4603:55:24;;;;;;;;;;9672:14:29;;9665:22;9647:41;;9707:8;9751:15;;;9746:2;9731:18;;9724:43;9803:15;;;;9783:18;;;9776:43;;;;9838:6;9880:15;;;9875:2;9860:18;;9853:43;9933:15;9927:3;9912:19;;9905:44;-1:-1:-1;;;;;9986:39:29;9980:3;9965:19;;9958:68;9634:3;9619:19;4603:55:24;9376:656:29;20102:114:24;;;:::i;5222:23::-;;;;;-1:-1:-1;;;;;5222:23:24;;;;;;-1:-1:-1;;;;;10199:39:29;;;10181:58;;10169:2;10154:18;5222:23:24;10037:208:29;5322:20:24;;;;;-1:-1:-1;;;5322:20:24;;;;;;;;;10415:14:29;;10408:22;10390:41;;10378:2;10363:18;5322:20:24;10250:187:29;20363:152:24;;;;;;:::i;:::-;;:::i;7937:34::-;;;;;589:26:16;;;;;-1:-1:-1;;;;;589:26:16;;;20596:522:24;;;;;;:::i;:::-;;:::i;:::-;;;-1:-1:-1;;;;;11750:47:29;;;11732:66;;11720:2;11705:18;20596:522:24;11586:218:29;11591:1336:24;;;;;;:::i;:::-;;:::i;1963:164:16:-;;;;;;:::i;:::-;;:::i;7683:40:24:-;;;;;8990:1374;902:33:16;915:10;927:7;;-1:-1:-1;;;;;;927:7:16;902:12;:33::i;:::-;894:58;;;;-1:-1:-1;;;894:58:16;;;;;;;:::i;:::-;;;;;;;;;9178:11:24::1;-1:-1:-1::0;;;;;9152:38:24::1;9160:5;-1:-1:-1::0;;;;;9152:38:24::1;::::0;9148:1170:::1;;9206:27;9236:26;:17;:24;:26::i;:::-;9303:17:::0;;9206:56;;-1:-1:-1;9338:41:24;;::::1;9334:84;;9388:30;;-1:-1:-1::0;;;9388:30:24::1;;;;;;;;;;;9334:84;9633:29;::::0;9676:255:::1;9700:16;9696:1;:20;9676:255;;;9789:10;9800:1;9789:13;;;;;;;;:::i;:::-;;;;;;;9766:14;;9781:1;9766:17;;;;;;;:::i;:::-;;;;;;9755:29;;;;;;;;:::i;:::-;;;;;;;;;;;;;9745:40;;;;;;:57;9741:100;;9811:30;;-1:-1:-1::0;;;9811:30:24::1;;;;;;;;;;;9741:100;9884:14;;9899:1;9884:17;;;;;;;:::i;:::-;;;;;;:32;;;;;;;;;;:::i;:::-;9859:57;::::0;-1:-1:-1;;;;;9859:57:24::1;::::0;::::1;:::i;:::-;::::0;-1:-1:-1;9718:3:24::1;::::0;::::1;:::i;:::-;;;9676:255;;;-1:-1:-1::0;9965:36:24::1;::::0;-1:-1:-1;;;9965:36:24;;9995:4:::1;9965:36;::::0;::::1;5194:51:29::0;9944:18:24::1;::::0;10004:21;;-1:-1:-1;;;;;9965:11:24::1;:21;::::0;::::1;::::0;5167:18:29;;9965:36:24::1;;;;;;;;;;;;;;;;;::::0;::::1;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;:::i;:::-;:60;;;;:::i;:::-;9944:81;;-1:-1:-1::0;;10043:6:24::1;:27:::0;10039:165:::1;;10081:10;10072:19;;10039:165;;;10123:10;10114:6;:19;10110:94;;;10142:62;;-1:-1:-1::0;;;10142:62:24::1;;;;;;;;;;;10110:94;9192:1023;;;;9148:1170;;;-1:-1:-1::0;;10239:6:24::1;:27:::0;10235:72:::1;;10277:30;::::0;-1:-1:-1;;;10277:30:24;;10301:4:::1;10277:30;::::0;::::1;5194:51:29::0;-1:-1:-1;;;;;10277:15:24;::::1;::::0;::::1;::::0;5167:18:29;;10277:30:24::1;;;;;;;;;;;;;;;;;::::0;::::1;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;:::i;:::-;10268:39;;10235:72;10327:30;-1:-1:-1::0;;;;;10327:18:24;::::1;10346:2:::0;10350:6;10327:18:::1;:30::i;:::-;8990:1374:::0;;;;;:::o;10876:99::-;902:33:16;915:10;927:7;;-1:-1:-1;;;;;;927:7:16;902:12;:33::i;:::-;894:58;;;;-1:-1:-1;;;894:58:16;;;;;;;:::i;:::-;10927:8:24::1;:16:::0;;-1:-1:-1;;;;10927:16:24::1;::::0;;10958:10:::1;::::0;::::1;::::0;10938:5:::1;::::0;10958:10:::1;10876:99::o:0;18073:1694::-;902:33:16;915:10;927:7;;-1:-1:-1;;;;;;927:7:16;902:12;:33::i;:::-;894:58;;;;-1:-1:-1;;;894:58:16;;;;;;;:::i;:::-;18239:8:24::1;::::0;-1:-1:-1;;;18239:8:24;::::1;;;18235:49;;;18256:28;;-1:-1:-1::0;;;18256:28:24::1;;;;;;;;;;;18235:49;18295:16;18320:8;;18329:1;18320:11;;;;;;;:::i;:::-;;;;;;:20;;;;;;;;;;:::i;:::-;18295:46:::0;-1:-1:-1;18351:22:24::1;::::0;18437:8;18351:22;18462:771:::1;18486:14;18482:1;:18;18462:771;;;18548:8;;18557:1;18548:11;;;;;;;:::i;:::-;;;;;;:20;;;;;;;;;;:::i;:::-;-1:-1:-1::0;;;;;18525:43:24::1;18533:10;-1:-1:-1::0;;;;;18525:43:24::1;;18521:96;;18577:40;;-1:-1:-1::0;;;18577:40:24::1;;;;;;;;;;;18521:96;18631:16;18677:8;;18686:1;18677:11;;;;;;;:::i;:::-;;;;;;:29;;;;;;;;;;:::i;:::-;18650:56;;:8;;18659:1;18650:11;;;;;;;:::i;:::-;;;;;;:24;;;;;;;;;;:::i;:::-;:56;;;;:::i;:::-;18631:75;;;;18742:8;18724:15;:26;18720:71;;;18759:32;;-1:-1:-1::0;;;18759:32:24::1;;;;;;;;;;;18720:71;18805:16;18835:8;;18844:1;18835:11;;;;;;;:::i;:::-;;;;;;:29;;;;;;;;;;:::i;:::-;18824:40;::::0;::::1;;:8:::0;:40:::1;:::i;:::-;18805:59;;18900:8;18882:15;:26;18878:75;;;18917:36;;-1:-1:-1::0;;;18917:36:24::1;;;;;;;;;;;18878:75;18985:8;;18994:1;18985:11;;;;;;;:::i;:::-;;;;;;:26;;;;;;;;;;:::i;:::-;18967:44;::::0;-1:-1:-1;;;;;18967:44:24::1;::::0;::::1;:::i;:::-;;;19040:8;;19049:1;19040:11;;;;;;;:::i;:::-;;;;;;:26;;;;;;;;;;:::i;:::-;19025:41;::::0;-1:-1:-1;;;;;19025:41:24::1;::::0;::::1;:::i;:::-;;;19080:17;19100:36;19124:8;;19133:1;19124:11;;;;;;;:::i;:::-;;;;;;19100:36;;;;;;;;;;:::i;:::-;:23;:36::i;:::-;19080:56;;19188:8;;19197:1;19188:11;;;;;;;:::i;:::-;;;;;;:16;;;;;;;;;;:::i;:::-;-1:-1:-1::0;;;;;19155:67:24::1;19177:9;19155:67;19206:15;19155:67;;;;4976:25:29::0;;4964:2;4949:18;;4830:177;19155:67:24::1;;;;;;;;18507:726;;;18502:3;;;;:::i;:::-;;;18462:771;;;-1:-1:-1::0;19281:45:24::1;-1:-1:-1::0;;;;;19281:11:24::1;:24;19306:6:::0;19314:11;19281:24:::1;:45::i;:::-;19395:20:::0;;19391:209:::1;;19431:158;::::0;-1:-1:-1;;;19431:158:24;;-1:-1:-1;;;;;19431:33:24;::::1;::::0;::::1;::::0;:158:::1;::::0;19482:10:::1;::::0;19502:11:::1;::::0;19524:10;;19537:11;;19550:14;;19566:9;;;;19431:158:::1;;;:::i;:::-;;;;;;;;;;;;;;;;;;::::0;::::1;;;;;;;;;;;;::::0;::::1;;;;;;;;;19391:209;19615:9;19610:151;19634:14;19630:1;:18;19610:151;;;19669:81;19697:6;19705:8;;19714:1;19705:11;;;;;;;:::i;:::-;;;;;;:16;;;;;;;;;;:::i;:::-;19723:8;;19732:1;19723:11;;;;;;;:::i;:::-;;;;;;:26;;;;;;;;;;:::i;:::-;-1:-1:-1::0;;;;;19669:27:24;::::1;::::0;:81;;-1:-1:-1;;;;;19669:81:24::1;:27;:81::i;:::-;19650:3;::::0;::::1;:::i;:::-;;;19610:151;;;;18225:1542;;;;18073:1694:::0;;;;;:::o;16657:230::-;16791:17;902:33:16;915:10;927:7;;-1:-1:-1;;;;;;927:7:16;902:12;:33::i;:::-;894:58;;;;-1:-1:-1;;;894:58:16;;;;;;;:::i;:::-;16836:44:24::1;16872:7;16836:35;:44::i;:::-;16824:56:::0;16657:230;-1:-1:-1;;16657:230:24:o;15473:1032::-;15764:17;902:33:16;915:10;927:7;;-1:-1:-1;;;;;;927:7:16;902:12;:33::i;:::-;894:58;;;;-1:-1:-1;;;894:58:16;;;;;;;:::i;:::-;-1:-1:-1;;;;;15830:24:24;::::1;15793:34;15830:24:::0;;;:14:::1;:24;::::0;;;;;;;;15793:61;;::::1;::::0;::::1;::::0;;;;::::1;::::0;::::1;;;::::0;;::::1;;::::0;::::1;::::0;::::1;::::0;;::::1;::::0;;;;;;::::1;::::0;;::::1;::::0;;;;;;;::::1;-1:-1:-1::0;;;15793:61:24;::::1;::::0;::::1;::::0;;;;-1:-1:-1;;;15793:61:24;::::1;;::::0;;;;-1:-1:-1;;;;;;;;15793:61:24;;::::1;;::::0;;;;15865:77:::1;15793:61:::0;15898:14;15914:8;15924:17;15865::::1;:77::i;:::-;15957:86;::::0;-1:-1:-1;;;15957:86:24;;15976:10:::1;15957:86;::::0;::::1;17190:34:29::0;15996:4:24::1;17240:18:29::0;;;17233:43;-1:-1:-1;;;;;17312:47:29;;17292:18;;;17285:75;17376:18;;;17369:34;;;17452:4;17440:17;;17419:19;;;17412:46;17474:19;;;17467:35;;;17518:19;;;17511:35;;;15957:11:24::1;-1:-1:-1::0;;;;;15957:18:24::1;::::0;::::1;::::0;17124:19:29;;15957:86:24::1;;;;;;;;;;;;;;;;;::::0;::::1;;;;;;;;;;;;;;;;15953:295;;16079:48;::::0;-1:-1:-1;;;16079:48:24;;16101:10:::1;16079:48;::::0;::::1;17769:34:29::0;16121:4:24::1;17819:18:29::0;;;17812:43;-1:-1:-1;;;;;16079:65:24;::::1;::::0;:11:::1;-1:-1:-1::0;;;;;16079:21:24::1;::::0;::::1;::::0;17704:18:29;;16079:48:24::1;;;;;;;;;;;;;;;;;::::0;::::1;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;:::i;:::-;:65;16075:163;;;16171:52;;-1:-1:-1::0;;;16171:52:24::1;;;;;;;;;;;16075:163;16258:71;-1:-1:-1::0;;;;;16258:11:24::1;:28;16287:10;16307:4;-1:-1:-1::0;;;;;16258:71:24;::::1;:28;:71::i;:::-;16355:143;16390:10;16402:8;16412:14;16428:8;16438:13;:31;;;16471:17;16355:21;:143::i;:::-;-1:-1:-1::0;16340:158:24;15473:1032;-1:-1:-1;;;;;;;;;;15473:1032:24:o;14252:628::-;14440:17;902:33:16;915:10;927:7;;-1:-1:-1;;;;;;927:7:16;902:12;:33::i;:::-;894:58;;;;-1:-1:-1;;;894:58:16;;;;;;;:::i;:::-;-1:-1:-1;;;;;14510:24:24;::::1;14473:34;14510:24:::0;;;:14:::1;:24;::::0;;;;;;;;14473:61;;::::1;::::0;::::1;::::0;;;;::::1;::::0;::::1;;;::::0;;::::1;;::::0;::::1;::::0;::::1;::::0;;::::1;::::0;;;;;;::::1;::::0;;::::1;::::0;;;;;;;::::1;-1:-1:-1::0;;;14473:61:24;::::1;::::0;::::1;::::0;;;;-1:-1:-1;;;14473:61:24;::::1;;::::0;;;;-1:-1:-1;;;;;;;;14473:61:24;;::::1;;::::0;;;;14545:77:::1;14473:61:::0;14578:14;14594:8;14604:17;14545::::1;:77::i;:::-;14633:71;-1:-1:-1::0;;;;;14633:11:24::1;:28;14662:10;14682:4;-1:-1:-1::0;;;;;14633:71:24;::::1;:28;:71::i;:::-;14730:143;14765:10;14777:8;14787:14;14803:8;14813:13;:31;;;14846:17;14730:21;:143::i;:::-;-1:-1:-1::0;14715:158:24;14252:628;-1:-1:-1;;;;;;14252:628:24:o;13086:179::-;902:33:16;915:10;927:7;;-1:-1:-1;;;;;;927:7:16;902:12;:33::i;:::-;894:58;;;;-1:-1:-1;;;894:58:16;;;;;;;:::i;:::-;-1:-1:-1;;;;;13166:24:24;::::1;13208:5;13166:24:::0;;;:14:::1;:24;::::0;;;;;:47;;-1:-1:-1;;13166:47:24::1;::::0;;13228:30;::::1;::::0;13208:5;13228:30:::1;13086:179:::0;:::o;1523:434:16:-;1794:5;;-1:-1:-1;;;;;1794:5:16;1780:10;:19;;:76;;-1:-1:-1;1803:9:16;;:53;;-1:-1:-1;;;1803:53:16;;-1:-1:-1;;;;;1803:9:16;;;;:17;;:53;;1821:10;;1841:4;;-1:-1:-1;;;;;;1803:9:16;1848:7;;;1803:53;;;:::i;:::-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;:::i;:::-;1772:85;;;;;;1868:9;:24;;-1:-1:-1;;;;;;1868:24:16;-1:-1:-1;;;;;1868:24:16;;;;;;;;1908:42;;1925:10;;1908:42;;-1:-1:-1;;1908:42:16;1523:434;:::o;10573:94:24:-;902:33:16;915:10;927:7;;-1:-1:-1;;;;;;927:7:16;902:12;:33::i;:::-;894:58;;;;-1:-1:-1;;;894:58:16;;;;;;;:::i;:::-;10622:8:24::1;:15:::0;;-1:-1:-1;;;;10622:15:24::1;-1:-1:-1::0;;;10622:15:24::1;::::0;;10652:8:::1;::::0;::::1;::::0;10622:15;;10652:8:::1;10573:94::o:0;13384:417::-;13505:35;902:33:16;915:10;927:7;;-1:-1:-1;;;;;;927:7:16;902:12;:33::i;:::-;894:58;;;;-1:-1:-1;;;894:58:16;;;;;;;:::i;:::-;13581:8:24;;13627:29:::1;::::0;::::1;;;;;;:::i;:::-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;::::0;-1:-1:-1;13627:29:24::1;;13606:50;;13671:9;13666:129;13690:14;13686:1;:18;13666:129;;;13749:35;13772:8;;13781:1;13772:11;;;;;;;:::i;:::-;;;;;;13749:35;;;;;;;;;;:::i;:::-;:22;:35::i;:::-;13725:18;13744:1;13725:21;;;;;;;;:::i;:::-;;::::0;;::::1;::::0;;;;;:59;13706:3:::1;::::0;::::1;:::i;:::-;;;13666:129;;;;13546:255;13384:417:::0;;;;:::o;17319:354::-;17500:20;17522;902:33:16;915:10;927:7;;-1:-1:-1;;;;;;927:7:16;902:12;:33::i;:::-;894:58;;;;-1:-1:-1;;;894:58:16;;;;;;;:::i;:::-;17589:77:24::1;17626:10;17638:8;17648:17;17589:36;:77::i;:::-;17558:108:::0;;;;-1:-1:-1;17319:354:24;-1:-1:-1;;;;17319:354:24:o;20102:114::-;20148:16;20183:26;:17;:24;:26::i;:::-;20176:33;;20102:114;:::o;20363:152::-;20442:17;20499:7;20488:19;;;;;;;;:::i;:::-;;;;;;;;;;;;;20478:30;;;;;;20471:37;;20363:152;;;:::o;20596:522::-;20783:46;;-1:-1:-1;;;20783:46:24;;-1:-1:-1;;;;;5212:32:29;;;20783:46:24;;;5194:51:29;20726:25:24;;;;20783:10;:29;;;;5167:18:29;;20783:46:24;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;:::i;:::-;20767:62;-1:-1:-1;20847:37:24;20864:14;20870:8;20864:3;:14;:::i;:::-;20847:5;;:37;;20880:3;20847:16;:37::i;:::-;20839:45;-1:-1:-1;20894:22:24;20919:52;-1:-1:-1;;;;;20919:23:24;;20839:45;20961:9;20919:34;:52::i;:::-;20894:77;-1:-1:-1;;;;;;20985:34:24;;20981:77;;;21028:30;;-1:-1:-1;;;21028:30:24;;;;;;;;;;;20981:77;21096:14;20596:522;-1:-1:-1;;;;;20596:522:24:o;11591:1336::-;902:33:16;915:10;927:7;;-1:-1:-1;;;;;;927:7:16;902:12;:33::i;:::-;894:58;;;;-1:-1:-1;;;894:58:16;;;;;;;:::i;:::-;3513:5:24::1;11876:26;::::0;::::1;;11872:73;;;11911:34;;-1:-1:-1::0;;;11911:34:24::1;;;;;;;;;;;11872:73;3676:7;11959:47;::::0;::::1;;11955:134;;;12029:49;;-1:-1:-1::0;;;12029:49:24::1;;;;;;;;;;;11955:134;3876:7;12102:62;::::0;::::1;;12098:157;;;12187:57;;-1:-1:-1::0;;;12187:57:24::1;;;;;;;;;;;12098:157;12282:11;12268:25;;:11;:25;;;12264:71;;;12302:33;;-1:-1:-1::0;;;12302:33:24::1;;;;;;;;;;;12264:71;12391:46;::::0;-1:-1:-1;;;12391:46:24;;-1:-1:-1;;;;;5212:32:29;;;12391:46:24::1;::::0;::::1;5194:51:29::0;12391:10:24::1;:29;::::0;::::1;::::0;5167:18:29;;12391:46:24::1;;;;;;;;;;;;;;;;;::::0;::::1;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;:::i;:::-;;12475:291;;;;;;;;12519:4;12475:291;;;;;;12556:17;12475:291;;;;;;12613:24;12475:291;;;;;;12664:11;12475:291;;;;;;12702:11;12475:291;;;;;;12742:13;-1:-1:-1::0;;;;;12475:291:24::1;;;::::0;12448:14:::1;:24;12463:8;-1:-1:-1::0;;;;;12448:24:24::1;-1:-1:-1::0;;;;;12448:24:24::1;;;;;;;;;;;;:318;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;-1:-1:-1::0;;;;;12448:318:24::1;;;;;-1:-1:-1::0;;;;;12448:318:24::1;;;;;;;;;12816:8;-1:-1:-1::0;;;;;12782:138:24::1;;12826:17;12845:24;12871:11;12884;12897:13;12782:138;;;;;;;;;19210:8:29::0;19245:15;;;19227:34;;19297:15;;;;19292:2;19277:18;;19270:43;19332:6;19374:15;;;19369:2;19354:18;;19347:43;19426:15;19421:2;19406:18;;19399:43;-1:-1:-1;;;;;19479:39:29;;;;19473:3;19458:19;;19451:68;19187:3;19172:19;;18951:574;12782:138:24::1;;;;;;;;11591:1336:::0;;;;;;:::o;1963:164:16:-;902:33;915:10;927:7;;-1:-1:-1;;;;;;927:7:16;902:12;:33::i;:::-;894:58;;;;-1:-1:-1;;;894:58:16;;;;;;;:::i;:::-;2046:5:::1;:16:::0;;-1:-1:-1;;;;;;2046:16:16::1;-1:-1:-1::0;;;;;2046:16:16;::::1;::::0;;::::1;::::0;;2078:42:::1;::::0;2046:16;;2099:10:::1;::::0;2078:42:::1;::::0;2046:5;2078:42:::1;1963:164:::0;:::o;977:540::-;1097:9;;1064:4;;-1:-1:-1;;;;;1097:9:16;1415:27;;;;;:77;;-1:-1:-1;1446:46:16;;-1:-1:-1;;;1446:46:16;;-1:-1:-1;;;;;1446:12:16;;;;;:46;;1459:4;;1473;;1480:11;;1446:46;;;:::i;:::-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;:::i;:::-;1414:96;;;-1:-1:-1;1505:5:16;;-1:-1:-1;;;;;1497:13:16;;;1505:5;;1497:13;1414:96;1407:103;977:540;-1:-1:-1;;;;977:540:16:o;8819:273:15:-;8882:16;8910:22;8935:19;8943:3;8935:7;:19::i;:::-;8910:44;8819:273;-1:-1:-1;;;8819:273:15:o;2832:1464:21:-;2944:12;3114:4;3108:11;-1:-1:-1;;;3237:17:21;3230:93;-1:-1:-1;;;;;3374:2:21;3370:51;3366:1;3347:17;3343:25;3336:86;3508:6;3503:2;3484:17;3480:26;3473:42;3855:2;3852:1;3848:2;3829:17;3826:1;3819:5;3812;3807:51;3796:62;;;4125:7;4118:2;4100:16;4097:24;4093:1;4089;4083:8;4080:15;4076:46;4069:54;4065:68;4062:172;;;-1:-1:-1;4180:18:21;;4173:26;4201:16;4170:48;4163:56;4062:172;4262:7;4254:35;;;;-1:-1:-1;;;4254:35:21;;19732:2:29;4254:35:21;;;19714:21:29;19771:2;19751:18;;;19744:30;-1:-1:-1;;;19790:18:29;;;19783:45;19845:18;;4254:35:21;19530:339:29;4254:35:21;2934:1362;2832:1464;;;:::o;28029:349:24:-;28120:17;28220:7;28209:19;;;;;;;;:::i;:::-;;;;-1:-1:-1;;28209:19:24;;;;;;;;;28199:30;;28209:19;28199:30;;;;;-1:-1:-1;28239:19:24;28261:35;:17;28199:30;28261:24;:35::i;:::-;28239:57;;28311:14;28306:65;;28334:37;;-1:-1:-1;;;28334:37:24;;;;;;;;;;;28306:65;28139:239;28029:349;;;:::o;1187:1639:21:-;1325:12;1495:4;1489:11;-1:-1:-1;;;1618:17:21;1611:93;-1:-1:-1;;;;;1755:4:21;1751:53;1747:1;1728:17;1724:25;1717:88;-1:-1:-1;;;;;1897:2:21;1893:51;1888:2;1869:17;1865:26;1858:87;2031:6;2026:2;2007:17;2003:26;1996:42;2380:2;2377:1;2372:3;2353:17;2350:1;2343:5;2336;2331:52;2320:63;;;2650:7;2643:2;2625:16;2622:24;2618:1;2614;2608:8;2605:15;2601:46;2594:54;2590:68;2587:172;;;-1:-1:-1;2705:18:21;;2698:26;2726:16;2695:48;2688:56;2587:172;2787:7;2779:40;;;;-1:-1:-1;;;2779:40:21;;21169:2:29;2779:40:21;;;21151:21:29;21208:2;21188:18;;;21181:30;-1:-1:-1;;;21227:18:29;;;21220:50;21287:18;;2779:40:21;20967:344:29;22507:260:24;22641:12;;;;22684:17;;22655:10;-1:-1:-1;;;;;4166:24:24;;;;4162:66;;4199:29;;-1:-1:-1;;;4199:29:24;;;;;;;;;;;4162:66;22729:31:::1;22752:7;22729:22;:31::i;21550:731::-:0;21754:8;;-1:-1:-1;;;21754:8:24;;;;21750:49;;;21771:28;;-1:-1:-1;;;21771:28:24;;;;;;;;;;;21750:49;21815:28;;21810:91;;21852:49;;-1:-1:-1;;;21852:49:24;;;;;;;;;;;21810:91;21926:13;:25;;;21915:36;;:8;:36;;;:76;;;;21966:13;:25;;;21955:36;;:8;:36;;;21915:76;21911:147;;;22014:33;;-1:-1:-1;;;22014:33:24;;;;;;;;;;;21911:147;22088:13;:27;;;-1:-1:-1;;;;;22071:44:24;:14;-1:-1:-1;;;;;22071:44:24;;22067:93;;;22124:36;;-1:-1:-1;;;22124:36:24;;;;;;;;;;;22067:93;22194:13;:38;;;22174:58;;:17;:58;;;22170:104;;;22241:33;;-1:-1:-1;;;22241:33:24;;;;;;;;;;;26079:1586;-1:-1:-1;;;;;;;;26315:17:24;-1:-1:-1;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;26598:5:24;:7;;-1:-1:-1;;26598:7:24;;;-1:-1:-1;;;;;26598:7:24;;;;;;;;;;;;;-1:-1:-1;26654:52:24;26671:8;26681:14;26697:8;26654:16;:52::i;:::-;26626:80;;26717:14;26741:15;26717:40;;26850:342;;;;;;;;26887:12;-1:-1:-1;;;;;26850:342:24;;;;;26919:4;-1:-1:-1;;;;;26850:342:24;;;;;26947:8;-1:-1:-1;;;;;26850:342:24;;;;;26985:14;-1:-1:-1;;;;;26850:342:24;;;;;27029:17;-1:-1:-1;;;;;26850:342:24;;;;;27074:7;26850:342;;;;;;27114:17;26850:342;;;;;;27164:17;26850:342;;;;;26844:348;;27236:3;27225:15;;;;;;;;:::i;:::-;;;;-1:-1:-1;;27225:15:24;;;;;;;;;27215:26;;27225:15;27215:26;;;;;-1:-1:-1;27252:15:24;27270:32;:17;27215:26;27270:21;:32::i;:::-;27252:50;;27318:10;27313:64;;27337:40;;-1:-1:-1;;;27337:40:24;;;;;;;;;;;27313:64;27393:265;;;-1:-1:-1;;;;;21613:39:29;;21595:58;;-1:-1:-1;;;;;21742:15:29;;;21737:2;21722:18;;21715:43;21794:15;;21774:18;;;21767:43;21858:12;21846:25;;21841:2;21826:18;;21819:53;21891:8;21936:15;;;21930:3;21915:19;;21908:44;21989:15;;21983:3;21968:19;;21961:44;27393:265:24;;-1:-1:-1;;;;;27393:265:24;;;;;;;;27431:9;;27393:265;;;;;;21582:3:29;27393:265:24;;;26362:1303;;;;26079:1586;;;;;;;;;:::o;22919:323::-;23009:17;23050:32;23074:7;23050:23;:32::i;:::-;23038:44;;23092:62;23117:7;:12;;;23131:7;:22;;;-1:-1:-1;;;;;23092:62:24;:11;-1:-1:-1;;;;;23092:24:24;;;:62;;;;;:::i;:::-;23205:7;:12;;;-1:-1:-1;;;;;23169:66:24;23194:9;23169:66;23219:15;23169:66;;;;4976:25:29;;4964:2;4949:18;;4830:177;23169:66:24;;;;;;;;22919:323;;;:::o;23748:417::-;24005:20;24027;23959:10;:15;;;23976:10;4181:9;-1:-1:-1;;;;;4166:24:24;:11;-1:-1:-1;;;;;4166:24:24;;4162:66;;4199:29;;-1:-1:-1;;;4199:29:24;;;;;;;;;;;4162:66;24094:64:::1;24118:10;24130:8;24140:17;24094:23;:64::i;:::-;24063:95:::0;;;;-1:-1:-1;23748:417:24;-1:-1:-1;;;;;;23748:417:24:o;1564:526:19:-;1680:9;1928:1;-1:-1:-1;;1911:19:19;1908:1;1905:26;1902:1;1898:34;1891:42;1878:11;1874:60;1864:116;;1964:1;1961;1954:12;1864:116;-1:-1:-1;2051:9:19;;2047:27;;1564:526::o;6227:109:15:-;6283:16;6318:3;:11;;6311:18;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;6227:109;;;:::o;6867:129::-;6940:4;6963:26;6971:3;6983:5;6963:7;:26::i;6576:123::-;6646:4;6669:23;6674:3;6686:5;6669:4;:23::i;24597:889:24:-;24811:20;24833;24765:10;:15;;;24782:10;4181:9;-1:-1:-1;;;;;4166:24:24;:11;-1:-1:-1;;;;;4166:24:24;;4162:66;;4199:29;;-1:-1:-1;;;4199:29:24;;;;;;;;;;;4162:66;24921:19:::1;::::0;;::::1;::::0;-1:-1:-1;;;;;24906:35:24::1;24869:34;24906:35:::0;;;:14:::1;:35;::::0;;;;;;;24869:72;;::::1;::::0;::::1;::::0;;;;::::1;::::0;::::1;;;::::0;;::::1;::::0;::::1;;::::0;;::::1;::::0;;::::1;::::0;;;;;;::::1;::::0;;::::1;::::0;;;;;;;-1:-1:-1;;;24869:72:24;::::1;;::::0;;::::1;::::0;;;;;;;;-1:-1:-1;;;24869:72:24;::::1;::::0;;::::1;::::0;;;;-1:-1:-1;;;24869:72:24;;::::1;-1:-1:-1::0;;;;;24869:72:24::1;::::0;;;;24985:25;::::1;::::0;24952:88:::1;::::0;24869:72;;25012:8;25022:17;24952::::1;:88::i;:::-;25066:35;25090:10;25066:23;:35::i;:::-;25051:50;;25156:10;:15;;;-1:-1:-1::0;;;;;25117:72:24::1;25142:12;25117:72;25173:15;25117:72;;;;4976:25:29::0;;4964:2;4949:18;;4830:177;25117:72:24::1;;;;;;;;25249:230;25284:10;:15;;;25313:10;:19;;;25346:10;:25;;;25385:8;25407:13;:31;;;25452:17;25249:21;:230::i;:::-;25231:248;;;;;24859:627;24597:889:::0;;;;;;;;:::o;2910:1368:15:-;2976:4;3105:21;;;:14;;;:21;;;;;;3141:13;;3137:1135;;3508:18;3529:12;3540:1;3529:8;:12;:::i;:::-;3575:18;;3508:33;;-1:-1:-1;3555:17:15;;3575:22;;3596:1;;3575:22;:::i;:::-;3555:42;;3630:9;3616:10;:23;3612:378;;3659:17;3679:3;:11;;3691:9;3679:22;;;;;;;;:::i;:::-;;;;;;;;;3659:42;;3826:9;3800:3;:11;;3812:10;3800:23;;;;;;;;:::i;:::-;;;;;;;;;;;;:35;;;;3939:25;;;:14;;;:25;;;;;:36;;;3612:378;4068:17;;:3;;:17;;;;;:::i;:::-;;;;;;;;;;;;;;;;;;4171:3;:14;;:21;4186:5;4171:21;;;;;;;;;;;4164:28;;;4214:4;4207:11;;;;;;;3137:1135;4256:5;4249:12;;;;;3137:1135;2982:1296;2910:1368;;;;:::o;2336:406::-;2399:4;5006:21;;;:14;;;:21;;;;;;2415:321;;-1:-1:-1;2457:23:15;;;;;;;;:11;:23;;;;;;;;;;;;;2639:18;;2615:21;;;:14;;;:21;;;;;;:42;;;;2671:11;;2415:321;-1:-1:-1;2720:5:15;2713:12;;14:138:29;-1:-1:-1;;;;;96:31:29;;86:42;;76:70;;142:1;139;132:12;76:70;14:138;:::o;157:141::-;225:20;;254:38;225:20;254:38;:::i;:::-;157:141;;;:::o;303:391::-;390:8;400:6;454:3;447:4;439:6;435:17;431:27;421:55;;472:1;469;462:12;421:55;-1:-1:-1;495:20:29;;538:18;527:30;;524:50;;;570:1;567;560:12;524:50;607:4;599:6;595:17;583:29;;667:3;660:4;650:6;647:1;643:14;635:6;631:27;627:38;624:47;621:67;;;684:1;681;674:12;621:67;303:391;;;;;:::o;699:869::-;861:6;869;877;885;893;946:3;934:9;925:7;921:23;917:33;914:53;;;963:1;960;953:12;914:53;1002:9;989:23;1021:38;1053:5;1021:38;:::i;:::-;1078:5;-1:-1:-1;1130:2:29;1115:18;;1102:32;;-1:-1:-1;1186:2:29;1171:18;;1158:32;1199:40;1158:32;1199:40;:::i;:::-;1258:7;-1:-1:-1;1316:2:29;1301:18;;1288:32;1343:18;1332:30;;1329:50;;;1375:1;1372;1365:12;1329:50;1414:94;1500:7;1491:6;1480:9;1476:22;1414:94;:::i;:::-;699:869;;;;-1:-1:-1;699:869:29;;-1:-1:-1;1527:8:29;;1388:120;699:869;-1:-1:-1;;;699:869:29:o;1573:1107::-;1723:6;1731;1739;1747;1755;1808:2;1796:9;1787:7;1783:23;1779:32;1776:52;;;1824:1;1821;1814:12;1776:52;1864:9;1851:23;1893:18;1934:2;1926:6;1923:14;1920:34;;;1950:1;1947;1940:12;1920:34;1989:94;2075:7;2066:6;2055:9;2051:22;1989:94;:::i;:::-;2102:8;;-1:-1:-1;1963:120:29;-1:-1:-1;2190:2:29;2175:18;;2162:32;;-1:-1:-1;2206:16:29;;;2203:36;;;2235:1;2232;2225:12;2203:36;2273:8;2262:9;2258:24;2248:34;;2320:7;2313:4;2309:2;2305:13;2301:27;2291:55;;2342:1;2339;2332:12;2291:55;2382:2;2369:16;2408:2;2400:6;2397:14;2394:34;;;2424:1;2421;2414:12;2394:34;2469:7;2464:2;2455:6;2451:2;2447:15;2443:24;2440:37;2437:57;;;2490:1;2487;2480:12;2437:57;2521:2;2517;2513:11;2503:21;;2543:6;2533:16;;;;;2599:2;2588:9;2584:18;2571:32;2612:38;2644:5;2612:38;:::i;:::-;2669:5;2659:15;;;1573:1107;;;;;;;;:::o;2685:127::-;2746:10;2741:3;2737:20;2734:1;2727:31;2777:4;2774:1;2767:15;2801:4;2798:1;2791:15;2817:179;2884:20;;-1:-1:-1;;;;;2933:38:29;;2923:49;;2913:77;;2986:1;2983;2976:12;3001:188;3069:20;;-1:-1:-1;;;;;3118:46:29;;3108:57;;3098:85;;3179:1;3176;3169:12;3194:165;3261:20;;3321:12;3310:24;;3300:35;;3290:63;;3349:1;3346;3339:12;3364:161;3431:20;;3491:8;3480:20;;3470:31;;3460:59;;3515:1;3512;3505:12;3530:1046;3592:5;3622:6;3665:2;3653:9;3648:3;3644:19;3640:28;3637:48;;;3681:1;3678;3671:12;3637:48;3714:2;3708:9;3744:15;;;;3789:18;3774:34;;3810:22;;;3771:62;3768:185;;;3875:10;3870:3;3866:20;3863:1;3856:31;3910:4;3907:1;3900:15;3938:4;3935:1;3928:15;3768:185;3973:10;3969:2;3962:22;4002:6;3993:15;;4032:28;4050:9;4032:28;:::i;:::-;4024:6;4017:44;4094:38;4128:2;4117:9;4113:18;4094:38;:::i;:::-;4089:2;4081:6;4077:15;4070:63;4166:38;4200:2;4189:9;4185:18;4166:38;:::i;:::-;4161:2;4153:6;4149:15;4142:63;4238:38;4272:2;4261:9;4257:18;4238:38;:::i;:::-;4233:2;4225:6;4221:15;4214:63;4311:39;4345:3;4334:9;4330:19;4311:39;:::i;:::-;4305:3;4297:6;4293:16;4286:65;4385:38;4418:3;4407:9;4403:19;4385:38;:::i;:::-;4379:3;4371:6;4367:16;4360:64;4458:38;4491:3;4480:9;4476:19;4458:38;:::i;:::-;4452:3;4444:6;4440:16;4433:64;4531:38;4564:3;4553:9;4549:19;4531:38;:::i;:::-;4525:3;4517:6;4513:16;4506:64;;;3530:1046;;;;:::o;4581:244::-;4673:6;4726:3;4714:9;4705:7;4701:23;4697:33;4694:53;;;4743:1;4740;4733:12;4694:53;4766;4811:7;4800:9;4766:53;:::i;5256:159::-;5323:20;;5383:6;5372:18;;5362:29;;5352:57;;5405:1;5402;5395:12;5420:846;5538:6;5546;5554;5562;5570;5578;5586;5594;5647:3;5635:9;5626:7;5622:23;5618:33;5615:53;;;5664:1;5661;5654:12;5615:53;5703:9;5690:23;5722:38;5754:5;5722:38;:::i;:::-;5779:5;-1:-1:-1;5803:38:29;5837:2;5822:18;;5803:38;:::i;:::-;5793:48;;5860:37;5893:2;5882:9;5878:18;5860:37;:::i;:::-;5850:47;;5916:37;5949:2;5938:9;5934:18;5916:37;:::i;:::-;5906:47;;6000:3;5989:9;5985:19;5972:33;5962:43;;6057:3;6046:9;6042:19;6029:33;6106:4;6097:7;6093:18;6084:7;6081:31;6071:59;;6126:1;6123;6116:12;6071:59;5420:846;;;;-1:-1:-1;5420:846:29;;;;;;6149:7;;-1:-1:-1;;;6203:3:29;6188:19;;6175:33;;6255:3;6240:19;6227:33;;5420:846::o;6271:473::-;6355:6;6363;6371;6379;6432:3;6420:9;6411:7;6407:23;6403:33;6400:53;;;6449:1;6446;6439:12;6400:53;6488:9;6475:23;6507:38;6539:5;6507:38;:::i;:::-;6564:5;-1:-1:-1;6588:38:29;6622:2;6607:18;;6588:38;:::i;:::-;6578:48;;6645:37;6678:2;6667:9;6663:18;6645:37;:::i;:::-;6635:47;;6701:37;6734:2;6723:9;6719:18;6701:37;:::i;:::-;6691:47;;6271:473;;;;;;;:::o;6749:254::-;6808:6;6861:2;6849:9;6840:7;6836:23;6832:32;6829:52;;;6877:1;6874;6867:12;6829:52;6916:9;6903:23;6935:38;6967:5;6935:38;:::i;7493:496::-;7614:6;7622;7675:2;7663:9;7654:7;7650:23;7646:32;7643:52;;;7691:1;7688;7681:12;7643:52;7731:9;7718:23;7764:18;7756:6;7753:30;7750:50;;;7796:1;7793;7786:12;7750:50;7835:94;7921:7;7912:6;7901:9;7897:22;7835:94;:::i;7994:632::-;8165:2;8217:21;;;8287:13;;8190:18;;;8309:22;;;8136:4;;8165:2;8388:15;;;;8362:2;8347:18;;;8136:4;8431:169;8445:6;8442:1;8439:13;8431:169;;;8506:13;;8494:26;;8575:15;;;;8540:12;;;;8467:1;8460:9;8431:169;;;-1:-1:-1;8617:3:29;;7994:632;-1:-1:-1;;;;;;7994:632:29:o;8631:390::-;8739:6;8747;8755;8808:3;8796:9;8787:7;8783:23;8779:33;8776:53;;;8825:1;8822;8815:12;8776:53;8848;8893:7;8882:9;8848:53;:::i;:::-;8838:63;;8920:38;8953:3;8942:9;8938:19;8920:38;:::i;:::-;8910:48;;8977:38;9010:3;8999:9;8995:19;8977:38;:::i;:::-;8967:48;;8631:390;;;;;:::o;10442:202::-;10536:6;10589:3;10577:9;10568:7;10564:23;10560:33;10557:53;;;10606:1;10603;10596:12;11057:400;11133:6;11141;11149;11202:2;11190:9;11181:7;11177:23;11173:32;11170:52;;;11218:1;11215;11208:12;11170:52;11257:9;11244:23;11276:38;11308:5;11276:38;:::i;:::-;11333:5;-1:-1:-1;11357:38:29;11391:2;11376:18;;11357:38;:::i;:::-;11347:48;;11414:37;11447:2;11436:9;11432:18;11414:37;:::i;11809:617::-;11908:6;11916;11924;11932;11940;11948;12001:3;11989:9;11980:7;11976:23;11972:33;11969:53;;;12018:1;12015;12008:12;11969:53;12057:9;12044:23;12076:38;12108:5;12076:38;:::i;:::-;12133:5;-1:-1:-1;12157:37:29;12190:2;12175:18;;12157:37;:::i;:::-;12147:47;;12213:37;12246:2;12235:9;12231:18;12213:37;:::i;:::-;12203:47;;12269:37;12302:2;12291:9;12287:18;12269:37;:::i;:::-;12259:47;;12325:38;12358:3;12347:9;12343:19;12325:38;:::i;:::-;12315:48;;12382:38;12415:3;12404:9;12400:19;12382:38;:::i;:::-;12372:48;;11809:617;;;;;;;;:::o;12667:336::-;12869:2;12851:21;;;12908:2;12888:18;;;12881:30;-1:-1:-1;;;12942:2:29;12927:18;;12920:42;12994:2;12979:18;;12667:336::o;13008:127::-;13069:10;13064:3;13060:20;13057:1;13050:31;13100:4;13097:1;13090:15;13124:4;13121:1;13114:15;13241:1303;13443:3;13428:19;;-1:-1:-1;;;;;13478:25:29;13496:6;13478:25;:::i;:::-;13474:58;13463:9;13456:77;13580:4;13572:6;13568:17;13555:31;13595:38;13627:5;13595:38;:::i;:::-;-1:-1:-1;;;;;13709:14:29;;;13702:4;13687:20;;13680:44;13773:4;13761:17;;13748:31;;13788:40;13748:31;13788:40;:::i;:::-;13866:16;13859:4;13844:20;;13837:46;13912:37;13943:4;13931:17;;13912:37;:::i;:::-;-1:-1:-1;;;;;11528:46:29;14006:4;13991:20;;11516:59;14043:37;14074:4;14062:17;;14043:37;:::i;:::-;-1:-1:-1;;;;;11528:46:29;14139:4;14124:20;;11516:59;14176:36;14206:4;14194:17;;14176:36;:::i;:::-;13216:12;13205:24;14270:4;14255:20;;13193:37;14307:36;14337:4;14325:17;;14307:36;:::i;:::-;9355:8;9344:20;14401:4;14386:20;;9332:33;14438:36;14468:4;14456:17;;14438:36;:::i;:::-;9355:8;9344:20;;14532:4;14517:20;;9332:33;14483:55;9279:92;14549:186;14608:6;14661:2;14649:9;14640:7;14636:23;14632:32;14629:52;;;14677:1;14674;14667:12;14629:52;14700:29;14719:9;14700:29;:::i;14740:127::-;14801:10;14796:3;14792:20;14789:1;14782:31;14832:4;14829:1;14822:15;14856:4;14853:1;14846:15;14872:125;14937:9;;;14958:10;;;14955:36;;;14971:18;;:::i;15002:135::-;15041:3;15062:17;;;15059:43;;15082:18;;:::i;:::-;-1:-1:-1;15129:1:29;15118:13;;15002:135::o;15142:184::-;15212:6;15265:2;15253:9;15244:7;15240:23;15236:32;15233:52;;;15281:1;15278;15271:12;15233:52;-1:-1:-1;15304:16:29;;15142:184;-1:-1:-1;15142:184:29:o;15331:128::-;15398:9;;;15419:11;;;15416:37;;;15433:18;;:::i;15464:184::-;15522:6;15575:2;15563:9;15554:7;15550:23;15546:32;15543:52;;;15591:1;15588;15581:12;15543:52;15614:28;15632:9;15614:28;:::i;15653:184::-;15711:6;15764:2;15752:9;15743:7;15739:23;15735:32;15732:52;;;15780:1;15777;15770:12;15732:52;15803:28;15821:9;15803:28;:::i;15842:174::-;15909:12;15941:10;;;15953;;;15937:27;;15976:11;;;15973:37;;;15990:18;;:::i;16021:815::-;-1:-1:-1;;;;;16356:15:29;;;16338:34;;16408:15;;;16403:2;16388:18;;16381:43;16460:15;;16455:2;16440:18;;16433:43;16507:2;16492:18;;16485:34;;;16550:3;16535:19;;16528:35;;;16600:3;16318;16579:19;;16572:32;;;16620:19;;16613:35;;;16281:4;16641:6;16691;16685:3;16670:19;;16657:49;16756:1;16750:3;16741:6;16730:9;16726:22;16722:32;16715:43;16826:3;16819:2;16815:7;16810:2;16802:6;16798:15;16794:29;16783:9;16779:45;16775:55;16767:63;;16021:815;;;;;;;;;;:::o;17866:400::-;-1:-1:-1;;;;;18122:15:29;;;18104:34;;18174:15;;;;18169:2;18154:18;;18147:43;-1:-1:-1;;;;;;18226:33:29;;;18221:2;18206:18;;18199:61;18054:2;18039:18;;17866:400::o;18271:277::-;18338:6;18391:2;18379:9;18370:7;18366:23;18362:32;18359:52;;;18407:1;18404;18397:12;18359:52;18439:9;18433:16;18492:5;18485:13;18478:21;18471:5;18468:32;18458:60;;18514:1;18511;18504:12;18775:171;18843:6;18882:10;;;18870;;;18866:27;;18905:12;;;18902:38;;;18920:18;;:::i;19874:1088::-;20032:4;20074:3;20063:9;20059:19;20051:27;;-1:-1:-1;;;;;20115:6:29;20109:13;20105:46;20094:9;20087:65;20199:4;20191:6;20187:17;20181:24;20241:1;20237;20232:3;20228:11;20224:19;20299:2;20285:12;20281:21;20274:4;20263:9;20259:20;20252:51;20371:2;20363:4;20355:6;20351:17;20345:24;20341:33;20334:4;20323:9;20319:20;20312:63;;;-1:-1:-1;;;;;20435:4:29;20427:6;20423:17;20417:24;20413:65;20406:4;20395:9;20391:20;20384:95;20528:4;20520:6;20516:17;20510:24;20543:56;20593:4;20582:9;20578:20;20562:14;-1:-1:-1;;;;;11528:46:29;11516:59;;11462:119;20543:56;;20648:4;20640:6;20636:17;20630:24;20663:55;20712:4;20701:9;20697:20;20681:14;13216:12;13205:24;13193:37;;13140:96;20663:55;;20767:4;20759:6;20755:17;20749:24;20782:55;20831:4;20820:9;20816:20;20800:14;9355:8;9344:20;9332:33;;9279:92;20782:55;;20886:4;20878:6;20874:17;20868:24;20901:55;20950:4;20939:9;20935:20;20919:14;9355:8;9344:20;9332:33;;9279:92;22016:127;22077:10;22072:3;22068:20;22065:1;22058:31;22108:4;22105:1;22098:15;22132:4;22129:1;22122:15
Swarm Source
ipfs://be42bf19826951e506069d854684cfeb145629976172fd41247f2d74df8c5bab
Loading...
Loading
Loading...
Loading
Multichain Portfolio | 34 Chains
| Chain | Token | Portfolio % | Price | Amount | Value |
|---|
Loading...
Loading
Loading...
Loading
Loading...
Loading
[ 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.