Source Code
Latest 16 from a total of 16 transactions
| Transaction Hash |
Method
|
Block
|
From
|
To
|
|||||
|---|---|---|---|---|---|---|---|---|---|
| Lock | 39584125 | 56 days ago | IN | 0 MON | 0.10578215 | ||||
| Unlock | 39583833 | 56 days ago | IN | 0 MON | 0.07206607 | ||||
| Lock | 39583762 | 56 days ago | IN | 0 MON | 0.12461479 | ||||
| Unlock | 39571773 | 56 days ago | IN | 0 MON | 0.08187132 | ||||
| Collect | 39356667 | 57 days ago | IN | 0 MON | 0.07961041 | ||||
| Lock | 39356567 | 57 days ago | IN | 0 MON | 0.11595733 | ||||
| Lock | 39349786 | 57 days ago | IN | 0 MON | 0.16257176 | ||||
| Unlock | 39345715 | 57 days ago | IN | 0 MON | 0.05847871 | ||||
| Collect | 39325283 | 57 days ago | IN | 0 MON | 0.0491563 | ||||
| Lock | 39164048 | 58 days ago | IN | 0 MON | 0.10939765 | ||||
| Unlock | 38309772 | 62 days ago | IN | 0 MON | 0.05867633 | ||||
| Collect | 38309682 | 62 days ago | IN | 0 MON | 0.05354037 | ||||
| Relock | 38308964 | 62 days ago | IN | 0 MON | 0.00664422 | ||||
| Lock | 38308353 | 62 days ago | IN | 0 MON | 0.10864932 | ||||
| Add Supported Nf... | 37005738 | 68 days ago | IN | 0 MON | 0.01013737 | ||||
| Add Supported Nf... | 34008268 | 82 days ago | IN | 0 MON | 0.00767968 |
View more zero value Internal Transactions in Advanced View mode
Advanced mode:
Loading...
Loading
Contract Name:
UniV3LPLocker
Compiler Version
v0.8.20+commit.a1b79de6
Optimization Enabled:
Yes with 1000 runs
Other Settings:
paris EvmVersion
Contract Source Code (Solidity Standard Json-Input format)
// SPDX-License-Identifier: MIT
pragma solidity 0.8.20;
import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/utils/cryptography/MessageHashUtils.sol";
import "@openzeppelin/contracts/utils/cryptography/ECDSA.sol";
import "@openzeppelin/contracts/token/ERC20/extensions/IERC20Permit.sol";
import "@openzeppelin/contracts/token/ERC721/IERC721Receiver.sol";
import "@openzeppelin/contracts/utils/structs/EnumerableSet.sol";
import "@openzeppelin/contracts/utils/ReentrancyGuard.sol";
import "./interface/INonfungiblePositionManager.sol";
import "./interface/IUniswapV3Factory.sol";
import "./libs/TransferHelper.sol";
contract UniV3LPLocker is IERC721Receiver, Ownable, ReentrancyGuard {
using EnumerableSet for EnumerableSet.AddressSet;
using EnumerableSet for EnumerableSet.Bytes32Set;
using EnumerableSet for EnumerableSet.UintSet;
struct FeeStruct {
string name; // name by which the fee is accessed
uint256 lpFee; // 100 = 1%, 10,000 = 100%
uint256 collectFee; // 100 = 1%, 10,000 = 100%
uint256 lockFee; // in amount tokens
address lockFeeToken; // address(0) = ETH otherwise ERC20 address expected
}
struct LockInfo {
uint256 lockId;
INonfungiblePositionManager nftPositionManager;
address pendingOwner;
address owner;
address collector;
address pool;
uint256 collectFee;
uint256 nftId;
uint256 startTime;
uint256 endTime;
}
// contains keccak(feeName)
EnumerableSet.Bytes32Set private feeNameHashSet;
// fees
mapping(bytes32 nameHash => FeeStruct) public fees;
address public feeReceiver;
address public customFeeSigner;
uint256 constant public FEE_DENOMINATOR = 10_000;
uint256 public nextLockId = 1;
// supported nftPositionMangers
EnumerableSet.AddressSet private nftManagers;
// lock details
mapping(uint256 lockId => LockInfo) public locks;
// List of lock ids for user
mapping(address => EnumerableSet.UintSet) private userLocks;
mapping(bytes => bool) public disabledSigs;
event OnLock(
uint256 indexed lockId,
address nftPositionManager,
address owner,
uint256 nftId,
uint256 endTime
);
event OnUnlock(
uint256 indexed lockId,
address owner,
uint256 nftId,
uint256 unlockedTime
);
event OnLockPendingTransfer(
uint256 indexed lockId,
address previousOwner,
address newOwner
);
event OnLockTransferred(
uint256 indexed lockId,
address previousOwner,
address newOwner
);
event OnIncreaseLiquidity(uint256 indexed lockId);
event OnDecreaseLiquidity(uint256 indexed lockId);
event OnRelock(uint256 indexed lockId, uint256 endTime);
event OnSetCollector(uint256 indexed lockId, address collector);
event OnAddFee(bytes32 nameHash, string name, uint256 lpFee, uint256 collectFee, uint256 lockFee, address lockFeeToken);
event OnEditFee(bytes32 nameHash, string name, uint256 lpFee, uint256 collectFee, uint256 lockFee, address lockFeeToken);
event OnRemoveFee(bytes32 nameHash);
event OnFeeReceiverUpdated(address oldReceiver, address newReceiver);
event OnFeeSignerUpdated(address oldSigner, address newSigner);
event OnAddNftManger(address nftManger);
event OnSignatureDisabled(bytes sig);
modifier validLockOwner(uint256 lockId) {
require(lockId < nextLockId, "Invalid lockId");
require(locks[lockId].owner == _msgSender(), "Not lock owner");
_;
}
constructor(
address nftManager_,
address feeReceiver_,
address customFeeSigner_
) Ownable(_msgSender()) {
if(nftManager_ != address(0)) {
nftManagers.add(nftManager_);
}
feeReceiver = feeReceiver_;
customFeeSigner = customFeeSigner_;
addOrUpdateFee("DEFAULT", 40, 160, 0, address(0));
addOrUpdateFee("LVP", 64, 80, 0, address(0));
addOrUpdateFee("LLP", 24, 280, 0, address(0));
}
function addOrUpdateFee(string memory name_, uint256 lpFee_, uint256 collectFee_, uint256 lockFee_, address lockFeeToken_) public onlyOwner {
bytes32 nameHash = keccak256(abi.encodePacked(name_));
FeeStruct memory feeObj = FeeStruct(name_, lpFee_, collectFee_, lockFee_, lockFeeToken_);
fees[nameHash] = feeObj;
if(feeNameHashSet.contains(nameHash)) {
emit OnEditFee(nameHash, name_, lpFee_, collectFee_, lockFee_, lockFeeToken_);
} else {
feeNameHashSet.add(nameHash);
emit OnAddFee(nameHash, name_, lpFee_, collectFee_, lockFee_, lockFeeToken_);
}
}
function removeFee(string memory name_) external onlyOwner {
bytes32 nameHash = keccak256(abi.encodePacked(name_));
require(nameHash != keccak256(abi.encodePacked("DEFAULT")), "DEFAULT");
require(feeNameHashSet.contains(nameHash), "Fee not exists");
feeNameHashSet.remove(nameHash);
delete fees[nameHash];
emit OnRemoveFee(nameHash);
}
function updateFeeReceiver(address feeReceiver_) external onlyOwner {
emit OnFeeReceiverUpdated(feeReceiver, feeReceiver_);
feeReceiver = feeReceiver_;
}
function updateFeeSigner(address feeSigner_) external onlyOwner {
emit OnFeeSignerUpdated(customFeeSigner, feeSigner_);
customFeeSigner = feeSigner_;
}
function addSupportedNftManager(address nftManager_) external onlyOwner {
nftManagers.add(nftManager_);
emit OnAddNftManger(nftManager_);
}
function disableSig(bytes memory sig) external onlyOwner {
disabledSigs[sig] = true;
emit OnSignatureDisabled(sig);
}
function supportedNftManager(
address nftManager_
) public view returns (bool) {
return nftManagers.contains(nftManager_);
}
function isSupportedFeeName(string memory name_) public view returns(bool) {
bytes32 nameHash = keccak256(abi.encodePacked(name_));
return feeNameHashSet.contains(nameHash);
}
function getFee (string memory name_) public view returns (FeeStruct memory) {
bytes32 feeHash = keccak256(abi.encodePacked(name_));
require(feeNameHashSet.contains(feeHash), "NOT FOUND");
return fees[feeHash];
}
function _deductLockFee(FeeStruct memory feeObj) internal {
if(feeObj.lockFeeToken == address(0)) {// ETH
require(msg.value == feeObj.lockFee, "Insufficient Fee");
TransferHelper.safeTransferETH(feeReceiver, msg.value);
} else {
TransferHelper.safeTransferFrom(feeObj.lockFeeToken, _msgSender(), feeReceiver, feeObj.lockFee);
}
}
function _getPool(INonfungiblePositionManager nftManager_, uint256 nftId_) internal view returns(address pool) {
(,, address token0, address token1, uint24 fee,,,,,,,) = nftManager_.positions(nftId_);
// get factory
IUniswapV3Factory factory = IUniswapV3Factory(nftManager_.factory());
// get pool
pool = factory.getPool(token0, token1, fee);
}
function lock(
INonfungiblePositionManager nftManager_,
uint256 nftId_,
address owner_,
address collector_,
uint256 endTime_,
string memory feeName_
) external payable returns (uint256 lockId) {
require(collector_ != address(0), "CollectAddress invalid");
require(endTime_ > block.timestamp, "EndTime <= currentTime");
require(isSupportedFeeName(feeName_), "FeeName invalid");
require(
supportedNftManager(address(nftManager_)),
"nftPositionManager not supported"
);
FeeStruct memory feeObj = getFee(feeName_);
lockId = _lock(nftManager_, nftId_, owner_, collector_, endTime_, feeObj);
}
function lockWithCustomFee(
INonfungiblePositionManager nftManager_,
uint256 nftId_,
address owner_,
address collector_,
uint256 endTime_,
bytes memory signature_,
FeeStruct memory feeObj_
) external payable returns (uint256 lockId) {
require(collector_ != address(0), "CollectAddress invalid");
require(endTime_ > block.timestamp, "EndTime <= currentTime");
require(
supportedNftManager(address(nftManager_)),
"nftPositionManager not supported"
);
_verifySignature(feeObj_, signature_);
lockId = _lock(nftManager_, nftId_, owner_, collector_, endTime_, feeObj_);
}
function _verifySignature(
FeeStruct memory fee,
bytes memory signature
) internal view {
require(!disabledSigs[signature], "Signature disabled");
bytes32 messageHash = keccak256(
abi.encodePacked(block.chainid, _msgSender(), fee.name, fee.lpFee, fee.collectFee, fee.lockFee, fee.lockFeeToken)
);
bytes32 prefixedHash = MessageHashUtils.toEthSignedMessageHash(messageHash);
address signer = ECDSA.recover(prefixedHash, signature);
require(signer == customFeeSigner, "FeeSigner not allowed");
}
function _lock(
INonfungiblePositionManager nftManager_,
uint256 nftId_,
address owner_,
address collector_,
uint256 endTime_,
FeeStruct memory feeObj
) internal returns (uint256 lockId) {
if(feeObj.lockFee > 0) {
_deductLockFee(feeObj);
}
nftManager_.safeTransferFrom(_msgSender(), address(this), nftId_);
address pool = _getPool(nftManager_, nftId_);
// collect fees for user to prevent being charged a fee on existing fees
nftManager_.collect(INonfungiblePositionManager.CollectParams(nftId_, owner_, type(uint128).max, type(uint128).max));
// Take lp fee
if (feeObj.lpFee > 0) {
uint128 liquidity = _getLiquidity(nftManager_, nftId_);
nftManager_.decreaseLiquidity(
INonfungiblePositionManager.DecreaseLiquidityParams(nftId_, uint128(liquidity * feeObj.lpFee / FEE_DENOMINATOR),
0, 0, block.timestamp));
nftManager_.collect(INonfungiblePositionManager.CollectParams(nftId_, feeReceiver, type(uint128).max, type(uint128).max));
}
LockInfo memory newLock = LockInfo({
lockId: nextLockId,
nftPositionManager: nftManager_,
pendingOwner: address(0),
owner: owner_,
collector: collector_,
pool: pool,
collectFee: feeObj.collectFee,
nftId: nftId_,
startTime: block.timestamp,
endTime: endTime_
});
locks[newLock.lockId] = newLock;
userLocks[owner_].add(newLock.lockId);
nextLockId++;
emit OnLock(
newLock.lockId,
address(nftManager_),
owner_,
nftId_,
endTime_
);
return newLock.lockId;
}
function transferLock(
uint256 lockId_,
address newOwner_
) external validLockOwner(lockId_) {
locks[lockId_].pendingOwner = newOwner_;
emit OnLockPendingTransfer(lockId_, _msgSender(), newOwner_);
}
function acceptLock(uint256 lockId_) external {
require(lockId_ < nextLockId, "Invalid lockId");
address newOwner = _msgSender();
// check new owner
require(newOwner == locks[lockId_].pendingOwner, "Not pendingOwner");
// emit event
emit OnLockTransferred(lockId_, locks[lockId_].owner, newOwner);
// remove lockId from owner
userLocks[locks[lockId_].owner].remove(lockId_);
// add lockId to new owner
userLocks[newOwner].add(lockId_);
// set owner
locks[lockId_].pendingOwner = address(0);
locks[lockId_].owner = newOwner;
}
/**
* @dev increases liquidity. Can be called by anyone.
*/
function increaseLiquidity(
uint256 lockId_,
INonfungiblePositionManager.IncreaseLiquidityParams calldata params
)
external
payable
nonReentrant
returns (uint128 liquidity, uint256 amount0, uint256 amount1)
{
LockInfo memory userLock = locks[lockId_];
require(userLock.nftId == params.tokenId, "Invalid NFT_ID");
(, , address token0, address token1, , , , , , , , ) = userLock
.nftPositionManager
.positions(userLock.nftId);
uint256 balance0Before = IERC20(token0).balanceOf(address(this));
uint256 balance1Before = IERC20(token1).balanceOf(address(this));
TransferHelper.safeTransferFrom(
token0,
_msgSender(),
address(this),
params.amount0Desired
);
TransferHelper.safeTransferFrom(
token1,
_msgSender(),
address(this),
params.amount1Desired
);
TransferHelper.safeApprove(
token0,
address(userLock.nftPositionManager),
params.amount0Desired
);
TransferHelper.safeApprove(
token1,
address(userLock.nftPositionManager),
params.amount1Desired
);
(liquidity, amount0, amount1) = userLock
.nftPositionManager
.increaseLiquidity(params);
uint256 balance0diff = IERC20(token0).balanceOf(address(this)) - balance0Before;
uint256 balance1diff = IERC20(token1).balanceOf(address(this)) - balance1Before;
if (balance0diff > 0) {
TransferHelper.safeTransfer(token0, _msgSender(), balance0diff);
}
if (balance1diff > 0) {
TransferHelper.safeTransfer(token1, _msgSender(), balance1diff);
}
emit OnIncreaseLiquidity(lockId_);
}
/**
* @dev decrease liquidity if a lock has expired
*/
function decreaseLiquidity(
uint256 lockId_,
INonfungiblePositionManager.DecreaseLiquidityParams calldata params
)
external
payable
validLockOwner(lockId_)
nonReentrant
returns (uint256 amount0, uint256 amount1)
{
LockInfo memory userLock = locks[lockId_];
require(userLock.nftId == params.tokenId, "Invalid NFT_ID");
require(userLock.endTime < block.timestamp, "NOT YET");
_collect(lockId_, _msgSender(), type(uint128).max, type(uint128).max); // collect protocol fees
(amount0, amount1) = userLock.nftPositionManager.decreaseLiquidity(params);
userLock.nftPositionManager.collect(
INonfungiblePositionManager.CollectParams(
userLock.nftId,
userLock.owner,
type(uint128).max,
type(uint128).max
)
);
emit OnDecreaseLiquidity(lockId_);
}
function unlock(uint256 lockId_) external validLockOwner(lockId_) {
LockInfo memory userLock = locks[lockId_];
require(userLock.endTime < block.timestamp, "Not yet");
_collect(lockId_, userLock.owner, type(uint128).max, type(uint128).max);
userLock.nftPositionManager.safeTransferFrom(
address(this),
userLock.owner,
userLock.nftId
);
userLocks[userLock.owner].remove(lockId_);
emit OnUnlock(lockId_, userLock.owner, userLock.nftId, block.timestamp);
delete locks[lockId_]; // clear the state for this lock (reset all values to zero)
}
function relock(
uint256 lockId_,
uint256 endTime_
) external validLockOwner(lockId_) nonReentrant {
LockInfo storage userLock = locks[lockId_];
require(endTime_ > userLock.endTime, "EndTime <= currentEndTiem");
require(endTime_ > block.timestamp, "EndTime <= now");
userLock.endTime = endTime_;
emit OnRelock(lockId_, userLock.endTime);
}
/**
* @dev Private collect function, wrap this in re-entrancy guard calls
*/
function _collect(
uint256 lockId_,
address recipient_,
uint128 amount0Max_,
uint128 amount1Max_
) private returns (uint256 amount0, uint256 amount1, uint256 fee0, uint256 fee1) {
LockInfo memory userLock = locks[lockId_];
require(
userLock.owner == _msgSender() || userLock.collector == _msgSender(),
"Not owner"
);
if(userLock.collectFee == 0) {
// No user collect fee
(amount0, amount1) = userLock.nftPositionManager.collect(
INonfungiblePositionManager.CollectParams(
userLock.nftId,
recipient_,
amount0Max_,
amount1Max_
)
);
} else {
(,,address _token0,address _token1,,,,,,,,) = userLock.nftPositionManager.positions(userLock.nftId);
uint256 balance0 = IERC20(_token0).balanceOf(address(this));
uint256 balance1 = IERC20(_token1).balanceOf(address(this));
userLock.nftPositionManager.collect(
INonfungiblePositionManager.CollectParams(userLock.nftId, address(this), amount0Max_, amount1Max_)
);
balance0 = IERC20(_token0).balanceOf(address(this)) - balance0;
balance1 = IERC20(_token1).balanceOf(address(this)) - balance1;
if(balance0 > 0) {
fee0 = balance0 * userLock.collectFee / FEE_DENOMINATOR;
TransferHelper.safeTransfer(_token0, feeReceiver, fee0);
amount0 = balance0 - fee0;
TransferHelper.safeTransfer(_token0, recipient_, amount0);
}
if(balance1 > 0) {
fee1 = balance1 * userLock.collectFee / FEE_DENOMINATOR;
TransferHelper.safeTransfer(_token1, feeReceiver, fee1);
amount1 = balance1 - fee1;
TransferHelper.safeTransfer(_token1, recipient_, amount1);
}
}
}
/**
* @dev Collect fees to _recipient if msg.sender is the owner of _lockId
*/
function collect(
uint256 lockId_,
address recipient_,
uint128 amount0Max_,
uint128 amount1Max_
)
external
nonReentrant
returns (uint256 amount0, uint256 amount1, uint256 fee0, uint256 fee1)
{
(amount0, amount1, fee0, fee1) = _collect(
lockId_,
recipient_,
amount0Max_,
amount1Max_
);
}
/**
* @dev set the adress to which fees are automatically collected
*/
function setCollectAddress(
uint256 lockId_,
address collector_
) external validLockOwner(lockId_) nonReentrant {
require(collector_ != address(0), "COLLECT_ADDR");
LockInfo storage userLock = locks[lockId_];
userLock.collector = collector_;
emit OnSetCollector(lockId_, collector_);
}
/**
* @dev returns just the liquidity value from a position
*/
function _getLiquidity (INonfungiblePositionManager nftPositionManager_, uint256 tokenId_) private view returns (uint128) {
(,,,,,,,uint128 liquidity,,,,) = nftPositionManager_.positions(tokenId_);
return liquidity;
}
/**
* @dev Allows admin to remove any eth mistakenly sent to the contract
*/
function adminRefundEth (uint256 amount_, address payable receiver_) external onlyOwner nonReentrant {
(bool success, ) = receiver_.call{value: amount_}("");
if (!success) {
revert("Gas token transfer failed");
}
}
/**
* @dev Allows admin to remove any ERC20's mistakenly sent to the contract
* Since this contract is only for locking NFT liquidity, this allows removal of ERC20 tokens and cannot remove locked NFT liquidity.
*/
function adminRefundERC20 (address token_, address receiver_, uint256 amount_) external onlyOwner nonReentrant {
// TransferHelper.safeTransfer = token.call(abi.encodeWithSelector(IERC20.transfer.selector, to, value));
// Attempting to transfer nfts with this function (substituting a nft_id for amount_) wil fail with 'ST' as NFTS do not have the same interface
TransferHelper.safeTransfer(token_, receiver_, amount_);
}
function onERC721Received(
address operator,
address from,
uint256 tokenId,
bytes calldata data
) external pure override returns (bytes4) {
return IERC721Receiver.onERC721Received.selector;
}
function getUserLocks(
address user
) external view returns(uint256[] memory lockIds) {
return userLocks[user].values();
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (access/Ownable.sol)
pragma solidity ^0.8.20;
import {Context} from "../utils/Context.sol";
/**
* @dev Contract module which provides a basic access control mechanism, where
* there is an account (an owner) that can be granted exclusive access to
* specific functions.
*
* The initial owner is set to the address provided by the deployer. This can
* later be changed with {transferOwnership}.
*
* This module is used through inheritance. It will make available the modifier
* `onlyOwner`, which can be applied to your functions to restrict their use to
* the owner.
*/
abstract contract Ownable is Context {
address private _owner;
/**
* @dev The caller account is not authorized to perform an operation.
*/
error OwnableUnauthorizedAccount(address account);
/**
* @dev The owner is not a valid owner account. (eg. `address(0)`)
*/
error OwnableInvalidOwner(address owner);
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
/**
* @dev Initializes the contract setting the address provided by the deployer as the initial owner.
*/
constructor(address initialOwner) {
if (initialOwner == address(0)) {
revert OwnableInvalidOwner(address(0));
}
_transferOwnership(initialOwner);
}
/**
* @dev Throws if called by any account other than the owner.
*/
modifier onlyOwner() {
_checkOwner();
_;
}
/**
* @dev Returns the address of the current owner.
*/
function owner() public view virtual returns (address) {
return _owner;
}
/**
* @dev Throws if the sender is not the owner.
*/
function _checkOwner() internal view virtual {
if (owner() != _msgSender()) {
revert OwnableUnauthorizedAccount(_msgSender());
}
}
/**
* @dev Leaves the contract without owner. It will not be possible to call
* `onlyOwner` functions. Can only be called by the current owner.
*
* NOTE: Renouncing ownership will leave the contract without an owner,
* thereby disabling any functionality that is only available to the owner.
*/
function renounceOwnership() public virtual onlyOwner {
_transferOwnership(address(0));
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Can only be called by the current owner.
*/
function transferOwnership(address newOwner) public virtual onlyOwner {
if (newOwner == address(0)) {
revert OwnableInvalidOwner(address(0));
}
_transferOwnership(newOwner);
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Internal function without access restriction.
*/
function _transferOwnership(address newOwner) internal virtual {
address oldOwner = _owner;
_owner = newOwner;
emit OwnershipTransferred(oldOwner, newOwner);
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (token/ERC20/extensions/IERC20Permit.sol)
pragma solidity ^0.8.20;
/**
* @dev Interface of the ERC-20 Permit extension allowing approvals to be made via signatures, as defined in
* https://eips.ethereum.org/EIPS/eip-2612[ERC-2612].
*
* Adds the {permit} method, which can be used to change an account's ERC-20 allowance (see {IERC20-allowance}) by
* presenting a message signed by the account. By not relying on {IERC20-approve}, the token holder account doesn't
* need to send a transaction, and thus is not required to hold Ether at all.
*
* ==== Security Considerations
*
* There are two important considerations concerning the use of `permit`. The first is that a valid permit signature
* expresses an allowance, and it should not be assumed to convey additional meaning. In particular, it should not be
* considered as an intention to spend the allowance in any specific way. The second is that because permits have
* built-in replay protection and can be submitted by anyone, they can be frontrun. A protocol that uses permits should
* take this into consideration and allow a `permit` call to fail. Combining these two aspects, a pattern that may be
* generally recommended is:
*
* ```solidity
* function doThingWithPermit(..., uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s) public {
* try token.permit(msg.sender, address(this), value, deadline, v, r, s) {} catch {}
* doThing(..., value);
* }
*
* function doThing(..., uint256 value) public {
* token.safeTransferFrom(msg.sender, address(this), value);
* ...
* }
* ```
*
* Observe that: 1) `msg.sender` is used as the owner, leaving no ambiguity as to the signer intent, and 2) the use of
* `try/catch` allows the permit to fail and makes the code tolerant to frontrunning. (See also
* {SafeERC20-safeTransferFrom}).
*
* Additionally, note that smart contract wallets (such as Argent or Safe) are not able to produce permit signatures, so
* contracts should have entry points that don't rely on permit.
*/
interface IERC20Permit {
/**
* @dev Sets `value` as the allowance of `spender` over ``owner``'s tokens,
* given ``owner``'s signed approval.
*
* IMPORTANT: The same issues {IERC20-approve} has related to transaction
* ordering also apply here.
*
* Emits an {Approval} event.
*
* Requirements:
*
* - `spender` cannot be the zero address.
* - `deadline` must be a timestamp in the future.
* - `v`, `r` and `s` must be a valid `secp256k1` signature from `owner`
* over the EIP712-formatted function arguments.
* - the signature must use ``owner``'s current nonce (see {nonces}).
*
* For more information on the signature format, see the
* https://eips.ethereum.org/EIPS/eip-2612#specification[relevant EIP
* section].
*
* CAUTION: See Security Considerations above.
*/
function permit(
address owner,
address spender,
uint256 value,
uint256 deadline,
uint8 v,
bytes32 r,
bytes32 s
) external;
/**
* @dev Returns the current nonce for `owner`. This value must be
* included whenever a signature is generated for {permit}.
*
* Every successful call to {permit} increases ``owner``'s nonce by one. This
* prevents a signature from being used multiple times.
*/
function nonces(address owner) external view returns (uint256);
/**
* @dev Returns the domain separator used in the encoding of the signature for {permit}, as defined by {EIP712}.
*/
// solhint-disable-next-line func-name-mixedcase
function DOMAIN_SEPARATOR() external view returns (bytes32);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (token/ERC20/IERC20.sol)
pragma solidity ^0.8.20;
/**
* @dev Interface of the ERC-20 standard as defined in the ERC.
*/
interface IERC20 {
/**
* @dev Emitted when `value` tokens are moved from one account (`from`) to
* another (`to`).
*
* Note that `value` may be zero.
*/
event Transfer(address indexed from, address indexed to, uint256 value);
/**
* @dev Emitted when the allowance of a `spender` for an `owner` is set by
* a call to {approve}. `value` is the new allowance.
*/
event Approval(address indexed owner, address indexed spender, uint256 value);
/**
* @dev Returns the value of tokens in existence.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns the value of tokens owned by `account`.
*/
function balanceOf(address account) external view returns (uint256);
/**
* @dev Moves a `value` amount of tokens from the caller's account to `to`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transfer(address to, uint256 value) external returns (bool);
/**
* @dev Returns the remaining number of tokens that `spender` will be
* allowed to spend on behalf of `owner` through {transferFrom}. This is
* zero by default.
*
* This value changes when {approve} or {transferFrom} are called.
*/
function allowance(address owner, address spender) external view returns (uint256);
/**
* @dev Sets a `value` amount of tokens as the allowance of `spender` over the
* caller's tokens.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* IMPORTANT: Beware that changing an allowance with this method brings the risk
* that someone may use both the old and the new allowance by unfortunate
* transaction ordering. One possible solution to mitigate this race
* condition is to first reduce the spender's allowance to 0 and set the
* desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
*
* Emits an {Approval} event.
*/
function approve(address spender, uint256 value) external returns (bool);
/**
* @dev Moves a `value` amount of tokens from `from` to `to` using the
* allowance mechanism. `value` is then deducted from the caller's
* allowance.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transferFrom(address from, address to, uint256 value) external returns (bool);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (token/ERC721/IERC721Receiver.sol)
pragma solidity ^0.8.20;
/**
* @title ERC-721 token receiver interface
* @dev Interface for any contract that wants to support safeTransfers
* from ERC-721 asset contracts.
*/
interface IERC721Receiver {
/**
* @dev Whenever an {IERC721} `tokenId` token is transferred to this contract via {IERC721-safeTransferFrom}
* by `operator` from `from`, this function is called.
*
* It must return its Solidity selector to confirm the token transfer.
* If any other value is returned or the interface is not implemented by the recipient, the transfer will be
* reverted.
*
* The selector can be obtained in Solidity with `IERC721Receiver.onERC721Received.selector`.
*/
function onERC721Received(
address operator,
address from,
uint256 tokenId,
bytes calldata data
) external returns (bytes4);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.3.0) (utils/Arrays.sol)
// This file was procedurally generated from scripts/generate/templates/Arrays.js.
pragma solidity ^0.8.20;
import {Comparators} from "./Comparators.sol";
import {SlotDerivation} from "./SlotDerivation.sol";
import {StorageSlot} from "./StorageSlot.sol";
import {Math} from "./math/Math.sol";
/**
* @dev Collection of functions related to array types.
*/
library Arrays {
using SlotDerivation for bytes32;
using StorageSlot for bytes32;
/**
* @dev Sort an array of uint256 (in memory) following the provided comparator function.
*
* This function does the sorting "in place", meaning that it overrides the input. The object is returned for
* convenience, but that returned value can be discarded safely if the caller has a memory pointer to the array.
*
* NOTE: this function's cost is `O(n · log(n))` in average and `O(n²)` in the worst case, with n the length of the
* array. Using it in view functions that are executed through `eth_call` is safe, but one should be very careful
* when executing this as part of a transaction. If the array being sorted is too large, the sort operation may
* consume more gas than is available in a block, leading to potential DoS.
*
* IMPORTANT: Consider memory side-effects when using custom comparator functions that access memory in an unsafe way.
*/
function sort(
uint256[] memory array,
function(uint256, uint256) pure returns (bool) comp
) internal pure returns (uint256[] memory) {
_quickSort(_begin(array), _end(array), comp);
return array;
}
/**
* @dev Variant of {sort} that sorts an array of uint256 in increasing order.
*/
function sort(uint256[] memory array) internal pure returns (uint256[] memory) {
sort(array, Comparators.lt);
return array;
}
/**
* @dev Sort an array of address (in memory) following the provided comparator function.
*
* This function does the sorting "in place", meaning that it overrides the input. The object is returned for
* convenience, but that returned value can be discarded safely if the caller has a memory pointer to the array.
*
* NOTE: this function's cost is `O(n · log(n))` in average and `O(n²)` in the worst case, with n the length of the
* array. Using it in view functions that are executed through `eth_call` is safe, but one should be very careful
* when executing this as part of a transaction. If the array being sorted is too large, the sort operation may
* consume more gas than is available in a block, leading to potential DoS.
*
* IMPORTANT: Consider memory side-effects when using custom comparator functions that access memory in an unsafe way.
*/
function sort(
address[] memory array,
function(address, address) pure returns (bool) comp
) internal pure returns (address[] memory) {
sort(_castToUint256Array(array), _castToUint256Comp(comp));
return array;
}
/**
* @dev Variant of {sort} that sorts an array of address in increasing order.
*/
function sort(address[] memory array) internal pure returns (address[] memory) {
sort(_castToUint256Array(array), Comparators.lt);
return array;
}
/**
* @dev Sort an array of bytes32 (in memory) following the provided comparator function.
*
* This function does the sorting "in place", meaning that it overrides the input. The object is returned for
* convenience, but that returned value can be discarded safely if the caller has a memory pointer to the array.
*
* NOTE: this function's cost is `O(n · log(n))` in average and `O(n²)` in the worst case, with n the length of the
* array. Using it in view functions that are executed through `eth_call` is safe, but one should be very careful
* when executing this as part of a transaction. If the array being sorted is too large, the sort operation may
* consume more gas than is available in a block, leading to potential DoS.
*
* IMPORTANT: Consider memory side-effects when using custom comparator functions that access memory in an unsafe way.
*/
function sort(
bytes32[] memory array,
function(bytes32, bytes32) pure returns (bool) comp
) internal pure returns (bytes32[] memory) {
sort(_castToUint256Array(array), _castToUint256Comp(comp));
return array;
}
/**
* @dev Variant of {sort} that sorts an array of bytes32 in increasing order.
*/
function sort(bytes32[] memory array) internal pure returns (bytes32[] memory) {
sort(_castToUint256Array(array), Comparators.lt);
return array;
}
/**
* @dev Performs a quick sort of a segment of memory. The segment sorted starts at `begin` (inclusive), and stops
* at end (exclusive). Sorting follows the `comp` comparator.
*
* Invariant: `begin <= end`. This is the case when initially called by {sort} and is preserved in subcalls.
*
* IMPORTANT: Memory locations between `begin` and `end` are not validated/zeroed. This function should
* be used only if the limits are within a memory array.
*/
function _quickSort(uint256 begin, uint256 end, function(uint256, uint256) pure returns (bool) comp) private pure {
unchecked {
if (end - begin < 0x40) return;
// Use first element as pivot
uint256 pivot = _mload(begin);
// Position where the pivot should be at the end of the loop
uint256 pos = begin;
for (uint256 it = begin + 0x20; it < end; it += 0x20) {
if (comp(_mload(it), pivot)) {
// If the value stored at the iterator's position comes before the pivot, we increment the
// position of the pivot and move the value there.
pos += 0x20;
_swap(pos, it);
}
}
_swap(begin, pos); // Swap pivot into place
_quickSort(begin, pos, comp); // Sort the left side of the pivot
_quickSort(pos + 0x20, end, comp); // Sort the right side of the pivot
}
}
/**
* @dev Pointer to the memory location of the first element of `array`.
*/
function _begin(uint256[] memory array) private pure returns (uint256 ptr) {
assembly ("memory-safe") {
ptr := add(array, 0x20)
}
}
/**
* @dev Pointer to the memory location of the first memory word (32bytes) after `array`. This is the memory word
* that comes just after the last element of the array.
*/
function _end(uint256[] memory array) private pure returns (uint256 ptr) {
unchecked {
return _begin(array) + array.length * 0x20;
}
}
/**
* @dev Load memory word (as a uint256) at location `ptr`.
*/
function _mload(uint256 ptr) private pure returns (uint256 value) {
assembly {
value := mload(ptr)
}
}
/**
* @dev Swaps the elements memory location `ptr1` and `ptr2`.
*/
function _swap(uint256 ptr1, uint256 ptr2) private pure {
assembly {
let value1 := mload(ptr1)
let value2 := mload(ptr2)
mstore(ptr1, value2)
mstore(ptr2, value1)
}
}
/// @dev Helper: low level cast address memory array to uint256 memory array
function _castToUint256Array(address[] memory input) private pure returns (uint256[] memory output) {
assembly {
output := input
}
}
/// @dev Helper: low level cast bytes32 memory array to uint256 memory array
function _castToUint256Array(bytes32[] memory input) private pure returns (uint256[] memory output) {
assembly {
output := input
}
}
/// @dev Helper: low level cast address comp function to uint256 comp function
function _castToUint256Comp(
function(address, address) pure returns (bool) input
) private pure returns (function(uint256, uint256) pure returns (bool) output) {
assembly {
output := input
}
}
/// @dev Helper: low level cast bytes32 comp function to uint256 comp function
function _castToUint256Comp(
function(bytes32, bytes32) pure returns (bool) input
) private pure returns (function(uint256, uint256) pure returns (bool) output) {
assembly {
output := input
}
}
/**
* @dev Searches a sorted `array` and returns the first index that contains
* a value greater or equal to `element`. If no such index exists (i.e. all
* values in the array are strictly less than `element`), the array length is
* returned. Time complexity O(log n).
*
* NOTE: The `array` is expected to be sorted in ascending order, and to
* contain no repeated elements.
*
* IMPORTANT: Deprecated. This implementation behaves as {lowerBound} but lacks
* support for repeated elements in the array. The {lowerBound} function should
* be used instead.
*/
function findUpperBound(uint256[] storage array, uint256 element) internal view returns (uint256) {
uint256 low = 0;
uint256 high = array.length;
if (high == 0) {
return 0;
}
while (low < high) {
uint256 mid = Math.average(low, high);
// Note that mid will always be strictly less than high (i.e. it will be a valid array index)
// because Math.average rounds towards zero (it does integer division with truncation).
if (unsafeAccess(array, mid).value > element) {
high = mid;
} else {
low = mid + 1;
}
}
// At this point `low` is the exclusive upper bound. We will return the inclusive upper bound.
if (low > 0 && unsafeAccess(array, low - 1).value == element) {
return low - 1;
} else {
return low;
}
}
/**
* @dev Searches an `array` sorted in ascending order and returns the first
* index that contains a value greater or equal than `element`. If no such index
* exists (i.e. all values in the array are strictly less than `element`), the array
* length is returned. Time complexity O(log n).
*
* See C++'s https://en.cppreference.com/w/cpp/algorithm/lower_bound[lower_bound].
*/
function lowerBound(uint256[] storage array, uint256 element) internal view returns (uint256) {
uint256 low = 0;
uint256 high = array.length;
if (high == 0) {
return 0;
}
while (low < high) {
uint256 mid = Math.average(low, high);
// Note that mid will always be strictly less than high (i.e. it will be a valid array index)
// because Math.average rounds towards zero (it does integer division with truncation).
if (unsafeAccess(array, mid).value < element) {
// this cannot overflow because mid < high
unchecked {
low = mid + 1;
}
} else {
high = mid;
}
}
return low;
}
/**
* @dev Searches an `array` sorted in ascending order and returns the first
* index that contains a value strictly greater than `element`. If no such index
* exists (i.e. all values in the array are strictly less than `element`), the array
* length is returned. Time complexity O(log n).
*
* See C++'s https://en.cppreference.com/w/cpp/algorithm/upper_bound[upper_bound].
*/
function upperBound(uint256[] storage array, uint256 element) internal view returns (uint256) {
uint256 low = 0;
uint256 high = array.length;
if (high == 0) {
return 0;
}
while (low < high) {
uint256 mid = Math.average(low, high);
// Note that mid will always be strictly less than high (i.e. it will be a valid array index)
// because Math.average rounds towards zero (it does integer division with truncation).
if (unsafeAccess(array, mid).value > element) {
high = mid;
} else {
// this cannot overflow because mid < high
unchecked {
low = mid + 1;
}
}
}
return low;
}
/**
* @dev Same as {lowerBound}, but with an array in memory.
*/
function lowerBoundMemory(uint256[] memory array, uint256 element) internal pure returns (uint256) {
uint256 low = 0;
uint256 high = array.length;
if (high == 0) {
return 0;
}
while (low < high) {
uint256 mid = Math.average(low, high);
// Note that mid will always be strictly less than high (i.e. it will be a valid array index)
// because Math.average rounds towards zero (it does integer division with truncation).
if (unsafeMemoryAccess(array, mid) < element) {
// this cannot overflow because mid < high
unchecked {
low = mid + 1;
}
} else {
high = mid;
}
}
return low;
}
/**
* @dev Same as {upperBound}, but with an array in memory.
*/
function upperBoundMemory(uint256[] memory array, uint256 element) internal pure returns (uint256) {
uint256 low = 0;
uint256 high = array.length;
if (high == 0) {
return 0;
}
while (low < high) {
uint256 mid = Math.average(low, high);
// Note that mid will always be strictly less than high (i.e. it will be a valid array index)
// because Math.average rounds towards zero (it does integer division with truncation).
if (unsafeMemoryAccess(array, mid) > element) {
high = mid;
} else {
// this cannot overflow because mid < high
unchecked {
low = mid + 1;
}
}
}
return low;
}
/**
* @dev Access an array in an "unsafe" way. Skips solidity "index-out-of-range" check.
*
* WARNING: Only use if you are certain `pos` is lower than the array length.
*/
function unsafeAccess(address[] storage arr, uint256 pos) internal pure returns (StorageSlot.AddressSlot storage) {
bytes32 slot;
assembly ("memory-safe") {
slot := arr.slot
}
return slot.deriveArray().offset(pos).getAddressSlot();
}
/**
* @dev Access an array in an "unsafe" way. Skips solidity "index-out-of-range" check.
*
* WARNING: Only use if you are certain `pos` is lower than the array length.
*/
function unsafeAccess(bytes32[] storage arr, uint256 pos) internal pure returns (StorageSlot.Bytes32Slot storage) {
bytes32 slot;
assembly ("memory-safe") {
slot := arr.slot
}
return slot.deriveArray().offset(pos).getBytes32Slot();
}
/**
* @dev Access an array in an "unsafe" way. Skips solidity "index-out-of-range" check.
*
* WARNING: Only use if you are certain `pos` is lower than the array length.
*/
function unsafeAccess(uint256[] storage arr, uint256 pos) internal pure returns (StorageSlot.Uint256Slot storage) {
bytes32 slot;
assembly ("memory-safe") {
slot := arr.slot
}
return slot.deriveArray().offset(pos).getUint256Slot();
}
/**
* @dev Access an array in an "unsafe" way. Skips solidity "index-out-of-range" check.
*
* WARNING: Only use if you are certain `pos` is lower than the array length.
*/
function unsafeMemoryAccess(address[] memory arr, uint256 pos) internal pure returns (address res) {
assembly {
res := mload(add(add(arr, 0x20), mul(pos, 0x20)))
}
}
/**
* @dev Access an array in an "unsafe" way. Skips solidity "index-out-of-range" check.
*
* WARNING: Only use if you are certain `pos` is lower than the array length.
*/
function unsafeMemoryAccess(bytes32[] memory arr, uint256 pos) internal pure returns (bytes32 res) {
assembly {
res := mload(add(add(arr, 0x20), mul(pos, 0x20)))
}
}
/**
* @dev Access an array in an "unsafe" way. Skips solidity "index-out-of-range" check.
*
* WARNING: Only use if you are certain `pos` is lower than the array length.
*/
function unsafeMemoryAccess(uint256[] memory arr, uint256 pos) internal pure returns (uint256 res) {
assembly {
res := mload(add(add(arr, 0x20), mul(pos, 0x20)))
}
}
/**
* @dev Helper to set the length of a dynamic array. Directly writing to `.length` is forbidden.
*
* WARNING: this does not clear elements if length is reduced, of initialize elements if length is increased.
*/
function unsafeSetLength(address[] storage array, uint256 len) internal {
assembly ("memory-safe") {
sstore(array.slot, len)
}
}
/**
* @dev Helper to set the length of a dynamic array. Directly writing to `.length` is forbidden.
*
* WARNING: this does not clear elements if length is reduced, of initialize elements if length is increased.
*/
function unsafeSetLength(bytes32[] storage array, uint256 len) internal {
assembly ("memory-safe") {
sstore(array.slot, len)
}
}
/**
* @dev Helper to set the length of a dynamic array. Directly writing to `.length` is forbidden.
*
* WARNING: this does not clear elements if length is reduced, of initialize elements if length is increased.
*/
function unsafeSetLength(uint256[] storage array, uint256 len) internal {
assembly ("memory-safe") {
sstore(array.slot, len)
}
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (utils/Comparators.sol)
pragma solidity ^0.8.20;
/**
* @dev Provides a set of functions to compare values.
*
* _Available since v5.1._
*/
library Comparators {
function lt(uint256 a, uint256 b) internal pure returns (bool) {
return a < b;
}
function gt(uint256 a, uint256 b) internal pure returns (bool) {
return a > b;
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.1) (utils/Context.sol)
pragma solidity ^0.8.20;
/**
* @dev Provides information about the current execution context, including the
* sender of the transaction and its data. While these are generally available
* via msg.sender and msg.data, they should not be accessed in such a direct
* manner, since when dealing with meta-transactions the account sending and
* paying for execution may not be the actual sender (as far as an application
* is concerned).
*
* This contract is only required for intermediate, library-like contracts.
*/
abstract contract Context {
function _msgSender() internal view virtual returns (address) {
return msg.sender;
}
function _msgData() internal view virtual returns (bytes calldata) {
return msg.data;
}
function _contextSuffixLength() internal view virtual returns (uint256) {
return 0;
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (utils/cryptography/ECDSA.sol)
pragma solidity ^0.8.20;
/**
* @dev Elliptic Curve Digital Signature Algorithm (ECDSA) operations.
*
* These functions can be used to verify that a message was signed by the holder
* of the private keys of a given address.
*/
library ECDSA {
enum RecoverError {
NoError,
InvalidSignature,
InvalidSignatureLength,
InvalidSignatureS
}
/**
* @dev The signature derives the `address(0)`.
*/
error ECDSAInvalidSignature();
/**
* @dev The signature has an invalid length.
*/
error ECDSAInvalidSignatureLength(uint256 length);
/**
* @dev The signature has an S value that is in the upper half order.
*/
error ECDSAInvalidSignatureS(bytes32 s);
/**
* @dev Returns the address that signed a hashed message (`hash`) with `signature` or an error. This will not
* return address(0) without also returning an error description. Errors are documented using an enum (error type)
* and a bytes32 providing additional information about the error.
*
* If no error is returned, then the address can be used for verification purposes.
*
* The `ecrecover` EVM precompile allows for malleable (non-unique) signatures:
* this function rejects them by requiring the `s` value to be in the lower
* half order, and the `v` value to be either 27 or 28.
*
* IMPORTANT: `hash` _must_ be the result of a hash operation for the
* verification to be secure: it is possible to craft signatures that
* recover to arbitrary addresses for non-hashed data. A safe way to ensure
* this is by receiving a hash of the original message (which may otherwise
* be too long), and then calling {MessageHashUtils-toEthSignedMessageHash} on it.
*
* Documentation for signature generation:
* - with https://web3js.readthedocs.io/en/v1.3.4/web3-eth-accounts.html#sign[Web3.js]
* - with https://docs.ethers.io/v5/api/signer/#Signer-signMessage[ethers]
*/
function tryRecover(
bytes32 hash,
bytes memory signature
) internal pure returns (address recovered, RecoverError err, bytes32 errArg) {
if (signature.length == 65) {
bytes32 r;
bytes32 s;
uint8 v;
// ecrecover takes the signature parameters, and the only way to get them
// currently is to use assembly.
assembly ("memory-safe") {
r := mload(add(signature, 0x20))
s := mload(add(signature, 0x40))
v := byte(0, mload(add(signature, 0x60)))
}
return tryRecover(hash, v, r, s);
} else {
return (address(0), RecoverError.InvalidSignatureLength, bytes32(signature.length));
}
}
/**
* @dev Returns the address that signed a hashed message (`hash`) with
* `signature`. This address can then be used for verification purposes.
*
* The `ecrecover` EVM precompile allows for malleable (non-unique) signatures:
* this function rejects them by requiring the `s` value to be in the lower
* half order, and the `v` value to be either 27 or 28.
*
* IMPORTANT: `hash` _must_ be the result of a hash operation for the
* verification to be secure: it is possible to craft signatures that
* recover to arbitrary addresses for non-hashed data. A safe way to ensure
* this is by receiving a hash of the original message (which may otherwise
* be too long), and then calling {MessageHashUtils-toEthSignedMessageHash} on it.
*/
function recover(bytes32 hash, bytes memory signature) internal pure returns (address) {
(address recovered, RecoverError error, bytes32 errorArg) = tryRecover(hash, signature);
_throwError(error, errorArg);
return recovered;
}
/**
* @dev Overload of {ECDSA-tryRecover} that receives the `r` and `vs` short-signature fields separately.
*
* See https://eips.ethereum.org/EIPS/eip-2098[ERC-2098 short signatures]
*/
function tryRecover(
bytes32 hash,
bytes32 r,
bytes32 vs
) internal pure returns (address recovered, RecoverError err, bytes32 errArg) {
unchecked {
bytes32 s = vs & bytes32(0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff);
// We do not check for an overflow here since the shift operation results in 0 or 1.
uint8 v = uint8((uint256(vs) >> 255) + 27);
return tryRecover(hash, v, r, s);
}
}
/**
* @dev Overload of {ECDSA-recover} that receives the `r and `vs` short-signature fields separately.
*/
function recover(bytes32 hash, bytes32 r, bytes32 vs) internal pure returns (address) {
(address recovered, RecoverError error, bytes32 errorArg) = tryRecover(hash, r, vs);
_throwError(error, errorArg);
return recovered;
}
/**
* @dev Overload of {ECDSA-tryRecover} that receives the `v`,
* `r` and `s` signature fields separately.
*/
function tryRecover(
bytes32 hash,
uint8 v,
bytes32 r,
bytes32 s
) internal pure returns (address recovered, RecoverError err, bytes32 errArg) {
// EIP-2 still allows signature malleability for ecrecover(). Remove this possibility and make the signature
// unique. Appendix F in the Ethereum Yellow paper (https://ethereum.github.io/yellowpaper/paper.pdf), defines
// the valid range for s in (301): 0 < s < secp256k1n ÷ 2 + 1, and for v in (302): v ∈ {27, 28}. Most
// signatures from current libraries generate a unique signature with an s-value in the lower half order.
//
// If your library generates malleable signatures, such as s-values in the upper range, calculate a new s-value
// with 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141 - s1 and flip v from 27 to 28 or
// vice versa. If your library also generates signatures with 0/1 for v instead 27/28, add 27 to v to accept
// these malleable signatures as well.
if (uint256(s) > 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5D576E7357A4501DDFE92F46681B20A0) {
return (address(0), RecoverError.InvalidSignatureS, s);
}
// If the signature is valid (and not malleable), return the signer address
address signer = ecrecover(hash, v, r, s);
if (signer == address(0)) {
return (address(0), RecoverError.InvalidSignature, bytes32(0));
}
return (signer, RecoverError.NoError, bytes32(0));
}
/**
* @dev Overload of {ECDSA-recover} that receives the `v`,
* `r` and `s` signature fields separately.
*/
function recover(bytes32 hash, uint8 v, bytes32 r, bytes32 s) internal pure returns (address) {
(address recovered, RecoverError error, bytes32 errorArg) = tryRecover(hash, v, r, s);
_throwError(error, errorArg);
return recovered;
}
/**
* @dev Optionally reverts with the corresponding custom error according to the `error` argument provided.
*/
function _throwError(RecoverError error, bytes32 errorArg) private pure {
if (error == RecoverError.NoError) {
return; // no error: do nothing
} else if (error == RecoverError.InvalidSignature) {
revert ECDSAInvalidSignature();
} else if (error == RecoverError.InvalidSignatureLength) {
revert ECDSAInvalidSignatureLength(uint256(errorArg));
} else if (error == RecoverError.InvalidSignatureS) {
revert ECDSAInvalidSignatureS(errorArg);
}
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.3.0) (utils/cryptography/MessageHashUtils.sol)
pragma solidity ^0.8.20;
import {Strings} from "../Strings.sol";
/**
* @dev Signature message hash utilities for producing digests to be consumed by {ECDSA} recovery or signing.
*
* The library provides methods for generating a hash of a message that conforms to the
* https://eips.ethereum.org/EIPS/eip-191[ERC-191] and https://eips.ethereum.org/EIPS/eip-712[EIP 712]
* specifications.
*/
library MessageHashUtils {
/**
* @dev Returns the keccak256 digest of an ERC-191 signed data with version
* `0x45` (`personal_sign` messages).
*
* The digest is calculated by prefixing a bytes32 `messageHash` with
* `"\x19Ethereum Signed Message:\n32"` and hashing the result. It corresponds with the
* hash signed when using the https://ethereum.org/en/developers/docs/apis/json-rpc/#eth_sign[`eth_sign`] JSON-RPC method.
*
* NOTE: The `messageHash` parameter is intended to be the result of hashing a raw message with
* keccak256, although any bytes32 value can be safely used because the final digest will
* be re-hashed.
*
* See {ECDSA-recover}.
*/
function toEthSignedMessageHash(bytes32 messageHash) internal pure returns (bytes32 digest) {
assembly ("memory-safe") {
mstore(0x00, "\x19Ethereum Signed Message:\n32") // 32 is the bytes-length of messageHash
mstore(0x1c, messageHash) // 0x1c (28) is the length of the prefix
digest := keccak256(0x00, 0x3c) // 0x3c is the length of the prefix (0x1c) + messageHash (0x20)
}
}
/**
* @dev Returns the keccak256 digest of an ERC-191 signed data with version
* `0x45` (`personal_sign` messages).
*
* The digest is calculated by prefixing an arbitrary `message` with
* `"\x19Ethereum Signed Message:\n" + len(message)` and hashing the result. It corresponds with the
* hash signed when using the https://ethereum.org/en/developers/docs/apis/json-rpc/#eth_sign[`eth_sign`] JSON-RPC method.
*
* See {ECDSA-recover}.
*/
function toEthSignedMessageHash(bytes memory message) internal pure returns (bytes32) {
return
keccak256(bytes.concat("\x19Ethereum Signed Message:\n", bytes(Strings.toString(message.length)), message));
}
/**
* @dev Returns the keccak256 digest of an ERC-191 signed data with version
* `0x00` (data with intended validator).
*
* The digest is calculated by prefixing an arbitrary `data` with `"\x19\x00"` and the intended
* `validator` address. Then hashing the result.
*
* See {ECDSA-recover}.
*/
function toDataWithIntendedValidatorHash(address validator, bytes memory data) internal pure returns (bytes32) {
return keccak256(abi.encodePacked(hex"19_00", validator, data));
}
/**
* @dev Variant of {toDataWithIntendedValidatorHash-address-bytes} optimized for cases where `data` is a bytes32.
*/
function toDataWithIntendedValidatorHash(
address validator,
bytes32 messageHash
) internal pure returns (bytes32 digest) {
assembly ("memory-safe") {
mstore(0x00, hex"19_00")
mstore(0x02, shl(96, validator))
mstore(0x16, messageHash)
digest := keccak256(0x00, 0x36)
}
}
/**
* @dev Returns the keccak256 digest of an EIP-712 typed data (ERC-191 version `0x01`).
*
* The digest is calculated from a `domainSeparator` and a `structHash`, by prefixing them with
* `\x19\x01` and hashing the result. It corresponds to the hash signed by the
* https://eips.ethereum.org/EIPS/eip-712[`eth_signTypedData`] JSON-RPC method as part of EIP-712.
*
* See {ECDSA-recover}.
*/
function toTypedDataHash(bytes32 domainSeparator, bytes32 structHash) internal pure returns (bytes32 digest) {
assembly ("memory-safe") {
let ptr := mload(0x40)
mstore(ptr, hex"19_01")
mstore(add(ptr, 0x02), domainSeparator)
mstore(add(ptr, 0x22), structHash)
digest := keccak256(ptr, 0x42)
}
}
}// 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.1.0) (utils/ReentrancyGuard.sol)
pragma solidity ^0.8.20;
/**
* @dev Contract module that helps prevent reentrant calls to a function.
*
* Inheriting from `ReentrancyGuard` will make the {nonReentrant} modifier
* available, which can be applied to functions to make sure there are no nested
* (reentrant) calls to them.
*
* Note that because there is a single `nonReentrant` guard, functions marked as
* `nonReentrant` may not call one another. This can be worked around by making
* those functions `private`, and then adding `external` `nonReentrant` entry
* points to them.
*
* TIP: If EIP-1153 (transient storage) is available on the chain you're deploying at,
* consider using {ReentrancyGuardTransient} instead.
*
* TIP: If you would like to learn more about reentrancy and alternative ways
* to protect against it, check out our blog post
* https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul].
*/
abstract contract ReentrancyGuard {
// Booleans are more expensive than uint256 or any type that takes up a full
// word because each write operation emits an extra SLOAD to first read the
// slot's contents, replace the bits taken up by the boolean, and then write
// back. This is the compiler's defense against contract upgrades and
// pointer aliasing, and it cannot be disabled.
// The values being non-zero value makes deployment a bit more expensive,
// but in exchange the refund on every call to nonReentrant will be lower in
// amount. Since refunds are capped to a percentage of the total
// transaction's gas, it is best to keep them low in cases like this one, to
// increase the likelihood of the full refund coming into effect.
uint256 private constant NOT_ENTERED = 1;
uint256 private constant ENTERED = 2;
uint256 private _status;
/**
* @dev Unauthorized reentrant call.
*/
error ReentrancyGuardReentrantCall();
constructor() {
_status = NOT_ENTERED;
}
/**
* @dev Prevents a contract from calling itself, directly or indirectly.
* Calling a `nonReentrant` function from another `nonReentrant`
* function is not supported. It is possible to prevent this from happening
* by making the `nonReentrant` function external, and making it call a
* `private` function that does the actual work.
*/
modifier nonReentrant() {
_nonReentrantBefore();
_;
_nonReentrantAfter();
}
function _nonReentrantBefore() private {
// On the first call to nonReentrant, _status will be NOT_ENTERED
if (_status == ENTERED) {
revert ReentrancyGuardReentrantCall();
}
// Any calls to nonReentrant after this point will fail
_status = ENTERED;
}
function _nonReentrantAfter() private {
// By storing the original value once again, a refund is triggered (see
// https://eips.ethereum.org/EIPS/eip-2200)
_status = NOT_ENTERED;
}
/**
* @dev Returns true if the reentrancy guard is currently set to "entered", which indicates there is a
* `nonReentrant` function in the call stack.
*/
function _reentrancyGuardEntered() internal view returns (bool) {
return _status == ENTERED;
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.3.0) (utils/SlotDerivation.sol)
// This file was procedurally generated from scripts/generate/templates/SlotDerivation.js.
pragma solidity ^0.8.20;
/**
* @dev Library for computing storage (and transient storage) locations from namespaces and deriving slots
* corresponding to standard patterns. The derivation method for array and mapping matches the storage layout used by
* the solidity language / compiler.
*
* See https://docs.soliditylang.org/en/v0.8.20/internals/layout_in_storage.html#mappings-and-dynamic-arrays[Solidity docs for mappings and dynamic arrays.].
*
* Example usage:
* ```solidity
* contract Example {
* // Add the library methods
* using StorageSlot for bytes32;
* using SlotDerivation for bytes32;
*
* // Declare a namespace
* string private constant _NAMESPACE = "<namespace>"; // eg. OpenZeppelin.Slot
*
* function setValueInNamespace(uint256 key, address newValue) internal {
* _NAMESPACE.erc7201Slot().deriveMapping(key).getAddressSlot().value = newValue;
* }
*
* function getValueInNamespace(uint256 key) internal view returns (address) {
* return _NAMESPACE.erc7201Slot().deriveMapping(key).getAddressSlot().value;
* }
* }
* ```
*
* TIP: Consider using this library along with {StorageSlot}.
*
* NOTE: This library provides a way to manipulate storage locations in a non-standard way. Tooling for checking
* upgrade safety will ignore the slots accessed through this library.
*
* _Available since v5.1._
*/
library SlotDerivation {
/**
* @dev Derive an ERC-7201 slot from a string (namespace).
*/
function erc7201Slot(string memory namespace) internal pure returns (bytes32 slot) {
assembly ("memory-safe") {
mstore(0x00, sub(keccak256(add(namespace, 0x20), mload(namespace)), 1))
slot := and(keccak256(0x00, 0x20), not(0xff))
}
}
/**
* @dev Add an offset to a slot to get the n-th element of a structure or an array.
*/
function offset(bytes32 slot, uint256 pos) internal pure returns (bytes32 result) {
unchecked {
return bytes32(uint256(slot) + pos);
}
}
/**
* @dev Derive the location of the first element in an array from the slot where the length is stored.
*/
function deriveArray(bytes32 slot) internal pure returns (bytes32 result) {
assembly ("memory-safe") {
mstore(0x00, slot)
result := keccak256(0x00, 0x20)
}
}
/**
* @dev Derive the location of a mapping element from the key.
*/
function deriveMapping(bytes32 slot, address key) internal pure returns (bytes32 result) {
assembly ("memory-safe") {
mstore(0x00, and(key, shr(96, not(0))))
mstore(0x20, slot)
result := keccak256(0x00, 0x40)
}
}
/**
* @dev Derive the location of a mapping element from the key.
*/
function deriveMapping(bytes32 slot, bool key) internal pure returns (bytes32 result) {
assembly ("memory-safe") {
mstore(0x00, iszero(iszero(key)))
mstore(0x20, slot)
result := keccak256(0x00, 0x40)
}
}
/**
* @dev Derive the location of a mapping element from the key.
*/
function deriveMapping(bytes32 slot, bytes32 key) internal pure returns (bytes32 result) {
assembly ("memory-safe") {
mstore(0x00, key)
mstore(0x20, slot)
result := keccak256(0x00, 0x40)
}
}
/**
* @dev Derive the location of a mapping element from the key.
*/
function deriveMapping(bytes32 slot, uint256 key) internal pure returns (bytes32 result) {
assembly ("memory-safe") {
mstore(0x00, key)
mstore(0x20, slot)
result := keccak256(0x00, 0x40)
}
}
/**
* @dev Derive the location of a mapping element from the key.
*/
function deriveMapping(bytes32 slot, int256 key) internal pure returns (bytes32 result) {
assembly ("memory-safe") {
mstore(0x00, key)
mstore(0x20, slot)
result := keccak256(0x00, 0x40)
}
}
/**
* @dev Derive the location of a mapping element from the key.
*/
function deriveMapping(bytes32 slot, string memory key) internal pure returns (bytes32 result) {
assembly ("memory-safe") {
let length := mload(key)
let begin := add(key, 0x20)
let end := add(begin, length)
let cache := mload(end)
mstore(end, slot)
result := keccak256(begin, add(length, 0x20))
mstore(end, cache)
}
}
/**
* @dev Derive the location of a mapping element from the key.
*/
function deriveMapping(bytes32 slot, bytes memory key) internal pure returns (bytes32 result) {
assembly ("memory-safe") {
let length := mload(key)
let begin := add(key, 0x20)
let end := add(begin, length)
let cache := mload(end)
mstore(end, slot)
result := keccak256(begin, add(length, 0x20))
mstore(end, cache)
}
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (utils/StorageSlot.sol)
// This file was procedurally generated from scripts/generate/templates/StorageSlot.js.
pragma solidity ^0.8.20;
/**
* @dev Library for reading and writing primitive types to specific storage slots.
*
* Storage slots are often used to avoid storage conflict when dealing with upgradeable contracts.
* This library helps with reading and writing to such slots without the need for inline assembly.
*
* The functions in this library return Slot structs that contain a `value` member that can be used to read or write.
*
* Example usage to set ERC-1967 implementation slot:
* ```solidity
* contract ERC1967 {
* // Define the slot. Alternatively, use the SlotDerivation library to derive the slot.
* bytes32 internal constant _IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc;
*
* function _getImplementation() internal view returns (address) {
* return StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value;
* }
*
* function _setImplementation(address newImplementation) internal {
* require(newImplementation.code.length > 0);
* StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value = newImplementation;
* }
* }
* ```
*
* TIP: Consider using this library along with {SlotDerivation}.
*/
library StorageSlot {
struct AddressSlot {
address value;
}
struct BooleanSlot {
bool value;
}
struct Bytes32Slot {
bytes32 value;
}
struct Uint256Slot {
uint256 value;
}
struct Int256Slot {
int256 value;
}
struct StringSlot {
string value;
}
struct BytesSlot {
bytes value;
}
/**
* @dev Returns an `AddressSlot` with member `value` located at `slot`.
*/
function getAddressSlot(bytes32 slot) internal pure returns (AddressSlot storage r) {
assembly ("memory-safe") {
r.slot := slot
}
}
/**
* @dev Returns a `BooleanSlot` with member `value` located at `slot`.
*/
function getBooleanSlot(bytes32 slot) internal pure returns (BooleanSlot storage r) {
assembly ("memory-safe") {
r.slot := slot
}
}
/**
* @dev Returns a `Bytes32Slot` with member `value` located at `slot`.
*/
function getBytes32Slot(bytes32 slot) internal pure returns (Bytes32Slot storage r) {
assembly ("memory-safe") {
r.slot := slot
}
}
/**
* @dev Returns a `Uint256Slot` with member `value` located at `slot`.
*/
function getUint256Slot(bytes32 slot) internal pure returns (Uint256Slot storage r) {
assembly ("memory-safe") {
r.slot := slot
}
}
/**
* @dev Returns a `Int256Slot` with member `value` located at `slot`.
*/
function getInt256Slot(bytes32 slot) internal pure returns (Int256Slot storage r) {
assembly ("memory-safe") {
r.slot := slot
}
}
/**
* @dev Returns a `StringSlot` with member `value` located at `slot`.
*/
function getStringSlot(bytes32 slot) internal pure returns (StringSlot storage r) {
assembly ("memory-safe") {
r.slot := slot
}
}
/**
* @dev Returns an `StringSlot` representation of the string storage pointer `store`.
*/
function getStringSlot(string storage store) internal pure returns (StringSlot storage r) {
assembly ("memory-safe") {
r.slot := store.slot
}
}
/**
* @dev Returns a `BytesSlot` with member `value` located at `slot`.
*/
function getBytesSlot(bytes32 slot) internal pure returns (BytesSlot storage r) {
assembly ("memory-safe") {
r.slot := slot
}
}
/**
* @dev Returns an `BytesSlot` representation of the bytes storage pointer `store`.
*/
function getBytesSlot(bytes storage store) internal pure returns (BytesSlot storage r) {
assembly ("memory-safe") {
r.slot := store.slot
}
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.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)))
}
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.3.0) (utils/structs/EnumerableSet.sol)
// This file was procedurally generated from scripts/generate/templates/EnumerableSet.js.
pragma solidity ^0.8.20;
import {Arrays} from "../Arrays.sol";
/**
* @dev Library for managing
* https://en.wikipedia.org/wiki/Set_(abstract_data_type)[sets] of primitive
* types.
*
* Sets have the following properties:
*
* - Elements are added, removed, and checked for existence in constant time
* (O(1)).
* - Elements are enumerated in O(n). No guarantees are made on the ordering.
* - Set can be cleared (all elements removed) in O(n).
*
* ```solidity
* contract Example {
* // Add the library methods
* using EnumerableSet for EnumerableSet.AddressSet;
*
* // Declare a set state variable
* EnumerableSet.AddressSet private mySet;
* }
* ```
*
* As of v3.3.0, sets of type `bytes32` (`Bytes32Set`), `address` (`AddressSet`)
* and `uint256` (`UintSet`) are supported.
*
* [WARNING]
* ====
* Trying to delete such a structure from storage will likely result in data corruption, rendering the structure
* unusable.
* See https://github.com/ethereum/solidity/pull/11843[ethereum/solidity#11843] for more info.
*
* In order to clean an EnumerableSet, you can either remove all elements one by one or create a fresh instance using an
* array of EnumerableSet.
* ====
*/
library EnumerableSet {
// To implement this library for multiple types with as little code
// repetition as possible, we write it in terms of a generic Set type with
// bytes32 values.
// The Set implementation uses private functions, and user-facing
// implementations (such as AddressSet) are just wrappers around the
// underlying Set.
// This means that we can only create new EnumerableSets for types that fit
// in bytes32.
struct Set {
// Storage of set values
bytes32[] _values;
// Position is the index of the value in the `values` array plus 1.
// Position 0 is used to mean a value is not in the set.
mapping(bytes32 value => uint256) _positions;
}
/**
* @dev Add a value to a set. O(1).
*
* Returns true if the value was added to the set, that is if it was not
* already present.
*/
function _add(Set storage set, bytes32 value) private returns (bool) {
if (!_contains(set, value)) {
set._values.push(value);
// The value is stored at length-1, but we add 1 to all indexes
// and use 0 as a sentinel value
set._positions[value] = set._values.length;
return true;
} else {
return false;
}
}
/**
* @dev Removes a value from a set. O(1).
*
* Returns true if the value was removed from the set, that is if it was
* present.
*/
function _remove(Set storage set, bytes32 value) private returns (bool) {
// We cache the value's position to prevent multiple reads from the same storage slot
uint256 position = set._positions[value];
if (position != 0) {
// Equivalent to contains(set, value)
// To delete an element from the _values array in O(1), we swap the element to delete with the last one in
// the array, and then remove the last element (sometimes called as 'swap and pop').
// This modifies the order of the array, as noted in {at}.
uint256 valueIndex = position - 1;
uint256 lastIndex = set._values.length - 1;
if (valueIndex != lastIndex) {
bytes32 lastValue = set._values[lastIndex];
// Move the lastValue to the index where the value to delete is
set._values[valueIndex] = lastValue;
// Update the tracked position of the lastValue (that was just moved)
set._positions[lastValue] = position;
}
// Delete the slot where the moved value was stored
set._values.pop();
// Delete the tracked position for the deleted slot
delete set._positions[value];
return true;
} else {
return false;
}
}
/**
* @dev Removes all the values from a set. O(n).
*
* WARNING: Developers should keep in mind that this function has an unbounded cost and using it may render the
* function uncallable if the set grows to the point where clearing it consumes too much gas to fit in a block.
*/
function _clear(Set storage set) private {
uint256 len = _length(set);
for (uint256 i = 0; i < len; ++i) {
delete set._positions[set._values[i]];
}
Arrays.unsafeSetLength(set._values, 0);
}
/**
* @dev Returns true if the value is in the set. O(1).
*/
function _contains(Set storage set, bytes32 value) private view returns (bool) {
return set._positions[value] != 0;
}
/**
* @dev Returns the number of values on the set. O(1).
*/
function _length(Set storage set) private view returns (uint256) {
return set._values.length;
}
/**
* @dev Returns the value stored at position `index` in the set. O(1).
*
* Note that there are no guarantees on the ordering of values inside the
* array, and it may change when more values are added or removed.
*
* Requirements:
*
* - `index` must be strictly less than {length}.
*/
function _at(Set storage set, uint256 index) private view returns (bytes32) {
return set._values[index];
}
/**
* @dev Return the entire set in an array
*
* WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
* to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
* this function has an unbounded cost, and using it as part of a state-changing function may render the function
* uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
*/
function _values(Set storage set) private view returns (bytes32[] memory) {
return set._values;
}
// Bytes32Set
struct Bytes32Set {
Set _inner;
}
/**
* @dev Add a value to a set. O(1).
*
* Returns true if the value was added to the set, that is if it was not
* already present.
*/
function add(Bytes32Set storage set, bytes32 value) internal returns (bool) {
return _add(set._inner, value);
}
/**
* @dev Removes a value from a set. O(1).
*
* Returns true if the value was removed from the set, that is if it was
* present.
*/
function remove(Bytes32Set storage set, bytes32 value) internal returns (bool) {
return _remove(set._inner, value);
}
/**
* @dev Removes all the values from a set. O(n).
*
* WARNING: Developers should keep in mind that this function has an unbounded cost and using it may render the
* function uncallable if the set grows to the point where clearing it consumes too much gas to fit in a block.
*/
function clear(Bytes32Set storage set) internal {
_clear(set._inner);
}
/**
* @dev Returns true if the value is in the set. O(1).
*/
function contains(Bytes32Set storage set, bytes32 value) internal view returns (bool) {
return _contains(set._inner, value);
}
/**
* @dev Returns the number of values in the set. O(1).
*/
function length(Bytes32Set storage set) internal view returns (uint256) {
return _length(set._inner);
}
/**
* @dev Returns the value stored at position `index` in the set. O(1).
*
* Note that there are no guarantees on the ordering of values inside the
* array, and it may change when more values are added or removed.
*
* Requirements:
*
* - `index` must be strictly less than {length}.
*/
function at(Bytes32Set storage set, uint256 index) internal view returns (bytes32) {
return _at(set._inner, index);
}
/**
* @dev Return the entire set in an array
*
* WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
* to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
* this function has an unbounded cost, and using it as part of a state-changing function may render the function
* uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
*/
function values(Bytes32Set storage set) internal view returns (bytes32[] memory) {
bytes32[] memory store = _values(set._inner);
bytes32[] memory result;
assembly ("memory-safe") {
result := store
}
return result;
}
// AddressSet
struct AddressSet {
Set _inner;
}
/**
* @dev Add a value to a set. O(1).
*
* Returns true if the value was added to the set, that is if it was not
* already present.
*/
function add(AddressSet storage set, address value) internal returns (bool) {
return _add(set._inner, bytes32(uint256(uint160(value))));
}
/**
* @dev Removes a value from a set. O(1).
*
* Returns true if the value was removed from the set, that is if it was
* present.
*/
function remove(AddressSet storage set, address value) internal returns (bool) {
return _remove(set._inner, bytes32(uint256(uint160(value))));
}
/**
* @dev Removes all the values from a set. O(n).
*
* WARNING: Developers should keep in mind that this function has an unbounded cost and using it may render the
* function uncallable if the set grows to the point where clearing it consumes too much gas to fit in a block.
*/
function clear(AddressSet storage set) internal {
_clear(set._inner);
}
/**
* @dev Returns true if the value is in the set. O(1).
*/
function contains(AddressSet storage set, address value) internal view returns (bool) {
return _contains(set._inner, bytes32(uint256(uint160(value))));
}
/**
* @dev Returns the number of values in the set. O(1).
*/
function length(AddressSet storage set) internal view returns (uint256) {
return _length(set._inner);
}
/**
* @dev Returns the value stored at position `index` in the set. O(1).
*
* Note that there are no guarantees on the ordering of values inside the
* array, and it may change when more values are added or removed.
*
* Requirements:
*
* - `index` must be strictly less than {length}.
*/
function at(AddressSet storage set, uint256 index) internal view returns (address) {
return address(uint160(uint256(_at(set._inner, index))));
}
/**
* @dev Return the entire set in an array
*
* WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
* to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
* this function has an unbounded cost, and using it as part of a state-changing function may render the function
* uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
*/
function values(AddressSet storage set) internal view returns (address[] memory) {
bytes32[] memory store = _values(set._inner);
address[] memory result;
assembly ("memory-safe") {
result := store
}
return result;
}
// UintSet
struct UintSet {
Set _inner;
}
/**
* @dev Add a value to a set. O(1).
*
* Returns true if the value was added to the set, that is if it was not
* already present.
*/
function add(UintSet storage set, uint256 value) internal returns (bool) {
return _add(set._inner, bytes32(value));
}
/**
* @dev Removes a value from a set. O(1).
*
* Returns true if the value was removed from the set, that is if it was
* present.
*/
function remove(UintSet storage set, uint256 value) internal returns (bool) {
return _remove(set._inner, bytes32(value));
}
/**
* @dev Removes all the values from a set. O(n).
*
* WARNING: Developers should keep in mind that this function has an unbounded cost and using it may render the
* function uncallable if the set grows to the point where clearing it consumes too much gas to fit in a block.
*/
function clear(UintSet storage set) internal {
_clear(set._inner);
}
/**
* @dev Returns true if the value is in the set. O(1).
*/
function contains(UintSet storage set, uint256 value) internal view returns (bool) {
return _contains(set._inner, bytes32(value));
}
/**
* @dev Returns the number of values in the set. O(1).
*/
function length(UintSet storage set) internal view returns (uint256) {
return _length(set._inner);
}
/**
* @dev Returns the value stored at position `index` in the set. O(1).
*
* Note that there are no guarantees on the ordering of values inside the
* array, and it may change when more values are added or removed.
*
* Requirements:
*
* - `index` must be strictly less than {length}.
*/
function at(UintSet storage set, uint256 index) internal view returns (uint256) {
return uint256(_at(set._inner, index));
}
/**
* @dev Return the entire set in an array
*
* WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
* to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
* this function has an unbounded cost, and using it as part of a state-changing function may render the function
* uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
*/
function values(UintSet storage set) internal view returns (uint256[] memory) {
bytes32[] memory store = _values(set._inner);
uint256[] memory result;
assembly ("memory-safe") {
result := store
}
return result;
}
}// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.20;
// Importing from @uniswap doesnt work with @openzepplins latest release so this is refactored
// Source: https://github.com/Uniswap/v3-periphery/blob/main/contracts/interfaces/INonfungiblePositionManager.sol
interface INonfungiblePositionManager {
event Transfer(address indexed from, address indexed to, uint256 indexed tokenId);
struct MintParams {
address token0;
address token1;
uint24 fee;
int24 tickLower;
int24 tickUpper;
uint256 amount0Desired;
uint256 amount1Desired;
uint256 amount0Min;
uint256 amount1Min;
address recipient;
uint256 deadline;
}
function mint(
MintParams calldata params
)
external
payable
returns (
uint256 tokenId,
uint128 liquidity,
uint256 amount0,
uint256 amount1
);
struct Position {
uint96 nonce;
address operator;
address token0;
address token1;
uint24 fee;
int24 tickLower;
int24 tickUpper;
uint128 liquidity;
uint256 feeGrowthInside0LastX128;
uint256 feeGrowthInside1LastX128;
uint128 tokensOwed0;
uint128 tokensOwed1;
}
function positions(
uint256 tokenId
)
external
view
returns (
uint96 nonce,
address operator,
address token0,
address token1,
uint24 fee,
int24 tickLower,
int24 tickUpper,
uint128 liquidity,
uint256 feeGrowthInside0LastX128,
uint256 feeGrowthInside1LastX128,
uint128 tokensOwed0,
uint128 tokensOwed1
);
struct IncreaseLiquidityParams {
uint256 tokenId;
uint256 amount0Desired;
uint256 amount1Desired;
uint256 amount0Min;
uint256 amount1Min;
uint256 deadline;
}
/// @notice Increases the amount of liquidity in a position, with tokens paid by the `msg.sender`
/// @param params tokenId The ID of the token for which liquidity is being increased,
/// amount0Desired The desired amount of token0 to be spent,
/// amount1Desired The desired amount of token1 to be spent,
/// amount0Min The minimum amount of token0 to spend, which serves as a slippage check,
/// amount1Min The minimum amount of token1 to spend, which serves as a slippage check,
/// deadline The time by which the transaction must be included to effect the change
/// @return liquidity The new liquidity amount as a result of the increase
/// @return amount0 The amount of token0 to acheive resulting liquidity
/// @return amount1 The amount of token1 to acheive resulting liquidity
function increaseLiquidity(IncreaseLiquidityParams calldata params)
external
payable
returns (
uint128 liquidity,
uint256 amount0,
uint256 amount1
);
struct DecreaseLiquidityParams {
uint256 tokenId;
uint128 liquidity;
uint256 amount0Min;
uint256 amount1Min;
uint256 deadline;
}
/// @notice Decreases the amount of liquidity in a position and accounts it to the position
/// @param params tokenId The ID of the token for which liquidity is being decreased,
/// amount The amount by which liquidity will be decreased,
/// amount0Min The minimum amount of token0 that should be accounted for the burned liquidity,
/// amount1Min The minimum amount of token1 that should be accounted for the burned liquidity,
/// deadline The time by which the transaction must be included to effect the change
/// @return amount0 The amount of token0 accounted to the position's tokens owed
/// @return amount1 The amount of token1 accounted to the position's tokens owed
function decreaseLiquidity(DecreaseLiquidityParams calldata params)
external
payable
returns (uint256 amount0, uint256 amount1);
struct CollectParams {
uint256 tokenId;
address recipient;
uint128 amount0Max;
uint128 amount1Max;
}
function collect(
CollectParams calldata params
) external payable returns (uint256 amount0, uint256 amount1);
function factory() external view returns (address);
function burn(uint256 tokenId) external payable;
function approve(address to, uint256 tokenId) external;
function ownerOf(uint256 tokenId) external view returns (address owner);
function createAndInitializePoolIfNecessary(
address token0,
address token1,
uint24 fee,
uint160 sqrtPriceX96
) external payable returns (address pool);
function safeTransferFrom(
address from,
address to,
uint256 tokenId
) external;
}// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity 0.8.20;
/// @title The interface for the Uniswap V3 Factory
/// @notice The Uniswap V3 Factory facilitates creation of Uniswap V3 pools and control over the protocol fees
interface IUniswapV3Factory {
/// @notice Emitted when the owner of the factory is changed
/// @param oldOwner The owner before the owner was changed
/// @param newOwner The owner after the owner was changed
event OwnerChanged(address indexed oldOwner, address indexed newOwner);
/// @notice Emitted when a pool is created
/// @param token0 The first token of the pool by address sort order
/// @param token1 The second token of the pool by address sort order
/// @param fee The fee collected upon every swap in the pool, denominated in hundredths of a bip
/// @param tickSpacing The minimum number of ticks between initialized ticks
/// @param pool The address of the created pool
event PoolCreated(
address indexed token0,
address indexed token1,
uint24 indexed fee,
int24 tickSpacing,
address pool
);
/// @notice Emitted when a new fee amount is enabled for pool creation via the factory
/// @param fee The enabled fee, denominated in hundredths of a bip
/// @param tickSpacing The minimum number of ticks between initialized ticks for pools created with the given fee
event FeeAmountEnabled(uint24 indexed fee, int24 indexed tickSpacing);
/// @notice Returns the current owner of the factory
/// @dev Can be changed by the current owner via setOwner
/// @return The address of the factory owner
function owner() external view returns (address);
/// @notice Returns the tick spacing for a given fee amount, if enabled, or 0 if not enabled
/// @dev A fee amount can never be removed, so this value should be hard coded or cached in the calling context
/// @param fee The enabled fee, denominated in hundredths of a bip. Returns 0 in case of unenabled fee
/// @return The tick spacing
function feeAmountTickSpacing(uint24 fee) external view returns (int24);
/// @notice Returns the pool address for a given pair of tokens and a fee, or address 0 if it does not exist
/// @dev tokenA and tokenB may be passed in either token0/token1 or token1/token0 order
/// @param tokenA The contract address of either token0 or token1
/// @param tokenB The contract address of the other token
/// @param fee The fee collected upon every swap in the pool, denominated in hundredths of a bip
/// @return pool The pool address
function getPool(
address tokenA,
address tokenB,
uint24 fee
) external view returns (address pool);
/// @notice Creates a pool for the given two tokens and fee
/// @param tokenA One of the two tokens in the desired pool
/// @param tokenB The other of the two tokens in the desired pool
/// @param fee The desired fee for the pool
/// @dev tokenA and tokenB may be passed in either order: token0/token1 or token1/token0. tickSpacing is retrieved
/// from the fee. The call will revert if the pool already exists, the fee is invalid, or the token arguments
/// are invalid.
/// @return pool The address of the newly created pool
function createPool(
address tokenA,
address tokenB,
uint24 fee
) external returns (address pool);
/// @notice Updates the owner of the factory
/// @dev Must be called by the current owner
/// @param _owner The new owner of the factory
function setOwner(address _owner) external;
/// @notice Enables a fee amount with the given tickSpacing
/// @dev Fee amounts may never be removed once enabled
/// @param fee The fee amount to enable, denominated in hundredths of a bip (i.e. 1e-6)
/// @param tickSpacing The spacing between ticks to be enforced for all pools created with the given fee amount
function enableFeeAmount(uint24 fee, int24 tickSpacing) external;
}// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity 0.8.20;
import '@openzeppelin/contracts/token/ERC20/IERC20.sol';
library TransferHelper {
/// @notice Transfers tokens from the targeted address to the given destination
/// @notice Errors with 'STF' if transfer fails
/// @param token The contract address of the token to be transferred
/// @param from The originating address from which the tokens will be transferred
/// @param to The destination address of the transfer
/// @param value The amount to be transferred
function safeTransferFrom(
address token,
address from,
address to,
uint256 value
) internal {
(bool success, bytes memory data) =
token.call(abi.encodeWithSelector(IERC20.transferFrom.selector, from, to, value));
require(success && (data.length == 0 || abi.decode(data, (bool))), 'STF');
}
/// @notice Transfers tokens from msg.sender to a recipient
/// @dev Errors with ST if transfer fails
/// @param token The contract address of the token which will be transferred
/// @param to The recipient of the transfer
/// @param value The value of the transfer
function safeTransfer(
address token,
address to,
uint256 value
) internal {
(bool success, bytes memory data) = token.call(abi.encodeWithSelector(IERC20.transfer.selector, to, value));
require(success && (data.length == 0 || abi.decode(data, (bool))), 'ST');
}
/// @notice Approves the stipulated contract to spend the given allowance in the given token
/// @dev Errors with 'SA' if transfer fails
/// @param token The contract address of the token to be approved
/// @param to The target of the approval
/// @param value The amount of the given token the target will be allowed to spend
function safeApprove(
address token,
address to,
uint256 value
) internal {
(bool success, bytes memory data) = token.call(abi.encodeWithSelector(IERC20.approve.selector, to, value));
require(success && (data.length == 0 || abi.decode(data, (bool))), 'SA');
}
/// @notice Transfers ETH to the recipient address
/// @dev Fails with `STE`
/// @param to The destination of the transfer
/// @param value The value to be transferred
function safeTransferETH(address to, uint256 value) internal {
(bool success, ) = to.call{value: value}(new bytes(0));
require(success, 'STE');
}
}{
"optimizer": {
"enabled": true,
"runs": 1000
},
"evmVersion": "paris",
"viaIR": true,
"outputSelection": {
"*": {
"*": [
"evm.bytecode",
"evm.deployedBytecode",
"devdoc",
"userdoc",
"metadata",
"abi"
]
}
}
}Contract Security Audit
- No Contract Security Audit Submitted- Submit Audit Here
Contract ABI
API[{"inputs":[{"internalType":"address","name":"nftManager_","type":"address"},{"internalType":"address","name":"feeReceiver_","type":"address"},{"internalType":"address","name":"customFeeSigner_","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[],"name":"ECDSAInvalidSignature","type":"error"},{"inputs":[{"internalType":"uint256","name":"length","type":"uint256"}],"name":"ECDSAInvalidSignatureLength","type":"error"},{"inputs":[{"internalType":"bytes32","name":"s","type":"bytes32"}],"name":"ECDSAInvalidSignatureS","type":"error"},{"inputs":[{"internalType":"address","name":"owner","type":"address"}],"name":"OwnableInvalidOwner","type":"error"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"OwnableUnauthorizedAccount","type":"error"},{"inputs":[],"name":"ReentrancyGuardReentrantCall","type":"error"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"bytes32","name":"nameHash","type":"bytes32"},{"indexed":false,"internalType":"string","name":"name","type":"string"},{"indexed":false,"internalType":"uint256","name":"lpFee","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"collectFee","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"lockFee","type":"uint256"},{"indexed":false,"internalType":"address","name":"lockFeeToken","type":"address"}],"name":"OnAddFee","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"nftManger","type":"address"}],"name":"OnAddNftManger","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"lockId","type":"uint256"}],"name":"OnDecreaseLiquidity","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"bytes32","name":"nameHash","type":"bytes32"},{"indexed":false,"internalType":"string","name":"name","type":"string"},{"indexed":false,"internalType":"uint256","name":"lpFee","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"collectFee","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"lockFee","type":"uint256"},{"indexed":false,"internalType":"address","name":"lockFeeToken","type":"address"}],"name":"OnEditFee","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"oldReceiver","type":"address"},{"indexed":false,"internalType":"address","name":"newReceiver","type":"address"}],"name":"OnFeeReceiverUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"oldSigner","type":"address"},{"indexed":false,"internalType":"address","name":"newSigner","type":"address"}],"name":"OnFeeSignerUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"lockId","type":"uint256"}],"name":"OnIncreaseLiquidity","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"lockId","type":"uint256"},{"indexed":false,"internalType":"address","name":"nftPositionManager","type":"address"},{"indexed":false,"internalType":"address","name":"owner","type":"address"},{"indexed":false,"internalType":"uint256","name":"nftId","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"endTime","type":"uint256"}],"name":"OnLock","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"lockId","type":"uint256"},{"indexed":false,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":false,"internalType":"address","name":"newOwner","type":"address"}],"name":"OnLockPendingTransfer","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"lockId","type":"uint256"},{"indexed":false,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":false,"internalType":"address","name":"newOwner","type":"address"}],"name":"OnLockTransferred","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"lockId","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"endTime","type":"uint256"}],"name":"OnRelock","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"bytes32","name":"nameHash","type":"bytes32"}],"name":"OnRemoveFee","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"lockId","type":"uint256"},{"indexed":false,"internalType":"address","name":"collector","type":"address"}],"name":"OnSetCollector","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"bytes","name":"sig","type":"bytes"}],"name":"OnSignatureDisabled","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"lockId","type":"uint256"},{"indexed":false,"internalType":"address","name":"owner","type":"address"},{"indexed":false,"internalType":"uint256","name":"nftId","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"unlockedTime","type":"uint256"}],"name":"OnUnlock","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"},{"inputs":[],"name":"FEE_DENOMINATOR","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"lockId_","type":"uint256"}],"name":"acceptLock","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"string","name":"name_","type":"string"},{"internalType":"uint256","name":"lpFee_","type":"uint256"},{"internalType":"uint256","name":"collectFee_","type":"uint256"},{"internalType":"uint256","name":"lockFee_","type":"uint256"},{"internalType":"address","name":"lockFeeToken_","type":"address"}],"name":"addOrUpdateFee","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"nftManager_","type":"address"}],"name":"addSupportedNftManager","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"token_","type":"address"},{"internalType":"address","name":"receiver_","type":"address"},{"internalType":"uint256","name":"amount_","type":"uint256"}],"name":"adminRefundERC20","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"amount_","type":"uint256"},{"internalType":"address payable","name":"receiver_","type":"address"}],"name":"adminRefundEth","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"lockId_","type":"uint256"},{"internalType":"address","name":"recipient_","type":"address"},{"internalType":"uint128","name":"amount0Max_","type":"uint128"},{"internalType":"uint128","name":"amount1Max_","type":"uint128"}],"name":"collect","outputs":[{"internalType":"uint256","name":"amount0","type":"uint256"},{"internalType":"uint256","name":"amount1","type":"uint256"},{"internalType":"uint256","name":"fee0","type":"uint256"},{"internalType":"uint256","name":"fee1","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"customFeeSigner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"lockId_","type":"uint256"},{"components":[{"internalType":"uint256","name":"tokenId","type":"uint256"},{"internalType":"uint128","name":"liquidity","type":"uint128"},{"internalType":"uint256","name":"amount0Min","type":"uint256"},{"internalType":"uint256","name":"amount1Min","type":"uint256"},{"internalType":"uint256","name":"deadline","type":"uint256"}],"internalType":"struct INonfungiblePositionManager.DecreaseLiquidityParams","name":"params","type":"tuple"}],"name":"decreaseLiquidity","outputs":[{"internalType":"uint256","name":"amount0","type":"uint256"},{"internalType":"uint256","name":"amount1","type":"uint256"}],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"bytes","name":"sig","type":"bytes"}],"name":"disableSig","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes","name":"","type":"bytes"}],"name":"disabledSigs","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"feeReceiver","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"nameHash","type":"bytes32"}],"name":"fees","outputs":[{"internalType":"string","name":"name","type":"string"},{"internalType":"uint256","name":"lpFee","type":"uint256"},{"internalType":"uint256","name":"collectFee","type":"uint256"},{"internalType":"uint256","name":"lockFee","type":"uint256"},{"internalType":"address","name":"lockFeeToken","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"string","name":"name_","type":"string"}],"name":"getFee","outputs":[{"components":[{"internalType":"string","name":"name","type":"string"},{"internalType":"uint256","name":"lpFee","type":"uint256"},{"internalType":"uint256","name":"collectFee","type":"uint256"},{"internalType":"uint256","name":"lockFee","type":"uint256"},{"internalType":"address","name":"lockFeeToken","type":"address"}],"internalType":"struct UniV3LPLocker.FeeStruct","name":"","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"user","type":"address"}],"name":"getUserLocks","outputs":[{"internalType":"uint256[]","name":"lockIds","type":"uint256[]"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"lockId_","type":"uint256"},{"components":[{"internalType":"uint256","name":"tokenId","type":"uint256"},{"internalType":"uint256","name":"amount0Desired","type":"uint256"},{"internalType":"uint256","name":"amount1Desired","type":"uint256"},{"internalType":"uint256","name":"amount0Min","type":"uint256"},{"internalType":"uint256","name":"amount1Min","type":"uint256"},{"internalType":"uint256","name":"deadline","type":"uint256"}],"internalType":"struct INonfungiblePositionManager.IncreaseLiquidityParams","name":"params","type":"tuple"}],"name":"increaseLiquidity","outputs":[{"internalType":"uint128","name":"liquidity","type":"uint128"},{"internalType":"uint256","name":"amount0","type":"uint256"},{"internalType":"uint256","name":"amount1","type":"uint256"}],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"string","name":"name_","type":"string"}],"name":"isSupportedFeeName","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"contract INonfungiblePositionManager","name":"nftManager_","type":"address"},{"internalType":"uint256","name":"nftId_","type":"uint256"},{"internalType":"address","name":"owner_","type":"address"},{"internalType":"address","name":"collector_","type":"address"},{"internalType":"uint256","name":"endTime_","type":"uint256"},{"internalType":"string","name":"feeName_","type":"string"}],"name":"lock","outputs":[{"internalType":"uint256","name":"lockId","type":"uint256"}],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"contract INonfungiblePositionManager","name":"nftManager_","type":"address"},{"internalType":"uint256","name":"nftId_","type":"uint256"},{"internalType":"address","name":"owner_","type":"address"},{"internalType":"address","name":"collector_","type":"address"},{"internalType":"uint256","name":"endTime_","type":"uint256"},{"internalType":"bytes","name":"signature_","type":"bytes"},{"components":[{"internalType":"string","name":"name","type":"string"},{"internalType":"uint256","name":"lpFee","type":"uint256"},{"internalType":"uint256","name":"collectFee","type":"uint256"},{"internalType":"uint256","name":"lockFee","type":"uint256"},{"internalType":"address","name":"lockFeeToken","type":"address"}],"internalType":"struct UniV3LPLocker.FeeStruct","name":"feeObj_","type":"tuple"}],"name":"lockWithCustomFee","outputs":[{"internalType":"uint256","name":"lockId","type":"uint256"}],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"uint256","name":"lockId","type":"uint256"}],"name":"locks","outputs":[{"internalType":"uint256","name":"lockId","type":"uint256"},{"internalType":"contract INonfungiblePositionManager","name":"nftPositionManager","type":"address"},{"internalType":"address","name":"pendingOwner","type":"address"},{"internalType":"address","name":"owner","type":"address"},{"internalType":"address","name":"collector","type":"address"},{"internalType":"address","name":"pool","type":"address"},{"internalType":"uint256","name":"collectFee","type":"uint256"},{"internalType":"uint256","name":"nftId","type":"uint256"},{"internalType":"uint256","name":"startTime","type":"uint256"},{"internalType":"uint256","name":"endTime","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"nextLockId","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"operator","type":"address"},{"internalType":"address","name":"from","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"},{"internalType":"bytes","name":"data","type":"bytes"}],"name":"onERC721Received","outputs":[{"internalType":"bytes4","name":"","type":"bytes4"}],"stateMutability":"pure","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"lockId_","type":"uint256"},{"internalType":"uint256","name":"endTime_","type":"uint256"}],"name":"relock","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"string","name":"name_","type":"string"}],"name":"removeFee","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"renounceOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"lockId_","type":"uint256"},{"internalType":"address","name":"collector_","type":"address"}],"name":"setCollectAddress","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"nftManager_","type":"address"}],"name":"supportedNftManager","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"lockId_","type":"uint256"},{"internalType":"address","name":"newOwner_","type":"address"}],"name":"transferLock","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"lockId_","type":"uint256"}],"name":"unlock","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"feeReceiver_","type":"address"}],"name":"updateFeeReceiver","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"feeSigner_","type":"address"}],"name":"updateFeeSigner","outputs":[],"stateMutability":"nonpayable","type":"function"}]Contract Creation Code
608080604052346200090f57606081620053ff80380380916200002382856200094c565b8339810103126200090f57620000398162000970565b906200005660406200004e6020840162000970565b920162000970565b913315620008f65760008054336001600160a01b0319821681178355916001600160a01b03909116907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09080a360018080556007556001600160a01b031680620008e3575b50600580546001600160a01b039283166001600160a01b03199182161790915560068054939092169216919091179055604051620000f98162000930565b6007815260208101661111519055531560ca1b81523360018060a01b036000541603620006b95762000141906200014f60206040518093828201958691885192839162000a98565b81010380845201826200094c565b51902090604051620001618162000914565b8181526028602082015260a0604082015260006060820152600060808201528260005260046020526040600020815180519060018060401b038211620006a3578254600181811c91168015620008d8575b60208210146200068257601f81116200088f575b50602090601f83116001146200081d5760049392916000918362000811575b50508160011b916000199060031b1c19161781555b6020830151600182015560408301516002820155606083015160038201550190608060018060a01b039101511660018060a01b03198254161790556200024d826000526003602052604060002054151590565b15620007da57600080516020620053bf83398151915291620002756040519283928362000abd565b0390a15b604051620002878162000930565b60038152602081016204c56560ec1b81523360018060a01b036000541603620006b9576200014190620002cb60206040518093828201958691885192839162000a98565b51902090604051620002dd8162000914565b818152604060208201526050604082015260006060820152600060808201528260005260046020526040600020815180519060018060401b038211620006a3578254600181811c91168015620007cf575b60208210146200068257601f811162000786575b50602090601f8311600114620007145760049392916000918362000708575b50508160011b916000199060031b1c19161781555b6020830151600182015560408301516002820155606083015160038201550190608060018060a01b039101511660018060a01b0319825416179055620003c9826000526003602052604060002054151590565b15620006d157600080516020620053bf83398151915291620003f16040519283928362000b0d565b0390a15b604051620004038162000930565b60038152602081016204c4c560ec1b81523360018060a01b036000541603620006b95762000141906200044760206040518093828201958691885192839162000a98565b51902090604051620004598162000914565b81815260186020820152610118604082015260006060820152600060808201528260005260046020526040600020815180519060018060401b038211620006a3578254600181811c9116801562000698575b60208210146200068257601f811162000635575b50602090601f8311600114620005c557600493929160009183620005b9575b50508160011b916000199060031b1c19161781555b6020830151600182015560408301516002820155606083015160038201550190608060018060a01b039101511660018060a01b031982541617905562000546826000526003602052604060002054151590565b156200058257600080516020620053bf833981519152916200056e6040519283928362000b5d565b0390a15b60405161480f908162000bb08239f35b816200059e600080516020620053df8339815191529362000a25565b50620005b06040519283928362000b5d565b0390a162000572565b015190503880620004de565b90601f198316918460005260206000209260005b8181106200061c575091600193918560049796941062000602575b505050811b018155620004f3565b015160001960f88460031b161c19169055388080620005f4565b92936020600181928786015181550195019301620005d9565b836000526020600020601f840160051c8101916020851062000677575b601f0160051c01905b8181106200066a5750620004bf565b600081556001016200065b565b909150819062000652565b634e487b7160e01b600052602260045260246000fd5b90607f1690620004ab565b634e487b7160e01b600052604160045260246000fd5b60405163118cdaa760e01b8152336004820152602490fd5b81620006ed600080516020620053df8339815191529362000a25565b50620006ff6040519283928362000b0d565b0390a1620003f5565b01519050388062000361565b908360005260206000209160005b601f19851681106200076d575091839160019360049695601f1981161062000753575b505050811b01815562000376565b015160001960f88460031b161c1916905538808062000745565b9192602060018192868501518155019401920162000722565b836000526020600020601f840160051c810160208510620007c7575b601f830160051c82018110620007ba57505062000342565b60008155600101620007a2565b5080620007a2565b90607f16906200032e565b81620007f6600080516020620053df8339815191529362000a25565b50620008086040519283928362000abd565b0390a162000279565b015190503880620001e5565b908360005260206000209160005b601f198516811062000876575091839160019360049695601f198116106200085c575b505050811b018155620001fa565b015160001960f88460031b161c191690553880806200084e565b919260206001819286850151815501940192016200082b565b836000526020600020601f840160051c810160208510620008d0575b601f830160051c82018110620008c3575050620001c6565b60008155600101620008ab565b5080620008ab565b90607f1690620001b2565b620008ee9062000985565b5038620000bb565b604051631e4fbdf760e01b815260006004820152602490fd5b600080fd5b60a081019081106001600160401b03821117620006a357604052565b604081019081106001600160401b03821117620006a357604052565b601f909101601f19168101906001600160401b03821190821017620006a357604052565b51906001600160a01b03821682036200090f57565b60008181526009602052604081205462000a20576008546801000000000000000081101562000a0c576001810180600855811015620009f8577ff3f7a9fe364faab93b216da50a3214154f22a0a2b415b23a84c8169e8b636ee30182905560085491815260096020526040902055600190565b634e487b7160e01b82526032600452602482fd5b634e487b7160e01b82526041600452602482fd5b905090565b60008181526003602052604081205462000a20576002546801000000000000000081101562000a0c576001810180600255811015620009f8577f405787fa12a823e0f2b7631cc41b3ba8828b3321ca811111fa75cd3aa3bb5ace0182905560025491815260036020526040902055600190565b60005b83811062000aac5750506000910152565b818101518382015260200162000a9b565b929160e060a091600093865260c0602087015262000aeb815180928160c08a01526020858a01910162000a98565b601f801991011685010193602860408201528160608201528260808201520152565b929160e060a091600093865260c0602087015262000b3b815180928160c08a01526020858a01910162000a98565b601f801991011685010193604080820152605060608201528260808201520152565b929160e060a091600093865260c0602087015262000b8b815180928160c08a01526020858a01910162000a98565b601f801991011685010193601860408201526101186060820152826080820152015256fe6080604052600436101561001257600080fd5b6000803560e01c806306f9b07a14612ff0578063093cf39114612eb65780630d12033114612e8f578063100fc94314612be6578063150b7a0214612b6357806317d616a014612b27578063186941551461268557806323a35de9146125d75780632473a6b214612574578063260e12b014611fa5578063280f386714611f605780636198e3391461180c5780636518a0b3146117ee5780636850cb241461174c5780636ec3af85146114c5578063715018a61461146b57806387d8de3d1461136d5780638da5cb5b14611347578063ab9ae180146112aa578063b08348931461122f578063b2fb30cb14611102578063b3f00674146110db578063b48dd3be1461101b578063b707a28814610f29578063c69bebe414610eae578063cdb5661f14610e34578063d5fdb73214610c3a578063d73792a914610c1d578063ed1eee6814610b90578063f0582e1414610b4b578063f11478f8146102cf578063f2fde38b1461022e5763f4dadc611461018857600080fd5b3461022b57602036600319011261022b576040610140916004358152600a602052208054906001600160a01b03908160018201541691806002830154169080600384015416908060048501541690600585015416906006850154926007860154946009600888015497015497604051998a5260208a015260408901526060880152608087015260a086015260c085015260e0840152610100830152610120820152f35b80fd5b503461022b57602036600319011261022b57610248613052565b6102506132d6565b6001600160a01b0380911690811561029e57600054826001600160a01b0319821617600055167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0600080a380f35b602483604051907f1e4fbdf70000000000000000000000000000000000000000000000000000000082526004820152fd5b5060c036600319011261022b5760a036602319011261022b576102f7600754600435106143ae565b6004358152600a60205261031c6001600160a01b0360036040842001541633146143f9565b61032461448f565b6004358152600a602052604081209060405161033f816130c6565b825481526001600160a01b0360018401541660208201526001600160a01b0360028401541660408201526001600160a01b0360038401541660608201526001600160a01b0360048401541660808201526001600160a01b0360058401541660a0820152600683015460c08201526007830154928360e08301526009600882015491610100928385015201546103e06101209586850192835260243514614444565b51421115610b0757600435600052600a602052604060002060405194610405866130c6565b815486526001600160a01b0360018301541660208701526001600160a01b03600283015416604087015260096001600160a01b03600384015416928360608901526001600160a01b03600482015416948560808a01526001600160a01b0360058301541660a08a0152600682015460c08a0152600782015460e08a01526008820154908901520154908601523314908115610afd575b5015610ab95760c08301516107415760406105418460e06001600160a01b036020600097980151169101518351906104d2826130f7565b81523360208201526001600160801b0380858301526060820152835195868094819363fc6f786560e01b83526004830191909160606080820193805183526001600160a01b036020820151166020840152816001600160801b0391826040820151166040860152015116910152565b03925af1918215610735578392610717575b505b6001600160a01b0360208201511660405190630624e65f60e11b8252602435600483015260408260a481876001600160801b0395866105926131bb565b16602484015260643560448401526084356064840152833560848401525af192831561070c57849285946106df575b50604091816001600160a01b03602061065d94015116916001600160a01b03606060e0840151930151168551926105f7846130f7565b8352602083015280858301526060820152835197888094819363fc6f786560e01b83526004830191909160606080820193805183526001600160a01b036020820151166020840152816001600160801b0391826040820151166040860152015116910152565b03925af19384156106d4576040946106a8575b508351927fabcec736cf7ffb1e2406a7d4f50174d68847773bd8bf43d6f9ee131a24121a7d6004359180a26001805582526020820152f35b6106c790853d87116106cd575b6106bf8183613113565b810190613af7565b50610670565b503d6106b5565b6040513d85823e3d90fd5b61065d919450604092935061070090833d85116106cd576106bf8183613113565b939093949150916105c1565b6040513d86823e3d90fd5b61072f9060403d6040116106cd576106bf8183613113565b50610553565b6040513d6000823e3d90fd5b6001600160a01b0360208401511661018060e085015160246040518094819363133f757160e31b835260048301525afa8015610735576000918291610a79575b50604051946370a0823160e01b86523060048701526020866024816001600160a01b0387165afa95861561073557600096610a45575b50604051956370a0823160e01b87523060048801526020876024816001600160a01b0387165afa96871561073557600097610a11575b50600060406108836001600160a01b0360208601511660e0860151835190610814826130f7565b81523060208201526001600160801b0380858301526060820152835194858094819363fc6f786560e01b83526004830191909160606080820193805183526001600160a01b036020820151166020840152816001600160801b0391826040820151166040860152015116910152565b03925af18015610735576109f3575b506040516370a0823160e01b81523060048201526020816024816001600160a01b0389165afa908115610735576000916109bf575b50906108d291613576565b6040516370a0823160e01b81523060048201526020816024816001600160a01b0388165afa9081156107355760009161098d575b50869761091291613576565b938161096e575b505082610929575b505050610555565b6109669261271061094160c061095e9401518361354d565b0490610959826001600160a01b03600554168661460f565b613576565b90339061460f565b388080610921565b61095e6109869261271061094160c08701518361354d565b3880610919565b906020823d6020116109b7575b816109a760209383613113565b8101031261022b57505186610906565b3d915061099a565b906020823d6020116109eb575b816109d960209383613113565b8101031261022b5750516108d26108c7565b3d91506109cc565b610a0b9060403d6040116106cd576106bf8183613113565b50610892565b90966020823d602011610a3d575b81610a2c60209383613113565b8101031261022b57505195386107ed565b3d9150610a1f565b90956020823d602011610a71575b81610a6060209383613113565b8101031261022b57505194386107b7565b3d9150610a53565b9050610a9f91506101803d61018011610ab2575b610a978183613113565b810190614301565b5050505050505050925090509038610781565b503d610a8d565b606460405162461bcd60e51b815260206004820152600960248201527f4e6f74206f776e657200000000000000000000000000000000000000000000006044820152fd5b905033143861049b565b606460405162461bcd60e51b815260206004820152600760248201527f4e4f5420594554000000000000000000000000000000000000000000000000006044820152fd5b503461022b57602036600319011261022b576020610b866001600160a01b03610b72613052565b166000526009602052604060002054151590565b6040519015158152f35b503461022b57602036600319011261022b576004359067ffffffffffffffff821161022b57610bca610bc53660048501613151565b613797565b6040518091602082526001600160a01b036080610bf3835160a0602087015260c08601906132b1565b92602081015160408601526040810151606086015260608101518286015201511660a08301520390f35b503461022b578060031936011261022b5760206040516127108152f35b503461022b57602080600319360112610e305767ffffffffffffffff600435818111610e2c57610c6e903690600401613151565b610c766132d6565b604051610c9f848281610c928183019687815193849201613198565b8101038084520182613113565b51902090604051838101907f44454641554c54000000000000000000000000000000000000000000000000009182815260078252604082019382851090851117610e165783604052815190208414610df65750505080835260038252604083205415610db2579081610d317fb2c474098bd86300759342af0b60dbf39dcf9552246e0b7ffd3c19a4e3e9060593613583565b50808452600482528360046040822082610d4b82546131d1565b80610d74575b50506000600182015560006002820155600060038201550155604051908152a180f35b601f8111600114610d8d575050600081555b8238610d51565b828252610da8601f888420920160051c82016001830161331a565b6000835555610d86565b6064826040519062461bcd60e51b82526004820152600e60248201527f466565206e6f74206578697374730000000000000000000000000000000000006044820152fd5b606493506084908562461bcd60e51b855260448201526007858201520152fd5b634e487b7160e01b600052604160045260246000fd5b8380fd5b5080fd5b503461022b57602036600319011261022b576040610e95916004358152600460205220610e608161320b565b906001810154906002810154906001600160a01b0360046003830154920154169160405195869560a0875260a08701906132b1565b9360208601526040850152606084015260808301520390f35b503461022b57602036600319011261022b57610ec8613052565b610ed06132d6565b600554604080516001600160a01b038084168252848116602083015292936001600160a01b0319939290917f02cbe864dd291b617018e5a2181cfd770c54bf3fba21fc323434c694b3b2ad1f9190a11691161760055580f35b503461022b57604036600319011261022b57600435610f46613068565b610f5360075483106143ae565b818352600a6020526001600160a01b0390610f788260036040872001541633146143f9565b610f8061448f565b168015610fd75760207fbf72678a283f17a2d52bd1bd823f5fcd1f921056005db4c2ac6e29f88da5b75491838552600a825260046040862001816001600160a01b0319825416179055604051908152a26001805580f35b606460405162461bcd60e51b815260206004820152600c60248201527f434f4c4c4543545f4144445200000000000000000000000000000000000000006044820152fd5b503461022b57604036600319011261022b576004357f2ab916445cd7f71b7d22f037187a5e1b6086c455fa944619946ca72b62030ca26110d561105c613068565b61106960075485106143ae565b838552600a6020526001600160a01b0361108d8160036040892001541633146143f9565b848652600a602052600260408720019082166001600160a01b031982541617905560405191829133839060209093929360408301946001600160a01b03809216845216910152565b0390a280f35b503461022b578060031936011261022b5760206001600160a01b0360055416604051908152f35b503461022b57604036600319011261022b5760043560243561112760075483106143ae565b818352600a60205261114a6001600160a01b0360036040862001541633146143f9565b61115261448f565b818352600a6020526009604084200180548211156111eb57428211156111a757817f34fc5c313b2fd97c2b528805434c6cb36ab482f72af6117a52208cf18874fdf49260209255604051908152a26001805580f35b606460405162461bcd60e51b815260206004820152600e60248201527f456e6454696d65203c3d206e6f770000000000000000000000000000000000006044820152fd5b606460405162461bcd60e51b815260206004820152601960248201527f456e6454696d65203c3d2063757272656e74456e645469656d000000000000006044820152fd5b503461022b57602036600319011261022b57611249613052565b6112516132d6565b600654604080516001600160a01b038084168252848116602083015292936001600160a01b0319939290917f32e004fe7121682349ed511e2414e25e6dc53f3a6db355f0af4724b4dc17c8109190a11691161760065580f35b503461022b57604036600319011261022b57806024356001600160a01b03811680910361134457818080926112dd6132d6565b6112e561448f565b600435905af16112f36144ca565b5015611300576001805580f35b606460405162461bcd60e51b815260206004820152601960248201527f47617320746f6b656e207472616e73666572206661696c6564000000000000006044820152fd5b50fd5b503461022b578060031936011261022b576001600160a01b036020915416604051908152f35b5060c036600319011261022b57611382613052565b9061138b61307e565b91611394613094565b916084359060a4359067ffffffffffffffff821161022b57506113bb903690600401613151565b926001600160a01b03946113d28683161515613888565b6113dd4284116138d3565b6113e68561375d565b156114275761141561141f95610bc561141060209988166000526009602052604060002054151590565b61391e565b9360243590613b0d565b604051908152f35b606460405162461bcd60e51b815260206004820152600f60248201527f4665654e616d6520696e76616c696400000000000000000000000000000000006044820152fd5b503461022b578060031936011261022b576114846132d6565b60006001600160a01b0381546001600160a01b031981168355167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e08280a380f35b506003199060e03683011261022b576114dc613052565b916114e561307e565b6114ed613094565b6084359160a4359367ffffffffffffffff9485811161174857611514903690600401613151565b60c435918683116117445760a09083360301126117485760405195611538876130aa565b8260040135908111611744576115549060043691850101613151565b86526020968787019260248101358452604088019360448201358552608460608a0192606481013584520135946001600160a01b0395868116810361173f5760808b019081526115ba611410888f610b728e6115b38f85161515613888565b42106138d3565b60ff6040518d81816115d28b83815193849201613198565b8101600c81520301902054166116fb5761169d96959361166560c8603c958f94958f966116949a975192519151955190519060405196879461162d8a87019a468c523360601b6040890152825192839160548a019101613198565b8501936054850152607484015260948301526bffffffffffffffffffffffff199060601b1660b48201520360a8810184520182613113565b5190207f19457468657265756d205369676e6564204d6573736167653a0a3332000000008252601c5220613969565b90939193613a29565b80600654169116036116b75761141f949560243590613b0d565b6064856040519062461bcd60e51b82526004820152601560248201527f4665655369676e6572206e6f7420616c6c6f77656400000000000000000000006044820152fd5b60648c6040519062461bcd60e51b82526004820152601260248201527f5369676e61747572652064697361626c656400000000000000000000000000006044820152fd5b600080fd5b8780fd5b8680fd5b503461022b57602036600319011261022b5760043567ffffffffffffffff8111610e30576117e86117a27fc19cc6d72b61c6ab50ce499b71c09e6c79b65906c65247abc661980f5e142b22923690600401613151565b6117aa6132d6565b60405160208183516117bf8183858801613198565b8101600c815203019020600160ff198254161790556040519182916020835260208301906132b1565b0390a180f35b503461022b578060031936011261022b576020600754604051908152f35b503461022b57602036600319011261022b5761182d600754600435106143ae565b6004358152600a6020526118526001600160a01b0360036040842001541633146143f9565b6004358152600a60205260408120906040519161186e836130c6565b805483526001600160a01b0360018201541660208401526001600160a01b0360028201541660408401526001600160a01b0360038201541660608401526001600160a01b0360048201541660808401526001600160a01b0360058201541660a0840152600681015460c0840152600781015460e0840152600960088201549161010092838601520154610120908082860152421115611f1c576001600160a01b03606085015116916004358452600a6020526040842060405192611931846130c6565b815484526001600160a01b0360018301541660208501526001600160a01b03600283015416604085015260096001600160a01b03600384015416928360608701526001600160a01b03600482015416948560808801526001600160a01b0360058301541660a0880152600682015460c0880152600782015460e08801526008820154908701520154908401523314908115611f12575b5015610ab957829160c082015115600014611be55781611a719160e06001600160a01b03602060409601511692015190845191611a03836130f7565b825260208201526001600160801b0380858301526060820152835194858094819363fc6f786560e01b83526004830191909160606080820193805183526001600160a01b036020820151166020840152816001600160801b0391826040820151166040860152015116910152565b03925af18015611bbc57611bc7575b505b6001600160a01b036020830151166001600160a01b036060840151169060e084015191813b15610e2c57604051632142170760e11b81523060048201526001600160a01b03919091166024820152604481019290925282908290606490829084905af18015611bbc57611bad575b50906001600160a01b036060820151168252600b602052611b166004356040842061366d565b5060e06001600160a01b0360608301511691015160405191825260208201524260408201527f462608836dd129ef58f79f0a556fe285515f86287c758ea37a6d2f0a052e3f9d606060043592a26004358152600a6020526000600960408320828155836001820155836002820155836003820155836004820155836005820155826006820155826007820155826008820155015580f35b611bb6906130e3565b38611af0565b6040513d84823e3d90fd5b611bdf9060403d6040116106cd576106bf8183613113565b50611a80565b91506001600160a01b036020820151169160e08201519160405193849363133f757160e31b855260048501528360246101809687935afa928315611f075785948694611ed5575b50506040516370a0823160e01b81523060048201526020816024816001600160a01b0389165afa908115611eca578691611e94575b50604051906370a0823160e01b82523060048301526020826024816001600160a01b0389165afa918215611e89578792611e55575b50866040611cbc6001600160a01b0360208701511660e0870151835190610814826130f7565b03925af18015611df657611e37575b50604051906370a0823160e01b82523060048301526020826024816001600160a01b038b165afa8015611df6578890611e01575b611d099250613576565b90604051906370a0823160e01b82523060048301526020826024816001600160a01b038a165afa8015611df6578890611dc0575b611d479250613576565b948382611da0575b50505083611d61575b50505050611a82565b611d9793612710611d7960c0611d919401518361354d565b0490610959826001600160a01b03600554168761460f565b9161460f565b38808080611d58565b611d91611db893612710611d7960c08801518361354d565b388083611d4f565b50906020813d602011611dee575b81611ddb60209383613113565b810103126117445790611d479151611d3d565b3d9150611dce565b6040513d8a823e3d90fd5b50906020813d602011611e2f575b81611e1c60209383613113565b810103126117445790611d099151611cff565b3d9150611e0f565b611e4f9060403d6040116106cd576106bf8183613113565b50611ccb565b9091506020813d602011611e81575b81611e7160209383613113565b8101031261174857519038611c96565b3d9150611e64565b6040513d89823e3d90fd5b90506020813d602011611ec2575b81611eaf60209383613113565b81010312611ebe575138611c61565b8580fd5b3d9150611ea2565b6040513d88823e3d90fd5b611ef19395508091929450903d10610ab257610a978183613113565b5050505050505050949250905092913880611c2c565b6040513d87823e3d90fd5b90503314386119c7565b606460405162461bcd60e51b815260206004820152600760248201527f4e6f7420796574000000000000000000000000000000000000000000000000006044820152fd5b503461022b57606036600319011261022b57611f9e611f7d613052565b611f85613068565b611f8d6132d6565b611f9561448f565b6044359161460f565b6001805580f35b503461022b57608036600319011261022b57611fbf613068565b90611fc86131bb565b916064356001600160801b038116810361249557611fe461448f565b82918390849285946004358752600a602052604087209360405194612008866130c6565b805486526001600160a01b0360018201541660208701526001600160a01b0360028201541660408701526001600160a01b0360038201541680606088015260096001600160a01b03600484015416928360808a01526001600160a01b0360058201541660a08a0152600681015460c08a0152600781015460e08a015260088101546101008a01520154610120880152331490811561256a575b5015610ab95760c08501516121a45750509161214e916001600160801b0360409481899a6001600160a01b0360e081602089015116970151958951966120e6886130f7565b87521660208601521686840152166060820152835197888094819363fc6f786560e01b83526004830191909160606080820193805183526001600160a01b036020820151166020840152816001600160801b0391826040820151166040860152015116910152565b03925af180156106d457608094849161217f575b505b60018055604051938452602084015260408301526060820152f35b905061219b91935060403d6040116106cd576106bf8183613113565b92909238612162565b936001600160a01b0360208299959493990151169361018060e083015160246040518098819363133f757160e31b835260048301525afa92831561255d5781958294612529575b50604051906370a0823160e01b82523060048301526020826024816001600160a01b038b165afa9182156106d45783926124f5575b506040516370a0823160e01b81523060048201529b60208d6024816001600160a01b038a165afa9c8d1561070c57849d6124bf575b506122f084926040926001600160801b036001600160a01b0360208a015116928160e08b015193875194612288866130f7565b85523060208601521686840152166060820152835194858094819363fc6f786560e01b83526004830191909160606080820193805183526001600160a01b036020820151166020840152816001600160801b0391826040820151166040860152015116910152565b03925af180156106d4576124a1575b50604051906370a0823160e01b82523060048301526020826024816001600160a01b038b165afa80156106d4578390612467575b61233d9250613576565b906040516370a0823160e01b81523060048201526020816024816001600160a01b0389165afa91821561245b578092612424575b505060809a61237f91613576565b94816123df575b505083612397575b50505050612164565b6123d69396506123ce919294506123b560c06127109201518861354d565b048096610959826001600160a01b03600554168661460f565b92839161460f565b3880808061238e565b84995061241d9197506124156127106123fc60c08601518b61354d565b048099610959826001600160a01b03600554168661460f565b998a9161460f565b3880612386565b9091506020823d602011612453575b8161244060209383613113565b8101031261022b5750518a61237f612371565b3d9150612433565b604051903d90823e3d90fd5b50906020813d602011612499575b8161248260209383613113565b81010312612495579061233d9151612333565b8280fd5b3d9150612475565b6124b99060403d6040116106cd576106bf8183613113565b506122ff565b909c506020813d6020116124ed575b816124db60209383613113565b81010312610e2c57519b6122f0612255565b3d91506124ce565b9091506020813d602011612521575b8161251160209383613113565b8101031261249557519038612220565b3d9150612504565b9093506125489195506101803d61018011610ab257610a978183613113565b505050505050505096925090509492386121eb565b50604051903d90823e3d90fd5b90503314386120a1565b503461022b57602036600319011261022b576004359067ffffffffffffffff821161022b57602060ff6125c1826125ae3660048801613151565b8160405193828580945193849201613198565b8101600c81520301902054166040519015158152f35b503461022b57602080600319360112610e30576001600160a01b036125fa613052565b168252600b81526040822060405192838383549182815201908193835284832090835b8181106126715750505084612633910385613113565b60405193838594850191818652518092526040850193925b82811061265a57505050500390f35b83518552869550938101939281019260010161264b565b82548452928601926001928301920161261d565b5060e036600319011261022b5760c036602319011261022b576126a661448f565b6004358152600a6020526040812090604051916126c2836130c6565b805483526001600160a01b0360018201541660208401526001600160a01b0360028201541660408401526001600160a01b0360038201541660608401526001600160a01b0360048201541660808401526001600160a01b0360058201541660a0840152600681015460c084015261275d6007820154600960e08601938285526008810154610100880152015461012086015260243514614444565b6001600160a01b03602084015116905160405191829163133f757160e31b835260048301528160246101809485935afa9081156106d45783928492612af9575b5050604051936370a0823160e01b85523060048601526020856024816001600160a01b0387165afa94851561070c578495612ac5575b50604051906370a0823160e01b82523060048301526020826024816001600160a01b0387165afa918215611f075790859392918492612a86575b506001600160a01b03602060609261282960443530338b614512565b612837606435303389614512565b6128496044358484840151168a6146f4565b61285b606435848484015116886146f4565b01511660c4604051809681937f219f5d17000000000000000000000000000000000000000000000000000000008352602435600484015260443560248401526064356044840152608435606484015260a4356084840152833560a48401525af1938415611f0757859686948796612a35575b50604051906370a0823160e01b82523060048301526020826024816001600160a01b0387165afa8015611df65788906129ff575b61290b9250613576565b916040516370a0823160e01b81523060048201526020816024816001600160a01b0389165afa908115611df65788916129cb575b509161295860609994926001600160801b039694613576565b91806129b9575b5050806129a7575b5050604051947f94c501c466d590ed97ef3d786c5fa1a7a4a5227f599f2546df3ea86389b534f96004359180a26001805516835260208301526040820152f35b6129b291339061460f565b3880612967565b6129c491339061460f565b388061295f565b90506020813d6020116129f7575b816129e660209383613113565b81010312611744575161295861293f565b3d91506129d9565b50906020813d602011612a2d575b81612a1a60209383613113565b81010312611744579061290b9151612901565b3d9150612a0d565b9750945092506060863d606011612a7e575b81612a5460609383613113565b81010312612a7a57612a65866142ed565b926040602088015197015193969394386128cd565b8480fd5b3d9150612a47565b91509192506020813d602011612abd575b81612aa460209383613113565b81010312612a7a57518492916001600160a01b0361280d565b3d9150612a97565b9094506020813d602011612af1575b81612ae160209383613113565b81010312610e2c575193386127d3565b3d9150612ad4565b612b13935080919250903d10610ab257610a978183613113565b50505050505050509250905090388061279d565b503461022b57602036600319011261022b576004359067ffffffffffffffff821161022b576020610b86612b5e3660048601613151565b61375d565b503461022b57608036600319011261022b57612b7d613052565b50612b86613068565b5060643567ffffffffffffffff8082116124955736602383011215612495578160040135908111612495573691016024011161022b5760206040517f150b7a02000000000000000000000000000000000000000000000000000000008152f35b503461022b5760a036600319011261022b5767ffffffffffffffff60043581811161249557612c19903690600401613151565b6001600160a01b03608435168060843503610e2c57612c366132d6565b6040516020810190612c536020828651610c928187858b01613198565b5190209260405191612c64836130aa565b83835260208301602435815260408401916044358352606435606086015260808501528587526004602052604087209284518051918211612e7b57612ca985546131d1565b601f8111612e40575b50602090601f8311600114612dcd5792826001600160a01b039693608096936004968d92612dc2575b50508160011b916000199060031b1c19161783555b5160018301555160028201556060850151600382015501920151166001600160a01b0319825416179055612d31826000526003602052604060002054151590565b15612d77577fcef0ac813efcf2b70c3ca9407cb4b9c7a2c13f88069eb984681924530d733714916117e86040519283926084359160643591604435916024359187613331565b81612da27f57c45aa395835adc7c2b2cacb6fcce511da0c9e4ef3887a310645a944161ad3f93613471565b506117e86040519283926084359160643591604435916024359187613331565b015190503880612cdb565b858a5260208a209190601f1984168b5b818110612e285750936080969360049693600193836001600160a01b039b9810612e0f575b505050811b018355612cf0565b015160001960f88460031b161c19169055388080612e02565b92936020600181928786015181550195019301612ddd565b612e6b90868b5260208b20601f850160051c81019160208610612e71575b601f0160051c019061331a565b38612cb2565b9091508190612e5e565b602489634e487b7160e01b81526041600452fd5b503461022b578060031936011261022b5760206001600160a01b0360065416604051908152f35b503461022b57602080600319360112610e3057600435612ed960075482106143ae565b808352600a82526001600160a01b03806002604086200154163303612fac57818452600a80845260408086206003015481519084166001600160a01b03168152336020820152919493929183917f977f200b2646b170d74b50cb3968700a2cc1884b0f7918d49efdb96302cb185491a28185528383526003604086200154168452600b8252612f6b816040862061366d565b50338452600b8252612f8081604086206134da565b5083525260408120600360028201916001600160a01b0319928381541690550190339082541617905580f35b6064836040519062461bcd60e51b82526004820152601060248201527f4e6f742070656e64696e674f776e6572000000000000000000000000000000006044820152fd5b503461022b57602036600319011261022b577fff6127f8243e336003b53caa06a61be0a98e6a527cfd0b071872424c5d916e4a60206001600160a01b03613035613052565b61303d6132d6565b16613047816133d4565b50604051908152a180f35b600435906001600160a01b038216820361173f57565b602435906001600160a01b038216820361173f57565b604435906001600160a01b038216820361173f57565b606435906001600160a01b038216820361173f57565b60a0810190811067ffffffffffffffff821117610e1657604052565b610140810190811067ffffffffffffffff821117610e1657604052565b67ffffffffffffffff8111610e1657604052565b6080810190811067ffffffffffffffff821117610e1657604052565b90601f8019910116810190811067ffffffffffffffff821117610e1657604052565b67ffffffffffffffff8111610e1657601f01601f191660200190565b81601f8201121561173f5780359061316882613135565b926131766040519485613113565b8284526020838301011161173f57816000926020809301838601378301015290565b60005b8381106131ab5750506000910152565b818101518382015260200161319b565b604435906001600160801b038216820361173f57565b90600182811c92168015613201575b60208310146131eb57565b634e487b7160e01b600052602260045260246000fd5b91607f16916131e0565b906040519182600082549261321f846131d1565b90818452600194858116908160001461328e575060011461324b575b505061324992500383613113565b565b9093915060005260209081600020936000915b8183106132765750506132499350820101388061323b565b8554888401850152948501948794509183019161325e565b91505061324994506020925060ff191682840152151560051b820101388061323b565b906020916132ca81518092818552858086019101613198565b601f01601f1916010190565b6001600160a01b036000541633036132ea57565b60246040517f118cdaa7000000000000000000000000000000000000000000000000000000008152336004820152fd5b818110613325575050565b6000815560010161331a565b9490936133596001600160a01b039498979360a096885260c0602089015260c08801906132b1565b9760408701526060860152608085015216910152565b6002548110156133a65760026000527f405787fa12a823e0f2b7631cc41b3ba8828b3321ca811111fa75cd3aa3bb5ace0190600090565b634e487b7160e01b600052603260045260246000fd5b80548210156133a65760005260206000200190600090565b60008181526009602052604081205461346c57600854680100000000000000008110156134585760018101806008558110156134445790826040927ff3f7a9fe364faab93b216da50a3214154f22a0a2b415b23a84c8169e8b636ee3015560085492815260096020522055600190565b602482634e487b7160e01b81526032600452fd5b602482634e487b7160e01b81526041600452fd5b905090565b60008181526003602052604081205461346c57600254680100000000000000008110156134585790826134c66134af8460016040960160025561336f565b819391549060031b91821b91600019901b19161790565b905560025492815260036020522055600190565b91906001830160009082825280602052604082205415600014613547578454946801000000000000000086101561353357836135236134af886001604098999a018555846133bc565b9055549382526020522055600190565b602483634e487b7160e01b81526041600452fd5b50925050565b8181029291811591840414171561356057565b634e487b7160e01b600052601160045260246000fd5b9190820391821161356057565b6000818152600360205260408120549091908015613668576000199080820181811161365457600254908382019182116136405781810361360c575b50505060025480156135f8578101906135d78261336f565b909182549160031b1b19169055600255815260036020526040812055600190565b602484634e487b7160e01b81526031600452fd5b61362a61361b6134af9361336f565b90549060031b1c92839261336f565b90558452600360205260408420553880806135bf565b602486634e487b7160e01b81526011600452fd5b602485634e487b7160e01b81526011600452fd5b505090565b9060018201906000928184528260205260408420549081151560001461375657600019918083018181116137425782549084820191821161372e578181036136f9575b505050805480156136e5578201916136c883836133bc565b909182549160031b1b191690555582526020526040812055600190565b602486634e487b7160e01b81526031600452fd5b6137196137096134af93866133bc565b90549060031b1c928392866133bc565b905586528460205260408620553880806136b0565b602488634e487b7160e01b81526011600452fd5b602487634e487b7160e01b81526011600452fd5b5050505090565b6137949060405161377e60208281610c928183019687815193849201613198565b5190206000526003602052604060002054151590565b90565b60408051916137a5836130aa565b6060835260009081608060209582878201528286820152826060820152015282516137df858281610c928183019687815193849201613198565b519020808252600384528282205415613845579180826001600160a01b0394600494528386522090805194613813866130aa565b61381c8361320b565b865260018301549086015260028201549085015260038101546060850152015416608082015290565b60648484519062461bcd60e51b82526004820152600960248201527f4e4f5420464f554e4400000000000000000000000000000000000000000000006044820152fd5b1561388f57565b606460405162461bcd60e51b815260206004820152601660248201527f436f6c6c6563744164647265737320696e76616c6964000000000000000000006044820152fd5b156138da57565b606460405162461bcd60e51b815260206004820152601660248201527f456e6454696d65203c3d2063757272656e7454696d65000000000000000000006044820152fd5b1561392557565b606460405162461bcd60e51b815260206004820152602060248201527f6e6674506f736974696f6e4d616e61676572206e6f7420737570706f727465646044820152fd5b815191906041830361399a5761399392506020820151906060604084015193015160001a906139a5565b9192909190565b505060009160029190565b91907f7fffffffffffffffffffffffffffffff5d576e7357a4501ddfe92f46681b20a08411613a1d57926020929160ff608095604051948552168484015260408301526060820152600092839182805260015afa1561245b5780516001600160a01b03811615613a1457918190565b50809160019190565b50505060009160039190565b6004811015613ae15780613a3b575050565b60018103613a6d5760046040517ff645eedf000000000000000000000000000000000000000000000000000000008152fd5b60028103613aa657602482604051907ffce698f70000000000000000000000000000000000000000000000000000000082526004820152fd5b600314613ab05750565b602490604051907fd78bce0c0000000000000000000000000000000000000000000000000000000082526004820152fd5b634e487b7160e01b600052602160045260246000fd5b919082604091031261173f576020825192015190565b9294939193606081018051600091816141b1575b50506001600160a01b0385163b1561022b57604051632142170760e11b8152336004820152306024820152604481018490528181606481836001600160a01b038b165af18015611bbc576141a2575b50906040519063133f757160e31b8252836004830152610180826024816001600160a01b038a165afa80156106d45783908493859161416f575b50604051907fc45a01550000000000000000000000000000000000000000000000000000000082526020826004816001600160a01b038d165afa918215611eca57869261411b575b506020926001600160a01b03809362ffffff606494836040519a8b9889977f1698ee82000000000000000000000000000000000000000000000000000000008952166004880152166024860152166044840152165afa9182156106d45783926140df575b50613ce560408051613c67816130f7565b8681526001600160a01b038a1660208201526001600160801b03828201526001600160801b03606082015281518093819263fc6f786560e01b83526004830191909160606080820193805183526001600160a01b036020820151166020840152816001600160801b0391826040820151166040860152015116910152565b0381876001600160a01b038c165af1801561070c576140c1575b50846020820151613ec8575b6009916040600754910151996040519a8b95613d26876130c6565b838752602087016001600160a01b038c16815260408801938985528d6001600160a01b0360608b01911681526001600160a01b0360808b01921682526001600160a01b0360a08b019416845260c08a0194855260e08a01958c87526101008b01974289526101208c01998a528c52600a60205260408c209a518b556001600160a01b0360018c01945116936001600160a01b031994858254161790556001600160a01b0360028c01915116848254161790556001600160a01b0360038b01915116838254161790556001600160a01b0360048a01915116828254161790556001600160a01b036005890192511690825416179055516006860155516007850155516008840155519101556001600160a01b0385168152600b602052613e50604082208751906134da565b50600754906000198214613eb45750917fc1d62c166ce7dbf25ddb2c2746bfe7d0a3a9c465f1190f5b2c1148177508b66193916001608094016007556001600160a01b03875196816040519516855216602084015260408301526060820152a25190565b80634e487b7160e01b602492526011600452fd5b5060405163133f757160e31b8152846004820152610180816024816001600160a01b038b165afa90811561070c57613f1b6001600160801b0392612710928791614094575b50836020860151911661354d565b041660405190613f2a826130aa565b858252602082019081526040820185815260608301908682526001600160801b03608085019342855260405195630624e65f60e11b87525160048701525116602485015251604484015251606483015251608482015260408160a481876001600160a01b038c165af1801561070c57614076575b5061403060406001600160a01b0360055416815190613fbc826130f7565b87825260208201526001600160801b03828201526001600160801b03606082015281518093819263fc6f786560e01b83526004830191909160606080820193805183526001600160a01b036020820151166020840152816001600160801b0391826040820151166040860152015116910152565b0381876001600160a01b038c165af1801561070c57918691600993614058575b509150613d0b565b6140709060403d6040116106cd576106bf8183613113565b50614050565b61408e9060403d6040116106cd576106bf8183613113565b50613f9e565b6140af91506101803d61018011610ab257610a978183613113565b50505050965050505050505038613f0d565b6140d99060403d6040116106cd576106bf8183613113565b50613cff565b9091506020813d602011614113575b816140fb60209383613113565b810103126124955761410c906142cb565b9038613c56565b3d91506140ee565b9091506020813d602011614167575b8161413760209383613113565b81010312611ebe576020926001600160a01b03809362ffffff61415b6064956142cb565b95505092505092613bf2565b3d915061412a565b91505061418e9192506101803d61018011610ab257610a978183613113565b505050505050509493509150909238613baa565b6141ab906130e3565b38613b70565b6001600160a01b03918260808601511680156000146142b357505051340361426f57600554166040516020810181811067ffffffffffffffff82111761425b5783809381809481946040525234905af16142096144ca565b5015614217575b3880613b21565b606460405162461bcd60e51b815260206004820152600360248201527f53544500000000000000000000000000000000000000000000000000000000006044820152fd5b602484634e487b7160e01b81526041600452fd5b606460405162461bcd60e51b815260206004820152601060248201527f496e73756666696369656e7420466565000000000000000000000000000000006044820152fd5b9091506142c69260055416903390614512565b614210565b51906001600160a01b038216820361173f57565b51908160020b820361173f57565b51906001600160801b038216820361173f57565b91908261018091031261173f5781516bffffffffffffffffffffffff8116810361173f5791614332602082016142cb565b9161433f604083016142cb565b9161434c606082016142cb565b91608082015162ffffff8116810361173f579161436b60a082016142df565b9161437860c083016142df565b9161438560e082016142ed565b9161010082015191610120810151916137946101606143a761014085016142ed565b93016142ed565b156143b557565b606460405162461bcd60e51b815260206004820152600e60248201527f496e76616c6964206c6f636b49640000000000000000000000000000000000006044820152fd5b1561440057565b606460405162461bcd60e51b815260206004820152600e60248201527f4e6f74206c6f636b206f776e65720000000000000000000000000000000000006044820152fd5b1561444b57565b606460405162461bcd60e51b815260206004820152600e60248201527f496e76616c6964204e46545f49440000000000000000000000000000000000006044820152fd5b6002600154146144a0576002600155565b60046040517f3ee5aeb5000000000000000000000000000000000000000000000000000000008152fd5b3d156144f5573d906144db82613135565b916144e96040519384613113565b82523d6000602084013e565b606090565b9081602091031261173f5751801515810361173f5790565b9060008094614582829561457460405193849260208401977f23b872dd000000000000000000000000000000000000000000000000000000008952602485016040919493929460608201956001600160a01b0380921683521660208201520152565b03601f198101835282613113565b51925af161458e6144ca565b816145e0575b501561459c57565b606460405162461bcd60e51b815260206004820152600360248201527f53544600000000000000000000000000000000000000000000000000000000006044820152fd5b80518015925082156145f5575b505038614594565b61460892506020809183010191016144fa565b38806145ed565b6040517fa9059cbb00000000000000000000000000000000000000000000000000000000602082019081526001600160a01b039093166024820152604481019390935260009283929083906146678160648101614574565b51925af16146736144ca565b816146c5575b501561468157565b606460405162461bcd60e51b815260206004820152600260248201527f53540000000000000000000000000000000000000000000000000000000000006044820152fd5b80518015925082156146da575b505038614679565b6146ed92506020809183010191016144fa565b38806146d2565b6040517f095ea7b300000000000000000000000000000000000000000000000000000000602082019081526001600160a01b0390931660248201526044810193909352600092839290839061474c8160648101614574565b51925af16147586144ca565b816147aa575b501561476657565b606460405162461bcd60e51b815260206004820152600260248201527f53410000000000000000000000000000000000000000000000000000000000006044820152fd5b80518015925082156147bf575b50503861475e565b6147d292506020809183010191016144fa565b38806147b756fea2646970667358221220b9421526ab597f9ba98b35bdf61a92efd85706aa2f9524deeef69bb23b49d88c64736f6c63430008140033cef0ac813efcf2b70c3ca9407cb4b9c7a2c13f88069eb984681924530d73371457c45aa395835adc7c2b2cacb6fcce511da0c9e4ef3887a310645a944161ad3f0000000000000000000000007197e214c0b767cfb76fb734ab638e2c192f4e53000000000000000000000000521faacdfa097ad35a32387727e468f7fd032fd6000000000000000000000000333a16307d8bef80616f719e958af5c76290ca85
Deployed Bytecode
0x6080604052600436101561001257600080fd5b6000803560e01c806306f9b07a14612ff0578063093cf39114612eb65780630d12033114612e8f578063100fc94314612be6578063150b7a0214612b6357806317d616a014612b27578063186941551461268557806323a35de9146125d75780632473a6b214612574578063260e12b014611fa5578063280f386714611f605780636198e3391461180c5780636518a0b3146117ee5780636850cb241461174c5780636ec3af85146114c5578063715018a61461146b57806387d8de3d1461136d5780638da5cb5b14611347578063ab9ae180146112aa578063b08348931461122f578063b2fb30cb14611102578063b3f00674146110db578063b48dd3be1461101b578063b707a28814610f29578063c69bebe414610eae578063cdb5661f14610e34578063d5fdb73214610c3a578063d73792a914610c1d578063ed1eee6814610b90578063f0582e1414610b4b578063f11478f8146102cf578063f2fde38b1461022e5763f4dadc611461018857600080fd5b3461022b57602036600319011261022b576040610140916004358152600a602052208054906001600160a01b03908160018201541691806002830154169080600384015416908060048501541690600585015416906006850154926007860154946009600888015497015497604051998a5260208a015260408901526060880152608087015260a086015260c085015260e0840152610100830152610120820152f35b80fd5b503461022b57602036600319011261022b57610248613052565b6102506132d6565b6001600160a01b0380911690811561029e57600054826001600160a01b0319821617600055167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0600080a380f35b602483604051907f1e4fbdf70000000000000000000000000000000000000000000000000000000082526004820152fd5b5060c036600319011261022b5760a036602319011261022b576102f7600754600435106143ae565b6004358152600a60205261031c6001600160a01b0360036040842001541633146143f9565b61032461448f565b6004358152600a602052604081209060405161033f816130c6565b825481526001600160a01b0360018401541660208201526001600160a01b0360028401541660408201526001600160a01b0360038401541660608201526001600160a01b0360048401541660808201526001600160a01b0360058401541660a0820152600683015460c08201526007830154928360e08301526009600882015491610100928385015201546103e06101209586850192835260243514614444565b51421115610b0757600435600052600a602052604060002060405194610405866130c6565b815486526001600160a01b0360018301541660208701526001600160a01b03600283015416604087015260096001600160a01b03600384015416928360608901526001600160a01b03600482015416948560808a01526001600160a01b0360058301541660a08a0152600682015460c08a0152600782015460e08a01526008820154908901520154908601523314908115610afd575b5015610ab95760c08301516107415760406105418460e06001600160a01b036020600097980151169101518351906104d2826130f7565b81523360208201526001600160801b0380858301526060820152835195868094819363fc6f786560e01b83526004830191909160606080820193805183526001600160a01b036020820151166020840152816001600160801b0391826040820151166040860152015116910152565b03925af1918215610735578392610717575b505b6001600160a01b0360208201511660405190630624e65f60e11b8252602435600483015260408260a481876001600160801b0395866105926131bb565b16602484015260643560448401526084356064840152833560848401525af192831561070c57849285946106df575b50604091816001600160a01b03602061065d94015116916001600160a01b03606060e0840151930151168551926105f7846130f7565b8352602083015280858301526060820152835197888094819363fc6f786560e01b83526004830191909160606080820193805183526001600160a01b036020820151166020840152816001600160801b0391826040820151166040860152015116910152565b03925af19384156106d4576040946106a8575b508351927fabcec736cf7ffb1e2406a7d4f50174d68847773bd8bf43d6f9ee131a24121a7d6004359180a26001805582526020820152f35b6106c790853d87116106cd575b6106bf8183613113565b810190613af7565b50610670565b503d6106b5565b6040513d85823e3d90fd5b61065d919450604092935061070090833d85116106cd576106bf8183613113565b939093949150916105c1565b6040513d86823e3d90fd5b61072f9060403d6040116106cd576106bf8183613113565b50610553565b6040513d6000823e3d90fd5b6001600160a01b0360208401511661018060e085015160246040518094819363133f757160e31b835260048301525afa8015610735576000918291610a79575b50604051946370a0823160e01b86523060048701526020866024816001600160a01b0387165afa95861561073557600096610a45575b50604051956370a0823160e01b87523060048801526020876024816001600160a01b0387165afa96871561073557600097610a11575b50600060406108836001600160a01b0360208601511660e0860151835190610814826130f7565b81523060208201526001600160801b0380858301526060820152835194858094819363fc6f786560e01b83526004830191909160606080820193805183526001600160a01b036020820151166020840152816001600160801b0391826040820151166040860152015116910152565b03925af18015610735576109f3575b506040516370a0823160e01b81523060048201526020816024816001600160a01b0389165afa908115610735576000916109bf575b50906108d291613576565b6040516370a0823160e01b81523060048201526020816024816001600160a01b0388165afa9081156107355760009161098d575b50869761091291613576565b938161096e575b505082610929575b505050610555565b6109669261271061094160c061095e9401518361354d565b0490610959826001600160a01b03600554168661460f565b613576565b90339061460f565b388080610921565b61095e6109869261271061094160c08701518361354d565b3880610919565b906020823d6020116109b7575b816109a760209383613113565b8101031261022b57505186610906565b3d915061099a565b906020823d6020116109eb575b816109d960209383613113565b8101031261022b5750516108d26108c7565b3d91506109cc565b610a0b9060403d6040116106cd576106bf8183613113565b50610892565b90966020823d602011610a3d575b81610a2c60209383613113565b8101031261022b57505195386107ed565b3d9150610a1f565b90956020823d602011610a71575b81610a6060209383613113565b8101031261022b57505194386107b7565b3d9150610a53565b9050610a9f91506101803d61018011610ab2575b610a978183613113565b810190614301565b5050505050505050925090509038610781565b503d610a8d565b606460405162461bcd60e51b815260206004820152600960248201527f4e6f74206f776e657200000000000000000000000000000000000000000000006044820152fd5b905033143861049b565b606460405162461bcd60e51b815260206004820152600760248201527f4e4f5420594554000000000000000000000000000000000000000000000000006044820152fd5b503461022b57602036600319011261022b576020610b866001600160a01b03610b72613052565b166000526009602052604060002054151590565b6040519015158152f35b503461022b57602036600319011261022b576004359067ffffffffffffffff821161022b57610bca610bc53660048501613151565b613797565b6040518091602082526001600160a01b036080610bf3835160a0602087015260c08601906132b1565b92602081015160408601526040810151606086015260608101518286015201511660a08301520390f35b503461022b578060031936011261022b5760206040516127108152f35b503461022b57602080600319360112610e305767ffffffffffffffff600435818111610e2c57610c6e903690600401613151565b610c766132d6565b604051610c9f848281610c928183019687815193849201613198565b8101038084520182613113565b51902090604051838101907f44454641554c54000000000000000000000000000000000000000000000000009182815260078252604082019382851090851117610e165783604052815190208414610df65750505080835260038252604083205415610db2579081610d317fb2c474098bd86300759342af0b60dbf39dcf9552246e0b7ffd3c19a4e3e9060593613583565b50808452600482528360046040822082610d4b82546131d1565b80610d74575b50506000600182015560006002820155600060038201550155604051908152a180f35b601f8111600114610d8d575050600081555b8238610d51565b828252610da8601f888420920160051c82016001830161331a565b6000835555610d86565b6064826040519062461bcd60e51b82526004820152600e60248201527f466565206e6f74206578697374730000000000000000000000000000000000006044820152fd5b606493506084908562461bcd60e51b855260448201526007858201520152fd5b634e487b7160e01b600052604160045260246000fd5b8380fd5b5080fd5b503461022b57602036600319011261022b576040610e95916004358152600460205220610e608161320b565b906001810154906002810154906001600160a01b0360046003830154920154169160405195869560a0875260a08701906132b1565b9360208601526040850152606084015260808301520390f35b503461022b57602036600319011261022b57610ec8613052565b610ed06132d6565b600554604080516001600160a01b038084168252848116602083015292936001600160a01b0319939290917f02cbe864dd291b617018e5a2181cfd770c54bf3fba21fc323434c694b3b2ad1f9190a11691161760055580f35b503461022b57604036600319011261022b57600435610f46613068565b610f5360075483106143ae565b818352600a6020526001600160a01b0390610f788260036040872001541633146143f9565b610f8061448f565b168015610fd75760207fbf72678a283f17a2d52bd1bd823f5fcd1f921056005db4c2ac6e29f88da5b75491838552600a825260046040862001816001600160a01b0319825416179055604051908152a26001805580f35b606460405162461bcd60e51b815260206004820152600c60248201527f434f4c4c4543545f4144445200000000000000000000000000000000000000006044820152fd5b503461022b57604036600319011261022b576004357f2ab916445cd7f71b7d22f037187a5e1b6086c455fa944619946ca72b62030ca26110d561105c613068565b61106960075485106143ae565b838552600a6020526001600160a01b0361108d8160036040892001541633146143f9565b848652600a602052600260408720019082166001600160a01b031982541617905560405191829133839060209093929360408301946001600160a01b03809216845216910152565b0390a280f35b503461022b578060031936011261022b5760206001600160a01b0360055416604051908152f35b503461022b57604036600319011261022b5760043560243561112760075483106143ae565b818352600a60205261114a6001600160a01b0360036040862001541633146143f9565b61115261448f565b818352600a6020526009604084200180548211156111eb57428211156111a757817f34fc5c313b2fd97c2b528805434c6cb36ab482f72af6117a52208cf18874fdf49260209255604051908152a26001805580f35b606460405162461bcd60e51b815260206004820152600e60248201527f456e6454696d65203c3d206e6f770000000000000000000000000000000000006044820152fd5b606460405162461bcd60e51b815260206004820152601960248201527f456e6454696d65203c3d2063757272656e74456e645469656d000000000000006044820152fd5b503461022b57602036600319011261022b57611249613052565b6112516132d6565b600654604080516001600160a01b038084168252848116602083015292936001600160a01b0319939290917f32e004fe7121682349ed511e2414e25e6dc53f3a6db355f0af4724b4dc17c8109190a11691161760065580f35b503461022b57604036600319011261022b57806024356001600160a01b03811680910361134457818080926112dd6132d6565b6112e561448f565b600435905af16112f36144ca565b5015611300576001805580f35b606460405162461bcd60e51b815260206004820152601960248201527f47617320746f6b656e207472616e73666572206661696c6564000000000000006044820152fd5b50fd5b503461022b578060031936011261022b576001600160a01b036020915416604051908152f35b5060c036600319011261022b57611382613052565b9061138b61307e565b91611394613094565b916084359060a4359067ffffffffffffffff821161022b57506113bb903690600401613151565b926001600160a01b03946113d28683161515613888565b6113dd4284116138d3565b6113e68561375d565b156114275761141561141f95610bc561141060209988166000526009602052604060002054151590565b61391e565b9360243590613b0d565b604051908152f35b606460405162461bcd60e51b815260206004820152600f60248201527f4665654e616d6520696e76616c696400000000000000000000000000000000006044820152fd5b503461022b578060031936011261022b576114846132d6565b60006001600160a01b0381546001600160a01b031981168355167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e08280a380f35b506003199060e03683011261022b576114dc613052565b916114e561307e565b6114ed613094565b6084359160a4359367ffffffffffffffff9485811161174857611514903690600401613151565b60c435918683116117445760a09083360301126117485760405195611538876130aa565b8260040135908111611744576115549060043691850101613151565b86526020968787019260248101358452604088019360448201358552608460608a0192606481013584520135946001600160a01b0395868116810361173f5760808b019081526115ba611410888f610b728e6115b38f85161515613888565b42106138d3565b60ff6040518d81816115d28b83815193849201613198565b8101600c81520301902054166116fb5761169d96959361166560c8603c958f94958f966116949a975192519151955190519060405196879461162d8a87019a468c523360601b6040890152825192839160548a019101613198565b8501936054850152607484015260948301526bffffffffffffffffffffffff199060601b1660b48201520360a8810184520182613113565b5190207f19457468657265756d205369676e6564204d6573736167653a0a3332000000008252601c5220613969565b90939193613a29565b80600654169116036116b75761141f949560243590613b0d565b6064856040519062461bcd60e51b82526004820152601560248201527f4665655369676e6572206e6f7420616c6c6f77656400000000000000000000006044820152fd5b60648c6040519062461bcd60e51b82526004820152601260248201527f5369676e61747572652064697361626c656400000000000000000000000000006044820152fd5b600080fd5b8780fd5b8680fd5b503461022b57602036600319011261022b5760043567ffffffffffffffff8111610e30576117e86117a27fc19cc6d72b61c6ab50ce499b71c09e6c79b65906c65247abc661980f5e142b22923690600401613151565b6117aa6132d6565b60405160208183516117bf8183858801613198565b8101600c815203019020600160ff198254161790556040519182916020835260208301906132b1565b0390a180f35b503461022b578060031936011261022b576020600754604051908152f35b503461022b57602036600319011261022b5761182d600754600435106143ae565b6004358152600a6020526118526001600160a01b0360036040842001541633146143f9565b6004358152600a60205260408120906040519161186e836130c6565b805483526001600160a01b0360018201541660208401526001600160a01b0360028201541660408401526001600160a01b0360038201541660608401526001600160a01b0360048201541660808401526001600160a01b0360058201541660a0840152600681015460c0840152600781015460e0840152600960088201549161010092838601520154610120908082860152421115611f1c576001600160a01b03606085015116916004358452600a6020526040842060405192611931846130c6565b815484526001600160a01b0360018301541660208501526001600160a01b03600283015416604085015260096001600160a01b03600384015416928360608701526001600160a01b03600482015416948560808801526001600160a01b0360058301541660a0880152600682015460c0880152600782015460e08801526008820154908701520154908401523314908115611f12575b5015610ab957829160c082015115600014611be55781611a719160e06001600160a01b03602060409601511692015190845191611a03836130f7565b825260208201526001600160801b0380858301526060820152835194858094819363fc6f786560e01b83526004830191909160606080820193805183526001600160a01b036020820151166020840152816001600160801b0391826040820151166040860152015116910152565b03925af18015611bbc57611bc7575b505b6001600160a01b036020830151166001600160a01b036060840151169060e084015191813b15610e2c57604051632142170760e11b81523060048201526001600160a01b03919091166024820152604481019290925282908290606490829084905af18015611bbc57611bad575b50906001600160a01b036060820151168252600b602052611b166004356040842061366d565b5060e06001600160a01b0360608301511691015160405191825260208201524260408201527f462608836dd129ef58f79f0a556fe285515f86287c758ea37a6d2f0a052e3f9d606060043592a26004358152600a6020526000600960408320828155836001820155836002820155836003820155836004820155836005820155826006820155826007820155826008820155015580f35b611bb6906130e3565b38611af0565b6040513d84823e3d90fd5b611bdf9060403d6040116106cd576106bf8183613113565b50611a80565b91506001600160a01b036020820151169160e08201519160405193849363133f757160e31b855260048501528360246101809687935afa928315611f075785948694611ed5575b50506040516370a0823160e01b81523060048201526020816024816001600160a01b0389165afa908115611eca578691611e94575b50604051906370a0823160e01b82523060048301526020826024816001600160a01b0389165afa918215611e89578792611e55575b50866040611cbc6001600160a01b0360208701511660e0870151835190610814826130f7565b03925af18015611df657611e37575b50604051906370a0823160e01b82523060048301526020826024816001600160a01b038b165afa8015611df6578890611e01575b611d099250613576565b90604051906370a0823160e01b82523060048301526020826024816001600160a01b038a165afa8015611df6578890611dc0575b611d479250613576565b948382611da0575b50505083611d61575b50505050611a82565b611d9793612710611d7960c0611d919401518361354d565b0490610959826001600160a01b03600554168761460f565b9161460f565b38808080611d58565b611d91611db893612710611d7960c08801518361354d565b388083611d4f565b50906020813d602011611dee575b81611ddb60209383613113565b810103126117445790611d479151611d3d565b3d9150611dce565b6040513d8a823e3d90fd5b50906020813d602011611e2f575b81611e1c60209383613113565b810103126117445790611d099151611cff565b3d9150611e0f565b611e4f9060403d6040116106cd576106bf8183613113565b50611ccb565b9091506020813d602011611e81575b81611e7160209383613113565b8101031261174857519038611c96565b3d9150611e64565b6040513d89823e3d90fd5b90506020813d602011611ec2575b81611eaf60209383613113565b81010312611ebe575138611c61565b8580fd5b3d9150611ea2565b6040513d88823e3d90fd5b611ef19395508091929450903d10610ab257610a978183613113565b5050505050505050949250905092913880611c2c565b6040513d87823e3d90fd5b90503314386119c7565b606460405162461bcd60e51b815260206004820152600760248201527f4e6f7420796574000000000000000000000000000000000000000000000000006044820152fd5b503461022b57606036600319011261022b57611f9e611f7d613052565b611f85613068565b611f8d6132d6565b611f9561448f565b6044359161460f565b6001805580f35b503461022b57608036600319011261022b57611fbf613068565b90611fc86131bb565b916064356001600160801b038116810361249557611fe461448f565b82918390849285946004358752600a602052604087209360405194612008866130c6565b805486526001600160a01b0360018201541660208701526001600160a01b0360028201541660408701526001600160a01b0360038201541680606088015260096001600160a01b03600484015416928360808a01526001600160a01b0360058201541660a08a0152600681015460c08a0152600781015460e08a015260088101546101008a01520154610120880152331490811561256a575b5015610ab95760c08501516121a45750509161214e916001600160801b0360409481899a6001600160a01b0360e081602089015116970151958951966120e6886130f7565b87521660208601521686840152166060820152835197888094819363fc6f786560e01b83526004830191909160606080820193805183526001600160a01b036020820151166020840152816001600160801b0391826040820151166040860152015116910152565b03925af180156106d457608094849161217f575b505b60018055604051938452602084015260408301526060820152f35b905061219b91935060403d6040116106cd576106bf8183613113565b92909238612162565b936001600160a01b0360208299959493990151169361018060e083015160246040518098819363133f757160e31b835260048301525afa92831561255d5781958294612529575b50604051906370a0823160e01b82523060048301526020826024816001600160a01b038b165afa9182156106d45783926124f5575b506040516370a0823160e01b81523060048201529b60208d6024816001600160a01b038a165afa9c8d1561070c57849d6124bf575b506122f084926040926001600160801b036001600160a01b0360208a015116928160e08b015193875194612288866130f7565b85523060208601521686840152166060820152835194858094819363fc6f786560e01b83526004830191909160606080820193805183526001600160a01b036020820151166020840152816001600160801b0391826040820151166040860152015116910152565b03925af180156106d4576124a1575b50604051906370a0823160e01b82523060048301526020826024816001600160a01b038b165afa80156106d4578390612467575b61233d9250613576565b906040516370a0823160e01b81523060048201526020816024816001600160a01b0389165afa91821561245b578092612424575b505060809a61237f91613576565b94816123df575b505083612397575b50505050612164565b6123d69396506123ce919294506123b560c06127109201518861354d565b048096610959826001600160a01b03600554168661460f565b92839161460f565b3880808061238e565b84995061241d9197506124156127106123fc60c08601518b61354d565b048099610959826001600160a01b03600554168661460f565b998a9161460f565b3880612386565b9091506020823d602011612453575b8161244060209383613113565b8101031261022b5750518a61237f612371565b3d9150612433565b604051903d90823e3d90fd5b50906020813d602011612499575b8161248260209383613113565b81010312612495579061233d9151612333565b8280fd5b3d9150612475565b6124b99060403d6040116106cd576106bf8183613113565b506122ff565b909c506020813d6020116124ed575b816124db60209383613113565b81010312610e2c57519b6122f0612255565b3d91506124ce565b9091506020813d602011612521575b8161251160209383613113565b8101031261249557519038612220565b3d9150612504565b9093506125489195506101803d61018011610ab257610a978183613113565b505050505050505096925090509492386121eb565b50604051903d90823e3d90fd5b90503314386120a1565b503461022b57602036600319011261022b576004359067ffffffffffffffff821161022b57602060ff6125c1826125ae3660048801613151565b8160405193828580945193849201613198565b8101600c81520301902054166040519015158152f35b503461022b57602080600319360112610e30576001600160a01b036125fa613052565b168252600b81526040822060405192838383549182815201908193835284832090835b8181106126715750505084612633910385613113565b60405193838594850191818652518092526040850193925b82811061265a57505050500390f35b83518552869550938101939281019260010161264b565b82548452928601926001928301920161261d565b5060e036600319011261022b5760c036602319011261022b576126a661448f565b6004358152600a6020526040812090604051916126c2836130c6565b805483526001600160a01b0360018201541660208401526001600160a01b0360028201541660408401526001600160a01b0360038201541660608401526001600160a01b0360048201541660808401526001600160a01b0360058201541660a0840152600681015460c084015261275d6007820154600960e08601938285526008810154610100880152015461012086015260243514614444565b6001600160a01b03602084015116905160405191829163133f757160e31b835260048301528160246101809485935afa9081156106d45783928492612af9575b5050604051936370a0823160e01b85523060048601526020856024816001600160a01b0387165afa94851561070c578495612ac5575b50604051906370a0823160e01b82523060048301526020826024816001600160a01b0387165afa918215611f075790859392918492612a86575b506001600160a01b03602060609261282960443530338b614512565b612837606435303389614512565b6128496044358484840151168a6146f4565b61285b606435848484015116886146f4565b01511660c4604051809681937f219f5d17000000000000000000000000000000000000000000000000000000008352602435600484015260443560248401526064356044840152608435606484015260a4356084840152833560a48401525af1938415611f0757859686948796612a35575b50604051906370a0823160e01b82523060048301526020826024816001600160a01b0387165afa8015611df65788906129ff575b61290b9250613576565b916040516370a0823160e01b81523060048201526020816024816001600160a01b0389165afa908115611df65788916129cb575b509161295860609994926001600160801b039694613576565b91806129b9575b5050806129a7575b5050604051947f94c501c466d590ed97ef3d786c5fa1a7a4a5227f599f2546df3ea86389b534f96004359180a26001805516835260208301526040820152f35b6129b291339061460f565b3880612967565b6129c491339061460f565b388061295f565b90506020813d6020116129f7575b816129e660209383613113565b81010312611744575161295861293f565b3d91506129d9565b50906020813d602011612a2d575b81612a1a60209383613113565b81010312611744579061290b9151612901565b3d9150612a0d565b9750945092506060863d606011612a7e575b81612a5460609383613113565b81010312612a7a57612a65866142ed565b926040602088015197015193969394386128cd565b8480fd5b3d9150612a47565b91509192506020813d602011612abd575b81612aa460209383613113565b81010312612a7a57518492916001600160a01b0361280d565b3d9150612a97565b9094506020813d602011612af1575b81612ae160209383613113565b81010312610e2c575193386127d3565b3d9150612ad4565b612b13935080919250903d10610ab257610a978183613113565b50505050505050509250905090388061279d565b503461022b57602036600319011261022b576004359067ffffffffffffffff821161022b576020610b86612b5e3660048601613151565b61375d565b503461022b57608036600319011261022b57612b7d613052565b50612b86613068565b5060643567ffffffffffffffff8082116124955736602383011215612495578160040135908111612495573691016024011161022b5760206040517f150b7a02000000000000000000000000000000000000000000000000000000008152f35b503461022b5760a036600319011261022b5767ffffffffffffffff60043581811161249557612c19903690600401613151565b6001600160a01b03608435168060843503610e2c57612c366132d6565b6040516020810190612c536020828651610c928187858b01613198565b5190209260405191612c64836130aa565b83835260208301602435815260408401916044358352606435606086015260808501528587526004602052604087209284518051918211612e7b57612ca985546131d1565b601f8111612e40575b50602090601f8311600114612dcd5792826001600160a01b039693608096936004968d92612dc2575b50508160011b916000199060031b1c19161783555b5160018301555160028201556060850151600382015501920151166001600160a01b0319825416179055612d31826000526003602052604060002054151590565b15612d77577fcef0ac813efcf2b70c3ca9407cb4b9c7a2c13f88069eb984681924530d733714916117e86040519283926084359160643591604435916024359187613331565b81612da27f57c45aa395835adc7c2b2cacb6fcce511da0c9e4ef3887a310645a944161ad3f93613471565b506117e86040519283926084359160643591604435916024359187613331565b015190503880612cdb565b858a5260208a209190601f1984168b5b818110612e285750936080969360049693600193836001600160a01b039b9810612e0f575b505050811b018355612cf0565b015160001960f88460031b161c19169055388080612e02565b92936020600181928786015181550195019301612ddd565b612e6b90868b5260208b20601f850160051c81019160208610612e71575b601f0160051c019061331a565b38612cb2565b9091508190612e5e565b602489634e487b7160e01b81526041600452fd5b503461022b578060031936011261022b5760206001600160a01b0360065416604051908152f35b503461022b57602080600319360112610e3057600435612ed960075482106143ae565b808352600a82526001600160a01b03806002604086200154163303612fac57818452600a80845260408086206003015481519084166001600160a01b03168152336020820152919493929183917f977f200b2646b170d74b50cb3968700a2cc1884b0f7918d49efdb96302cb185491a28185528383526003604086200154168452600b8252612f6b816040862061366d565b50338452600b8252612f8081604086206134da565b5083525260408120600360028201916001600160a01b0319928381541690550190339082541617905580f35b6064836040519062461bcd60e51b82526004820152601060248201527f4e6f742070656e64696e674f776e6572000000000000000000000000000000006044820152fd5b503461022b57602036600319011261022b577fff6127f8243e336003b53caa06a61be0a98e6a527cfd0b071872424c5d916e4a60206001600160a01b03613035613052565b61303d6132d6565b16613047816133d4565b50604051908152a180f35b600435906001600160a01b038216820361173f57565b602435906001600160a01b038216820361173f57565b604435906001600160a01b038216820361173f57565b606435906001600160a01b038216820361173f57565b60a0810190811067ffffffffffffffff821117610e1657604052565b610140810190811067ffffffffffffffff821117610e1657604052565b67ffffffffffffffff8111610e1657604052565b6080810190811067ffffffffffffffff821117610e1657604052565b90601f8019910116810190811067ffffffffffffffff821117610e1657604052565b67ffffffffffffffff8111610e1657601f01601f191660200190565b81601f8201121561173f5780359061316882613135565b926131766040519485613113565b8284526020838301011161173f57816000926020809301838601378301015290565b60005b8381106131ab5750506000910152565b818101518382015260200161319b565b604435906001600160801b038216820361173f57565b90600182811c92168015613201575b60208310146131eb57565b634e487b7160e01b600052602260045260246000fd5b91607f16916131e0565b906040519182600082549261321f846131d1565b90818452600194858116908160001461328e575060011461324b575b505061324992500383613113565b565b9093915060005260209081600020936000915b8183106132765750506132499350820101388061323b565b8554888401850152948501948794509183019161325e565b91505061324994506020925060ff191682840152151560051b820101388061323b565b906020916132ca81518092818552858086019101613198565b601f01601f1916010190565b6001600160a01b036000541633036132ea57565b60246040517f118cdaa7000000000000000000000000000000000000000000000000000000008152336004820152fd5b818110613325575050565b6000815560010161331a565b9490936133596001600160a01b039498979360a096885260c0602089015260c08801906132b1565b9760408701526060860152608085015216910152565b6002548110156133a65760026000527f405787fa12a823e0f2b7631cc41b3ba8828b3321ca811111fa75cd3aa3bb5ace0190600090565b634e487b7160e01b600052603260045260246000fd5b80548210156133a65760005260206000200190600090565b60008181526009602052604081205461346c57600854680100000000000000008110156134585760018101806008558110156134445790826040927ff3f7a9fe364faab93b216da50a3214154f22a0a2b415b23a84c8169e8b636ee3015560085492815260096020522055600190565b602482634e487b7160e01b81526032600452fd5b602482634e487b7160e01b81526041600452fd5b905090565b60008181526003602052604081205461346c57600254680100000000000000008110156134585790826134c66134af8460016040960160025561336f565b819391549060031b91821b91600019901b19161790565b905560025492815260036020522055600190565b91906001830160009082825280602052604082205415600014613547578454946801000000000000000086101561353357836135236134af886001604098999a018555846133bc565b9055549382526020522055600190565b602483634e487b7160e01b81526041600452fd5b50925050565b8181029291811591840414171561356057565b634e487b7160e01b600052601160045260246000fd5b9190820391821161356057565b6000818152600360205260408120549091908015613668576000199080820181811161365457600254908382019182116136405781810361360c575b50505060025480156135f8578101906135d78261336f565b909182549160031b1b19169055600255815260036020526040812055600190565b602484634e487b7160e01b81526031600452fd5b61362a61361b6134af9361336f565b90549060031b1c92839261336f565b90558452600360205260408420553880806135bf565b602486634e487b7160e01b81526011600452fd5b602485634e487b7160e01b81526011600452fd5b505090565b9060018201906000928184528260205260408420549081151560001461375657600019918083018181116137425782549084820191821161372e578181036136f9575b505050805480156136e5578201916136c883836133bc565b909182549160031b1b191690555582526020526040812055600190565b602486634e487b7160e01b81526031600452fd5b6137196137096134af93866133bc565b90549060031b1c928392866133bc565b905586528460205260408620553880806136b0565b602488634e487b7160e01b81526011600452fd5b602487634e487b7160e01b81526011600452fd5b5050505090565b6137949060405161377e60208281610c928183019687815193849201613198565b5190206000526003602052604060002054151590565b90565b60408051916137a5836130aa565b6060835260009081608060209582878201528286820152826060820152015282516137df858281610c928183019687815193849201613198565b519020808252600384528282205415613845579180826001600160a01b0394600494528386522090805194613813866130aa565b61381c8361320b565b865260018301549086015260028201549085015260038101546060850152015416608082015290565b60648484519062461bcd60e51b82526004820152600960248201527f4e4f5420464f554e4400000000000000000000000000000000000000000000006044820152fd5b1561388f57565b606460405162461bcd60e51b815260206004820152601660248201527f436f6c6c6563744164647265737320696e76616c6964000000000000000000006044820152fd5b156138da57565b606460405162461bcd60e51b815260206004820152601660248201527f456e6454696d65203c3d2063757272656e7454696d65000000000000000000006044820152fd5b1561392557565b606460405162461bcd60e51b815260206004820152602060248201527f6e6674506f736974696f6e4d616e61676572206e6f7420737570706f727465646044820152fd5b815191906041830361399a5761399392506020820151906060604084015193015160001a906139a5565b9192909190565b505060009160029190565b91907f7fffffffffffffffffffffffffffffff5d576e7357a4501ddfe92f46681b20a08411613a1d57926020929160ff608095604051948552168484015260408301526060820152600092839182805260015afa1561245b5780516001600160a01b03811615613a1457918190565b50809160019190565b50505060009160039190565b6004811015613ae15780613a3b575050565b60018103613a6d5760046040517ff645eedf000000000000000000000000000000000000000000000000000000008152fd5b60028103613aa657602482604051907ffce698f70000000000000000000000000000000000000000000000000000000082526004820152fd5b600314613ab05750565b602490604051907fd78bce0c0000000000000000000000000000000000000000000000000000000082526004820152fd5b634e487b7160e01b600052602160045260246000fd5b919082604091031261173f576020825192015190565b9294939193606081018051600091816141b1575b50506001600160a01b0385163b1561022b57604051632142170760e11b8152336004820152306024820152604481018490528181606481836001600160a01b038b165af18015611bbc576141a2575b50906040519063133f757160e31b8252836004830152610180826024816001600160a01b038a165afa80156106d45783908493859161416f575b50604051907fc45a01550000000000000000000000000000000000000000000000000000000082526020826004816001600160a01b038d165afa918215611eca57869261411b575b506020926001600160a01b03809362ffffff606494836040519a8b9889977f1698ee82000000000000000000000000000000000000000000000000000000008952166004880152166024860152166044840152165afa9182156106d45783926140df575b50613ce560408051613c67816130f7565b8681526001600160a01b038a1660208201526001600160801b03828201526001600160801b03606082015281518093819263fc6f786560e01b83526004830191909160606080820193805183526001600160a01b036020820151166020840152816001600160801b0391826040820151166040860152015116910152565b0381876001600160a01b038c165af1801561070c576140c1575b50846020820151613ec8575b6009916040600754910151996040519a8b95613d26876130c6565b838752602087016001600160a01b038c16815260408801938985528d6001600160a01b0360608b01911681526001600160a01b0360808b01921682526001600160a01b0360a08b019416845260c08a0194855260e08a01958c87526101008b01974289526101208c01998a528c52600a60205260408c209a518b556001600160a01b0360018c01945116936001600160a01b031994858254161790556001600160a01b0360028c01915116848254161790556001600160a01b0360038b01915116838254161790556001600160a01b0360048a01915116828254161790556001600160a01b036005890192511690825416179055516006860155516007850155516008840155519101556001600160a01b0385168152600b602052613e50604082208751906134da565b50600754906000198214613eb45750917fc1d62c166ce7dbf25ddb2c2746bfe7d0a3a9c465f1190f5b2c1148177508b66193916001608094016007556001600160a01b03875196816040519516855216602084015260408301526060820152a25190565b80634e487b7160e01b602492526011600452fd5b5060405163133f757160e31b8152846004820152610180816024816001600160a01b038b165afa90811561070c57613f1b6001600160801b0392612710928791614094575b50836020860151911661354d565b041660405190613f2a826130aa565b858252602082019081526040820185815260608301908682526001600160801b03608085019342855260405195630624e65f60e11b87525160048701525116602485015251604484015251606483015251608482015260408160a481876001600160a01b038c165af1801561070c57614076575b5061403060406001600160a01b0360055416815190613fbc826130f7565b87825260208201526001600160801b03828201526001600160801b03606082015281518093819263fc6f786560e01b83526004830191909160606080820193805183526001600160a01b036020820151166020840152816001600160801b0391826040820151166040860152015116910152565b0381876001600160a01b038c165af1801561070c57918691600993614058575b509150613d0b565b6140709060403d6040116106cd576106bf8183613113565b50614050565b61408e9060403d6040116106cd576106bf8183613113565b50613f9e565b6140af91506101803d61018011610ab257610a978183613113565b50505050965050505050505038613f0d565b6140d99060403d6040116106cd576106bf8183613113565b50613cff565b9091506020813d602011614113575b816140fb60209383613113565b810103126124955761410c906142cb565b9038613c56565b3d91506140ee565b9091506020813d602011614167575b8161413760209383613113565b81010312611ebe576020926001600160a01b03809362ffffff61415b6064956142cb565b95505092505092613bf2565b3d915061412a565b91505061418e9192506101803d61018011610ab257610a978183613113565b505050505050509493509150909238613baa565b6141ab906130e3565b38613b70565b6001600160a01b03918260808601511680156000146142b357505051340361426f57600554166040516020810181811067ffffffffffffffff82111761425b5783809381809481946040525234905af16142096144ca565b5015614217575b3880613b21565b606460405162461bcd60e51b815260206004820152600360248201527f53544500000000000000000000000000000000000000000000000000000000006044820152fd5b602484634e487b7160e01b81526041600452fd5b606460405162461bcd60e51b815260206004820152601060248201527f496e73756666696369656e7420466565000000000000000000000000000000006044820152fd5b9091506142c69260055416903390614512565b614210565b51906001600160a01b038216820361173f57565b51908160020b820361173f57565b51906001600160801b038216820361173f57565b91908261018091031261173f5781516bffffffffffffffffffffffff8116810361173f5791614332602082016142cb565b9161433f604083016142cb565b9161434c606082016142cb565b91608082015162ffffff8116810361173f579161436b60a082016142df565b9161437860c083016142df565b9161438560e082016142ed565b9161010082015191610120810151916137946101606143a761014085016142ed565b93016142ed565b156143b557565b606460405162461bcd60e51b815260206004820152600e60248201527f496e76616c6964206c6f636b49640000000000000000000000000000000000006044820152fd5b1561440057565b606460405162461bcd60e51b815260206004820152600e60248201527f4e6f74206c6f636b206f776e65720000000000000000000000000000000000006044820152fd5b1561444b57565b606460405162461bcd60e51b815260206004820152600e60248201527f496e76616c6964204e46545f49440000000000000000000000000000000000006044820152fd5b6002600154146144a0576002600155565b60046040517f3ee5aeb5000000000000000000000000000000000000000000000000000000008152fd5b3d156144f5573d906144db82613135565b916144e96040519384613113565b82523d6000602084013e565b606090565b9081602091031261173f5751801515810361173f5790565b9060008094614582829561457460405193849260208401977f23b872dd000000000000000000000000000000000000000000000000000000008952602485016040919493929460608201956001600160a01b0380921683521660208201520152565b03601f198101835282613113565b51925af161458e6144ca565b816145e0575b501561459c57565b606460405162461bcd60e51b815260206004820152600360248201527f53544600000000000000000000000000000000000000000000000000000000006044820152fd5b80518015925082156145f5575b505038614594565b61460892506020809183010191016144fa565b38806145ed565b6040517fa9059cbb00000000000000000000000000000000000000000000000000000000602082019081526001600160a01b039093166024820152604481019390935260009283929083906146678160648101614574565b51925af16146736144ca565b816146c5575b501561468157565b606460405162461bcd60e51b815260206004820152600260248201527f53540000000000000000000000000000000000000000000000000000000000006044820152fd5b80518015925082156146da575b505038614679565b6146ed92506020809183010191016144fa565b38806146d2565b6040517f095ea7b300000000000000000000000000000000000000000000000000000000602082019081526001600160a01b0390931660248201526044810193909352600092839290839061474c8160648101614574565b51925af16147586144ca565b816147aa575b501561476657565b606460405162461bcd60e51b815260206004820152600260248201527f53410000000000000000000000000000000000000000000000000000000000006044820152fd5b80518015925082156147bf575b50503861475e565b6147d292506020809183010191016144fa565b38806147b756fea2646970667358221220b9421526ab597f9ba98b35bdf61a92efd85706aa2f9524deeef69bb23b49d88c64736f6c63430008140033
Constructor Arguments (ABI-Encoded and is the last bytes of the Contract Creation Code above)
0000000000000000000000007197e214c0b767cfb76fb734ab638e2c192f4e53000000000000000000000000521faacdfa097ad35a32387727e468f7fd032fd6000000000000000000000000333a16307d8bef80616f719e958af5c76290ca85
-----Decoded View---------------
Arg [0] : nftManager_ (address): 0x7197E214c0b767cFB76Fb734ab638E2c192F4E53
Arg [1] : feeReceiver_ (address): 0x521faAcDFA097ad35a32387727e468F7fD032fD6
Arg [2] : customFeeSigner_ (address): 0x333A16307d8bEf80616F719E958Af5C76290CA85
-----Encoded View---------------
3 Constructor Arguments found :
Arg [0] : 0000000000000000000000007197e214c0b767cfb76fb734ab638e2c192f4e53
Arg [1] : 000000000000000000000000521faacdfa097ad35a32387727e468f7fd032fd6
Arg [2] : 000000000000000000000000333a16307d8bef80616f719e958af5c76290ca85
Loading...
Loading
Loading...
Loading
Loading...
Loading
Net Worth in USD
$0.00
Net Worth in MON
Multichain Portfolio | 35 Chains
| Chain | Token | Portfolio % | Price | Amount | Value |
|---|
Loading...
Loading
Loading...
Loading
[ Download: CSV Export ]
A contract address hosts a smart contract, which is a set of code stored on the blockchain that runs when predetermined conditions are met. Learn more about addresses in our Knowledge Base.