More Info
Private Name Tags
ContractCreator
Latest 25 from a total of 4,786 transactions
Transaction Hash |
Method
|
Block
|
From
|
To
|
|||||
---|---|---|---|---|---|---|---|---|---|
Mint | 4079358 | 4 hrs ago | IN | 0 BERA | 0.00004912 | ||||
Mint | 4064080 | 13 hrs ago | IN | 0 BERA | 0.00000011 | ||||
Mint | 4063611 | 13 hrs ago | IN | 0 BERA | 0.00000001 | ||||
Mint | 4062119 | 14 hrs ago | IN | 0 BERA | 0.00000011 | ||||
Mint | 4061234 | 14 hrs ago | IN | 0 BERA | 0.00000001 | ||||
Mint | 4061218 | 14 hrs ago | IN | 0 BERA | 0.00000002 | ||||
Mint | 4061204 | 14 hrs ago | IN | 0 BERA | 0.00000002 | ||||
Mint | 4060683 | 15 hrs ago | IN | 0 BERA | 0.00000028 | ||||
Mint | 4056779 | 17 hrs ago | IN | 0 BERA | 0 | ||||
Mint | 4051576 | 20 hrs ago | IN | 0 BERA | 0.00000015 | ||||
Mint | 4051279 | 20 hrs ago | IN | 0 BERA | 0.00000004 | ||||
Mint | 4051241 | 20 hrs ago | IN | 0 BERA | 0.00000009 | ||||
Mint | 4050612 | 20 hrs ago | IN | 0 BERA | 0 | ||||
Mint | 4050572 | 20 hrs ago | IN | 0 BERA | 0 | ||||
Mint | 4046198 | 23 hrs ago | IN | 0 BERA | 0.00000189 | ||||
Mint | 4036411 | 28 hrs ago | IN | 0 BERA | 0 | ||||
Mint | 4032504 | 30 hrs ago | IN | 0 BERA | 0.00004913 | ||||
Mint | 4030920 | 31 hrs ago | IN | 0 BERA | 0.00001473 | ||||
Mint | 4021576 | 36 hrs ago | IN | 0 BERA | 0 | ||||
Mint | 4014764 | 40 hrs ago | IN | 0 BERA | 0 | ||||
Mint | 4012485 | 41 hrs ago | IN | 0 BERA | 0 | ||||
Mint | 4009419 | 43 hrs ago | IN | 0 BERA | 0.00005152 | ||||
Mint | 4007498 | 44 hrs ago | IN | 0 BERA | 0 | ||||
Mint | 3992789 | 2 days ago | IN | 0 BERA | 0.00000104 | ||||
Mint | 3991183 | 2 days ago | IN | 0 BERA | 0.00004912 |
Latest 6 internal transactions
Parent Transaction Hash | Block | From | To | |||
---|---|---|---|---|---|---|
2042153 | 46 days ago | Contract Creation | 0 BERA | |||
2042144 | 46 days ago | Contract Creation | 0 BERA | |||
2042135 | 46 days ago | Contract Creation | 0 BERA | |||
2042121 | 46 days ago | Contract Creation | 0 BERA | |||
2042100 | 46 days ago | Contract Creation | 0 BERA | |||
2041392 | 46 days ago | Contract Creation | 0 BERA |
Loading...
Loading
Contract Source Code Verified (Exact Match)
Contract Name:
Henlocker
Compiler Version
v0.8.25+commit.b61c2a91
Optimization Enabled:
Yes with 200 runs
Other Settings:
cancun EvmVersion
Contract Source Code (Solidity Standard Json-Input format)
// SPDX-License-Identifier: UNLICENSED pragma solidity ^0.8.20; import {SafeERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol"; import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol"; import {ReentrancyGuard} from "@openzeppelin/contracts/utils/ReentrancyGuard.sol"; import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol"; import {Pausable} from "@openzeppelin/contracts/utils/Pausable.sol"; import {FixedPointMathLib} from "@solady/utils/FixedPointMathLib.sol"; import {IOracleChainsight} from "./interfaces/IOracleChainsight.sol"; import {henlocked} from "./multi/henlocked.sol"; import {henlockedToken} from "./single/henlockedERC20.sol"; interface IReservoir { function matchMint(uint256 amount) external returns (uint256); function started() external view returns (bool); function endTime() external view returns (uint256); function incrementMatched(uint256 amount) external; function canMatch() external view returns (bool); } // Henlocker is the core contract for the HENLOCKED system. It manages the minting // and redemption of HENLOCKED tokens based on predefined strike prices. Based on the HodlMoney price lock contract. contract Henlocker is ReentrancyGuard, Ownable, Pausable { using SafeERC20 for IERC20; using FixedPointMathLib for uint256; /*############################################################### EVENTS ###############################################################*/ event SetTreasury(address treasury); event SetFee(uint256 fee); event DeployERC20(uint64 indexed strike, address token); event Mint(address indexed user, uint256 indexed strike, uint256 amount); event MintFromReservoir(address indexed reservoir, uint64 indexed strike, uint256 amount); event Redeem(address indexed user, uint64 indexed strike, uint256 amount); event RoundOpened(uint48 indexed epochId, uint64 indexed strike, uint256 depositLimit); event RoundClosed(uint48 indexed epochId, uint64 indexed strike); event DepositLimitUpdated(uint48 indexed epochId, uint64 indexed strike, uint256 newDepositLimit); event OracleSenderUpdated(address indexed newSender); event OracleKeyUpdated(bytes32 indexed newKey); event OracleUpdated(address indexed newOracle); event DepositsPaused(uint48 indexed epochId, uint64 indexed strike); event DepositsUnpaused(uint48 indexed epochId, uint64 indexed strike); /*############################################################### ERRORS ###############################################################*/ error ZeroAddress(); error ZeroOracleAddress(); error ZeroTreasuryAddress(); error ZeroOracleSenderAddress(); error MaxFeeExceeded(); error StrikeTooLow(); error InvalidDepositLimit(); error RoundAlreadyExistsOrNotClosed(); error RoundNotOpened(); error RoundIsClosed(); error DepositsArePaused(); error ZeroMint(); error AmountExceedsDepositLimit(); error ZeroRedeemAmount(); error CannotRedeemAtThisTime(); error InsufficientHenlockedBalance(); error AlreadyDeployed(); error DepositsAlreadyPaused(); error DepositsNotPaused(); error NewLimitTooLow(); error StaleOracleData(); error InvalidEpochStrike(); /*############################################################### STRUCTS ###############################################################*/ struct EpochInfo { uint64 strike; bool closed; bool depositsPaused; // Flag to pause deposits uint256 timestamp; uint256 depositLimit; // Max deposits allowed for this epoch uint256 totalDeposits; // Tracks deposits for this specific epoch address reservoir; // Address of the Reservoir contract for this epoch } /*############################################################### STORAGE ###############################################################*/ uint256 public constant FEE_BASIS = 100_00; uint256 public constant MAX_FEE = 10_00; // 10% uint48 public nextId = 1; uint256 public fee = 0; IERC20 public immutable asset; // Direct reference to HENLO token IOracleChainsight public oracle; henlocked public immutable hodlMulti; address public treasury; address public oracleSender; bytes32 private oracleKey; // Keep track of deployed ERC20 HENLOCKED tokens mapping(uint64 strike => IERC20 token) public deployments; mapping(uint48 epochId => EpochInfo) public infos; mapping(uint64 strike => uint48 epochId) public epochs; /*############################################################### CONSTRUCTOR ###############################################################*/ constructor(address asset_, address oracle_, address treasury_, address oracleSender_, bytes32 oracleKey_) ReentrancyGuard() Ownable(msg.sender) Pausable() { if (asset_ == address(0)) revert ZeroAddress(); if (oracle_ == address(0)) revert ZeroOracleAddress(); if (treasury_ == address(0)) revert ZeroTreasuryAddress(); if (oracleSender_ == address(0)) revert ZeroOracleSenderAddress(); asset = IERC20(asset_); oracle = IOracleChainsight(oracle_); treasury = treasury_; oracleSender = oracleSender_; oracleKey = oracleKey_; hodlMulti = new henlocked(""); } /*############################################################### ADMIN FUNCTIONS ###############################################################*/ /** * @notice Pause the contract */ function pause() external onlyOwner { _pause(); } /** * @notice Unpause the contract */ function unpause() external onlyOwner { _unpause(); } /** * @notice Set a new treasury address * @param treasury_ The new treasury address */ function setTreasury(address treasury_) external nonReentrant onlyOwner { if (treasury_ == address(0)) revert ZeroAddress(); treasury = treasury_; emit SetTreasury(treasury); } /** * @notice Set a new fee * @param fee_ The new fee value */ function setFee(uint256 fee_) external nonReentrant onlyOwner { if (fee_ > MAX_FEE) revert MaxFeeExceeded(); fee = fee_; emit SetFee(fee); } /** * @notice Open a new round for minting HENLOCKED tokens * @param strike The strike price for the new round * @param depositLimit The maximum deposits allowed for this epoch * @param reservoir The address of the Reservoir contract * @return The created epochId */ function openRound(uint64 strike, uint256 depositLimit, address reservoir) external nonReentrant onlyOwner returns (uint48) { (uint64 currentPrice, uint64 timestamp) = oracle.readAsUint64WithTimestamp(oracleSender, oracleKey); if (strike <= currentPrice) revert StrikeTooLow(); if (timestamp + 1 hours < uint64(block.timestamp)) revert StaleOracleData(); uint256 existingSupply = hodlMulti.totalSupply(strike); if (depositLimit <= existingSupply) revert InvalidDepositLimit(); uint48 existingEpochId = epochs[strike]; if (existingEpochId != 0 && !infos[existingEpochId].closed) revert RoundAlreadyExistsOrNotClosed(); uint48 epochId = nextId++; infos[epochId] = EpochInfo({ strike: strike, closed: false, depositsPaused: false, timestamp: timestamp, depositLimit: depositLimit, totalDeposits: existingSupply, reservoir: reservoir }); epochs[strike] = epochId; emit RoundOpened(epochId, strike, depositLimit); return epochId; } /*############################################################### MINTING AND REDEEMING ###############################################################*/ /** * @notice Preview minting to calculate fee * @param value The amount to be minted * @return depositAfterFee The net value after fee * @return feeAmount The fee amount */ function previewMint(uint256 value) external view returns (uint256 depositAfterFee, uint256 feeAmount) { if (fee == 0) { return (value, 0); } else { uint256 feeValue = value.mulDivUp(fee, FEE_BASIS); return (value - feeValue, feeValue); } } /** * @notice Mint HENLOCKED tokens by depositing HENLO * @param strike The strike price for minting * @param amount The amount of HENLO to deposit * @return The amount of HENLOCKED tokens minted */ function mint(uint64 strike, uint256 amount, uint256 minimumWhaleMatch) external nonReentrant whenNotPaused returns (uint256) { uint48 epochId = epochs[strike]; if (epochId == 0) revert RoundNotOpened(); EpochInfo storage info = infos[epochId]; if (info.closed) revert RoundIsClosed(); if (info.depositsPaused) revert DepositsArePaused(); if (amount == 0) revert ZeroMint(); uint256 value = amount; uint256 feeValue = value.mulDivUp(fee, FEE_BASIS); value -= feeValue; // Security: Exclude fee from deposit limit calculation if (info.totalDeposits + value > info.depositLimit) revert AmountExceedsDepositLimit(); uint256 y = 0; if (info.reservoir != address(0)) { IReservoir reservoir = IReservoir(info.reservoir); if (reservoir.canMatch()) { uint256 remainingCapacity = info.depositLimit - (info.totalDeposits + value); if (value < remainingCapacity) { remainingCapacity = value; } y = reservoir.matchMint(remainingCapacity); } } info.totalDeposits += value; // Security: Track net deposit amount require(y >= minimumWhaleMatch, "Whale slippage"); if (y > 0) { info.totalDeposits += y; } if (feeValue > 0) { asset.safeTransferFrom(msg.sender, treasury, feeValue); } asset.safeTransferFrom(msg.sender, address(this), value); if (y > 0) { IReservoir reservoir = IReservoir(info.reservoir); reservoir.incrementMatched(y); asset.safeTransferFrom(info.reservoir, address(this), y); hodlMulti.mint(info.reservoir, strike, y); emit MintFromReservoir(info.reservoir, strike, y); } hodlMulti.mint(msg.sender, strike, value); emit Mint(msg.sender, strike, value); return value; } /** * @notice Redeem HENLOCKED tokens for HENLO * @param strike The strike price of the HENLOCKED tokens * @param amount The amount of HENLOCKED tokens to redeem * @return The amount of HENLO redeemed */ function redeem(uint64 strike, uint256 amount) external nonReentrant returns (uint256) { if (amount == 0) revert ZeroRedeemAmount(); if (!canRedeem(strike)) revert CannotRedeemAtThisTime(); if (hodlMulti.balanceOf(msg.sender, strike) < amount) revert InsufficientHenlockedBalance(); hodlMulti.burn(msg.sender, strike, amount); _closeOutEpoch(strike); asset.safeTransfer(msg.sender, amount); emit Redeem(msg.sender, strike, amount); return amount; } /** * @notice Deploy a new ERC20 HENLOCKED token for a specific strike * @param strike The strike price for the HENLOCKED token * @return The address of the newly deployed HENLOCKED token */ function deployERC20(uint64 strike) external nonReentrant returns (address) { if (address(deployments[strike]) != address(0)) revert AlreadyDeployed(); henlockedToken hodl = new henlockedToken(address(hodlMulti), strike); hodlMulti.authorize(address(hodl)); deployments[strike] = hodl; emit DeployERC20(strike, address(hodl)); return address(hodl); } /*############################################################### DEPOSIT MANAGEMENT ###############################################################*/ /** * @notice Pause deposits for a specific strike * @param strike The strike price to pause deposits */ function pauseDeposits(uint64 strike) external onlyOwner { uint48 epochId = epochs[strike]; if (epochId == 0) revert RoundNotOpened(); EpochInfo storage info = infos[epochId]; if (info.closed) revert RoundIsClosed(); if (info.depositsPaused) revert DepositsAlreadyPaused(); info.depositsPaused = true; emit DepositsPaused(epochId, strike); } /** * @notice Unpause deposits for a specific strike * @param strike The strike price to unpause deposits */ function unpauseDeposits(uint64 strike) external onlyOwner { uint48 epochId = epochs[strike]; if (epochId == 0) revert RoundNotOpened(); EpochInfo storage info = infos[epochId]; if (info.closed) revert RoundIsClosed(); if (!info.depositsPaused) revert DepositsNotPaused(); info.depositsPaused = false; emit DepositsUnpaused(epochId, strike); } /** * @notice Update the deposit limit for a specific strike * @param strike The strike price to update * @param newDepositLimit The new deposit limit */ function updateDepositLimit(uint64 strike, uint256 newDepositLimit) external nonReentrant onlyOwner { uint48 epochId = epochs[strike]; if (epochId == 0) revert RoundNotOpened(); EpochInfo storage info = infos[epochId]; if (info.closed) revert RoundIsClosed(); if (newDepositLimit < info.totalDeposits) revert NewLimitTooLow(); info.depositLimit = newDepositLimit; emit DepositLimitUpdated(epochId, strike, newDepositLimit); } /*############################################################### ORACLE MANAGEMENT ###############################################################*/ /** * @notice Set a new oracle sender * @param newSender The new oracle sender address */ function setOracleSender(address newSender) external onlyOwner { if (newSender == address(0)) revert ZeroAddress(); oracleSender = newSender; emit OracleSenderUpdated(newSender); } /** * @notice Get the current oracle key * @return The current oracle key */ function getOracleKey() external view returns (bytes32) { return oracleKey; } /** * @notice Set a new oracle key * @param newKey The new oracle key */ function setOracleKey(bytes32 newKey) external onlyOwner { oracleKey = newKey; emit OracleKeyUpdated(newKey); } /** * @notice Update the oracle address * @param newOracle The new oracle contract address */ function setOracle(address newOracle) external onlyOwner { oracle = IOracleChainsight(newOracle); emit OracleUpdated(newOracle); } /*############################################################### VIEW FUNCTIONS ###############################################################*/ /** * @notice Check if redemption is possible for a given strike * @param strike The strike price to check * @return True if redemption is possible, otherwise false */ function canRedeem(uint64 strike) public view returns (bool) { uint48 epochId = epochs[strike]; EpochInfo storage info = infos[epochId]; // Security: Check closed status first to ensure redemption availability if (info.closed) { return true; } (uint64 currentPrice, uint64 timestamp) = oracle.readAsUint64WithTimestamp(oracleSender, oracleKey); if (timestamp + 1 hours < uint64(block.timestamp)) revert StaleOracleData(); // Condition 1: Current price is above or equal to strike if (currentPrice >= strike && timestamp >= info.timestamp) { return true; } return false; } /** * @notice Get information about a specific round * @param strike The strike price of the round * @return exists Whether the round exists * @return closed Whether the round is closed * @return depositsPaused Whether deposits are paused for the round * @return timestamp The timestamp of the round * @return depositLimit The deposit limit of the round * @return totalDeposits The total deposits of the round * @return remainingCapacity The remaining deposit capacity of the round */ function getRoundInfo(uint64 strike) external view returns ( bool exists, bool closed, bool depositsPaused, // New return value uint256 timestamp, uint256 depositLimit, uint256 totalDeposits, uint256 remainingCapacity ) { uint48 epochId = epochs[strike]; if (epochId == 0) return (false, false, false, 0, 0, 0, 0); EpochInfo storage info = infos[epochId]; return ( true, info.closed, info.depositsPaused, // Return deposit pause status info.timestamp, info.depositLimit, info.totalDeposits, info.depositLimit - info.totalDeposits ); } /*############################################################### INTERNAL FUNCTIONS ###############################################################*/ /** * @notice Close out an epoch if it hasn't been closed yet * @param strike The strike price of the epoch to close */ function _closeOutEpoch(uint64 strike) private { uint48 epochId = epochs[strike]; EpochInfo storage info = infos[epochId]; if (info.closed) { return; } if (info.strike == 0) revert InvalidEpochStrike(); // Mark the epoch as closed info.closed = true; emit RoundClosed(epochId, strike); } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v5.1.0) (token/ERC20/utils/SafeERC20.sol) pragma solidity ^0.8.20; import {IERC20} from "../IERC20.sol"; import {IERC1363} from "../../../interfaces/IERC1363.sol"; import {Address} from "../../../utils/Address.sol"; /** * @title SafeERC20 * @dev Wrappers around ERC-20 operations that throw on failure (when the token * contract returns false). Tokens that return no value (and instead revert or * throw on failure) are also supported, non-reverting calls are assumed to be * successful. * To use this library you can add a `using SafeERC20 for IERC20;` statement to your contract, * which allows you to call the safe operations as `token.safeTransfer(...)`, etc. */ library SafeERC20 { /** * @dev An operation with an ERC-20 token failed. */ error SafeERC20FailedOperation(address token); /** * @dev Indicates a failed `decreaseAllowance` request. */ error SafeERC20FailedDecreaseAllowance(address spender, uint256 currentAllowance, uint256 requestedDecrease); /** * @dev Transfer `value` amount of `token` from the calling contract to `to`. If `token` returns no value, * non-reverting calls are assumed to be successful. */ function safeTransfer(IERC20 token, address to, uint256 value) internal { _callOptionalReturn(token, abi.encodeCall(token.transfer, (to, value))); } /** * @dev Transfer `value` amount of `token` from `from` to `to`, spending the approval given by `from` to the * calling contract. If `token` returns no value, non-reverting calls are assumed to be successful. */ function safeTransferFrom(IERC20 token, address from, address to, uint256 value) internal { _callOptionalReturn(token, abi.encodeCall(token.transferFrom, (from, to, value))); } /** * @dev Increase the calling contract's allowance toward `spender` by `value`. If `token` returns no value, * non-reverting calls are assumed to be successful. * * IMPORTANT: If the token implements ERC-7674 (ERC-20 with temporary allowance), and if the "client" * smart contract uses ERC-7674 to set temporary allowances, then the "client" smart contract should avoid using * this function. Performing a {safeIncreaseAllowance} or {safeDecreaseAllowance} operation on a token contract * that has a non-zero temporary allowance (for that particular owner-spender) will result in unexpected behavior. */ function safeIncreaseAllowance(IERC20 token, address spender, uint256 value) internal { uint256 oldAllowance = token.allowance(address(this), spender); forceApprove(token, spender, oldAllowance + value); } /** * @dev Decrease the calling contract's allowance toward `spender` by `requestedDecrease`. If `token` returns no * value, non-reverting calls are assumed to be successful. * * IMPORTANT: If the token implements ERC-7674 (ERC-20 with temporary allowance), and if the "client" * smart contract uses ERC-7674 to set temporary allowances, then the "client" smart contract should avoid using * this function. Performing a {safeIncreaseAllowance} or {safeDecreaseAllowance} operation on a token contract * that has a non-zero temporary allowance (for that particular owner-spender) will result in unexpected behavior. */ function safeDecreaseAllowance(IERC20 token, address spender, uint256 requestedDecrease) internal { unchecked { uint256 currentAllowance = token.allowance(address(this), spender); if (currentAllowance < requestedDecrease) { revert SafeERC20FailedDecreaseAllowance(spender, currentAllowance, requestedDecrease); } forceApprove(token, spender, currentAllowance - requestedDecrease); } } /** * @dev Set the calling contract's allowance toward `spender` to `value`. If `token` returns no value, * non-reverting calls are assumed to be successful. Meant to be used with tokens that require the approval * to be set to zero before setting it to a non-zero value, such as USDT. * * NOTE: If the token implements ERC-7674, this function will not modify any temporary allowance. This function * only sets the "standard" allowance. Any temporary allowance will remain active, in addition to the value being * set here. */ function forceApprove(IERC20 token, address spender, uint256 value) internal { bytes memory approvalCall = abi.encodeCall(token.approve, (spender, value)); if (!_callOptionalReturnBool(token, approvalCall)) { _callOptionalReturn(token, abi.encodeCall(token.approve, (spender, 0))); _callOptionalReturn(token, approvalCall); } } /** * @dev Performs an {ERC1363} transferAndCall, with a fallback to the simple {ERC20} transfer if the target has no * code. This can be used to implement an {ERC721}-like safe transfer that rely on {ERC1363} checks when * targeting contracts. * * Reverts if the returned value is other than `true`. */ function transferAndCallRelaxed(IERC1363 token, address to, uint256 value, bytes memory data) internal { if (to.code.length == 0) { safeTransfer(token, to, value); } else if (!token.transferAndCall(to, value, data)) { revert SafeERC20FailedOperation(address(token)); } } /** * @dev Performs an {ERC1363} transferFromAndCall, with a fallback to the simple {ERC20} transferFrom if the target * has no code. This can be used to implement an {ERC721}-like safe transfer that rely on {ERC1363} checks when * targeting contracts. * * Reverts if the returned value is other than `true`. */ function transferFromAndCallRelaxed( IERC1363 token, address from, address to, uint256 value, bytes memory data ) internal { if (to.code.length == 0) { safeTransferFrom(token, from, to, value); } else if (!token.transferFromAndCall(from, to, value, data)) { revert SafeERC20FailedOperation(address(token)); } } /** * @dev Performs an {ERC1363} approveAndCall, with a fallback to the simple {ERC20} approve if the target has no * code. This can be used to implement an {ERC721}-like safe transfer that rely on {ERC1363} checks when * targeting contracts. * * NOTE: When the recipient address (`to`) has no code (i.e. is an EOA), this function behaves as {forceApprove}. * Opposedly, when the recipient address (`to`) has code, this function only attempts to call {ERC1363-approveAndCall} * once without retrying, and relies on the returned value to be true. * * Reverts if the returned value is other than `true`. */ function approveAndCallRelaxed(IERC1363 token, address to, uint256 value, bytes memory data) internal { if (to.code.length == 0) { forceApprove(token, to, value); } else if (!token.approveAndCall(to, value, data)) { revert SafeERC20FailedOperation(address(token)); } } /** * @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement * on the return value: the return value is optional (but if data is returned, it must not be false). * @param token The token targeted by the call. * @param data The call data (encoded using abi.encode or one of its variants). * * This is a variant of {_callOptionalReturnBool} that reverts if call fails to meet the requirements. */ function _callOptionalReturn(IERC20 token, bytes memory data) private { uint256 returnSize; uint256 returnValue; assembly ("memory-safe") { let success := call(gas(), token, 0, add(data, 0x20), mload(data), 0, 0x20) // bubble errors if iszero(success) { let ptr := mload(0x40) returndatacopy(ptr, 0, returndatasize()) revert(ptr, returndatasize()) } returnSize := returndatasize() returnValue := mload(0) } if (returnSize == 0 ? address(token).code.length == 0 : returnValue != 1) { revert SafeERC20FailedOperation(address(token)); } } /** * @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement * on the return value: the return value is optional (but if data is returned, it must not be false). * @param token The token targeted by the call. * @param data The call data (encoded using abi.encode or one of its variants). * * This is a variant of {_callOptionalReturn} that silently catches all reverts and returns a bool instead. */ function _callOptionalReturnBool(IERC20 token, bytes memory data) private returns (bool) { bool success; uint256 returnSize; uint256 returnValue; assembly ("memory-safe") { success := call(gas(), token, 0, add(data, 0x20), mload(data), 0, 0x20) returnSize := returndatasize() returnValue := mload(0) } return success && (returnSize == 0 ? address(token).code.length > 0 : returnValue == 1); } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v5.1.0) (token/ERC20/IERC20.sol) pragma solidity ^0.8.20; /** * @dev Interface of the ERC-20 standard as defined in the ERC. */ interface IERC20 { /** * @dev Emitted when `value` tokens are moved from one account (`from`) to * another (`to`). * * Note that `value` may be zero. */ event Transfer(address indexed from, address indexed to, uint256 value); /** * @dev Emitted when the allowance of a `spender` for an `owner` is set by * a call to {approve}. `value` is the new allowance. */ event Approval(address indexed owner, address indexed spender, uint256 value); /** * @dev Returns the value of tokens in existence. */ function totalSupply() external view returns (uint256); /** * @dev Returns the value of tokens owned by `account`. */ function balanceOf(address account) external view returns (uint256); /** * @dev Moves a `value` amount of tokens from the caller's account to `to`. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transfer(address to, uint256 value) external returns (bool); /** * @dev Returns the remaining number of tokens that `spender` will be * allowed to spend on behalf of `owner` through {transferFrom}. This is * zero by default. * * This value changes when {approve} or {transferFrom} are called. */ function allowance(address owner, address spender) external view returns (uint256); /** * @dev Sets a `value` amount of tokens as the allowance of `spender` over the * caller's tokens. * * Returns a boolean value indicating whether the operation succeeded. * * IMPORTANT: Beware that changing an allowance with this method brings the risk * that someone may use both the old and the new allowance by unfortunate * transaction ordering. One possible solution to mitigate this race * condition is to first reduce the spender's allowance to 0 and set the * desired value afterwards: * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 * * Emits an {Approval} event. */ function approve(address spender, uint256 value) external returns (bool); /** * @dev Moves a `value` amount of tokens from `from` to `to` using the * allowance mechanism. `value` is then deducted from the caller's * allowance. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transferFrom(address from, address to, uint256 value) external returns (bool); }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v5.1.0) (utils/ReentrancyGuard.sol) pragma solidity ^0.8.20; /** * @dev Contract module that helps prevent reentrant calls to a function. * * Inheriting from `ReentrancyGuard` will make the {nonReentrant} modifier * available, which can be applied to functions to make sure there are no nested * (reentrant) calls to them. * * Note that because there is a single `nonReentrant` guard, functions marked as * `nonReentrant` may not call one another. This can be worked around by making * those functions `private`, and then adding `external` `nonReentrant` entry * points to them. * * TIP: If EIP-1153 (transient storage) is available on the chain you're deploying at, * consider using {ReentrancyGuardTransient} instead. * * TIP: If you would like to learn more about reentrancy and alternative ways * to protect against it, check out our blog post * https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul]. */ abstract contract ReentrancyGuard { // Booleans are more expensive than uint256 or any type that takes up a full // word because each write operation emits an extra SLOAD to first read the // slot's contents, replace the bits taken up by the boolean, and then write // back. This is the compiler's defense against contract upgrades and // pointer aliasing, and it cannot be disabled. // The values being non-zero value makes deployment a bit more expensive, // but in exchange the refund on every call to nonReentrant will be lower in // amount. Since refunds are capped to a percentage of the total // transaction's gas, it is best to keep them low in cases like this one, to // increase the likelihood of the full refund coming into effect. uint256 private constant NOT_ENTERED = 1; uint256 private constant ENTERED = 2; uint256 private _status; /** * @dev Unauthorized reentrant call. */ error ReentrancyGuardReentrantCall(); constructor() { _status = NOT_ENTERED; } /** * @dev Prevents a contract from calling itself, directly or indirectly. * Calling a `nonReentrant` function from another `nonReentrant` * function is not supported. It is possible to prevent this from happening * by making the `nonReentrant` function external, and making it call a * `private` function that does the actual work. */ modifier nonReentrant() { _nonReentrantBefore(); _; _nonReentrantAfter(); } function _nonReentrantBefore() private { // On the first call to nonReentrant, _status will be NOT_ENTERED if (_status == ENTERED) { revert ReentrancyGuardReentrantCall(); } // Any calls to nonReentrant after this point will fail _status = ENTERED; } function _nonReentrantAfter() private { // By storing the original value once again, a refund is triggered (see // https://eips.ethereum.org/EIPS/eip-2200) _status = NOT_ENTERED; } /** * @dev Returns true if the reentrancy guard is currently set to "entered", which indicates there is a * `nonReentrant` function in the call stack. */ function _reentrancyGuardEntered() internal view returns (bool) { return _status == ENTERED; } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v5.0.0) (access/Ownable.sol) pragma solidity ^0.8.20; import {Context} from "../utils/Context.sol"; /** * @dev Contract module which provides a basic access control mechanism, where * there is an account (an owner) that can be granted exclusive access to * specific functions. * * The initial owner is set to the address provided by the deployer. This can * later be changed with {transferOwnership}. * * This module is used through inheritance. It will make available the modifier * `onlyOwner`, which can be applied to your functions to restrict their use to * the owner. */ abstract contract Ownable is Context { address private _owner; /** * @dev The caller account is not authorized to perform an operation. */ error OwnableUnauthorizedAccount(address account); /** * @dev The owner is not a valid owner account. (eg. `address(0)`) */ error OwnableInvalidOwner(address owner); event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); /** * @dev Initializes the contract setting the address provided by the deployer as the initial owner. */ constructor(address initialOwner) { if (initialOwner == address(0)) { revert OwnableInvalidOwner(address(0)); } _transferOwnership(initialOwner); } /** * @dev Throws if called by any account other than the owner. */ modifier onlyOwner() { _checkOwner(); _; } /** * @dev Returns the address of the current owner. */ function owner() public view virtual returns (address) { return _owner; } /** * @dev Throws if the sender is not the owner. */ function _checkOwner() internal view virtual { if (owner() != _msgSender()) { revert OwnableUnauthorizedAccount(_msgSender()); } } /** * @dev Leaves the contract without owner. It will not be possible to call * `onlyOwner` functions. Can only be called by the current owner. * * NOTE: Renouncing ownership will leave the contract without an owner, * thereby disabling any functionality that is only available to the owner. */ function renounceOwnership() public virtual onlyOwner { _transferOwnership(address(0)); } /** * @dev Transfers ownership of the contract to a new account (`newOwner`). * Can only be called by the current owner. */ function transferOwnership(address newOwner) public virtual onlyOwner { if (newOwner == address(0)) { revert OwnableInvalidOwner(address(0)); } _transferOwnership(newOwner); } /** * @dev Transfers ownership of the contract to a new account (`newOwner`). * Internal function without access restriction. */ function _transferOwnership(address newOwner) internal virtual { address oldOwner = _owner; _owner = newOwner; emit OwnershipTransferred(oldOwner, newOwner); } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v5.0.0) (utils/Pausable.sol) pragma solidity ^0.8.20; import {Context} from "../utils/Context.sol"; /** * @dev Contract module which allows children to implement an emergency stop * mechanism that can be triggered by an authorized account. * * This module is used through inheritance. It will make available the * modifiers `whenNotPaused` and `whenPaused`, which can be applied to * the functions of your contract. Note that they will not be pausable by * simply including this module, only once the modifiers are put in place. */ abstract contract Pausable is Context { bool private _paused; /** * @dev Emitted when the pause is triggered by `account`. */ event Paused(address account); /** * @dev Emitted when the pause is lifted by `account`. */ event Unpaused(address account); /** * @dev The operation failed because the contract is paused. */ error EnforcedPause(); /** * @dev The operation failed because the contract is not paused. */ error ExpectedPause(); /** * @dev Initializes the contract in unpaused state. */ constructor() { _paused = false; } /** * @dev Modifier to make a function callable only when the contract is not paused. * * Requirements: * * - The contract must not be paused. */ modifier whenNotPaused() { _requireNotPaused(); _; } /** * @dev Modifier to make a function callable only when the contract is paused. * * Requirements: * * - The contract must be paused. */ modifier whenPaused() { _requirePaused(); _; } /** * @dev Returns true if the contract is paused, and false otherwise. */ function paused() public view virtual returns (bool) { return _paused; } /** * @dev Throws if the contract is paused. */ function _requireNotPaused() internal view virtual { if (paused()) { revert EnforcedPause(); } } /** * @dev Throws if the contract is not paused. */ function _requirePaused() internal view virtual { if (!paused()) { revert ExpectedPause(); } } /** * @dev Triggers stopped state. * * Requirements: * * - The contract must not be paused. */ function _pause() internal virtual whenNotPaused { _paused = true; emit Paused(_msgSender()); } /** * @dev Returns to normal state. * * Requirements: * * - The contract must be paused. */ function _unpause() internal virtual whenPaused { _paused = false; emit Unpaused(_msgSender()); } }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.4; /// @notice Arithmetic library with operations for fixed-point numbers. /// @author Solady (https://github.com/vectorized/solady/blob/main/src/utils/FixedPointMathLib.sol) /// @author Modified from Solmate (https://github.com/transmissions11/solmate/blob/main/src/utils/FixedPointMathLib.sol) library FixedPointMathLib { /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* CUSTOM ERRORS */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ /// @dev The operation failed, as the output exceeds the maximum value of uint256. error ExpOverflow(); /// @dev The operation failed, as the output exceeds the maximum value of uint256. error FactorialOverflow(); /// @dev The operation failed, due to an overflow. error RPowOverflow(); /// @dev The mantissa is too big to fit. error MantissaOverflow(); /// @dev The operation failed, due to an multiplication overflow. error MulWadFailed(); /// @dev The operation failed, due to an multiplication overflow. error SMulWadFailed(); /// @dev The operation failed, either due to a multiplication overflow, or a division by a zero. error DivWadFailed(); /// @dev The operation failed, either due to a multiplication overflow, or a division by a zero. error SDivWadFailed(); /// @dev The operation failed, either due to a multiplication overflow, or a division by a zero. error MulDivFailed(); /// @dev The division failed, as the denominator is zero. error DivFailed(); /// @dev The full precision multiply-divide operation failed, either due /// to the result being larger than 256 bits, or a division by a zero. error FullMulDivFailed(); /// @dev The output is undefined, as the input is less-than-or-equal to zero. error LnWadUndefined(); /// @dev The input outside the acceptable domain. error OutOfDomain(); /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* CONSTANTS */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ /// @dev The scalar of ETH and most ERC20s. uint256 internal constant WAD = 1e18; /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* SIMPLIFIED FIXED POINT OPERATIONS */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ /// @dev Equivalent to `(x * y) / WAD` rounded down. function mulWad(uint256 x, uint256 y) internal pure returns (uint256 z) { /// @solidity memory-safe-assembly assembly { // Equivalent to `require(y == 0 || x <= type(uint256).max / y)`. if gt(x, div(not(0), y)) { if y { mstore(0x00, 0xbac65e5b) // `MulWadFailed()`. revert(0x1c, 0x04) } } z := div(mul(x, y), WAD) } } /// @dev Equivalent to `(x * y) / WAD` rounded down. function sMulWad(int256 x, int256 y) internal pure returns (int256 z) { /// @solidity memory-safe-assembly assembly { z := mul(x, y) // Equivalent to `require((x == 0 || z / x == y) && !(x == -1 && y == type(int256).min))`. if iszero(gt(or(iszero(x), eq(sdiv(z, x), y)), lt(not(x), eq(y, shl(255, 1))))) { mstore(0x00, 0xedcd4dd4) // `SMulWadFailed()`. revert(0x1c, 0x04) } z := sdiv(z, WAD) } } /// @dev Equivalent to `(x * y) / WAD` rounded down, but without overflow checks. function rawMulWad(uint256 x, uint256 y) internal pure returns (uint256 z) { /// @solidity memory-safe-assembly assembly { z := div(mul(x, y), WAD) } } /// @dev Equivalent to `(x * y) / WAD` rounded down, but without overflow checks. function rawSMulWad(int256 x, int256 y) internal pure returns (int256 z) { /// @solidity memory-safe-assembly assembly { z := sdiv(mul(x, y), WAD) } } /// @dev Equivalent to `(x * y) / WAD` rounded up. function mulWadUp(uint256 x, uint256 y) internal pure returns (uint256 z) { /// @solidity memory-safe-assembly assembly { z := mul(x, y) // Equivalent to `require(y == 0 || x <= type(uint256).max / y)`. if iszero(eq(div(z, y), x)) { if y { mstore(0x00, 0xbac65e5b) // `MulWadFailed()`. revert(0x1c, 0x04) } } z := add(iszero(iszero(mod(z, WAD))), div(z, WAD)) } } /// @dev Equivalent to `(x * y) / WAD` rounded up, but without overflow checks. function rawMulWadUp(uint256 x, uint256 y) internal pure returns (uint256 z) { /// @solidity memory-safe-assembly assembly { z := add(iszero(iszero(mod(mul(x, y), WAD))), div(mul(x, y), WAD)) } } /// @dev Equivalent to `(x * WAD) / y` rounded down. function divWad(uint256 x, uint256 y) internal pure returns (uint256 z) { /// @solidity memory-safe-assembly assembly { // Equivalent to `require(y != 0 && x <= type(uint256).max / WAD)`. if iszero(mul(y, lt(x, add(1, div(not(0), WAD))))) { mstore(0x00, 0x7c5f487d) // `DivWadFailed()`. revert(0x1c, 0x04) } z := div(mul(x, WAD), y) } } /// @dev Equivalent to `(x * WAD) / y` rounded down. function sDivWad(int256 x, int256 y) internal pure returns (int256 z) { /// @solidity memory-safe-assembly assembly { z := mul(x, WAD) // Equivalent to `require(y != 0 && ((x * WAD) / WAD == x))`. if iszero(mul(y, eq(sdiv(z, WAD), x))) { mstore(0x00, 0x5c43740d) // `SDivWadFailed()`. revert(0x1c, 0x04) } z := sdiv(z, y) } } /// @dev Equivalent to `(x * WAD) / y` rounded down, but without overflow and divide by zero checks. function rawDivWad(uint256 x, uint256 y) internal pure returns (uint256 z) { /// @solidity memory-safe-assembly assembly { z := div(mul(x, WAD), y) } } /// @dev Equivalent to `(x * WAD) / y` rounded down, but without overflow and divide by zero checks. function rawSDivWad(int256 x, int256 y) internal pure returns (int256 z) { /// @solidity memory-safe-assembly assembly { z := sdiv(mul(x, WAD), y) } } /// @dev Equivalent to `(x * WAD) / y` rounded up. function divWadUp(uint256 x, uint256 y) internal pure returns (uint256 z) { /// @solidity memory-safe-assembly assembly { // Equivalent to `require(y != 0 && x <= type(uint256).max / WAD)`. if iszero(mul(y, lt(x, add(1, div(not(0), WAD))))) { mstore(0x00, 0x7c5f487d) // `DivWadFailed()`. revert(0x1c, 0x04) } z := add(iszero(iszero(mod(mul(x, WAD), y))), div(mul(x, WAD), y)) } } /// @dev Equivalent to `(x * WAD) / y` rounded up, but without overflow and divide by zero checks. function rawDivWadUp(uint256 x, uint256 y) internal pure returns (uint256 z) { /// @solidity memory-safe-assembly assembly { z := add(iszero(iszero(mod(mul(x, WAD), y))), div(mul(x, WAD), y)) } } /// @dev Equivalent to `x` to the power of `y`. /// because `x ** y = (e ** ln(x)) ** y = e ** (ln(x) * y)`. /// Note: This function is an approximation. function powWad(int256 x, int256 y) internal pure returns (int256) { // Using `ln(x)` means `x` must be greater than 0. return expWad((lnWad(x) * y) / int256(WAD)); } /// @dev Returns `exp(x)`, denominated in `WAD`. /// Credit to Remco Bloemen under MIT license: https://2π.com/22/exp-ln /// Note: This function is an approximation. Monotonically increasing. function expWad(int256 x) internal pure returns (int256 r) { unchecked { // When the result is less than 0.5 we return zero. // This happens when `x <= (log(1e-18) * 1e18) ~ -4.15e19`. if (x <= -41446531673892822313) return r; /// @solidity memory-safe-assembly assembly { // When the result is greater than `(2**255 - 1) / 1e18` we can not represent it as // an int. This happens when `x >= floor(log((2**255 - 1) / 1e18) * 1e18) ≈ 135`. if iszero(slt(x, 135305999368893231589)) { mstore(0x00, 0xa37bfec9) // `ExpOverflow()`. revert(0x1c, 0x04) } } // `x` is now in the range `(-42, 136) * 1e18`. Convert to `(-42, 136) * 2**96` // for more intermediate precision and a binary basis. This base conversion // is a multiplication by 1e18 / 2**96 = 5**18 / 2**78. x = (x << 78) / 5 ** 18; // Reduce range of x to (-½ ln 2, ½ ln 2) * 2**96 by factoring out powers // of two such that exp(x) = exp(x') * 2**k, where k is an integer. // Solving this gives k = round(x / log(2)) and x' = x - k * log(2). int256 k = ((x << 96) / 54916777467707473351141471128 + 2 ** 95) >> 96; x = x - k * 54916777467707473351141471128; // `k` is in the range `[-61, 195]`. // Evaluate using a (6, 7)-term rational approximation. // `p` is made monic, we'll multiply by a scale factor later. int256 y = x + 1346386616545796478920950773328; y = ((y * x) >> 96) + 57155421227552351082224309758442; int256 p = y + x - 94201549194550492254356042504812; p = ((p * y) >> 96) + 28719021644029726153956944680412240; p = p * x + (4385272521454847904659076985693276 << 96); // We leave `p` in `2**192` basis so we don't need to scale it back up for the division. int256 q = x - 2855989394907223263936484059900; q = ((q * x) >> 96) + 50020603652535783019961831881945; q = ((q * x) >> 96) - 533845033583426703283633433725380; q = ((q * x) >> 96) + 3604857256930695427073651918091429; q = ((q * x) >> 96) - 14423608567350463180887372962807573; q = ((q * x) >> 96) + 26449188498355588339934803723976023; /// @solidity memory-safe-assembly assembly { // Div in assembly because solidity adds a zero check despite the unchecked. // The q polynomial won't have zeros in the domain as all its roots are complex. // No scaling is necessary because p is already `2**96` too large. r := sdiv(p, q) } // r should be in the range `(0.09, 0.25) * 2**96`. // We now need to multiply r by: // - The scale factor `s ≈ 6.031367120`. // - The `2**k` factor from the range reduction. // - The `1e18 / 2**96` factor for base conversion. // We do this all at once, with an intermediate result in `2**213` // basis, so the final right shift is always by a positive amount. r = int256( (uint256(r) * 3822833074963236453042738258902158003155416615667) >> uint256(195 - k) ); } } /// @dev Returns `ln(x)`, denominated in `WAD`. /// Credit to Remco Bloemen under MIT license: https://2π.com/22/exp-ln /// Note: This function is an approximation. Monotonically increasing. function lnWad(int256 x) internal pure returns (int256 r) { /// @solidity memory-safe-assembly assembly { // We want to convert `x` from `10**18` fixed point to `2**96` fixed point. // We do this by multiplying by `2**96 / 10**18`. But since // `ln(x * C) = ln(x) + ln(C)`, we can simply do nothing here // and add `ln(2**96 / 10**18)` at the end. // Compute `k = log2(x) - 96`, `r = 159 - k = 255 - log2(x) = 255 ^ log2(x)`. r := shl(7, lt(0xffffffffffffffffffffffffffffffff, x)) r := or(r, shl(6, lt(0xffffffffffffffff, shr(r, x)))) r := or(r, shl(5, lt(0xffffffff, shr(r, x)))) r := or(r, shl(4, lt(0xffff, shr(r, x)))) r := or(r, shl(3, lt(0xff, shr(r, x)))) // We place the check here for more optimal stack operations. if iszero(sgt(x, 0)) { mstore(0x00, 0x1615e638) // `LnWadUndefined()`. revert(0x1c, 0x04) } // forgefmt: disable-next-item r := xor(r, byte(and(0x1f, shr(shr(r, x), 0x8421084210842108cc6318c6db6d54be)), 0xf8f9f9faf9fdfafbf9fdfcfdfafbfcfef9fafdfafcfcfbfefafafcfbffffffff)) // Reduce range of x to (1, 2) * 2**96 // ln(2^k * x) = k * ln(2) + ln(x) x := shr(159, shl(r, x)) // Evaluate using a (8, 8)-term rational approximation. // `p` is made monic, we will multiply by a scale factor later. // forgefmt: disable-next-item let p := sub( // This heavily nested expression is to avoid stack-too-deep for via-ir. sar(96, mul(add(43456485725739037958740375743393, sar(96, mul(add(24828157081833163892658089445524, sar(96, mul(add(3273285459638523848632254066296, x), x))), x))), x)), 11111509109440967052023855526967) p := sub(sar(96, mul(p, x)), 45023709667254063763336534515857) p := sub(sar(96, mul(p, x)), 14706773417378608786704636184526) p := sub(mul(p, x), shl(96, 795164235651350426258249787498)) // We leave `p` in `2**192` basis so we don't need to scale it back up for the division. // `q` is monic by convention. let q := add(5573035233440673466300451813936, x) q := add(71694874799317883764090561454958, sar(96, mul(x, q))) q := add(283447036172924575727196451306956, sar(96, mul(x, q))) q := add(401686690394027663651624208769553, sar(96, mul(x, q))) q := add(204048457590392012362485061816622, sar(96, mul(x, q))) q := add(31853899698501571402653359427138, sar(96, mul(x, q))) q := add(909429971244387300277376558375, sar(96, mul(x, q))) // `p / q` is in the range `(0, 0.125) * 2**96`. // Finalization, we need to: // - Multiply by the scale factor `s = 5.549…`. // - Add `ln(2**96 / 10**18)`. // - Add `k * ln(2)`. // - Multiply by `10**18 / 2**96 = 5**18 >> 78`. // The q polynomial is known not to have zeros in the domain. // No scaling required because p is already `2**96` too large. p := sdiv(p, q) // Multiply by the scaling factor: `s * 5**18 * 2**96`, base is now `5**18 * 2**192`. p := mul(1677202110996718588342820967067443963516166, p) // Add `ln(2) * k * 5**18 * 2**192`. // forgefmt: disable-next-item p := add(mul(16597577552685614221487285958193947469193820559219878177908093499208371, sub(159, r)), p) // Add `ln(2**96 / 10**18) * 5**18 * 2**192`. p := add(600920179829731861736702779321621459595472258049074101567377883020018308, p) // Base conversion: mul `2**18 / 2**192`. r := sar(174, p) } } /// @dev Returns `W_0(x)`, denominated in `WAD`. /// See: https://en.wikipedia.org/wiki/Lambert_W_function /// a.k.a. Product log function. This is an approximation of the principal branch. /// Note: This function is an approximation. Monotonically increasing. function lambertW0Wad(int256 x) internal pure returns (int256 w) { // forgefmt: disable-next-item unchecked { if ((w = x) <= -367879441171442322) revert OutOfDomain(); // `x` less than `-1/e`. (int256 wad, int256 p) = (int256(WAD), x); uint256 c; // Whether we need to avoid catastrophic cancellation. uint256 i = 4; // Number of iterations. if (w <= 0x1ffffffffffff) { if (-0x4000000000000 <= w) { i = 1; // Inputs near zero only take one step to converge. } else if (w <= -0x3ffffffffffffff) { i = 32; // Inputs near `-1/e` take very long to converge. } } else if (uint256(w >> 63) == uint256(0)) { /// @solidity memory-safe-assembly assembly { // Inline log2 for more performance, since the range is small. let v := shr(49, w) let l := shl(3, lt(0xff, v)) l := add(or(l, byte(and(0x1f, shr(shr(l, v), 0x8421084210842108cc6318c6db6d54be)), 0x0706060506020504060203020504030106050205030304010505030400000000)), 49) w := sdiv(shl(l, 7), byte(sub(l, 31), 0x0303030303030303040506080c13)) c := gt(l, 60) i := add(2, add(gt(l, 53), c)) } } else { int256 ll = lnWad(w = lnWad(w)); /// @solidity memory-safe-assembly assembly { // `w = ln(x) - ln(ln(x)) + b * ln(ln(x)) / ln(x)`. w := add(sdiv(mul(ll, 1023715080943847266), w), sub(w, ll)) i := add(3, iszero(shr(68, x))) c := iszero(shr(143, x)) } if (c == uint256(0)) { do { // If `x` is big, use Newton's so that intermediate values won't overflow. int256 e = expWad(w); /// @solidity memory-safe-assembly assembly { let t := mul(w, div(e, wad)) w := sub(w, sdiv(sub(t, x), div(add(e, t), wad))) } if (p <= w) break; p = w; } while (--i != uint256(0)); /// @solidity memory-safe-assembly assembly { w := sub(w, sgt(w, 2)) } return w; } } do { // Otherwise, use Halley's for faster convergence. int256 e = expWad(w); /// @solidity memory-safe-assembly assembly { let t := add(w, wad) let s := sub(mul(w, e), mul(x, wad)) w := sub(w, sdiv(mul(s, wad), sub(mul(e, t), sdiv(mul(add(t, wad), s), add(t, t))))) } if (p <= w) break; p = w; } while (--i != c); /// @solidity memory-safe-assembly assembly { w := sub(w, sgt(w, 2)) } // For certain ranges of `x`, we'll use the quadratic-rate recursive formula of // R. Iacono and J.P. Boyd for the last iteration, to avoid catastrophic cancellation. if (c == uint256(0)) return w; int256 t = w | 1; /// @solidity memory-safe-assembly assembly { x := sdiv(mul(x, wad), t) } x = (t * (wad + lnWad(x))); /// @solidity memory-safe-assembly assembly { w := sdiv(x, add(wad, t)) } } } /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* GENERAL NUMBER UTILITIES */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ /// @dev Returns `a * b == x * y`, with full precision. function fullMulEq(uint256 a, uint256 b, uint256 x, uint256 y) internal pure returns (bool result) { /// @solidity memory-safe-assembly assembly { result := and(eq(mul(a, b), mul(x, y)), eq(mulmod(x, y, not(0)), mulmod(a, b, not(0)))) } } /// @dev Calculates `floor(x * y / d)` with full precision. /// Throws if result overflows a uint256 or when `d` is zero. /// Credit to Remco Bloemen under MIT license: https://2π.com/21/muldiv function fullMulDiv(uint256 x, uint256 y, uint256 d) internal pure returns (uint256 z) { /// @solidity memory-safe-assembly assembly { // 512-bit multiply `[p1 p0] = x * y`. // Compute the product mod `2**256` and mod `2**256 - 1` // then use the Chinese Remainder Theorem to reconstruct // the 512 bit result. The result is stored in two 256 // variables such that `product = p1 * 2**256 + p0`. // Temporarily use `z` as `p0` to save gas. z := mul(x, y) // Lower 256 bits of `x * y`. for {} 1 {} { // If overflows. if iszero(mul(or(iszero(x), eq(div(z, x), y)), d)) { let mm := mulmod(x, y, not(0)) let p1 := sub(mm, add(z, lt(mm, z))) // Upper 256 bits of `x * y`. /*------------------- 512 by 256 division --------------------*/ // Make division exact by subtracting the remainder from `[p1 p0]`. let r := mulmod(x, y, d) // Compute remainder using mulmod. let t := and(d, sub(0, d)) // The least significant bit of `d`. `t >= 1`. // Make sure `z` is less than `2**256`. Also prevents `d == 0`. // Placing the check here seems to give more optimal stack operations. if iszero(gt(d, p1)) { mstore(0x00, 0xae47f702) // `FullMulDivFailed()`. revert(0x1c, 0x04) } d := div(d, t) // Divide `d` by `t`, which is a power of two. // Invert `d mod 2**256` // Now that `d` is an odd number, it has an inverse // modulo `2**256` such that `d * inv = 1 mod 2**256`. // Compute the inverse by starting with a seed that is correct // correct for four bits. That is, `d * inv = 1 mod 2**4`. let inv := xor(2, mul(3, d)) // Now use Newton-Raphson iteration to improve the precision. // Thanks to Hensel's lifting lemma, this also works in modular // arithmetic, doubling the correct bits in each step. inv := mul(inv, sub(2, mul(d, inv))) // inverse mod 2**8 inv := mul(inv, sub(2, mul(d, inv))) // inverse mod 2**16 inv := mul(inv, sub(2, mul(d, inv))) // inverse mod 2**32 inv := mul(inv, sub(2, mul(d, inv))) // inverse mod 2**64 inv := mul(inv, sub(2, mul(d, inv))) // inverse mod 2**128 z := mul( // Divide [p1 p0] by the factors of two. // Shift in bits from `p1` into `p0`. For this we need // to flip `t` such that it is `2**256 / t`. or(mul(sub(p1, gt(r, z)), add(div(sub(0, t), t), 1)), div(sub(z, r), t)), mul(sub(2, mul(d, inv)), inv) // inverse mod 2**256 ) break } z := div(z, d) break } } } /// @dev Calculates `floor(x * y / d)` with full precision. /// Behavior is undefined if `d` is zero or the final result cannot fit in 256 bits. /// Performs the full 512 bit calculation regardless. function fullMulDivUnchecked(uint256 x, uint256 y, uint256 d) internal pure returns (uint256 z) { /// @solidity memory-safe-assembly assembly { z := mul(x, y) let mm := mulmod(x, y, not(0)) let p1 := sub(mm, add(z, lt(mm, z))) let t := and(d, sub(0, d)) let r := mulmod(x, y, d) d := div(d, t) let inv := xor(2, mul(3, d)) inv := mul(inv, sub(2, mul(d, inv))) inv := mul(inv, sub(2, mul(d, inv))) inv := mul(inv, sub(2, mul(d, inv))) inv := mul(inv, sub(2, mul(d, inv))) inv := mul(inv, sub(2, mul(d, inv))) z := mul( or(mul(sub(p1, gt(r, z)), add(div(sub(0, t), t), 1)), div(sub(z, r), t)), mul(sub(2, mul(d, inv)), inv) ) } } /// @dev Calculates `floor(x * y / d)` with full precision, rounded up. /// Throws if result overflows a uint256 or when `d` is zero. /// Credit to Uniswap-v3-core under MIT license: /// https://github.com/Uniswap/v3-core/blob/main/contracts/libraries/FullMath.sol function fullMulDivUp(uint256 x, uint256 y, uint256 d) internal pure returns (uint256 z) { z = fullMulDiv(x, y, d); /// @solidity memory-safe-assembly assembly { if mulmod(x, y, d) { z := add(z, 1) if iszero(z) { mstore(0x00, 0xae47f702) // `FullMulDivFailed()`. revert(0x1c, 0x04) } } } } /// @dev Calculates `floor(x * y / 2 ** n)` with full precision. /// Throws if result overflows a uint256. /// Credit to Philogy under MIT license: /// https://github.com/SorellaLabs/angstrom/blob/main/contracts/src/libraries/X128MathLib.sol function fullMulDivN(uint256 x, uint256 y, uint8 n) internal pure returns (uint256 z) { /// @solidity memory-safe-assembly assembly { // Temporarily use `z` as `p0` to save gas. z := mul(x, y) // Lower 256 bits of `x * y`. We'll call this `z`. for {} 1 {} { if iszero(or(iszero(x), eq(div(z, x), y))) { let k := and(n, 0xff) // `n`, cleaned. let mm := mulmod(x, y, not(0)) let p1 := sub(mm, add(z, lt(mm, z))) // Upper 256 bits of `x * y`. // | p1 | z | // Before: | p1_0 ¦ p1_1 | z_0 ¦ z_1 | // Final: | 0 ¦ p1_0 | p1_1 ¦ z_0 | // Check that final `z` doesn't overflow by checking that p1_0 = 0. if iszero(shr(k, p1)) { z := add(shl(sub(256, k), p1), shr(k, z)) break } mstore(0x00, 0xae47f702) // `FullMulDivFailed()`. revert(0x1c, 0x04) } z := shr(and(n, 0xff), z) break } } } /// @dev Returns `floor(x * y / d)`. /// Reverts if `x * y` overflows, or `d` is zero. function mulDiv(uint256 x, uint256 y, uint256 d) internal pure returns (uint256 z) { /// @solidity memory-safe-assembly assembly { z := mul(x, y) // Equivalent to `require(d != 0 && (y == 0 || x <= type(uint256).max / y))`. if iszero(mul(or(iszero(x), eq(div(z, x), y)), d)) { mstore(0x00, 0xad251c27) // `MulDivFailed()`. revert(0x1c, 0x04) } z := div(z, d) } } /// @dev Returns `ceil(x * y / d)`. /// Reverts if `x * y` overflows, or `d` is zero. function mulDivUp(uint256 x, uint256 y, uint256 d) internal pure returns (uint256 z) { /// @solidity memory-safe-assembly assembly { z := mul(x, y) // Equivalent to `require(d != 0 && (y == 0 || x <= type(uint256).max / y))`. if iszero(mul(or(iszero(x), eq(div(z, x), y)), d)) { mstore(0x00, 0xad251c27) // `MulDivFailed()`. revert(0x1c, 0x04) } z := add(iszero(iszero(mod(z, d))), div(z, d)) } } /// @dev Returns `x`, the modular multiplicative inverse of `a`, such that `(a * x) % n == 1`. function invMod(uint256 a, uint256 n) internal pure returns (uint256 x) { /// @solidity memory-safe-assembly assembly { let g := n let r := mod(a, n) for { let y := 1 } 1 {} { let q := div(g, r) let t := g g := r r := sub(t, mul(r, q)) let u := x x := y y := sub(u, mul(y, q)) if iszero(r) { break } } x := mul(eq(g, 1), add(x, mul(slt(x, 0), n))) } } /// @dev Returns `ceil(x / d)`. /// Reverts if `d` is zero. function divUp(uint256 x, uint256 d) internal pure returns (uint256 z) { /// @solidity memory-safe-assembly assembly { if iszero(d) { mstore(0x00, 0x65244e4e) // `DivFailed()`. revert(0x1c, 0x04) } z := add(iszero(iszero(mod(x, d))), div(x, d)) } } /// @dev Returns `max(0, x - y)`. function zeroFloorSub(uint256 x, uint256 y) internal pure returns (uint256 z) { /// @solidity memory-safe-assembly assembly { z := mul(gt(x, y), sub(x, y)) } } /// @dev Returns `condition ? x : y`, without branching. function ternary(bool condition, uint256 x, uint256 y) internal pure returns (uint256 z) { /// @solidity memory-safe-assembly assembly { z := xor(x, mul(xor(x, y), iszero(condition))) } } /// @dev Returns `condition ? x : y`, without branching. function ternary(bool condition, bytes32 x, bytes32 y) internal pure returns (bytes32 z) { /// @solidity memory-safe-assembly assembly { z := xor(x, mul(xor(x, y), iszero(condition))) } } /// @dev Returns `condition ? x : y`, without branching. function ternary(bool condition, address x, address y) internal pure returns (address z) { /// @solidity memory-safe-assembly assembly { z := xor(x, mul(xor(x, y), iszero(condition))) } } /// @dev Exponentiate `x` to `y` by squaring, denominated in base `b`. /// Reverts if the computation overflows. function rpow(uint256 x, uint256 y, uint256 b) internal pure returns (uint256 z) { /// @solidity memory-safe-assembly assembly { z := mul(b, iszero(y)) // `0 ** 0 = 1`. Otherwise, `0 ** n = 0`. if x { z := xor(b, mul(xor(b, x), and(y, 1))) // `z = isEven(y) ? scale : x` let half := shr(1, b) // Divide `b` by 2. // Divide `y` by 2 every iteration. for { y := shr(1, y) } y { y := shr(1, y) } { let xx := mul(x, x) // Store x squared. let xxRound := add(xx, half) // Round to the nearest number. // Revert if `xx + half` overflowed, or if `x ** 2` overflows. if or(lt(xxRound, xx), shr(128, x)) { mstore(0x00, 0x49f7642b) // `RPowOverflow()`. revert(0x1c, 0x04) } x := div(xxRound, b) // Set `x` to scaled `xxRound`. // If `y` is odd: if and(y, 1) { let zx := mul(z, x) // Compute `z * x`. let zxRound := add(zx, half) // Round to the nearest number. // If `z * x` overflowed or `zx + half` overflowed: if or(xor(div(zx, x), z), lt(zxRound, zx)) { // Revert if `x` is non-zero. if x { mstore(0x00, 0x49f7642b) // `RPowOverflow()`. revert(0x1c, 0x04) } } z := div(zxRound, b) // Return properly scaled `zxRound`. } } } } } /// @dev Returns the square root of `x`, rounded down. function sqrt(uint256 x) internal pure returns (uint256 z) { /// @solidity memory-safe-assembly assembly { // `floor(sqrt(2**15)) = 181`. `sqrt(2**15) - 181 = 2.84`. z := 181 // The "correct" value is 1, but this saves a multiplication later. // This segment is to get a reasonable initial estimate for the Babylonian method. With a bad // start, the correct # of bits increases ~linearly each iteration instead of ~quadratically. // Let `y = x / 2**r`. We check `y >= 2**(k + 8)` // but shift right by `k` bits to ensure that if `x >= 256`, then `y >= 256`. let r := shl(7, lt(0xffffffffffffffffffffffffffffffffff, x)) r := or(r, shl(6, lt(0xffffffffffffffffff, shr(r, x)))) r := or(r, shl(5, lt(0xffffffffff, shr(r, x)))) r := or(r, shl(4, lt(0xffffff, shr(r, x)))) z := shl(shr(1, r), z) // Goal was to get `z*z*y` within a small factor of `x`. More iterations could // get y in a tighter range. Currently, we will have y in `[256, 256*(2**16))`. // We ensured `y >= 256` so that the relative difference between `y` and `y+1` is small. // That's not possible if `x < 256` but we can just verify those cases exhaustively. // Now, `z*z*y <= x < z*z*(y+1)`, and `y <= 2**(16+8)`, and either `y >= 256`, or `x < 256`. // Correctness can be checked exhaustively for `x < 256`, so we assume `y >= 256`. // Then `z*sqrt(y)` is within `sqrt(257)/sqrt(256)` of `sqrt(x)`, or about 20bps. // For `s` in the range `[1/256, 256]`, the estimate `f(s) = (181/1024) * (s+1)` // is in the range `(1/2.84 * sqrt(s), 2.84 * sqrt(s))`, // with largest error when `s = 1` and when `s = 256` or `1/256`. // Since `y` is in `[256, 256*(2**16))`, let `a = y/65536`, so that `a` is in `[1/256, 256)`. // Then we can estimate `sqrt(y)` using // `sqrt(65536) * 181/1024 * (a + 1) = 181/4 * (y + 65536)/65536 = 181 * (y + 65536)/2**18`. // There is no overflow risk here since `y < 2**136` after the first branch above. z := shr(18, mul(z, add(shr(r, x), 65536))) // A `mul()` is saved from starting `z` at 181. // Given the worst case multiplicative error of 2.84 above, 7 iterations should be enough. z := shr(1, add(z, div(x, z))) z := shr(1, add(z, div(x, z))) z := shr(1, add(z, div(x, z))) z := shr(1, add(z, div(x, z))) z := shr(1, add(z, div(x, z))) z := shr(1, add(z, div(x, z))) z := shr(1, add(z, div(x, z))) // If `x+1` is a perfect square, the Babylonian method cycles between // `floor(sqrt(x))` and `ceil(sqrt(x))`. This statement ensures we return floor. // See: https://en.wikipedia.org/wiki/Integer_square_root#Using_only_integer_division z := sub(z, lt(div(x, z), z)) } } /// @dev Returns the cube root of `x`, rounded down. /// Credit to bout3fiddy and pcaversaccio under AGPLv3 license: /// https://github.com/pcaversaccio/snekmate/blob/main/src/utils/Math.vy /// Formally verified by xuwinnie: /// https://github.com/vectorized/solady/blob/main/audits/xuwinnie-solady-cbrt-proof.pdf function cbrt(uint256 x) internal pure returns (uint256 z) { /// @solidity memory-safe-assembly assembly { let r := shl(7, lt(0xffffffffffffffffffffffffffffffff, x)) r := or(r, shl(6, lt(0xffffffffffffffff, shr(r, x)))) r := or(r, shl(5, lt(0xffffffff, shr(r, x)))) r := or(r, shl(4, lt(0xffff, shr(r, x)))) r := or(r, shl(3, lt(0xff, shr(r, x)))) // Makeshift lookup table to nudge the approximate log2 result. z := div(shl(div(r, 3), shl(lt(0xf, shr(r, x)), 0xf)), xor(7, mod(r, 3))) // Newton-Raphson's. z := div(add(add(div(x, mul(z, z)), z), z), 3) z := div(add(add(div(x, mul(z, z)), z), z), 3) z := div(add(add(div(x, mul(z, z)), z), z), 3) z := div(add(add(div(x, mul(z, z)), z), z), 3) z := div(add(add(div(x, mul(z, z)), z), z), 3) z := div(add(add(div(x, mul(z, z)), z), z), 3) z := div(add(add(div(x, mul(z, z)), z), z), 3) // Round down. z := sub(z, lt(div(x, mul(z, z)), z)) } } /// @dev Returns the square root of `x`, denominated in `WAD`, rounded down. function sqrtWad(uint256 x) internal pure returns (uint256 z) { unchecked { if (x <= type(uint256).max / 10 ** 18) return sqrt(x * 10 ** 18); z = (1 + sqrt(x)) * 10 ** 9; z = (fullMulDivUnchecked(x, 10 ** 18, z) + z) >> 1; } /// @solidity memory-safe-assembly assembly { z := sub(z, gt(999999999999999999, sub(mulmod(z, z, x), 1))) // Round down. } } /// @dev Returns the cube root of `x`, denominated in `WAD`, rounded down. /// Formally verified by xuwinnie: /// https://github.com/vectorized/solady/blob/main/audits/xuwinnie-solady-cbrt-proof.pdf function cbrtWad(uint256 x) internal pure returns (uint256 z) { unchecked { if (x <= type(uint256).max / 10 ** 36) return cbrt(x * 10 ** 36); z = (1 + cbrt(x)) * 10 ** 12; z = (fullMulDivUnchecked(x, 10 ** 36, z * z) + z + z) / 3; } /// @solidity memory-safe-assembly assembly { let p := x for {} 1 {} { if iszero(shr(229, p)) { if iszero(shr(199, p)) { p := mul(p, 100000000000000000) // 10 ** 17. break } p := mul(p, 100000000) // 10 ** 8. break } if iszero(shr(249, p)) { p := mul(p, 100) } break } let t := mulmod(mul(z, z), z, p) z := sub(z, gt(lt(t, shr(1, p)), iszero(t))) // Round down. } } /// @dev Returns the factorial of `x`. function factorial(uint256 x) internal pure returns (uint256 z) { /// @solidity memory-safe-assembly assembly { z := 1 if iszero(lt(x, 58)) { mstore(0x00, 0xaba0f2a2) // `FactorialOverflow()`. revert(0x1c, 0x04) } for {} x { x := sub(x, 1) } { z := mul(z, x) } } } /// @dev Returns the log2 of `x`. /// Equivalent to computing the index of the most significant bit (MSB) of `x`. /// Returns 0 if `x` is zero. function log2(uint256 x) internal pure returns (uint256 r) { /// @solidity memory-safe-assembly assembly { r := shl(7, lt(0xffffffffffffffffffffffffffffffff, x)) r := or(r, shl(6, lt(0xffffffffffffffff, shr(r, x)))) r := or(r, shl(5, lt(0xffffffff, shr(r, x)))) r := or(r, shl(4, lt(0xffff, shr(r, x)))) r := or(r, shl(3, lt(0xff, shr(r, x)))) // forgefmt: disable-next-item r := or(r, byte(and(0x1f, shr(shr(r, x), 0x8421084210842108cc6318c6db6d54be)), 0x0706060506020504060203020504030106050205030304010505030400000000)) } } /// @dev Returns the log2 of `x`, rounded up. /// Returns 0 if `x` is zero. function log2Up(uint256 x) internal pure returns (uint256 r) { r = log2(x); /// @solidity memory-safe-assembly assembly { r := add(r, lt(shl(r, 1), x)) } } /// @dev Returns the log10 of `x`. /// Returns 0 if `x` is zero. function log10(uint256 x) internal pure returns (uint256 r) { /// @solidity memory-safe-assembly assembly { if iszero(lt(x, 100000000000000000000000000000000000000)) { x := div(x, 100000000000000000000000000000000000000) r := 38 } if iszero(lt(x, 100000000000000000000)) { x := div(x, 100000000000000000000) r := add(r, 20) } if iszero(lt(x, 10000000000)) { x := div(x, 10000000000) r := add(r, 10) } if iszero(lt(x, 100000)) { x := div(x, 100000) r := add(r, 5) } r := add(r, add(gt(x, 9), add(gt(x, 99), add(gt(x, 999), gt(x, 9999))))) } } /// @dev Returns the log10 of `x`, rounded up. /// Returns 0 if `x` is zero. function log10Up(uint256 x) internal pure returns (uint256 r) { r = log10(x); /// @solidity memory-safe-assembly assembly { r := add(r, lt(exp(10, r), x)) } } /// @dev Returns the log256 of `x`. /// Returns 0 if `x` is zero. function log256(uint256 x) internal pure returns (uint256 r) { /// @solidity memory-safe-assembly assembly { r := shl(7, lt(0xffffffffffffffffffffffffffffffff, x)) r := or(r, shl(6, lt(0xffffffffffffffff, shr(r, x)))) r := or(r, shl(5, lt(0xffffffff, shr(r, x)))) r := or(r, shl(4, lt(0xffff, shr(r, x)))) r := or(shr(3, r), lt(0xff, shr(r, x))) } } /// @dev Returns the log256 of `x`, rounded up. /// Returns 0 if `x` is zero. function log256Up(uint256 x) internal pure returns (uint256 r) { r = log256(x); /// @solidity memory-safe-assembly assembly { r := add(r, lt(shl(shl(3, r), 1), x)) } } /// @dev Returns the scientific notation format `mantissa * 10 ** exponent` of `x`. /// Useful for compressing prices (e.g. using 25 bit mantissa and 7 bit exponent). function sci(uint256 x) internal pure returns (uint256 mantissa, uint256 exponent) { /// @solidity memory-safe-assembly assembly { mantissa := x if mantissa { if iszero(mod(mantissa, 1000000000000000000000000000000000)) { mantissa := div(mantissa, 1000000000000000000000000000000000) exponent := 33 } if iszero(mod(mantissa, 10000000000000000000)) { mantissa := div(mantissa, 10000000000000000000) exponent := add(exponent, 19) } if iszero(mod(mantissa, 1000000000000)) { mantissa := div(mantissa, 1000000000000) exponent := add(exponent, 12) } if iszero(mod(mantissa, 1000000)) { mantissa := div(mantissa, 1000000) exponent := add(exponent, 6) } if iszero(mod(mantissa, 10000)) { mantissa := div(mantissa, 10000) exponent := add(exponent, 4) } if iszero(mod(mantissa, 100)) { mantissa := div(mantissa, 100) exponent := add(exponent, 2) } if iszero(mod(mantissa, 10)) { mantissa := div(mantissa, 10) exponent := add(exponent, 1) } } } } /// @dev Convenience function for packing `x` into a smaller number using `sci`. /// The `mantissa` will be in bits [7..255] (the upper 249 bits). /// The `exponent` will be in bits [0..6] (the lower 7 bits). /// Use `SafeCastLib` to safely ensure that the `packed` number is small /// enough to fit in the desired unsigned integer type: /// ``` /// uint32 packed = SafeCastLib.toUint32(FixedPointMathLib.packSci(777 ether)); /// ``` function packSci(uint256 x) internal pure returns (uint256 packed) { (x, packed) = sci(x); // Reuse for `mantissa` and `exponent`. /// @solidity memory-safe-assembly assembly { if shr(249, x) { mstore(0x00, 0xce30380c) // `MantissaOverflow()`. revert(0x1c, 0x04) } packed := or(shl(7, x), packed) } } /// @dev Convenience function for unpacking a packed number from `packSci`. function unpackSci(uint256 packed) internal pure returns (uint256 unpacked) { unchecked { unpacked = (packed >> 7) * 10 ** (packed & 0x7f); } } /// @dev Returns the average of `x` and `y`. Rounds towards zero. function avg(uint256 x, uint256 y) internal pure returns (uint256 z) { unchecked { z = (x & y) + ((x ^ y) >> 1); } } /// @dev Returns the average of `x` and `y`. Rounds towards negative infinity. function avg(int256 x, int256 y) internal pure returns (int256 z) { unchecked { z = (x >> 1) + (y >> 1) + (x & y & 1); } } /// @dev Returns the absolute value of `x`. function abs(int256 x) internal pure returns (uint256 z) { unchecked { z = (uint256(x) + uint256(x >> 255)) ^ uint256(x >> 255); } } /// @dev Returns the absolute distance between `x` and `y`. function dist(uint256 x, uint256 y) internal pure returns (uint256 z) { /// @solidity memory-safe-assembly assembly { z := add(xor(sub(0, gt(x, y)), sub(y, x)), gt(x, y)) } } /// @dev Returns the absolute distance between `x` and `y`. function dist(int256 x, int256 y) internal pure returns (uint256 z) { /// @solidity memory-safe-assembly assembly { z := add(xor(sub(0, sgt(x, y)), sub(y, x)), sgt(x, y)) } } /// @dev Returns the minimum of `x` and `y`. function min(uint256 x, uint256 y) internal pure returns (uint256 z) { /// @solidity memory-safe-assembly assembly { z := xor(x, mul(xor(x, y), lt(y, x))) } } /// @dev Returns the minimum of `x` and `y`. function min(int256 x, int256 y) internal pure returns (int256 z) { /// @solidity memory-safe-assembly assembly { z := xor(x, mul(xor(x, y), slt(y, x))) } } /// @dev Returns the maximum of `x` and `y`. function max(uint256 x, uint256 y) internal pure returns (uint256 z) { /// @solidity memory-safe-assembly assembly { z := xor(x, mul(xor(x, y), gt(y, x))) } } /// @dev Returns the maximum of `x` and `y`. function max(int256 x, int256 y) internal pure returns (int256 z) { /// @solidity memory-safe-assembly assembly { z := xor(x, mul(xor(x, y), sgt(y, x))) } } /// @dev Returns `x`, bounded to `minValue` and `maxValue`. function clamp(uint256 x, uint256 minValue, uint256 maxValue) internal pure returns (uint256 z) { /// @solidity memory-safe-assembly assembly { z := xor(x, mul(xor(x, minValue), gt(minValue, x))) z := xor(z, mul(xor(z, maxValue), lt(maxValue, z))) } } /// @dev Returns `x`, bounded to `minValue` and `maxValue`. function clamp(int256 x, int256 minValue, int256 maxValue) internal pure returns (int256 z) { /// @solidity memory-safe-assembly assembly { z := xor(x, mul(xor(x, minValue), sgt(minValue, x))) z := xor(z, mul(xor(z, maxValue), slt(maxValue, z))) } } /// @dev Returns greatest common divisor of `x` and `y`. function gcd(uint256 x, uint256 y) internal pure returns (uint256 z) { /// @solidity memory-safe-assembly assembly { for { z := x } y {} { let t := y y := mod(z, y) z := t } } } /// @dev Returns `a + (b - a) * (t - begin) / (end - begin)`, /// with `t` clamped between `begin` and `end` (inclusive). /// Agnostic to the order of (`a`, `b`) and (`end`, `begin`). /// If `begins == end`, returns `t <= begin ? a : b`. function lerp(uint256 a, uint256 b, uint256 t, uint256 begin, uint256 end) internal pure returns (uint256) { if (begin > end) (t, begin, end) = (~t, ~begin, ~end); if (t <= begin) return a; if (t >= end) return b; unchecked { if (b >= a) return a + fullMulDiv(b - a, t - begin, end - begin); return a - fullMulDiv(a - b, t - begin, end - begin); } } /// @dev Returns `a + (b - a) * (t - begin) / (end - begin)`. /// with `t` clamped between `begin` and `end` (inclusive). /// Agnostic to the order of (`a`, `b`) and (`end`, `begin`). /// If `begins == end`, returns `t <= begin ? a : b`. function lerp(int256 a, int256 b, int256 t, int256 begin, int256 end) internal pure returns (int256) { if (begin > end) (t, begin, end) = (~t, ~begin, ~end); if (t <= begin) return a; if (t >= end) return b; // forgefmt: disable-next-item unchecked { if (b >= a) return int256(uint256(a) + fullMulDiv(uint256(b - a), uint256(t - begin), uint256(end - begin))); return int256(uint256(a) - fullMulDiv(uint256(a - b), uint256(t - begin), uint256(end - begin))); } } /// @dev Returns if `x` is an even number. Some people may need this. function isEven(uint256 x) internal pure returns (bool) { return x & uint256(1) == uint256(0); } /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* RAW NUMBER OPERATIONS */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ /// @dev Returns `x + y`, without checking for overflow. function rawAdd(uint256 x, uint256 y) internal pure returns (uint256 z) { unchecked { z = x + y; } } /// @dev Returns `x + y`, without checking for overflow. function rawAdd(int256 x, int256 y) internal pure returns (int256 z) { unchecked { z = x + y; } } /// @dev Returns `x - y`, without checking for underflow. function rawSub(uint256 x, uint256 y) internal pure returns (uint256 z) { unchecked { z = x - y; } } /// @dev Returns `x - y`, without checking for underflow. function rawSub(int256 x, int256 y) internal pure returns (int256 z) { unchecked { z = x - y; } } /// @dev Returns `x * y`, without checking for overflow. function rawMul(uint256 x, uint256 y) internal pure returns (uint256 z) { unchecked { z = x * y; } } /// @dev Returns `x * y`, without checking for overflow. function rawMul(int256 x, int256 y) internal pure returns (int256 z) { unchecked { z = x * y; } } /// @dev Returns `x / y`, returning 0 if `y` is zero. function rawDiv(uint256 x, uint256 y) internal pure returns (uint256 z) { /// @solidity memory-safe-assembly assembly { z := div(x, y) } } /// @dev Returns `x / y`, returning 0 if `y` is zero. function rawSDiv(int256 x, int256 y) internal pure returns (int256 z) { /// @solidity memory-safe-assembly assembly { z := sdiv(x, y) } } /// @dev Returns `x % y`, returning 0 if `y` is zero. function rawMod(uint256 x, uint256 y) internal pure returns (uint256 z) { /// @solidity memory-safe-assembly assembly { z := mod(x, y) } } /// @dev Returns `x % y`, returning 0 if `y` is zero. function rawSMod(int256 x, int256 y) internal pure returns (int256 z) { /// @solidity memory-safe-assembly assembly { z := smod(x, y) } } /// @dev Returns `(x + y) % d`, return 0 if `d` if zero. function rawAddMod(uint256 x, uint256 y, uint256 d) internal pure returns (uint256 z) { /// @solidity memory-safe-assembly assembly { z := addmod(x, y, d) } } /// @dev Returns `(x * y) % d`, return 0 if `d` if zero. function rawMulMod(uint256 x, uint256 y, uint256 d) internal pure returns (uint256 z) { /// @solidity memory-safe-assembly assembly { z := mulmod(x, y, d) } } }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.13; interface IOracleChainsight { function readAsInt256ByKey(address sender, bytes32 key) external view returns (int256); function readAsInt256WithTimestamp(address sender, bytes32 key) external view returns (int256, uint64); function readAsUint64WithTimestamp(address sender, bytes32 key) external view returns (uint64, uint64); }
// SPDX-License-Identifier: UNLICENSED pragma solidity ^0.8.13; import "@openzeppelin/contracts/utils/Strings.sol"; import {ERC1155} from "@openzeppelin/contracts/token/ERC1155/ERC1155.sol"; import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol"; contract henlocked is ERC1155, Ownable { mapping(uint256 => uint256) public totalSupply; mapping(address => bool) public authorized; // Events event Authorize(address indexed user); event Mint(address indexed user, uint256 indexed strike, uint256 amount); event Burn(address indexed user, uint256 indexed strike, uint256 amount); constructor(string memory uri_) ERC1155(uri_) Ownable(msg.sender) {} // Assumes 100b token supply and price in 1e8 (Chainlink format) function name(uint256 strike) public view virtual returns (string memory) { // strike is in 1e8 format from Chainlink // For 100B supply: // $1.00 (100000000) = 100B mcap // $0.42 (42000000) = 42B mcap // $0.042 (4200000) = 4.2B mcap // $0.0042 (420000) = 420M mcap // Convert to millions by dividing by 1000 // 100000000 / 1000 = 100000 (100b) // 42000000 / 1000 = 42000 (42b) // 4200000 / 1000 = 4200 (4.2b) // 420000 / 1000 = 420 (420m) uint256 mcapInMillions = strike / 1000; // Convert to millions if (mcapInMillions >= 100000) { // 100B+ return string(abi.encodePacked("henlocked@", Strings.toString(mcapInMillions / 100000), "00b")); } else if (mcapInMillions >= 1000) { // 1B to 99.9B uint256 billions = mcapInMillions / 1000; uint256 decimal = (mcapInMillions % 1000) / 100; if (decimal > 0) { return string( abi.encodePacked("henlocked@", Strings.toString(billions), ".", Strings.toString(decimal), "b") ); } return string(abi.encodePacked("henlocked@", Strings.toString(billions), "b")); } else if (mcapInMillions > 0) { // 1M to 999M if (mcapInMillions >= 100) { // No decimals needed return string(abi.encodePacked("henlocked@", Strings.toString(mcapInMillions), "m")); } else { // Add one decimal place for < 100M uint256 whole = mcapInMillions; uint256 decimal = (strike % 1000) / 100; if (decimal > 0) { return string( abi.encodePacked("henlocked@", Strings.toString(whole), ".", Strings.toString(decimal), "m") ); } return string(abi.encodePacked("henlocked@", Strings.toString(whole), "m")); } } else { // Under 1M uint256 mcapInThousands = strike; return string(abi.encodePacked("henlocked@", Strings.toString(mcapInThousands), "k")); } } function symbol(uint256 strike) public view virtual returns (string memory) { return name(strike); } // authorize enables another contract to transfer tokens between accounts. // This is for use by deployed ERC20 tokens. See src/single/HodlToken.sol. function authorize(address operator) public onlyOwner { authorized[operator] = true; emit Authorize(operator); } // This is for use by deployed ERC20 tokens function safeTransferFromHenlocked(address from, address to, uint256 strike, uint256 amount) external { require(authorized[msg.sender], "Not authorized"); uint256[] memory strikes = new uint256[](1); uint256[] memory amounts = new uint256[](1); strikes[0] = strike; amounts[0] = amount; _update(from, to, strikes, amounts); } function mint(address user, uint256 strike, uint256 amount) public onlyOwner { totalSupply[strike] += amount; _mint(user, strike, amount, ""); emit Mint(user, strike, amount); } function burn(address user, uint256 strike, uint256 amount) public onlyOwner { totalSupply[strike] -= amount; _burn(user, strike, amount); emit Burn(user, strike, amount); } }
// SPDX-License-Identifier: UNLICENSED pragma solidity ^0.8.13; import "@openzeppelin/contracts/utils/Strings.sol"; import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol"; import {henlocked} from "../multi/henlocked.sol"; // HodlToken is an ERC20 wrapper on top of the ERC1155 HodlMultiToken. It // represents a token at a particular strike, and can be composed inside defi // applications that expect ERC20 tokens. For example, it can be used to create // a swap liquidity pool in protocols that operate on ERC20 tokens. contract henlockedToken is IERC20 { mapping(address => mapping(address => uint256)) private _allowances; henlocked public immutable hodlMulti; uint256 public immutable strike; string private _name; string private _symbol; constructor(address hodlMulti_, uint64 strike_) { require(hodlMulti_ != address(0)); hodlMulti = henlocked(hodlMulti_); strike = strike_; _name = hodlMulti.name(strike); _symbol = hodlMulti.symbol(strike); } function name() public view virtual returns (string memory) { return _name; } function symbol() public view virtual returns (string memory) { return _symbol; } function decimals() public view virtual returns (uint8) { return 18; } function totalSupply() public view returns (uint256) { return hodlMulti.totalSupply(strike); } function balanceOf(address user) public view returns (uint256) { return hodlMulti.balanceOf(user, strike); } function transfer(address to, uint256 amount) public returns (bool) { hodlMulti.safeTransferFromHenlocked(msg.sender, to, strike, amount); emit Transfer(msg.sender, to, amount); return true; } function allowance(address owner, address spender) public view returns (uint256) { return _allowances[owner][spender]; } function approve(address spender, uint256 amount) public returns (bool) { require(spender != address(0), "approve zero address"); _allowances[msg.sender][spender] = amount; emit Approval(msg.sender, spender, amount); return true; } function transferFrom(address from, address to, uint256 amount) public returns (bool) { require(_allowances[from][msg.sender] >= amount, "not authorized"); if (_allowances[from][msg.sender] != type(uint256).max) { _allowances[from][msg.sender] -= amount; } hodlMulti.safeTransferFromHenlocked(from, to, strike, amount); emit Transfer(from, to, amount); return true; } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v5.1.0) (interfaces/IERC1363.sol) pragma solidity ^0.8.20; import {IERC20} from "./IERC20.sol"; import {IERC165} from "./IERC165.sol"; /** * @title IERC1363 * @dev Interface of the ERC-1363 standard as defined in the https://eips.ethereum.org/EIPS/eip-1363[ERC-1363]. * * Defines an extension interface for ERC-20 tokens that supports executing code on a recipient contract * after `transfer` or `transferFrom`, or code on a spender contract after `approve`, in a single transaction. */ interface IERC1363 is IERC20, IERC165 { /* * Note: the ERC-165 identifier for this interface is 0xb0202a11. * 0xb0202a11 === * bytes4(keccak256('transferAndCall(address,uint256)')) ^ * bytes4(keccak256('transferAndCall(address,uint256,bytes)')) ^ * bytes4(keccak256('transferFromAndCall(address,address,uint256)')) ^ * bytes4(keccak256('transferFromAndCall(address,address,uint256,bytes)')) ^ * bytes4(keccak256('approveAndCall(address,uint256)')) ^ * bytes4(keccak256('approveAndCall(address,uint256,bytes)')) */ /** * @dev Moves a `value` amount of tokens from the caller's account to `to` * and then calls {IERC1363Receiver-onTransferReceived} on `to`. * @param to The address which you want to transfer to. * @param value The amount of tokens to be transferred. * @return A boolean value indicating whether the operation succeeded unless throwing. */ function transferAndCall(address to, uint256 value) external returns (bool); /** * @dev Moves a `value` amount of tokens from the caller's account to `to` * and then calls {IERC1363Receiver-onTransferReceived} on `to`. * @param to The address which you want to transfer to. * @param value The amount of tokens to be transferred. * @param data Additional data with no specified format, sent in call to `to`. * @return A boolean value indicating whether the operation succeeded unless throwing. */ function transferAndCall(address to, uint256 value, bytes calldata data) external returns (bool); /** * @dev Moves a `value` amount of tokens from `from` to `to` using the allowance mechanism * and then calls {IERC1363Receiver-onTransferReceived} on `to`. * @param from The address which you want to send tokens from. * @param to The address which you want to transfer to. * @param value The amount of tokens to be transferred. * @return A boolean value indicating whether the operation succeeded unless throwing. */ function transferFromAndCall(address from, address to, uint256 value) external returns (bool); /** * @dev Moves a `value` amount of tokens from `from` to `to` using the allowance mechanism * and then calls {IERC1363Receiver-onTransferReceived} on `to`. * @param from The address which you want to send tokens from. * @param to The address which you want to transfer to. * @param value The amount of tokens to be transferred. * @param data Additional data with no specified format, sent in call to `to`. * @return A boolean value indicating whether the operation succeeded unless throwing. */ function transferFromAndCall(address from, address to, uint256 value, bytes calldata data) external returns (bool); /** * @dev Sets a `value` amount of tokens as the allowance of `spender` over the * caller's tokens and then calls {IERC1363Spender-onApprovalReceived} on `spender`. * @param spender The address which will spend the funds. * @param value The amount of tokens to be spent. * @return A boolean value indicating whether the operation succeeded unless throwing. */ function approveAndCall(address spender, uint256 value) external returns (bool); /** * @dev Sets a `value` amount of tokens as the allowance of `spender` over the * caller's tokens and then calls {IERC1363Spender-onApprovalReceived} on `spender`. * @param spender The address which will spend the funds. * @param value The amount of tokens to be spent. * @param data Additional data with no specified format, sent in call to `spender`. * @return A boolean value indicating whether the operation succeeded unless throwing. */ function approveAndCall(address spender, uint256 value, bytes calldata data) external returns (bool); }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v5.1.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, ) = recipient.call{value: amount}(""); if (!success) { revert Errors.FailedCall(); } } /** * @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") { let returndata_size := mload(returndata) revert(add(32, returndata), returndata_size) } } else { revert Errors.FailedCall(); } } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v5.0.1) (utils/Context.sol) pragma solidity ^0.8.20; /** * @dev Provides information about the current execution context, including the * sender of the transaction and its data. While these are generally available * via msg.sender and msg.data, they should not be accessed in such a direct * manner, since when dealing with meta-transactions the account sending and * paying for execution may not be the actual sender (as far as an application * is concerned). * * This contract is only required for intermediate, library-like contracts. */ abstract contract Context { function _msgSender() internal view virtual returns (address) { return msg.sender; } function _msgData() internal view virtual returns (bytes calldata) { return msg.data; } function _contextSuffixLength() internal view virtual returns (uint256) { return 0; } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v5.1.0) (utils/Strings.sol) pragma solidity ^0.8.20; import {Math} from "./math/Math.sol"; import {SignedMath} from "./math/SignedMath.sol"; /** * @dev String operations. */ library Strings { bytes16 private constant HEX_DIGITS = "0123456789abcdef"; uint8 private constant ADDRESS_LENGTH = 20; /** * @dev The `value` string doesn't fit in the specified `length`. */ error StringsInsufficientHexLength(uint256 value, uint256 length); /** * @dev Converts a `uint256` to its ASCII `string` decimal representation. */ function toString(uint256 value) internal pure returns (string memory) { unchecked { uint256 length = Math.log10(value) + 1; string memory buffer = new string(length); uint256 ptr; assembly ("memory-safe") { ptr := add(buffer, add(32, length)) } while (true) { ptr--; assembly ("memory-safe") { mstore8(ptr, byte(mod(value, 10), HEX_DIGITS)) } value /= 10; if (value == 0) break; } return buffer; } } /** * @dev Converts a `int256` to its ASCII `string` decimal representation. */ function toStringSigned(int256 value) internal pure returns (string memory) { return string.concat(value < 0 ? "-" : "", toString(SignedMath.abs(value))); } /** * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation. */ function toHexString(uint256 value) internal pure returns (string memory) { unchecked { return toHexString(value, Math.log256(value) + 1); } } /** * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length. */ function toHexString(uint256 value, uint256 length) internal pure returns (string memory) { uint256 localValue = value; bytes memory buffer = new bytes(2 * length + 2); buffer[0] = "0"; buffer[1] = "x"; for (uint256 i = 2 * length + 1; i > 1; --i) { buffer[i] = HEX_DIGITS[localValue & 0xf]; localValue >>= 4; } if (localValue != 0) { revert StringsInsufficientHexLength(value, length); } return string(buffer); } /** * @dev Converts an `address` with fixed length of 20 bytes to its not checksummed ASCII `string` hexadecimal * representation. */ function toHexString(address addr) internal pure returns (string memory) { return toHexString(uint256(uint160(addr)), ADDRESS_LENGTH); } /** * @dev Converts an `address` with fixed length of 20 bytes to its checksummed ASCII `string` hexadecimal * representation, according to EIP-55. */ function toChecksumHexString(address addr) internal pure returns (string memory) { bytes memory buffer = bytes(toHexString(addr)); // hash the hex part of buffer (skip length + 2 bytes, length 40) uint256 hashValue; assembly ("memory-safe") { hashValue := shr(96, keccak256(add(buffer, 0x22), 40)) } for (uint256 i = 41; i > 1; --i) { // possible values for buffer[i] are 48 (0) to 57 (9) and 97 (a) to 102 (f) if (hashValue & 0xf > 7 && uint8(buffer[i]) > 96) { // case shift by xoring with 0x20 buffer[i] ^= 0x20; } hashValue >>= 4; } return string(buffer); } /** * @dev Returns true if the two strings are equal. */ function equal(string memory a, string memory b) internal pure returns (bool) { return bytes(a).length == bytes(b).length && keccak256(bytes(a)) == keccak256(bytes(b)); } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v5.1.0) (token/ERC1155/ERC1155.sol) pragma solidity ^0.8.20; import {IERC1155} from "./IERC1155.sol"; import {IERC1155MetadataURI} from "./extensions/IERC1155MetadataURI.sol"; import {ERC1155Utils} from "./utils/ERC1155Utils.sol"; import {Context} from "../../utils/Context.sol"; import {IERC165, ERC165} from "../../utils/introspection/ERC165.sol"; import {Arrays} from "../../utils/Arrays.sol"; import {IERC1155Errors} from "../../interfaces/draft-IERC6093.sol"; /** * @dev Implementation of the basic standard multi-token. * See https://eips.ethereum.org/EIPS/eip-1155 * Originally based on code by Enjin: https://github.com/enjin/erc-1155 */ abstract contract ERC1155 is Context, ERC165, IERC1155, IERC1155MetadataURI, IERC1155Errors { using Arrays for uint256[]; using Arrays for address[]; mapping(uint256 id => mapping(address account => uint256)) private _balances; mapping(address account => mapping(address operator => bool)) private _operatorApprovals; // Used as the URI for all token types by relying on ID substitution, e.g. https://token-cdn-domain/{id}.json string private _uri; /** * @dev See {_setURI}. */ constructor(string memory uri_) { _setURI(uri_); } /** * @dev See {IERC165-supportsInterface}. */ function supportsInterface(bytes4 interfaceId) public view virtual override(ERC165, IERC165) returns (bool) { return interfaceId == type(IERC1155).interfaceId || interfaceId == type(IERC1155MetadataURI).interfaceId || super.supportsInterface(interfaceId); } /** * @dev See {IERC1155MetadataURI-uri}. * * This implementation returns the same URI for *all* token types. It relies * on the token type ID substitution mechanism * https://eips.ethereum.org/EIPS/eip-1155#metadata[defined in the ERC]. * * Clients calling this function must replace the `\{id\}` substring with the * actual token type ID. */ function uri(uint256 /* id */) public view virtual returns (string memory) { return _uri; } /** * @dev See {IERC1155-balanceOf}. */ function balanceOf(address account, uint256 id) public view virtual returns (uint256) { return _balances[id][account]; } /** * @dev See {IERC1155-balanceOfBatch}. * * Requirements: * * - `accounts` and `ids` must have the same length. */ function balanceOfBatch( address[] memory accounts, uint256[] memory ids ) public view virtual returns (uint256[] memory) { if (accounts.length != ids.length) { revert ERC1155InvalidArrayLength(ids.length, accounts.length); } uint256[] memory batchBalances = new uint256[](accounts.length); for (uint256 i = 0; i < accounts.length; ++i) { batchBalances[i] = balanceOf(accounts.unsafeMemoryAccess(i), ids.unsafeMemoryAccess(i)); } return batchBalances; } /** * @dev See {IERC1155-setApprovalForAll}. */ function setApprovalForAll(address operator, bool approved) public virtual { _setApprovalForAll(_msgSender(), operator, approved); } /** * @dev See {IERC1155-isApprovedForAll}. */ function isApprovedForAll(address account, address operator) public view virtual returns (bool) { return _operatorApprovals[account][operator]; } /** * @dev See {IERC1155-safeTransferFrom}. */ function safeTransferFrom(address from, address to, uint256 id, uint256 value, bytes memory data) public virtual { address sender = _msgSender(); if (from != sender && !isApprovedForAll(from, sender)) { revert ERC1155MissingApprovalForAll(sender, from); } _safeTransferFrom(from, to, id, value, data); } /** * @dev See {IERC1155-safeBatchTransferFrom}. */ function safeBatchTransferFrom( address from, address to, uint256[] memory ids, uint256[] memory values, bytes memory data ) public virtual { address sender = _msgSender(); if (from != sender && !isApprovedForAll(from, sender)) { revert ERC1155MissingApprovalForAll(sender, from); } _safeBatchTransferFrom(from, to, ids, values, data); } /** * @dev Transfers a `value` amount of tokens of type `id` from `from` to `to`. Will mint (or burn) if `from` * (or `to`) is the zero address. * * Emits a {TransferSingle} event if the arrays contain one element, and {TransferBatch} otherwise. * * Requirements: * * - If `to` refers to a smart contract, it must implement either {IERC1155Receiver-onERC1155Received} * or {IERC1155Receiver-onERC1155BatchReceived} and return the acceptance magic value. * - `ids` and `values` must have the same length. * * NOTE: The ERC-1155 acceptance check is not performed in this function. See {_updateWithAcceptanceCheck} instead. */ function _update(address from, address to, uint256[] memory ids, uint256[] memory values) internal virtual { if (ids.length != values.length) { revert ERC1155InvalidArrayLength(ids.length, values.length); } address operator = _msgSender(); for (uint256 i = 0; i < ids.length; ++i) { uint256 id = ids.unsafeMemoryAccess(i); uint256 value = values.unsafeMemoryAccess(i); if (from != address(0)) { uint256 fromBalance = _balances[id][from]; if (fromBalance < value) { revert ERC1155InsufficientBalance(from, fromBalance, value, id); } unchecked { // Overflow not possible: value <= fromBalance _balances[id][from] = fromBalance - value; } } if (to != address(0)) { _balances[id][to] += value; } } if (ids.length == 1) { uint256 id = ids.unsafeMemoryAccess(0); uint256 value = values.unsafeMemoryAccess(0); emit TransferSingle(operator, from, to, id, value); } else { emit TransferBatch(operator, from, to, ids, values); } } /** * @dev Version of {_update} that performs the token acceptance check by calling * {IERC1155Receiver-onERC1155Received} or {IERC1155Receiver-onERC1155BatchReceived} on the receiver address if it * contains code (eg. is a smart contract at the moment of execution). * * IMPORTANT: Overriding this function is discouraged because it poses a reentrancy risk from the receiver. So any * update to the contract state after this function would break the check-effect-interaction pattern. Consider * overriding {_update} instead. */ function _updateWithAcceptanceCheck( address from, address to, uint256[] memory ids, uint256[] memory values, bytes memory data ) internal virtual { _update(from, to, ids, values); if (to != address(0)) { address operator = _msgSender(); if (ids.length == 1) { uint256 id = ids.unsafeMemoryAccess(0); uint256 value = values.unsafeMemoryAccess(0); ERC1155Utils.checkOnERC1155Received(operator, from, to, id, value, data); } else { ERC1155Utils.checkOnERC1155BatchReceived(operator, from, to, ids, values, data); } } } /** * @dev Transfers a `value` tokens of token type `id` from `from` to `to`. * * Emits a {TransferSingle} event. * * Requirements: * * - `to` cannot be the zero address. * - `from` must have a balance of tokens of type `id` of at least `value` amount. * - If `to` refers to a smart contract, it must implement {IERC1155Receiver-onERC1155Received} and return the * acceptance magic value. */ function _safeTransferFrom(address from, address to, uint256 id, uint256 value, bytes memory data) internal { if (to == address(0)) { revert ERC1155InvalidReceiver(address(0)); } if (from == address(0)) { revert ERC1155InvalidSender(address(0)); } (uint256[] memory ids, uint256[] memory values) = _asSingletonArrays(id, value); _updateWithAcceptanceCheck(from, to, ids, values, data); } /** * @dev xref:ROOT:erc1155.adoc#batch-operations[Batched] version of {_safeTransferFrom}. * * Emits a {TransferBatch} event. * * Requirements: * * - If `to` refers to a smart contract, it must implement {IERC1155Receiver-onERC1155BatchReceived} and return the * acceptance magic value. * - `ids` and `values` must have the same length. */ function _safeBatchTransferFrom( address from, address to, uint256[] memory ids, uint256[] memory values, bytes memory data ) internal { if (to == address(0)) { revert ERC1155InvalidReceiver(address(0)); } if (from == address(0)) { revert ERC1155InvalidSender(address(0)); } _updateWithAcceptanceCheck(from, to, ids, values, data); } /** * @dev Sets a new URI for all token types, by relying on the token type ID * substitution mechanism * https://eips.ethereum.org/EIPS/eip-1155#metadata[defined in the ERC]. * * By this mechanism, any occurrence of the `\{id\}` substring in either the * URI or any of the values in the JSON file at said URI will be replaced by * clients with the token type ID. * * For example, the `https://token-cdn-domain/\{id\}.json` URI would be * interpreted by clients as * `https://token-cdn-domain/000000000000000000000000000000000000000000000000000000000004cce0.json` * for token type ID 0x4cce0. * * See {uri}. * * Because these URIs cannot be meaningfully represented by the {URI} event, * this function emits no events. */ function _setURI(string memory newuri) internal virtual { _uri = newuri; } /** * @dev Creates a `value` amount of tokens of type `id`, and assigns them to `to`. * * Emits a {TransferSingle} event. * * Requirements: * * - `to` cannot be the zero address. * - If `to` refers to a smart contract, it must implement {IERC1155Receiver-onERC1155Received} and return the * acceptance magic value. */ function _mint(address to, uint256 id, uint256 value, bytes memory data) internal { if (to == address(0)) { revert ERC1155InvalidReceiver(address(0)); } (uint256[] memory ids, uint256[] memory values) = _asSingletonArrays(id, value); _updateWithAcceptanceCheck(address(0), to, ids, values, data); } /** * @dev xref:ROOT:erc1155.adoc#batch-operations[Batched] version of {_mint}. * * Emits a {TransferBatch} event. * * Requirements: * * - `ids` and `values` must have the same length. * - `to` cannot be the zero address. * - If `to` refers to a smart contract, it must implement {IERC1155Receiver-onERC1155BatchReceived} and return the * acceptance magic value. */ function _mintBatch(address to, uint256[] memory ids, uint256[] memory values, bytes memory data) internal { if (to == address(0)) { revert ERC1155InvalidReceiver(address(0)); } _updateWithAcceptanceCheck(address(0), to, ids, values, data); } /** * @dev Destroys a `value` amount of tokens of type `id` from `from` * * Emits a {TransferSingle} event. * * Requirements: * * - `from` cannot be the zero address. * - `from` must have at least `value` amount of tokens of type `id`. */ function _burn(address from, uint256 id, uint256 value) internal { if (from == address(0)) { revert ERC1155InvalidSender(address(0)); } (uint256[] memory ids, uint256[] memory values) = _asSingletonArrays(id, value); _updateWithAcceptanceCheck(from, address(0), ids, values, ""); } /** * @dev xref:ROOT:erc1155.adoc#batch-operations[Batched] version of {_burn}. * * Emits a {TransferBatch} event. * * Requirements: * * - `from` cannot be the zero address. * - `from` must have at least `value` amount of tokens of type `id`. * - `ids` and `values` must have the same length. */ function _burnBatch(address from, uint256[] memory ids, uint256[] memory values) internal { if (from == address(0)) { revert ERC1155InvalidSender(address(0)); } _updateWithAcceptanceCheck(from, address(0), ids, values, ""); } /** * @dev Approve `operator` to operate on all of `owner` tokens * * Emits an {ApprovalForAll} event. * * Requirements: * * - `operator` cannot be the zero address. */ function _setApprovalForAll(address owner, address operator, bool approved) internal virtual { if (operator == address(0)) { revert ERC1155InvalidOperator(address(0)); } _operatorApprovals[owner][operator] = approved; emit ApprovalForAll(owner, operator, approved); } /** * @dev Creates an array in memory with only one value for each of the elements provided. */ function _asSingletonArrays( uint256 element1, uint256 element2 ) private pure returns (uint256[] memory array1, uint256[] memory array2) { assembly ("memory-safe") { // Load the free memory pointer array1 := mload(0x40) // Set array length to 1 mstore(array1, 1) // Store the single element at the next word after the length (where content starts) mstore(add(array1, 0x20), element1) // Repeat for next array locating it right after the first array array2 := add(array1, 0x40) mstore(array2, 1) mstore(add(array2, 0x20), element2) // Update the free memory pointer by pointing after the second array mstore(0x40, add(array2, 0x40)) } } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v5.0.0) (interfaces/IERC20.sol) pragma solidity ^0.8.20; import {IERC20} from "../token/ERC20/IERC20.sol";
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v5.0.0) (interfaces/IERC165.sol) pragma solidity ^0.8.20; import {IERC165} from "../utils/introspection/IERC165.sol";
// 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/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 Returns the addition of two unsigned integers, with an success flag (no overflow). */ function tryAdd(uint256 a, uint256 b) internal pure returns (bool success, uint256 result) { unchecked { uint256 c = a + b; if (c < a) return (false, 0); return (true, c); } } /** * @dev Returns the subtraction of two unsigned integers, with an success flag (no overflow). */ function trySub(uint256 a, uint256 b) internal pure returns (bool success, uint256 result) { unchecked { if (b > a) return (false, 0); return (true, a - b); } } /** * @dev Returns the multiplication of two unsigned integers, with an success flag (no overflow). */ function tryMul(uint256 a, uint256 b) internal pure returns (bool success, uint256 result) { unchecked { // Gas optimization: this is cheaper than requiring 'a' not being zero, but the // benefit is lost if 'b' is also tested. // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 if (a == 0) return (true, 0); uint256 c = a * b; if (c / a != b) return (false, 0); return (true, c); } } /** * @dev Returns the division of two unsigned integers, with a success flag (no division by zero). */ function tryDiv(uint256 a, uint256 b) internal pure returns (bool success, uint256 result) { unchecked { if (b == 0) return (false, 0); return (true, 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 { if (b == 0) return (false, 0); return (true, a % b); } } /** * @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 { // 512-bit multiply [prod1 prod0] = x * y. Compute the product mod 2²⁵⁶ and mod 2²⁵⁶ - 1, then use // the Chinese Remainder Theorem to reconstruct the 512 bit result. The result is stored in two 256 // variables such that product = prod1 * 2²⁵⁶ + prod0. uint256 prod0 = x * y; // Least significant 256 bits of the product uint256 prod1; // Most significant 256 bits of the product assembly { let mm := mulmod(x, y, not(0)) prod1 := sub(sub(mm, prod0), lt(mm, prod0)) } // Handle non-overflow cases, 256 by 256 division. if (prod1 == 0) { // Solidity will revert if denominator == 0, unlike the div opcode on its own. // The surrounding unchecked block does not change this fact. // See https://docs.soliditylang.org/en/latest/control-structures.html#checked-or-unchecked-arithmetic. return prod0 / denominator; } // Make sure the result is less than 2²⁵⁶. Also prevents denominator == 0. if (denominator <= prod1) { Panic.panic(ternary(denominator == 0, Panic.DIVISION_BY_ZERO, Panic.UNDER_OVERFLOW)); } /////////////////////////////////////////////// // 512 by 256 division. /////////////////////////////////////////////// // Make division exact by subtracting the remainder from [prod1 prod0]. uint256 remainder; assembly { // Compute remainder using mulmod. remainder := mulmod(x, y, denominator) // Subtract 256 bit number from 512 bit number. prod1 := sub(prod1, gt(remainder, prod0)) prod0 := sub(prod0, remainder) } // Factor powers of two out of denominator and compute largest power of two divisor of denominator. // Always >= 1. See https://cs.stackexchange.com/q/138556/92363. uint256 twos = denominator & (0 - denominator); assembly { // Divide denominator by twos. denominator := div(denominator, twos) // Divide [prod1 prod0] by twos. prod0 := div(prod0, twos) // Flip twos such that it is 2²⁵⁶ / twos. If twos is zero, then it becomes one. twos := add(div(sub(0, twos), twos), 1) } // Shift in bits from prod1 into prod0. prod0 |= prod1 * twos; // Invert denominator mod 2²⁵⁶. Now that denominator is an odd number, it has an inverse modulo 2²⁵⁶ such // that denominator * inv ≡ 1 mod 2²⁵⁶. Compute the inverse by starting with a seed that is correct for // four bits. That is, denominator * inv ≡ 1 mod 2⁴. uint256 inverse = (3 * denominator) ^ 2; // Use the Newton-Raphson iteration to improve the precision. Thanks to Hensel's lifting lemma, this also // works in modular arithmetic, doubling the correct bits in each step. inverse *= 2 - denominator * inverse; // inverse mod 2⁸ inverse *= 2 - denominator * inverse; // inverse mod 2¹⁶ inverse *= 2 - denominator * inverse; // inverse mod 2³² inverse *= 2 - denominator * inverse; // inverse mod 2⁶⁴ inverse *= 2 - denominator * inverse; // inverse mod 2¹²⁸ inverse *= 2 - denominator * inverse; // inverse mod 2²⁵⁶ // 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²⁵⁶. Since the preconditions guarantee that the outcome is // less than 2²⁵⁶, this is the final result. We don't need to compute the high bits of the result and prod1 // is no longer required. result = prod0 * inverse; return result; } } /** * @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 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 `ε_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¹²⁸)² = 2²⁵⁶` 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 ε_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 ε_n ≤ 2**(e-2). // This is going to be our x_0 (and ε_0) xn = (3 * xn) >> 1; // ε_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_n⁴ + 2 * a * x_n² + a²) / (4 * x_n²) - a // = (x_n⁴ + 2 * a * x_n² + a² - 4 * a * x_n²) / (4 * x_n²) // = (x_n⁴ - 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: // ε_{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) | // = | ε_n² / (2 * x_n) | // = ε_n² / | (2 * x_n) | // // For the first iteration, we have a special case where x_0 is known: // ε_1 = ε_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: // ε_{n+1} = ε_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; // ε_1 := | x_1 - sqrt(a) | ≤ 2**(e-4.5) -- special case, see above xn = (xn + a / xn) >> 1; // ε_2 := | x_2 - sqrt(a) | ≤ 2**(e-9) -- general case with k = 4.5 xn = (xn + a / xn) >> 1; // ε_3 := | x_3 - sqrt(a) | ≤ 2**(e-18) -- general case with k = 9 xn = (xn + a / xn) >> 1; // ε_4 := | x_4 - sqrt(a) | ≤ 2**(e-36) -- general case with k = 18 xn = (xn + a / xn) >> 1; // ε_5 := | x_5 - sqrt(a) | ≤ 2**(e-72) -- general case with k = 36 xn = (xn + a / xn) >> 1; // ε_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 // ε_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 value) internal pure returns (uint256) { uint256 result = 0; uint256 exp; unchecked { exp = 128 * SafeCast.toUint(value > (1 << 128) - 1); value >>= exp; result += exp; exp = 64 * SafeCast.toUint(value > (1 << 64) - 1); value >>= exp; result += exp; exp = 32 * SafeCast.toUint(value > (1 << 32) - 1); value >>= exp; result += exp; exp = 16 * SafeCast.toUint(value > (1 << 16) - 1); value >>= exp; result += exp; exp = 8 * SafeCast.toUint(value > (1 << 8) - 1); value >>= exp; result += exp; exp = 4 * SafeCast.toUint(value > (1 << 4) - 1); value >>= exp; result += exp; exp = 2 * SafeCast.toUint(value > (1 << 2) - 1); value >>= exp; result += exp; result += SafeCast.toUint(value > 1); } return result; } /** * @dev Return the log in base 2, following the selected rounding direction, of a positive value. * Returns 0 if given 0. */ function log2(uint256 value, Rounding rounding) internal pure returns (uint256) { unchecked { uint256 result = log2(value); return result + 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 value) internal pure returns (uint256) { uint256 result = 0; uint256 isGt; unchecked { isGt = SafeCast.toUint(value > (1 << 128) - 1); value >>= isGt * 128; result += isGt * 16; isGt = SafeCast.toUint(value > (1 << 64) - 1); value >>= isGt * 64; result += isGt * 8; isGt = SafeCast.toUint(value > (1 << 32) - 1); value >>= isGt * 32; result += isGt * 4; isGt = SafeCast.toUint(value > (1 << 16) - 1); value >>= isGt * 16; result += isGt * 2; result += SafeCast.toUint(value > (1 << 8) - 1); } return result; } /** * @dev Return the log in base 256, following the selected rounding direction, of a positive value. * Returns 0 if given 0. */ function log256(uint256 value, Rounding rounding) internal pure returns (uint256) { unchecked { uint256 result = log256(value); return result + 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/SignedMath.sol) pragma solidity ^0.8.20; import {SafeCast} from "./SafeCast.sol"; /** * @dev Standard signed math utilities missing in the Solidity language. */ library SignedMath { /** * @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, int256 a, int256 b) internal pure returns (int256) { unchecked { // branchless ternary works because: // b ^ (a ^ b) == a // b ^ 0 == b return b ^ ((a ^ b) * int256(SafeCast.toUint(condition))); } } /** * @dev Returns the largest of two signed numbers. */ function max(int256 a, int256 b) internal pure returns (int256) { return ternary(a > b, a, b); } /** * @dev Returns the smallest of two signed numbers. */ function min(int256 a, int256 b) internal pure returns (int256) { return ternary(a < b, a, b); } /** * @dev Returns the average of two signed numbers without overflow. * The result is rounded towards zero. */ function average(int256 a, int256 b) internal pure returns (int256) { // Formula from the book "Hacker's Delight" int256 x = (a & b) + ((a ^ b) >> 1); return x + (int256(uint256(x) >> 255) & (a ^ b)); } /** * @dev Returns the absolute unsigned value of a signed value. */ function abs(int256 n) internal pure returns (uint256) { unchecked { // Formula from the "Bit Twiddling Hacks" by Sean Eron Anderson. // Since `n` is a signed integer, the generated bytecode will use the SAR opcode to perform the right shift, // taking advantage of the most significant (or "sign" bit) in two's complement representation. // This opcode adds new most significant bits set to the value of the previous most significant bit. As a result, // the mask will either be `bytes32(0)` (if n is positive) or `~bytes32(0)` (if n is negative). int256 mask = n >> 255; // A `bytes32(0)` mask leaves the input unchanged, while a `~bytes32(0)` mask complements it. return uint256((n + mask) ^ mask); } } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v5.1.0) (token/ERC1155/IERC1155.sol) pragma solidity ^0.8.20; import {IERC165} from "../../utils/introspection/IERC165.sol"; /** * @dev Required interface of an ERC-1155 compliant contract, as defined in the * https://eips.ethereum.org/EIPS/eip-1155[ERC]. */ interface IERC1155 is IERC165 { /** * @dev Emitted when `value` amount of tokens of type `id` are transferred from `from` to `to` by `operator`. */ event TransferSingle(address indexed operator, address indexed from, address indexed to, uint256 id, uint256 value); /** * @dev Equivalent to multiple {TransferSingle} events, where `operator`, `from` and `to` are the same for all * transfers. */ event TransferBatch( address indexed operator, address indexed from, address indexed to, uint256[] ids, uint256[] values ); /** * @dev Emitted when `account` grants or revokes permission to `operator` to transfer their tokens, according to * `approved`. */ event ApprovalForAll(address indexed account, address indexed operator, bool approved); /** * @dev Emitted when the URI for token type `id` changes to `value`, if it is a non-programmatic URI. * * If an {URI} event was emitted for `id`, the standard * https://eips.ethereum.org/EIPS/eip-1155#metadata-extensions[guarantees] that `value` will equal the value * returned by {IERC1155MetadataURI-uri}. */ event URI(string value, uint256 indexed id); /** * @dev Returns the value of tokens of token type `id` owned by `account`. */ function balanceOf(address account, uint256 id) external view returns (uint256); /** * @dev xref:ROOT:erc1155.adoc#batch-operations[Batched] version of {balanceOf}. * * Requirements: * * - `accounts` and `ids` must have the same length. */ function balanceOfBatch( address[] calldata accounts, uint256[] calldata ids ) external view returns (uint256[] memory); /** * @dev Grants or revokes permission to `operator` to transfer the caller's tokens, according to `approved`, * * Emits an {ApprovalForAll} event. * * Requirements: * * - `operator` cannot be the zero address. */ function setApprovalForAll(address operator, bool approved) external; /** * @dev Returns true if `operator` is approved to transfer ``account``'s tokens. * * See {setApprovalForAll}. */ function isApprovedForAll(address account, address operator) external view returns (bool); /** * @dev Transfers a `value` amount of tokens of type `id` from `from` to `to`. * * WARNING: This function can potentially allow a reentrancy attack when transferring tokens * to an untrusted contract, when invoking {onERC1155Received} on the receiver. * Ensure to follow the checks-effects-interactions pattern and consider employing * reentrancy guards when interacting with untrusted contracts. * * Emits a {TransferSingle} event. * * Requirements: * * - `to` cannot be the zero address. * - If the caller is not `from`, it must have been approved to spend ``from``'s tokens via {setApprovalForAll}. * - `from` must have a balance of tokens of type `id` of at least `value` amount. * - If `to` refers to a smart contract, it must implement {IERC1155Receiver-onERC1155Received} and return the * acceptance magic value. */ function safeTransferFrom(address from, address to, uint256 id, uint256 value, bytes calldata data) external; /** * @dev xref:ROOT:erc1155.adoc#batch-operations[Batched] version of {safeTransferFrom}. * * WARNING: This function can potentially allow a reentrancy attack when transferring tokens * to an untrusted contract, when invoking {onERC1155BatchReceived} on the receiver. * Ensure to follow the checks-effects-interactions pattern and consider employing * reentrancy guards when interacting with untrusted contracts. * * Emits either a {TransferSingle} or a {TransferBatch} event, depending on the length of the array arguments. * * Requirements: * * - `ids` and `values` must have the same length. * - If `to` refers to a smart contract, it must implement {IERC1155Receiver-onERC1155BatchReceived} and return the * acceptance magic value. */ function safeBatchTransferFrom( address from, address to, uint256[] calldata ids, uint256[] calldata values, bytes calldata data ) external; }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v5.1.0) (token/ERC1155/extensions/IERC1155MetadataURI.sol) pragma solidity ^0.8.20; import {IERC1155} from "../IERC1155.sol"; /** * @dev Interface of the optional ERC1155MetadataExtension interface, as defined * in the https://eips.ethereum.org/EIPS/eip-1155#metadata-extensions[ERC]. */ interface IERC1155MetadataURI is IERC1155 { /** * @dev Returns the URI for token type `id`. * * If the `\{id\}` substring is present in the URI, it must be replaced by * clients with the actual token type ID. */ function uri(uint256 id) external view returns (string memory); }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v5.1.0) (token/ERC1155/utils/ERC1155Utils.sol) pragma solidity ^0.8.20; import {IERC1155Receiver} from "../IERC1155Receiver.sol"; import {IERC1155Errors} from "../../../interfaces/draft-IERC6093.sol"; /** * @dev Library that provide common ERC-1155 utility functions. * * See https://eips.ethereum.org/EIPS/eip-1155[ERC-1155]. * * _Available since v5.1._ */ library ERC1155Utils { /** * @dev Performs an acceptance check for the provided `operator` by calling {IERC1155-onERC1155Received} * on the `to` address. The `operator` is generally the address that initiated the token transfer (i.e. `msg.sender`). * * The acceptance call is not executed and treated as a no-op if the target address doesn't contain code (i.e. an EOA). * Otherwise, the recipient must implement {IERC1155Receiver-onERC1155Received} and return the acceptance magic value to accept * the transfer. */ function checkOnERC1155Received( address operator, address from, address to, uint256 id, uint256 value, bytes memory data ) internal { if (to.code.length > 0) { try IERC1155Receiver(to).onERC1155Received(operator, from, id, value, data) returns (bytes4 response) { if (response != IERC1155Receiver.onERC1155Received.selector) { // Tokens rejected revert IERC1155Errors.ERC1155InvalidReceiver(to); } } catch (bytes memory reason) { if (reason.length == 0) { // non-IERC1155Receiver implementer revert IERC1155Errors.ERC1155InvalidReceiver(to); } else { assembly ("memory-safe") { revert(add(32, reason), mload(reason)) } } } } } /** * @dev Performs a batch acceptance check for the provided `operator` by calling {IERC1155-onERC1155BatchReceived} * on the `to` address. The `operator` is generally the address that initiated the token transfer (i.e. `msg.sender`). * * The acceptance call is not executed and treated as a no-op if the target address doesn't contain code (i.e. an EOA). * Otherwise, the recipient must implement {IERC1155Receiver-onERC1155Received} and return the acceptance magic value to accept * the transfer. */ function checkOnERC1155BatchReceived( address operator, address from, address to, uint256[] memory ids, uint256[] memory values, bytes memory data ) internal { if (to.code.length > 0) { try IERC1155Receiver(to).onERC1155BatchReceived(operator, from, ids, values, data) returns ( bytes4 response ) { if (response != IERC1155Receiver.onERC1155BatchReceived.selector) { // Tokens rejected revert IERC1155Errors.ERC1155InvalidReceiver(to); } } catch (bytes memory reason) { if (reason.length == 0) { // non-IERC1155Receiver implementer revert IERC1155Errors.ERC1155InvalidReceiver(to); } else { assembly ("memory-safe") { revert(add(32, reason), mload(reason)) } } } } } }
// 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 { /** * @dev See {IERC165-supportsInterface}. */ 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/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 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 Helper to set the length of an 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 an 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 an 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) } } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v5.1.0) (interfaces/draft-IERC6093.sol) pragma solidity ^0.8.20; /** * @dev Standard ERC-20 Errors * Interface of the https://eips.ethereum.org/EIPS/eip-6093[ERC-6093] custom errors for ERC-20 tokens. */ interface IERC20Errors { /** * @dev Indicates an error related to the current `balance` of a `sender`. Used in transfers. * @param sender Address whose tokens are being transferred. * @param balance Current balance for the interacting account. * @param needed Minimum amount required to perform a transfer. */ error ERC20InsufficientBalance(address sender, uint256 balance, uint256 needed); /** * @dev Indicates a failure with the token `sender`. Used in transfers. * @param sender Address whose tokens are being transferred. */ error ERC20InvalidSender(address sender); /** * @dev Indicates a failure with the token `receiver`. Used in transfers. * @param receiver Address to which tokens are being transferred. */ error ERC20InvalidReceiver(address receiver); /** * @dev Indicates a failure with the `spender`’s `allowance`. Used in transfers. * @param spender Address that may be allowed to operate on tokens without being their owner. * @param allowance Amount of tokens a `spender` is allowed to operate with. * @param needed Minimum amount required to perform a transfer. */ error ERC20InsufficientAllowance(address spender, uint256 allowance, uint256 needed); /** * @dev Indicates a failure with the `approver` of a token to be approved. Used in approvals. * @param approver Address initiating an approval operation. */ error ERC20InvalidApprover(address approver); /** * @dev Indicates a failure with the `spender` to be approved. Used in approvals. * @param spender Address that may be allowed to operate on tokens without being their owner. */ error ERC20InvalidSpender(address spender); } /** * @dev Standard ERC-721 Errors * Interface of the https://eips.ethereum.org/EIPS/eip-6093[ERC-6093] custom errors for ERC-721 tokens. */ interface IERC721Errors { /** * @dev Indicates that an address can't be an owner. For example, `address(0)` is a forbidden owner in ERC-20. * Used in balance queries. * @param owner Address of the current owner of a token. */ error ERC721InvalidOwner(address owner); /** * @dev Indicates a `tokenId` whose `owner` is the zero address. * @param tokenId Identifier number of a token. */ error ERC721NonexistentToken(uint256 tokenId); /** * @dev Indicates an error related to the ownership over a particular token. Used in transfers. * @param sender Address whose tokens are being transferred. * @param tokenId Identifier number of a token. * @param owner Address of the current owner of a token. */ error ERC721IncorrectOwner(address sender, uint256 tokenId, address owner); /** * @dev Indicates a failure with the token `sender`. Used in transfers. * @param sender Address whose tokens are being transferred. */ error ERC721InvalidSender(address sender); /** * @dev Indicates a failure with the token `receiver`. Used in transfers. * @param receiver Address to which tokens are being transferred. */ error ERC721InvalidReceiver(address receiver); /** * @dev Indicates a failure with the `operator`’s approval. Used in transfers. * @param operator Address that may be allowed to operate on tokens without being their owner. * @param tokenId Identifier number of a token. */ error ERC721InsufficientApproval(address operator, uint256 tokenId); /** * @dev Indicates a failure with the `approver` of a token to be approved. Used in approvals. * @param approver Address initiating an approval operation. */ error ERC721InvalidApprover(address approver); /** * @dev Indicates a failure with the `operator` to be approved. Used in approvals. * @param operator Address that may be allowed to operate on tokens without being their owner. */ error ERC721InvalidOperator(address operator); } /** * @dev Standard ERC-1155 Errors * Interface of the https://eips.ethereum.org/EIPS/eip-6093[ERC-6093] custom errors for ERC-1155 tokens. */ interface IERC1155Errors { /** * @dev Indicates an error related to the current `balance` of a `sender`. Used in transfers. * @param sender Address whose tokens are being transferred. * @param balance Current balance for the interacting account. * @param needed Minimum amount required to perform a transfer. * @param tokenId Identifier number of a token. */ error ERC1155InsufficientBalance(address sender, uint256 balance, uint256 needed, uint256 tokenId); /** * @dev Indicates a failure with the token `sender`. Used in transfers. * @param sender Address whose tokens are being transferred. */ error ERC1155InvalidSender(address sender); /** * @dev Indicates a failure with the token `receiver`. Used in transfers. * @param receiver Address to which tokens are being transferred. */ error ERC1155InvalidReceiver(address receiver); /** * @dev Indicates a failure with the `operator`’s approval. Used in transfers. * @param operator Address that may be allowed to operate on tokens without being their owner. * @param owner Address of the current owner of a token. */ error ERC1155MissingApprovalForAll(address operator, address owner); /** * @dev Indicates a failure with the `approver` of a token to be approved. Used in approvals. * @param approver Address initiating an approval operation. */ error ERC1155InvalidApprover(address approver); /** * @dev Indicates a failure with the `operator` to be approved. Used in approvals. * @param operator Address that may be allowed to operate on tokens without being their owner. */ error ERC1155InvalidOperator(address operator); /** * @dev Indicates an array length mismatch between ids and values in a safeBatchTransferFrom operation. * Used in batch transfers. * @param idsLength Length of the array of token identifiers * @param valuesLength Length of the array of token amounts */ error ERC1155InvalidArrayLength(uint256 idsLength, uint256 valuesLength); }
// 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.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.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.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) (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/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 } } }
{ "remappings": [ "@openzeppelin/contracts/=lib/openzeppelin-contracts/contracts/", "ds-test/=lib/openzeppelin-contracts/lib/forge-std/lib/ds-test/src/", "erc4626-tests/=lib/openzeppelin-contracts/lib/erc4626-tests/", "forge-std/=lib/forge-std/src/", "halmos-cheatcodes/=lib/openzeppelin-contracts/lib/halmos-cheatcodes/src/", "openzeppelin-contracts/=lib/openzeppelin-contracts/", "@solady/=lib/solady/src/", "solady/=lib/solady/src/" ], "optimizer": { "enabled": true, "runs": 200 }, "metadata": { "useLiteralContent": false, "bytecodeHash": "ipfs", "appendCBOR": true }, "outputSelection": { "*": { "*": [ "evm.bytecode", "evm.deployedBytecode", "devdoc", "userdoc", "metadata", "abi" ] } }, "evmVersion": "cancun", "viaIR": true, "libraries": {} }
Contract Security Audit
- No Contract Security Audit Submitted- Submit Audit Here
Contract ABI
API[{"inputs":[{"internalType":"address","name":"asset_","type":"address"},{"internalType":"address","name":"oracle_","type":"address"},{"internalType":"address","name":"treasury_","type":"address"},{"internalType":"address","name":"oracleSender_","type":"address"},{"internalType":"bytes32","name":"oracleKey_","type":"bytes32"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[],"name":"AlreadyDeployed","type":"error"},{"inputs":[],"name":"AmountExceedsDepositLimit","type":"error"},{"inputs":[],"name":"CannotRedeemAtThisTime","type":"error"},{"inputs":[],"name":"DepositsAlreadyPaused","type":"error"},{"inputs":[],"name":"DepositsArePaused","type":"error"},{"inputs":[],"name":"DepositsNotPaused","type":"error"},{"inputs":[],"name":"EnforcedPause","type":"error"},{"inputs":[],"name":"ExpectedPause","type":"error"},{"inputs":[],"name":"InsufficientHenlockedBalance","type":"error"},{"inputs":[],"name":"InvalidDepositLimit","type":"error"},{"inputs":[],"name":"InvalidEpochStrike","type":"error"},{"inputs":[],"name":"MaxFeeExceeded","type":"error"},{"inputs":[],"name":"NewLimitTooLow","type":"error"},{"inputs":[{"internalType":"address","name":"owner","type":"address"}],"name":"OwnableInvalidOwner","type":"error"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"OwnableUnauthorizedAccount","type":"error"},{"inputs":[],"name":"ReentrancyGuardReentrantCall","type":"error"},{"inputs":[],"name":"RoundAlreadyExistsOrNotClosed","type":"error"},{"inputs":[],"name":"RoundIsClosed","type":"error"},{"inputs":[],"name":"RoundNotOpened","type":"error"},{"inputs":[{"internalType":"address","name":"token","type":"address"}],"name":"SafeERC20FailedOperation","type":"error"},{"inputs":[],"name":"StaleOracleData","type":"error"},{"inputs":[],"name":"StrikeTooLow","type":"error"},{"inputs":[],"name":"ZeroAddress","type":"error"},{"inputs":[],"name":"ZeroMint","type":"error"},{"inputs":[],"name":"ZeroOracleAddress","type":"error"},{"inputs":[],"name":"ZeroOracleSenderAddress","type":"error"},{"inputs":[],"name":"ZeroRedeemAmount","type":"error"},{"inputs":[],"name":"ZeroTreasuryAddress","type":"error"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint64","name":"strike","type":"uint64"},{"indexed":false,"internalType":"address","name":"token","type":"address"}],"name":"DeployERC20","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint48","name":"epochId","type":"uint48"},{"indexed":true,"internalType":"uint64","name":"strike","type":"uint64"},{"indexed":false,"internalType":"uint256","name":"newDepositLimit","type":"uint256"}],"name":"DepositLimitUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint48","name":"epochId","type":"uint48"},{"indexed":true,"internalType":"uint64","name":"strike","type":"uint64"}],"name":"DepositsPaused","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint48","name":"epochId","type":"uint48"},{"indexed":true,"internalType":"uint64","name":"strike","type":"uint64"}],"name":"DepositsUnpaused","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"user","type":"address"},{"indexed":true,"internalType":"uint256","name":"strike","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"Mint","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"reservoir","type":"address"},{"indexed":true,"internalType":"uint64","name":"strike","type":"uint64"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"MintFromReservoir","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"newKey","type":"bytes32"}],"name":"OracleKeyUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"newSender","type":"address"}],"name":"OracleSenderUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"newOracle","type":"address"}],"name":"OracleUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"account","type":"address"}],"name":"Paused","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"user","type":"address"},{"indexed":true,"internalType":"uint64","name":"strike","type":"uint64"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"Redeem","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint48","name":"epochId","type":"uint48"},{"indexed":true,"internalType":"uint64","name":"strike","type":"uint64"}],"name":"RoundClosed","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint48","name":"epochId","type":"uint48"},{"indexed":true,"internalType":"uint64","name":"strike","type":"uint64"},{"indexed":false,"internalType":"uint256","name":"depositLimit","type":"uint256"}],"name":"RoundOpened","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"fee","type":"uint256"}],"name":"SetFee","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"treasury","type":"address"}],"name":"SetTreasury","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"account","type":"address"}],"name":"Unpaused","type":"event"},{"inputs":[],"name":"FEE_BASIS","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"MAX_FEE","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"asset","outputs":[{"internalType":"contract IERC20","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint64","name":"strike","type":"uint64"}],"name":"canRedeem","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint64","name":"strike","type":"uint64"}],"name":"deployERC20","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint64","name":"strike","type":"uint64"}],"name":"deployments","outputs":[{"internalType":"contract IERC20","name":"token","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint64","name":"strike","type":"uint64"}],"name":"epochs","outputs":[{"internalType":"uint48","name":"epochId","type":"uint48"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"fee","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getOracleKey","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint64","name":"strike","type":"uint64"}],"name":"getRoundInfo","outputs":[{"internalType":"bool","name":"exists","type":"bool"},{"internalType":"bool","name":"closed","type":"bool"},{"internalType":"bool","name":"depositsPaused","type":"bool"},{"internalType":"uint256","name":"timestamp","type":"uint256"},{"internalType":"uint256","name":"depositLimit","type":"uint256"},{"internalType":"uint256","name":"totalDeposits","type":"uint256"},{"internalType":"uint256","name":"remainingCapacity","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"hodlMulti","outputs":[{"internalType":"contract henlocked","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint48","name":"epochId","type":"uint48"}],"name":"infos","outputs":[{"internalType":"uint64","name":"strike","type":"uint64"},{"internalType":"bool","name":"closed","type":"bool"},{"internalType":"bool","name":"depositsPaused","type":"bool"},{"internalType":"uint256","name":"timestamp","type":"uint256"},{"internalType":"uint256","name":"depositLimit","type":"uint256"},{"internalType":"uint256","name":"totalDeposits","type":"uint256"},{"internalType":"address","name":"reservoir","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint64","name":"strike","type":"uint64"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"uint256","name":"minimumWhaleMatch","type":"uint256"}],"name":"mint","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"nextId","outputs":[{"internalType":"uint48","name":"","type":"uint48"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint64","name":"strike","type":"uint64"},{"internalType":"uint256","name":"depositLimit","type":"uint256"},{"internalType":"address","name":"reservoir","type":"address"}],"name":"openRound","outputs":[{"internalType":"uint48","name":"","type":"uint48"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"oracle","outputs":[{"internalType":"contract IOracleChainsight","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"oracleSender","outputs":[{"internalType":"address","name":"","type":"address"}],"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":"uint64","name":"strike","type":"uint64"}],"name":"pauseDeposits","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"paused","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"value","type":"uint256"}],"name":"previewMint","outputs":[{"internalType":"uint256","name":"depositAfterFee","type":"uint256"},{"internalType":"uint256","name":"feeAmount","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint64","name":"strike","type":"uint64"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"redeem","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"renounceOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"fee_","type":"uint256"}],"name":"setFee","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newOracle","type":"address"}],"name":"setOracle","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"newKey","type":"bytes32"}],"name":"setOracleKey","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newSender","type":"address"}],"name":"setOracleSender","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"treasury_","type":"address"}],"name":"setTreasury","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"treasury","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"unpause","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint64","name":"strike","type":"uint64"}],"name":"unpauseDeposits","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint64","name":"strike","type":"uint64"},{"internalType":"uint256","name":"newDepositLimit","type":"uint256"}],"name":"updateDepositLimit","outputs":[],"stateMutability":"nonpayable","type":"function"}]
Contract Creation Code
60c03461023557601f614a1e38819003918201601f19168301926001600160401b03929091838511838610176101c8578160a092849260409788528339810103126102355761004d81610239565b9061005a60208201610239565b90610066858201610239565b90608061007560608301610239565b9101519360015f55331561021e576001548751946001600160a01b03929091839190338382167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e05f80a36001600160d81b0319163366ffffffffffffff60a01b191617600160a81b176001555f6002551694851561020f575081169283156101fe5781169182156101ed57169283156101dc5760805260018060a01b0319918260035416176003558160045416176004556005541617600555600655815190611db480830191838310908311176101c85783918391612c6a8339602081525f60208201520301905ff080156101be5760a05251612a1c908161024e82396080518181816103640152818161103a015281816112be01526116ff015260a05181818161028a0152818161098c01528181610dd20152818161106f015281816111aa01526116bb0152f35b50513d5f823e3d90fd5b634e487b7160e01b5f52604160045260245ffd5b8651636a37f5a560e11b8152600490fd5b87516351dc806d60e11b8152600490fd5b875163dc6d352160e01b8152600490fd5b63d92e233d60e01b8152600490fd5b8651631e4fbdf760e01b81525f6004820152602490fd5b5f80fd5b51906001600160a01b03821682036102355756fe6080806040526004361015610012575f80fd5b5f905f3560e01c90816302e7940514611796575080630e9d7dd11461172e57806338d52e0f146116ea5780633a59aac7146116a65780633f4ba83a14611635578063473d0452146115f55780634bd2d7f9146115b5578063508f3630146115985780635bc90b52146115525780635c975abb1461152d57806361b8ce8c1461150557806361d027b3146114dd57806369fe0e2d1461146a5780636e5deac414610f3f578063715018a614610ee25780637a94043714610d825780637adbf97314610d1a5780637dc0d1d014610cf15780637f815e5614610cc35780638456cb5914610c605780638686ebcc14610c435780638da5cb5b14610c1a57806396d457af146108a3578063b3d7f6b914610878578063bc063e1a1461085b578063c889fd7d146107ae578063d9d02b01146106f6578063ddca3f43146106d8578063ddcaddbf146105f3578063eb3b8a5f1461055a578063ef113d0f14610503578063f0f442601461046d578063f1378457146102205763f2fde38b14610194575f80fd5b3461021d57602036600319011261021d576101ad6117b9565b6101b5611a3d565b6001600160a01b0390811690811561020457600154826001600160601b0360a01b821617600155167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e05f80a380f35b604051631e4fbdf760e01b815260048101849052602490fd5b80fd5b503461021d57604036600319011261021d5761023a6117cf565b60243590610246611a69565b811561045b5761025581611898565b1561044957604051627eeac760e11b81523360048201526001600160401b0382811660248301819052602095919391929091907f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316908781604481855afa90811561043e579087918691610409575b50106103f757803b156103f357604051637a94c56560e11b81523360048201526001600160401b0383166024820152604481018790529084908290606490829084905af180156103e8579084916103d0575b505061032990611b34565b60405163a9059cbb60e01b86820152336024820152604480820186905281529260808401908111848210176103bc57600193610388916040527f0000000000000000000000000000000000000000000000000000000000000000611bd0565b6040518481527f53307341a0e8c285b0e4488d042d0ab431a1becc0771bbdb906b57a2b4087594863392a355604051908152f35b634e487b7160e01b5f52604160045260245ffd5b6103d990611813565b6103e457825f61031e565b8280fd5b6040513d86823e3d90fd5b8380fd5b604051630e13fa7160e31b8152600490fd5b809250898092503d8311610437575b6104228183611826565b81010312610433578690515f6102cc565b5f80fd5b503d610418565b6040513d87823e3d90fd5b6040516353193d3760e01b8152600490fd5b60405163dee12e0360e01b8152600490fd5b503461021d57602036600319011261021d576104876117b9565b61048f611a69565b610497611a3d565b6001600160a01b031680156104f15760207fcb7ef3e545f5cdb893f5c568ba710fe08f336375a2d9fd66e161033f8fc09ef39160045490806001600160601b0360a01b831617600455846040519216178152a16001815580f35b60405163d92e233d60e01b8152600490fd5b503461021d57602036600319011261021d5760e06105276105226117cf565b6119ca565b94604094919493929351961515875215156020870152151560408601526060850152608084015260a083015260c0820152f35b503461021d57602036600319011261021d5760043565ffffffffffff81168091036105ef578160409160e093526008602052208054906001810154906002810154600382015491600460018060a01b03910154169260ff604051956001600160401b0381168752818160401c161515602088015260481c16151560408601526060850152608084015260a083015260c0820152f35b5080fd5b503461021d57604036600319011261021d5761060d6117cf565b6001600160401b0360243591610621611a69565b610629611a3d565b1690818352600960205265ffffffffffff6040842054169081156106c65781845260086020526040842060ff815460401c166106b457600381015482106106a257817fbd8c81882ee7e90afad11c4f70486f25c0bc860285d7ba8fd3ee1fde95a607f49260026020930155604051908152a36001815580f35b604051631c362e1160e31b8152600490fd5b604051636d70cc8960e11b8152600490fd5b60405163eed34f0760e01b8152600490fd5b503461021d578060031936011261021d576020600254604051908152f35b503461021d57602036600319011261021d576001600160401b036107186117cf565b610720611a3d565b16808252600960205265ffffffffffff60408320541680156106c657808352600860205260408320805460ff8160401c166106b45760ff8160481c1661079c5760ff60481b191669010000000000000000001790557f023dff3dced99e172de9866eb8fbddaf670d6096c898c86020d86d28c728e6588380a380f35b60405163acf542ab60e01b8152600490fd5b503461021d57602036600319011261021d576001600160401b036107d06117cf565b6107d8611a3d565b16808252600960205265ffffffffffff60408320541680156106c657808352600860205260408320805460ff8160401c166106b45760ff8160481c16156108495760ff60481b191690557fe78dd8e5fb9202ec320b9ef5cc26cc642ee92cafa66816332b1d0b79b39baf618380a380f35b604051632934c26360e21b8152600490fd5b503461021d578060031936011261021d5760206040516103e88152f35b503461021d57602036600319011261021d5760406108976004356119a1565b82519182526020820152f35b503461021d57606036600319011261021d576108bd6117cf565b602435916044356001600160a01b03818116939092918490036104335761092f906108e6611a69565b6108ee611a3d565b604084600354168560055416906006549183518096819482936357732dbb60e11b84526004840160209093929193604081019460018060a01b031681520152565b03915afa908115610c0f5783928492610bdb575b506001600160401b03808092169316831115610bc9576109628261187f565b81804216911610610bb7576040519163bd85b03960e01b835283600484015260209788846024818a7f0000000000000000000000000000000000000000000000000000000000000000165afa938415610bac578694610b7d575b5083811115610b6b578486526009895265ffffffffffff97886040882054168015159081610b51575b50610b3f57600154898160a81c16998a14610b2b5765ffffffffffff60a81b191660018a810160a81b65ffffffffffff60a81b169190911790556040519760e08901948086118a8710176103bc576001998b97858e97888b6004968f8f906040917fc35303cbdb16af3e918634bdda99307f23696c65fba6f7139e645fe22eb56fe29f835289526008858a0195828752838b01958387528560608d019916895260808c01998a5260a08c019a8b5260c08c019e8f528352522096511669ff00000000000000000068ff000000000000000088549451151560401b169251151560481b169269ffffffffffffffffffff19161717178455518d840155516002830155516003820155019151166001600160601b0360a01b82541617905584865260098252604086208465ffffffffffff19825416179055604051908152a355604051908152f35b634e487b7160e01b88526011600452602488fd5b604051632e6d917160e21b8152600490fd5b9050875260088a5260ff604088205460401c16155f6109e5565b604051637fb1277b60e01b8152600490fd5b9093508881813d8311610ba5575b610b958183611826565b810103126104335751925f6109bc565b503d610b8b565b6040513d88823e3d90fd5b60405163a527363160e01b8152600490fd5b604051630bc672fd60e21b8152600490fd5b909250610c00915060403d604011610c08575b610bf88183611826565b81019061185b565b90915f610943565b503d610bee565b6040513d85823e3d90fd5b503461021d578060031936011261021d576001546040516001600160a01b039091168152602090f35b503461021d578060031936011261021d5760206040516127108152f35b503461021d578060031936011261021d57610c79611a3d565b610c81611a8a565b6001805460ff60a01b1916600160a01b1790556040513381527f62e78cea01bee320cd4e420270b5ea74000d11b0c9f74754ebdbfc544b05a25890602090a180f35b503461021d57602036600319011261021d576020610ce7610ce26117cf565b611898565b6040519015158152f35b503461021d578060031936011261021d576003546040516001600160a01b039091168152602090f35b503461021d57602036600319011261021d57610d346117b9565b610d3c611a3d565b600380546001600160a01b0319166001600160a01b039290921691821790557f3df77beb5db05fcdd70a30fc8adf3f83f9501b68579455adbd100b81809403948280a280f35b503461021d576020908160031936011261021d57610d9e6117cf565b90610da7611a69565b6001600160401b039182168082526007845260408220546001600160a01b03908116610ed0576040517f0000000000000000000000000000000000000000000000000000000000000000821694610dbc80830191821183831017610ebc576040918391611c2b8339878152858982015203019084f08015610c0f571692803b156103e457828091602460405180948193635b52ebef60e11b83528960048401525af18015610c0f57610ea8575b50908160019282526007855260408220846001600160601b0360a01b8254161790557f5ca11f4052e8cadbe59c1a0cd3acc22f4977f49509b0f7cd04d2dbb19aa5940c85604051868152a255604051908152f35b610eb28391611813565b6105ef575f610e54565b634e487b7160e01b86526041600452602486fd5b60405163a6ef0ba160e01b8152600490fd5b503461021d578060031936011261021d57610efb611a3d565b600180546001600160a01b031981169091555f906001600160a01b03167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e08280a380f35b503461043357606036600319011261043357610f596117cf565b60243590610f65611a69565b610f6d611a8a565b6001600160401b0381165f52600960205265ffffffffffff60405f20541680156106c6575f52600860205260405f2091825460ff8160401c166106b45760481c60ff1661145857801561144657610fd0610fc960025483611aab565b80926117e5565b9260038101805492610fe28685611806565b9360028401548095116114345760048401545f956001600160a01b039091169182611331575b505050611016868354611806565b9182815560443585106112fb578415159285846112e8575b505050806112aa575b507f00000000000000000000000000000000000000000000000000000000000000009061106686303385611ada565b61113c575b50507f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03169050803b156103f357604051630ab714fb60e11b81523360048201526001600160401b0383166024820152604481018490529084908290606490829084905af180156103e857611128575b506020926001916001600160401b036040519185835216907f4c209b5fc8ad50758f13e2e1088ba56a560dff690a1c6fef26394f4c03821c4f863392a355604051908152f35b6111328491611813565b6103e4575f6110e2565b60048201546001600160a01b0316803b15610433575f80916024604051809481936395e1d97760e01b83528960048401525af1801561129f5761128c575b508261119591309060018060a01b0360048601541690611ada565b600481015485906001600160a01b03908116907f000000000000000000000000000000000000000000000000000000000000000016803b156103e457604051630ab714fb60e11b81526001600160a01b039290921660048301526001600160401b03861660248301526044820185905282908290606490829084905af1801561128157611269575b5050600460018060a01b03910154166040519182527fef970e06880f8548844c9f7420575bbf879f646b6f7b8f4c241ca6b7678e4eb060206001600160401b03851693a35f808061106b565b61127290611813565b61127d57845f61121d565b8480fd5b6040513d84823e3d90fd5b611297919650611813565b5f948261117a565b6040513d5f823e3d90fd5b6004546112e291906001600160a01b0316337f0000000000000000000000000000000000000000000000000000000000000000611ada565b5f611037565b6112f191611806565b90555f808561102e565b60405162461bcd60e51b815260206004820152600e60248201526d5768616c6520736c69707061676560901b6044820152606490fd5b604051637cb5dbbd60e11b815290602082600481875afa801561129f578a925f916113f4575b50611363575b50611008565b5f9497509161137861137e9260209594611806565b906117e5565b8089106113ed575b6024906040519485938492630d384a6f60e11b845260048401525af190811561129f575f916113bb575b50925f80878161135d565b90506020813d6020116113e5575b816113d660209383611826565b8101031261043357515f6113b0565b3d91506113c9565b5087611386565b919250506020813d60201161142c575b8161141160209383611826565b8101031261043357519081151582036104335789915f611357565b3d9150611404565b604051639670687960e01b8152600490fd5b60405163a776bb4d60e01b8152600490fd5b604051630b4cba3160e31b8152600490fd5b3461043357602036600319011261043357600435611486611a69565b61148e611a3d565b6103e881116114cb576020817e172ddfc5ae88d08b3de01a5a187667c37a5a53989e8c175055cb6c993792a792600255604051908152a160015f55005b60405163f4df6ae560e01b8152600490fd5b34610433575f366003190112610433576004546040516001600160a01b039091168152602090f35b34610433575f36600319011261043357602065ffffffffffff60015460a81c16604051908152f35b34610433575f36600319011261043357602060ff60015460a01c166040519015158152f35b346104335760203660031901126104335760043561156e611a3d565b806006557f54ef723920b7713f0db1bd7930ad9789cc963b5df84af3396860d2cd45d0ec815f80a2005b34610433575f366003190112610433576020600654604051908152f35b34610433576020366003190112610433576001600160401b036115d66117cf565b165f526009602052602065ffffffffffff60405f205416604051908152f35b34610433576020366003190112610433576001600160401b036116166117cf565b165f526007602052602060018060a01b0360405f205416604051908152f35b34610433575f3660031901126104335761164d611a3d565b60015460ff8160a01c16156116945760ff60a01b19166001556040513381527f5db9ee0a495bf2e6ff9c91a7834c1ba4fdd244a5e8aa4e537bd38aeae4b073aa90602090a1005b604051638dfc202b60e01b8152600490fd5b34610433575f366003190112610433576040517f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03168152602090f35b34610433575f366003190112610433576040517f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03168152602090f35b34610433576020366003190112610433576117476117b9565b61174f611a3d565b6001600160a01b031680156104f157600580546001600160a01b031916821790557fba2b62c9461657dff915dd9c97496dc57d1ff2cf348b2b947cc5e9e72947b1425f80a2005b34610433575f366003190112610433576005546001600160a01b03168152602090f35b600435906001600160a01b038216820361043357565b600435906001600160401b038216820361043357565b919082039182116117f257565b634e487b7160e01b5f52601160045260245ffd5b919082018092116117f257565b6001600160401b0381116103bc57604052565b90601f801991011681019081106001600160401b038211176103bc57604052565b51906001600160401b038216820361043357565b91908260409103126104335761187c602061187584611847565b9301611847565b90565b90610e106001600160401b03809316019182116117f257565b6001600160401b0380911690815f52600960205260409065ffffffffffff825f2054165f526008602052815f209260ff8454841c166119985760035460055460065485516357732dbb60e11b81526001600160a01b039283166004820152602481019190915291859183916044918391165afa93841561198f575f915f9561196e575b506119258561187f565b8480421691161061195e575082161015928361194c575b505050611947575f90565b600190565b600101549116101590505f808061193c565b5163a527363160e01b8152600490fd5b9080955061198892503d8611610c0857610bf88183611826565b935f61191b565b513d5f823e3d90fd5b50505050600190565b9060025480155f146119b257505f90565b6119bf6119c69184611aab565b80936117e5565b9190565b6001600160401b03165f52600960205265ffffffffffff60405f2054168015611a2c575f52600860205260405f2080549060018101549060036002820154910154611a1581836117e5565b60019560ff808760401c169660481c169493929190565b505f905f905f905f905f905f905f90565b6001546001600160a01b03163303611a5157565b60405163118cdaa760e01b8152336004820152602490fd5b60025f5414611a785760025f55565b604051633ee5aeb560e01b8152600490fd5b60ff60015460a01c16611a9957565b60405163d93c066560e01b8152600490fd5b81810291612710918291818504149015170215611acd57808204910615150190565b63ad251c275f526004601cfd5b6040516323b872dd60e01b60208201526001600160a01b03928316602482015292909116604483015260648083019390935291815260a08101918183106001600160401b038411176103bc57611b3292604052611bd0565b565b6001600160401b0380911690815f52600960205265ffffffffffff60405f20541690815f52600860205260405f209081549060ff8260401c16611bc957811615611bb75768ff00000000000000001916680100000000000000001790557ff93f4d3a19af6703dc8c284b246c3681ae2e0087236087d929b85670589576d35f80a3565b604051631b086e7b60e11b8152600490fd5b5050505050565b905f602091828151910182855af11561129f575f513d611c2157506001600160a01b0381163b155b611bff5750565b604051635274afe760e01b81526001600160a01b039091166004820152602490fd5b60011415611bf856fe60c0604090808252346103e8578181610dbc803803809161002082856103ec565b8339810103126103e85780516001600160a01b039190828116908190036103e8576020918201516001600160401b039283821692918390036103e85781156103e8575f92826080528060a052865193848094622b600360e21b82526004938483015260249586915afa9384156103de575f946103c2575b508351958587116103b0576001968754958887811c971680156103a6575b85881014610394578190601f97888111610346575b5085908883116001146102e7575f926102dc575b50505f19600383901b1c191690881b1787555b60805116925f60a051828a5180978193634e41a1fb60e01b8352878301525afa9384156102d2575f946102ae575b50835195861161029c57600254918783811c93168015610292575b8484101461028157505083811161023d575b50809284116001146101d957509282939183925f946101ce575b50501b915f199060031b1c1916176002555b51610931908161048b8239608051818181610146015281816103970152818161041b015281816104d10152610671015260a05181818160fb015281816101920152818161036a0152818161052001526106430152f35b015192505f80610166565b919083601f19811660025f52845f20945f905b88838310610223575050501061020b575b505050811b01600255610178565b01515f1960f88460031b161c191690555f80806101fd565b8587015188559096019594850194879350908101906101ec565b60025f52815f208480870160051c820192848810610278575b0160051c019086905b82811061026d57505061014c565b5f815501869061025f565b92508192610256565b602290634e487b7160e01b5f52525ffd5b92607f169261013a565b634e487b7160e01b5f90815260418352fd5b6102cb9194503d805f833e6102c381836103ec565b810190610423565b925f61011f565b88513d5f823e3d90fd5b015190505f806100de565b908a9350601f19831691845f52875f20925f5b898282106103305750508411610318575b505050811b0187556100f1565b01515f1960f88460031b161c191690555f808061030b565b8385015186558e979095019493840193016102fa565b909150895f52855f208880850160051c82019288861061038b575b918c91869594930160051c01915b82811061037d5750506100ca565b5f81558594508c910161036f565b92508192610361565b85602285634e487b7160e01b5f52525ffd5b96607f16966100b5565b83604183634e487b7160e01b5f52525ffd5b6103d79194503d805f833e6102c381836103ec565b925f610097565b87513d5f823e3d90fd5b5f80fd5b601f909101601f19168101906001600160401b0382119082101761040f57604052565b634e487b7160e01b5f52604160045260245ffd5b602080828403126103e85781516001600160401b03928382116103e857019183601f840112156103e857825190811161040f576040519361046d601f8301601f19168401866103ec565b8185528282850101116103e85780825f94018386015e830101529056fe6080604090808252600480361015610015575f80fd5b5f3560e01c91826306fdde031461079e57508163095ea7b3146106f157816318160ddd1461062457816323b872dd14610465578163313ce5671461044a5781633a59aac71461040757816370a082311461032d57816395d89b411461022b578163a9059cbb1461011e57508063ad8f5008146100e45763dd62ed3e14610099575f80fd5b346100e057806003193601126100e0576020906100b4610885565b6100bc61089b565b9060018060a01b038091165f525f8452825f2091165f528252805f20549051908152f35b5f80fd5b50346100e0575f3660031901126100e057602090517f00000000000000000000000000000000000000000000000000000000000000008152f35b82346100e057806003193601126100e057610137610885565b602435906001600160a01b03907f00000000000000000000000000000000000000000000000000000000000000008216803b156100e05784516361f3f6e960e01b8152339681019687526001600160a01b03831660208801527f0000000000000000000000000000000000000000000000000000000000000000604088015260608701859052955f91879182908490829060800103925af194851561022157602095610212575b50835192835216907fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef843392a35160018152f35b61021b906108b1565b856101de565b84513d5f823e3d90fd5b82346100e0575f3660031901126100e0578051905f9260025460018160011c91600181168015610323575b602094858510821461031057508387529081156102f05750600114610296575b505050610288826102929403836108d9565b519182918261085b565b0390f35b60025f9081529295507f405787fa12a823e0f2b7631cc41b3ba8828b3321ca811111fa75cd3aa3bb5ace5b8284106102dd5750505082610292946102889282010194610276565b80548685018801529286019281016102c1565b60ff1916868501525050151560051b830101925061028882610292610276565b602290634e487b7160e01b5f525260245ffd5b92607f1692610256565b9050346100e057602091826003193601126100e0578261034b610885565b8251627eeac760e11b81526001600160a01b03918216948101949094527f00000000000000000000000000000000000000000000000000000000000000006024850152839060449082907f0000000000000000000000000000000000000000000000000000000000000000165afa9182156103fd575f926103ce575b5051908152f35b9091508281813d83116103f6575b6103e681836108d9565b810103126100e05751905f6103c7565b503d6103dc565b50513d5f823e3d90fd5b82346100e0575f3660031901126100e057517f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03168152602090f35b82346100e0575f3660031901126100e0576020905160128152f35b82346100e05760603660031901126100e05761047f610885565b9161048861089b565b906044359160018060a01b039081861692835f526020965f8852865f20335f52885285875f2054106105f057845f525f8852865f20335f5288525f19875f2054036105b9575b837f00000000000000000000000000000000000000000000000000000000000000001691823b156100e05787516361f3f6e960e01b81526001600160a01b0392831691810191825291841660208201527f000000000000000000000000000000000000000000000000000000000000000060408201526060810187905290915f9183919082908490829060800103925af180156105af57917fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef939188936105a0575b5086519586521693a35160018152f35b6105a9906108b1565b88610590565b86513d5f823e3d90fd5b845f525f8852865f20335f528852865f208054908782039182116105dd57556104ce565b601184634e487b7160e01b5f525260245ffd5b865162461bcd60e51b8152808301899052600e60248201526d1b9bdd08185d5d1a1bdc9a5e995960921b6044820152606490fd5b82346100e0575f3660031901126100e057805163bd85b03960e01b81527f0000000000000000000000000000000000000000000000000000000000000000928101929092526020826024817f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03165afa9081156106e8575f916106b3575b6020925051908152f35b90506020823d6020116106e0575b816106ce602093836108d9565b810103126100e05760209151906106a9565b3d91506106c1565b513d5f823e3d90fd5b82346100e057806003193601126100e05761070a610885565b6001600160a01b031660243581156107645760209350335f525f8452825f20825f52845280835f205582519081527f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925843392a35160018152f35b825162461bcd60e51b81526020818601526014602482015273617070726f7665207a65726f206164647265737360601b6044820152606490fd5b83346100e0575f3660031901126100e0575f9260018054908160011c91600181168015610851575b602094858510821461031057508387529081156102f057506001146107f757505050610288826102929403836108d9565b60015f9081529295507fb10e2d527612073b26eecdfd717e6a320cf44b4afac2b0732d9fcbe2b7fa0cf65b82841061083e5750505082610292946102889282010194610276565b8054868501880152928601928101610822565b92607f16926107c6565b602060409281835280519182918282860152018484015e5f828201840152601f01601f1916010190565b600435906001600160a01b03821682036100e057565b602435906001600160a01b03821682036100e057565b67ffffffffffffffff81116108c557604052565b634e487b7160e01b5f52604160045260245ffd5b90601f8019910116810190811067ffffffffffffffff8211176108c55760405256fea26469706673582212207f3711ca38e587c8d8e1da805191c92c4123070a29e49baa108d17ee3d3c52d964736f6c63430008190033a2646970667358221220454358eb0b9f92eca5fb7dc710ed2d5dd0cb3de3c4e7836139038914c9f9042d64736f6c6343000819003360806040523461023257611db48038038061001981610236565b928339810190602080828403126102325781516001600160401b0392838211610232570192601f9080828601121561023257845184811161021e57601f199561006782850188168601610236565b9282845285838301011161023257815f92868093018386015e83010152805193841161021e57600254926001938481811c91168015610214575b82821014610200578381116101bc575b508092851160011461015a5750839450908392915f9461014f575b50501b915f199060031b1c1916176002555b33156101375760038054336001600160a01b03198216811790925560405191906001600160a01b03167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e05f80a3611b58908161025c8239f35b604051631e4fbdf760e01b81525f6004820152602490fd5b015192505f806100cc565b92948490811660025f52845f20945f905b888383106101a2575050501061018a575b505050811b016002556100de565b01515f1960f88460031b161c191690555f808061017c565b85870151885590960195948501948793509081019061016b565b60025f52815f208480880160051c8201928489106101f7575b0160051c019085905b8281106101ec5750506100b1565b5f81550185906101de565b925081926101d5565b634e487b7160e01b5f52602260045260245ffd5b90607f16906100a1565b634e487b7160e01b5f52604160045260245ffd5b5f80fd5b6040519190601f01601f191682016001600160401b0381118382101761021e5760405256fe60806040526004361015610011575f80fd5b5f3560e01c8062ad800c1461011f578062fdd58e1461013d57806301ffc9a7146101385780630e89341c14610133578063156e29f61461012e5780632eb2c2d6146101295780634e1273f4146101245780634e41a1fb1461011f57806361f3f6e91461011a578063715018a6146101155780638da5cb5b14610110578063a22cb4651461010b578063b6a5d7de14610106578063b918161114610101578063bd85b039146100fc578063e985e9c5146100f7578063f242432a146100f2578063f2fde38b146100ed5763f5298aca146100e8575f80fd5b610e33565b610da7565b610c8c565b610c30565b610c06565b610bc9565b610b61565b610aaa565b610a82565b610a27565b610985565b61017a565b6108ca565b610760565b6103ea565b6102bd565b61024f565b6101f5565b805180835260209291819084018484015e5f828201840152601f01601f1916010190565b906020610177928181520190610142565b90565b346101b15760203660031901126101b1576101ad61019960043561107d565b604051918291602083526020830190610142565b0390f35b5f80fd5b600435906001600160a01b03821682036101b157565b602435906001600160a01b03821682036101b157565b35906001600160a01b03821682036101b157565b346101b15760403660031901126101b15760206102346102136101b5565b6024355f525f835260405f209060018060a01b03165f5260205260405f2090565b54604051908152f35b6001600160e01b03198116036101b157565b346101b15760203660031901126101b157602060043561026e8161023d565b63ffffffff60e01b16636cdb3d1360e11b81149081156102ac575b811561029b575b506040519015158152f35b6301ffc9a760e01b1490505f610290565b6303a24d0760e21b81149150610289565b346101b1576020806003193601126101b157604051905f906002546001918160011c92600183169283156103b6575b6020851084146103a2578487526020870193908115610383575060011461032a575b6101ad8661031e81880382610664565b60405191829182610166565b60025f90815294509192917f405787fa12a823e0f2b7631cc41b3ba8828b3321ca811111fa75cd3aa3bb5ace5b838610610372575050509101905061031e826101ad5f61030e565b805485870152948201948101610357565b60ff1916845250505090151560051b01905061031e826101ad5f61030e565b634e487b7160e01b5f52602260045260245ffd5b93607f16936102ec565b60609060031901126101b1576004356001600160a01b03811681036101b157906024359060443590565b346101b1576103f8366103c0565b610403929192611494565b825f5260209160048352604090815f2080549084820180921161062a575581519061042d82610643565b5f82526001600160a01b0381169485156106135761046b85889160405192600184526020840152604083019160018352606084015260808301604052565b91906104788382866114e5565b80516001036104cf57926104bc92827f4c209b5fc8ad50758f13e2e1088ba56a560dff690a1c6fef26394f4c03821c4f9896936104ca9896015191015191336119f4565b519081529081906020820190565b0390a3005b91839491943b61050a575b50505050507f4c209b5fc8ad50758f13e2e1088ba56a560dff690a1c6fef26394f4c03821c4f916104ca916104bc565b93610533918697949895829a9751938492839263bc197c8160e01b9788855233600486016118e6565b03815f885af15f91816105e4575b5061057f57878787610551611962565b80519384610579578251632bfa23e760e11b81526001600160a01b0385166004820152602490fd5b84925001fd5b90919493965063ffffffff60e09693961b16036105c35750816104ca7f4c209b5fc8ad50758f13e2e1088ba56a560dff690a1c6fef26394f4c03821c4f5f806104da565b9051632bfa23e760e11b81526001600160a01b039091166004820152602490fd5b610605919250893d8b1161060c575b6105fd8183610664565b8101906118d1565b905f610541565b503d6105f3565b8351632bfa23e760e11b81525f6004820152602490fd5b611057565b634e487b7160e01b5f52604160045260245ffd5b6020810190811067ffffffffffffffff82111761065f57604052565b61062f565b90601f8019910116810190811067ffffffffffffffff82111761065f57604052565b67ffffffffffffffff811161065f5760051b60200190565b9080601f830112156101b15760209082356106b881610686565b936106c66040519586610664565b81855260208086019260051b8201019283116101b157602001905b8282106106ef575050505090565b813581529083019083016106e1565b67ffffffffffffffff811161065f57601f01601f191660200190565b81601f820112156101b157803590610731826106fe565b9261073f6040519485610664565b828452602083830101116101b157815f926020809301838601378301015290565b346101b15760a03660031901126101b1576107796101b5565b6107816101cb565b906044359167ffffffffffffffff908184116101b1576107a66004943690860161069e565b906064358381116101b1576107be903690870161069e565b926084359081116101b1576107d6903690870161071a565b936001600160a01b03808216903382141580610863575b6108365783161561081f5715610809576108079550611796565b005b604051626a0d4560e21b81525f81880152602490fd5b604051632bfa23e760e11b81525f81890152602490fd5b6040805163711bec9160e11b815233818b019081526001600160a01b038616602082015290918291010390fd5b505f82815260016020908152604080832033845290915290205460ff16156107ed565b9081518082526020808093019301915f5b8281106108a5575050505090565b835185529381019392810192600101610897565b906020610177928181520190610886565b346101b15760403660031901126101b15760043567ffffffffffffffff8082116101b157366023830112156101b157816004013561090781610686565b926109156040519485610664565b8184526020916024602086019160051b830101913683116101b157602401905b82821061096e57856024358681116101b1576101ad9161095c61096292369060040161069e565b90611294565b604051918291826108b9565b83809161097a846101e1565b815201910190610935565b346101b15760803660031901126101b15761099e6101b5565b6109a66101cb565b90335f52600560205260ff60405f205416156109f157610807916109c8611202565b906109d1611202565b926044356109de8461125f565b526064356109eb8561125f565b526115f9565b60405162461bcd60e51b815260206004820152600e60248201526d139bdd08185d5d1a1bdc9a5e995960921b6044820152606490fd5b346101b1575f3660031901126101b157610a3f611494565b600380546001600160a01b031981169091555f906001600160a01b03167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e08280a3005b346101b1575f3660031901126101b1576003546040516001600160a01b039091168152602090f35b346101b15760403660031901126101b157610ac36101b5565b60243590811515908183036101b1576001600160a01b038116928315610b4a57610b0b610b1c92335f52600160205260405f209060018060a01b03165f5260205260405f2090565b9060ff801983541691151516179055565b6040519081527f17307eab39ab6107e8899845ad3d59bd9653f200f220920489ca2b5937696c3160203392a3005b60405162ced3e160e81b81525f6004820152602490fd5b346101b15760203660031901126101b157610b7a6101b5565b610b82611494565b6001600160a01b03165f818152600560205260408120805460ff191660011790557f6d81a01b39982517ba331aeb4f387b0f9cc32334b65bb9a343a077973cf7adf59080a2005b346101b15760203660031901126101b1576001600160a01b03610bea6101b5565b165f526005602052602060ff60405f2054166040519015158152f35b346101b15760203660031901126101b1576004355f526004602052602060405f2054604051908152f35b346101b15760403660031901126101b157602060ff610c80610c506101b5565b610c586101cb565b6001600160a01b039182165f9081526001865260408082209290931681526020919091522090565b54166040519015158152f35b346101b15760a03660031901126101b157610ca56101b5565b610cad6101cb565b60843567ffffffffffffffff81116101b157610ccd90369060040161071a565b906001600160a01b03838116903382141580610d84575b610d5d57821615610d455715610d2e5761080792610d266064356044359160405192600184526020840152604083019160018352606084015260808301604052565b929091611796565b604051626a0d4560e21b81525f6004820152602490fd5b604051632bfa23e760e11b81525f6004820152602490fd5b60405163711bec9160e11b81523360048201526001600160a01b0386166024820152604490fd5b505f82815260016020908152604080832033845290915290205460ff1615610ce4565b346101b15760203660031901126101b157610dc06101b5565b610dc8611494565b6001600160a01b03908116908115610e1b57600354826bffffffffffffffffffffffff60a01b821617600355167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e05f80a3005b604051631e4fbdf760e01b81525f6004820152602490fd5b346101b157610e41366103c0565b90610e4a611494565b805f526004602060048152604090815f2080549086820391821161062a57556001600160a01b038616801561104157610ea386869160405192600184526020840152604083019160018352606084015260808301604052565b9590915f8551610eb281610643565b5282518751908181036110205750505f5b8351811015610f6f578060051b8a86808388010151928b010151610f0782610ef2855f525f60205260405f2090565b9060018060a01b03165f5260205260405f2090565b54818110610f325791610ef2610f2b92600196959403935f525f60205260405f2090565b5501610ec3565b89516303dee4c560e01b81526001600160a01b03909316838c01908152602081019190915260408101919091526060810183905281906080010390fd5b507f49995e5dd6158cf69ad3e9777c46755a1a826a446c6416992167462dad033b2a8489875f85888d8660018351148514610fe557918201519101518451918252602082015233907fc3d58168c5ae7397731d063d5bbf3d657854427343f4c083240f7aacaa2d0f6290604090a45b51908152a3005b506110187f4a39dc06d4c0dbc64b70af90fd698a233a518aa5d07e595d983b8c0526c8f7fb9186519182913395836114c0565b0390a4610fde565b8651635b05999160e01b815260048101919091526024810191909152604490fd5b8251626a0d4560e21b81525f6004820152602490fd5b634e487b7160e01b5f52601160045260245ffd5b805191908290602001825e015f815290565b6103e880820491620186a091908284106110ed5750506110a4610177916110d09304611352565b6110df6040519384926110ca602085016901a195b9b1bd8dad959160b61b8152600a0190565b9061106b565b6218183160e91b815260030190565b03601f198101835282610664565b90915081831061117557508060649183049206048061112357506101776110a461111692611352565b603160f91b815260010190565b610177906110df61111661114261113c61116896611352565b93611352565b6110ca6040519687956110ca602088016901a195b9b1bd8dad959160b61b8152600a0190565b601760f91b815260010190565b82156111d557606483106111a15750506101776110a461119492611352565b606d60f81b815260010190565b906064910604806111bc57506101776110a461119492611352565b610177906110df61119461114261113c61116896611352565b6111e8925061017791506110a490611352565b606b60f81b815260010190565b9190820180921161062a57565b604051906040820182811067ffffffffffffffff82111761065f576040526001825260203681840137565b9061123782610686565b6112446040519182610664565b8281528092611255601f1991610686565b0190602036910137565b80511561126c5760200190565b634e487b7160e01b5f52603260045260245ffd5b805182101561126c5760209160051b010190565b919091805183518082036113085750506112ae815161122d565b905f5b815181101561130157806112ef60019260051b5f602080808489010151938b01015182525260405f209060018060a01b03165f5260205260405f2090565b546112fa8286611280565b52016112b1565b5090925050565b604051635b05999160e01b815260048101919091526024810191909152604490fd5b90611334826106fe565b6113416040519182610664565b8281528092611255601f19916106fe565b805f917a184f03e93ff9f4daa797ed6e38ed64bf6a1f01000000000000000080821015611486575b506d04ee2d6d415b85acef810000000080831015611477575b50662386f26fc1000080831015611468575b506305f5e10080831015611459575b506127108083101561144a575b50606482101561143a575b600a80921015611430575b6001908160216113e96001870161132a565b95860101905b6113fb575b5050505090565b5f19019083906f181899199a1a9b1b9c1cb0b131b232b360811b8282061a83530491821561142b579190826113ef565b6113f4565b91600101916113d7565b91906064600291049101916113cc565b6004919392049101915f6113c1565b6008919392049101915f6113b4565b6010919392049101915f6113a5565b6020919392049101915f611393565b60409350810491505f61137a565b6003546001600160a01b031633036114a857565b60405163118cdaa760e01b8152336004820152602490fd5b90916114d761017793604084526040840190610886565b916020818403910152610886565b91909182518251908181036113085750505f5b835181101561155c57600581901b84810160209081015191850101516001929184906001600160a01b038216611532575b505050016114f8565b61155291610ef261154a925f525f60205260405f2090565b9182546111f5565b90555f8381611529565b509160018151145f146115bb576020908101519181015160408051938452918301526001600160a01b03909216915f9133917fc3d58168c5ae7397731d063d5bbf3d657854427343f4c083240f7aacaa2d0f629190819081015b0390a4565b7f4a39dc06d4c0dbc64b70af90fd698a233a518aa5d07e595d983b8c0526c8f7fb6115b65f939460405191829160018060a01b0316963395836114c0565b93929180518351908181036113085750505f5b81518110156116f157600581901b82810160209081015191860101516001600160a01b0392918590898516611671575b600194821661164f575b5050500161160c565b61166791610ef261154a925f525f60205260405f2090565b90555f8481611646565b919293905061168b89610ef2845f525f60205260405f2090565b548381106116ba57918691846001969594036116b28c610ef2855f525f60205260405f2090565b55945061163c565b6040516303dee4c560e01b81526001600160a01b038b16600482015260248101919091526044810184905260648101839052608490fd5b508051939493919291600103611753576020908101519181015160408051938452918301526001600160a01b03928316939092169133917fc3d58168c5ae7397731d063d5bbf3d657854427343f4c083240f7aacaa2d0f6291819081016115b6565b6040516001600160a01b03938416949093169233927f4a39dc06d4c0dbc64b70af90fd698a233a518aa5d07e595d983b8c0526c8f7fb9282916115b691836114c0565b91939290936117a7828287866115f9565b6001600160a01b038516806117bf575b505050505050565b81516001036117e85750936020806117dd9601519201519233611a8a565b5f80808080806117b7565b8594919293943b6117ff575b5050505050506117dd565b611827935f6020946040519687958694859363bc197c8160e01b9b8c86523360048701611930565b03925af15f91816118b0575b506118725782611841611962565b805191908261186b57604051632bfa23e760e11b81526001600160a01b0383166004820152602490fd5b9050602001fd5b6001600160e01b0319160361188d57505f80808080806117f4565b604051632bfa23e760e11b81526001600160a01b03919091166004820152602490fd5b6118ca91925060203d60201161060c576105fd8183610664565b905f611833565b908160209103126101b157516101778161023d565b9261191461017795936119229360018060a01b031686525f602087015260a0604087015260a0860190610886565b908482036060860152610886565b916080818403910152610142565b93906101779593611914916119229460018060a01b03809216885216602087015260a0604087015260a0860190610886565b3d1561198c573d90611973826106fe565b916119816040519384610664565b82523d5f602084013e565b606090565b909260a0926101779594600180861b031683525f6020840152604083015260608201528160808201520190610142565b919261017795949160a094600180871b038092168552166020840152604083015260608201528160808201520190610142565b9293919093843b611a07575b5050505050565b602091611a2a604051948593849363f23a6e6160e01b9889865260048601611991565b03815f6001600160a01b0388165af15f9181611a69575b50611a4f5782611841611962565b6001600160e01b0319160361188d57505f80808080611a00565b611a8391925060203d60201161060c576105fd8183610664565b905f611a41565b939290949194853b611a9e57505050505050565b611ac1602093604051958694859463f23a6e6160e01b998a8752600487016119c1565b03815f6001600160a01b0388165af15f9181611b01575b50611ae65782611841611962565b6001600160e01b0319160361188d57505f80808080806117b7565b611b1b91925060203d60201161060c576105fd8183610664565b905f611ad856fea2646970667358221220582f3b8b29a87023f457dafc272d2fb9338d0beec0dc16fb197e26b85da0771764736f6c63430008190033000000000000000000000000b2f776e9c1c926c4b2e54182fac058da9af0b6a5000000000000000000000000d5f76a363135a0781295043241f18496daa31e3d0000000000000000000000008727b25ece0098c4c5571fbea30257f527bc964500000000000000000000000097de4fa69e79bd9b812111f12f38767ada36e58e77e9b912bc18f8931d6bf02e4a6c8920848a4de015bbe080f36f82639c8db295
Deployed Bytecode
0x6080806040526004361015610012575f80fd5b5f905f3560e01c90816302e7940514611796575080630e9d7dd11461172e57806338d52e0f146116ea5780633a59aac7146116a65780633f4ba83a14611635578063473d0452146115f55780634bd2d7f9146115b5578063508f3630146115985780635bc90b52146115525780635c975abb1461152d57806361b8ce8c1461150557806361d027b3146114dd57806369fe0e2d1461146a5780636e5deac414610f3f578063715018a614610ee25780637a94043714610d825780637adbf97314610d1a5780637dc0d1d014610cf15780637f815e5614610cc35780638456cb5914610c605780638686ebcc14610c435780638da5cb5b14610c1a57806396d457af146108a3578063b3d7f6b914610878578063bc063e1a1461085b578063c889fd7d146107ae578063d9d02b01146106f6578063ddca3f43146106d8578063ddcaddbf146105f3578063eb3b8a5f1461055a578063ef113d0f14610503578063f0f442601461046d578063f1378457146102205763f2fde38b14610194575f80fd5b3461021d57602036600319011261021d576101ad6117b9565b6101b5611a3d565b6001600160a01b0390811690811561020457600154826001600160601b0360a01b821617600155167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e05f80a380f35b604051631e4fbdf760e01b815260048101849052602490fd5b80fd5b503461021d57604036600319011261021d5761023a6117cf565b60243590610246611a69565b811561045b5761025581611898565b1561044957604051627eeac760e11b81523360048201526001600160401b0382811660248301819052602095919391929091907f000000000000000000000000437f681fc3c71c21eb3033a14b7590b4cdca329b6001600160a01b0316908781604481855afa90811561043e579087918691610409575b50106103f757803b156103f357604051637a94c56560e11b81523360048201526001600160401b0383166024820152604481018790529084908290606490829084905af180156103e8579084916103d0575b505061032990611b34565b60405163a9059cbb60e01b86820152336024820152604480820186905281529260808401908111848210176103bc57600193610388916040527f000000000000000000000000b2f776e9c1c926c4b2e54182fac058da9af0b6a5611bd0565b6040518481527f53307341a0e8c285b0e4488d042d0ab431a1becc0771bbdb906b57a2b4087594863392a355604051908152f35b634e487b7160e01b5f52604160045260245ffd5b6103d990611813565b6103e457825f61031e565b8280fd5b6040513d86823e3d90fd5b8380fd5b604051630e13fa7160e31b8152600490fd5b809250898092503d8311610437575b6104228183611826565b81010312610433578690515f6102cc565b5f80fd5b503d610418565b6040513d87823e3d90fd5b6040516353193d3760e01b8152600490fd5b60405163dee12e0360e01b8152600490fd5b503461021d57602036600319011261021d576104876117b9565b61048f611a69565b610497611a3d565b6001600160a01b031680156104f15760207fcb7ef3e545f5cdb893f5c568ba710fe08f336375a2d9fd66e161033f8fc09ef39160045490806001600160601b0360a01b831617600455846040519216178152a16001815580f35b60405163d92e233d60e01b8152600490fd5b503461021d57602036600319011261021d5760e06105276105226117cf565b6119ca565b94604094919493929351961515875215156020870152151560408601526060850152608084015260a083015260c0820152f35b503461021d57602036600319011261021d5760043565ffffffffffff81168091036105ef578160409160e093526008602052208054906001810154906002810154600382015491600460018060a01b03910154169260ff604051956001600160401b0381168752818160401c161515602088015260481c16151560408601526060850152608084015260a083015260c0820152f35b5080fd5b503461021d57604036600319011261021d5761060d6117cf565b6001600160401b0360243591610621611a69565b610629611a3d565b1690818352600960205265ffffffffffff6040842054169081156106c65781845260086020526040842060ff815460401c166106b457600381015482106106a257817fbd8c81882ee7e90afad11c4f70486f25c0bc860285d7ba8fd3ee1fde95a607f49260026020930155604051908152a36001815580f35b604051631c362e1160e31b8152600490fd5b604051636d70cc8960e11b8152600490fd5b60405163eed34f0760e01b8152600490fd5b503461021d578060031936011261021d576020600254604051908152f35b503461021d57602036600319011261021d576001600160401b036107186117cf565b610720611a3d565b16808252600960205265ffffffffffff60408320541680156106c657808352600860205260408320805460ff8160401c166106b45760ff8160481c1661079c5760ff60481b191669010000000000000000001790557f023dff3dced99e172de9866eb8fbddaf670d6096c898c86020d86d28c728e6588380a380f35b60405163acf542ab60e01b8152600490fd5b503461021d57602036600319011261021d576001600160401b036107d06117cf565b6107d8611a3d565b16808252600960205265ffffffffffff60408320541680156106c657808352600860205260408320805460ff8160401c166106b45760ff8160481c16156108495760ff60481b191690557fe78dd8e5fb9202ec320b9ef5cc26cc642ee92cafa66816332b1d0b79b39baf618380a380f35b604051632934c26360e21b8152600490fd5b503461021d578060031936011261021d5760206040516103e88152f35b503461021d57602036600319011261021d5760406108976004356119a1565b82519182526020820152f35b503461021d57606036600319011261021d576108bd6117cf565b602435916044356001600160a01b03818116939092918490036104335761092f906108e6611a69565b6108ee611a3d565b604084600354168560055416906006549183518096819482936357732dbb60e11b84526004840160209093929193604081019460018060a01b031681520152565b03915afa908115610c0f5783928492610bdb575b506001600160401b03808092169316831115610bc9576109628261187f565b81804216911610610bb7576040519163bd85b03960e01b835283600484015260209788846024818a7f000000000000000000000000437f681fc3c71c21eb3033a14b7590b4cdca329b165afa938415610bac578694610b7d575b5083811115610b6b578486526009895265ffffffffffff97886040882054168015159081610b51575b50610b3f57600154898160a81c16998a14610b2b5765ffffffffffff60a81b191660018a810160a81b65ffffffffffff60a81b169190911790556040519760e08901948086118a8710176103bc576001998b97858e97888b6004968f8f906040917fc35303cbdb16af3e918634bdda99307f23696c65fba6f7139e645fe22eb56fe29f835289526008858a0195828752838b01958387528560608d019916895260808c01998a5260a08c019a8b5260c08c019e8f528352522096511669ff00000000000000000068ff000000000000000088549451151560401b169251151560481b169269ffffffffffffffffffff19161717178455518d840155516002830155516003820155019151166001600160601b0360a01b82541617905584865260098252604086208465ffffffffffff19825416179055604051908152a355604051908152f35b634e487b7160e01b88526011600452602488fd5b604051632e6d917160e21b8152600490fd5b9050875260088a5260ff604088205460401c16155f6109e5565b604051637fb1277b60e01b8152600490fd5b9093508881813d8311610ba5575b610b958183611826565b810103126104335751925f6109bc565b503d610b8b565b6040513d88823e3d90fd5b60405163a527363160e01b8152600490fd5b604051630bc672fd60e21b8152600490fd5b909250610c00915060403d604011610c08575b610bf88183611826565b81019061185b565b90915f610943565b503d610bee565b6040513d85823e3d90fd5b503461021d578060031936011261021d576001546040516001600160a01b039091168152602090f35b503461021d578060031936011261021d5760206040516127108152f35b503461021d578060031936011261021d57610c79611a3d565b610c81611a8a565b6001805460ff60a01b1916600160a01b1790556040513381527f62e78cea01bee320cd4e420270b5ea74000d11b0c9f74754ebdbfc544b05a25890602090a180f35b503461021d57602036600319011261021d576020610ce7610ce26117cf565b611898565b6040519015158152f35b503461021d578060031936011261021d576003546040516001600160a01b039091168152602090f35b503461021d57602036600319011261021d57610d346117b9565b610d3c611a3d565b600380546001600160a01b0319166001600160a01b039290921691821790557f3df77beb5db05fcdd70a30fc8adf3f83f9501b68579455adbd100b81809403948280a280f35b503461021d576020908160031936011261021d57610d9e6117cf565b90610da7611a69565b6001600160401b039182168082526007845260408220546001600160a01b03908116610ed0576040517f000000000000000000000000437f681fc3c71c21eb3033a14b7590b4cdca329b821694610dbc80830191821183831017610ebc576040918391611c2b8339878152858982015203019084f08015610c0f571692803b156103e457828091602460405180948193635b52ebef60e11b83528960048401525af18015610c0f57610ea8575b50908160019282526007855260408220846001600160601b0360a01b8254161790557f5ca11f4052e8cadbe59c1a0cd3acc22f4977f49509b0f7cd04d2dbb19aa5940c85604051868152a255604051908152f35b610eb28391611813565b6105ef575f610e54565b634e487b7160e01b86526041600452602486fd5b60405163a6ef0ba160e01b8152600490fd5b503461021d578060031936011261021d57610efb611a3d565b600180546001600160a01b031981169091555f906001600160a01b03167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e08280a380f35b503461043357606036600319011261043357610f596117cf565b60243590610f65611a69565b610f6d611a8a565b6001600160401b0381165f52600960205265ffffffffffff60405f20541680156106c6575f52600860205260405f2091825460ff8160401c166106b45760481c60ff1661145857801561144657610fd0610fc960025483611aab565b80926117e5565b9260038101805492610fe28685611806565b9360028401548095116114345760048401545f956001600160a01b039091169182611331575b505050611016868354611806565b9182815560443585106112fb578415159285846112e8575b505050806112aa575b507f000000000000000000000000b2f776e9c1c926c4b2e54182fac058da9af0b6a59061106686303385611ada565b61113c575b50507f000000000000000000000000437f681fc3c71c21eb3033a14b7590b4cdca329b6001600160a01b03169050803b156103f357604051630ab714fb60e11b81523360048201526001600160401b0383166024820152604481018490529084908290606490829084905af180156103e857611128575b506020926001916001600160401b036040519185835216907f4c209b5fc8ad50758f13e2e1088ba56a560dff690a1c6fef26394f4c03821c4f863392a355604051908152f35b6111328491611813565b6103e4575f6110e2565b60048201546001600160a01b0316803b15610433575f80916024604051809481936395e1d97760e01b83528960048401525af1801561129f5761128c575b508261119591309060018060a01b0360048601541690611ada565b600481015485906001600160a01b03908116907f000000000000000000000000437f681fc3c71c21eb3033a14b7590b4cdca329b16803b156103e457604051630ab714fb60e11b81526001600160a01b039290921660048301526001600160401b03861660248301526044820185905282908290606490829084905af1801561128157611269575b5050600460018060a01b03910154166040519182527fef970e06880f8548844c9f7420575bbf879f646b6f7b8f4c241ca6b7678e4eb060206001600160401b03851693a35f808061106b565b61127290611813565b61127d57845f61121d565b8480fd5b6040513d84823e3d90fd5b611297919650611813565b5f948261117a565b6040513d5f823e3d90fd5b6004546112e291906001600160a01b0316337f000000000000000000000000b2f776e9c1c926c4b2e54182fac058da9af0b6a5611ada565b5f611037565b6112f191611806565b90555f808561102e565b60405162461bcd60e51b815260206004820152600e60248201526d5768616c6520736c69707061676560901b6044820152606490fd5b604051637cb5dbbd60e11b815290602082600481875afa801561129f578a925f916113f4575b50611363575b50611008565b5f9497509161137861137e9260209594611806565b906117e5565b8089106113ed575b6024906040519485938492630d384a6f60e11b845260048401525af190811561129f575f916113bb575b50925f80878161135d565b90506020813d6020116113e5575b816113d660209383611826565b8101031261043357515f6113b0565b3d91506113c9565b5087611386565b919250506020813d60201161142c575b8161141160209383611826565b8101031261043357519081151582036104335789915f611357565b3d9150611404565b604051639670687960e01b8152600490fd5b60405163a776bb4d60e01b8152600490fd5b604051630b4cba3160e31b8152600490fd5b3461043357602036600319011261043357600435611486611a69565b61148e611a3d565b6103e881116114cb576020817e172ddfc5ae88d08b3de01a5a187667c37a5a53989e8c175055cb6c993792a792600255604051908152a160015f55005b60405163f4df6ae560e01b8152600490fd5b34610433575f366003190112610433576004546040516001600160a01b039091168152602090f35b34610433575f36600319011261043357602065ffffffffffff60015460a81c16604051908152f35b34610433575f36600319011261043357602060ff60015460a01c166040519015158152f35b346104335760203660031901126104335760043561156e611a3d565b806006557f54ef723920b7713f0db1bd7930ad9789cc963b5df84af3396860d2cd45d0ec815f80a2005b34610433575f366003190112610433576020600654604051908152f35b34610433576020366003190112610433576001600160401b036115d66117cf565b165f526009602052602065ffffffffffff60405f205416604051908152f35b34610433576020366003190112610433576001600160401b036116166117cf565b165f526007602052602060018060a01b0360405f205416604051908152f35b34610433575f3660031901126104335761164d611a3d565b60015460ff8160a01c16156116945760ff60a01b19166001556040513381527f5db9ee0a495bf2e6ff9c91a7834c1ba4fdd244a5e8aa4e537bd38aeae4b073aa90602090a1005b604051638dfc202b60e01b8152600490fd5b34610433575f366003190112610433576040517f000000000000000000000000437f681fc3c71c21eb3033a14b7590b4cdca329b6001600160a01b03168152602090f35b34610433575f366003190112610433576040517f000000000000000000000000b2f776e9c1c926c4b2e54182fac058da9af0b6a56001600160a01b03168152602090f35b34610433576020366003190112610433576117476117b9565b61174f611a3d565b6001600160a01b031680156104f157600580546001600160a01b031916821790557fba2b62c9461657dff915dd9c97496dc57d1ff2cf348b2b947cc5e9e72947b1425f80a2005b34610433575f366003190112610433576005546001600160a01b03168152602090f35b600435906001600160a01b038216820361043357565b600435906001600160401b038216820361043357565b919082039182116117f257565b634e487b7160e01b5f52601160045260245ffd5b919082018092116117f257565b6001600160401b0381116103bc57604052565b90601f801991011681019081106001600160401b038211176103bc57604052565b51906001600160401b038216820361043357565b91908260409103126104335761187c602061187584611847565b9301611847565b90565b90610e106001600160401b03809316019182116117f257565b6001600160401b0380911690815f52600960205260409065ffffffffffff825f2054165f526008602052815f209260ff8454841c166119985760035460055460065485516357732dbb60e11b81526001600160a01b039283166004820152602481019190915291859183916044918391165afa93841561198f575f915f9561196e575b506119258561187f565b8480421691161061195e575082161015928361194c575b505050611947575f90565b600190565b600101549116101590505f808061193c565b5163a527363160e01b8152600490fd5b9080955061198892503d8611610c0857610bf88183611826565b935f61191b565b513d5f823e3d90fd5b50505050600190565b9060025480155f146119b257505f90565b6119bf6119c69184611aab565b80936117e5565b9190565b6001600160401b03165f52600960205265ffffffffffff60405f2054168015611a2c575f52600860205260405f2080549060018101549060036002820154910154611a1581836117e5565b60019560ff808760401c169660481c169493929190565b505f905f905f905f905f905f905f90565b6001546001600160a01b03163303611a5157565b60405163118cdaa760e01b8152336004820152602490fd5b60025f5414611a785760025f55565b604051633ee5aeb560e01b8152600490fd5b60ff60015460a01c16611a9957565b60405163d93c066560e01b8152600490fd5b81810291612710918291818504149015170215611acd57808204910615150190565b63ad251c275f526004601cfd5b6040516323b872dd60e01b60208201526001600160a01b03928316602482015292909116604483015260648083019390935291815260a08101918183106001600160401b038411176103bc57611b3292604052611bd0565b565b6001600160401b0380911690815f52600960205265ffffffffffff60405f20541690815f52600860205260405f209081549060ff8260401c16611bc957811615611bb75768ff00000000000000001916680100000000000000001790557ff93f4d3a19af6703dc8c284b246c3681ae2e0087236087d929b85670589576d35f80a3565b604051631b086e7b60e11b8152600490fd5b5050505050565b905f602091828151910182855af11561129f575f513d611c2157506001600160a01b0381163b155b611bff5750565b604051635274afe760e01b81526001600160a01b039091166004820152602490fd5b60011415611bf856fe60c0604090808252346103e8578181610dbc803803809161002082856103ec565b8339810103126103e85780516001600160a01b039190828116908190036103e8576020918201516001600160401b039283821692918390036103e85781156103e8575f92826080528060a052865193848094622b600360e21b82526004938483015260249586915afa9384156103de575f946103c2575b508351958587116103b0576001968754958887811c971680156103a6575b85881014610394578190601f97888111610346575b5085908883116001146102e7575f926102dc575b50505f19600383901b1c191690881b1787555b60805116925f60a051828a5180978193634e41a1fb60e01b8352878301525afa9384156102d2575f946102ae575b50835195861161029c57600254918783811c93168015610292575b8484101461028157505083811161023d575b50809284116001146101d957509282939183925f946101ce575b50501b915f199060031b1c1916176002555b51610931908161048b8239608051818181610146015281816103970152818161041b015281816104d10152610671015260a05181818160fb015281816101920152818161036a0152818161052001526106430152f35b015192505f80610166565b919083601f19811660025f52845f20945f905b88838310610223575050501061020b575b505050811b01600255610178565b01515f1960f88460031b161c191690555f80806101fd565b8587015188559096019594850194879350908101906101ec565b60025f52815f208480870160051c820192848810610278575b0160051c019086905b82811061026d57505061014c565b5f815501869061025f565b92508192610256565b602290634e487b7160e01b5f52525ffd5b92607f169261013a565b634e487b7160e01b5f90815260418352fd5b6102cb9194503d805f833e6102c381836103ec565b810190610423565b925f61011f565b88513d5f823e3d90fd5b015190505f806100de565b908a9350601f19831691845f52875f20925f5b898282106103305750508411610318575b505050811b0187556100f1565b01515f1960f88460031b161c191690555f808061030b565b8385015186558e979095019493840193016102fa565b909150895f52855f208880850160051c82019288861061038b575b918c91869594930160051c01915b82811061037d5750506100ca565b5f81558594508c910161036f565b92508192610361565b85602285634e487b7160e01b5f52525ffd5b96607f16966100b5565b83604183634e487b7160e01b5f52525ffd5b6103d79194503d805f833e6102c381836103ec565b925f610097565b87513d5f823e3d90fd5b5f80fd5b601f909101601f19168101906001600160401b0382119082101761040f57604052565b634e487b7160e01b5f52604160045260245ffd5b602080828403126103e85781516001600160401b03928382116103e857019183601f840112156103e857825190811161040f576040519361046d601f8301601f19168401866103ec565b8185528282850101116103e85780825f94018386015e830101529056fe6080604090808252600480361015610015575f80fd5b5f3560e01c91826306fdde031461079e57508163095ea7b3146106f157816318160ddd1461062457816323b872dd14610465578163313ce5671461044a5781633a59aac71461040757816370a082311461032d57816395d89b411461022b578163a9059cbb1461011e57508063ad8f5008146100e45763dd62ed3e14610099575f80fd5b346100e057806003193601126100e0576020906100b4610885565b6100bc61089b565b9060018060a01b038091165f525f8452825f2091165f528252805f20549051908152f35b5f80fd5b50346100e0575f3660031901126100e057602090517f00000000000000000000000000000000000000000000000000000000000000008152f35b82346100e057806003193601126100e057610137610885565b602435906001600160a01b03907f00000000000000000000000000000000000000000000000000000000000000008216803b156100e05784516361f3f6e960e01b8152339681019687526001600160a01b03831660208801527f0000000000000000000000000000000000000000000000000000000000000000604088015260608701859052955f91879182908490829060800103925af194851561022157602095610212575b50835192835216907fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef843392a35160018152f35b61021b906108b1565b856101de565b84513d5f823e3d90fd5b82346100e0575f3660031901126100e0578051905f9260025460018160011c91600181168015610323575b602094858510821461031057508387529081156102f05750600114610296575b505050610288826102929403836108d9565b519182918261085b565b0390f35b60025f9081529295507f405787fa12a823e0f2b7631cc41b3ba8828b3321ca811111fa75cd3aa3bb5ace5b8284106102dd5750505082610292946102889282010194610276565b80548685018801529286019281016102c1565b60ff1916868501525050151560051b830101925061028882610292610276565b602290634e487b7160e01b5f525260245ffd5b92607f1692610256565b9050346100e057602091826003193601126100e0578261034b610885565b8251627eeac760e11b81526001600160a01b03918216948101949094527f00000000000000000000000000000000000000000000000000000000000000006024850152839060449082907f0000000000000000000000000000000000000000000000000000000000000000165afa9182156103fd575f926103ce575b5051908152f35b9091508281813d83116103f6575b6103e681836108d9565b810103126100e05751905f6103c7565b503d6103dc565b50513d5f823e3d90fd5b82346100e0575f3660031901126100e057517f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03168152602090f35b82346100e0575f3660031901126100e0576020905160128152f35b82346100e05760603660031901126100e05761047f610885565b9161048861089b565b906044359160018060a01b039081861692835f526020965f8852865f20335f52885285875f2054106105f057845f525f8852865f20335f5288525f19875f2054036105b9575b837f00000000000000000000000000000000000000000000000000000000000000001691823b156100e05787516361f3f6e960e01b81526001600160a01b0392831691810191825291841660208201527f000000000000000000000000000000000000000000000000000000000000000060408201526060810187905290915f9183919082908490829060800103925af180156105af57917fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef939188936105a0575b5086519586521693a35160018152f35b6105a9906108b1565b88610590565b86513d5f823e3d90fd5b845f525f8852865f20335f528852865f208054908782039182116105dd57556104ce565b601184634e487b7160e01b5f525260245ffd5b865162461bcd60e51b8152808301899052600e60248201526d1b9bdd08185d5d1a1bdc9a5e995960921b6044820152606490fd5b82346100e0575f3660031901126100e057805163bd85b03960e01b81527f0000000000000000000000000000000000000000000000000000000000000000928101929092526020826024817f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03165afa9081156106e8575f916106b3575b6020925051908152f35b90506020823d6020116106e0575b816106ce602093836108d9565b810103126100e05760209151906106a9565b3d91506106c1565b513d5f823e3d90fd5b82346100e057806003193601126100e05761070a610885565b6001600160a01b031660243581156107645760209350335f525f8452825f20825f52845280835f205582519081527f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925843392a35160018152f35b825162461bcd60e51b81526020818601526014602482015273617070726f7665207a65726f206164647265737360601b6044820152606490fd5b83346100e0575f3660031901126100e0575f9260018054908160011c91600181168015610851575b602094858510821461031057508387529081156102f057506001146107f757505050610288826102929403836108d9565b60015f9081529295507fb10e2d527612073b26eecdfd717e6a320cf44b4afac2b0732d9fcbe2b7fa0cf65b82841061083e5750505082610292946102889282010194610276565b8054868501880152928601928101610822565b92607f16926107c6565b602060409281835280519182918282860152018484015e5f828201840152601f01601f1916010190565b600435906001600160a01b03821682036100e057565b602435906001600160a01b03821682036100e057565b67ffffffffffffffff81116108c557604052565b634e487b7160e01b5f52604160045260245ffd5b90601f8019910116810190811067ffffffffffffffff8211176108c55760405256fea26469706673582212207f3711ca38e587c8d8e1da805191c92c4123070a29e49baa108d17ee3d3c52d964736f6c63430008190033a2646970667358221220454358eb0b9f92eca5fb7dc710ed2d5dd0cb3de3c4e7836139038914c9f9042d64736f6c63430008190033
Constructor Arguments (ABI-Encoded and is the last bytes of the Contract Creation Code above)
000000000000000000000000b2f776e9c1c926c4b2e54182fac058da9af0b6a5000000000000000000000000d5f76a363135a0781295043241f18496daa31e3d0000000000000000000000008727b25ece0098c4c5571fbea30257f527bc964500000000000000000000000097de4fa69e79bd9b812111f12f38767ada36e58e77e9b912bc18f8931d6bf02e4a6c8920848a4de015bbe080f36f82639c8db295
-----Decoded View---------------
Arg [0] : asset_ (address): 0xb2F776e9c1C926C4b2e54182Fac058dA9Af0B6A5
Arg [1] : oracle_ (address): 0xD5F76a363135A0781295043241f18496dAa31E3d
Arg [2] : treasury_ (address): 0x8727B25eCe0098c4C5571FBea30257F527Bc9645
Arg [3] : oracleSender_ (address): 0x97De4fa69E79Bd9b812111f12F38767AdA36E58E
Arg [4] : oracleKey_ (bytes32): 0x77e9b912bc18f8931d6bf02e4a6c8920848a4de015bbe080f36f82639c8db295
-----Encoded View---------------
5 Constructor Arguments found :
Arg [0] : 000000000000000000000000b2f776e9c1c926c4b2e54182fac058da9af0b6a5
Arg [1] : 000000000000000000000000d5f76a363135a0781295043241f18496daa31e3d
Arg [2] : 0000000000000000000000008727b25ece0098c4c5571fbea30257f527bc9645
Arg [3] : 00000000000000000000000097de4fa69e79bd9b812111f12f38767ada36e58e
Arg [4] : 77e9b912bc18f8931d6bf02e4a6c8920848a4de015bbe080f36f82639c8db295
Loading...
Loading
Loading...
Loading
Multichain Portfolio | 34 Chains
Chain | Token | Portfolio % | Price | Amount | Value |
---|
Loading...
Loading
Loading...
Loading
[ Download: CSV Export ]
[ Download: CSV Export ]
A contract address hosts a smart contract, which is a set of code stored on the blockchain that runs when predetermined conditions are met. Learn more about addresses in our Knowledge Base.