Source Code
Overview
APE Balance
APE Value
$0.00Multichain Info
N/A
View more zero value Internal Transactions in Advanced View mode
Advanced mode:
Cross-Chain Transactions
Loading...
Loading
Contract Name:
ApeLiquidityBonds
Compiler Version
v0.8.22+commit.4fc1097e
Optimization Enabled:
Yes with 200 runs
Other Settings:
paris EvmVersion
Contract Source Code (Solidity Standard Json-Input format)
// Copyright 2025 Energi Core
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program. If not,
// see <http://www.gnu.org/licenses/>.
// Energi Governance system is the fundamental part of Energi Core.
// NOTE: It's not allowed to change the compiler due to byte-to-byte
// match requirement.
/// @title LiquidityBonds
/// @author Energi Core
pragma solidity 0.8.22;
import { OwnableUpgradeable } from "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";
import { PausableUpgradeable } from "@openzeppelin/contracts-upgradeable/security/PausableUpgradeable.sol";
import {
ReentrancyGuardUpgradeable
} from "@openzeppelin/contracts-upgradeable/security/ReentrancyGuardUpgradeable.sol";
import { ERC721Upgradeable } from "@openzeppelin/contracts-upgradeable/token/ERC721/ERC721Upgradeable.sol";
import { IApeLiquidityBondLocker as ILiquidityBondLocker } from "./interface/IApeLiquidityBondLocker.sol";
import { IOperatorRegistry } from "../interface/IOperatorRegistry.sol";
import { Strings } from "@openzeppelin/contracts/utils/Strings.sol";
import { Base64 } from "@openzeppelin/contracts/utils/Base64.sol";
import {
IAlgebraNonfungiblePositionManager as INonFungiblePositionManager
} from "./interface/IAlgebraNonfungiblePositionManager.sol";
contract ApeLiquidityBonds is ERC721Upgradeable, OwnableUpgradeable, PausableUpgradeable, ReentrancyGuardUpgradeable {
using Strings for uint256;
// ------------------------------------------------------------------------
// Events
// ------------------------------------------------------------------------
event MinterAdded(address indexed minter);
event MinterRemoved(address indexed minter);
event LiquidityBondLockerUpdated(address indexed oldLiquidityBondLocker, address indexed newLiquidityBondLocker);
event LiquidityBondMinted(address indexed to, uint256 indexed bondId, uint256 indexed uniswapV3PositionId);
event LiquidityBondBurned(uint256 indexed bondId);
event OperatorRegistryUpdated(address indexed oldOperatorRegistry, address indexed newOperatorRegistry);
// ------------------------------------------------------------------------
// Storage
// ------------------------------------------------------------------------
string public bondType; // Type of the bond, can be used for categorization
struct Bond {
uint256 bondId; // Bond ID
uint256 uniswapV3PositionId; // Uniswap V3 position ID
bool isRedemeed; // Whether the bond is locked
}
uint256 public currentIndex; // Current index for the next bond ID
mapping(uint256 => Bond) public bonds; // Mapping of bond ID to Bond struct
mapping(address => bool) public minters; // Mapping of minters
address public liquidityBondLocker; // Address of the liquidity bond locker
address public operatorRegistry; // Address of the operator registry
// ------------------------------------------------------------------------
// Modifiers
// ------------------------------------------------------------------------
/**
* @notice Modifier to check if the caller is a minter or the owner
*/
modifier onlyMinterOrOwner() {
require(minters[msg.sender] || msg.sender == owner(), "LiquidityBonds:: Not a minter or owner");
_;
}
/**
* @notice Internal function to validate a transfer, according to whether the calling address,
* from address and to address is an EOA or Whitelisted
* @param from the address of the from target to be validated
* @param to the address of the to target to be validated
*/
modifier validateTransfer(address from, address to) {
require(
msg.sender == tx.origin || IOperatorRegistry(operatorRegistry).isOperatorAllowed(address(this), msg.sender),
"LiquidityBonds: Sender is not whitelist"
);
uint256 codeLength;
assembly {
codeLength := extcodesize(to)
}
require(
codeLength == 0 || IOperatorRegistry(operatorRegistry).isOperatorAllowed(address(this), to),
"LiquidityBonds: Receiver not whitelist"
);
_;
}
/**
* @notice Internal function to validate a approve
* @param _operator the address of the from target to be validated
*/
modifier validateApprove(address _operator) {
uint256 codeLength;
assembly {
codeLength := extcodesize(_operator)
}
require(
codeLength == 0 || IOperatorRegistry(operatorRegistry).isOperatorAllowed(address(this), _operator),
"LiquidityBonds: Operator is not whitelisted"
);
_;
}
// ------------------------------------------------------------------------
// Initialization
// ------------------------------------------------------------------------
/**
* @notice Initializes the contract
* @dev Only callable once
* @param liquidityBondLocker_ ~ Address of the liquidity bond locker
*/
function initialize(
string memory name_,
string memory symbol_,
address liquidityBondLocker_,
address operatorRegistry_,
string memory bondType_
) external initializer {
__ERC721_init(name_, symbol_);
__Ownable_init();
__Pausable_init();
__ReentrancyGuard_init();
liquidityBondLocker = liquidityBondLocker_;
operatorRegistry = operatorRegistry_;
bondType = bondType_;
minters[liquidityBondLocker_] = true; // Set the liquidity bond locker as a minter
}
// ------------------------------------------------------------------------
// Public Functions
// ------------------------------------------------------------------------
/**
* @notice Mints a new liquidity bond
* @dev Only callable by the minter or owner
* @param _to ~ Address to mint the bond to
* @param _uniswapV3PositionId ~ Uniswap V3 position ID
*/
function mint(address _to, uint256 _uniswapV3PositionId) external onlyMinterOrOwner whenNotPaused nonReentrant {
require(_to != address(0), "LiquidityBonds:: Address is zero");
require(_uniswapV3PositionId != 0, "LiquidityBonds:: Uniswap V3 position ID is zero");
ILiquidityBondLocker locker = ILiquidityBondLocker(liquidityBondLocker);
require(locker.locks(_uniswapV3PositionId).isLocked == false, "LiquidityBonds:: Position is already locked");
currentIndex++;
bonds[currentIndex] = Bond(currentIndex, _uniswapV3PositionId, false);
_mint(_to, currentIndex);
emit LiquidityBondMinted(_to, currentIndex, _uniswapV3PositionId);
}
/**
* @notice Burn liquidity bond
* @dev Only callable by the minter or owner
* @param _bondId ~ Token ID of the bond
*/
function burn(uint256 _bondId) external onlyMinterOrOwner whenNotPaused nonReentrant {
require(_bondId != 0, "LiquidityBonds:: Bond ID is zero");
require(_exists(_bondId), "LiquidityBonds:: Bond does not exist");
bonds[_bondId].isRedemeed = true;
_burn(_bondId);
emit LiquidityBondBurned(_bondId);
}
// ------------------------------------------------------------------------
// Owner Functions
// ------------------------------------------------------------------------
/**
* @notice Pauses contract
*/
function pause() external onlyOwner {
_pause();
}
/**
* @notice Unpauses contract
*/
function unpause() external onlyOwner {
_unpause();
}
/**
* @notice Adds a new minter
* @dev Only callable by the owner
* @param _minter ~ Address of the new minter
*/
function addMinter(address _minter) external onlyOwner {
require(_minter != address(0), "LiquidityBonds:: Address is zero");
require(!minters[_minter], "LiquidityBonds:: Address is already a minter");
minters[_minter] = true;
emit MinterAdded(_minter);
}
/**
* @notice Removes a minter
* @dev Only callable by the owner
* @param _minter ~ Address of the minter
*/
function removeMinter(address _minter) external onlyOwner {
require(_minter != address(0), "LiquidityBonds:: Address is zero");
require(minters[_minter], "LiquidityBonds:: Address is not a minter");
minters[_minter] = false;
emit MinterRemoved(_minter);
}
/**
* @notice Updates the liquidity bond locker address
* @dev Only callable by the owner
* @param _liquidityBondLocker ~ Address of the new liquidity bond locker
*/
function updateLiquidityBondLocker(address _liquidityBondLocker) external onlyOwner {
require(_liquidityBondLocker != address(0), "LiquidityBonds:: Address is zero");
require(_liquidityBondLocker != liquidityBondLocker, "LiquidityBonds:: Address is already set");
address oldLiquidityBondLocker = liquidityBondLocker;
liquidityBondLocker = _liquidityBondLocker;
emit LiquidityBondLockerUpdated(oldLiquidityBondLocker, _liquidityBondLocker);
}
/**
* @notice Updates the operator registry address
* @dev Only callable by the owner
* @param _operatorRegistry ~ Address of the new operator registry
*/
function updateOperatorRegistry(address _operatorRegistry) external onlyOwner {
require(_operatorRegistry != address(0), "LiquidityBonds:: Address is zero");
require(_operatorRegistry != operatorRegistry, "LiquidityBonds:: Address is already set");
address oldOperatorRegistry = operatorRegistry;
operatorRegistry = _operatorRegistry;
emit OperatorRegistryUpdated(oldOperatorRegistry, _operatorRegistry);
}
// ------------------------------------------------------------------------
// Internal
// ------------------------------------------------------------------------
/// @dev Gets current timestamp
function _currentTime() internal view virtual returns (uint256) {
return block.timestamp;
}
/**
* @notice Extracts a portion of a string
* @param str The input string to extract from
* @param startIndex The starting position to extract from
* @param endIndex The end position to extract to
* @return The extracted substring
*/
function substring(string memory str, uint256 startIndex, uint256 endIndex) internal pure returns (string memory) {
bytes memory strBytes = bytes(str);
bytes memory result = new bytes(endIndex - startIndex);
for (uint256 i = startIndex; i < endIndex; i++) {
result[i - startIndex] = strBytes[i];
}
return string(result);
}
/**
* @notice Formats a number from 18 decimals to a 4 decimal place string
* @param value The number to format (with 18 decimals)
* @return The formatted string with 4 decimal places
*/
function formatDecimals(uint256 value) internal pure returns (string memory) {
if (value == 0) {
return "0.0000";
}
string memory str = value.toString();
uint256 length = bytes(str).length;
if (length <= 18) {
uint256 zeros = 18 - length;
string memory pad;
for (uint256 i = 0; i < zeros; i++) {
pad = string(abi.encodePacked("0", pad));
}
str = string(abi.encodePacked(pad, str));
length = 18;
}
uint256 decimalPosition = length - 18;
string memory wholeNumber = decimalPosition == 0 ? "0" : substring(str, 0, decimalPosition);
string memory decimals = substring(str, decimalPosition, decimalPosition + 4);
return string(abi.encodePacked(wholeNumber, ".", decimals));
}
/**
* @dev Note it will validate the from and to address in the allowlist
*/
function _transfer(address from, address to, uint256 tokenId) internal virtual override validateTransfer(from, to) {
super._transfer(from, to, tokenId);
}
/**
* @dev Note it will validate operator is allowed or not
*/
function _approve(address to, uint256 tokenId) internal virtual override validateApprove(to) {
super._approve(to, tokenId);
}
/**
* @dev Approve `operator` to operate on all of `owner` tokens
*/
function _setApprovalForAll(
address owner,
address operator,
bool approved
) internal virtual override validateApprove(operator) {
super._setApprovalForAll(owner, operator, approved);
}
// ------------------------------------------------------------------------
// View
// ------------------------------------------------------------------------
/**
* @notice Get bond information
* @param _bondId ID of the bond
* @return uniswapV3PositionId ID of the Uniswap V3 position
* @return startTime Start time of the bond
* @return duration Duration of the bond
* @return durationLeft Time left for the bond to unlock
* @return rewardsGMI GMI rewards for the bond
* @return rewardsWETH9 WETH9 rewards for the bond
*/
function getBondInfo(
uint256 _bondId
)
public
view
returns (
uint256 uniswapV3PositionId,
uint256 startTime,
uint256 duration,
uint256 durationLeft,
uint256 rewardsGMI,
uint256 rewardsWETH9
)
{
Bond memory bond = bonds[_bondId];
ILiquidityBondLocker locker = ILiquidityBondLocker(liquidityBondLocker);
ILiquidityBondLocker.Lock memory lock = locker.locks(bond.uniswapV3PositionId);
ILiquidityBondLocker.Bond memory currentBond = locker.bonds(lock.bondId);
uint256 timeLeft = _currentTime() >= currentBond.lockDuration ? 0 : currentBond.lockDuration - _currentTime();
(rewardsGMI) = locker.getRewards0(bond.uniswapV3PositionId);
(, , , , , , , , , uint128 tokensOwed0, uint128 tokensOwed1) = INonFungiblePositionManager(
locker.uniswapPositionManager()
).positions(bond.uniswapV3PositionId);
return (
lock.uniswapV3PositionId,
lock.startTime,
currentBond.lockDuration - locker.startTime(bond.bondId),
timeLeft,
rewardsGMI + tokensOwed1,
tokensOwed0
);
}
/**
* @notice Generate SVG header with defs and filters
* @return SVG header string
*/
function _generateSVGHeader() private pure returns (string memory) {
return
'<svg width="290" height="500" viewBox="0 0 290 500" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"><defs><filter id="f1"><feImage result="p0" xlink:href="data:image/svg+xml;base64,PHN2ZyB3aWR0aD0nMjkwJyBoZWlnaHQ9JzUwMCcgdmlld0JveD0nMCAwIDI5MCA1MDAnIHhtbG5zPSdodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2Zyc+PHJlY3Qgd2lkdGg9JzI5MHB4JyBoZWlnaHQ9JzUwMHB4JyBmaWxsPScjMWM3ZDRiJy8+PC9zdmc+"/> <feImage result="p1" xlink:href="data:image/svg+xml;base64,PHN2ZyB3aWR0aD0nMjkwJyBoZWlnaHQ9JzUwMCcgdmlld0JveD0nMCAwIDI5MCA1MDAnIHhtbG5zPSdodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2Zyc+PGNpcmNsZSBjeD0nMjIyJyBjeT0nMjAyJyByPScxMjBweCcgZmlsbD0nI2ZmZjk5NycvPjwvc3ZnPg==" /> <feImage result="p2" xlink:href="data:image/svg+xml;base64,PHN2ZyB3aWR0aD0nMjkwJyBoZWlnaHQ9JzUwMCcgdmlld0JveD0nMCAwIDI5MCA1MDAnIHhtbG5zPSdodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2Zyc+PGNpcmNsZSBjeD0nODQnIGN5PSczODEnIHI9JzEyMHB4JyBmaWxsPScjOWM3MjM4Jy8+PC9zdmc+" /> <feImage result="p3" xlink:href="data:image/svg+xml;base64,PHN2ZyB3aWR0aD0nMjkwJyBoZWlnaHQ9JzUwMCcgdmlld0JveD0nMCAwIDI5MCA1MDAnIHhtbG5zPSdodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2Zyc+PGNpcmNsZSBjeD0nMjU2JyBjeT0nNDA3JyByPScxMDBweCcgZmlsbD0nIzRkNmIxNCcvPjwvc3ZnPg==" /> <feBlend mode="overlay" in="p0" in2="p1" /> <feBlend mode="exclusion" in2="p2" /> <feBlend mode="overlay" in2="p3" result="blendOut" /> <feGaussianBlur in="blendOut" stdDeviation="42" /> </filter> <clipPath id="corners"> <rect width="290" height="500" rx="42" ry="42" /> </clipPath> <path id="text-path-a" d="M40 12 H250 A28 28 0 0 1 278 40 V460 A28 28 0 0 1 250 488 H40 A28 28 0 0 1 12 460 V40 A28 28 0 0 1 40 12 z" /> <path id="minimap" d="M234 444C234 457.949 242.21 463 253 463" /> <filter id="top-region-blur"> <feGaussianBlur in="SourceGraphic" stdDeviation="24" /> </filter> <linearGradient id="grad-up" x1="1" x2="0" y1="1" y2="0"> <stop offset="0.0" stop-color="white" stop-opacity="1" /> <stop offset=".9" stop-color="white" stop-opacity="0" /> </linearGradient> <linearGradient id="grad-down" x1="0" x2="1" y1="0" y2="1"> <stop offset="0.0" stop-color="white" stop-opacity="1" /> <stop offset="0.9" stop-color="white" stop-opacity="0" /> </linearGradient> <mask id="fade-up" maskContentUnits="objectBoundingBox"> <rect width="1" height="1" fill="url(#grad-up)" /> </mask> <mask id="fade-down" maskContentUnits="objectBoundingBox"> <rect width="1" height="1" fill="url(#grad-down)" /> </mask> <mask id="none" maskContentUnits="objectBoundingBox"> <rect width="1" height="1" fill="white" /> </mask> <linearGradient id="grad-symbol"> <stop offset="0.7" stop-color="white" stop-opacity="1" /> <stop offset=".95" stop-color="white" stop-opacity="0" /> </linearGradient> <mask id="fade-symbol" maskContentUnits="userSpaceOnUse"> <rect width="290px" height="200px" fill="url(#grad-symbol)" /> </mask> </defs> <g clip-path="url(#corners)"> <rect fill="#1c7d4b" x="0px" y="0px" width="290px" height="500px" /> <rect style="filter: url(#f1)" x="0px" y="0px" width="290px" height="500px" /> <g style="filter:url(#top-region-blur); transform:scale(1.5); transform-origin:center top;"> <rect fill="none" x="0px" y="0px" width="290px" height="500px" /> <ellipse cx="50%" cy="0px" rx="180px" ry="120px" fill="#000" opacity="0.85" /> </g> <rect x="0" y="0" width="290" height="500" rx="42" ry="42" fill="rgba(0,0,0,0)" stroke="rgba(255,255,255,0.2)" /> </g> <text text-rendering="optimizeSpeed"> <textPath startOffset="-100%" fill="white" font-family="Verdana" font-size="10px" xlink:href="#text-path-a">';
}
/**
* @notice Generate SVG text paths
* @param symbolStr Symbol string
* @param tokenIdStr Token ID string
* @return SVG text paths string
*/
function _generateTextPaths(
string memory symbolStr,
string memory tokenIdStr
) private pure returns (string memory) {
return
string(
abi.encodePacked(
symbolStr,
" #",
tokenIdStr,
'<animate additive="sum" attributeName="startOffset" from="0%" to="100%" begin="0s" dur="30s" repeatCount="indefinite" /> </textPath> <textPath startOffset="0%" fill="white" font-family="Verdana" font-size="10px" xlink:href="#text-path-a">',
symbolStr,
" #",
tokenIdStr,
'<animate additive="sum" attributeName="startOffset" from="0%" to="100%" begin="0s" dur="30s" repeatCount="indefinite" /> </textPath> <textPath startOffset="0%" fill="white" font-family="Verdana" font-size="10px" xlink:href="#text-path-a">',
symbolStr,
" #",
tokenIdStr,
'<animate additive="sum" attributeName="startOffset" from="0%" to="100%" begin="0s" dur="30s" repeatCount="indefinite" /> </textPath> <textPath startOffset="-50%" fill="white" font-family="Verdana" font-size="10px" xlink:href="#text-path-a">',
symbolStr,
" #",
tokenIdStr,
'<animate additive="sum" attributeName="startOffset" from="0%" to="100%" begin="0s" dur="30s" repeatCount="indefinite" /> </textPath> </text> <g mask="url(#fade-symbol)"> <rect fill="none" x="0px" y="0px" width="290px" height="200px" /> <text y="70px" x="32px" fill="white" font-family="Verdana" font-weight="200" font-size="36px">LP BOND</text> <text y="115px" x="32px" fill="white" font-family="Verdana" font-weight="200" font-size="36px">#',
tokenIdStr,
'</text> </g> <rect x="16" y="16" width="258" height="468" rx="26" ry="26" fill="rgba(0,0,0,0)" stroke="rgba(255,255,255,0.2)" />'
)
);
}
/**
* @notice Generate SVG data sections
* @param positionId Position ID string
* @param gmiRewards GMI rewards string
* @param wethRewards WETH rewards string
* @return SVG data sections string
*/
function _generateDataSections(
string memory positionId,
string memory gmiRewards,
string memory wethRewards
) private pure returns (string memory) {
return
string(
abi.encodePacked(
' <g style="transform:translate(29px, 384px)"> <rect width="230px" height="26px" rx="8px" ry="8px" fill="rgba(0,0,0,0.6)" /> <text x="12px" y="17px" font-family="Verdana" font-size="12px" fill="white"> <tspan fill="rgba(255,255,255,0.6)">Position Id: </tspan>',
positionId,
'</text> </g> <g style="transform:translate(29px, 414px)"> <rect width="230px" height="26px" rx="8px" ry="8px" fill="rgba(0,0,0,0.6)" /> <text x="12px" y="17px" font-family="Verdana" font-size="12px" fill="white"> <tspan fill="rgba(255,255,255,0.6)">GMI Rewards: </tspan>',
gmiRewards,
'</text> </g> <g style="transform:translate(29px, 444px)"> <rect width="230px" height="26px" rx="8px" ry="8px" fill="rgba(0,0,0,0.6)" /> <text x="12px" y="17px" font-family="Verdana" font-size="12px" fill="white"> <tspan fill="rgba(255,255,255,0.6)">WETH Rewards: </tspan>',
wethRewards,
"</text> </g> </svg>"
)
);
}
/**
* @notice Get the token URI for a bond
* @param _tokenId ID of the bond
* @return Token URI for the bond
*/
function tokenURI(uint256 _tokenId) public view override returns (string memory) {
(
uint256 uniswapV3PositionId,
uint256 startTime,
uint256 duration,
uint256 durationLeft,
uint256 rewardsGMI,
uint256 rewardsWETH9
) = getBondInfo(_tokenId);
string memory tokenIdStr = _tokenId.toString();
string memory symbolStr = this.symbol();
string memory svg = string(
abi.encodePacked(
_generateSVGHeader(),
_generateTextPaths(symbolStr, tokenIdStr),
_generateDataSections(
uniswapV3PositionId.toString(),
formatDecimals(rewardsGMI),
formatDecimals(rewardsWETH9)
)
)
);
uint256 unlockTime = _currentTime() + durationLeft;
string memory attributes = string(
abi.encodePacked(
'", "attributes": [{"trait_type": "Algebra V3 Position ID", "value": "',
uniswapV3PositionId.toString(),
'"}, {"trait_type": "Start Time", "value": "',
startTime.toString(),
'"}, {"trait_type": "Bond Duration", "value": "',
duration.toString(),
'"}, {"trait_type": "GMI Rewards", "value": "',
rewardsGMI.toString(),
'"}, {"trait_type": "Partner token Rewards", "value": "',
rewardsWETH9.toString(),
'"}, {"display_type": "date", "trait_type": "Unlock Time", "value": ',
unlockTime.toString(),
"}]}"
)
);
string memory json = string(
abi.encodePacked(
'{"name": "',
symbolStr,
" #",
tokenIdStr,
'", "description": "A locked Uniswap V3 liquidity bond with rewards.", "image": "data:image/svg+xml;base64,',
Base64.encode(bytes(svg)),
attributes
)
);
return string(abi.encodePacked("data:application/json;base64,", Base64.encode(bytes(json))));
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (access/Ownable.sol)
pragma solidity ^0.8.0;
import "../utils/ContextUpgradeable.sol";
import "../proxy/utils/Initializable.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.
*
* By default, the owner account will be the one that deploys the contract. 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 OwnableUpgradeable is Initializable, ContextUpgradeable {
address private _owner;
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
/**
* @dev Initializes the contract setting the deployer as the initial owner.
*/
function __Ownable_init() internal onlyInitializing {
__Ownable_init_unchained();
}
function __Ownable_init_unchained() internal onlyInitializing {
_transferOwnership(_msgSender());
}
/**
* @dev Returns the address of the current owner.
*/
function owner() public view virtual returns (address) {
return _owner;
}
/**
* @dev Throws if called by any account other than the owner.
*/
modifier onlyOwner() {
require(owner() == _msgSender(), "Ownable: caller is not the owner");
_;
}
/**
* @dev Leaves the contract without owner. It will not be possible to call
* `onlyOwner` functions anymore. Can only be called by the current owner.
*
* NOTE: Renouncing ownership will leave the contract without an owner,
* thereby removing 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 {
require(newOwner != address(0), "Ownable: new owner is the zero address");
_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);
}
/**
* This empty reserved space is put in place to allow future versions to add new
* variables without shifting down storage in the inheritance chain.
* See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps
*/
uint256[49] private __gap;
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.5.0) (proxy/utils/Initializable.sol)
pragma solidity ^0.8.0;
import "../../utils/AddressUpgradeable.sol";
/**
* @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed
* behind a proxy. Since proxied contracts do not make use of a constructor, it's common to move constructor logic to an
* external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer
* function so it can only be called once. The {initializer} modifier provided by this contract will have this effect.
*
* TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as
* possible by providing the encoded function call as the `_data` argument to {ERC1967Proxy-constructor}.
*
* CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure
* that all initializers are idempotent. This is not verified automatically as constructors are by Solidity.
*
* [CAUTION]
* ====
* Avoid leaving a contract uninitialized.
*
* An uninitialized contract can be taken over by an attacker. This applies to both a proxy and its implementation
* contract, which may impact the proxy. To initialize the implementation contract, you can either invoke the
* initializer manually, or you can include a constructor to automatically mark it as initialized when it is deployed:
*
* [.hljs-theme-light.nopadding]
* ```
* /// @custom:oz-upgrades-unsafe-allow constructor
* constructor() initializer {}
* ```
* ====
*/
abstract contract Initializable {
/**
* @dev Indicates that the contract has been initialized.
*/
bool private _initialized;
/**
* @dev Indicates that the contract is in the process of being initialized.
*/
bool private _initializing;
/**
* @dev Modifier to protect an initializer function from being invoked twice.
*/
modifier initializer() {
// If the contract is initializing we ignore whether _initialized is set in order to support multiple
// inheritance patterns, but we only do this in the context of a constructor, because in other contexts the
// contract may have been reentered.
require(_initializing ? _isConstructor() : !_initialized, "Initializable: contract is already initialized");
bool isTopLevelCall = !_initializing;
if (isTopLevelCall) {
_initializing = true;
_initialized = true;
}
_;
if (isTopLevelCall) {
_initializing = false;
}
}
/**
* @dev Modifier to protect an initialization function so that it can only be invoked by functions with the
* {initializer} modifier, directly or indirectly.
*/
modifier onlyInitializing() {
require(_initializing, "Initializable: contract is not initializing");
_;
}
function _isConstructor() private view returns (bool) {
return !AddressUpgradeable.isContract(address(this));
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (security/Pausable.sol)
pragma solidity ^0.8.0;
import "../utils/ContextUpgradeable.sol";
import "../proxy/utils/Initializable.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 PausableUpgradeable is Initializable, ContextUpgradeable {
/**
* @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);
bool private _paused;
/**
* @dev Initializes the contract in unpaused state.
*/
function __Pausable_init() internal onlyInitializing {
__Pausable_init_unchained();
}
function __Pausable_init_unchained() internal onlyInitializing {
_paused = false;
}
/**
* @dev Returns true if the contract is paused, and false otherwise.
*/
function paused() public view virtual returns (bool) {
return _paused;
}
/**
* @dev Modifier to make a function callable only when the contract is not paused.
*
* Requirements:
*
* - The contract must not be paused.
*/
modifier whenNotPaused() {
require(!paused(), "Pausable: paused");
_;
}
/**
* @dev Modifier to make a function callable only when the contract is paused.
*
* Requirements:
*
* - The contract must be paused.
*/
modifier whenPaused() {
require(paused(), "Pausable: not paused");
_;
}
/**
* @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());
}
/**
* This empty reserved space is put in place to allow future versions to add new
* variables without shifting down storage in the inheritance chain.
* See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps
*/
uint256[49] private __gap;
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (security/ReentrancyGuard.sol)
pragma solidity ^0.8.0;
import "../proxy/utils/Initializable.sol";
/**
* @dev Contract module that helps prevent reentrant calls to a function.
*
* Inheriting from `ReentrancyGuard` will make the {nonReentrant} modifier
* available, which can be applied to functions to make sure there are no nested
* (reentrant) calls to them.
*
* Note that because there is a single `nonReentrant` guard, functions marked as
* `nonReentrant` may not call one another. This can be worked around by making
* those functions `private`, and then adding `external` `nonReentrant` entry
* points to them.
*
* TIP: If you would like to learn more about reentrancy and alternative ways
* to protect against it, check out our blog post
* https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul].
*/
abstract contract ReentrancyGuardUpgradeable is Initializable {
// 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;
function __ReentrancyGuard_init() internal onlyInitializing {
__ReentrancyGuard_init_unchained();
}
function __ReentrancyGuard_init_unchained() internal onlyInitializing {
_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() {
// On the first call to nonReentrant, _notEntered will be true
require(_status != _ENTERED, "ReentrancyGuard: reentrant call");
// Any calls to nonReentrant after this point will fail
_status = _ENTERED;
_;
// By storing the original value once again, a refund is triggered (see
// https://eips.ethereum.org/EIPS/eip-2200)
_status = _NOT_ENTERED;
}
/**
* This empty reserved space is put in place to allow future versions to add new
* variables without shifting down storage in the inheritance chain.
* See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps
*/
uint256[49] private __gap;
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.5.0) (token/ERC721/ERC721.sol)
pragma solidity ^0.8.0;
import "./IERC721Upgradeable.sol";
import "./IERC721ReceiverUpgradeable.sol";
import "./extensions/IERC721MetadataUpgradeable.sol";
import "../../utils/AddressUpgradeable.sol";
import "../../utils/ContextUpgradeable.sol";
import "../../utils/StringsUpgradeable.sol";
import "../../utils/introspection/ERC165Upgradeable.sol";
import "../../proxy/utils/Initializable.sol";
/**
* @dev Implementation of https://eips.ethereum.org/EIPS/eip-721[ERC721] Non-Fungible Token Standard, including
* the Metadata extension, but not including the Enumerable extension, which is available separately as
* {ERC721Enumerable}.
*/
contract ERC721Upgradeable is Initializable, ContextUpgradeable, ERC165Upgradeable, IERC721Upgradeable, IERC721MetadataUpgradeable {
using AddressUpgradeable for address;
using StringsUpgradeable for uint256;
// Token name
string private _name;
// Token symbol
string private _symbol;
// Mapping from token ID to owner address
mapping(uint256 => address) private _owners;
// Mapping owner address to token count
mapping(address => uint256) private _balances;
// Mapping from token ID to approved address
mapping(uint256 => address) private _tokenApprovals;
// Mapping from owner to operator approvals
mapping(address => mapping(address => bool)) private _operatorApprovals;
/**
* @dev Initializes the contract by setting a `name` and a `symbol` to the token collection.
*/
function __ERC721_init(string memory name_, string memory symbol_) internal onlyInitializing {
__ERC721_init_unchained(name_, symbol_);
}
function __ERC721_init_unchained(string memory name_, string memory symbol_) internal onlyInitializing {
_name = name_;
_symbol = symbol_;
}
/**
* @dev See {IERC165-supportsInterface}.
*/
function supportsInterface(bytes4 interfaceId) public view virtual override(ERC165Upgradeable, IERC165Upgradeable) returns (bool) {
return
interfaceId == type(IERC721Upgradeable).interfaceId ||
interfaceId == type(IERC721MetadataUpgradeable).interfaceId ||
super.supportsInterface(interfaceId);
}
/**
* @dev See {IERC721-balanceOf}.
*/
function balanceOf(address owner) public view virtual override returns (uint256) {
require(owner != address(0), "ERC721: balance query for the zero address");
return _balances[owner];
}
/**
* @dev See {IERC721-ownerOf}.
*/
function ownerOf(uint256 tokenId) public view virtual override returns (address) {
address owner = _owners[tokenId];
require(owner != address(0), "ERC721: owner query for nonexistent token");
return owner;
}
/**
* @dev See {IERC721Metadata-name}.
*/
function name() public view virtual override returns (string memory) {
return _name;
}
/**
* @dev See {IERC721Metadata-symbol}.
*/
function symbol() public view virtual override returns (string memory) {
return _symbol;
}
/**
* @dev See {IERC721Metadata-tokenURI}.
*/
function tokenURI(uint256 tokenId) public view virtual override returns (string memory) {
require(_exists(tokenId), "ERC721Metadata: URI query for nonexistent token");
string memory baseURI = _baseURI();
return bytes(baseURI).length > 0 ? string(abi.encodePacked(baseURI, tokenId.toString())) : "";
}
/**
* @dev Base URI for computing {tokenURI}. If set, the resulting URI for each
* token will be the concatenation of the `baseURI` and the `tokenId`. Empty
* by default, can be overriden in child contracts.
*/
function _baseURI() internal view virtual returns (string memory) {
return "";
}
/**
* @dev See {IERC721-approve}.
*/
function approve(address to, uint256 tokenId) public virtual override {
address owner = ERC721Upgradeable.ownerOf(tokenId);
require(to != owner, "ERC721: approval to current owner");
require(
_msgSender() == owner || isApprovedForAll(owner, _msgSender()),
"ERC721: approve caller is not owner nor approved for all"
);
_approve(to, tokenId);
}
/**
* @dev See {IERC721-getApproved}.
*/
function getApproved(uint256 tokenId) public view virtual override returns (address) {
require(_exists(tokenId), "ERC721: approved query for nonexistent token");
return _tokenApprovals[tokenId];
}
/**
* @dev See {IERC721-setApprovalForAll}.
*/
function setApprovalForAll(address operator, bool approved) public virtual override {
_setApprovalForAll(_msgSender(), operator, approved);
}
/**
* @dev See {IERC721-isApprovedForAll}.
*/
function isApprovedForAll(address owner, address operator) public view virtual override returns (bool) {
return _operatorApprovals[owner][operator];
}
/**
* @dev See {IERC721-transferFrom}.
*/
function transferFrom(
address from,
address to,
uint256 tokenId
) public virtual override {
//solhint-disable-next-line max-line-length
require(_isApprovedOrOwner(_msgSender(), tokenId), "ERC721: transfer caller is not owner nor approved");
_transfer(from, to, tokenId);
}
/**
* @dev See {IERC721-safeTransferFrom}.
*/
function safeTransferFrom(
address from,
address to,
uint256 tokenId
) public virtual override {
safeTransferFrom(from, to, tokenId, "");
}
/**
* @dev See {IERC721-safeTransferFrom}.
*/
function safeTransferFrom(
address from,
address to,
uint256 tokenId,
bytes memory _data
) public virtual override {
require(_isApprovedOrOwner(_msgSender(), tokenId), "ERC721: transfer caller is not owner nor approved");
_safeTransfer(from, to, tokenId, _data);
}
/**
* @dev Safely transfers `tokenId` token from `from` to `to`, checking first that contract recipients
* are aware of the ERC721 protocol to prevent tokens from being forever locked.
*
* `_data` is additional data, it has no specified format and it is sent in call to `to`.
*
* This internal function is equivalent to {safeTransferFrom}, and can be used to e.g.
* implement alternative mechanisms to perform token transfer, such as signature-based.
*
* Requirements:
*
* - `from` cannot be the zero address.
* - `to` cannot be the zero address.
* - `tokenId` token must exist and be owned by `from`.
* - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.
*
* Emits a {Transfer} event.
*/
function _safeTransfer(
address from,
address to,
uint256 tokenId,
bytes memory _data
) internal virtual {
_transfer(from, to, tokenId);
require(_checkOnERC721Received(from, to, tokenId, _data), "ERC721: transfer to non ERC721Receiver implementer");
}
/**
* @dev Returns whether `tokenId` exists.
*
* Tokens can be managed by their owner or approved accounts via {approve} or {setApprovalForAll}.
*
* Tokens start existing when they are minted (`_mint`),
* and stop existing when they are burned (`_burn`).
*/
function _exists(uint256 tokenId) internal view virtual returns (bool) {
return _owners[tokenId] != address(0);
}
/**
* @dev Returns whether `spender` is allowed to manage `tokenId`.
*
* Requirements:
*
* - `tokenId` must exist.
*/
function _isApprovedOrOwner(address spender, uint256 tokenId) internal view virtual returns (bool) {
require(_exists(tokenId), "ERC721: operator query for nonexistent token");
address owner = ERC721Upgradeable.ownerOf(tokenId);
return (spender == owner || getApproved(tokenId) == spender || isApprovedForAll(owner, spender));
}
/**
* @dev Safely mints `tokenId` and transfers it to `to`.
*
* Requirements:
*
* - `tokenId` must not exist.
* - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.
*
* Emits a {Transfer} event.
*/
function _safeMint(address to, uint256 tokenId) internal virtual {
_safeMint(to, tokenId, "");
}
/**
* @dev Same as {xref-ERC721-_safeMint-address-uint256-}[`_safeMint`], with an additional `data` parameter which is
* forwarded in {IERC721Receiver-onERC721Received} to contract recipients.
*/
function _safeMint(
address to,
uint256 tokenId,
bytes memory _data
) internal virtual {
_mint(to, tokenId);
require(
_checkOnERC721Received(address(0), to, tokenId, _data),
"ERC721: transfer to non ERC721Receiver implementer"
);
}
/**
* @dev Mints `tokenId` and transfers it to `to`.
*
* WARNING: Usage of this method is discouraged, use {_safeMint} whenever possible
*
* Requirements:
*
* - `tokenId` must not exist.
* - `to` cannot be the zero address.
*
* Emits a {Transfer} event.
*/
function _mint(address to, uint256 tokenId) internal virtual {
require(to != address(0), "ERC721: mint to the zero address");
require(!_exists(tokenId), "ERC721: token already minted");
_beforeTokenTransfer(address(0), to, tokenId);
_balances[to] += 1;
_owners[tokenId] = to;
emit Transfer(address(0), to, tokenId);
_afterTokenTransfer(address(0), to, tokenId);
}
/**
* @dev Destroys `tokenId`.
* The approval is cleared when the token is burned.
*
* Requirements:
*
* - `tokenId` must exist.
*
* Emits a {Transfer} event.
*/
function _burn(uint256 tokenId) internal virtual {
address owner = ERC721Upgradeable.ownerOf(tokenId);
_beforeTokenTransfer(owner, address(0), tokenId);
// Clear approvals
_approve(address(0), tokenId);
_balances[owner] -= 1;
delete _owners[tokenId];
emit Transfer(owner, address(0), tokenId);
_afterTokenTransfer(owner, address(0), tokenId);
}
/**
* @dev Transfers `tokenId` from `from` to `to`.
* As opposed to {transferFrom}, this imposes no restrictions on msg.sender.
*
* Requirements:
*
* - `to` cannot be the zero address.
* - `tokenId` token must be owned by `from`.
*
* Emits a {Transfer} event.
*/
function _transfer(
address from,
address to,
uint256 tokenId
) internal virtual {
require(ERC721Upgradeable.ownerOf(tokenId) == from, "ERC721: transfer from incorrect owner");
require(to != address(0), "ERC721: transfer to the zero address");
_beforeTokenTransfer(from, to, tokenId);
// Clear approvals from the previous owner
_approve(address(0), tokenId);
_balances[from] -= 1;
_balances[to] += 1;
_owners[tokenId] = to;
emit Transfer(from, to, tokenId);
_afterTokenTransfer(from, to, tokenId);
}
/**
* @dev Approve `to` to operate on `tokenId`
*
* Emits a {Approval} event.
*/
function _approve(address to, uint256 tokenId) internal virtual {
_tokenApprovals[tokenId] = to;
emit Approval(ERC721Upgradeable.ownerOf(tokenId), to, tokenId);
}
/**
* @dev Approve `operator` to operate on all of `owner` tokens
*
* Emits a {ApprovalForAll} event.
*/
function _setApprovalForAll(
address owner,
address operator,
bool approved
) internal virtual {
require(owner != operator, "ERC721: approve to caller");
_operatorApprovals[owner][operator] = approved;
emit ApprovalForAll(owner, operator, approved);
}
/**
* @dev Internal function to invoke {IERC721Receiver-onERC721Received} on a target address.
* The call is not executed if the target address is not a contract.
*
* @param from address representing the previous owner of the given token ID
* @param to target address that will receive the tokens
* @param tokenId uint256 ID of the token to be transferred
* @param _data bytes optional data to send along with the call
* @return bool whether the call correctly returned the expected magic value
*/
function _checkOnERC721Received(
address from,
address to,
uint256 tokenId,
bytes memory _data
) private returns (bool) {
if (to.isContract()) {
try IERC721ReceiverUpgradeable(to).onERC721Received(_msgSender(), from, tokenId, _data) returns (bytes4 retval) {
return retval == IERC721ReceiverUpgradeable.onERC721Received.selector;
} catch (bytes memory reason) {
if (reason.length == 0) {
revert("ERC721: transfer to non ERC721Receiver implementer");
} else {
assembly {
revert(add(32, reason), mload(reason))
}
}
}
} else {
return true;
}
}
/**
* @dev Hook that is called before any token transfer. This includes minting
* and burning.
*
* Calling conditions:
*
* - When `from` and `to` are both non-zero, ``from``'s `tokenId` will be
* transferred to `to`.
* - When `from` is zero, `tokenId` will be minted for `to`.
* - When `to` is zero, ``from``'s `tokenId` will be burned.
* - `from` and `to` are never both zero.
*
* To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
*/
function _beforeTokenTransfer(
address from,
address to,
uint256 tokenId
) internal virtual {}
/**
* @dev Hook that is called after any transfer of tokens. This includes
* minting and burning.
*
* Calling conditions:
*
* - when `from` and `to` are both non-zero.
* - `from` and `to` are never both zero.
*
* To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
*/
function _afterTokenTransfer(
address from,
address to,
uint256 tokenId
) internal virtual {}
/**
* This empty reserved space is put in place to allow future versions to add new
* variables without shifting down storage in the inheritance chain.
* See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps
*/
uint256[44] private __gap;
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (token/ERC721/extensions/IERC721Metadata.sol)
pragma solidity ^0.8.0;
import "../IERC721Upgradeable.sol";
/**
* @title ERC-721 Non-Fungible Token Standard, optional metadata extension
* @dev See https://eips.ethereum.org/EIPS/eip-721
*/
interface IERC721MetadataUpgradeable is IERC721Upgradeable {
/**
* @dev Returns the token collection name.
*/
function name() external view returns (string memory);
/**
* @dev Returns the token collection symbol.
*/
function symbol() external view returns (string memory);
/**
* @dev Returns the Uniform Resource Identifier (URI) for `tokenId` token.
*/
function tokenURI(uint256 tokenId) external view returns (string memory);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (token/ERC721/IERC721Receiver.sol)
pragma solidity ^0.8.0;
/**
* @title ERC721 token receiver interface
* @dev Interface for any contract that wants to support safeTransfers
* from ERC721 asset contracts.
*/
interface IERC721ReceiverUpgradeable {
/**
* @dev Whenever an {IERC721} `tokenId` token is transferred to this contract via {IERC721-safeTransferFrom}
* by `operator` from `from`, this function is called.
*
* It must return its Solidity selector to confirm the token transfer.
* If any other value is returned or the interface is not implemented by the recipient, the transfer will be reverted.
*
* The selector can be obtained in Solidity with `IERC721.onERC721Received.selector`.
*/
function onERC721Received(
address operator,
address from,
uint256 tokenId,
bytes calldata data
) external returns (bytes4);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (token/ERC721/IERC721.sol)
pragma solidity ^0.8.0;
import "../../utils/introspection/IERC165Upgradeable.sol";
/**
* @dev Required interface of an ERC721 compliant contract.
*/
interface IERC721Upgradeable is IERC165Upgradeable {
/**
* @dev Emitted when `tokenId` token is transferred from `from` to `to`.
*/
event Transfer(address indexed from, address indexed to, uint256 indexed tokenId);
/**
* @dev Emitted when `owner` enables `approved` to manage the `tokenId` token.
*/
event Approval(address indexed owner, address indexed approved, uint256 indexed tokenId);
/**
* @dev Emitted when `owner` enables or disables (`approved`) `operator` to manage all of its assets.
*/
event ApprovalForAll(address indexed owner, address indexed operator, bool approved);
/**
* @dev Returns the number of tokens in ``owner``'s account.
*/
function balanceOf(address owner) external view returns (uint256 balance);
/**
* @dev Returns the owner of the `tokenId` token.
*
* Requirements:
*
* - `tokenId` must exist.
*/
function ownerOf(uint256 tokenId) external view returns (address owner);
/**
* @dev Safely transfers `tokenId` token from `from` to `to`, checking first that contract recipients
* are aware of the ERC721 protocol to prevent tokens from being forever locked.
*
* Requirements:
*
* - `from` cannot be the zero address.
* - `to` cannot be the zero address.
* - `tokenId` token must exist and be owned by `from`.
* - If the caller is not `from`, it must be have been allowed to move this token by either {approve} or {setApprovalForAll}.
* - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.
*
* Emits a {Transfer} event.
*/
function safeTransferFrom(
address from,
address to,
uint256 tokenId
) external;
/**
* @dev Transfers `tokenId` token from `from` to `to`.
*
* WARNING: Usage of this method is discouraged, use {safeTransferFrom} whenever possible.
*
* Requirements:
*
* - `from` cannot be the zero address.
* - `to` cannot be the zero address.
* - `tokenId` token must be owned by `from`.
* - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}.
*
* Emits a {Transfer} event.
*/
function transferFrom(
address from,
address to,
uint256 tokenId
) external;
/**
* @dev Gives permission to `to` to transfer `tokenId` token to another account.
* The approval is cleared when the token is transferred.
*
* Only a single account can be approved at a time, so approving the zero address clears previous approvals.
*
* Requirements:
*
* - The caller must own the token or be an approved operator.
* - `tokenId` must exist.
*
* Emits an {Approval} event.
*/
function approve(address to, uint256 tokenId) external;
/**
* @dev Returns the account approved for `tokenId` token.
*
* Requirements:
*
* - `tokenId` must exist.
*/
function getApproved(uint256 tokenId) external view returns (address operator);
/**
* @dev Approve or remove `operator` as an operator for the caller.
* Operators can call {transferFrom} or {safeTransferFrom} for any token owned by the caller.
*
* Requirements:
*
* - The `operator` cannot be the caller.
*
* Emits an {ApprovalForAll} event.
*/
function setApprovalForAll(address operator, bool _approved) external;
/**
* @dev Returns if the `operator` is allowed to manage all of the assets of `owner`.
*
* See {setApprovalForAll}
*/
function isApprovedForAll(address owner, address operator) external view returns (bool);
/**
* @dev Safely transfers `tokenId` token from `from` to `to`.
*
* Requirements:
*
* - `from` cannot be the zero address.
* - `to` cannot be the zero address.
* - `tokenId` token must exist and be owned by `from`.
* - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}.
* - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.
*
* Emits a {Transfer} event.
*/
function safeTransferFrom(
address from,
address to,
uint256 tokenId,
bytes calldata data
) external;
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.5.0) (utils/Address.sol)
pragma solidity ^0.8.1;
/**
* @dev Collection of functions related to the address type
*/
library AddressUpgradeable {
/**
* @dev Returns true if `account` is a contract.
*
* [IMPORTANT]
* ====
* It is unsafe to assume that an address for which this function returns
* false is an externally-owned account (EOA) and not a contract.
*
* Among others, `isContract` will return false for the following
* types of addresses:
*
* - an externally-owned account
* - a contract in construction
* - an address where a contract will be created
* - an address where a contract lived, but was destroyed
* ====
*
* [IMPORTANT]
* ====
* You shouldn't rely on `isContract` to protect against flash loan attacks!
*
* Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets
* like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract
* constructor.
* ====
*/
function isContract(address account) internal view returns (bool) {
// This method relies on extcodesize/address.code.length, which returns 0
// for contracts in construction, since the code is only stored at the end
// of the constructor execution.
return account.code.length > 0;
}
/**
* @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://diligence.consensys.net/posts/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.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
*/
function sendValue(address payable recipient, uint256 amount) internal {
require(address(this).balance >= amount, "Address: insufficient balance");
(bool success, ) = recipient.call{value: amount}("");
require(success, "Address: unable to send value, recipient may have reverted");
}
/**
* @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, it is bubbled up by this
* function (like regular Solidity function calls).
*
* 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.
*
* _Available since v3.1._
*/
function functionCall(address target, bytes memory data) internal returns (bytes memory) {
return functionCall(target, data, "Address: low-level call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with
* `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCall(
address target,
bytes memory data,
string memory errorMessage
) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0, errorMessage);
}
/**
* @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`.
*
* _Available since v3.1._
*/
function functionCallWithValue(
address target,
bytes memory data,
uint256 value
) internal returns (bytes memory) {
return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
}
/**
* @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but
* with `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCallWithValue(
address target,
bytes memory data,
uint256 value,
string memory errorMessage
) internal returns (bytes memory) {
require(address(this).balance >= value, "Address: insufficient balance for call");
require(isContract(target), "Address: call to non-contract");
(bool success, bytes memory returndata) = target.call{value: value}(data);
return verifyCallResult(success, returndata, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a static call.
*
* _Available since v3.3._
*/
function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
return functionStaticCall(target, data, "Address: low-level static call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
* but performing a static call.
*
* _Available since v3.3._
*/
function functionStaticCall(
address target,
bytes memory data,
string memory errorMessage
) internal view returns (bytes memory) {
require(isContract(target), "Address: static call to non-contract");
(bool success, bytes memory returndata) = target.staticcall(data);
return verifyCallResult(success, returndata, errorMessage);
}
/**
* @dev Tool to verifies that a low level call was successful, and revert if it wasn't, either by bubbling the
* revert reason using the provided one.
*
* _Available since v4.3._
*/
function verifyCallResult(
bool success,
bytes memory returndata,
string memory errorMessage
) internal pure returns (bytes memory) {
if (success) {
return returndata;
} else {
// 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 {
let returndata_size := mload(returndata)
revert(add(32, returndata), returndata_size)
}
} else {
revert(errorMessage);
}
}
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/Context.sol)
pragma solidity ^0.8.0;
import "../proxy/utils/Initializable.sol";
/**
* @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 ContextUpgradeable is Initializable {
function __Context_init() internal onlyInitializing {
}
function __Context_init_unchained() internal onlyInitializing {
}
function _msgSender() internal view virtual returns (address) {
return msg.sender;
}
function _msgData() internal view virtual returns (bytes calldata) {
return msg.data;
}
/**
* This empty reserved space is put in place to allow future versions to add new
* variables without shifting down storage in the inheritance chain.
* See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps
*/
uint256[50] private __gap;
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/introspection/ERC165.sol)
pragma solidity ^0.8.0;
import "./IERC165Upgradeable.sol";
import "../../proxy/utils/Initializable.sol";
/**
* @dev Implementation of the {IERC165} interface.
*
* Contracts that want to implement ERC165 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);
* }
* ```
*
* Alternatively, {ERC165Storage} provides an easier to use but more expensive implementation.
*/
abstract contract ERC165Upgradeable is Initializable, IERC165Upgradeable {
function __ERC165_init() internal onlyInitializing {
}
function __ERC165_init_unchained() internal onlyInitializing {
}
/**
* @dev See {IERC165-supportsInterface}.
*/
function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
return interfaceId == type(IERC165Upgradeable).interfaceId;
}
/**
* This empty reserved space is put in place to allow future versions to add new
* variables without shifting down storage in the inheritance chain.
* See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps
*/
uint256[50] private __gap;
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/introspection/IERC165.sol)
pragma solidity ^0.8.0;
/**
* @dev Interface of the ERC165 standard, as defined in the
* https://eips.ethereum.org/EIPS/eip-165[EIP].
*
* Implementers can declare support of contract interfaces, which can then be
* queried by others ({ERC165Checker}).
*
* For an implementation, see {ERC165}.
*/
interface IERC165Upgradeable {
/**
* @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[EIP 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 v4.4.1 (utils/Strings.sol)
pragma solidity ^0.8.0;
/**
* @dev String operations.
*/
library StringsUpgradeable {
bytes16 private constant _HEX_SYMBOLS = "0123456789abcdef";
/**
* @dev Converts a `uint256` to its ASCII `string` decimal representation.
*/
function toString(uint256 value) internal pure returns (string memory) {
// Inspired by OraclizeAPI's implementation - MIT licence
// https://github.com/oraclize/ethereum-api/blob/b42146b063c7d6ee1358846c198246239e9360e8/oraclizeAPI_0.4.25.sol
if (value == 0) {
return "0";
}
uint256 temp = value;
uint256 digits;
while (temp != 0) {
digits++;
temp /= 10;
}
bytes memory buffer = new bytes(digits);
while (value != 0) {
digits -= 1;
buffer[digits] = bytes1(uint8(48 + uint256(value % 10)));
value /= 10;
}
return string(buffer);
}
/**
* @dev Converts a `uint256` to its ASCII `string` hexadecimal representation.
*/
function toHexString(uint256 value) internal pure returns (string memory) {
if (value == 0) {
return "0x00";
}
uint256 temp = value;
uint256 length = 0;
while (temp != 0) {
length++;
temp >>= 8;
}
return toHexString(value, length);
}
/**
* @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length.
*/
function toHexString(uint256 value, uint256 length) internal pure returns (string memory) {
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_SYMBOLS[value & 0xf];
value >>= 4;
}
require(value == 0, "Strings: hex length insufficient");
return string(buffer);
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (token/ERC721/IERC721.sol)
pragma solidity ^0.8.20;
import {IERC165} from "../../utils/introspection/IERC165.sol";
/**
* @dev Required interface of an ERC-721 compliant contract.
*/
interface IERC721 is IERC165 {
/**
* @dev Emitted when `tokenId` token is transferred from `from` to `to`.
*/
event Transfer(address indexed from, address indexed to, uint256 indexed tokenId);
/**
* @dev Emitted when `owner` enables `approved` to manage the `tokenId` token.
*/
event Approval(address indexed owner, address indexed approved, uint256 indexed tokenId);
/**
* @dev Emitted when `owner` enables or disables (`approved`) `operator` to manage all of its assets.
*/
event ApprovalForAll(address indexed owner, address indexed operator, bool approved);
/**
* @dev Returns the number of tokens in ``owner``'s account.
*/
function balanceOf(address owner) external view returns (uint256 balance);
/**
* @dev Returns the owner of the `tokenId` token.
*
* Requirements:
*
* - `tokenId` must exist.
*/
function ownerOf(uint256 tokenId) external view returns (address owner);
/**
* @dev Safely transfers `tokenId` token from `from` to `to`.
*
* Requirements:
*
* - `from` cannot be the zero address.
* - `to` cannot be the zero address.
* - `tokenId` token must exist and be owned by `from`.
* - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}.
* - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon
* a safe transfer.
*
* Emits a {Transfer} event.
*/
function safeTransferFrom(address from, address to, uint256 tokenId, bytes calldata data) external;
/**
* @dev Safely transfers `tokenId` token from `from` to `to`, checking first that contract recipients
* are aware of the ERC-721 protocol to prevent tokens from being forever locked.
*
* Requirements:
*
* - `from` cannot be the zero address.
* - `to` cannot be the zero address.
* - `tokenId` token must exist and be owned by `from`.
* - If the caller is not `from`, it must have been allowed to move this token by either {approve} or
* {setApprovalForAll}.
* - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon
* a safe transfer.
*
* Emits a {Transfer} event.
*/
function safeTransferFrom(address from, address to, uint256 tokenId) external;
/**
* @dev Transfers `tokenId` token from `from` to `to`.
*
* WARNING: Note that the caller is responsible to confirm that the recipient is capable of receiving ERC-721
* or else they may be permanently lost. Usage of {safeTransferFrom} prevents loss, though the caller must
* understand this adds an external call which potentially creates a reentrancy vulnerability.
*
* Requirements:
*
* - `from` cannot be the zero address.
* - `to` cannot be the zero address.
* - `tokenId` token must be owned by `from`.
* - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}.
*
* Emits a {Transfer} event.
*/
function transferFrom(address from, address to, uint256 tokenId) external;
/**
* @dev Gives permission to `to` to transfer `tokenId` token to another account.
* The approval is cleared when the token is transferred.
*
* Only a single account can be approved at a time, so approving the zero address clears previous approvals.
*
* Requirements:
*
* - The caller must own the token or be an approved operator.
* - `tokenId` must exist.
*
* Emits an {Approval} event.
*/
function approve(address to, uint256 tokenId) external;
/**
* @dev Approve or remove `operator` as an operator for the caller.
* Operators can call {transferFrom} or {safeTransferFrom} for any token owned by the caller.
*
* Requirements:
*
* - The `operator` cannot be the address zero.
*
* Emits an {ApprovalForAll} event.
*/
function setApprovalForAll(address operator, bool approved) external;
/**
* @dev Returns the account approved for `tokenId` token.
*
* Requirements:
*
* - `tokenId` must exist.
*/
function getApproved(uint256 tokenId) external view returns (address operator);
/**
* @dev Returns if the `operator` is allowed to manage all of the assets of `owner`.
*
* See {setApprovalForAll}
*/
function isApprovedForAll(address owner, address operator) external view returns (bool);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (utils/Base64.sol)
pragma solidity ^0.8.20;
/**
* @dev Provides a set of functions to operate with Base64 strings.
*/
library Base64 {
/**
* @dev Base64 Encoding/Decoding Table
* See sections 4 and 5 of https://datatracker.ietf.org/doc/html/rfc4648
*/
string internal constant _TABLE = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
string internal constant _TABLE_URL = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_";
/**
* @dev Converts a `bytes` to its Bytes64 `string` representation.
*/
function encode(bytes memory data) internal pure returns (string memory) {
return _encode(data, _TABLE, true);
}
/**
* @dev Converts a `bytes` to its Bytes64Url `string` representation.
* Output is not padded with `=` as specified in https://www.rfc-editor.org/rfc/rfc4648[rfc4648].
*/
function encodeURL(bytes memory data) internal pure returns (string memory) {
return _encode(data, _TABLE_URL, false);
}
/**
* @dev Internal table-agnostic conversion
*/
function _encode(bytes memory data, string memory table, bool withPadding) private pure returns (string memory) {
/**
* Inspired by Brecht Devos (Brechtpd) implementation - MIT licence
* https://github.com/Brechtpd/base64/blob/e78d9fd951e7b0977ddca77d92dc85183770daf4/base64.sol
*/
if (data.length == 0) return "";
// If padding is enabled, the final length should be `bytes` data length divided by 3 rounded up and then
// multiplied by 4 so that it leaves room for padding the last chunk
// - `data.length + 2` -> Prepare for division rounding up
// - `/ 3` -> Number of 3-bytes chunks (rounded up)
// - `4 *` -> 4 characters for each chunk
// This is equivalent to: 4 * Math.ceil(data.length / 3)
//
// If padding is disabled, the final length should be `bytes` data length multiplied by 4/3 rounded up as
// opposed to when padding is required to fill the last chunk.
// - `4 * data.length` -> 4 characters for each chunk
// - ` + 2` -> Prepare for division rounding up
// - `/ 3` -> Number of 3-bytes chunks (rounded up)
// This is equivalent to: Math.ceil((4 * data.length) / 3)
uint256 resultLength = withPadding ? 4 * ((data.length + 2) / 3) : (4 * data.length + 2) / 3;
string memory result = new string(resultLength);
assembly ("memory-safe") {
// Prepare the lookup table (skip the first "length" byte)
let tablePtr := add(table, 1)
// Prepare result pointer, jump over length
let resultPtr := add(result, 0x20)
let dataPtr := data
let endPtr := add(data, mload(data))
// In some cases, the last iteration will read bytes after the end of the data. We cache the value, and
// set it to zero to make sure no dirty bytes are read in that section.
let afterPtr := add(endPtr, 0x20)
let afterCache := mload(afterPtr)
mstore(afterPtr, 0x00)
// Run over the input, 3 bytes at a time
for {
} lt(dataPtr, endPtr) {
} {
// Advance 3 bytes
dataPtr := add(dataPtr, 3)
let input := mload(dataPtr)
// To write each character, shift the 3 byte (24 bits) chunk
// 4 times in blocks of 6 bits for each character (18, 12, 6, 0)
// and apply logical AND with 0x3F to bitmask the least significant 6 bits.
// Use this as an index into the lookup table, mload an entire word
// so the desired character is in the least significant byte, and
// mstore8 this least significant byte into the result and continue.
mstore8(resultPtr, mload(add(tablePtr, and(shr(18, input), 0x3F))))
resultPtr := add(resultPtr, 1) // Advance
mstore8(resultPtr, mload(add(tablePtr, and(shr(12, input), 0x3F))))
resultPtr := add(resultPtr, 1) // Advance
mstore8(resultPtr, mload(add(tablePtr, and(shr(6, input), 0x3F))))
resultPtr := add(resultPtr, 1) // Advance
mstore8(resultPtr, mload(add(tablePtr, and(input, 0x3F))))
resultPtr := add(resultPtr, 1) // Advance
}
// Reset the value that was cached
mstore(afterPtr, afterCache)
if withPadding {
// When data `bytes` is not exactly 3 bytes long
// it is padded with `=` characters at the end
switch mod(mload(data), 3)
case 1 {
mstore8(sub(resultPtr, 1), 0x3d)
mstore8(sub(resultPtr, 2), 0x3d)
}
case 2 {
mstore8(sub(resultPtr, 1), 0x3d)
}
}
}
return result;
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (utils/introspection/IERC165.sol)
pragma solidity ^0.8.20;
/**
* @dev Interface of the ERC-165 standard, as defined in the
* https://eips.ethereum.org/EIPS/eip-165[ERC].
*
* Implementers can declare support of contract interfaces, which can then be
* queried by others ({ERC165Checker}).
*
* For an implementation, see {ERC165}.
*/
interface IERC165 {
/**
* @dev Returns true if this contract implements the interface defined by
* `interfaceId`. See the corresponding
* https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[ERC section]
* to learn more about how these ids are created.
*
* This function call must use less than 30 000 gas.
*/
function supportsInterface(bytes4 interfaceId) external view returns (bool);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.3.0) (utils/math/Math.sol)
pragma solidity ^0.8.20;
import {Panic} from "../Panic.sol";
import {SafeCast} from "./SafeCast.sol";
/**
* @dev Standard math utilities missing in the Solidity language.
*/
library Math {
enum Rounding {
Floor, // Toward negative infinity
Ceil, // Toward positive infinity
Trunc, // Toward zero
Expand // Away from zero
}
/**
* @dev Return the 512-bit addition of two uint256.
*
* The result is stored in two 256 variables such that sum = high * 2²⁵⁶ + low.
*/
function add512(uint256 a, uint256 b) internal pure returns (uint256 high, uint256 low) {
assembly ("memory-safe") {
low := add(a, b)
high := lt(low, a)
}
}
/**
* @dev Return the 512-bit multiplication of two uint256.
*
* The result is stored in two 256 variables such that product = high * 2²⁵⁶ + low.
*/
function mul512(uint256 a, uint256 b) internal pure returns (uint256 high, uint256 low) {
// 512-bit multiply [high low] = x * y. Compute the product mod 2²⁵⁶ 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 = high * 2²⁵⁶ + low.
assembly ("memory-safe") {
let mm := mulmod(a, b, not(0))
low := mul(a, b)
high := sub(sub(mm, low), lt(mm, low))
}
}
/**
* @dev Returns the addition of two unsigned integers, with a success flag (no overflow).
*/
function tryAdd(uint256 a, uint256 b) internal pure returns (bool success, uint256 result) {
unchecked {
uint256 c = a + b;
success = c >= a;
result = c * SafeCast.toUint(success);
}
}
/**
* @dev Returns the subtraction of two unsigned integers, with a success flag (no overflow).
*/
function trySub(uint256 a, uint256 b) internal pure returns (bool success, uint256 result) {
unchecked {
uint256 c = a - b;
success = c <= a;
result = c * SafeCast.toUint(success);
}
}
/**
* @dev Returns the multiplication of two unsigned integers, with a success flag (no overflow).
*/
function tryMul(uint256 a, uint256 b) internal pure returns (bool success, uint256 result) {
unchecked {
uint256 c = a * b;
assembly ("memory-safe") {
// Only true when the multiplication doesn't overflow
// (c / a == b) || (a == 0)
success := or(eq(div(c, a), b), iszero(a))
}
// equivalent to: success ? c : 0
result = c * SafeCast.toUint(success);
}
}
/**
* @dev Returns the division of two unsigned integers, with a success flag (no division by zero).
*/
function tryDiv(uint256 a, uint256 b) internal pure returns (bool success, uint256 result) {
unchecked {
success = b > 0;
assembly ("memory-safe") {
// The `DIV` opcode returns zero when the denominator is 0.
result := div(a, b)
}
}
}
/**
* @dev Returns the remainder of dividing two unsigned integers, with a success flag (no division by zero).
*/
function tryMod(uint256 a, uint256 b) internal pure returns (bool success, uint256 result) {
unchecked {
success = b > 0;
assembly ("memory-safe") {
// The `MOD` opcode returns zero when the denominator is 0.
result := mod(a, b)
}
}
}
/**
* @dev Unsigned saturating addition, bounds to `2²⁵⁶ - 1` instead of overflowing.
*/
function saturatingAdd(uint256 a, uint256 b) internal pure returns (uint256) {
(bool success, uint256 result) = tryAdd(a, b);
return ternary(success, result, type(uint256).max);
}
/**
* @dev Unsigned saturating subtraction, bounds to zero instead of overflowing.
*/
function saturatingSub(uint256 a, uint256 b) internal pure returns (uint256) {
(, uint256 result) = trySub(a, b);
return result;
}
/**
* @dev Unsigned saturating multiplication, bounds to `2²⁵⁶ - 1` instead of overflowing.
*/
function saturatingMul(uint256 a, uint256 b) internal pure returns (uint256) {
(bool success, uint256 result) = tryMul(a, b);
return ternary(success, result, type(uint256).max);
}
/**
* @dev Branchless ternary evaluation for `a ? b : c`. Gas costs are constant.
*
* IMPORTANT: This function may reduce bytecode size and consume less gas when used standalone.
* However, the compiler may optimize Solidity ternary operations (i.e. `a ? b : c`) to only compute
* one branch when needed, making this function more expensive.
*/
function ternary(bool condition, uint256 a, uint256 b) internal pure returns (uint256) {
unchecked {
// branchless ternary works because:
// b ^ (a ^ b) == a
// b ^ 0 == b
return b ^ ((a ^ b) * SafeCast.toUint(condition));
}
}
/**
* @dev Returns the largest of two numbers.
*/
function max(uint256 a, uint256 b) internal pure returns (uint256) {
return ternary(a > b, a, b);
}
/**
* @dev Returns the smallest of two numbers.
*/
function min(uint256 a, uint256 b) internal pure returns (uint256) {
return ternary(a < b, a, b);
}
/**
* @dev Returns the average of two numbers. The result is rounded towards
* zero.
*/
function average(uint256 a, uint256 b) internal pure returns (uint256) {
// (a + b) / 2 can overflow.
return (a & b) + (a ^ b) / 2;
}
/**
* @dev Returns the ceiling of the division of two numbers.
*
* This differs from standard division with `/` in that it rounds towards infinity instead
* of rounding towards zero.
*/
function ceilDiv(uint256 a, uint256 b) internal pure returns (uint256) {
if (b == 0) {
// Guarantee the same behavior as in a regular Solidity division.
Panic.panic(Panic.DIVISION_BY_ZERO);
}
// The following calculation ensures accurate ceiling division without overflow.
// Since a is non-zero, (a - 1) / b will not overflow.
// The largest possible result occurs when (a - 1) / b is type(uint256).max,
// but the largest value we can obtain is type(uint256).max - 1, which happens
// when a = type(uint256).max and b = 1.
unchecked {
return SafeCast.toUint(a > 0) * ((a - 1) / b + 1);
}
}
/**
* @dev Calculates floor(x * y / denominator) with full precision. Throws if result overflows a uint256 or
* denominator == 0.
*
* Original credit to Remco Bloemen under MIT license (https://xn--2-umb.com/21/muldiv) with further edits by
* Uniswap Labs also under MIT license.
*/
function mulDiv(uint256 x, uint256 y, uint256 denominator) internal pure returns (uint256 result) {
unchecked {
(uint256 high, uint256 low) = mul512(x, y);
// Handle non-overflow cases, 256 by 256 division.
if (high == 0) {
// Solidity will revert if denominator == 0, unlike the div opcode on its own.
// The surrounding unchecked block does not change this fact.
// See https://docs.soliditylang.org/en/latest/control-structures.html#checked-or-unchecked-arithmetic.
return low / denominator;
}
// Make sure the result is less than 2²⁵⁶. Also prevents denominator == 0.
if (denominator <= high) {
Panic.panic(ternary(denominator == 0, Panic.DIVISION_BY_ZERO, Panic.UNDER_OVERFLOW));
}
///////////////////////////////////////////////
// 512 by 256 division.
///////////////////////////////////////////////
// Make division exact by subtracting the remainder from [high low].
uint256 remainder;
assembly ("memory-safe") {
// Compute remainder using mulmod.
remainder := mulmod(x, y, denominator)
// Subtract 256 bit number from 512 bit number.
high := sub(high, gt(remainder, low))
low := sub(low, remainder)
}
// Factor powers of two out of denominator and compute largest power of two divisor of denominator.
// Always >= 1. See https://cs.stackexchange.com/q/138556/92363.
uint256 twos = denominator & (0 - denominator);
assembly ("memory-safe") {
// Divide denominator by twos.
denominator := div(denominator, twos)
// Divide [high low] by twos.
low := div(low, twos)
// Flip twos such that it is 2²⁵⁶ / twos. If twos is zero, then it becomes one.
twos := add(div(sub(0, twos), twos), 1)
}
// Shift in bits from high into low.
low |= high * twos;
// Invert denominator mod 2²⁵⁶. 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 high
// is no longer required.
result = low * inverse;
return result;
}
}
/**
* @dev Calculates x * y / denominator with full precision, following the selected rounding direction.
*/
function mulDiv(uint256 x, uint256 y, uint256 denominator, Rounding rounding) internal pure returns (uint256) {
return mulDiv(x, y, denominator) + SafeCast.toUint(unsignedRoundsUp(rounding) && mulmod(x, y, denominator) > 0);
}
/**
* @dev Calculates floor(x * y >> n) with full precision. Throws if result overflows a uint256.
*/
function mulShr(uint256 x, uint256 y, uint8 n) internal pure returns (uint256 result) {
unchecked {
(uint256 high, uint256 low) = mul512(x, y);
if (high >= 1 << n) {
Panic.panic(Panic.UNDER_OVERFLOW);
}
return (high << (256 - n)) | (low >> n);
}
}
/**
* @dev Calculates x * y >> n with full precision, following the selected rounding direction.
*/
function mulShr(uint256 x, uint256 y, uint8 n, Rounding rounding) internal pure returns (uint256) {
return mulShr(x, y, n) + SafeCast.toUint(unsignedRoundsUp(rounding) && mulmod(x, y, 1 << n) > 0);
}
/**
* @dev Calculate the modular multiplicative inverse of a number in Z/nZ.
*
* If n is a prime, then Z/nZ is a field. In that case all elements are inversible, except 0.
* If n is not a prime, then Z/nZ is not a field, and some elements might not be inversible.
*
* If the input value is not inversible, 0 is returned.
*
* NOTE: If you know for sure that n is (big) a prime, it may be cheaper to use Fermat's little theorem and get the
* inverse using `Math.modExp(a, n - 2, n)`. See {invModPrime}.
*/
function invMod(uint256 a, uint256 n) internal pure returns (uint256) {
unchecked {
if (n == 0) return 0;
// The inverse modulo is calculated using the Extended Euclidean Algorithm (iterative version)
// Used to compute integers x and y such that: ax + ny = gcd(a, n).
// When the gcd is 1, then the inverse of a modulo n exists and it's x.
// ax + ny = 1
// ax = 1 + (-y)n
// ax ≡ 1 (mod n) # x is the inverse of a modulo n
// If the remainder is 0 the gcd is n right away.
uint256 remainder = a % n;
uint256 gcd = n;
// Therefore the initial coefficients are:
// ax + ny = gcd(a, n) = n
// 0a + 1n = n
int256 x = 0;
int256 y = 1;
while (remainder != 0) {
uint256 quotient = gcd / remainder;
(gcd, remainder) = (
// The old remainder is the next gcd to try.
remainder,
// Compute the next remainder.
// Can't overflow given that (a % gcd) * (gcd // (a % gcd)) <= gcd
// where gcd is at most n (capped to type(uint256).max)
gcd - remainder * quotient
);
(x, y) = (
// Increment the coefficient of a.
y,
// Decrement the coefficient of n.
// Can overflow, but the result is casted to uint256 so that the
// next value of y is "wrapped around" to a value between 0 and n - 1.
x - y * int256(quotient)
);
}
if (gcd != 1) return 0; // No inverse exists.
return ternary(x < 0, n - uint256(-x), uint256(x)); // Wrap the result if it's negative.
}
}
/**
* @dev Variant of {invMod}. More efficient, but only works if `p` is known to be a prime greater than `2`.
*
* From https://en.wikipedia.org/wiki/Fermat%27s_little_theorem[Fermat's little theorem], we know that if p is
* prime, then `a**(p-1) ≡ 1 mod p`. As a consequence, we have `a * a**(p-2) ≡ 1 mod p`, which means that
* `a**(p-2)` is the modular multiplicative inverse of a in Fp.
*
* NOTE: this function does NOT check that `p` is a prime greater than `2`.
*/
function invModPrime(uint256 a, uint256 p) internal view returns (uint256) {
unchecked {
return Math.modExp(a, p - 2, p);
}
}
/**
* @dev Returns the modular exponentiation of the specified base, exponent and modulus (b ** e % m)
*
* Requirements:
* - modulus can't be zero
* - underlying staticcall to precompile must succeed
*
* IMPORTANT: The result is only valid if the underlying call succeeds. When using this function, make
* sure the chain you're using it on supports the precompiled contract for modular exponentiation
* at address 0x05 as specified in https://eips.ethereum.org/EIPS/eip-198[EIP-198]. Otherwise,
* the underlying function will succeed given the lack of a revert, but the result may be incorrectly
* interpreted as 0.
*/
function modExp(uint256 b, uint256 e, uint256 m) internal view returns (uint256) {
(bool success, uint256 result) = tryModExp(b, e, m);
if (!success) {
Panic.panic(Panic.DIVISION_BY_ZERO);
}
return result;
}
/**
* @dev Returns the modular exponentiation of the specified base, exponent and modulus (b ** e % m).
* It includes a success flag indicating if the operation succeeded. Operation will be marked as failed if trying
* to operate modulo 0 or if the underlying precompile reverted.
*
* IMPORTANT: The result is only valid if the success flag is true. When using this function, make sure the chain
* you're using it on supports the precompiled contract for modular exponentiation at address 0x05 as specified in
* https://eips.ethereum.org/EIPS/eip-198[EIP-198]. Otherwise, the underlying function will succeed given the lack
* of a revert, but the result may be incorrectly interpreted as 0.
*/
function tryModExp(uint256 b, uint256 e, uint256 m) internal view returns (bool success, uint256 result) {
if (m == 0) return (false, 0);
assembly ("memory-safe") {
let ptr := mload(0x40)
// | Offset | Content | Content (Hex) |
// |-----------|------------|--------------------------------------------------------------------|
// | 0x00:0x1f | size of b | 0x0000000000000000000000000000000000000000000000000000000000000020 |
// | 0x20:0x3f | size of e | 0x0000000000000000000000000000000000000000000000000000000000000020 |
// | 0x40:0x5f | size of m | 0x0000000000000000000000000000000000000000000000000000000000000020 |
// | 0x60:0x7f | value of b | 0x<.............................................................b> |
// | 0x80:0x9f | value of e | 0x<.............................................................e> |
// | 0xa0:0xbf | value of m | 0x<.............................................................m> |
mstore(ptr, 0x20)
mstore(add(ptr, 0x20), 0x20)
mstore(add(ptr, 0x40), 0x20)
mstore(add(ptr, 0x60), b)
mstore(add(ptr, 0x80), e)
mstore(add(ptr, 0xa0), m)
// Given the result < m, it's guaranteed to fit in 32 bytes,
// so we can use the memory scratch space located at offset 0.
success := staticcall(gas(), 0x05, ptr, 0xc0, 0x00, 0x20)
result := mload(0x00)
}
}
/**
* @dev Variant of {modExp} that supports inputs of arbitrary length.
*/
function modExp(bytes memory b, bytes memory e, bytes memory m) internal view returns (bytes memory) {
(bool success, bytes memory result) = tryModExp(b, e, m);
if (!success) {
Panic.panic(Panic.DIVISION_BY_ZERO);
}
return result;
}
/**
* @dev Variant of {tryModExp} that supports inputs of arbitrary length.
*/
function tryModExp(
bytes memory b,
bytes memory e,
bytes memory m
) internal view returns (bool success, bytes memory result) {
if (_zeroBytes(m)) return (false, new bytes(0));
uint256 mLen = m.length;
// Encode call args in result and move the free memory pointer
result = abi.encodePacked(b.length, e.length, mLen, b, e, m);
assembly ("memory-safe") {
let dataPtr := add(result, 0x20)
// Write result on top of args to avoid allocating extra memory.
success := staticcall(gas(), 0x05, dataPtr, mload(result), dataPtr, mLen)
// Overwrite the length.
// result.length > returndatasize() is guaranteed because returndatasize() == m.length
mstore(result, mLen)
// Set the memory pointer after the returned data.
mstore(0x40, add(dataPtr, mLen))
}
}
/**
* @dev Returns whether the provided byte array is zero.
*/
function _zeroBytes(bytes memory byteArray) private pure returns (bool) {
for (uint256 i = 0; i < byteArray.length; ++i) {
if (byteArray[i] != 0) {
return false;
}
}
return true;
}
/**
* @dev Returns the square root of a number. If the number is not a perfect square, the value is rounded
* towards zero.
*
* This method is based on Newton's method for computing square roots; the algorithm is restricted to only
* using integer operations.
*/
function sqrt(uint256 a) internal pure returns (uint256) {
unchecked {
// Take care of easy edge cases when a == 0 or a == 1
if (a <= 1) {
return a;
}
// In this function, we use Newton's method to get a root of `f(x) := x² - a`. It involves building a
// sequence x_n that converges toward sqrt(a). For each iteration x_n, we also define the error between
// the current value as `ε_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 x) internal pure returns (uint256 r) {
// If value has upper 128 bits set, log2 result is at least 128
r = SafeCast.toUint(x > 0xffffffffffffffffffffffffffffffff) << 7;
// If upper 64 bits of 128-bit half set, add 64 to result
r |= SafeCast.toUint((x >> r) > 0xffffffffffffffff) << 6;
// If upper 32 bits of 64-bit half set, add 32 to result
r |= SafeCast.toUint((x >> r) > 0xffffffff) << 5;
// If upper 16 bits of 32-bit half set, add 16 to result
r |= SafeCast.toUint((x >> r) > 0xffff) << 4;
// If upper 8 bits of 16-bit half set, add 8 to result
r |= SafeCast.toUint((x >> r) > 0xff) << 3;
// If upper 4 bits of 8-bit half set, add 4 to result
r |= SafeCast.toUint((x >> r) > 0xf) << 2;
// Shifts value right by the current result and use it as an index into this lookup table:
//
// | x (4 bits) | index | table[index] = MSB position |
// |------------|---------|-----------------------------|
// | 0000 | 0 | table[0] = 0 |
// | 0001 | 1 | table[1] = 0 |
// | 0010 | 2 | table[2] = 1 |
// | 0011 | 3 | table[3] = 1 |
// | 0100 | 4 | table[4] = 2 |
// | 0101 | 5 | table[5] = 2 |
// | 0110 | 6 | table[6] = 2 |
// | 0111 | 7 | table[7] = 2 |
// | 1000 | 8 | table[8] = 3 |
// | 1001 | 9 | table[9] = 3 |
// | 1010 | 10 | table[10] = 3 |
// | 1011 | 11 | table[11] = 3 |
// | 1100 | 12 | table[12] = 3 |
// | 1101 | 13 | table[13] = 3 |
// | 1110 | 14 | table[14] = 3 |
// | 1111 | 15 | table[15] = 3 |
//
// The lookup table is represented as a 32-byte value with the MSB positions for 0-15 in the last 16 bytes.
assembly ("memory-safe") {
r := or(r, byte(shr(r, x), 0x0000010102020202030303030303030300000000000000000000000000000000))
}
}
/**
* @dev Return the log in base 2, following the selected rounding direction, of a positive value.
* Returns 0 if given 0.
*/
function log2(uint256 value, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = log2(value);
return result + SafeCast.toUint(unsignedRoundsUp(rounding) && 1 << result < value);
}
}
/**
* @dev Return the log in base 10 of a positive value rounded towards zero.
* Returns 0 if given 0.
*/
function log10(uint256 value) internal pure returns (uint256) {
uint256 result = 0;
unchecked {
if (value >= 10 ** 64) {
value /= 10 ** 64;
result += 64;
}
if (value >= 10 ** 32) {
value /= 10 ** 32;
result += 32;
}
if (value >= 10 ** 16) {
value /= 10 ** 16;
result += 16;
}
if (value >= 10 ** 8) {
value /= 10 ** 8;
result += 8;
}
if (value >= 10 ** 4) {
value /= 10 ** 4;
result += 4;
}
if (value >= 10 ** 2) {
value /= 10 ** 2;
result += 2;
}
if (value >= 10 ** 1) {
result += 1;
}
}
return result;
}
/**
* @dev Return the log in base 10, following the selected rounding direction, of a positive value.
* Returns 0 if given 0.
*/
function log10(uint256 value, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = log10(value);
return result + SafeCast.toUint(unsignedRoundsUp(rounding) && 10 ** result < value);
}
}
/**
* @dev Return the log in base 256 of a positive value rounded towards zero.
* Returns 0 if given 0.
*
* Adding one to the result gives the number of pairs of hex symbols needed to represent `value` as a hex string.
*/
function log256(uint256 x) internal pure returns (uint256 r) {
// If value has upper 128 bits set, log2 result is at least 128
r = SafeCast.toUint(x > 0xffffffffffffffffffffffffffffffff) << 7;
// If upper 64 bits of 128-bit half set, add 64 to result
r |= SafeCast.toUint((x >> r) > 0xffffffffffffffff) << 6;
// If upper 32 bits of 64-bit half set, add 32 to result
r |= SafeCast.toUint((x >> r) > 0xffffffff) << 5;
// If upper 16 bits of 32-bit half set, add 16 to result
r |= SafeCast.toUint((x >> r) > 0xffff) << 4;
// Add 1 if upper 8 bits of 16-bit half set, and divide accumulated result by 8
return (r >> 3) | SafeCast.toUint((x >> r) > 0xff);
}
/**
* @dev Return the log in base 256, following the selected rounding direction, of a positive value.
* Returns 0 if given 0.
*/
function log256(uint256 value, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = log256(value);
return result + SafeCast.toUint(unsignedRoundsUp(rounding) && 1 << (result << 3) < value);
}
}
/**
* @dev Returns whether a provided rounding mode is considered rounding up for unsigned integers.
*/
function unsignedRoundsUp(Rounding rounding) internal pure returns (bool) {
return uint8(rounding) % 2 == 1;
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (utils/math/SafeCast.sol)
// This file was procedurally generated from scripts/generate/templates/SafeCast.js.
pragma solidity ^0.8.20;
/**
* @dev Wrappers over Solidity's uintXX/intXX/bool casting operators with added overflow
* checks.
*
* Downcasting from uint256/int256 in Solidity does not revert on overflow. This can
* easily result in undesired exploitation or bugs, since developers usually
* assume that overflows raise errors. `SafeCast` restores this intuition by
* reverting the transaction when such an operation overflows.
*
* Using this library instead of the unchecked operations eliminates an entire
* class of bugs, so it's recommended to use it always.
*/
library SafeCast {
/**
* @dev Value doesn't fit in an uint of `bits` size.
*/
error SafeCastOverflowedUintDowncast(uint8 bits, uint256 value);
/**
* @dev An int value doesn't fit in an uint of `bits` size.
*/
error SafeCastOverflowedIntToUint(int256 value);
/**
* @dev Value doesn't fit in an int of `bits` size.
*/
error SafeCastOverflowedIntDowncast(uint8 bits, int256 value);
/**
* @dev An uint value doesn't fit in an int of `bits` size.
*/
error SafeCastOverflowedUintToInt(uint256 value);
/**
* @dev Returns the downcasted uint248 from uint256, reverting on
* overflow (when the input is greater than largest uint248).
*
* Counterpart to Solidity's `uint248` operator.
*
* Requirements:
*
* - input must fit into 248 bits
*/
function toUint248(uint256 value) internal pure returns (uint248) {
if (value > type(uint248).max) {
revert SafeCastOverflowedUintDowncast(248, value);
}
return uint248(value);
}
/**
* @dev Returns the downcasted uint240 from uint256, reverting on
* overflow (when the input is greater than largest uint240).
*
* Counterpart to Solidity's `uint240` operator.
*
* Requirements:
*
* - input must fit into 240 bits
*/
function toUint240(uint256 value) internal pure returns (uint240) {
if (value > type(uint240).max) {
revert SafeCastOverflowedUintDowncast(240, value);
}
return uint240(value);
}
/**
* @dev Returns the downcasted uint232 from uint256, reverting on
* overflow (when the input is greater than largest uint232).
*
* Counterpart to Solidity's `uint232` operator.
*
* Requirements:
*
* - input must fit into 232 bits
*/
function toUint232(uint256 value) internal pure returns (uint232) {
if (value > type(uint232).max) {
revert SafeCastOverflowedUintDowncast(232, value);
}
return uint232(value);
}
/**
* @dev Returns the downcasted uint224 from uint256, reverting on
* overflow (when the input is greater than largest uint224).
*
* Counterpart to Solidity's `uint224` operator.
*
* Requirements:
*
* - input must fit into 224 bits
*/
function toUint224(uint256 value) internal pure returns (uint224) {
if (value > type(uint224).max) {
revert SafeCastOverflowedUintDowncast(224, value);
}
return uint224(value);
}
/**
* @dev Returns the downcasted uint216 from uint256, reverting on
* overflow (when the input is greater than largest uint216).
*
* Counterpart to Solidity's `uint216` operator.
*
* Requirements:
*
* - input must fit into 216 bits
*/
function toUint216(uint256 value) internal pure returns (uint216) {
if (value > type(uint216).max) {
revert SafeCastOverflowedUintDowncast(216, value);
}
return uint216(value);
}
/**
* @dev Returns the downcasted uint208 from uint256, reverting on
* overflow (when the input is greater than largest uint208).
*
* Counterpart to Solidity's `uint208` operator.
*
* Requirements:
*
* - input must fit into 208 bits
*/
function toUint208(uint256 value) internal pure returns (uint208) {
if (value > type(uint208).max) {
revert SafeCastOverflowedUintDowncast(208, value);
}
return uint208(value);
}
/**
* @dev Returns the downcasted uint200 from uint256, reverting on
* overflow (when the input is greater than largest uint200).
*
* Counterpart to Solidity's `uint200` operator.
*
* Requirements:
*
* - input must fit into 200 bits
*/
function toUint200(uint256 value) internal pure returns (uint200) {
if (value > type(uint200).max) {
revert SafeCastOverflowedUintDowncast(200, value);
}
return uint200(value);
}
/**
* @dev Returns the downcasted uint192 from uint256, reverting on
* overflow (when the input is greater than largest uint192).
*
* Counterpart to Solidity's `uint192` operator.
*
* Requirements:
*
* - input must fit into 192 bits
*/
function toUint192(uint256 value) internal pure returns (uint192) {
if (value > type(uint192).max) {
revert SafeCastOverflowedUintDowncast(192, value);
}
return uint192(value);
}
/**
* @dev Returns the downcasted uint184 from uint256, reverting on
* overflow (when the input is greater than largest uint184).
*
* Counterpart to Solidity's `uint184` operator.
*
* Requirements:
*
* - input must fit into 184 bits
*/
function toUint184(uint256 value) internal pure returns (uint184) {
if (value > type(uint184).max) {
revert SafeCastOverflowedUintDowncast(184, value);
}
return uint184(value);
}
/**
* @dev Returns the downcasted uint176 from uint256, reverting on
* overflow (when the input is greater than largest uint176).
*
* Counterpart to Solidity's `uint176` operator.
*
* Requirements:
*
* - input must fit into 176 bits
*/
function toUint176(uint256 value) internal pure returns (uint176) {
if (value > type(uint176).max) {
revert SafeCastOverflowedUintDowncast(176, value);
}
return uint176(value);
}
/**
* @dev Returns the downcasted uint168 from uint256, reverting on
* overflow (when the input is greater than largest uint168).
*
* Counterpart to Solidity's `uint168` operator.
*
* Requirements:
*
* - input must fit into 168 bits
*/
function toUint168(uint256 value) internal pure returns (uint168) {
if (value > type(uint168).max) {
revert SafeCastOverflowedUintDowncast(168, value);
}
return uint168(value);
}
/**
* @dev Returns the downcasted uint160 from uint256, reverting on
* overflow (when the input is greater than largest uint160).
*
* Counterpart to Solidity's `uint160` operator.
*
* Requirements:
*
* - input must fit into 160 bits
*/
function toUint160(uint256 value) internal pure returns (uint160) {
if (value > type(uint160).max) {
revert SafeCastOverflowedUintDowncast(160, value);
}
return uint160(value);
}
/**
* @dev Returns the downcasted uint152 from uint256, reverting on
* overflow (when the input is greater than largest uint152).
*
* Counterpart to Solidity's `uint152` operator.
*
* Requirements:
*
* - input must fit into 152 bits
*/
function toUint152(uint256 value) internal pure returns (uint152) {
if (value > type(uint152).max) {
revert SafeCastOverflowedUintDowncast(152, value);
}
return uint152(value);
}
/**
* @dev Returns the downcasted uint144 from uint256, reverting on
* overflow (when the input is greater than largest uint144).
*
* Counterpart to Solidity's `uint144` operator.
*
* Requirements:
*
* - input must fit into 144 bits
*/
function toUint144(uint256 value) internal pure returns (uint144) {
if (value > type(uint144).max) {
revert SafeCastOverflowedUintDowncast(144, value);
}
return uint144(value);
}
/**
* @dev Returns the downcasted uint136 from uint256, reverting on
* overflow (when the input is greater than largest uint136).
*
* Counterpart to Solidity's `uint136` operator.
*
* Requirements:
*
* - input must fit into 136 bits
*/
function toUint136(uint256 value) internal pure returns (uint136) {
if (value > type(uint136).max) {
revert SafeCastOverflowedUintDowncast(136, value);
}
return uint136(value);
}
/**
* @dev Returns the downcasted uint128 from uint256, reverting on
* overflow (when the input is greater than largest uint128).
*
* Counterpart to Solidity's `uint128` operator.
*
* Requirements:
*
* - input must fit into 128 bits
*/
function toUint128(uint256 value) internal pure returns (uint128) {
if (value > type(uint128).max) {
revert SafeCastOverflowedUintDowncast(128, value);
}
return uint128(value);
}
/**
* @dev Returns the downcasted uint120 from uint256, reverting on
* overflow (when the input is greater than largest uint120).
*
* Counterpart to Solidity's `uint120` operator.
*
* Requirements:
*
* - input must fit into 120 bits
*/
function toUint120(uint256 value) internal pure returns (uint120) {
if (value > type(uint120).max) {
revert SafeCastOverflowedUintDowncast(120, value);
}
return uint120(value);
}
/**
* @dev Returns the downcasted uint112 from uint256, reverting on
* overflow (when the input is greater than largest uint112).
*
* Counterpart to Solidity's `uint112` operator.
*
* Requirements:
*
* - input must fit into 112 bits
*/
function toUint112(uint256 value) internal pure returns (uint112) {
if (value > type(uint112).max) {
revert SafeCastOverflowedUintDowncast(112, value);
}
return uint112(value);
}
/**
* @dev Returns the downcasted uint104 from uint256, reverting on
* overflow (when the input is greater than largest uint104).
*
* Counterpart to Solidity's `uint104` operator.
*
* Requirements:
*
* - input must fit into 104 bits
*/
function toUint104(uint256 value) internal pure returns (uint104) {
if (value > type(uint104).max) {
revert SafeCastOverflowedUintDowncast(104, value);
}
return uint104(value);
}
/**
* @dev Returns the downcasted uint96 from uint256, reverting on
* overflow (when the input is greater than largest uint96).
*
* Counterpart to Solidity's `uint96` operator.
*
* Requirements:
*
* - input must fit into 96 bits
*/
function toUint96(uint256 value) internal pure returns (uint96) {
if (value > type(uint96).max) {
revert SafeCastOverflowedUintDowncast(96, value);
}
return uint96(value);
}
/**
* @dev Returns the downcasted uint88 from uint256, reverting on
* overflow (when the input is greater than largest uint88).
*
* Counterpart to Solidity's `uint88` operator.
*
* Requirements:
*
* - input must fit into 88 bits
*/
function toUint88(uint256 value) internal pure returns (uint88) {
if (value > type(uint88).max) {
revert SafeCastOverflowedUintDowncast(88, value);
}
return uint88(value);
}
/**
* @dev Returns the downcasted uint80 from uint256, reverting on
* overflow (when the input is greater than largest uint80).
*
* Counterpart to Solidity's `uint80` operator.
*
* Requirements:
*
* - input must fit into 80 bits
*/
function toUint80(uint256 value) internal pure returns (uint80) {
if (value > type(uint80).max) {
revert SafeCastOverflowedUintDowncast(80, value);
}
return uint80(value);
}
/**
* @dev Returns the downcasted uint72 from uint256, reverting on
* overflow (when the input is greater than largest uint72).
*
* Counterpart to Solidity's `uint72` operator.
*
* Requirements:
*
* - input must fit into 72 bits
*/
function toUint72(uint256 value) internal pure returns (uint72) {
if (value > type(uint72).max) {
revert SafeCastOverflowedUintDowncast(72, value);
}
return uint72(value);
}
/**
* @dev Returns the downcasted uint64 from uint256, reverting on
* overflow (when the input is greater than largest uint64).
*
* Counterpart to Solidity's `uint64` operator.
*
* Requirements:
*
* - input must fit into 64 bits
*/
function toUint64(uint256 value) internal pure returns (uint64) {
if (value > type(uint64).max) {
revert SafeCastOverflowedUintDowncast(64, value);
}
return uint64(value);
}
/**
* @dev Returns the downcasted uint56 from uint256, reverting on
* overflow (when the input is greater than largest uint56).
*
* Counterpart to Solidity's `uint56` operator.
*
* Requirements:
*
* - input must fit into 56 bits
*/
function toUint56(uint256 value) internal pure returns (uint56) {
if (value > type(uint56).max) {
revert SafeCastOverflowedUintDowncast(56, value);
}
return uint56(value);
}
/**
* @dev Returns the downcasted uint48 from uint256, reverting on
* overflow (when the input is greater than largest uint48).
*
* Counterpart to Solidity's `uint48` operator.
*
* Requirements:
*
* - input must fit into 48 bits
*/
function toUint48(uint256 value) internal pure returns (uint48) {
if (value > type(uint48).max) {
revert SafeCastOverflowedUintDowncast(48, value);
}
return uint48(value);
}
/**
* @dev Returns the downcasted uint40 from uint256, reverting on
* overflow (when the input is greater than largest uint40).
*
* Counterpart to Solidity's `uint40` operator.
*
* Requirements:
*
* - input must fit into 40 bits
*/
function toUint40(uint256 value) internal pure returns (uint40) {
if (value > type(uint40).max) {
revert SafeCastOverflowedUintDowncast(40, value);
}
return uint40(value);
}
/**
* @dev Returns the downcasted uint32 from uint256, reverting on
* overflow (when the input is greater than largest uint32).
*
* Counterpart to Solidity's `uint32` operator.
*
* Requirements:
*
* - input must fit into 32 bits
*/
function toUint32(uint256 value) internal pure returns (uint32) {
if (value > type(uint32).max) {
revert SafeCastOverflowedUintDowncast(32, value);
}
return uint32(value);
}
/**
* @dev Returns the downcasted uint24 from uint256, reverting on
* overflow (when the input is greater than largest uint24).
*
* Counterpart to Solidity's `uint24` operator.
*
* Requirements:
*
* - input must fit into 24 bits
*/
function toUint24(uint256 value) internal pure returns (uint24) {
if (value > type(uint24).max) {
revert SafeCastOverflowedUintDowncast(24, value);
}
return uint24(value);
}
/**
* @dev Returns the downcasted uint16 from uint256, reverting on
* overflow (when the input is greater than largest uint16).
*
* Counterpart to Solidity's `uint16` operator.
*
* Requirements:
*
* - input must fit into 16 bits
*/
function toUint16(uint256 value) internal pure returns (uint16) {
if (value > type(uint16).max) {
revert SafeCastOverflowedUintDowncast(16, value);
}
return uint16(value);
}
/**
* @dev Returns the downcasted uint8 from uint256, reverting on
* overflow (when the input is greater than largest uint8).
*
* Counterpart to Solidity's `uint8` operator.
*
* Requirements:
*
* - input must fit into 8 bits
*/
function toUint8(uint256 value) internal pure returns (uint8) {
if (value > type(uint8).max) {
revert SafeCastOverflowedUintDowncast(8, value);
}
return uint8(value);
}
/**
* @dev Converts a signed int256 into an unsigned uint256.
*
* Requirements:
*
* - input must be greater than or equal to 0.
*/
function toUint256(int256 value) internal pure returns (uint256) {
if (value < 0) {
revert SafeCastOverflowedIntToUint(value);
}
return uint256(value);
}
/**
* @dev Returns the downcasted int248 from int256, reverting on
* overflow (when the input is less than smallest int248 or
* greater than largest int248).
*
* Counterpart to Solidity's `int248` operator.
*
* Requirements:
*
* - input must fit into 248 bits
*/
function toInt248(int256 value) internal pure returns (int248 downcasted) {
downcasted = int248(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(248, value);
}
}
/**
* @dev Returns the downcasted int240 from int256, reverting on
* overflow (when the input is less than smallest int240 or
* greater than largest int240).
*
* Counterpart to Solidity's `int240` operator.
*
* Requirements:
*
* - input must fit into 240 bits
*/
function toInt240(int256 value) internal pure returns (int240 downcasted) {
downcasted = int240(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(240, value);
}
}
/**
* @dev Returns the downcasted int232 from int256, reverting on
* overflow (when the input is less than smallest int232 or
* greater than largest int232).
*
* Counterpart to Solidity's `int232` operator.
*
* Requirements:
*
* - input must fit into 232 bits
*/
function toInt232(int256 value) internal pure returns (int232 downcasted) {
downcasted = int232(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(232, value);
}
}
/**
* @dev Returns the downcasted int224 from int256, reverting on
* overflow (when the input is less than smallest int224 or
* greater than largest int224).
*
* Counterpart to Solidity's `int224` operator.
*
* Requirements:
*
* - input must fit into 224 bits
*/
function toInt224(int256 value) internal pure returns (int224 downcasted) {
downcasted = int224(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(224, value);
}
}
/**
* @dev Returns the downcasted int216 from int256, reverting on
* overflow (when the input is less than smallest int216 or
* greater than largest int216).
*
* Counterpart to Solidity's `int216` operator.
*
* Requirements:
*
* - input must fit into 216 bits
*/
function toInt216(int256 value) internal pure returns (int216 downcasted) {
downcasted = int216(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(216, value);
}
}
/**
* @dev Returns the downcasted int208 from int256, reverting on
* overflow (when the input is less than smallest int208 or
* greater than largest int208).
*
* Counterpart to Solidity's `int208` operator.
*
* Requirements:
*
* - input must fit into 208 bits
*/
function toInt208(int256 value) internal pure returns (int208 downcasted) {
downcasted = int208(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(208, value);
}
}
/**
* @dev Returns the downcasted int200 from int256, reverting on
* overflow (when the input is less than smallest int200 or
* greater than largest int200).
*
* Counterpart to Solidity's `int200` operator.
*
* Requirements:
*
* - input must fit into 200 bits
*/
function toInt200(int256 value) internal pure returns (int200 downcasted) {
downcasted = int200(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(200, value);
}
}
/**
* @dev Returns the downcasted int192 from int256, reverting on
* overflow (when the input is less than smallest int192 or
* greater than largest int192).
*
* Counterpart to Solidity's `int192` operator.
*
* Requirements:
*
* - input must fit into 192 bits
*/
function toInt192(int256 value) internal pure returns (int192 downcasted) {
downcasted = int192(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(192, value);
}
}
/**
* @dev Returns the downcasted int184 from int256, reverting on
* overflow (when the input is less than smallest int184 or
* greater than largest int184).
*
* Counterpart to Solidity's `int184` operator.
*
* Requirements:
*
* - input must fit into 184 bits
*/
function toInt184(int256 value) internal pure returns (int184 downcasted) {
downcasted = int184(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(184, value);
}
}
/**
* @dev Returns the downcasted int176 from int256, reverting on
* overflow (when the input is less than smallest int176 or
* greater than largest int176).
*
* Counterpart to Solidity's `int176` operator.
*
* Requirements:
*
* - input must fit into 176 bits
*/
function toInt176(int256 value) internal pure returns (int176 downcasted) {
downcasted = int176(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(176, value);
}
}
/**
* @dev Returns the downcasted int168 from int256, reverting on
* overflow (when the input is less than smallest int168 or
* greater than largest int168).
*
* Counterpart to Solidity's `int168` operator.
*
* Requirements:
*
* - input must fit into 168 bits
*/
function toInt168(int256 value) internal pure returns (int168 downcasted) {
downcasted = int168(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(168, value);
}
}
/**
* @dev Returns the downcasted int160 from int256, reverting on
* overflow (when the input is less than smallest int160 or
* greater than largest int160).
*
* Counterpart to Solidity's `int160` operator.
*
* Requirements:
*
* - input must fit into 160 bits
*/
function toInt160(int256 value) internal pure returns (int160 downcasted) {
downcasted = int160(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(160, value);
}
}
/**
* @dev Returns the downcasted int152 from int256, reverting on
* overflow (when the input is less than smallest int152 or
* greater than largest int152).
*
* Counterpart to Solidity's `int152` operator.
*
* Requirements:
*
* - input must fit into 152 bits
*/
function toInt152(int256 value) internal pure returns (int152 downcasted) {
downcasted = int152(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(152, value);
}
}
/**
* @dev Returns the downcasted int144 from int256, reverting on
* overflow (when the input is less than smallest int144 or
* greater than largest int144).
*
* Counterpart to Solidity's `int144` operator.
*
* Requirements:
*
* - input must fit into 144 bits
*/
function toInt144(int256 value) internal pure returns (int144 downcasted) {
downcasted = int144(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(144, value);
}
}
/**
* @dev Returns the downcasted int136 from int256, reverting on
* overflow (when the input is less than smallest int136 or
* greater than largest int136).
*
* Counterpart to Solidity's `int136` operator.
*
* Requirements:
*
* - input must fit into 136 bits
*/
function toInt136(int256 value) internal pure returns (int136 downcasted) {
downcasted = int136(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(136, value);
}
}
/**
* @dev Returns the downcasted int128 from int256, reverting on
* overflow (when the input is less than smallest int128 or
* greater than largest int128).
*
* Counterpart to Solidity's `int128` operator.
*
* Requirements:
*
* - input must fit into 128 bits
*/
function toInt128(int256 value) internal pure returns (int128 downcasted) {
downcasted = int128(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(128, value);
}
}
/**
* @dev Returns the downcasted int120 from int256, reverting on
* overflow (when the input is less than smallest int120 or
* greater than largest int120).
*
* Counterpart to Solidity's `int120` operator.
*
* Requirements:
*
* - input must fit into 120 bits
*/
function toInt120(int256 value) internal pure returns (int120 downcasted) {
downcasted = int120(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(120, value);
}
}
/**
* @dev Returns the downcasted int112 from int256, reverting on
* overflow (when the input is less than smallest int112 or
* greater than largest int112).
*
* Counterpart to Solidity's `int112` operator.
*
* Requirements:
*
* - input must fit into 112 bits
*/
function toInt112(int256 value) internal pure returns (int112 downcasted) {
downcasted = int112(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(112, value);
}
}
/**
* @dev Returns the downcasted int104 from int256, reverting on
* overflow (when the input is less than smallest int104 or
* greater than largest int104).
*
* Counterpart to Solidity's `int104` operator.
*
* Requirements:
*
* - input must fit into 104 bits
*/
function toInt104(int256 value) internal pure returns (int104 downcasted) {
downcasted = int104(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(104, value);
}
}
/**
* @dev Returns the downcasted int96 from int256, reverting on
* overflow (when the input is less than smallest int96 or
* greater than largest int96).
*
* Counterpart to Solidity's `int96` operator.
*
* Requirements:
*
* - input must fit into 96 bits
*/
function toInt96(int256 value) internal pure returns (int96 downcasted) {
downcasted = int96(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(96, value);
}
}
/**
* @dev Returns the downcasted int88 from int256, reverting on
* overflow (when the input is less than smallest int88 or
* greater than largest int88).
*
* Counterpart to Solidity's `int88` operator.
*
* Requirements:
*
* - input must fit into 88 bits
*/
function toInt88(int256 value) internal pure returns (int88 downcasted) {
downcasted = int88(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(88, value);
}
}
/**
* @dev Returns the downcasted int80 from int256, reverting on
* overflow (when the input is less than smallest int80 or
* greater than largest int80).
*
* Counterpart to Solidity's `int80` operator.
*
* Requirements:
*
* - input must fit into 80 bits
*/
function toInt80(int256 value) internal pure returns (int80 downcasted) {
downcasted = int80(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(80, value);
}
}
/**
* @dev Returns the downcasted int72 from int256, reverting on
* overflow (when the input is less than smallest int72 or
* greater than largest int72).
*
* Counterpart to Solidity's `int72` operator.
*
* Requirements:
*
* - input must fit into 72 bits
*/
function toInt72(int256 value) internal pure returns (int72 downcasted) {
downcasted = int72(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(72, value);
}
}
/**
* @dev Returns the downcasted int64 from int256, reverting on
* overflow (when the input is less than smallest int64 or
* greater than largest int64).
*
* Counterpart to Solidity's `int64` operator.
*
* Requirements:
*
* - input must fit into 64 bits
*/
function toInt64(int256 value) internal pure returns (int64 downcasted) {
downcasted = int64(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(64, value);
}
}
/**
* @dev Returns the downcasted int56 from int256, reverting on
* overflow (when the input is less than smallest int56 or
* greater than largest int56).
*
* Counterpart to Solidity's `int56` operator.
*
* Requirements:
*
* - input must fit into 56 bits
*/
function toInt56(int256 value) internal pure returns (int56 downcasted) {
downcasted = int56(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(56, value);
}
}
/**
* @dev Returns the downcasted int48 from int256, reverting on
* overflow (when the input is less than smallest int48 or
* greater than largest int48).
*
* Counterpart to Solidity's `int48` operator.
*
* Requirements:
*
* - input must fit into 48 bits
*/
function toInt48(int256 value) internal pure returns (int48 downcasted) {
downcasted = int48(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(48, value);
}
}
/**
* @dev Returns the downcasted int40 from int256, reverting on
* overflow (when the input is less than smallest int40 or
* greater than largest int40).
*
* Counterpart to Solidity's `int40` operator.
*
* Requirements:
*
* - input must fit into 40 bits
*/
function toInt40(int256 value) internal pure returns (int40 downcasted) {
downcasted = int40(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(40, value);
}
}
/**
* @dev Returns the downcasted int32 from int256, reverting on
* overflow (when the input is less than smallest int32 or
* greater than largest int32).
*
* Counterpart to Solidity's `int32` operator.
*
* Requirements:
*
* - input must fit into 32 bits
*/
function toInt32(int256 value) internal pure returns (int32 downcasted) {
downcasted = int32(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(32, value);
}
}
/**
* @dev Returns the downcasted int24 from int256, reverting on
* overflow (when the input is less than smallest int24 or
* greater than largest int24).
*
* Counterpart to Solidity's `int24` operator.
*
* Requirements:
*
* - input must fit into 24 bits
*/
function toInt24(int256 value) internal pure returns (int24 downcasted) {
downcasted = int24(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(24, value);
}
}
/**
* @dev Returns the downcasted int16 from int256, reverting on
* overflow (when the input is less than smallest int16 or
* greater than largest int16).
*
* Counterpart to Solidity's `int16` operator.
*
* Requirements:
*
* - input must fit into 16 bits
*/
function toInt16(int256 value) internal pure returns (int16 downcasted) {
downcasted = int16(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(16, value);
}
}
/**
* @dev Returns the downcasted int8 from int256, reverting on
* overflow (when the input is less than smallest int8 or
* greater than largest int8).
*
* Counterpart to Solidity's `int8` operator.
*
* Requirements:
*
* - input must fit into 8 bits
*/
function toInt8(int256 value) internal pure returns (int8 downcasted) {
downcasted = int8(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(8, value);
}
}
/**
* @dev Converts an unsigned uint256 into a signed int256.
*
* Requirements:
*
* - input must be less than or equal to maxInt256.
*/
function toInt256(uint256 value) internal pure returns (int256) {
// Note: Unsafe cast below is okay because `type(int256).max` is guaranteed to be positive
if (value > uint256(type(int256).max)) {
revert SafeCastOverflowedUintToInt(value);
}
return int256(value);
}
/**
* @dev Cast a boolean (false or true) to a uint256 (0 or 1) with no jump.
*/
function toUint(bool b) internal pure returns (uint256 u) {
assembly ("memory-safe") {
u := iszero(iszero(b))
}
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.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) (utils/Panic.sol)
pragma solidity ^0.8.20;
/**
* @dev Helper library for emitting standardized panic codes.
*
* ```solidity
* contract Example {
* using Panic for uint256;
*
* // Use any of the declared internal constants
* function foo() { Panic.GENERIC.panic(); }
*
* // Alternatively
* function foo() { Panic.panic(Panic.GENERIC); }
* }
* ```
*
* Follows the list from https://github.com/ethereum/solidity/blob/v0.8.24/libsolutil/ErrorCodes.h[libsolutil].
*
* _Available since v5.1._
*/
// slither-disable-next-line unused-state
library Panic {
/// @dev generic / unspecified error
uint256 internal constant GENERIC = 0x00;
/// @dev used by the assert() builtin
uint256 internal constant ASSERT = 0x01;
/// @dev arithmetic underflow or overflow
uint256 internal constant UNDER_OVERFLOW = 0x11;
/// @dev division or modulo by zero
uint256 internal constant DIVISION_BY_ZERO = 0x12;
/// @dev enum conversion error
uint256 internal constant ENUM_CONVERSION_ERROR = 0x21;
/// @dev invalid encoding in storage
uint256 internal constant STORAGE_ENCODING_ERROR = 0x22;
/// @dev empty array pop
uint256 internal constant EMPTY_ARRAY_POP = 0x31;
/// @dev array out of bounds access
uint256 internal constant ARRAY_OUT_OF_BOUNDS = 0x32;
/// @dev resource error (too large allocation or too large array)
uint256 internal constant RESOURCE_ERROR = 0x41;
/// @dev calling invalid internal function
uint256 internal constant INVALID_INTERNAL_FUNCTION = 0x51;
/// @dev Reverts with a panic code. Recommended to use with
/// the internal constants with predefined codes.
function panic(uint256 code) internal pure {
assembly ("memory-safe") {
mstore(0x00, 0x4e487b71)
mstore(0x20, code)
revert(0x1c, 0x24)
}
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.3.0) (utils/Strings.sol)
pragma solidity ^0.8.20;
import {Math} from "./math/Math.sol";
import {SafeCast} from "./math/SafeCast.sol";
import {SignedMath} from "./math/SignedMath.sol";
/**
* @dev String operations.
*/
library Strings {
using SafeCast for *;
bytes16 private constant HEX_DIGITS = "0123456789abcdef";
uint8 private constant ADDRESS_LENGTH = 20;
uint256 private constant SPECIAL_CHARS_LOOKUP =
(1 << 0x08) | // backspace
(1 << 0x09) | // tab
(1 << 0x0a) | // newline
(1 << 0x0c) | // form feed
(1 << 0x0d) | // carriage return
(1 << 0x22) | // double quote
(1 << 0x5c); // backslash
/**
* @dev The `value` string doesn't fit in the specified `length`.
*/
error StringsInsufficientHexLength(uint256 value, uint256 length);
/**
* @dev The string being parsed contains characters that are not in scope of the given base.
*/
error StringsInvalidChar();
/**
* @dev The string being parsed is not a properly formatted address.
*/
error StringsInvalidAddressFormat();
/**
* @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));
}
/**
* @dev Parse a decimal string and returns the value as a `uint256`.
*
* Requirements:
* - The string must be formatted as `[0-9]*`
* - The result must fit into an `uint256` type
*/
function parseUint(string memory input) internal pure returns (uint256) {
return parseUint(input, 0, bytes(input).length);
}
/**
* @dev Variant of {parseUint-string} that parses a substring of `input` located between position `begin` (included) and
* `end` (excluded).
*
* Requirements:
* - The substring must be formatted as `[0-9]*`
* - The result must fit into an `uint256` type
*/
function parseUint(string memory input, uint256 begin, uint256 end) internal pure returns (uint256) {
(bool success, uint256 value) = tryParseUint(input, begin, end);
if (!success) revert StringsInvalidChar();
return value;
}
/**
* @dev Variant of {parseUint-string} that returns false if the parsing fails because of an invalid character.
*
* NOTE: This function will revert if the result does not fit in a `uint256`.
*/
function tryParseUint(string memory input) internal pure returns (bool success, uint256 value) {
return _tryParseUintUncheckedBounds(input, 0, bytes(input).length);
}
/**
* @dev Variant of {parseUint-string-uint256-uint256} that returns false if the parsing fails because of an invalid
* character.
*
* NOTE: This function will revert if the result does not fit in a `uint256`.
*/
function tryParseUint(
string memory input,
uint256 begin,
uint256 end
) internal pure returns (bool success, uint256 value) {
if (end > bytes(input).length || begin > end) return (false, 0);
return _tryParseUintUncheckedBounds(input, begin, end);
}
/**
* @dev Implementation of {tryParseUint-string-uint256-uint256} that does not check bounds. Caller should make sure that
* `begin <= end <= input.length`. Other inputs would result in undefined behavior.
*/
function _tryParseUintUncheckedBounds(
string memory input,
uint256 begin,
uint256 end
) private pure returns (bool success, uint256 value) {
bytes memory buffer = bytes(input);
uint256 result = 0;
for (uint256 i = begin; i < end; ++i) {
uint8 chr = _tryParseChr(bytes1(_unsafeReadBytesOffset(buffer, i)));
if (chr > 9) return (false, 0);
result *= 10;
result += chr;
}
return (true, result);
}
/**
* @dev Parse a decimal string and returns the value as a `int256`.
*
* Requirements:
* - The string must be formatted as `[-+]?[0-9]*`
* - The result must fit in an `int256` type.
*/
function parseInt(string memory input) internal pure returns (int256) {
return parseInt(input, 0, bytes(input).length);
}
/**
* @dev Variant of {parseInt-string} that parses a substring of `input` located between position `begin` (included) and
* `end` (excluded).
*
* Requirements:
* - The substring must be formatted as `[-+]?[0-9]*`
* - The result must fit in an `int256` type.
*/
function parseInt(string memory input, uint256 begin, uint256 end) internal pure returns (int256) {
(bool success, int256 value) = tryParseInt(input, begin, end);
if (!success) revert StringsInvalidChar();
return value;
}
/**
* @dev Variant of {parseInt-string} that returns false if the parsing fails because of an invalid character or if
* the result does not fit in a `int256`.
*
* NOTE: This function will revert if the absolute value of the result does not fit in a `uint256`.
*/
function tryParseInt(string memory input) internal pure returns (bool success, int256 value) {
return _tryParseIntUncheckedBounds(input, 0, bytes(input).length);
}
uint256 private constant ABS_MIN_INT256 = 2 ** 255;
/**
* @dev Variant of {parseInt-string-uint256-uint256} that returns false if the parsing fails because of an invalid
* character or if the result does not fit in a `int256`.
*
* NOTE: This function will revert if the absolute value of the result does not fit in a `uint256`.
*/
function tryParseInt(
string memory input,
uint256 begin,
uint256 end
) internal pure returns (bool success, int256 value) {
if (end > bytes(input).length || begin > end) return (false, 0);
return _tryParseIntUncheckedBounds(input, begin, end);
}
/**
* @dev Implementation of {tryParseInt-string-uint256-uint256} that does not check bounds. Caller should make sure that
* `begin <= end <= input.length`. Other inputs would result in undefined behavior.
*/
function _tryParseIntUncheckedBounds(
string memory input,
uint256 begin,
uint256 end
) private pure returns (bool success, int256 value) {
bytes memory buffer = bytes(input);
// Check presence of a negative sign.
bytes1 sign = begin == end ? bytes1(0) : bytes1(_unsafeReadBytesOffset(buffer, begin)); // don't do out-of-bound (possibly unsafe) read if sub-string is empty
bool positiveSign = sign == bytes1("+");
bool negativeSign = sign == bytes1("-");
uint256 offset = (positiveSign || negativeSign).toUint();
(bool absSuccess, uint256 absValue) = tryParseUint(input, begin + offset, end);
if (absSuccess && absValue < ABS_MIN_INT256) {
return (true, negativeSign ? -int256(absValue) : int256(absValue));
} else if (absSuccess && negativeSign && absValue == ABS_MIN_INT256) {
return (true, type(int256).min);
} else return (false, 0);
}
/**
* @dev Parse a hexadecimal string (with or without "0x" prefix), and returns the value as a `uint256`.
*
* Requirements:
* - The string must be formatted as `(0x)?[0-9a-fA-F]*`
* - The result must fit in an `uint256` type.
*/
function parseHexUint(string memory input) internal pure returns (uint256) {
return parseHexUint(input, 0, bytes(input).length);
}
/**
* @dev Variant of {parseHexUint-string} that parses a substring of `input` located between position `begin` (included) and
* `end` (excluded).
*
* Requirements:
* - The substring must be formatted as `(0x)?[0-9a-fA-F]*`
* - The result must fit in an `uint256` type.
*/
function parseHexUint(string memory input, uint256 begin, uint256 end) internal pure returns (uint256) {
(bool success, uint256 value) = tryParseHexUint(input, begin, end);
if (!success) revert StringsInvalidChar();
return value;
}
/**
* @dev Variant of {parseHexUint-string} that returns false if the parsing fails because of an invalid character.
*
* NOTE: This function will revert if the result does not fit in a `uint256`.
*/
function tryParseHexUint(string memory input) internal pure returns (bool success, uint256 value) {
return _tryParseHexUintUncheckedBounds(input, 0, bytes(input).length);
}
/**
* @dev Variant of {parseHexUint-string-uint256-uint256} that returns false if the parsing fails because of an
* invalid character.
*
* NOTE: This function will revert if the result does not fit in a `uint256`.
*/
function tryParseHexUint(
string memory input,
uint256 begin,
uint256 end
) internal pure returns (bool success, uint256 value) {
if (end > bytes(input).length || begin > end) return (false, 0);
return _tryParseHexUintUncheckedBounds(input, begin, end);
}
/**
* @dev Implementation of {tryParseHexUint-string-uint256-uint256} that does not check bounds. Caller should make sure that
* `begin <= end <= input.length`. Other inputs would result in undefined behavior.
*/
function _tryParseHexUintUncheckedBounds(
string memory input,
uint256 begin,
uint256 end
) private pure returns (bool success, uint256 value) {
bytes memory buffer = bytes(input);
// skip 0x prefix if present
bool hasPrefix = (end > begin + 1) && bytes2(_unsafeReadBytesOffset(buffer, begin)) == bytes2("0x"); // don't do out-of-bound (possibly unsafe) read if sub-string is empty
uint256 offset = hasPrefix.toUint() * 2;
uint256 result = 0;
for (uint256 i = begin + offset; i < end; ++i) {
uint8 chr = _tryParseChr(bytes1(_unsafeReadBytesOffset(buffer, i)));
if (chr > 15) return (false, 0);
result *= 16;
unchecked {
// Multiplying by 16 is equivalent to a shift of 4 bits (with additional overflow check).
// This guarantees that adding a value < 16 will not cause an overflow, hence the unchecked.
result += chr;
}
}
return (true, result);
}
/**
* @dev Parse a hexadecimal string (with or without "0x" prefix), and returns the value as an `address`.
*
* Requirements:
* - The string must be formatted as `(0x)?[0-9a-fA-F]{40}`
*/
function parseAddress(string memory input) internal pure returns (address) {
return parseAddress(input, 0, bytes(input).length);
}
/**
* @dev Variant of {parseAddress-string} that parses a substring of `input` located between position `begin` (included) and
* `end` (excluded).
*
* Requirements:
* - The substring must be formatted as `(0x)?[0-9a-fA-F]{40}`
*/
function parseAddress(string memory input, uint256 begin, uint256 end) internal pure returns (address) {
(bool success, address value) = tryParseAddress(input, begin, end);
if (!success) revert StringsInvalidAddressFormat();
return value;
}
/**
* @dev Variant of {parseAddress-string} that returns false if the parsing fails because the input is not a properly
* formatted address. See {parseAddress-string} requirements.
*/
function tryParseAddress(string memory input) internal pure returns (bool success, address value) {
return tryParseAddress(input, 0, bytes(input).length);
}
/**
* @dev Variant of {parseAddress-string-uint256-uint256} that returns false if the parsing fails because input is not a properly
* formatted address. See {parseAddress-string-uint256-uint256} requirements.
*/
function tryParseAddress(
string memory input,
uint256 begin,
uint256 end
) internal pure returns (bool success, address value) {
if (end > bytes(input).length || begin > end) return (false, address(0));
bool hasPrefix = (end > begin + 1) && bytes2(_unsafeReadBytesOffset(bytes(input), begin)) == bytes2("0x"); // don't do out-of-bound (possibly unsafe) read if sub-string is empty
uint256 expectedLength = 40 + hasPrefix.toUint() * 2;
// check that input is the correct length
if (end - begin == expectedLength) {
// length guarantees that this does not overflow, and value is at most type(uint160).max
(bool s, uint256 v) = _tryParseHexUintUncheckedBounds(input, begin, end);
return (s, address(uint160(v)));
} else {
return (false, address(0));
}
}
function _tryParseChr(bytes1 chr) private pure returns (uint8) {
uint8 value = uint8(chr);
// Try to parse `chr`:
// - Case 1: [0-9]
// - Case 2: [a-f]
// - Case 3: [A-F]
// - otherwise not supported
unchecked {
if (value > 47 && value < 58) value -= 48;
else if (value > 96 && value < 103) value -= 87;
else if (value > 64 && value < 71) value -= 55;
else return type(uint8).max;
}
return value;
}
/**
* @dev Escape special characters in JSON strings. This can be useful to prevent JSON injection in NFT metadata.
*
* WARNING: This function should only be used in double quoted JSON strings. Single quotes are not escaped.
*
* NOTE: This function escapes all unicode characters, and not just the ones in ranges defined in section 2.5 of
* RFC-4627 (U+0000 to U+001F, U+0022 and U+005C). ECMAScript's `JSON.parse` does recover escaped unicode
* characters that are not in this range, but other tooling may provide different results.
*/
function escapeJSON(string memory input) internal pure returns (string memory) {
bytes memory buffer = bytes(input);
bytes memory output = new bytes(2 * buffer.length); // worst case scenario
uint256 outputLength = 0;
for (uint256 i; i < buffer.length; ++i) {
bytes1 char = bytes1(_unsafeReadBytesOffset(buffer, i));
if (((SPECIAL_CHARS_LOOKUP & (1 << uint8(char))) != 0)) {
output[outputLength++] = "\\";
if (char == 0x08) output[outputLength++] = "b";
else if (char == 0x09) output[outputLength++] = "t";
else if (char == 0x0a) output[outputLength++] = "n";
else if (char == 0x0c) output[outputLength++] = "f";
else if (char == 0x0d) output[outputLength++] = "r";
else if (char == 0x5c) output[outputLength++] = "\\";
else if (char == 0x22) {
// solhint-disable-next-line quotes
output[outputLength++] = '"';
}
} else {
output[outputLength++] = char;
}
}
// write the actual length and deallocate unused memory
assembly ("memory-safe") {
mstore(output, outputLength)
mstore(0x40, add(output, shl(5, shr(5, add(outputLength, 63)))))
}
return string(output);
}
/**
* @dev Reads a bytes32 from a bytes array without bounds checking.
*
* NOTE: making this function internal would mean it could be used with memory unsafe offset, and marking the
* assembly block as such would prevent some optimizations.
*/
function _unsafeReadBytesOffset(bytes memory buffer, uint256 offset) private pure returns (bytes32 value) {
// This is not memory safe in the general case, but all calls to this private function are within bounds.
assembly ("memory-safe") {
value := mload(add(buffer, add(0x20, offset)))
}
}
}// Copyright 2025 Energi Core
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
// Energi Governance system is the fundamental part of Energi Core.
// NOTE: It's not allowed to change the compiler due to byte-to-byte
// match requirement.
/// @title INonFungiblePositionManager
/// @author Energi Core
pragma solidity 0.8.22;
import { IERC721 } from "@openzeppelin/contracts/token/ERC721/IERC721.sol";
interface IAlgebraNonfungiblePositionManager is IERC721 {
struct MintParams {
address token0;
address token1;
int24 tickLower;
int24 tickUpper;
uint256 amount0Desired;
uint256 amount1Desired;
uint256 amount0Min;
uint256 amount1Min;
address recipient;
uint256 deadline;
}
function positions(
uint256 tokenId
)
external
view
returns (
uint96 nonce,
address operator,
address token0,
address token1,
int24 tickLower,
int24 tickUpper,
uint128 liquidity,
uint256 feeGrowthInside0LastX128,
uint256 feeGrowthInside1LastX128,
uint128 tokensOwed0,
uint128 tokensOwed1
);
function mint(
MintParams calldata params
) external payable returns (uint256 tokenId, uint128 liquidity, uint256 amount0, uint256 amount1);
}// Copyright 2025 Energi Core
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
// Energi Governance system is the fundamental part of Energi Core.
// NOTE: It's not allowed to change the compiler due to byte-to-byte
// match requirement.
/// @title IApeLiquidityBondLocker
/// @author Energi Core
pragma solidity 0.8.22;
interface IApeLiquidityBondLocker {
struct Lock {
uint256 uniswapV3PositionId;
uint256 lpBondId;
uint256 bondId;
uint256 startTime;
uint256 lockedAmount0;
uint256 lockedAmount1;
bool isLocked;
}
struct Bond {
uint256 bondId;
address collection;
address token0;
address token1;
uint256 requiredAmount1;
int24 tickLower;
int24 tickUpper;
uint256 amount0Min;
uint256 amount1Min;
uint256 bondType;
uint256 lockDuration;
uint256 multiplier;
bool isActive;
address pool;
bool isGMIPool;
}
function lockDuration() external view returns (uint256);
function locks(uint256 _uniswapV3PositionId) external view returns (Lock memory);
function bonds(uint256 _bondId) external view returns (Bond memory);
function lockPosition(uint256 _uniswapV3PositionId) external;
function unlockPosition(uint256 _uniswapV3PositionId) external;
function getRewards0(uint256 _uniswapV3PositionId) external view returns (uint256 rewardsGMI);
function uniswapPositionManager() external view returns (address);
function startTime(uint256 _bondId) external view returns (uint256);
}// Copyright 2025 Energi Core
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
// Energi Governance system is the fundamental part of Energi Core.
// NOTE: It's not allowed to change the compiler due to byte-to-byte
// match requirement.
/// @title IOperatorRegistry
/// @author Energi Core
pragma solidity 0.8.22;
interface IOperatorRegistry {
function isWhitelist(address _collection, address _operator) external view returns (bool);
function isOperatorAllowed(address _collection, address _operator) external view returns (bool);
function universalAllowedOperators(address _operator) external view returns (bool);
function fundReceiver() external view returns (address);
function sharePercentageBps() external view returns (uint256);
function addWhitelist(address _collection, address _operator) external;
function removeWhitelist(address _collection, address _operator) external;
function addUniversalOperator(address _operator) external;
function removeUniversalOperator(address _operator) external;
function changeFundReceiver(address _fundReceiver) external;
function changeSharePercentageBps(uint256 _sharePercentageBps) external;
function pause() external;
function unpause() external;
}{
"optimizer": {
"enabled": true,
"runs": 200
},
"viaIR": true,
"evmVersion": "paris",
"outputSelection": {
"*": {
"*": [
"evm.bytecode",
"evm.deployedBytecode",
"devdoc",
"userdoc",
"metadata",
"abi"
]
}
}
}Contract Security Audit
- No Contract Security Audit Submitted- Submit Audit Here
Contract ABI
API[{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":true,"internalType":"address","name":"approved","type":"address"},{"indexed":true,"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"Approval","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":true,"internalType":"address","name":"operator","type":"address"},{"indexed":false,"internalType":"bool","name":"approved","type":"bool"}],"name":"ApprovalForAll","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"bondId","type":"uint256"}],"name":"LiquidityBondBurned","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"oldLiquidityBondLocker","type":"address"},{"indexed":true,"internalType":"address","name":"newLiquidityBondLocker","type":"address"}],"name":"LiquidityBondLockerUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"to","type":"address"},{"indexed":true,"internalType":"uint256","name":"bondId","type":"uint256"},{"indexed":true,"internalType":"uint256","name":"uniswapV3PositionId","type":"uint256"}],"name":"LiquidityBondMinted","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"minter","type":"address"}],"name":"MinterAdded","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"minter","type":"address"}],"name":"MinterRemoved","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"oldOperatorRegistry","type":"address"},{"indexed":true,"internalType":"address","name":"newOperatorRegistry","type":"address"}],"name":"OperatorRegistryUpdated","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":"from","type":"address"},{"indexed":true,"internalType":"address","name":"to","type":"address"},{"indexed":true,"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"Transfer","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"account","type":"address"}],"name":"Unpaused","type":"event"},{"inputs":[{"internalType":"address","name":"_minter","type":"address"}],"name":"addMinter","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"approve","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"}],"name":"balanceOf","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"bondType","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"bonds","outputs":[{"internalType":"uint256","name":"bondId","type":"uint256"},{"internalType":"uint256","name":"uniswapV3PositionId","type":"uint256"},{"internalType":"bool","name":"isRedemeed","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_bondId","type":"uint256"}],"name":"burn","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"currentIndex","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"getApproved","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_bondId","type":"uint256"}],"name":"getBondInfo","outputs":[{"internalType":"uint256","name":"uniswapV3PositionId","type":"uint256"},{"internalType":"uint256","name":"startTime","type":"uint256"},{"internalType":"uint256","name":"duration","type":"uint256"},{"internalType":"uint256","name":"durationLeft","type":"uint256"},{"internalType":"uint256","name":"rewardsGMI","type":"uint256"},{"internalType":"uint256","name":"rewardsWETH9","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"string","name":"name_","type":"string"},{"internalType":"string","name":"symbol_","type":"string"},{"internalType":"address","name":"liquidityBondLocker_","type":"address"},{"internalType":"address","name":"operatorRegistry_","type":"address"},{"internalType":"string","name":"bondType_","type":"string"}],"name":"initialize","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"},{"internalType":"address","name":"operator","type":"address"}],"name":"isApprovedForAll","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"liquidityBondLocker","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_to","type":"address"},{"internalType":"uint256","name":"_uniswapV3PositionId","type":"uint256"}],"name":"mint","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"minters","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"name","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"operatorRegistry","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"ownerOf","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"pause","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"paused","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_minter","type":"address"}],"name":"removeMinter","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"renounceOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"from","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"safeTransferFrom","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"from","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"},{"internalType":"bytes","name":"_data","type":"bytes"}],"name":"safeTransferFrom","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"operator","type":"address"},{"internalType":"bool","name":"approved","type":"bool"}],"name":"setApprovalForAll","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes4","name":"interfaceId","type":"bytes4"}],"name":"supportsInterface","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"symbol","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_tokenId","type":"uint256"}],"name":"tokenURI","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"from","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"transferFrom","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"unpause","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_liquidityBondLocker","type":"address"}],"name":"updateLiquidityBondLocker","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_operatorRegistry","type":"address"}],"name":"updateOperatorRegistry","outputs":[],"stateMutability":"nonpayable","type":"function"}]Contract Creation Code
608080604052346100175761587990816200001d8239f35b600080fdfe6080604052600436101561001257600080fd5b60003560e01c806301ffc9a71461022757806306fdde0314610222578063081812fc1461021d578063095ea7b3146102185780630989f2971461021357806323b872dd1461020e57806326987b60146102095780633092afd5146102045780633392bec8146101ff5780633f4ba83a146101fa57806340c10f19146101f557806342842e0e146101f057806342966c68146101eb57806358c2225b146101e65780635c975abb146101e15780635f1c17c0146101dc5780636352211e146101d757806370a08231146101d2578063715018a6146101cd57806374ec06bc146101c85780638456cb59146101c35780638da5cb5b146101be57806394c8636f146101b957806395d89b41146101b4578063983b2d56146101af578063a22cb465146101aa578063b5215aaa146101a5578063b88d4fde146101a0578063c87b56dd1461019b578063db74ee3114610196578063e985e9c514610191578063f2fde38b1461018c5763f46eccc41461018757600080fd5b611bd7565b611b3d565b611ad5565b611983565b6114d7565b611470565b611360565b6112a2565b611192565b6110ea565b611012565b610f06565b610e9a565b610e70565b610e0f565b610d69565b610d4b565b610d02565b610cdf565b610cb5565b610b2f565b610b07565b610953565b6108b2565b61086f565b610776565b610757565b6105e5565b61052a565b610437565b6103f6565b61030d565b610243565b6001600160e01b031981160361023e57565b600080fd5b3461023e57602036600319011261023e5760206004356102628161022c565b63ffffffff60e01b166380ac58cd60e01b81149081156102a0575b811561028f575b506040519015158152f35b6301ffc9a760e01b14905038610284565b635b5e139f60e01b8114915061027d565b60005b8381106102c45750506000910152565b81810151838201526020016102b4565b906020916102ed815180928185528580860191016102b1565b601f01601f1916010190565b90602061030a9281815201906102d4565b90565b3461023e576000806003193601126103f35760405190806065549061033182610f2f565b808552916020916001918281169081156103c6575060011461036e575b61036a8661035e81880382610ff1565b604051918291826102f9565b0390f35b9350606584527f8ff97419363ffd7000167f130ef7168fbea05faf9251824ca5043f113cc6a7c75b8385106103b35750505050810160200161035e8261036a3861034e565b8054868601840152938201938101610396565b905086955061036a9693506020925061035e94915060ff191682840152151560051b82010192933861034e565b80fd5b3461023e57602036600319011261023e576020610414600435611c1a565b6040516001600160a01b039091168152f35b6001600160a01b0381160361023e57565b3461023e57604036600319011261023e5760043561045481610426565b6024356104608161269e565b916001600160a01b0380841690821681146104db576104929361048d913314908115610494575b50611cac565b612f07565b005b6001600160a01b03166000908152606a602052604090206104d591506104ce9033905b9060018060a01b0316600052602052604060002090565b5460ff1690565b38610487565b60405162461bcd60e51b815260206004820152602160248201527f4552433732313a20617070726f76616c20746f2063757272656e74206f776e656044820152603960f91b6064820152608490fd5b3461023e57602036600319011261023e5760043561054781610426565b6097546001600160a01b039182916105629083163314611d1e565b169061056f821515611d69565b6101328281549283169261058584831415611db4565b6001600160a01b0319161790557ff8b0ee9361a0f0225b39f58411465016adbd34abff194e6119b537fa8b063247600080a3005b606090600319011261023e576004356105d181610426565b906024356105de81610426565b9060443590565b3461023e576105f3366105b9565b906106066106018333612fee565b611e10565b32331480156106df575b610619906130d9565b803b158015610635575b9261063061049294613135565b61531e565b506101325461065a9061064e906001600160a01b031681565b6001600160a01b031690565b604051633185c44d60e21b81523060048201526001600160a01b03831660248201529390602090859060449082905afa9384156106da5761049294610630916000916106ab575b5091945050610623565b6106cd915060203d6020116106d3575b6106c58183610ff1565b810190612dbe565b386106a1565b503d6106bb565b611f33565b50610132546106f89061064e906001600160a01b031681565b604051633185c44d60e21b815230600482015233602482015290602090829060449082905afa80156106da5761061991600091610738575b509050610610565b610751915060203d6020116106d3576106c58183610ff1565b38610730565b3461023e57600036600319011261023e57602061012e54604051908152f35b3461023e57602036600319011261023e5760043561079381610426565b6097546001600160a01b03906107ac9082163314611d1e565b81166107b9811515611d69565b60009181835261013060205260ff60408420541615610819576001600160a01b0316600090815261013060205260409020805460ff191690557fe94479a9f7e1952cc78f2d6baab678adc1b772d936c6583def489e524cb666928280a280f35b60405162461bcd60e51b815260206004820152602860248201527f4c6971756964697479426f6e64733a3a2041646472657373206973206e6f7420604482015267309036b4b73a32b960c11b6064820152608490fd5b3461023e57602036600319011261023e5760c061088d60043561219f565b93604093919351958652602086015260408501526060840152608083015260a0820152f35b3461023e57600036600319011261023e576108d860018060a01b03609754163314611d1e565b60c95460ff8116156109175760ff191660c9557f5db9ee0a495bf2e6ff9c91a7834c1ba4fdd244a5e8aa4e537bd38aeae4b073aa6020604051338152a1005b60405162461bcd60e51b815260206004820152601460248201527314185d5cd8589b194e881b9bdd081c185d5cd95960621b6044820152606490fd5b3461023e57604036600319011261023e5760043561097081610426565b60243560009133835261013060205260ff6040842054168015610af3575b610997906124a5565b6109a660ff60c9541615612500565b6109b5600260fb54141561253f565b600260fb556001600160a01b038116906109d0821515611d69565b6109db83151561258b565b610131546109f39061064e906001600160a01b031681565b60405163f4dadc6160e01b8152600481018590529060e090829060249082905afa80156106da5760c0610a3391610a39938891610ac4575b500151151590565b156125ef565b610a9161012e91610a53610a4d845461264f565b61012e55565b610a898354610a84610a636113ef565b9180835288602084015289604084015260005261012f602052604060002090565b61265e565b825490613190565b54907f72970e8e667928f70b2da0ecfd32c52c589298ecc73c7c540586fb6003ba040f8480a4610ac1600160fb55565b80f35b610ae6915060e03d60e011610aec575b610ade8183610ff1565b810190611ebe565b38610a2b565b503d610ad4565b506097546001600160a01b0316331461098e565b3461023e57610492610b18366105b9565b9060405192610b2684610f7f565b60008452612716565b3461023e57602036600319011261023e5760043560009033825261013060205260ff6040832054168015610ca1575b610b67906124a5565b610b7660ff60c9541615612500565b610b85600260fb54141561253f565b600260fb558015610c5d576000818152606760205260409020546001600160a01b031615610c0c57610bd56002610bc78360005261012f602052604060002090565b01805460ff19166001179055565b610bde816132ca565b7f0d7a61e190b0f85b64fde8b74afceb2d1894072e7b5ee31e2295b51ad0d441bc8280a2610ac1600160fb55565b60405162461bcd60e51b8152602060048201526024808201527f4c6971756964697479426f6e64733a3a20426f6e6420646f6573206e6f7420656044820152631e1a5cdd60e21b6064820152608490fd5b606460405162461bcd60e51b815260206004820152602060248201527f4c6971756964697479426f6e64733a3a20426f6e64204944206973207a65726f6044820152fd5b506097546001600160a01b03163314610b5e565b3461023e57600036600319011261023e57610132546040516001600160a01b039091168152602090f35b3461023e57600036600319011261023e57602060ff60c954166040519015158152f35b3461023e57602036600319011261023e5760043560005261012f6020526060604060002080549060ff600260018301549201541690604051928352602083015215156040820152f35b3461023e57602036600319011261023e57602061041460043561269e565b3461023e57602036600319011261023e57600435610d8681610426565b6001600160a01b03168015610db757600052606860205261036a604060002054604051918291829190602083019252565b60405162461bcd60e51b815260206004820152602a60248201527f4552433732313a2062616c616e636520717565727920666f7220746865207a65604482015269726f206164647265737360b01b6064820152608490fd5b3461023e576000806003193601126103f35760975481906001600160a01b03811690610e3c338314611d1e565b6001600160a01b0319166097557f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e08280a380f35b3461023e57600036600319011261023e57610131546040516001600160a01b039091168152602090f35b3461023e57600036600319011261023e57610ec060018060a01b03609754163314611d1e565b600160c954610ed260ff821615612500565b60ff19161760c9557f62e78cea01bee320cd4e420270b5ea74000d11b0c9f74754ebdbfc544b05a2586020604051338152a1005b3461023e57600036600319011261023e576097546040516001600160a01b039091168152602090f35b90600182811c92168015610f5f575b6020831014610f4957565b634e487b7160e01b600052602260045260246000fd5b91607f1691610f3e565b634e487b7160e01b600052604160045260246000fd5b602081019081106001600160401b03821117610f9a57604052565b610f69565b606081019081106001600160401b03821117610f9a57604052565b610dc081019081106001600160401b03821117610f9a57604052565b604081019081106001600160401b03821117610f9a57604052565b90601f801991011681019081106001600160401b03821117610f9a57604052565b3461023e576000806003193601126103f357604051908061012d805461103781610f2f565b808652926020926001928084169081156110bb5750600114611064575b61036a8761035e81890382610ff1565b815293507f193a3ae4da5049eb74cee39e4cf5827f7ce7b1d1d1775ef1c6311eb60558e6d55b8385106110a85750505050810160200161035e8261036a3880611054565b805486860184015293820193810161108a565b91505086955061036a9693506020925061035e94915060ff191682840152151560051b82010192933880611054565b3461023e576000806003193601126103f35760405190806066549061110e82610f2f565b808552916020916001918281169081156103c6575060011461113a5761036a8661035e81880382610ff1565b9350606684527f46501879b8ca8525e8c2fd519e2fbfcfa2ebea26501294aa02cbfcfb12e943545b83851061117f5750505050810160200161035e8261036a3861034e565b8054868601840152938201938101611162565b3461023e57602036600319011261023e576004356111af81610426565b6097546001600160a01b03906111c89082163314611d1e565b81166111d5811515611d69565b60009181835261013060205260ff60408420541661123e576001600160a01b0316600090815261013060205260409020611217905b805460ff19166001179055565b7f6ae172837ea30b801fbfcdd4108aa1d5bf8ff775444fd70256b44e6bf3dfc3f68280a280f35b60405162461bcd60e51b815260206004820152602c60248201527f4c6971756964697479426f6e64733a3a204164647265737320697320616c726560448201526b30b23c90309036b4b73a32b960a11b6064820152608490fd5b8015150361023e57565b3461023e57604036600319011261023e576004356112bf81610426565b6024356112cb81611298565b813b1580156112e8575b916112e261049293612dd3565b33615435565b5061013254604051633185c44d60e21b81523060048201526001600160a01b03848116602483015290939160209185916044918391165afa9283156106da57610492936112e291600091611341575b50919350506112d5565b61135a915060203d6020116106d3576106c58183610ff1565b38611337565b3461023e57602036600319011261023e5760043561137d81610426565b6097546001600160a01b039182916113989083163314611d1e565b16906113a5821515611d69565b610131828154928316926113bb84831415611db4565b6001600160a01b0319161790557f748f722ee0920121a4d9633c16ef2dd3a68219e5c44480aeb31ab9df22412424600080a3005b604051906113fc82610f9f565b565b604051906101e082018281106001600160401b03821117610f9a57604052565b6001600160401b038111610f9a57601f01601f191660200190565b9291926114458261141e565b916114536040519384610ff1565b82948184528183011161023e578281602093846000960137010152565b3461023e57608036600319011261023e5760043561148d81610426565b60243561149981610426565b606435916001600160401b03831161023e573660238401121561023e576114cd610492933690602481600401359101611439565b9160443591612716565b3461023e57602036600319011261023e576115036004356114f78161219f565b919690959493946134d3565b936040958651946395d89b4160e01b8652600086600481305afa9586156106da57600096611943575b50611535613617565b936115408888614641565b9461154a836134d3565b61155385614c5d565b61155c84614c5d565b9061156692614d62565b8a5196879260208401611578916128d6565b611581916128d6565b61158a916128d6565b0399601f199a8b8101875261159f9087610ff1565b6115a99042612192565b916115b3906134d3565b936115bd906134d3565b956115c7906134d3565b926115d1906134d3565b906115db906134d3565b916115e5906134d3565b89517f222c202261747472696275746573223a205b7b2274726169745f74797065223a60208201527f2022416c676562726120563320506f736974696f6e204944222c202276616c7560408201526432911d101160d91b606082015296879591949160658701611654916128d6565b7f227d2c207b2274726169745f74797065223a202253746172742054696d65222c81526a10113b30b63ab2911d101160a91b6020820152602b01611697916128d6565b7f227d2c207b2274726169745f74797065223a2022426f6e64204475726174696f81526d37111610113b30b63ab2911d101160911b6020820152602e016116dd916128d6565b7f227d2c207b2274726169745f74797065223a2022474d4920526577617264732281526b1610113b30b63ab2911d101160a11b6020820152602c01611721916128d6565b7f227d2c207b2274726169745f74797065223a2022506172746e657220746f6b6581527537102932bbb0b93239911610113b30b63ab2911d101160511b602082015260360161176f916128d6565b7f227d2c207b22646973706c61795f74797065223a202264617465222c2022747281527f6169745f74797065223a2022556e6c6f636b2054696d65222c202276616c75656020820152620111d160ed1b60408201526043016117d0916128d6565b627d5d7d60e81b81526003010386810183526117ec9083610ff1565b6117f461517f565b6117fd91615762565b8451693d913730b6b2911d101160b11b6020820152938493602a8501611822916128d6565b61202360f01b8152600201611836916128d6565b7f222c20226465736372697074696f6e223a202241206c6f636b656420556e697381527f776170205633206c697175696469747920626f6e64207769746820726577617260208201527f64732e222c2022696d616765223a2022646174613a696d6167652f7376672b786040820152691b5b0ed8985cd94d8d0b60b21b6060820152606a016118c4916128d6565b6118cd916128d6565b0383810182526118dd9082610ff1565b6118e561517f565b6118ee91615762565b81517f646174613a6170706c69636174696f6e2f6a736f6e3b6261736536342c000000602082015292908390603d8201611927916128d6565b0390810183526119379083610ff1565b5161036a8192826102f9565b6119619196503d806000833e6119598183610ff1565b810190612878565b943861152c565b9080601f8301121561023e5781602061030a93359101611439565b3461023e5760a036600319011261023e576001600160401b0360043581811161023e576119b4903690600401611968565b9060243581811161023e576119cd903690600401611968565b90604435906119db82610426565b606435906119e882610426565b60843590811161023e57611a00903690600401611968565b916000549360ff8560081c169485600014611acc5750303b155b15611a7057611a2f94159586611a4557612c1c565b611a3557005b61049261ff001960005416600055565b611a5961010061ff00196000541617600055565b611a6b600160ff196000541617600055565b612c1c565b60405162461bcd60e51b815260206004820152602e60248201527f496e697469616c697a61626c653a20636f6e747261637420697320616c72656160448201526d191e481a5b9a5d1a585b1a5e995960921b6064820152608490fd5b60ff1615611a1a565b3461023e57604036600319011261023e57602060ff611b31600435611af981610426565b60243590611b0682610426565b60018060a01b0316600052606a845260406000209060018060a01b0316600052602052604060002090565b54166040519015158152f35b3461023e57602036600319011261023e57600435611b5a81610426565b6097546001600160a01b0390611b739082163314611d1e565b811615611b8357610492906133e1565b60405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201526564647265737360d01b6064820152608490fd5b3461023e57602036600319011261023e57600435611bf481610426565b60018060a01b0316600052610130602052602060ff604060002054166040519015158152f35b6000818152606760205260409020546001600160a01b031615611c52576000908152606960205260409020546001600160a01b031690565b60405162461bcd60e51b815260206004820152602c60248201527f4552433732313a20617070726f76656420717565727920666f72206e6f6e657860448201526b34b9ba32b73a103a37b5b2b760a11b6064820152608490fd5b15611cb357565b60405162461bcd60e51b815260206004820152603860248201527f4552433732313a20617070726f76652063616c6c6572206973206e6f74206f7760448201527f6e6572206e6f7220617070726f76656420666f7220616c6c00000000000000006064820152608490fd5b15611d2557565b606460405162461bcd60e51b815260206004820152602060248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e65726044820152fd5b15611d7057565b606460405162461bcd60e51b815260206004820152602060248201527f4c6971756964697479426f6e64733a3a2041646472657373206973207a65726f6044820152fd5b15611dbb57565b60405162461bcd60e51b815260206004820152602760248201527f4c6971756964697479426f6e64733a3a204164647265737320697320616c726560448201526618591e481cd95d60ca1b6064820152608490fd5b15611e1757565b60405162461bcd60e51b815260206004820152603160248201527f4552433732313a207472616e736665722063616c6c6572206973206e6f74206f6044820152701ddb995c881b9bdc88185c1c1c9bdd9959607a1b6064820152608490fd5b90604051606081018181106001600160401b03821117610f9a57604052604060ff6002839580548552600181015460208601520154161515910152565b51906113fc82611298565b908160e091031261023e576040519060e08201908282106001600160401b03831117610f9a5760c091604052805183526020810151602084015260408101516040840152606081015160608401526080810151608084015260a081015160a08401520151611f2b81611298565b60c082015290565b6040513d6000823e3d90fd5b51906113fc82610426565b51908160020b820361023e57565b90816101e091031261023e57611f6c6113fe565b9080518252611f7d60208201611f3f565b6020830152611f8e60408201611f3f565b6040830152611f9f60608201611f3f565b606083015260808101516080830152611fba60a08201611f4a565b60a0830152611fcb60c08201611f4a565b60c083015260e081015160e08301526101008082015190830152610120808201519083015261014080820151908301526101608082015190830152610180612014818301611eb3565b908301526101a0612026818301611f3f565b908301526120386101c0809201611eb3565b9082015290565b634e487b7160e01b600052601160045260246000fd5b60001981019190821161206457565b61203f565b601203906012821161206457565b60111981019190821161206457565b9190820391821161206457565b9081602091031261023e575190565b9081602091031261023e575161030a81610426565b51906001600160801b038216820361023e57565b908161016091031261023e5780516bffffffffffffffffffffffff8116810361023e579160208201516120fd81610426565b91604081015161210c81610426565b9161211960608301611f3f565b9161212660808201611f4a565b9161213360a08301611f4a565b9161214060c082016120b7565b9160e0820151916101008101519161030a61014061216161012085016120b7565b93016120b7565b906001820180921161206457565b906004820180921161206457565b906002820180921161206457565b9190820180921161206457565b6121b76121bc9160005261012f602052604060002090565b611e76565b610131549091906121d79061064e906001600160a01b031681565b602083810180516040805163f4dadc6160e01b8152600480820193909352939590949260e085602481875afa9485156106da57600095612484575b5084860151865163017c705f60e61b815284810191825297906101e09081908a9081906020010381895afa80156106da5761228a9961014092600092612457575b5050019889518042101560001461244657506000975b83518151634086b3ad60e11b81528781019182529a84918c91829160200190565b03818a5afa998a156106da5760009a612427575b508051630e5047b360e41b815295838782818b5afa9485156106da576122eb976000966123f8575b50518251809663133f757160e31b825281806101609b8c958783019190602083019252565b03916001600160a01b03165afa9485156106da576000976000966123ac575b50509061233f94959697849260608b519b01519d51945192518097819482936307d8992d60e31b845283019190602083019252565b03915afa9081156106da57612373936123619360009361237d575b5050612086565b966001600160801b0380931690612192565b9396959493921690565b61239d929350803d106123a5575b6123958183610ff1565b810190612093565b90388061235a565b503d61238b565b85939297985061233f965090816123d792903d106123f1575b6123cf8183610ff1565b8101906120cb565b99509750505050505050509890958199989792935061230a565b503d6123c5565b612419919650853d8711612420575b6124118183610ff1565b8101906120a2565b94386122c6565b503d612407565b61243f919a50833d85116123a5576123958183610ff1565b983861229e565b612451904290612086565b97612269565b6124769250803d1061247d575b61246e8183610ff1565b810190611f58565b3880612253565b503d612464565b61249e91955060e03d60e011610aec57610ade8183610ff1565b9338612212565b156124ac57565b60405162461bcd60e51b815260206004820152602660248201527f4c6971756964697479426f6e64733a3a204e6f742061206d696e746572206f726044820152651037bbb732b960d11b6064820152608490fd5b1561250757565b60405162461bcd60e51b815260206004820152601060248201526f14185d5cd8589b194e881c185d5cd95960821b6044820152606490fd5b1561254657565b60405162461bcd60e51b815260206004820152601f60248201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c006044820152606490fd5b1561259257565b60405162461bcd60e51b815260206004820152602f60248201527f4c6971756964697479426f6e64733a3a20556e697377617020563320706f736960448201526e74696f6e204944206973207a65726f60881b6064820152608490fd5b156125f657565b60405162461bcd60e51b815260206004820152602b60248201527f4c6971756964697479426f6e64733a3a20506f736974696f6e20697320616c7260448201526a1958591e481b1bd8dad95960aa1b6064820152608490fd5b60001981146120645760010190565b600260406113fc9380518455602081015160018501550151151591019060ff801983541691151516179055565b6040519061269882610f7f565b60008252565b6000908152606760205260409020546001600160a01b031680156126bf5790565b60405162461bcd60e51b815260206004820152602960248201527f4552433732313a206f776e657220717565727920666f72206e6f6e657869737460448201526832b73a103a37b5b2b760b91b6064820152608490fd5b929190926127276106018333612fee565b3233148015612800575b61273a906130d9565b833b15801561276c575b936127679392916127576113fc96613135565b61276283838361531e565b615572565b61347d565b5061013254909291906127899061064e906001600160a01b031681565b604051633185c44d60e21b81523060048201526001600160a01b03861660248201529490602090869060449082905afa9384156106da57612757612767956113fc976000916127e1575b509296505091929350612744565b6127fa915060203d6020116106d3576106c58183610ff1565b386127d3565b50610132546128199061064e906001600160a01b031681565b604051633185c44d60e21b815230600482015233602482015290602090829060449082905afa80156106da5761273a91600091612859575b509050612731565b612872915060203d6020116106d3576106c58183610ff1565b38612851565b60208183031261023e578051906001600160401b03821161023e570181601f8201121561023e5780516128aa8161141e565b926128b86040519485610ff1565b8184526020828401011161023e5761030a91602080850191016102b1565b906128e9602092828151948592016102b1565b0190565b601f81116128f9575050565b60009060656000527f8ff97419363ffd7000167f130ef7168fbea05faf9251824ca5043f113cc6a7c7906020601f850160051c83019410612955575b601f0160051c01915b82811061294a57505050565b81815560010161293e565b9092508290612935565b601f811161296b575050565b60009060666000527f46501879b8ca8525e8c2fd519e2fbfcfa2ebea26501294aa02cbfcfb12e94354906020601f850160051c830194106129c7575b601f0160051c01915b8281106129bc57505050565b8181556001016129b0565b90925082906129a7565b601f81116129dd575050565b60009061012d6000527f193a3ae4da5049eb74cee39e4cf5827f7ce7b1d1d1775ef1c6311eb60558e6d5906020601f850160051c83019410612a3a575b601f0160051c01915b828110612a2f57505050565b818155600101612a23565b9092508290612a1a565b9081516001600160401b038111610f9a57612a6981612a64606654610f2f565b61295f565b602080601f8311600114612aac57508190612a9c9394600092612aa1575b50508160011b916000199060031b1c19161790565b606655565b015190503880612a87565b90601f19831694612adf60666000527f46501879b8ca8525e8c2fd519e2fbfcfa2ebea26501294aa02cbfcfb12e9435490565b926000905b878210612b1c575050836001959610612b03575b505050811b01606655565b015160001960f88460031b161c19169055388080612af8565b80600185968294968601518155019501930190612ae4565b9081516001600160401b038111610f9a5761012d90612b5c81612b578454610f2f565b6129d1565b602080601f8311600114612b9357508190612b8f939495600092612aa15750508160011b916000199060031b1c19161790565b9055565b90601f19831695612bc761012d6000527f193a3ae4da5049eb74cee39e4cf5827f7ce7b1d1d1775ef1c6311eb60558e6d590565b926000905b888210612c0457505083600195969710612beb575b505050811b019055565b015160001960f88460031b161c19169055388080612be1565b80600185968294968601518155019501930190612bcc565b93929193612c3a60ff60005460081c16612c35816151de565b6151de565b8051906001600160401b038211610f9a57612c5f82612c5a606554610f2f565b6128ed565b602090816001601f851114612d23575093612cad612d0894612ca58561120a9996612d03966113fc9c9a600092612aa15750508160011b916000199060031b1c19161790565b606555612a44565b612cb561523e565b612cbd61525c565b612cc561527d565b61013180546001600160a01b0319166001600160a01b03871617905561013280546001600160a01b0319166001600160a01b03909216919091179055565b612b34565b6001600160a01b031660009081526101306020526040902090565b60656000529190601f1984167f8ff97419363ffd7000167f130ef7168fbea05faf9251824ca5043f113cc6a7c7936000905b828210612da657505094600185612d03956113fc9b9995612cad9561120a9c99612d089b10612d8d575b505050811b01606555612a44565b015160001960f88460031b161c19169055388080612d7f565b80600186978294978701518155019601940190612d55565b9081602091031261023e575161030a81611298565b15612dda57565b60405162461bcd60e51b815260206004820152602b60248201527f4c6971756964697479426f6e64733a204f70657261746f72206973206e6f742060448201526a1dda1a5d195b1a5cdd195960aa1b6064820152608490fd5b6000803b158015612e9a575b612e4890612dd3565b81815260696020526040812080546001600160a01b03191690556001600160a01b03612e738361269e565b167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b9258280a4565b5061013254604051633185c44d60e21b81523060048201526024810183905290602090829060449082906001600160a01b03165afa80156106da57612e48918391612ee8575b509050612e3f565b612f01915060203d6020116106d3576106c58183610ff1565b38612ee0565b803b158015612f7e575b612f1a90612dd3565b600082815260696020526040902080546001600160a01b0319166001600160a01b0383161790556001600160a01b0380612f538461269e565b169116907f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925600080a4565b5061013254604051633185c44d60e21b81523060048201526001600160a01b038381166024830152909160209183916044918391165afa80156106da57612f1a91600091612fcf575b509050612f11565b612fe8915060203d6020116106d3576106c58183610ff1565b38612fc7565b6000828152606760205260409020546001600160a01b03161561307f576130148261269e565b6001600160a01b038281168282168114949091908515613067575b505050821561303d57505090565b6001600160a01b03166000908152606a6020526040902060ff925061306291906104b7565b541690565b6130749192939550611c1a565b16149138808061302f565b60405162461bcd60e51b815260206004820152602c60248201527f4552433732313a206f70657261746f7220717565727920666f72206e6f6e657860448201526b34b9ba32b73a103a37b5b2b760a11b6064820152608490fd5b156130e057565b60405162461bcd60e51b815260206004820152602760248201527f4c6971756964697479426f6e64733a2053656e646572206973206e6f742077686044820152661a5d195b1a5cdd60ca1b6064820152608490fd5b1561313c57565b60405162461bcd60e51b815260206004820152602660248201527f4c6971756964697479426f6e64733a205265636569766572206e6f74207768696044820152651d195b1a5cdd60d21b6064820152608490fd5b6001600160a01b038116908115613286576000838152606760205260409020546001600160a01b0316613241576001600160a01b038116600090815260686020526040902061321991906131e48154612168565b90556131fa846000526067602052604060002090565b80546001600160a01b0319166001600160a01b03909216919091179055565b60007fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef8180a4565b60405162461bcd60e51b815260206004820152601c60248201527f4552433732313a20746f6b656e20616c7265616479206d696e746564000000006044820152606490fd5b606460405162461bcd60e51b815260206004820152602060248201527f4552433732313a206d696e7420746f20746865207a65726f20616464726573736044820152fd5b6132d38161269e565b60003b15801561336d575b906132ea600092612dd3565b6132f383615299565b6001600160a01b03811660009081526068602052604090206133158154612055565b905561333e61332e846000526067602052604060002090565b80546001600160a01b0319169055565b6001600160a01b03167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef8280a4565b5061013254604051633185c44d60e21b8152306004820152600060248201529190602090839060449082906001600160a01b03165afa9182156106da576000926132ea9184916133c2575b50919250506132de565b6133db915060203d6020116106d3576106c58183610ff1565b386133b8565b609780546001600160a01b039283166001600160a01b0319821681179092559091167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0600080a3565b60809060208152603260208201527f4552433732313a207472616e7366657220746f206e6f6e20455243373231526560408201527131b2b4bb32b91034b6b83632b6b2b73a32b960711b60608201520190565b1561348457565b60405162461bcd60e51b81528061349d6004820161342a565b0390fd5b906134ab8261141e565b6134b86040519182610ff1565b82815280926134c9601f199161141e565b0190602036910137565b806000917a184f03e93ff9f4daa797ed6e38ed64bf6a1f01000000000000000080821015613609575b506d04ee2d6d415b85acef8100000000808310156135fa575b50662386f26fc10000808310156135eb575b506305f5e100808310156135dc575b50612710808310156135cd575b5060648210156135bd575b600a809210156135b3575b60019081602161356b600187016134a1565b95860101905b61357d575b5050505090565b600019019083906f181899199a1a9b1b9c1cb0b131b232b360811b8282061a8353049182156135ae57919082613571565b613576565b9160010191613559565b919060646002910491019161354e565b60049193920491019138613543565b60089193920491019138613536565b60109193920491019138613527565b60209193920491019138613515565b6040935081049150386134fc565b6040519061362482610fba565b610d9a82527f786c696e6b3a687265663d2223746578742d706174682d61223e000000000000610da0837f3c7376672077696474683d2232393022206865696768743d223530302220766960208201527f6577426f783d2230203020323930203530302220786d6c6e733d22687474703a60408201527f2f2f7777772e77332e6f72672f323030302f7376672220786d6c6e733a786c6960608201527f6e6b3d22687474703a2f2f7777772e77332e6f72672f313939392f786c696e6b60808201527f223e3c646566733e3c66696c7465722069643d226631223e3c6665496d61676560a08201527f20726573756c743d2270302220786c696e6b3a687265663d22646174613a696d60c08201527f6167652f7376672b786d6c3b6261736536342c50484e325a794233615752306160e08201527f44306e4d6a6b774a79426f5a576c6e614851394a7a55774d436367646d6c6c646101008201527f304a766544306e4d434177494449354d4341314d44416e494868746247357a506101208201527f53646f644852774f693876643364334c6e637a4c6d39795a7938794d4441774c6101408201527f334e325a79632b50484a6c5933516764326c6b644767394a7a49354d4842344a6101608201527f79426f5a576c6e614851394a7a55774d4842344a79426d615778735053636a4d6101808201527f574d335a4452694a79382b5043397a646d632b222f3e203c6665496d616765206101a08201527f726573756c743d2270312220786c696e6b3a687265663d22646174613a696d616101c08201527f67652f7376672b786d6c3b6261736536342c50484e325a7942336157523061446101e08201527f306e4d6a6b774a79426f5a576c6e614851394a7a55774d436367646d6c6c64306102008201527f4a766544306e4d434177494449354d4341314d44416e494868746247357a50536102208201527f646f644852774f693876643364334c6e637a4c6d39795a7938794d4441774c336102408201527f4e325a79632b50474e70636d4e735a53426a6544306e4d6a49794a79426a65546102608201527f306e4d6a41794a794279505363784d6a4277654363675a6d6c736244306e49326102808201527f5a6d5a6a6b354e796376506a777663335a6e50673d3d22202f3e203c6665496d6102a08201527f61676520726573756c743d2270322220786c696e6b3a687265663d22646174616102c08201527f3a696d6167652f7376672b786d6c3b6261736536342c50484e325a7942336157806102e08301527f52306144306e4d6a6b774a79426f5a576c6e614851394a7a55774d436367646d806103008401527f6c6c64304a766544306e4d434177494449354d4341314d44416e49486874624790816103208501527f357a5053646f644852774f693876643364334c6e637a4c6d39795a7938794d4492836103408601527f41774c334e325a79632b50474e70636d4e735a53426a6544306e4f44516e49476103608601527f4e355053637a4f44456e494849394a7a45794d4842344a79426d6157787350536103808601527f636a4f574d334d6a4d344a79382b5043397a646d632b22202f3e203c6665496d6103a08601527f61676520726573756c743d2270332220786c696e6b3a687265663d22646174616103c08601526103e08501526104008401526104208301526104408201527f41774c334e325a79632b50474e70636d4e735a53426a6544306e4d6a55324a796104608201527f426a6554306e4e4441334a794279505363784d444277654363675a6d6c7362446104808201527f306e497a526b4e6d49784e436376506a777663335a6e50673d3d22202f3e203c6104a08201527f6665426c656e64206d6f64653d226f7665726c61792220696e3d2270302220696104c08201527f6e323d22703122202f3e203c6665426c656e64206d6f64653d226578636c75736104e08201527f696f6e2220696e323d22703222202f3e203c6665426c656e64206d6f64653d226105008201527f6f7665726c61792220696e323d2270332220726573756c743d22626c656e644f6105208201527f757422202f3e203c6665476175737369616e426c757220696e3d22626c656e646105408201527f4f75742220737464446576696174696f6e3d22343222202f3e203c2f66696c746105608201527f65723e203c636c6970506174682069643d22636f726e657273223e203c7265636105808201527f742077696474683d2232393022206865696768743d22353030222072783d22346105a08201527f32222072793d22343222202f3e203c2f636c6970506174683e203c70617468206105c08201527f69643d22746578742d706174682d612220643d224d34302031322048323530206105e08201527f41323820323820302030203120323738203430205634363020413238203238206106008201527f30203020312032353020343838204834302041323820323820302030203120316106208201527f32203436302056343020413238203238203020302031203430203132207a22206106408201527f2f3e203c706174682069643d226d696e696d61702220643d224d3233342034346106608201527f3443323334203435372e393439203234322e32312034363320323533203436336106808201527f22202f3e203c66696c7465722069643d22746f702d726567696f6e2d626c75726106a08201527f223e203c6665476175737369616e426c757220696e3d22536f757263654772616106c08201527f706869632220737464446576696174696f6e3d22323422202f3e203c2f66696c6106e08201527f7465723e203c6c696e6561724772616469656e742069643d22677261642d75706107008201527f222078313d2231222078323d2230222079313d2231222079323d2230223e203c6107208201527f73746f70206f66667365743d22302e30222073746f702d636f6c6f723d2277686107408201527f697465222073746f702d6f7061636974793d223122202f3e203c73746f70206f6107608201527f66667365743d222e39222073746f702d636f6c6f723d227768697465222073746107808201527f6f702d6f7061636974793d223022202f3e203c2f6c696e6561724772616469656107a08201527f6e743e203c6c696e6561724772616469656e742069643d22677261642d646f776107c08201527f6e222078313d2230222078323d2231222079313d2230222079323d2231223e206107e08201527f3c73746f70206f66667365743d22302e30222073746f702d636f6c6f723d22776108008201527f68697465222073746f702d6f7061636974793d223122202f3e203c73746f70206108208201527f6f66667365743d22302e39222073746f702d636f6c6f723d22776869746522206108408201527f73746f702d6f7061636974793d223022202f3e203c2f6c696e656172477261646108608201527f69656e743e203c6d61736b2069643d22666164652d757022206d61736b436f6e6108808201527f74656e74556e6974733d226f626a656374426f756e64696e67426f78223e203c6108a08201527f726563742077696474683d223122206865696768743d2231222066696c6c3d226108c08201527f75726c2823677261642d75702922202f3e203c2f6d61736b3e203c6d61736b206108e08201527f69643d22666164652d646f776e22206d61736b436f6e74656e74556e6974733d6109008201527f226f626a656374426f756e64696e67426f78223e203c726563742077696474686109208201527f3d223122206865696768743d2231222066696c6c3d2275726c2823677261642d6109408201527f646f776e2922202f3e203c2f6d61736b3e203c6d61736b2069643d226e6f6e656109608201527f22206d61736b436f6e74656e74556e6974733d226f626a656374426f756e64696109808201527f6e67426f78223e203c726563742077696474683d223122206865696768743d226109a08201527f31222066696c6c3d22776869746522202f3e203c2f6d61736b3e203c6c696e656109c08201527f61724772616469656e742069643d22677261642d73796d626f6c223e203c73746109e08201527f6f70206f66667365743d22302e37222073746f702d636f6c6f723d2277686974610a008201527f65222073746f702d6f7061636974793d223122202f3e203c73746f70206f6666610a208201527f7365743d222e3935222073746f702d636f6c6f723d227768697465222073746f610a408201527f702d6f7061636974793d223022202f3e203c2f6c696e6561724772616469656e610a608201527f743e203c6d61736b2069643d22666164652d73796d626f6c22206d61736b436f610a808201527f6e74656e74556e6974733d227573657253706163654f6e557365223e203c7265610aa08201527f63742077696474683d22323930707822206865696768743d2232303070782220610ac08201527f66696c6c3d2275726c2823677261642d73796d626f6c2922202f3e203c2f6d61610ae08201527f736b3e203c2f646566733e203c6720636c69702d706174683d2275726c282363610b008201527f6f726e65727329223e203c726563742066696c6c3d2223316337643462222078610b208201527f3d223070782220793d22307078222077696474683d2232393070782220686569610b408201527f6768743d22353030707822202f3e203c72656374207374796c653d2266696c74610b608201527f65723a2075726c28236631292220783d223070782220793d2230707822207769610b808201527f6474683d22323930707822206865696768743d22353030707822202f3e203c67610ba08201527f207374796c653d2266696c7465723a75726c2823746f702d726567696f6e2d62610bc08201527f6c7572293b207472616e73666f726d3a7363616c6528312e35293b207472616e610be08201527f73666f726d2d6f726967696e3a63656e74657220746f703b223e203c72656374610c008201527f2066696c6c3d226e6f6e652220783d223070782220793d223070782220776964610c208201527f74683d22323930707822206865696768743d22353030707822202f3e203c656c610c408201527f6c697073652063783d22353025222063793d22307078222072783d2231383070610c608201527f78222072793d223132307078222066696c6c3d222330303022206f7061636974610c808201527f793d22302e383522202f3e203c2f673e203c7265637420783d22302220793d22610ca08201527f30222077696474683d2232393022206865696768743d22353030222072783d22610cc08201527f3432222072793d223432222066696c6c3d227267626128302c302c302c302922610ce08201527f207374726f6b653d2272676261283235352c3235352c3235352c302e32292220610d008201527f2f3e203c2f673e203c7465787420746578742d72656e646572696e673d226f70610d208201527f74696d697a655370656564223e203c74657874506174682073746172744f6666610d408201527f7365743d222d31303025222066696c6c3d2277686974652220666f6e742d6661610d608201527f6d696c793d2256657264616e612220666f6e742d73697a653d22313070782220610d808201520152565b61030a90614c10614b756149439461493d614957614951604051988761493d6148176148116148018e6147f46002829f5160208901936146858260208301876102b1565b018d6146b061202360f01b918260208501526147d66022825160208401966146b0828483018a6102b1565b01017f3c616e696d6174652061646469746976653d2273756d2220617474726962757481527f654e616d653d2273746172744f6666736574222066726f6d3d2230252220746f60208201527f3d22313030252220626567696e3d22307322206475723d22333073222072657060408201527f656174436f756e743d22696e646566696e69746522202f3e203c2f746578745060608201527f6174683e203c74657874506174682073746172744f66667365743d223025222060808201527f66696c6c3d2277686974652220666f6e742d66616d696c793d2256657264616e60a08201527f612220666f6e742d73697a653d22313070782220786c696e6b3a687265663d2260c08201526d11ba32bc3a16b830ba3416b0911f60911b60e082015260ee0190565b8c51906147e482828b6102b1565b01928352518093858401906102b1565b91829187519384916102b1565b0160029061202360f01b81520190565b886128d6565b7f3c616e696d6174652061646469746976653d2273756d2220617474726962757481527f654e616d653d2273746172744f6666736574222066726f6d3d2230252220746f60208201527f3d22313030252220626567696e3d22307322206475723d22333073222072657060408201527f656174436f756e743d22696e646566696e69746522202f3e203c2f746578745060608201527f6174683e203c74657874506174682073746172744f66667365743d222d35302560808201527f222066696c6c3d2277686974652220666f6e742d66616d696c793d225665726460a08201527f616e612220666f6e742d73697a653d22313070782220786c696e6b3a6872656660c08201526f1e9111ba32bc3a16b830ba3416b0911f60811b60e082015260f00190565b906128d6565b61202360f01b815260020190565b836128d6565b7f3c616e696d6174652061646469746976653d2273756d2220617474726962757481527f654e616d653d2273746172744f6666736574222066726f6d3d2230252220746f60208201527f3d22313030252220626567696e3d22307322206475723d22333073222072657060408201527f656174436f756e743d22696e646566696e69746522202f3e203c2f746578745060608201527f6174683e203c2f746578743e203c67206d61736b3d2275726c2823666164652d60808201527f73796d626f6c29223e203c726563742066696c6c3d226e6f6e652220783d223060a08201527f70782220793d22307078222077696474683d223239307078222068656967687460c08201527f3d22323030707822202f3e203c7465787420793d22373070782220783d22333260e08201527f7078222066696c6c3d2277686974652220666f6e742d66616d696c793d2256656101008201527f7264616e612220666f6e742d7765696768743d223230302220666f6e742d73696101208201527f7a653d2233367078223e4c5020424f4e443c2f746578743e203c7465787420796101408201527f3d2231313570782220783d2233327078222066696c6c3d2277686974652220666101608201527f6f6e742d66616d696c793d2256657264616e612220666f6e742d7765696768746101808201527f3d223230302220666f6e742d73697a653d2233367078223e23000000000000006101a08201526101b90190565b7f3c2f746578743e203c2f673e203c7265637420783d2231362220793d2231362281527f2077696474683d2232353822206865696768743d22343638222072783d22323660208201527f222072793d223236222066696c6c3d227267626128302c302c302c302922207360408201527f74726f6b653d2272676261283235352c3235352c3235352c302e322922202f3e606082015260800190565b03601f198101835282610ff1565b60405190614c2b82610fd6565b60068252650302e303030360d41b6020830152565b60405190614c4d82610fd6565b60018252600360fc1b6020830152565b8015614d5957614c6c906134d3565b9081516012811115614cdf575b614cc29192614c10614caf614c9061030a94612077565b9283614ccf57614c9e614c40565b935b614ca981612176565b916156ca565b61493d60405195869460208601906128d6565b601760f91b815260010190565b614cd9848261565d565b93614ca0565b614ceb90929192612069565b906060916000905b808210614d2957505061493d614d1d614cc293614c1061030a9460405194859360208501906128d6565b92915060129050614c79565b909392614c10614d5060019260405192839161493d60208401600190600360fc1b81520190565b93940190614cf3565b5061030a614c1e565b614c10615160614ec79461493d61501361030a9661493d604051998a987f203c67207374796c653d227472616e73666f726d3a7472616e736c617465283260208b01527f3970782c20333834707829223e203c726563742077696474683d22323330707860408b01527f22206865696768743d2232367078222072783d22387078222072793d2238707860608b01527f222066696c6c3d227267626128302c302c302c302e362922202f3e203c74657860808b01527f7420783d22313270782220793d22313770782220666f6e742d66616d696c793d60a08b01527f2256657264616e612220666f6e742d73697a653d2231327078222066696c6c3d60c08b01527f227768697465223e203c747370616e2066696c6c3d2272676261283235352c3260e08b01527f35352c3235352c302e3629223e506f736974696f6e2049643a203c2f747370616101008b015261371f60f11b6101208b01526101228a01906128d6565b7f3c2f746578743e203c2f673e203c67207374796c653d227472616e73666f726d81527f3a7472616e736c61746528323970782c20343134707829223e203c726563742060208201527f77696474683d22323330707822206865696768743d2232367078222072783d2260408201527f387078222072793d22387078222066696c6c3d227267626128302c302c302c3060608201527f2e362922202f3e203c7465787420783d22313270782220793d2231377078222060808201527f666f6e742d66616d696c793d2256657264616e612220666f6e742d73697a653d60a08201527f2231327078222066696c6c3d227768697465223e203c747370616e2066696c6c60c08201527f3d2272676261283235352c3235352c3235352c302e3629223e474d492052657760e08201526d30b932399d101e17ba39b830b71f60911b61010082015261010e0190565b7f3c2f746578743e203c2f673e203c67207374796c653d227472616e73666f726d81527f3a7472616e736c61746528323970782c20343434707829223e203c726563742060208201527f77696474683d22323330707822206865696768743d2232367078222072783d2260408201527f387078222072793d22387078222066696c6c3d227267626128302c302c302c3060608201527f2e362922202f3e203c7465787420783d22313270782220793d2231377078222060808201527f666f6e742d66616d696c793d2256657264616e612220666f6e742d73697a653d60a08201527f2231327078222066696c6c3d227768697465223e203c747370616e2066696c6c60c08201527f3d2272676261283235352c3235352c3235352c302e3629223e5745544820526560e08201526e3bb0b932399d101e17ba39b830b71f60891b61010082015261010f0190565b721e17ba32bc3a1f101e17b39f101e17b9bb339f60691b815260130190565b6040519061518c82610f9f565b604082527f6768696a6b6c6d6e6f707172737475767778797a303132333435363738392b2f6040837f4142434445464748494a4b4c4d4e4f505152535455565758595a61626364656660208201520152565b156151e557565b60405162461bcd60e51b815260206004820152602b60248201527f496e697469616c697a61626c653a20636f6e7472616374206973206e6f74206960448201526a6e697469616c697a696e6760a81b6064820152608490fd5b61525360ff60005460081c16612c35816151de565b6113fc336133e1565b61527160ff60005460081c16612c35816151de565b60ff1960c9541660c955565b61529260ff60005460081c16612c35816151de565b600160fb55565b600081815260696020526040812080546001600160a01b03191690556001600160a01b03612e738361269e565b156152cd57565b60405162461bcd60e51b8152602060048201526024808201527f4552433732313a207472616e7366657220746f20746865207a65726f206164646044820152637265737360e01b6064820152608490fd5b906153288361269e565b6001600160a01b0383811692909182168390036153e2576153776153bb928216946153548615156152c6565b61535d87612e33565b6001600160a01b0316600090815260686020526040902090565b6153818154612055565b90556001600160a01b03811660009081526068602052604090206153a58154612168565b90556131fa856000526067602052604060002090565b7fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef600080a4565b60405162461bcd60e51b815260206004820152602560248201527f4552433732313a207472616e736665722066726f6d20696e636f72726563742060448201526437bbb732b960d91b6064820152608490fd5b6001600160a01b03828116939116918284146154b757816154ac7f17307eab39ab6107e8899845ad3d59bd9653f200f220920489ca2b5937696c319361549b60209487600052606a865260406000209060018060a01b0316600052602052604060002090565b9060ff801983541691151516179055565b6040519015158152a3565b60405162461bcd60e51b815260206004820152601960248201527f4552433732313a20617070726f766520746f2063616c6c6572000000000000006044820152606490fd5b9081602091031261023e575161030a8161022c565b6001600160a01b03918216815291166020820152604081019190915260806060820181905261030a929101906102d4565b3d1561556d573d906155538261141e565b916155616040519384610ff1565b82523d6000602084013e565b606090565b92909190823b1561562d576155a5926020926000604051809681958294630a85bd0160e11b9a8b85523360048601615511565b03926001600160a01b03165af1600091816155fc575b506155ee576155c8615542565b805190816155e95760405162461bcd60e51b81528061349d6004820161342a565b602001fd5b6001600160e01b0319161490565b61561f91925060203d602011615626575b6156178183610ff1565b8101906154fc565b90386155bb565b503d61560d565b50505050600190565b908151811015615647570160200190565b634e487b7160e01b600052603260045260246000fd5b906156678161141e565b916156756040519384610ff1565b818352601f196156848361141e565b0136602085013760009060005b83811061569f575050505090565b6001906001600160f81b03196156b58285615636565b5116841a6156c38288615636565b5301615691565b9181810392818411612064576156df8461141e565b936156ed6040519586610ff1565b8085526156fc601f199161141e565b01366020860137825b828110615713575050505090565b6001600160f81b03196157268284615636565b5116908481038181116120645761574360019360001a9188615636565b5301615705565b600281901b91906001600160fe1b0381160361206457565b908151156158395761578e61578961578461577d8551612184565b6003900490565b61574a565b6134a1565b91602083019181825183016020810191825193600084525b8282106157e757505050525160039006600181146157d4576002146157c9575090565b603d90600019015390565b50603d9081600019820153600119015390565b9091956004906003809401938451600190603f9082828260121c16880101518553828282600c1c16880101518386015382828260061c16880101516002860153168501015190820153019591906157a6565b505061030a61268b56fea2646970667358221220b63a1f927216bae04a58f51c8f06a5e38833a486850ae10242467f007b369c9364736f6c63430008160033
Deployed Bytecode
0x6080604052600436101561001257600080fd5b60003560e01c806301ffc9a71461022757806306fdde0314610222578063081812fc1461021d578063095ea7b3146102185780630989f2971461021357806323b872dd1461020e57806326987b60146102095780633092afd5146102045780633392bec8146101ff5780633f4ba83a146101fa57806340c10f19146101f557806342842e0e146101f057806342966c68146101eb57806358c2225b146101e65780635c975abb146101e15780635f1c17c0146101dc5780636352211e146101d757806370a08231146101d2578063715018a6146101cd57806374ec06bc146101c85780638456cb59146101c35780638da5cb5b146101be57806394c8636f146101b957806395d89b41146101b4578063983b2d56146101af578063a22cb465146101aa578063b5215aaa146101a5578063b88d4fde146101a0578063c87b56dd1461019b578063db74ee3114610196578063e985e9c514610191578063f2fde38b1461018c5763f46eccc41461018757600080fd5b611bd7565b611b3d565b611ad5565b611983565b6114d7565b611470565b611360565b6112a2565b611192565b6110ea565b611012565b610f06565b610e9a565b610e70565b610e0f565b610d69565b610d4b565b610d02565b610cdf565b610cb5565b610b2f565b610b07565b610953565b6108b2565b61086f565b610776565b610757565b6105e5565b61052a565b610437565b6103f6565b61030d565b610243565b6001600160e01b031981160361023e57565b600080fd5b3461023e57602036600319011261023e5760206004356102628161022c565b63ffffffff60e01b166380ac58cd60e01b81149081156102a0575b811561028f575b506040519015158152f35b6301ffc9a760e01b14905038610284565b635b5e139f60e01b8114915061027d565b60005b8381106102c45750506000910152565b81810151838201526020016102b4565b906020916102ed815180928185528580860191016102b1565b601f01601f1916010190565b90602061030a9281815201906102d4565b90565b3461023e576000806003193601126103f35760405190806065549061033182610f2f565b808552916020916001918281169081156103c6575060011461036e575b61036a8661035e81880382610ff1565b604051918291826102f9565b0390f35b9350606584527f8ff97419363ffd7000167f130ef7168fbea05faf9251824ca5043f113cc6a7c75b8385106103b35750505050810160200161035e8261036a3861034e565b8054868601840152938201938101610396565b905086955061036a9693506020925061035e94915060ff191682840152151560051b82010192933861034e565b80fd5b3461023e57602036600319011261023e576020610414600435611c1a565b6040516001600160a01b039091168152f35b6001600160a01b0381160361023e57565b3461023e57604036600319011261023e5760043561045481610426565b6024356104608161269e565b916001600160a01b0380841690821681146104db576104929361048d913314908115610494575b50611cac565b612f07565b005b6001600160a01b03166000908152606a602052604090206104d591506104ce9033905b9060018060a01b0316600052602052604060002090565b5460ff1690565b38610487565b60405162461bcd60e51b815260206004820152602160248201527f4552433732313a20617070726f76616c20746f2063757272656e74206f776e656044820152603960f91b6064820152608490fd5b3461023e57602036600319011261023e5760043561054781610426565b6097546001600160a01b039182916105629083163314611d1e565b169061056f821515611d69565b6101328281549283169261058584831415611db4565b6001600160a01b0319161790557ff8b0ee9361a0f0225b39f58411465016adbd34abff194e6119b537fa8b063247600080a3005b606090600319011261023e576004356105d181610426565b906024356105de81610426565b9060443590565b3461023e576105f3366105b9565b906106066106018333612fee565b611e10565b32331480156106df575b610619906130d9565b803b158015610635575b9261063061049294613135565b61531e565b506101325461065a9061064e906001600160a01b031681565b6001600160a01b031690565b604051633185c44d60e21b81523060048201526001600160a01b03831660248201529390602090859060449082905afa9384156106da5761049294610630916000916106ab575b5091945050610623565b6106cd915060203d6020116106d3575b6106c58183610ff1565b810190612dbe565b386106a1565b503d6106bb565b611f33565b50610132546106f89061064e906001600160a01b031681565b604051633185c44d60e21b815230600482015233602482015290602090829060449082905afa80156106da5761061991600091610738575b509050610610565b610751915060203d6020116106d3576106c58183610ff1565b38610730565b3461023e57600036600319011261023e57602061012e54604051908152f35b3461023e57602036600319011261023e5760043561079381610426565b6097546001600160a01b03906107ac9082163314611d1e565b81166107b9811515611d69565b60009181835261013060205260ff60408420541615610819576001600160a01b0316600090815261013060205260409020805460ff191690557fe94479a9f7e1952cc78f2d6baab678adc1b772d936c6583def489e524cb666928280a280f35b60405162461bcd60e51b815260206004820152602860248201527f4c6971756964697479426f6e64733a3a2041646472657373206973206e6f7420604482015267309036b4b73a32b960c11b6064820152608490fd5b3461023e57602036600319011261023e5760c061088d60043561219f565b93604093919351958652602086015260408501526060840152608083015260a0820152f35b3461023e57600036600319011261023e576108d860018060a01b03609754163314611d1e565b60c95460ff8116156109175760ff191660c9557f5db9ee0a495bf2e6ff9c91a7834c1ba4fdd244a5e8aa4e537bd38aeae4b073aa6020604051338152a1005b60405162461bcd60e51b815260206004820152601460248201527314185d5cd8589b194e881b9bdd081c185d5cd95960621b6044820152606490fd5b3461023e57604036600319011261023e5760043561097081610426565b60243560009133835261013060205260ff6040842054168015610af3575b610997906124a5565b6109a660ff60c9541615612500565b6109b5600260fb54141561253f565b600260fb556001600160a01b038116906109d0821515611d69565b6109db83151561258b565b610131546109f39061064e906001600160a01b031681565b60405163f4dadc6160e01b8152600481018590529060e090829060249082905afa80156106da5760c0610a3391610a39938891610ac4575b500151151590565b156125ef565b610a9161012e91610a53610a4d845461264f565b61012e55565b610a898354610a84610a636113ef565b9180835288602084015289604084015260005261012f602052604060002090565b61265e565b825490613190565b54907f72970e8e667928f70b2da0ecfd32c52c589298ecc73c7c540586fb6003ba040f8480a4610ac1600160fb55565b80f35b610ae6915060e03d60e011610aec575b610ade8183610ff1565b810190611ebe565b38610a2b565b503d610ad4565b506097546001600160a01b0316331461098e565b3461023e57610492610b18366105b9565b9060405192610b2684610f7f565b60008452612716565b3461023e57602036600319011261023e5760043560009033825261013060205260ff6040832054168015610ca1575b610b67906124a5565b610b7660ff60c9541615612500565b610b85600260fb54141561253f565b600260fb558015610c5d576000818152606760205260409020546001600160a01b031615610c0c57610bd56002610bc78360005261012f602052604060002090565b01805460ff19166001179055565b610bde816132ca565b7f0d7a61e190b0f85b64fde8b74afceb2d1894072e7b5ee31e2295b51ad0d441bc8280a2610ac1600160fb55565b60405162461bcd60e51b8152602060048201526024808201527f4c6971756964697479426f6e64733a3a20426f6e6420646f6573206e6f7420656044820152631e1a5cdd60e21b6064820152608490fd5b606460405162461bcd60e51b815260206004820152602060248201527f4c6971756964697479426f6e64733a3a20426f6e64204944206973207a65726f6044820152fd5b506097546001600160a01b03163314610b5e565b3461023e57600036600319011261023e57610132546040516001600160a01b039091168152602090f35b3461023e57600036600319011261023e57602060ff60c954166040519015158152f35b3461023e57602036600319011261023e5760043560005261012f6020526060604060002080549060ff600260018301549201541690604051928352602083015215156040820152f35b3461023e57602036600319011261023e57602061041460043561269e565b3461023e57602036600319011261023e57600435610d8681610426565b6001600160a01b03168015610db757600052606860205261036a604060002054604051918291829190602083019252565b60405162461bcd60e51b815260206004820152602a60248201527f4552433732313a2062616c616e636520717565727920666f7220746865207a65604482015269726f206164647265737360b01b6064820152608490fd5b3461023e576000806003193601126103f35760975481906001600160a01b03811690610e3c338314611d1e565b6001600160a01b0319166097557f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e08280a380f35b3461023e57600036600319011261023e57610131546040516001600160a01b039091168152602090f35b3461023e57600036600319011261023e57610ec060018060a01b03609754163314611d1e565b600160c954610ed260ff821615612500565b60ff19161760c9557f62e78cea01bee320cd4e420270b5ea74000d11b0c9f74754ebdbfc544b05a2586020604051338152a1005b3461023e57600036600319011261023e576097546040516001600160a01b039091168152602090f35b90600182811c92168015610f5f575b6020831014610f4957565b634e487b7160e01b600052602260045260246000fd5b91607f1691610f3e565b634e487b7160e01b600052604160045260246000fd5b602081019081106001600160401b03821117610f9a57604052565b610f69565b606081019081106001600160401b03821117610f9a57604052565b610dc081019081106001600160401b03821117610f9a57604052565b604081019081106001600160401b03821117610f9a57604052565b90601f801991011681019081106001600160401b03821117610f9a57604052565b3461023e576000806003193601126103f357604051908061012d805461103781610f2f565b808652926020926001928084169081156110bb5750600114611064575b61036a8761035e81890382610ff1565b815293507f193a3ae4da5049eb74cee39e4cf5827f7ce7b1d1d1775ef1c6311eb60558e6d55b8385106110a85750505050810160200161035e8261036a3880611054565b805486860184015293820193810161108a565b91505086955061036a9693506020925061035e94915060ff191682840152151560051b82010192933880611054565b3461023e576000806003193601126103f35760405190806066549061110e82610f2f565b808552916020916001918281169081156103c6575060011461113a5761036a8661035e81880382610ff1565b9350606684527f46501879b8ca8525e8c2fd519e2fbfcfa2ebea26501294aa02cbfcfb12e943545b83851061117f5750505050810160200161035e8261036a3861034e565b8054868601840152938201938101611162565b3461023e57602036600319011261023e576004356111af81610426565b6097546001600160a01b03906111c89082163314611d1e565b81166111d5811515611d69565b60009181835261013060205260ff60408420541661123e576001600160a01b0316600090815261013060205260409020611217905b805460ff19166001179055565b7f6ae172837ea30b801fbfcdd4108aa1d5bf8ff775444fd70256b44e6bf3dfc3f68280a280f35b60405162461bcd60e51b815260206004820152602c60248201527f4c6971756964697479426f6e64733a3a204164647265737320697320616c726560448201526b30b23c90309036b4b73a32b960a11b6064820152608490fd5b8015150361023e57565b3461023e57604036600319011261023e576004356112bf81610426565b6024356112cb81611298565b813b1580156112e8575b916112e261049293612dd3565b33615435565b5061013254604051633185c44d60e21b81523060048201526001600160a01b03848116602483015290939160209185916044918391165afa9283156106da57610492936112e291600091611341575b50919350506112d5565b61135a915060203d6020116106d3576106c58183610ff1565b38611337565b3461023e57602036600319011261023e5760043561137d81610426565b6097546001600160a01b039182916113989083163314611d1e565b16906113a5821515611d69565b610131828154928316926113bb84831415611db4565b6001600160a01b0319161790557f748f722ee0920121a4d9633c16ef2dd3a68219e5c44480aeb31ab9df22412424600080a3005b604051906113fc82610f9f565b565b604051906101e082018281106001600160401b03821117610f9a57604052565b6001600160401b038111610f9a57601f01601f191660200190565b9291926114458261141e565b916114536040519384610ff1565b82948184528183011161023e578281602093846000960137010152565b3461023e57608036600319011261023e5760043561148d81610426565b60243561149981610426565b606435916001600160401b03831161023e573660238401121561023e576114cd610492933690602481600401359101611439565b9160443591612716565b3461023e57602036600319011261023e576115036004356114f78161219f565b919690959493946134d3565b936040958651946395d89b4160e01b8652600086600481305afa9586156106da57600096611943575b50611535613617565b936115408888614641565b9461154a836134d3565b61155385614c5d565b61155c84614c5d565b9061156692614d62565b8a5196879260208401611578916128d6565b611581916128d6565b61158a916128d6565b0399601f199a8b8101875261159f9087610ff1565b6115a99042612192565b916115b3906134d3565b936115bd906134d3565b956115c7906134d3565b926115d1906134d3565b906115db906134d3565b916115e5906134d3565b89517f222c202261747472696275746573223a205b7b2274726169745f74797065223a60208201527f2022416c676562726120563320506f736974696f6e204944222c202276616c7560408201526432911d101160d91b606082015296879591949160658701611654916128d6565b7f227d2c207b2274726169745f74797065223a202253746172742054696d65222c81526a10113b30b63ab2911d101160a91b6020820152602b01611697916128d6565b7f227d2c207b2274726169745f74797065223a2022426f6e64204475726174696f81526d37111610113b30b63ab2911d101160911b6020820152602e016116dd916128d6565b7f227d2c207b2274726169745f74797065223a2022474d4920526577617264732281526b1610113b30b63ab2911d101160a11b6020820152602c01611721916128d6565b7f227d2c207b2274726169745f74797065223a2022506172746e657220746f6b6581527537102932bbb0b93239911610113b30b63ab2911d101160511b602082015260360161176f916128d6565b7f227d2c207b22646973706c61795f74797065223a202264617465222c2022747281527f6169745f74797065223a2022556e6c6f636b2054696d65222c202276616c75656020820152620111d160ed1b60408201526043016117d0916128d6565b627d5d7d60e81b81526003010386810183526117ec9083610ff1565b6117f461517f565b6117fd91615762565b8451693d913730b6b2911d101160b11b6020820152938493602a8501611822916128d6565b61202360f01b8152600201611836916128d6565b7f222c20226465736372697074696f6e223a202241206c6f636b656420556e697381527f776170205633206c697175696469747920626f6e64207769746820726577617260208201527f64732e222c2022696d616765223a2022646174613a696d6167652f7376672b786040820152691b5b0ed8985cd94d8d0b60b21b6060820152606a016118c4916128d6565b6118cd916128d6565b0383810182526118dd9082610ff1565b6118e561517f565b6118ee91615762565b81517f646174613a6170706c69636174696f6e2f6a736f6e3b6261736536342c000000602082015292908390603d8201611927916128d6565b0390810183526119379083610ff1565b5161036a8192826102f9565b6119619196503d806000833e6119598183610ff1565b810190612878565b943861152c565b9080601f8301121561023e5781602061030a93359101611439565b3461023e5760a036600319011261023e576001600160401b0360043581811161023e576119b4903690600401611968565b9060243581811161023e576119cd903690600401611968565b90604435906119db82610426565b606435906119e882610426565b60843590811161023e57611a00903690600401611968565b916000549360ff8560081c169485600014611acc5750303b155b15611a7057611a2f94159586611a4557612c1c565b611a3557005b61049261ff001960005416600055565b611a5961010061ff00196000541617600055565b611a6b600160ff196000541617600055565b612c1c565b60405162461bcd60e51b815260206004820152602e60248201527f496e697469616c697a61626c653a20636f6e747261637420697320616c72656160448201526d191e481a5b9a5d1a585b1a5e995960921b6064820152608490fd5b60ff1615611a1a565b3461023e57604036600319011261023e57602060ff611b31600435611af981610426565b60243590611b0682610426565b60018060a01b0316600052606a845260406000209060018060a01b0316600052602052604060002090565b54166040519015158152f35b3461023e57602036600319011261023e57600435611b5a81610426565b6097546001600160a01b0390611b739082163314611d1e565b811615611b8357610492906133e1565b60405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201526564647265737360d01b6064820152608490fd5b3461023e57602036600319011261023e57600435611bf481610426565b60018060a01b0316600052610130602052602060ff604060002054166040519015158152f35b6000818152606760205260409020546001600160a01b031615611c52576000908152606960205260409020546001600160a01b031690565b60405162461bcd60e51b815260206004820152602c60248201527f4552433732313a20617070726f76656420717565727920666f72206e6f6e657860448201526b34b9ba32b73a103a37b5b2b760a11b6064820152608490fd5b15611cb357565b60405162461bcd60e51b815260206004820152603860248201527f4552433732313a20617070726f76652063616c6c6572206973206e6f74206f7760448201527f6e6572206e6f7220617070726f76656420666f7220616c6c00000000000000006064820152608490fd5b15611d2557565b606460405162461bcd60e51b815260206004820152602060248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e65726044820152fd5b15611d7057565b606460405162461bcd60e51b815260206004820152602060248201527f4c6971756964697479426f6e64733a3a2041646472657373206973207a65726f6044820152fd5b15611dbb57565b60405162461bcd60e51b815260206004820152602760248201527f4c6971756964697479426f6e64733a3a204164647265737320697320616c726560448201526618591e481cd95d60ca1b6064820152608490fd5b15611e1757565b60405162461bcd60e51b815260206004820152603160248201527f4552433732313a207472616e736665722063616c6c6572206973206e6f74206f6044820152701ddb995c881b9bdc88185c1c1c9bdd9959607a1b6064820152608490fd5b90604051606081018181106001600160401b03821117610f9a57604052604060ff6002839580548552600181015460208601520154161515910152565b51906113fc82611298565b908160e091031261023e576040519060e08201908282106001600160401b03831117610f9a5760c091604052805183526020810151602084015260408101516040840152606081015160608401526080810151608084015260a081015160a08401520151611f2b81611298565b60c082015290565b6040513d6000823e3d90fd5b51906113fc82610426565b51908160020b820361023e57565b90816101e091031261023e57611f6c6113fe565b9080518252611f7d60208201611f3f565b6020830152611f8e60408201611f3f565b6040830152611f9f60608201611f3f565b606083015260808101516080830152611fba60a08201611f4a565b60a0830152611fcb60c08201611f4a565b60c083015260e081015160e08301526101008082015190830152610120808201519083015261014080820151908301526101608082015190830152610180612014818301611eb3565b908301526101a0612026818301611f3f565b908301526120386101c0809201611eb3565b9082015290565b634e487b7160e01b600052601160045260246000fd5b60001981019190821161206457565b61203f565b601203906012821161206457565b60111981019190821161206457565b9190820391821161206457565b9081602091031261023e575190565b9081602091031261023e575161030a81610426565b51906001600160801b038216820361023e57565b908161016091031261023e5780516bffffffffffffffffffffffff8116810361023e579160208201516120fd81610426565b91604081015161210c81610426565b9161211960608301611f3f565b9161212660808201611f4a565b9161213360a08301611f4a565b9161214060c082016120b7565b9160e0820151916101008101519161030a61014061216161012085016120b7565b93016120b7565b906001820180921161206457565b906004820180921161206457565b906002820180921161206457565b9190820180921161206457565b6121b76121bc9160005261012f602052604060002090565b611e76565b610131549091906121d79061064e906001600160a01b031681565b602083810180516040805163f4dadc6160e01b8152600480820193909352939590949260e085602481875afa9485156106da57600095612484575b5084860151865163017c705f60e61b815284810191825297906101e09081908a9081906020010381895afa80156106da5761228a9961014092600092612457575b5050019889518042101560001461244657506000975b83518151634086b3ad60e11b81528781019182529a84918c91829160200190565b03818a5afa998a156106da5760009a612427575b508051630e5047b360e41b815295838782818b5afa9485156106da576122eb976000966123f8575b50518251809663133f757160e31b825281806101609b8c958783019190602083019252565b03916001600160a01b03165afa9485156106da576000976000966123ac575b50509061233f94959697849260608b519b01519d51945192518097819482936307d8992d60e31b845283019190602083019252565b03915afa9081156106da57612373936123619360009361237d575b5050612086565b966001600160801b0380931690612192565b9396959493921690565b61239d929350803d106123a5575b6123958183610ff1565b810190612093565b90388061235a565b503d61238b565b85939297985061233f965090816123d792903d106123f1575b6123cf8183610ff1565b8101906120cb565b99509750505050505050509890958199989792935061230a565b503d6123c5565b612419919650853d8711612420575b6124118183610ff1565b8101906120a2565b94386122c6565b503d612407565b61243f919a50833d85116123a5576123958183610ff1565b983861229e565b612451904290612086565b97612269565b6124769250803d1061247d575b61246e8183610ff1565b810190611f58565b3880612253565b503d612464565b61249e91955060e03d60e011610aec57610ade8183610ff1565b9338612212565b156124ac57565b60405162461bcd60e51b815260206004820152602660248201527f4c6971756964697479426f6e64733a3a204e6f742061206d696e746572206f726044820152651037bbb732b960d11b6064820152608490fd5b1561250757565b60405162461bcd60e51b815260206004820152601060248201526f14185d5cd8589b194e881c185d5cd95960821b6044820152606490fd5b1561254657565b60405162461bcd60e51b815260206004820152601f60248201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c006044820152606490fd5b1561259257565b60405162461bcd60e51b815260206004820152602f60248201527f4c6971756964697479426f6e64733a3a20556e697377617020563320706f736960448201526e74696f6e204944206973207a65726f60881b6064820152608490fd5b156125f657565b60405162461bcd60e51b815260206004820152602b60248201527f4c6971756964697479426f6e64733a3a20506f736974696f6e20697320616c7260448201526a1958591e481b1bd8dad95960aa1b6064820152608490fd5b60001981146120645760010190565b600260406113fc9380518455602081015160018501550151151591019060ff801983541691151516179055565b6040519061269882610f7f565b60008252565b6000908152606760205260409020546001600160a01b031680156126bf5790565b60405162461bcd60e51b815260206004820152602960248201527f4552433732313a206f776e657220717565727920666f72206e6f6e657869737460448201526832b73a103a37b5b2b760b91b6064820152608490fd5b929190926127276106018333612fee565b3233148015612800575b61273a906130d9565b833b15801561276c575b936127679392916127576113fc96613135565b61276283838361531e565b615572565b61347d565b5061013254909291906127899061064e906001600160a01b031681565b604051633185c44d60e21b81523060048201526001600160a01b03861660248201529490602090869060449082905afa9384156106da57612757612767956113fc976000916127e1575b509296505091929350612744565b6127fa915060203d6020116106d3576106c58183610ff1565b386127d3565b50610132546128199061064e906001600160a01b031681565b604051633185c44d60e21b815230600482015233602482015290602090829060449082905afa80156106da5761273a91600091612859575b509050612731565b612872915060203d6020116106d3576106c58183610ff1565b38612851565b60208183031261023e578051906001600160401b03821161023e570181601f8201121561023e5780516128aa8161141e565b926128b86040519485610ff1565b8184526020828401011161023e5761030a91602080850191016102b1565b906128e9602092828151948592016102b1565b0190565b601f81116128f9575050565b60009060656000527f8ff97419363ffd7000167f130ef7168fbea05faf9251824ca5043f113cc6a7c7906020601f850160051c83019410612955575b601f0160051c01915b82811061294a57505050565b81815560010161293e565b9092508290612935565b601f811161296b575050565b60009060666000527f46501879b8ca8525e8c2fd519e2fbfcfa2ebea26501294aa02cbfcfb12e94354906020601f850160051c830194106129c7575b601f0160051c01915b8281106129bc57505050565b8181556001016129b0565b90925082906129a7565b601f81116129dd575050565b60009061012d6000527f193a3ae4da5049eb74cee39e4cf5827f7ce7b1d1d1775ef1c6311eb60558e6d5906020601f850160051c83019410612a3a575b601f0160051c01915b828110612a2f57505050565b818155600101612a23565b9092508290612a1a565b9081516001600160401b038111610f9a57612a6981612a64606654610f2f565b61295f565b602080601f8311600114612aac57508190612a9c9394600092612aa1575b50508160011b916000199060031b1c19161790565b606655565b015190503880612a87565b90601f19831694612adf60666000527f46501879b8ca8525e8c2fd519e2fbfcfa2ebea26501294aa02cbfcfb12e9435490565b926000905b878210612b1c575050836001959610612b03575b505050811b01606655565b015160001960f88460031b161c19169055388080612af8565b80600185968294968601518155019501930190612ae4565b9081516001600160401b038111610f9a5761012d90612b5c81612b578454610f2f565b6129d1565b602080601f8311600114612b9357508190612b8f939495600092612aa15750508160011b916000199060031b1c19161790565b9055565b90601f19831695612bc761012d6000527f193a3ae4da5049eb74cee39e4cf5827f7ce7b1d1d1775ef1c6311eb60558e6d590565b926000905b888210612c0457505083600195969710612beb575b505050811b019055565b015160001960f88460031b161c19169055388080612be1565b80600185968294968601518155019501930190612bcc565b93929193612c3a60ff60005460081c16612c35816151de565b6151de565b8051906001600160401b038211610f9a57612c5f82612c5a606554610f2f565b6128ed565b602090816001601f851114612d23575093612cad612d0894612ca58561120a9996612d03966113fc9c9a600092612aa15750508160011b916000199060031b1c19161790565b606555612a44565b612cb561523e565b612cbd61525c565b612cc561527d565b61013180546001600160a01b0319166001600160a01b03871617905561013280546001600160a01b0319166001600160a01b03909216919091179055565b612b34565b6001600160a01b031660009081526101306020526040902090565b60656000529190601f1984167f8ff97419363ffd7000167f130ef7168fbea05faf9251824ca5043f113cc6a7c7936000905b828210612da657505094600185612d03956113fc9b9995612cad9561120a9c99612d089b10612d8d575b505050811b01606555612a44565b015160001960f88460031b161c19169055388080612d7f565b80600186978294978701518155019601940190612d55565b9081602091031261023e575161030a81611298565b15612dda57565b60405162461bcd60e51b815260206004820152602b60248201527f4c6971756964697479426f6e64733a204f70657261746f72206973206e6f742060448201526a1dda1a5d195b1a5cdd195960aa1b6064820152608490fd5b6000803b158015612e9a575b612e4890612dd3565b81815260696020526040812080546001600160a01b03191690556001600160a01b03612e738361269e565b167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b9258280a4565b5061013254604051633185c44d60e21b81523060048201526024810183905290602090829060449082906001600160a01b03165afa80156106da57612e48918391612ee8575b509050612e3f565b612f01915060203d6020116106d3576106c58183610ff1565b38612ee0565b803b158015612f7e575b612f1a90612dd3565b600082815260696020526040902080546001600160a01b0319166001600160a01b0383161790556001600160a01b0380612f538461269e565b169116907f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925600080a4565b5061013254604051633185c44d60e21b81523060048201526001600160a01b038381166024830152909160209183916044918391165afa80156106da57612f1a91600091612fcf575b509050612f11565b612fe8915060203d6020116106d3576106c58183610ff1565b38612fc7565b6000828152606760205260409020546001600160a01b03161561307f576130148261269e565b6001600160a01b038281168282168114949091908515613067575b505050821561303d57505090565b6001600160a01b03166000908152606a6020526040902060ff925061306291906104b7565b541690565b6130749192939550611c1a565b16149138808061302f565b60405162461bcd60e51b815260206004820152602c60248201527f4552433732313a206f70657261746f7220717565727920666f72206e6f6e657860448201526b34b9ba32b73a103a37b5b2b760a11b6064820152608490fd5b156130e057565b60405162461bcd60e51b815260206004820152602760248201527f4c6971756964697479426f6e64733a2053656e646572206973206e6f742077686044820152661a5d195b1a5cdd60ca1b6064820152608490fd5b1561313c57565b60405162461bcd60e51b815260206004820152602660248201527f4c6971756964697479426f6e64733a205265636569766572206e6f74207768696044820152651d195b1a5cdd60d21b6064820152608490fd5b6001600160a01b038116908115613286576000838152606760205260409020546001600160a01b0316613241576001600160a01b038116600090815260686020526040902061321991906131e48154612168565b90556131fa846000526067602052604060002090565b80546001600160a01b0319166001600160a01b03909216919091179055565b60007fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef8180a4565b60405162461bcd60e51b815260206004820152601c60248201527f4552433732313a20746f6b656e20616c7265616479206d696e746564000000006044820152606490fd5b606460405162461bcd60e51b815260206004820152602060248201527f4552433732313a206d696e7420746f20746865207a65726f20616464726573736044820152fd5b6132d38161269e565b60003b15801561336d575b906132ea600092612dd3565b6132f383615299565b6001600160a01b03811660009081526068602052604090206133158154612055565b905561333e61332e846000526067602052604060002090565b80546001600160a01b0319169055565b6001600160a01b03167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef8280a4565b5061013254604051633185c44d60e21b8152306004820152600060248201529190602090839060449082906001600160a01b03165afa9182156106da576000926132ea9184916133c2575b50919250506132de565b6133db915060203d6020116106d3576106c58183610ff1565b386133b8565b609780546001600160a01b039283166001600160a01b0319821681179092559091167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0600080a3565b60809060208152603260208201527f4552433732313a207472616e7366657220746f206e6f6e20455243373231526560408201527131b2b4bb32b91034b6b83632b6b2b73a32b960711b60608201520190565b1561348457565b60405162461bcd60e51b81528061349d6004820161342a565b0390fd5b906134ab8261141e565b6134b86040519182610ff1565b82815280926134c9601f199161141e565b0190602036910137565b806000917a184f03e93ff9f4daa797ed6e38ed64bf6a1f01000000000000000080821015613609575b506d04ee2d6d415b85acef8100000000808310156135fa575b50662386f26fc10000808310156135eb575b506305f5e100808310156135dc575b50612710808310156135cd575b5060648210156135bd575b600a809210156135b3575b60019081602161356b600187016134a1565b95860101905b61357d575b5050505090565b600019019083906f181899199a1a9b1b9c1cb0b131b232b360811b8282061a8353049182156135ae57919082613571565b613576565b9160010191613559565b919060646002910491019161354e565b60049193920491019138613543565b60089193920491019138613536565b60109193920491019138613527565b60209193920491019138613515565b6040935081049150386134fc565b6040519061362482610fba565b610d9a82527f786c696e6b3a687265663d2223746578742d706174682d61223e000000000000610da0837f3c7376672077696474683d2232393022206865696768743d223530302220766960208201527f6577426f783d2230203020323930203530302220786d6c6e733d22687474703a60408201527f2f2f7777772e77332e6f72672f323030302f7376672220786d6c6e733a786c6960608201527f6e6b3d22687474703a2f2f7777772e77332e6f72672f313939392f786c696e6b60808201527f223e3c646566733e3c66696c7465722069643d226631223e3c6665496d61676560a08201527f20726573756c743d2270302220786c696e6b3a687265663d22646174613a696d60c08201527f6167652f7376672b786d6c3b6261736536342c50484e325a794233615752306160e08201527f44306e4d6a6b774a79426f5a576c6e614851394a7a55774d436367646d6c6c646101008201527f304a766544306e4d434177494449354d4341314d44416e494868746247357a506101208201527f53646f644852774f693876643364334c6e637a4c6d39795a7938794d4441774c6101408201527f334e325a79632b50484a6c5933516764326c6b644767394a7a49354d4842344a6101608201527f79426f5a576c6e614851394a7a55774d4842344a79426d615778735053636a4d6101808201527f574d335a4452694a79382b5043397a646d632b222f3e203c6665496d616765206101a08201527f726573756c743d2270312220786c696e6b3a687265663d22646174613a696d616101c08201527f67652f7376672b786d6c3b6261736536342c50484e325a7942336157523061446101e08201527f306e4d6a6b774a79426f5a576c6e614851394a7a55774d436367646d6c6c64306102008201527f4a766544306e4d434177494449354d4341314d44416e494868746247357a50536102208201527f646f644852774f693876643364334c6e637a4c6d39795a7938794d4441774c336102408201527f4e325a79632b50474e70636d4e735a53426a6544306e4d6a49794a79426a65546102608201527f306e4d6a41794a794279505363784d6a4277654363675a6d6c736244306e49326102808201527f5a6d5a6a6b354e796376506a777663335a6e50673d3d22202f3e203c6665496d6102a08201527f61676520726573756c743d2270322220786c696e6b3a687265663d22646174616102c08201527f3a696d6167652f7376672b786d6c3b6261736536342c50484e325a7942336157806102e08301527f52306144306e4d6a6b774a79426f5a576c6e614851394a7a55774d436367646d806103008401527f6c6c64304a766544306e4d434177494449354d4341314d44416e49486874624790816103208501527f357a5053646f644852774f693876643364334c6e637a4c6d39795a7938794d4492836103408601527f41774c334e325a79632b50474e70636d4e735a53426a6544306e4f44516e49476103608601527f4e355053637a4f44456e494849394a7a45794d4842344a79426d6157787350536103808601527f636a4f574d334d6a4d344a79382b5043397a646d632b22202f3e203c6665496d6103a08601527f61676520726573756c743d2270332220786c696e6b3a687265663d22646174616103c08601526103e08501526104008401526104208301526104408201527f41774c334e325a79632b50474e70636d4e735a53426a6544306e4d6a55324a796104608201527f426a6554306e4e4441334a794279505363784d444277654363675a6d6c7362446104808201527f306e497a526b4e6d49784e436376506a777663335a6e50673d3d22202f3e203c6104a08201527f6665426c656e64206d6f64653d226f7665726c61792220696e3d2270302220696104c08201527f6e323d22703122202f3e203c6665426c656e64206d6f64653d226578636c75736104e08201527f696f6e2220696e323d22703222202f3e203c6665426c656e64206d6f64653d226105008201527f6f7665726c61792220696e323d2270332220726573756c743d22626c656e644f6105208201527f757422202f3e203c6665476175737369616e426c757220696e3d22626c656e646105408201527f4f75742220737464446576696174696f6e3d22343222202f3e203c2f66696c746105608201527f65723e203c636c6970506174682069643d22636f726e657273223e203c7265636105808201527f742077696474683d2232393022206865696768743d22353030222072783d22346105a08201527f32222072793d22343222202f3e203c2f636c6970506174683e203c70617468206105c08201527f69643d22746578742d706174682d612220643d224d34302031322048323530206105e08201527f41323820323820302030203120323738203430205634363020413238203238206106008201527f30203020312032353020343838204834302041323820323820302030203120316106208201527f32203436302056343020413238203238203020302031203430203132207a22206106408201527f2f3e203c706174682069643d226d696e696d61702220643d224d3233342034346106608201527f3443323334203435372e393439203234322e32312034363320323533203436336106808201527f22202f3e203c66696c7465722069643d22746f702d726567696f6e2d626c75726106a08201527f223e203c6665476175737369616e426c757220696e3d22536f757263654772616106c08201527f706869632220737464446576696174696f6e3d22323422202f3e203c2f66696c6106e08201527f7465723e203c6c696e6561724772616469656e742069643d22677261642d75706107008201527f222078313d2231222078323d2230222079313d2231222079323d2230223e203c6107208201527f73746f70206f66667365743d22302e30222073746f702d636f6c6f723d2277686107408201527f697465222073746f702d6f7061636974793d223122202f3e203c73746f70206f6107608201527f66667365743d222e39222073746f702d636f6c6f723d227768697465222073746107808201527f6f702d6f7061636974793d223022202f3e203c2f6c696e6561724772616469656107a08201527f6e743e203c6c696e6561724772616469656e742069643d22677261642d646f776107c08201527f6e222078313d2230222078323d2231222079313d2230222079323d2231223e206107e08201527f3c73746f70206f66667365743d22302e30222073746f702d636f6c6f723d22776108008201527f68697465222073746f702d6f7061636974793d223122202f3e203c73746f70206108208201527f6f66667365743d22302e39222073746f702d636f6c6f723d22776869746522206108408201527f73746f702d6f7061636974793d223022202f3e203c2f6c696e656172477261646108608201527f69656e743e203c6d61736b2069643d22666164652d757022206d61736b436f6e6108808201527f74656e74556e6974733d226f626a656374426f756e64696e67426f78223e203c6108a08201527f726563742077696474683d223122206865696768743d2231222066696c6c3d226108c08201527f75726c2823677261642d75702922202f3e203c2f6d61736b3e203c6d61736b206108e08201527f69643d22666164652d646f776e22206d61736b436f6e74656e74556e6974733d6109008201527f226f626a656374426f756e64696e67426f78223e203c726563742077696474686109208201527f3d223122206865696768743d2231222066696c6c3d2275726c2823677261642d6109408201527f646f776e2922202f3e203c2f6d61736b3e203c6d61736b2069643d226e6f6e656109608201527f22206d61736b436f6e74656e74556e6974733d226f626a656374426f756e64696109808201527f6e67426f78223e203c726563742077696474683d223122206865696768743d226109a08201527f31222066696c6c3d22776869746522202f3e203c2f6d61736b3e203c6c696e656109c08201527f61724772616469656e742069643d22677261642d73796d626f6c223e203c73746109e08201527f6f70206f66667365743d22302e37222073746f702d636f6c6f723d2277686974610a008201527f65222073746f702d6f7061636974793d223122202f3e203c73746f70206f6666610a208201527f7365743d222e3935222073746f702d636f6c6f723d227768697465222073746f610a408201527f702d6f7061636974793d223022202f3e203c2f6c696e6561724772616469656e610a608201527f743e203c6d61736b2069643d22666164652d73796d626f6c22206d61736b436f610a808201527f6e74656e74556e6974733d227573657253706163654f6e557365223e203c7265610aa08201527f63742077696474683d22323930707822206865696768743d2232303070782220610ac08201527f66696c6c3d2275726c2823677261642d73796d626f6c2922202f3e203c2f6d61610ae08201527f736b3e203c2f646566733e203c6720636c69702d706174683d2275726c282363610b008201527f6f726e65727329223e203c726563742066696c6c3d2223316337643462222078610b208201527f3d223070782220793d22307078222077696474683d2232393070782220686569610b408201527f6768743d22353030707822202f3e203c72656374207374796c653d2266696c74610b608201527f65723a2075726c28236631292220783d223070782220793d2230707822207769610b808201527f6474683d22323930707822206865696768743d22353030707822202f3e203c67610ba08201527f207374796c653d2266696c7465723a75726c2823746f702d726567696f6e2d62610bc08201527f6c7572293b207472616e73666f726d3a7363616c6528312e35293b207472616e610be08201527f73666f726d2d6f726967696e3a63656e74657220746f703b223e203c72656374610c008201527f2066696c6c3d226e6f6e652220783d223070782220793d223070782220776964610c208201527f74683d22323930707822206865696768743d22353030707822202f3e203c656c610c408201527f6c697073652063783d22353025222063793d22307078222072783d2231383070610c608201527f78222072793d223132307078222066696c6c3d222330303022206f7061636974610c808201527f793d22302e383522202f3e203c2f673e203c7265637420783d22302220793d22610ca08201527f30222077696474683d2232393022206865696768743d22353030222072783d22610cc08201527f3432222072793d223432222066696c6c3d227267626128302c302c302c302922610ce08201527f207374726f6b653d2272676261283235352c3235352c3235352c302e32292220610d008201527f2f3e203c2f673e203c7465787420746578742d72656e646572696e673d226f70610d208201527f74696d697a655370656564223e203c74657874506174682073746172744f6666610d408201527f7365743d222d31303025222066696c6c3d2277686974652220666f6e742d6661610d608201527f6d696c793d2256657264616e612220666f6e742d73697a653d22313070782220610d808201520152565b61030a90614c10614b756149439461493d614957614951604051988761493d6148176148116148018e6147f46002829f5160208901936146858260208301876102b1565b018d6146b061202360f01b918260208501526147d66022825160208401966146b0828483018a6102b1565b01017f3c616e696d6174652061646469746976653d2273756d2220617474726962757481527f654e616d653d2273746172744f6666736574222066726f6d3d2230252220746f60208201527f3d22313030252220626567696e3d22307322206475723d22333073222072657060408201527f656174436f756e743d22696e646566696e69746522202f3e203c2f746578745060608201527f6174683e203c74657874506174682073746172744f66667365743d223025222060808201527f66696c6c3d2277686974652220666f6e742d66616d696c793d2256657264616e60a08201527f612220666f6e742d73697a653d22313070782220786c696e6b3a687265663d2260c08201526d11ba32bc3a16b830ba3416b0911f60911b60e082015260ee0190565b8c51906147e482828b6102b1565b01928352518093858401906102b1565b91829187519384916102b1565b0160029061202360f01b81520190565b886128d6565b7f3c616e696d6174652061646469746976653d2273756d2220617474726962757481527f654e616d653d2273746172744f6666736574222066726f6d3d2230252220746f60208201527f3d22313030252220626567696e3d22307322206475723d22333073222072657060408201527f656174436f756e743d22696e646566696e69746522202f3e203c2f746578745060608201527f6174683e203c74657874506174682073746172744f66667365743d222d35302560808201527f222066696c6c3d2277686974652220666f6e742d66616d696c793d225665726460a08201527f616e612220666f6e742d73697a653d22313070782220786c696e6b3a6872656660c08201526f1e9111ba32bc3a16b830ba3416b0911f60811b60e082015260f00190565b906128d6565b61202360f01b815260020190565b836128d6565b7f3c616e696d6174652061646469746976653d2273756d2220617474726962757481527f654e616d653d2273746172744f6666736574222066726f6d3d2230252220746f60208201527f3d22313030252220626567696e3d22307322206475723d22333073222072657060408201527f656174436f756e743d22696e646566696e69746522202f3e203c2f746578745060608201527f6174683e203c2f746578743e203c67206d61736b3d2275726c2823666164652d60808201527f73796d626f6c29223e203c726563742066696c6c3d226e6f6e652220783d223060a08201527f70782220793d22307078222077696474683d223239307078222068656967687460c08201527f3d22323030707822202f3e203c7465787420793d22373070782220783d22333260e08201527f7078222066696c6c3d2277686974652220666f6e742d66616d696c793d2256656101008201527f7264616e612220666f6e742d7765696768743d223230302220666f6e742d73696101208201527f7a653d2233367078223e4c5020424f4e443c2f746578743e203c7465787420796101408201527f3d2231313570782220783d2233327078222066696c6c3d2277686974652220666101608201527f6f6e742d66616d696c793d2256657264616e612220666f6e742d7765696768746101808201527f3d223230302220666f6e742d73697a653d2233367078223e23000000000000006101a08201526101b90190565b7f3c2f746578743e203c2f673e203c7265637420783d2231362220793d2231362281527f2077696474683d2232353822206865696768743d22343638222072783d22323660208201527f222072793d223236222066696c6c3d227267626128302c302c302c302922207360408201527f74726f6b653d2272676261283235352c3235352c3235352c302e322922202f3e606082015260800190565b03601f198101835282610ff1565b60405190614c2b82610fd6565b60068252650302e303030360d41b6020830152565b60405190614c4d82610fd6565b60018252600360fc1b6020830152565b8015614d5957614c6c906134d3565b9081516012811115614cdf575b614cc29192614c10614caf614c9061030a94612077565b9283614ccf57614c9e614c40565b935b614ca981612176565b916156ca565b61493d60405195869460208601906128d6565b601760f91b815260010190565b614cd9848261565d565b93614ca0565b614ceb90929192612069565b906060916000905b808210614d2957505061493d614d1d614cc293614c1061030a9460405194859360208501906128d6565b92915060129050614c79565b909392614c10614d5060019260405192839161493d60208401600190600360fc1b81520190565b93940190614cf3565b5061030a614c1e565b614c10615160614ec79461493d61501361030a9661493d604051998a987f203c67207374796c653d227472616e73666f726d3a7472616e736c617465283260208b01527f3970782c20333834707829223e203c726563742077696474683d22323330707860408b01527f22206865696768743d2232367078222072783d22387078222072793d2238707860608b01527f222066696c6c3d227267626128302c302c302c302e362922202f3e203c74657860808b01527f7420783d22313270782220793d22313770782220666f6e742d66616d696c793d60a08b01527f2256657264616e612220666f6e742d73697a653d2231327078222066696c6c3d60c08b01527f227768697465223e203c747370616e2066696c6c3d2272676261283235352c3260e08b01527f35352c3235352c302e3629223e506f736974696f6e2049643a203c2f747370616101008b015261371f60f11b6101208b01526101228a01906128d6565b7f3c2f746578743e203c2f673e203c67207374796c653d227472616e73666f726d81527f3a7472616e736c61746528323970782c20343134707829223e203c726563742060208201527f77696474683d22323330707822206865696768743d2232367078222072783d2260408201527f387078222072793d22387078222066696c6c3d227267626128302c302c302c3060608201527f2e362922202f3e203c7465787420783d22313270782220793d2231377078222060808201527f666f6e742d66616d696c793d2256657264616e612220666f6e742d73697a653d60a08201527f2231327078222066696c6c3d227768697465223e203c747370616e2066696c6c60c08201527f3d2272676261283235352c3235352c3235352c302e3629223e474d492052657760e08201526d30b932399d101e17ba39b830b71f60911b61010082015261010e0190565b7f3c2f746578743e203c2f673e203c67207374796c653d227472616e73666f726d81527f3a7472616e736c61746528323970782c20343434707829223e203c726563742060208201527f77696474683d22323330707822206865696768743d2232367078222072783d2260408201527f387078222072793d22387078222066696c6c3d227267626128302c302c302c3060608201527f2e362922202f3e203c7465787420783d22313270782220793d2231377078222060808201527f666f6e742d66616d696c793d2256657264616e612220666f6e742d73697a653d60a08201527f2231327078222066696c6c3d227768697465223e203c747370616e2066696c6c60c08201527f3d2272676261283235352c3235352c3235352c302e3629223e5745544820526560e08201526e3bb0b932399d101e17ba39b830b71f60891b61010082015261010f0190565b721e17ba32bc3a1f101e17b39f101e17b9bb339f60691b815260130190565b6040519061518c82610f9f565b604082527f6768696a6b6c6d6e6f707172737475767778797a303132333435363738392b2f6040837f4142434445464748494a4b4c4d4e4f505152535455565758595a61626364656660208201520152565b156151e557565b60405162461bcd60e51b815260206004820152602b60248201527f496e697469616c697a61626c653a20636f6e7472616374206973206e6f74206960448201526a6e697469616c697a696e6760a81b6064820152608490fd5b61525360ff60005460081c16612c35816151de565b6113fc336133e1565b61527160ff60005460081c16612c35816151de565b60ff1960c9541660c955565b61529260ff60005460081c16612c35816151de565b600160fb55565b600081815260696020526040812080546001600160a01b03191690556001600160a01b03612e738361269e565b156152cd57565b60405162461bcd60e51b8152602060048201526024808201527f4552433732313a207472616e7366657220746f20746865207a65726f206164646044820152637265737360e01b6064820152608490fd5b906153288361269e565b6001600160a01b0383811692909182168390036153e2576153776153bb928216946153548615156152c6565b61535d87612e33565b6001600160a01b0316600090815260686020526040902090565b6153818154612055565b90556001600160a01b03811660009081526068602052604090206153a58154612168565b90556131fa856000526067602052604060002090565b7fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef600080a4565b60405162461bcd60e51b815260206004820152602560248201527f4552433732313a207472616e736665722066726f6d20696e636f72726563742060448201526437bbb732b960d91b6064820152608490fd5b6001600160a01b03828116939116918284146154b757816154ac7f17307eab39ab6107e8899845ad3d59bd9653f200f220920489ca2b5937696c319361549b60209487600052606a865260406000209060018060a01b0316600052602052604060002090565b9060ff801983541691151516179055565b6040519015158152a3565b60405162461bcd60e51b815260206004820152601960248201527f4552433732313a20617070726f766520746f2063616c6c6572000000000000006044820152606490fd5b9081602091031261023e575161030a8161022c565b6001600160a01b03918216815291166020820152604081019190915260806060820181905261030a929101906102d4565b3d1561556d573d906155538261141e565b916155616040519384610ff1565b82523d6000602084013e565b606090565b92909190823b1561562d576155a5926020926000604051809681958294630a85bd0160e11b9a8b85523360048601615511565b03926001600160a01b03165af1600091816155fc575b506155ee576155c8615542565b805190816155e95760405162461bcd60e51b81528061349d6004820161342a565b602001fd5b6001600160e01b0319161490565b61561f91925060203d602011615626575b6156178183610ff1565b8101906154fc565b90386155bb565b503d61560d565b50505050600190565b908151811015615647570160200190565b634e487b7160e01b600052603260045260246000fd5b906156678161141e565b916156756040519384610ff1565b818352601f196156848361141e565b0136602085013760009060005b83811061569f575050505090565b6001906001600160f81b03196156b58285615636565b5116841a6156c38288615636565b5301615691565b9181810392818411612064576156df8461141e565b936156ed6040519586610ff1565b8085526156fc601f199161141e565b01366020860137825b828110615713575050505090565b6001600160f81b03196157268284615636565b5116908481038181116120645761574360019360001a9188615636565b5301615705565b600281901b91906001600160fe1b0381160361206457565b908151156158395761578e61578961578461577d8551612184565b6003900490565b61574a565b6134a1565b91602083019181825183016020810191825193600084525b8282106157e757505050525160039006600181146157d4576002146157c9575090565b603d90600019015390565b50603d9081600019820153600119015390565b9091956004906003809401938451600190603f9082828260121c16880101518553828282600c1c16880101518386015382828260061c16880101516002860153168501015190820153019591906157a6565b505061030a61268b56fea2646970667358221220b63a1f927216bae04a58f51c8f06a5e38833a486850ae10242467f007b369c9364736f6c63430008160033
Loading...
Loading
Loading...
Loading
Loading...
Loading
Loading...
Loading
Loading...
Loading
A contract address hosts a smart contract, which is a set of code stored on the blockchain that runs when predetermined conditions are met. Learn more about addresses in our Knowledge Base.