ERC-721
Overview
Max Total Supply
2,338 OBLS
Holders
2,338
Market
Volume (24H)
N/A
Min Price (24H)
N/A
Max Price (24H)
N/A
Other Info
Token Contract
Balance
1 OBLSLoading...
Loading
Loading...
Loading
Loading...
Loading
# | Exchange | Pair | Price | 24H Volume | % Volume |
---|
Contract Source Code Verified (Exact Match)
Contract Name:
SingleTokenLockups
Compiler Version
v0.8.28+commit.7893614a
Optimization Enabled:
Yes with 200 runs
Other Settings:
paris EvmVersion
Contract Source Code (Solidity Standard Json-Input format)
// SPDX-License-Identifier: BUSL-1.1 pragma solidity 0.8.28; import '@openzeppelin/contracts/token/ERC20/IERC20.sol'; import '@openzeppelin/contracts/token/ERC721/extensions/ERC721Enumerable.sol'; import '@openzeppelin/contracts/utils/ReentrancyGuard.sol'; import './VotingVault.sol'; import './ClaimHandler.sol'; import './libraries/TimelockLibrary.sol'; import './libraries/TransferHelper.sol'; /// @title SingleTokenLockups /// this contract is used to lock tokens for many recipients that all have the same exact lockup schedule /// each lockup is represented by an NFT, ERC721, where the recipients are the owners of the NFTS /// only the owner can unlock the tokens based on the defined schedule that all NFT lockups adhere to /// There is a specific admin address that can adjust the parameters before the token unlocks have started /// and the contract can be setup with a blank parameter set that can be set by the admin after the fact /// @dev this contract can interact with ERC20Votes interfaces so that each recipient can delegate or participate in onchain DAO governance with their tokens while they are locked contract SingleTokenLockups is ERC721Enumerable, ReentrancyGuard { /**EVENTS ************************************************************************************************************************/ event LockupCreated(uint256 tokenId, address recipient, uint256 amount, uint256 rate); event LockupDelegated(uint256 tokenId, address delegatee, address votingVault); event TokensUnlocked(uint256 tokenId, uint256 unlockedAmount, uint256 remainingAmount, uint256 resetTime); event TokensStaked(uint256 tokenId, uint256 stakeAmount, address beneficiary); event LockupCancelled(uint256 tokenId); event StartAndCliffSet(uint256 start, uint256 cliff); event TransferabilityChanged(bool transferable); event AdminChanged(address admin); event ClaimContractSet(address claimContract); event StakingContractSet(address stakingContract); /******GLOBAL VARIABLES********************************************************************************************************** */ /// @notice _tokenIds is used for the NFT token IDs that is mapped to the amount and rate of the lockup uint256 internal _tokenIds; /// @notice token is the address of the ERC20 token that is being locked, only allows for one ERC20 to interact with a singleton contract address public token; /// @notice admin is the address that can adjust the parameters of the lockups before the start time, transferability, set the staking contract and claim contract address public admin; /// @notice address who deployed this contract - used to link the claim contract address internal _deployer; /// @notice stakingContract is the address of the staking contract that the tokens can be staked to after they are unlocked address public stakingContract; /// @notice claimContract is the address of the claim campaigns contract that is used for mass airdrops to many recipients to claim locked tokens address public claimContract; /// @notice a special adapter for the claimContract that allows this contract to interface with the claim campaigns contract ClaimHandler public claimHandler; /// @notice defines whether the NFTs are transferable or not, can be set by the admin at any time to true or false bool public transferable; /// @notice details of the lockup schedule that all NFTs adhere to /// start is the timestamp that the lockups start and tokens begin to unlock / vest uint256 public start; /// cliff is an optional parameter after the start date when tokens will unlock in a single discrete cliff time /// Tokens will begin to unlock on the start time, but if the cliff is set after the start, then no tokens unlock until the cliff time, /// whereupon all tokens that have vested from start to cliff will unlock in a big chunk on that date uint256 public cliff; /// period is the amount of time between discrete unlocks. Unlocks that are "streaming" or "linear" would use 1 here, where tokens will unlock every second /// a period of 86400 would unlock tokens every day, 604800 would unlock tokens every week, and generally 2,628,000 would unlock tokens every month uint256 public period; /// @notice lockups is the struct that uniquely defines each individual lockup, defined by the following parameters /// @param amount is the current amount of tokens locked in the mapped NFT. The amount gets updated each time tokens are unlocked, so the originally total is not stored only the current up to date locked amount /// @param rate is the amount of tokens that unlock in the given period of time /// @param resetTime is the timestamp when tokens have most recently been unlocked. This is set to the start time initially /// but is required so that each time an individual NFT is unlocked this time resets to record the most recent unlock time to recalibrate the lockup schedule for the individual NFT struct Lockup { uint256 amount; uint256 rate; uint256 resetTime; } /// @notice lockups is the mapping of the NFT token ID to the lockup struct that defines the lockup schedule for each individual NFT mapping(uint256 => Lockup) public lockups; /// @notice votingVaults is the mapping of the NFT token ID to the address of the VotingVault contract that holds the locked tokens for ERC20Votes delegation purposes mapping(uint256 => address) public votingVaults; /******CONSTRUCTOR************************************************************************ **********************************/ /// @notice the constructor sets the initial parameters of the lockup schedule and the admin address, though many of these are optional and can be set to 0 to be set at a later date /// @param _token is the address of the ERC20 token that is being locked /// @param _admin is the address that can adjust the parameters of the lockups before the start time, transferability, set the staking contract and claim contract /// @param _transferable is the boolean that defines whether the NFTs are transferable or not, can be set by the admin at any time to true or false /// @param _start is the timestamp that the lockups start and tokens begin to unlock / vest - this can be set to 0 if the admin wants to set it later /// @param _cliff is an optional parameter after the start date when tokens will unlock in a single discrete cliff time - this can be set to 0 if the admin wants to set it later /// @param _period is the amount of time between discrete unlocks /// @param _name is the name of the NFT token - just for metadata it has no financial implications /// @param _symbol is the symbol of the NFT token - just for metadata it has no financial implications constructor( address _token, address _admin, bool _transferable, uint256 _start, uint256 _cliff, uint256 _period, string memory _name, string memory _symbol ) ERC721(_name, _symbol) { require(_token != address(0), 'Token cannot be 0 address'); require(_admin != address(0), 'Admin cannot be 0 address'); require(_period > 0, 'Period cannot be 0'); require((_start > 0 && _cliff >= _start) || (_start == 0 && _cliff == 0), 'Start and cliff must be set together'); token = _token; admin = _admin; _deployer = msg.sender; transferable = _transferable; start = _start; cliff = _cliff; period = _period; claimHandler = new ClaimHandler(_token); } /******MODIFIERS******************************************************************************************************* */ /// @notice modifier for admin functions that only allows the admin to call the function modifier onlyAdmin() { require(msg.sender == admin, '!Admin'); _; } /// @notice modifier for owner functions that only allows the owner of the NFT to call the function modifier onlyOwner(uint256 tokenId) { require(ownerOf(tokenId) == msg.sender, '!Owner'); _; } /// @notice function to set the claim contract address by the admin /// @param _claimContract is the address of the claim contract /// @dev this can Only be set once - it cannot be done multiple times function setClaimContract(address _claimContract) external { require(msg.sender == _deployer || msg.sender == admin, '!Deployer|Admin'); require(claimContract == address(0), 'Claim contract already set'); claimContract = _claimContract; claimHandler.setClaimContract(_claimContract); emit ClaimContractSet(_claimContract); } /******BASIC NFT TOKEN FUNCTIONS************************************************************************ *********************/ /// @notice function to increment the tokenId internally when a new NFT is minted /// @dev this returns the current tokenId to be used when minting, by incrementing first and then mintning to the next tokenId in order function _incrementTokenId() internal returns (uint256) { _tokenIds++; return _tokenIds; } /// @notice function to get the current running total of tokenId, useful for when totalSupply does not match function currentTokenId() public view returns (uint256) { return _tokenIds; } /******VIEW METHODS********************************************************************************************************** */ /// @notice function to get the balance of the locked tokens for a given NFT token ID at a given timestamp /// @param tokenId is the NFT token ID that is being queried /// @param timestamp is the timestamp that the balance is being queried for /// @return unlockedBalance is the amount of tokens that have unlocked at the given timestamp /// @return lockedBalance is the amount of tokens that are still locked at the given timestamp /// @return unlockTime is the timestamp of the reset time function balanceOfLockup( uint256 tokenId, uint256 timestamp ) public view returns (uint256 unlockedBalance, uint256 lockedBalance, uint256 unlockTime) { require(startCliffSet(), 'Start and cliff not set'); Lockup memory lock = lockups[tokenId]; uint256 resetTime = lock.resetTime == 0 ? start : lock.resetTime; (unlockedBalance, lockedBalance, unlockTime) = TimelockLibrary.balanceAtTime( resetTime, cliff, lock.amount, lock.rate, period, timestamp ); } /// @notice function to get the initial global unlock - when all tokens have their first unlock event or timestamp function initialUnlock() public view returns (uint256) { require(startCliffSet(), 'Start and cliff not set'); return TimelockLibrary.initialUnlock(start, cliff, period); } /****EXTERNAL CREATE METHODS**********************************************************************************************************/ /// @notice function to create a lockup for a single recipient with a single lockup schedule /// @param recipient is the address of the recipient that will own the NFT /// @param amount is the amount of tokens that will be locked in the NFT /// @param rate is the amount of tokens that will unlock in the given period of time /// @return tokenId is the NFT token ID that is created and minted to the recipient /// @dev this function calls the internal _createLockup function to do all of the token transfers, minting and storage updates + events function createLockup(address recipient, uint256 amount, uint256 rate) external nonReentrant returns (uint256 tokenId) { // pull tokens from sender into contract tokenId = _createLockup(recipient, amount, rate); } /// @notice function to create many lockups for many recipients with many lockup schedules /// @param recipients is the array of addresses of the recipients that will own the NFTs /// @param amounts is the array of amounts of tokens that will be locked in the NFTs /// @param rates is the array of amounts of tokens that will unlock in the given period of time /// @return tokenIds is the array of NFT token IDs that are created and minted to the recipients /// @dev this function calls the internal _createLockup function to do all of the token transfers, minting and storage updates + events function createLockups( address[] memory recipients, uint256[] memory amounts, uint256[] memory rates ) external nonReentrant returns (uint256[] memory tokenIds) { require(recipients.length == amounts.length && amounts.length == rates.length, 'Array lengths must match'); tokenIds = new uint256[](recipients.length); for (uint256 i; i < recipients.length; i++) { tokenIds[i] = _createLockup(recipients[i], amounts[i], rates[i]); } } /// @notice function to create a lockup for a single recipient with a single lockup schedule and delegate the locked tokens, creating a VotingVault in the process /// @param recipient is the address of the recipient that will own the NFT /// @param amount is the amount of tokens that will be locked in the NFT /// @param rate is the amount of tokens that will unlock in the given period of time /// @param delegatee is the address of the delegatee, where tokens will be delegated to from the created voting vault /// @return tokenId is the NFT token ID that is created and minted to the recipient /// @return vault is the address of the voting vault that holds the locked tokens and is delegated to the delegatee /// @dev this function calls the internal _createLockup function to do all of the token transfers, minting and storage updates + events /// and then calls the internal _delegate function to create the voting vault and delegate the tokens to the delegatee function createLockupWithDelegation( address recipient, uint256 amount, uint256 rate, address delegatee ) external nonReentrant returns (uint256 tokenId, address vault) { tokenId = _createLockup(recipient, amount, rate); vault = _delegate(tokenId, delegatee); } /// @notice function to create many lockups for many recipients with many lockup schedules and delegate the locked tokens, creating a VotingVaults in the process /// @param recipients is the array of addresses of the recipients that will own the NFTs /// @param amounts is the array of amounts of tokens that will be locked in the NFTs /// @param rates is the array of amounts of tokens that will unlock in the given period of time /// @param delegatees is the array of addresses of the delegatees, where tokens will be delegated to from the created voting vaults /// @return tokenIds is the array of NFT token IDs that are created and minted to the recipients /// @return vaults is the array of addresses of the voting vaults that hold the locked tokens and are delegated to the delegatees /// @dev this function calls the internal _createLockup function to do all of the token transfers, minting and storage updates + events /// and then calls the internal _delegate function to create the voting vaults and delegate the tokens to the delegatees function createLockupsWithDelegation( address[] memory recipients, uint256[] memory amounts, uint256[] memory rates, address[] memory delegatees ) external nonReentrant returns (uint256[] memory tokenIds, address[] memory vaults) { require( recipients.length == amounts.length && amounts.length == rates.length && rates.length == delegatees.length, 'Array lengths must match' ); tokenIds = new uint256[](recipients.length); vaults = new address[](recipients.length); for (uint256 i; i < recipients.length; i++) { tokenIds[i] = _createLockup(recipients[i], amounts[i], rates[i]); vaults[i] = _delegate(tokenIds[i], delegatees[i]); } } /******EXTERNAL NFT OWNER METHODS********************************************************************************************** */ /// @notice function to unlock the tokens for a given NFT token ID /// @param tokenId is the NFT token ID that is being unlocked /// @dev this function calls the internal _unlock function to unlock the tokens and then transfers them to the owner of the NFT /// if the tokens have been delegated, it will withdraw and send tokens from the voting vault, otherwise it will send tokens from this main escrow contract out function unlock(uint256 tokenId) external nonReentrant onlyOwner(tokenId) { (uint256 redemption, address to, address vault) = _unlock(tokenId); if (vault != address(0)) { VotingVault(vault).withdrawTokens(to, redemption); } else { TransferHelper.withdrawTokens(IERC20(token), to, redemption); } } /// @notice function to unlock the tokens for a given NFT token ID and stake them in the staking contract /// @param tokenId is the NFT token ID that is being unlocked /// @dev this function requires that the staking contract has been set, and if it has not been cannot be called /// @dev this function cannot be called if the tokens have not been delegated and are sitting in the voting vault //// this is for extra security because staking requires to call an IERC20.approve() function, which is only done in the voting vault contract so that this main contract /// never approves any external contracts with token spend allowance function unlockAndStake(uint256 tokenId, uint256 nonce, uint256 deadline, bytes memory signature) external nonReentrant onlyOwner(tokenId) { require(stakingContract != address(0), 'Staking contract not set'); require(votingVaults[tokenId] != address(0), 'vault error'); (uint256 redemption, address to, address vault) = _unlock(tokenId); VotingVault(vault).withdrawAndStake(stakingContract, to, redemption, nonce, deadline, signature); emit TokensStaked(tokenId, redemption, to); } /// @notice function to delegate the tokens for a given NFT token ID to a delegatee /// @param tokenId is the NFT token ID that is being delegated /// @param delegatee is the address of the delegatee that the tokens will be delegated to /// @return vault is the address of the voting vault that holds the locked tokens and is delegated to the delegatee /// @dev this function calls the internal _delegate function to delegate the tokens to the delegatee /// if the tokens have not been delegated yet, it will create a voting vault and delegate the tokens to the delegatee, otherwise it will redelegate from the existing voting vault function delegate(uint256 tokenId, address delegatee) external nonReentrant onlyOwner(tokenId) returns (address vault) { vault = _delegate(tokenId, delegatee); } /***********INTERNAL METHODS****************************************************************************************************** */ /// @notice function to create a lockup for a single recipient with a single lockup schedule /// @param recipient is the address of the recipient that will own the NFT /// @param amount is the amount of tokens that will be locked in the NFT /// @param rate is the amount of tokens that will unlock in the given period of time /// @return tokenId is the NFT token ID that is created and minted to the recipient /// @dev this function will pull tokens into this contract from the msg.sender. /// then it will increment the tokenIds counter, create a new lockup struct, mint the NFT to the recipient, and emit the LockupCreated event function _createLockup(address recipient, uint256 amount, uint256 rate) internal returns (uint256 tokenId) { require(recipient != address(0), '!0address'); require(amount > 0, '0 amount'); require(rate > 0, '0 rate'); TransferHelper.transferTokens(IERC20(token), msg.sender, address(this), amount); tokenId = _incrementTokenId(); lockups[tokenId] = Lockup(amount, rate, start); _safeMint(recipient, tokenId); emit LockupCreated(tokenId, recipient, amount, rate); } /// @notice function to unlock the tokens for a given NFT token ID /// @param tokenId is the NFT token ID that is being unlocked /// @return redemption is the amount of tokens that have been unlocked /// @return to is the address of the recipient that the tokens will be sent to /// @return vault is the address of the voting vault that holds the locked tokens and is delegated to the delegatee /// @dev this function can only be called if the global lock is off, otherwise the unlock is not set and nothing can be unlocked yet /// @dev this function will check the reset time initially, as if the lockup was created prior to the start time being set, then it would be 0 and needs to be updated now /// once it checks the reset time, then it can calculate the balance at the current time, and if there are tokens available to be unlocked /// it intentionally returns the redemption amount, to address and vault, because if the locked balance is 0, then the NFT is burned and the vault is deleted /// if the lockedBalance is not 0, then it will update the reset time with the most recent unlock time, and adjust the amount to equal the locked balance function _unlock(uint256 tokenId) internal returns (uint256 redemption, address to, address vault) { require(!globalLock(), 'Locked'); if (lockups[tokenId].resetTime == 0) { // check if this is the first time unlocking and the start was not set initially lockups[tokenId].resetTime = start; } Lockup memory lock = lockups[tokenId]; require(lock.resetTime >= start, 'reset error'); to = ownerOf(tokenId); vault = votingVaults[tokenId]; (uint256 unlockedBalance, uint256 lockedBalance, uint256 unlockTime) = TimelockLibrary.balanceAtTime( lock.resetTime, cliff, lock.amount, lock.rate, period, block.timestamp ); require(unlockedBalance > 0, 'No tokens to unlock'); redemption = unlockedBalance; if (lockedBalance == 0) { delete lockups[tokenId]; _burn(tokenId); } else { lockups[tokenId].amount = lockedBalance; lockups[tokenId].resetTime = unlockTime; } emit TokensUnlocked(tokenId, redemption, lockedBalance, unlockTime); } /// @notice function to delegate the tokens for a given NFT token ID to a delegatee /// @param tokenId is the NFT token ID that is being delegated /// @param delegatee is the address of the delegatee that the tokens will be delegated to /// @return vault is the address of the voting vault that holds the locked tokens and is delegated to the delegatee /// @dev if there is no voting vault created (ie votingVault == address(0)), then it will create a new one using the interanl function _setupVotingVault function _delegate(uint256 tokenId, address delegatee) internal returns (address vault) { require(delegatee != address(0), '!0address'); vault = (votingVaults[tokenId] == address(0)) ? _setupVotingVault(tokenId) : votingVaults[tokenId]; VotingVault(vault).delegateTokens(delegatee); emit LockupDelegated(tokenId, delegatee, vault); } /// @notice function to setup a new voting vault for a given NFT token ID /// @param tokenId is the NFT token ID that is being delegated /// @return vault is the address of the voting vault that holds the locked tokens and is delegated to the delegatee /// @dev this function will create a new voting vault contract, transfer the locked tokens from this contract to the voting vault function _setupVotingVault(uint256 tokenId) internal returns (address) { require(votingVaults[tokenId] == address(0)); Lockup memory lock = lockups[tokenId]; VotingVault vault = new VotingVault(token); votingVaults[tokenId] = address(vault); TransferHelper.withdrawTokens(IERC20(token), address(vault), lock.amount); return address(vault); } /***** ADMIN ONLY FUNCTIONS *****************************************************************************************************/ /// @notice function to update the start and the cliff time - this assumes it has not been set or they are set in the future /// @param newStart is the new start time /// @param newCliff is the new cliff time /// @dev as long as the current cliff and start are both set to 0, or they are both set in the future - this function can be called to update it /// @dev the cliff can not be set prior to the start time, it must be equal to or greater than the start for validity function updateStartAndCliff(uint256 newStart, uint256 newCliff) external onlyAdmin { require(globalLock(), 'Cannot change start'); require(newStart > 0); require(newCliff >= newStart, 'Cliff must be after start'); start = newStart; cliff = newCliff; emit StartAndCliffSet(newStart, newCliff); } /// @notice function to set the staking contract by the admin /// @param _stakingContract is the address of the staking contract /// @dev this can Only be set once - it cannot be done multiple times function setStakingContract(address _stakingContract) external onlyAdmin { require(stakingContract == address(0), 'Staking contract already set'); stakingContract = _stakingContract; emit StakingContractSet(_stakingContract); } /// @notice function to change the transferability of the NFTs by the admin /// @param _transferable defines whether the NFTs are transferable or not function changeTransferability(bool _transferable) external onlyAdmin { transferable = _transferable; emit TransferabilityChanged(_transferable); } /// @notice function for the admin to cancel specific lockup NFTs /// @param tokenIds is the array of NFT token IDs that are being cancelled /// @dev this could be useful in case recipients are unable to unlock their tokens or for other reasons function cancelLockups(uint256[] memory tokenIds) external onlyAdmin { require(globalLock(), 'Cannot cancel'); for (uint256 i; i < tokenIds.length; i++) { _cancelLockup(tokenIds[i]); } } /// @notice function for the admin to cancel all lockup NFTs /// @dev used in emergency where all tokens need to be unlocked and returned to the admin function cancelAllLockups() external onlyAdmin { require(globalLock(), 'Cannot cancel'); uint256 totalSupply = totalSupply(); for (uint256 i; i < totalSupply; i++) { _cancelLockup(tokenByIndex(0)); } } /// @notice internal function to cancel a lockup /// @param tokenId is the NFT token ID that is being cancelled /// @dev this will delete the lockup, burn the NFT, and return the tokens to the admin /// if the lockup has been deleted, then this will just return so that the for loop can continue to the next tokenId without reverting function _cancelLockup(uint256 tokenId) internal { Lockup memory lock = lockups[tokenId]; if (lock.amount == 0) return; address vault = votingVaults[tokenId]; if (vault != address(0)) { VotingVault(vault).withdrawTokens(admin, lock.amount); } else { TransferHelper.withdrawTokens(IERC20(token), admin, lock.amount); } delete lockups[tokenId]; _burn(tokenId); emit LockupCancelled(tokenId); } /// @notice public function of if the start and cliff have been set - important as some other functions rely on its boolean return function startCliffSet() public view returns (bool) { return start > 0 && cliff >= start; } /// @notice public function to check if the global lock is on or off function globalLock() public view returns (bool) { return TimelockLibrary.initialUnlock(start, cliff, period) > block.timestamp || !startCliffSet(); } /// @notice internal ERC721 update function - overrides to check the transfeability of the NFTs function _update(address to, uint256 tokenId, address auth) internal virtual override returns (address) { if (auth == address(0)) { return super._update(to, tokenId, auth); } else { require(transferable, '!Transferable'); return super._update(to, tokenId, auth); } } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v5.1.0) (interfaces/draft-IERC6093.sol) pragma solidity ^0.8.20; /** * @dev Standard ERC-20 Errors * Interface of the https://eips.ethereum.org/EIPS/eip-6093[ERC-6093] custom errors for ERC-20 tokens. */ interface IERC20Errors { /** * @dev Indicates an error related to the current `balance` of a `sender`. Used in transfers. * @param sender Address whose tokens are being transferred. * @param balance Current balance for the interacting account. * @param needed Minimum amount required to perform a transfer. */ error ERC20InsufficientBalance(address sender, uint256 balance, uint256 needed); /** * @dev Indicates a failure with the token `sender`. Used in transfers. * @param sender Address whose tokens are being transferred. */ error ERC20InvalidSender(address sender); /** * @dev Indicates a failure with the token `receiver`. Used in transfers. * @param receiver Address to which tokens are being transferred. */ error ERC20InvalidReceiver(address receiver); /** * @dev Indicates a failure with the `spender`’s `allowance`. Used in transfers. * @param spender Address that may be allowed to operate on tokens without being their owner. * @param allowance Amount of tokens a `spender` is allowed to operate with. * @param needed Minimum amount required to perform a transfer. */ error ERC20InsufficientAllowance(address spender, uint256 allowance, uint256 needed); /** * @dev Indicates a failure with the `approver` of a token to be approved. Used in approvals. * @param approver Address initiating an approval operation. */ error ERC20InvalidApprover(address approver); /** * @dev Indicates a failure with the `spender` to be approved. Used in approvals. * @param spender Address that may be allowed to operate on tokens without being their owner. */ error ERC20InvalidSpender(address spender); } /** * @dev Standard ERC-721 Errors * Interface of the https://eips.ethereum.org/EIPS/eip-6093[ERC-6093] custom errors for ERC-721 tokens. */ interface IERC721Errors { /** * @dev Indicates that an address can't be an owner. For example, `address(0)` is a forbidden owner in ERC-20. * Used in balance queries. * @param owner Address of the current owner of a token. */ error ERC721InvalidOwner(address owner); /** * @dev Indicates a `tokenId` whose `owner` is the zero address. * @param tokenId Identifier number of a token. */ error ERC721NonexistentToken(uint256 tokenId); /** * @dev Indicates an error related to the ownership over a particular token. Used in transfers. * @param sender Address whose tokens are being transferred. * @param tokenId Identifier number of a token. * @param owner Address of the current owner of a token. */ error ERC721IncorrectOwner(address sender, uint256 tokenId, address owner); /** * @dev Indicates a failure with the token `sender`. Used in transfers. * @param sender Address whose tokens are being transferred. */ error ERC721InvalidSender(address sender); /** * @dev Indicates a failure with the token `receiver`. Used in transfers. * @param receiver Address to which tokens are being transferred. */ error ERC721InvalidReceiver(address receiver); /** * @dev Indicates a failure with the `operator`’s approval. Used in transfers. * @param operator Address that may be allowed to operate on tokens without being their owner. * @param tokenId Identifier number of a token. */ error ERC721InsufficientApproval(address operator, uint256 tokenId); /** * @dev Indicates a failure with the `approver` of a token to be approved. Used in approvals. * @param approver Address initiating an approval operation. */ error ERC721InvalidApprover(address approver); /** * @dev Indicates a failure with the `operator` to be approved. Used in approvals. * @param operator Address that may be allowed to operate on tokens without being their owner. */ error ERC721InvalidOperator(address operator); } /** * @dev Standard ERC-1155 Errors * Interface of the https://eips.ethereum.org/EIPS/eip-6093[ERC-6093] custom errors for ERC-1155 tokens. */ interface IERC1155Errors { /** * @dev Indicates an error related to the current `balance` of a `sender`. Used in transfers. * @param sender Address whose tokens are being transferred. * @param balance Current balance for the interacting account. * @param needed Minimum amount required to perform a transfer. * @param tokenId Identifier number of a token. */ error ERC1155InsufficientBalance(address sender, uint256 balance, uint256 needed, uint256 tokenId); /** * @dev Indicates a failure with the token `sender`. Used in transfers. * @param sender Address whose tokens are being transferred. */ error ERC1155InvalidSender(address sender); /** * @dev Indicates a failure with the token `receiver`. Used in transfers. * @param receiver Address to which tokens are being transferred. */ error ERC1155InvalidReceiver(address receiver); /** * @dev Indicates a failure with the `operator`’s approval. Used in transfers. * @param operator Address that may be allowed to operate on tokens without being their owner. * @param owner Address of the current owner of a token. */ error ERC1155MissingApprovalForAll(address operator, address owner); /** * @dev Indicates a failure with the `approver` of a token to be approved. Used in approvals. * @param approver Address initiating an approval operation. */ error ERC1155InvalidApprover(address approver); /** * @dev Indicates a failure with the `operator` to be approved. Used in approvals. * @param operator Address that may be allowed to operate on tokens without being their owner. */ error ERC1155InvalidOperator(address operator); /** * @dev Indicates an array length mismatch between ids and values in a safeBatchTransferFrom operation. * Used in batch transfers. * @param idsLength Length of the array of token identifiers * @param valuesLength Length of the array of token amounts */ error ERC1155InvalidArrayLength(uint256 idsLength, uint256 valuesLength); }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v5.1.0) (interfaces/IERC1363.sol) pragma solidity ^0.8.20; import {IERC20} from "./IERC20.sol"; import {IERC165} from "./IERC165.sol"; /** * @title IERC1363 * @dev Interface of the ERC-1363 standard as defined in the https://eips.ethereum.org/EIPS/eip-1363[ERC-1363]. * * Defines an extension interface for ERC-20 tokens that supports executing code on a recipient contract * after `transfer` or `transferFrom`, or code on a spender contract after `approve`, in a single transaction. */ interface IERC1363 is IERC20, IERC165 { /* * Note: the ERC-165 identifier for this interface is 0xb0202a11. * 0xb0202a11 === * bytes4(keccak256('transferAndCall(address,uint256)')) ^ * bytes4(keccak256('transferAndCall(address,uint256,bytes)')) ^ * bytes4(keccak256('transferFromAndCall(address,address,uint256)')) ^ * bytes4(keccak256('transferFromAndCall(address,address,uint256,bytes)')) ^ * bytes4(keccak256('approveAndCall(address,uint256)')) ^ * bytes4(keccak256('approveAndCall(address,uint256,bytes)')) */ /** * @dev Moves a `value` amount of tokens from the caller's account to `to` * and then calls {IERC1363Receiver-onTransferReceived} on `to`. * @param to The address which you want to transfer to. * @param value The amount of tokens to be transferred. * @return A boolean value indicating whether the operation succeeded unless throwing. */ function transferAndCall(address to, uint256 value) external returns (bool); /** * @dev Moves a `value` amount of tokens from the caller's account to `to` * and then calls {IERC1363Receiver-onTransferReceived} on `to`. * @param to The address which you want to transfer to. * @param value The amount of tokens to be transferred. * @param data Additional data with no specified format, sent in call to `to`. * @return A boolean value indicating whether the operation succeeded unless throwing. */ function transferAndCall(address to, uint256 value, bytes calldata data) external returns (bool); /** * @dev Moves a `value` amount of tokens from `from` to `to` using the allowance mechanism * and then calls {IERC1363Receiver-onTransferReceived} on `to`. * @param from The address which you want to send tokens from. * @param to The address which you want to transfer to. * @param value The amount of tokens to be transferred. * @return A boolean value indicating whether the operation succeeded unless throwing. */ function transferFromAndCall(address from, address to, uint256 value) external returns (bool); /** * @dev Moves a `value` amount of tokens from `from` to `to` using the allowance mechanism * and then calls {IERC1363Receiver-onTransferReceived} on `to`. * @param from The address which you want to send tokens from. * @param to The address which you want to transfer to. * @param value The amount of tokens to be transferred. * @param data Additional data with no specified format, sent in call to `to`. * @return A boolean value indicating whether the operation succeeded unless throwing. */ function transferFromAndCall(address from, address to, uint256 value, bytes calldata data) external returns (bool); /** * @dev Sets a `value` amount of tokens as the allowance of `spender` over the * caller's tokens and then calls {IERC1363Spender-onApprovalReceived} on `spender`. * @param spender The address which will spend the funds. * @param value The amount of tokens to be spent. * @return A boolean value indicating whether the operation succeeded unless throwing. */ function approveAndCall(address spender, uint256 value) external returns (bool); /** * @dev Sets a `value` amount of tokens as the allowance of `spender` over the * caller's tokens and then calls {IERC1363Spender-onApprovalReceived} on `spender`. * @param spender The address which will spend the funds. * @param value The amount of tokens to be spent. * @param data Additional data with no specified format, sent in call to `spender`. * @return A boolean value indicating whether the operation succeeded unless throwing. */ function approveAndCall(address spender, uint256 value, bytes calldata data) external returns (bool); }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v5.0.0) (interfaces/IERC165.sol) pragma solidity ^0.8.20; import {IERC165} from "../utils/introspection/IERC165.sol";
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v5.0.0) (interfaces/IERC20.sol) pragma solidity ^0.8.20; import {IERC20} from "../token/ERC20/IERC20.sol";
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v5.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/ERC20/utils/SafeERC20.sol) pragma solidity ^0.8.20; import {IERC20} from "../IERC20.sol"; import {IERC1363} from "../../../interfaces/IERC1363.sol"; import {Address} from "../../../utils/Address.sol"; /** * @title SafeERC20 * @dev Wrappers around ERC-20 operations that throw on failure (when the token * contract returns false). Tokens that return no value (and instead revert or * throw on failure) are also supported, non-reverting calls are assumed to be * successful. * To use this library you can add a `using SafeERC20 for IERC20;` statement to your contract, * which allows you to call the safe operations as `token.safeTransfer(...)`, etc. */ library SafeERC20 { /** * @dev An operation with an ERC-20 token failed. */ error SafeERC20FailedOperation(address token); /** * @dev Indicates a failed `decreaseAllowance` request. */ error SafeERC20FailedDecreaseAllowance(address spender, uint256 currentAllowance, uint256 requestedDecrease); /** * @dev Transfer `value` amount of `token` from the calling contract to `to`. If `token` returns no value, * non-reverting calls are assumed to be successful. */ function safeTransfer(IERC20 token, address to, uint256 value) internal { _callOptionalReturn(token, abi.encodeCall(token.transfer, (to, value))); } /** * @dev Transfer `value` amount of `token` from `from` to `to`, spending the approval given by `from` to the * calling contract. If `token` returns no value, non-reverting calls are assumed to be successful. */ function safeTransferFrom(IERC20 token, address from, address to, uint256 value) internal { _callOptionalReturn(token, abi.encodeCall(token.transferFrom, (from, to, value))); } /** * @dev Increase the calling contract's allowance toward `spender` by `value`. If `token` returns no value, * non-reverting calls are assumed to be successful. * * IMPORTANT: If the token implements ERC-7674 (ERC-20 with temporary allowance), and if the "client" * smart contract uses ERC-7674 to set temporary allowances, then the "client" smart contract should avoid using * this function. Performing a {safeIncreaseAllowance} or {safeDecreaseAllowance} operation on a token contract * that has a non-zero temporary allowance (for that particular owner-spender) will result in unexpected behavior. */ function safeIncreaseAllowance(IERC20 token, address spender, uint256 value) internal { uint256 oldAllowance = token.allowance(address(this), spender); forceApprove(token, spender, oldAllowance + value); } /** * @dev Decrease the calling contract's allowance toward `spender` by `requestedDecrease`. If `token` returns no * value, non-reverting calls are assumed to be successful. * * IMPORTANT: If the token implements ERC-7674 (ERC-20 with temporary allowance), and if the "client" * smart contract uses ERC-7674 to set temporary allowances, then the "client" smart contract should avoid using * this function. Performing a {safeIncreaseAllowance} or {safeDecreaseAllowance} operation on a token contract * that has a non-zero temporary allowance (for that particular owner-spender) will result in unexpected behavior. */ function safeDecreaseAllowance(IERC20 token, address spender, uint256 requestedDecrease) internal { unchecked { uint256 currentAllowance = token.allowance(address(this), spender); if (currentAllowance < requestedDecrease) { revert SafeERC20FailedDecreaseAllowance(spender, currentAllowance, requestedDecrease); } forceApprove(token, spender, currentAllowance - requestedDecrease); } } /** * @dev Set the calling contract's allowance toward `spender` to `value`. If `token` returns no value, * non-reverting calls are assumed to be successful. Meant to be used with tokens that require the approval * to be set to zero before setting it to a non-zero value, such as USDT. * * NOTE: If the token implements ERC-7674, this function will not modify any temporary allowance. This function * only sets the "standard" allowance. Any temporary allowance will remain active, in addition to the value being * set here. */ function forceApprove(IERC20 token, address spender, uint256 value) internal { bytes memory approvalCall = abi.encodeCall(token.approve, (spender, value)); if (!_callOptionalReturnBool(token, approvalCall)) { _callOptionalReturn(token, abi.encodeCall(token.approve, (spender, 0))); _callOptionalReturn(token, approvalCall); } } /** * @dev Performs an {ERC1363} transferAndCall, with a fallback to the simple {ERC20} transfer if the target has no * code. This can be used to implement an {ERC721}-like safe transfer that rely on {ERC1363} checks when * targeting contracts. * * Reverts if the returned value is other than `true`. */ function transferAndCallRelaxed(IERC1363 token, address to, uint256 value, bytes memory data) internal { if (to.code.length == 0) { safeTransfer(token, to, value); } else if (!token.transferAndCall(to, value, data)) { revert SafeERC20FailedOperation(address(token)); } } /** * @dev Performs an {ERC1363} transferFromAndCall, with a fallback to the simple {ERC20} transferFrom if the target * has no code. This can be used to implement an {ERC721}-like safe transfer that rely on {ERC1363} checks when * targeting contracts. * * Reverts if the returned value is other than `true`. */ function transferFromAndCallRelaxed( IERC1363 token, address from, address to, uint256 value, bytes memory data ) internal { if (to.code.length == 0) { safeTransferFrom(token, from, to, value); } else if (!token.transferFromAndCall(from, to, value, data)) { revert SafeERC20FailedOperation(address(token)); } } /** * @dev Performs an {ERC1363} approveAndCall, with a fallback to the simple {ERC20} approve if the target has no * code. This can be used to implement an {ERC721}-like safe transfer that rely on {ERC1363} checks when * targeting contracts. * * NOTE: When the recipient address (`to`) has no code (i.e. is an EOA), this function behaves as {forceApprove}. * Opposedly, when the recipient address (`to`) has code, this function only attempts to call {ERC1363-approveAndCall} * once without retrying, and relies on the returned value to be true. * * Reverts if the returned value is other than `true`. */ function approveAndCallRelaxed(IERC1363 token, address to, uint256 value, bytes memory data) internal { if (to.code.length == 0) { forceApprove(token, to, value); } else if (!token.approveAndCall(to, value, data)) { revert SafeERC20FailedOperation(address(token)); } } /** * @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement * on the return value: the return value is optional (but if data is returned, it must not be false). * @param token The token targeted by the call. * @param data The call data (encoded using abi.encode or one of its variants). * * This is a variant of {_callOptionalReturnBool} that reverts if call fails to meet the requirements. */ function _callOptionalReturn(IERC20 token, bytes memory data) private { uint256 returnSize; uint256 returnValue; assembly ("memory-safe") { let success := call(gas(), token, 0, add(data, 0x20), mload(data), 0, 0x20) // bubble errors if iszero(success) { let ptr := mload(0x40) returndatacopy(ptr, 0, returndatasize()) revert(ptr, returndatasize()) } returnSize := returndatasize() returnValue := mload(0) } if (returnSize == 0 ? address(token).code.length == 0 : returnValue != 1) { revert SafeERC20FailedOperation(address(token)); } } /** * @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement * on the return value: the return value is optional (but if data is returned, it must not be false). * @param token The token targeted by the call. * @param data The call data (encoded using abi.encode or one of its variants). * * This is a variant of {_callOptionalReturn} that silently catches all reverts and returns a bool instead. */ function _callOptionalReturnBool(IERC20 token, bytes memory data) private returns (bool) { bool success; uint256 returnSize; uint256 returnValue; assembly ("memory-safe") { success := call(gas(), token, 0, add(data, 0x20), mload(data), 0, 0x20) returnSize := returndatasize() returnValue := mload(0) } return success && (returnSize == 0 ? address(token).code.length > 0 : returnValue == 1); } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v5.1.0) (token/ERC721/ERC721.sol) pragma solidity ^0.8.20; import {IERC721} from "./IERC721.sol"; import {IERC721Metadata} from "./extensions/IERC721Metadata.sol"; import {ERC721Utils} from "./utils/ERC721Utils.sol"; import {Context} from "../../utils/Context.sol"; import {Strings} from "../../utils/Strings.sol"; import {IERC165, ERC165} from "../../utils/introspection/ERC165.sol"; import {IERC721Errors} from "../../interfaces/draft-IERC6093.sol"; /** * @dev Implementation of https://eips.ethereum.org/EIPS/eip-721[ERC-721] Non-Fungible Token Standard, including * the Metadata extension, but not including the Enumerable extension, which is available separately as * {ERC721Enumerable}. */ abstract contract ERC721 is Context, ERC165, IERC721, IERC721Metadata, IERC721Errors { using Strings for uint256; // Token name string private _name; // Token symbol string private _symbol; mapping(uint256 tokenId => address) private _owners; mapping(address owner => uint256) private _balances; mapping(uint256 tokenId => address) private _tokenApprovals; mapping(address owner => mapping(address operator => bool)) private _operatorApprovals; /** * @dev Initializes the contract by setting a `name` and a `symbol` to the token collection. */ constructor(string memory name_, string memory symbol_) { _name = name_; _symbol = symbol_; } /** * @dev See {IERC165-supportsInterface}. */ function supportsInterface(bytes4 interfaceId) public view virtual override(ERC165, IERC165) returns (bool) { return interfaceId == type(IERC721).interfaceId || interfaceId == type(IERC721Metadata).interfaceId || super.supportsInterface(interfaceId); } /** * @dev See {IERC721-balanceOf}. */ function balanceOf(address owner) public view virtual returns (uint256) { if (owner == address(0)) { revert ERC721InvalidOwner(address(0)); } return _balances[owner]; } /** * @dev See {IERC721-ownerOf}. */ function ownerOf(uint256 tokenId) public view virtual returns (address) { return _requireOwned(tokenId); } /** * @dev See {IERC721Metadata-name}. */ function name() public view virtual returns (string memory) { return _name; } /** * @dev See {IERC721Metadata-symbol}. */ function symbol() public view virtual returns (string memory) { return _symbol; } /** * @dev See {IERC721Metadata-tokenURI}. */ function tokenURI(uint256 tokenId) public view virtual returns (string memory) { _requireOwned(tokenId); string memory baseURI = _baseURI(); return bytes(baseURI).length > 0 ? string.concat(baseURI, tokenId.toString()) : ""; } /** * @dev Base URI for computing {tokenURI}. If set, the resulting URI for each * token will be the concatenation of the `baseURI` and the `tokenId`. Empty * by default, can be overridden in child contracts. */ function _baseURI() internal view virtual returns (string memory) { return ""; } /** * @dev See {IERC721-approve}. */ function approve(address to, uint256 tokenId) public virtual { _approve(to, tokenId, _msgSender()); } /** * @dev See {IERC721-getApproved}. */ function getApproved(uint256 tokenId) public view virtual returns (address) { _requireOwned(tokenId); return _getApproved(tokenId); } /** * @dev See {IERC721-setApprovalForAll}. */ function setApprovalForAll(address operator, bool approved) public virtual { _setApprovalForAll(_msgSender(), operator, approved); } /** * @dev See {IERC721-isApprovedForAll}. */ function isApprovedForAll(address owner, address operator) public view virtual returns (bool) { return _operatorApprovals[owner][operator]; } /** * @dev See {IERC721-transferFrom}. */ function transferFrom(address from, address to, uint256 tokenId) public virtual { if (to == address(0)) { revert ERC721InvalidReceiver(address(0)); } // Setting an "auth" arguments enables the `_isAuthorized` check which verifies that the token exists // (from != 0). Therefore, it is not needed to verify that the return value is not 0 here. address previousOwner = _update(to, tokenId, _msgSender()); if (previousOwner != from) { revert ERC721IncorrectOwner(from, tokenId, previousOwner); } } /** * @dev See {IERC721-safeTransferFrom}. */ function safeTransferFrom(address from, address to, uint256 tokenId) public { safeTransferFrom(from, to, tokenId, ""); } /** * @dev See {IERC721-safeTransferFrom}. */ function safeTransferFrom(address from, address to, uint256 tokenId, bytes memory data) public virtual { transferFrom(from, to, tokenId); ERC721Utils.checkOnERC721Received(_msgSender(), from, to, tokenId, data); } /** * @dev Returns the owner of the `tokenId`. Does NOT revert if token doesn't exist * * IMPORTANT: Any overrides to this function that add ownership of tokens not tracked by the * core ERC-721 logic MUST be matched with the use of {_increaseBalance} to keep balances * consistent with ownership. The invariant to preserve is that for any address `a` the value returned by * `balanceOf(a)` must be equal to the number of tokens such that `_ownerOf(tokenId)` is `a`. */ function _ownerOf(uint256 tokenId) internal view virtual returns (address) { return _owners[tokenId]; } /** * @dev Returns the approved address for `tokenId`. Returns 0 if `tokenId` is not minted. */ function _getApproved(uint256 tokenId) internal view virtual returns (address) { return _tokenApprovals[tokenId]; } /** * @dev Returns whether `spender` is allowed to manage `owner`'s tokens, or `tokenId` in * particular (ignoring whether it is owned by `owner`). * * WARNING: This function assumes that `owner` is the actual owner of `tokenId` and does not verify this * assumption. */ function _isAuthorized(address owner, address spender, uint256 tokenId) internal view virtual returns (bool) { return spender != address(0) && (owner == spender || isApprovedForAll(owner, spender) || _getApproved(tokenId) == spender); } /** * @dev Checks if `spender` can operate on `tokenId`, assuming the provided `owner` is the actual owner. * Reverts if: * - `spender` does not have approval from `owner` for `tokenId`. * - `spender` does not have approval to manage all of `owner`'s assets. * * WARNING: This function assumes that `owner` is the actual owner of `tokenId` and does not verify this * assumption. */ function _checkAuthorized(address owner, address spender, uint256 tokenId) internal view virtual { if (!_isAuthorized(owner, spender, tokenId)) { if (owner == address(0)) { revert ERC721NonexistentToken(tokenId); } else { revert ERC721InsufficientApproval(spender, tokenId); } } } /** * @dev Unsafe write access to the balances, used by extensions that "mint" tokens using an {ownerOf} override. * * NOTE: the value is limited to type(uint128).max. This protect against _balance overflow. It is unrealistic that * a uint256 would ever overflow from increments when these increments are bounded to uint128 values. * * WARNING: Increasing an account's balance using this function tends to be paired with an override of the * {_ownerOf} function to resolve the ownership of the corresponding tokens so that balances and ownership * remain consistent with one another. */ function _increaseBalance(address account, uint128 value) internal virtual { unchecked { _balances[account] += value; } } /** * @dev Transfers `tokenId` from its current owner to `to`, or alternatively mints (or burns) if the current owner * (or `to`) is the zero address. Returns the owner of the `tokenId` before the update. * * The `auth` argument is optional. If the value passed is non 0, then this function will check that * `auth` is either the owner of the token, or approved to operate on the token (by the owner). * * Emits a {Transfer} event. * * NOTE: If overriding this function in a way that tracks balances, see also {_increaseBalance}. */ function _update(address to, uint256 tokenId, address auth) internal virtual returns (address) { address from = _ownerOf(tokenId); // Perform (optional) operator check if (auth != address(0)) { _checkAuthorized(from, auth, tokenId); } // Execute the update if (from != address(0)) { // Clear approval. No need to re-authorize or emit the Approval event _approve(address(0), tokenId, address(0), false); unchecked { _balances[from] -= 1; } } if (to != address(0)) { unchecked { _balances[to] += 1; } } _owners[tokenId] = to; emit Transfer(from, to, tokenId); return from; } /** * @dev Mints `tokenId` and transfers it to `to`. * * WARNING: Usage of this method is discouraged, use {_safeMint} whenever possible * * Requirements: * * - `tokenId` must not exist. * - `to` cannot be the zero address. * * Emits a {Transfer} event. */ function _mint(address to, uint256 tokenId) internal { if (to == address(0)) { revert ERC721InvalidReceiver(address(0)); } address previousOwner = _update(to, tokenId, address(0)); if (previousOwner != address(0)) { revert ERC721InvalidSender(address(0)); } } /** * @dev Mints `tokenId`, transfers it to `to` and checks for `to` acceptance. * * Requirements: * * - `tokenId` must not exist. * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer. * * Emits a {Transfer} event. */ function _safeMint(address to, uint256 tokenId) internal { _safeMint(to, tokenId, ""); } /** * @dev Same as {xref-ERC721-_safeMint-address-uint256-}[`_safeMint`], with an additional `data` parameter which is * forwarded in {IERC721Receiver-onERC721Received} to contract recipients. */ function _safeMint(address to, uint256 tokenId, bytes memory data) internal virtual { _mint(to, tokenId); ERC721Utils.checkOnERC721Received(_msgSender(), address(0), to, tokenId, data); } /** * @dev Destroys `tokenId`. * The approval is cleared when the token is burned. * This is an internal function that does not check if the sender is authorized to operate on the token. * * Requirements: * * - `tokenId` must exist. * * Emits a {Transfer} event. */ function _burn(uint256 tokenId) internal { address previousOwner = _update(address(0), tokenId, address(0)); if (previousOwner == address(0)) { revert ERC721NonexistentToken(tokenId); } } /** * @dev Transfers `tokenId` from `from` to `to`. * As opposed to {transferFrom}, this imposes no restrictions on msg.sender. * * Requirements: * * - `to` cannot be the zero address. * - `tokenId` token must be owned by `from`. * * Emits a {Transfer} event. */ function _transfer(address from, address to, uint256 tokenId) internal { if (to == address(0)) { revert ERC721InvalidReceiver(address(0)); } address previousOwner = _update(to, tokenId, address(0)); if (previousOwner == address(0)) { revert ERC721NonexistentToken(tokenId); } else if (previousOwner != from) { revert ERC721IncorrectOwner(from, tokenId, previousOwner); } } /** * @dev Safely transfers `tokenId` token from `from` to `to`, checking that contract recipients * are aware of the ERC-721 standard to prevent tokens from being forever locked. * * `data` is additional data, it has no specified format and it is sent in call to `to`. * * This internal function is like {safeTransferFrom} in the sense that it invokes * {IERC721Receiver-onERC721Received} on the receiver, and can be used to e.g. * implement alternative mechanisms to perform token transfer, such as signature-based. * * Requirements: * * - `tokenId` token must exist and be owned by `from`. * - `to` cannot be the zero address. * - `from` cannot be the zero address. * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer. * * Emits a {Transfer} event. */ function _safeTransfer(address from, address to, uint256 tokenId) internal { _safeTransfer(from, to, tokenId, ""); } /** * @dev Same as {xref-ERC721-_safeTransfer-address-address-uint256-}[`_safeTransfer`], with an additional `data` parameter which is * forwarded in {IERC721Receiver-onERC721Received} to contract recipients. */ function _safeTransfer(address from, address to, uint256 tokenId, bytes memory data) internal virtual { _transfer(from, to, tokenId); ERC721Utils.checkOnERC721Received(_msgSender(), from, to, tokenId, data); } /** * @dev Approve `to` to operate on `tokenId` * * The `auth` argument is optional. If the value passed is non 0, then this function will check that `auth` is * either the owner of the token, or approved to operate on all tokens held by this owner. * * Emits an {Approval} event. * * Overrides to this logic should be done to the variant with an additional `bool emitEvent` argument. */ function _approve(address to, uint256 tokenId, address auth) internal { _approve(to, tokenId, auth, true); } /** * @dev Variant of `_approve` with an optional flag to enable or disable the {Approval} event. The event is not * emitted in the context of transfers. */ function _approve(address to, uint256 tokenId, address auth, bool emitEvent) internal virtual { // Avoid reading the owner unless necessary if (emitEvent || auth != address(0)) { address owner = _requireOwned(tokenId); // We do not use _isAuthorized because single-token approvals should not be able to call approve if (auth != address(0) && owner != auth && !isApprovedForAll(owner, auth)) { revert ERC721InvalidApprover(auth); } if (emitEvent) { emit Approval(owner, to, tokenId); } } _tokenApprovals[tokenId] = to; } /** * @dev Approve `operator` to operate on all of `owner` tokens * * Requirements: * - operator can't be the address zero. * * Emits an {ApprovalForAll} event. */ function _setApprovalForAll(address owner, address operator, bool approved) internal virtual { if (operator == address(0)) { revert ERC721InvalidOperator(operator); } _operatorApprovals[owner][operator] = approved; emit ApprovalForAll(owner, operator, approved); } /** * @dev Reverts if the `tokenId` doesn't have a current owner (it hasn't been minted, or it has been burned). * Returns the owner. * * Overrides to ownership logic should be done to {_ownerOf}. */ function _requireOwned(uint256 tokenId) internal view returns (address) { address owner = _ownerOf(tokenId); if (owner == address(0)) { revert ERC721NonexistentToken(tokenId); } return owner; } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v5.1.0) (token/ERC721/extensions/ERC721Enumerable.sol) pragma solidity ^0.8.20; import {ERC721} from "../ERC721.sol"; import {IERC721Enumerable} from "./IERC721Enumerable.sol"; import {IERC165} from "../../../utils/introspection/ERC165.sol"; /** * @dev This implements an optional extension of {ERC721} defined in the ERC that adds enumerability * of all the token ids in the contract as well as all token ids owned by each account. * * CAUTION: {ERC721} extensions that implement custom `balanceOf` logic, such as {ERC721Consecutive}, * interfere with enumerability and should not be used together with {ERC721Enumerable}. */ abstract contract ERC721Enumerable is ERC721, IERC721Enumerable { mapping(address owner => mapping(uint256 index => uint256)) private _ownedTokens; mapping(uint256 tokenId => uint256) private _ownedTokensIndex; uint256[] private _allTokens; mapping(uint256 tokenId => uint256) private _allTokensIndex; /** * @dev An `owner`'s token query was out of bounds for `index`. * * NOTE: The owner being `address(0)` indicates a global out of bounds index. */ error ERC721OutOfBoundsIndex(address owner, uint256 index); /** * @dev Batch mint is not allowed. */ error ERC721EnumerableForbiddenBatchMint(); /** * @dev See {IERC165-supportsInterface}. */ function supportsInterface(bytes4 interfaceId) public view virtual override(IERC165, ERC721) returns (bool) { return interfaceId == type(IERC721Enumerable).interfaceId || super.supportsInterface(interfaceId); } /** * @dev See {IERC721Enumerable-tokenOfOwnerByIndex}. */ function tokenOfOwnerByIndex(address owner, uint256 index) public view virtual returns (uint256) { if (index >= balanceOf(owner)) { revert ERC721OutOfBoundsIndex(owner, index); } return _ownedTokens[owner][index]; } /** * @dev See {IERC721Enumerable-totalSupply}. */ function totalSupply() public view virtual returns (uint256) { return _allTokens.length; } /** * @dev See {IERC721Enumerable-tokenByIndex}. */ function tokenByIndex(uint256 index) public view virtual returns (uint256) { if (index >= totalSupply()) { revert ERC721OutOfBoundsIndex(address(0), index); } return _allTokens[index]; } /** * @dev See {ERC721-_update}. */ function _update(address to, uint256 tokenId, address auth) internal virtual override returns (address) { address previousOwner = super._update(to, tokenId, auth); if (previousOwner == address(0)) { _addTokenToAllTokensEnumeration(tokenId); } else if (previousOwner != to) { _removeTokenFromOwnerEnumeration(previousOwner, tokenId); } if (to == address(0)) { _removeTokenFromAllTokensEnumeration(tokenId); } else if (previousOwner != to) { _addTokenToOwnerEnumeration(to, tokenId); } return previousOwner; } /** * @dev Private function to add a token to this extension's ownership-tracking data structures. * @param to address representing the new owner of the given token ID * @param tokenId uint256 ID of the token to be added to the tokens list of the given address */ function _addTokenToOwnerEnumeration(address to, uint256 tokenId) private { uint256 length = balanceOf(to) - 1; _ownedTokens[to][length] = tokenId; _ownedTokensIndex[tokenId] = length; } /** * @dev Private function to add a token to this extension's token tracking data structures. * @param tokenId uint256 ID of the token to be added to the tokens list */ function _addTokenToAllTokensEnumeration(uint256 tokenId) private { _allTokensIndex[tokenId] = _allTokens.length; _allTokens.push(tokenId); } /** * @dev Private function to remove a token from this extension's ownership-tracking data structures. Note that * while the token is not assigned a new owner, the `_ownedTokensIndex` mapping is _not_ updated: this allows for * gas optimizations e.g. when performing a transfer operation (avoiding double writes). * This has O(1) time complexity, but alters the order of the _ownedTokens array. * @param from address representing the previous owner of the given token ID * @param tokenId uint256 ID of the token to be removed from the tokens list of the given address */ function _removeTokenFromOwnerEnumeration(address from, uint256 tokenId) private { // To prevent a gap in from's tokens array, we store the last token in the index of the token to delete, and // then delete the last slot (swap and pop). uint256 lastTokenIndex = balanceOf(from); uint256 tokenIndex = _ownedTokensIndex[tokenId]; mapping(uint256 index => uint256) storage _ownedTokensByOwner = _ownedTokens[from]; // When the token to delete is the last token, the swap operation is unnecessary if (tokenIndex != lastTokenIndex) { uint256 lastTokenId = _ownedTokensByOwner[lastTokenIndex]; _ownedTokensByOwner[tokenIndex] = lastTokenId; // Move the last token to the slot of the to-delete token _ownedTokensIndex[lastTokenId] = tokenIndex; // Update the moved token's index } // This also deletes the contents at the last position of the array delete _ownedTokensIndex[tokenId]; delete _ownedTokensByOwner[lastTokenIndex]; } /** * @dev Private function to remove a token from this extension's token tracking data structures. * This has O(1) time complexity, but alters the order of the _allTokens array. * @param tokenId uint256 ID of the token to be removed from the tokens list */ function _removeTokenFromAllTokensEnumeration(uint256 tokenId) private { // To prevent a gap in the tokens array, we store the last token in the index of the token to delete, and // then delete the last slot (swap and pop). uint256 lastTokenIndex = _allTokens.length - 1; uint256 tokenIndex = _allTokensIndex[tokenId]; // When the token to delete is the last token, the swap operation is unnecessary. However, since this occurs so // rarely (when the last minted token is burnt) that we still do the swap here to avoid the gas cost of adding // an 'if' statement (like in _removeTokenFromOwnerEnumeration) uint256 lastTokenId = _allTokens[lastTokenIndex]; _allTokens[tokenIndex] = lastTokenId; // Move the last token to the slot of the to-delete token _allTokensIndex[lastTokenId] = tokenIndex; // Update the moved token's index // This also deletes the contents at the last position of the array delete _allTokensIndex[tokenId]; _allTokens.pop(); } /** * See {ERC721-_increaseBalance}. We need that to account tokens that were minted in batch */ function _increaseBalance(address account, uint128 amount) internal virtual override { if (amount > 0) { revert ERC721EnumerableForbiddenBatchMint(); } super._increaseBalance(account, amount); } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v5.0.0) (token/ERC721/extensions/IERC721Enumerable.sol) pragma solidity ^0.8.20; import {IERC721} from "../IERC721.sol"; /** * @title ERC-721 Non-Fungible Token Standard, optional enumeration extension * @dev See https://eips.ethereum.org/EIPS/eip-721 */ interface IERC721Enumerable is IERC721 { /** * @dev Returns the total amount of tokens stored by the contract. */ function totalSupply() external view returns (uint256); /** * @dev Returns a token ID owned by `owner` at a given `index` of its token list. * Use along with {balanceOf} to enumerate all of ``owner``'s tokens. */ function tokenOfOwnerByIndex(address owner, uint256 index) external view returns (uint256); /** * @dev Returns a token ID at a given `index` of all the tokens stored by the contract. * Use along with {totalSupply} to enumerate all tokens. */ function tokenByIndex(uint256 index) external view returns (uint256); }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v5.0.0) (token/ERC721/extensions/IERC721Metadata.sol) pragma solidity ^0.8.20; import {IERC721} from "../IERC721.sol"; /** * @title ERC-721 Non-Fungible Token Standard, optional metadata extension * @dev See https://eips.ethereum.org/EIPS/eip-721 */ interface IERC721Metadata is IERC721 { /** * @dev Returns the token collection name. */ function name() external view returns (string memory); /** * @dev Returns the token collection symbol. */ function symbol() external view returns (string memory); /** * @dev Returns the Uniform Resource Identifier (URI) for `tokenId` token. */ function tokenURI(uint256 tokenId) external view returns (string memory); }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v5.1.0) (token/ERC721/IERC721.sol) pragma solidity ^0.8.20; import {IERC165} from "../../utils/introspection/IERC165.sol"; /** * @dev Required interface of an ERC-721 compliant contract. */ interface IERC721 is IERC165 { /** * @dev Emitted when `tokenId` token is transferred from `from` to `to`. */ event Transfer(address indexed from, address indexed to, uint256 indexed tokenId); /** * @dev Emitted when `owner` enables `approved` to manage the `tokenId` token. */ event Approval(address indexed owner, address indexed approved, uint256 indexed tokenId); /** * @dev Emitted when `owner` enables or disables (`approved`) `operator` to manage all of its assets. */ event ApprovalForAll(address indexed owner, address indexed operator, bool approved); /** * @dev Returns the number of tokens in ``owner``'s account. */ function balanceOf(address owner) external view returns (uint256 balance); /** * @dev Returns the owner of the `tokenId` token. * * Requirements: * * - `tokenId` must exist. */ function ownerOf(uint256 tokenId) external view returns (address owner); /** * @dev Safely transfers `tokenId` token from `from` to `to`. * * Requirements: * * - `from` cannot be the zero address. * - `to` cannot be the zero address. * - `tokenId` token must exist and be owned by `from`. * - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}. * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon * a safe transfer. * * Emits a {Transfer} event. */ function safeTransferFrom(address from, address to, uint256 tokenId, bytes calldata data) external; /** * @dev Safely transfers `tokenId` token from `from` to `to`, checking first that contract recipients * are aware of the ERC-721 protocol to prevent tokens from being forever locked. * * Requirements: * * - `from` cannot be the zero address. * - `to` cannot be the zero address. * - `tokenId` token must exist and be owned by `from`. * - If the caller is not `from`, it must have been allowed to move this token by either {approve} or * {setApprovalForAll}. * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon * a safe transfer. * * Emits a {Transfer} event. */ function safeTransferFrom(address from, address to, uint256 tokenId) external; /** * @dev Transfers `tokenId` token from `from` to `to`. * * WARNING: Note that the caller is responsible to confirm that the recipient is capable of receiving ERC-721 * or else they may be permanently lost. Usage of {safeTransferFrom} prevents loss, though the caller must * understand this adds an external call which potentially creates a reentrancy vulnerability. * * Requirements: * * - `from` cannot be the zero address. * - `to` cannot be the zero address. * - `tokenId` token must be owned by `from`. * - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}. * * Emits a {Transfer} event. */ function transferFrom(address from, address to, uint256 tokenId) external; /** * @dev Gives permission to `to` to transfer `tokenId` token to another account. * The approval is cleared when the token is transferred. * * Only a single account can be approved at a time, so approving the zero address clears previous approvals. * * Requirements: * * - The caller must own the token or be an approved operator. * - `tokenId` must exist. * * Emits an {Approval} event. */ function approve(address to, uint256 tokenId) external; /** * @dev Approve or remove `operator` as an operator for the caller. * Operators can call {transferFrom} or {safeTransferFrom} for any token owned by the caller. * * Requirements: * * - The `operator` cannot be the address zero. * * Emits an {ApprovalForAll} event. */ function setApprovalForAll(address operator, bool approved) external; /** * @dev Returns the account approved for `tokenId` token. * * Requirements: * * - `tokenId` must exist. */ function getApproved(uint256 tokenId) external view returns (address operator); /** * @dev Returns if the `operator` is allowed to manage all of the assets of `owner`. * * See {setApprovalForAll} */ function isApprovedForAll(address owner, address operator) external view returns (bool); }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v5.1.0) (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.1.0) (token/ERC721/utils/ERC721Utils.sol) pragma solidity ^0.8.20; import {IERC721Receiver} from "../IERC721Receiver.sol"; import {IERC721Errors} from "../../../interfaces/draft-IERC6093.sol"; /** * @dev Library that provide common ERC-721 utility functions. * * See https://eips.ethereum.org/EIPS/eip-721[ERC-721]. * * _Available since v5.1._ */ library ERC721Utils { /** * @dev Performs an acceptance check for the provided `operator` by calling {IERC721-onERC721Received} * on the `to` address. The `operator` is generally the address that initiated the token transfer (i.e. `msg.sender`). * * The acceptance call is not executed and treated as a no-op if the target address doesn't contain code (i.e. an EOA). * Otherwise, the recipient must implement {IERC721Receiver-onERC721Received} and return the acceptance magic value to accept * the transfer. */ function checkOnERC721Received( address operator, address from, address to, uint256 tokenId, bytes memory data ) internal { if (to.code.length > 0) { try IERC721Receiver(to).onERC721Received(operator, from, tokenId, data) returns (bytes4 retval) { if (retval != IERC721Receiver.onERC721Received.selector) { // Token rejected revert IERC721Errors.ERC721InvalidReceiver(to); } } catch (bytes memory reason) { if (reason.length == 0) { // non-IERC721Receiver implementer revert IERC721Errors.ERC721InvalidReceiver(to); } else { assembly ("memory-safe") { revert(add(32, reason), mload(reason)) } } } } } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v5.1.0) (utils/Address.sol) pragma solidity ^0.8.20; import {Errors} from "./Errors.sol"; /** * @dev Collection of functions related to the address type */ library Address { /** * @dev There's no code at `target` (it is not a contract). */ error AddressEmptyCode(address target); /** * @dev Replacement for Solidity's `transfer`: sends `amount` wei to * `recipient`, forwarding all available gas and reverting on errors. * * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost * of certain opcodes, possibly making contracts go over the 2300 gas limit * imposed by `transfer`, making them unable to receive funds via * `transfer`. {sendValue} removes this limitation. * * https://consensys.net/diligence/blog/2019/09/stop-using-soliditys-transfer-now/[Learn more]. * * IMPORTANT: because control is transferred to `recipient`, care must be * taken to not create reentrancy vulnerabilities. Consider using * {ReentrancyGuard} or the * https://solidity.readthedocs.io/en/v0.8.20/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. */ function sendValue(address payable recipient, uint256 amount) internal { if (address(this).balance < amount) { revert Errors.InsufficientBalance(address(this).balance, amount); } (bool success, ) = recipient.call{value: amount}(""); if (!success) { revert Errors.FailedCall(); } } /** * @dev Performs a Solidity function call using a low level `call`. A * plain `call` is an unsafe replacement for a function call: use this * function instead. * * If `target` reverts with a revert reason or custom error, it is bubbled * up by this function (like regular Solidity function calls). However, if * the call reverted with no returned reason, this function reverts with a * {Errors.FailedCall} error. * * Returns the raw returned data. To convert to the expected return value, * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. * * Requirements: * * - `target` must be a contract. * - calling `target` with `data` must not revert. */ function functionCall(address target, bytes memory data) internal returns (bytes memory) { return functionCallWithValue(target, data, 0); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but also transferring `value` wei to `target`. * * Requirements: * * - the calling contract must have an ETH balance of at least `value`. * - the called Solidity function must be `payable`. */ function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { if (address(this).balance < value) { revert Errors.InsufficientBalance(address(this).balance, value); } (bool success, bytes memory returndata) = target.call{value: value}(data); return verifyCallResultFromTarget(target, success, returndata); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but performing a static call. */ function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) { (bool success, bytes memory returndata) = target.staticcall(data); return verifyCallResultFromTarget(target, success, returndata); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but performing a delegate call. */ function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) { (bool success, bytes memory returndata) = target.delegatecall(data); return verifyCallResultFromTarget(target, success, returndata); } /** * @dev Tool to verify that a low level call to smart-contract was successful, and reverts if the target * was not a contract or bubbling up the revert reason (falling back to {Errors.FailedCall}) in case * of an unsuccessful call. */ function verifyCallResultFromTarget( address target, bool success, bytes memory returndata ) internal view returns (bytes memory) { if (!success) { _revert(returndata); } else { // only check if target is a contract if the call was successful and the return data is empty // otherwise we already know that it was a contract if (returndata.length == 0 && target.code.length == 0) { revert AddressEmptyCode(target); } return returndata; } } /** * @dev Tool to verify that a low level call was successful, and reverts if it wasn't, either by bubbling the * revert reason or with a default {Errors.FailedCall} error. */ function verifyCallResult(bool success, bytes memory returndata) internal pure returns (bytes memory) { if (!success) { _revert(returndata); } else { return returndata; } } /** * @dev Reverts with returndata if present. Otherwise reverts with {Errors.FailedCall}. */ function _revert(bytes memory returndata) private pure { // Look for revert reason and bubble it up if present if (returndata.length > 0) { // The easiest way to bubble the revert reason is using memory via assembly assembly ("memory-safe") { let returndata_size := mload(returndata) revert(add(32, returndata), returndata_size) } } else { revert Errors.FailedCall(); } } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v5.0.1) (utils/Context.sol) pragma solidity ^0.8.20; /** * @dev Provides information about the current execution context, including the * sender of the transaction and its data. While these are generally available * via msg.sender and msg.data, they should not be accessed in such a direct * manner, since when dealing with meta-transactions the account sending and * paying for execution may not be the actual sender (as far as an application * is concerned). * * This contract is only required for intermediate, library-like contracts. */ abstract contract Context { function _msgSender() internal view virtual returns (address) { return msg.sender; } function _msgData() internal view virtual returns (bytes calldata) { return msg.data; } function _contextSuffixLength() internal view virtual returns (uint256) { return 0; } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v5.1.0) (utils/Errors.sol) pragma solidity ^0.8.20; /** * @dev Collection of common custom errors used in multiple contracts * * IMPORTANT: Backwards compatibility is not guaranteed in future versions of the library. * It is recommended to avoid relying on the error API for critical functionality. * * _Available since v5.1._ */ library Errors { /** * @dev The ETH balance of the account is not enough to perform the operation. */ error InsufficientBalance(uint256 balance, uint256 needed); /** * @dev A call to an address target failed. The target may have reverted. */ error FailedCall(); /** * @dev The deployment failed. */ error FailedDeployment(); /** * @dev A necessary precompile is missing. */ error MissingPrecompile(address); }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v5.1.0) (utils/introspection/ERC165.sol) pragma solidity ^0.8.20; import {IERC165} from "./IERC165.sol"; /** * @dev Implementation of the {IERC165} interface. * * Contracts that want to implement ERC-165 should inherit from this contract and override {supportsInterface} to check * for the additional interface id that will be supported. For example: * * ```solidity * function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) { * return interfaceId == type(MyInterface).interfaceId || super.supportsInterface(interfaceId); * } * ``` */ abstract contract ERC165 is IERC165 { /** * @dev See {IERC165-supportsInterface}. */ function supportsInterface(bytes4 interfaceId) public view virtual returns (bool) { return interfaceId == type(IERC165).interfaceId; } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v5.1.0) (utils/introspection/IERC165.sol) pragma solidity ^0.8.20; /** * @dev Interface of the ERC-165 standard, as defined in the * https://eips.ethereum.org/EIPS/eip-165[ERC]. * * Implementers can declare support of contract interfaces, which can then be * queried by others ({ERC165Checker}). * * For an implementation, see {ERC165}. */ interface IERC165 { /** * @dev Returns true if this contract implements the interface defined by * `interfaceId`. See the corresponding * https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[ERC section] * to learn more about how these ids are created. * * This function call must use less than 30 000 gas. */ function supportsInterface(bytes4 interfaceId) external view returns (bool); }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v5.1.0) (utils/math/Math.sol) pragma solidity ^0.8.20; import {Panic} from "../Panic.sol"; import {SafeCast} from "./SafeCast.sol"; /** * @dev Standard math utilities missing in the Solidity language. */ library Math { enum Rounding { Floor, // Toward negative infinity Ceil, // Toward positive infinity Trunc, // Toward zero Expand // Away from zero } /** * @dev Returns the addition of two unsigned integers, with an success flag (no overflow). */ function tryAdd(uint256 a, uint256 b) internal pure returns (bool success, uint256 result) { unchecked { uint256 c = a + b; if (c < a) return (false, 0); return (true, c); } } /** * @dev Returns the subtraction of two unsigned integers, with an success flag (no overflow). */ function trySub(uint256 a, uint256 b) internal pure returns (bool success, uint256 result) { unchecked { if (b > a) return (false, 0); return (true, a - b); } } /** * @dev Returns the multiplication of two unsigned integers, with an success flag (no overflow). */ function tryMul(uint256 a, uint256 b) internal pure returns (bool success, uint256 result) { unchecked { // Gas optimization: this is cheaper than requiring 'a' not being zero, but the // benefit is lost if 'b' is also tested. // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 if (a == 0) return (true, 0); uint256 c = a * b; if (c / a != b) return (false, 0); return (true, c); } } /** * @dev Returns the division of two unsigned integers, with a success flag (no division by zero). */ function tryDiv(uint256 a, uint256 b) internal pure returns (bool success, uint256 result) { unchecked { if (b == 0) return (false, 0); return (true, a / b); } } /** * @dev Returns the remainder of dividing two unsigned integers, with a success flag (no division by zero). */ function tryMod(uint256 a, uint256 b) internal pure returns (bool success, uint256 result) { unchecked { if (b == 0) return (false, 0); return (true, a % b); } } /** * @dev Branchless ternary evaluation for `a ? b : c`. Gas costs are constant. * * IMPORTANT: This function may reduce bytecode size and consume less gas when used standalone. * However, the compiler may optimize Solidity ternary operations (i.e. `a ? b : c`) to only compute * one branch when needed, making this function more expensive. */ function ternary(bool condition, uint256 a, uint256 b) internal pure returns (uint256) { unchecked { // branchless ternary works because: // b ^ (a ^ b) == a // b ^ 0 == b return b ^ ((a ^ b) * SafeCast.toUint(condition)); } } /** * @dev Returns the largest of two numbers. */ function max(uint256 a, uint256 b) internal pure returns (uint256) { return ternary(a > b, a, b); } /** * @dev Returns the smallest of two numbers. */ function min(uint256 a, uint256 b) internal pure returns (uint256) { return ternary(a < b, a, b); } /** * @dev Returns the average of two numbers. The result is rounded towards * zero. */ function average(uint256 a, uint256 b) internal pure returns (uint256) { // (a + b) / 2 can overflow. return (a & b) + (a ^ b) / 2; } /** * @dev Returns the ceiling of the division of two numbers. * * This differs from standard division with `/` in that it rounds towards infinity instead * of rounding towards zero. */ function ceilDiv(uint256 a, uint256 b) internal pure returns (uint256) { if (b == 0) { // Guarantee the same behavior as in a regular Solidity division. Panic.panic(Panic.DIVISION_BY_ZERO); } // The following calculation ensures accurate ceiling division without overflow. // Since a is non-zero, (a - 1) / b will not overflow. // The largest possible result occurs when (a - 1) / b is type(uint256).max, // but the largest value we can obtain is type(uint256).max - 1, which happens // when a = type(uint256).max and b = 1. unchecked { return SafeCast.toUint(a > 0) * ((a - 1) / b + 1); } } /** * @dev Calculates floor(x * y / denominator) with full precision. Throws if result overflows a uint256 or * denominator == 0. * * Original credit to Remco Bloemen under MIT license (https://xn--2-umb.com/21/muldiv) with further edits by * Uniswap Labs also under MIT license. */ function mulDiv(uint256 x, uint256 y, uint256 denominator) internal pure returns (uint256 result) { unchecked { // 512-bit multiply [prod1 prod0] = x * y. Compute the product mod 2²⁵⁶ and mod 2²⁵⁶ - 1, then use // the Chinese Remainder Theorem to reconstruct the 512 bit result. The result is stored in two 256 // variables such that product = prod1 * 2²⁵⁶ + prod0. uint256 prod0 = x * y; // Least significant 256 bits of the product uint256 prod1; // Most significant 256 bits of the product assembly { let mm := mulmod(x, y, not(0)) prod1 := sub(sub(mm, prod0), lt(mm, prod0)) } // Handle non-overflow cases, 256 by 256 division. if (prod1 == 0) { // Solidity will revert if denominator == 0, unlike the div opcode on its own. // The surrounding unchecked block does not change this fact. // See https://docs.soliditylang.org/en/latest/control-structures.html#checked-or-unchecked-arithmetic. return prod0 / denominator; } // Make sure the result is less than 2²⁵⁶. Also prevents denominator == 0. if (denominator <= prod1) { Panic.panic(ternary(denominator == 0, Panic.DIVISION_BY_ZERO, Panic.UNDER_OVERFLOW)); } /////////////////////////////////////////////// // 512 by 256 division. /////////////////////////////////////////////// // Make division exact by subtracting the remainder from [prod1 prod0]. uint256 remainder; assembly { // Compute remainder using mulmod. remainder := mulmod(x, y, denominator) // Subtract 256 bit number from 512 bit number. prod1 := sub(prod1, gt(remainder, prod0)) prod0 := sub(prod0, remainder) } // Factor powers of two out of denominator and compute largest power of two divisor of denominator. // Always >= 1. See https://cs.stackexchange.com/q/138556/92363. uint256 twos = denominator & (0 - denominator); assembly { // Divide denominator by twos. denominator := div(denominator, twos) // Divide [prod1 prod0] by twos. prod0 := div(prod0, twos) // Flip twos such that it is 2²⁵⁶ / twos. If twos is zero, then it becomes one. twos := add(div(sub(0, twos), twos), 1) } // Shift in bits from prod1 into prod0. prod0 |= prod1 * twos; // Invert denominator mod 2²⁵⁶. Now that denominator is an odd number, it has an inverse modulo 2²⁵⁶ such // that denominator * inv ≡ 1 mod 2²⁵⁶. Compute the inverse by starting with a seed that is correct for // four bits. That is, denominator * inv ≡ 1 mod 2⁴. uint256 inverse = (3 * denominator) ^ 2; // Use the Newton-Raphson iteration to improve the precision. Thanks to Hensel's lifting lemma, this also // works in modular arithmetic, doubling the correct bits in each step. inverse *= 2 - denominator * inverse; // inverse mod 2⁸ inverse *= 2 - denominator * inverse; // inverse mod 2¹⁶ inverse *= 2 - denominator * inverse; // inverse mod 2³² inverse *= 2 - denominator * inverse; // inverse mod 2⁶⁴ inverse *= 2 - denominator * inverse; // inverse mod 2¹²⁸ inverse *= 2 - denominator * inverse; // inverse mod 2²⁵⁶ // Because the division is now exact we can divide by multiplying with the modular inverse of denominator. // This will give us the correct result modulo 2²⁵⁶. Since the preconditions guarantee that the outcome is // less than 2²⁵⁶, this is the final result. We don't need to compute the high bits of the result and prod1 // is no longer required. result = prod0 * inverse; return result; } } /** * @dev Calculates x * y / denominator with full precision, following the selected rounding direction. */ function mulDiv(uint256 x, uint256 y, uint256 denominator, Rounding rounding) internal pure returns (uint256) { return mulDiv(x, y, denominator) + SafeCast.toUint(unsignedRoundsUp(rounding) && mulmod(x, y, denominator) > 0); } /** * @dev Calculate the modular multiplicative inverse of a number in Z/nZ. * * If n is a prime, then Z/nZ is a field. In that case all elements are inversible, except 0. * If n is not a prime, then Z/nZ is not a field, and some elements might not be inversible. * * If the input value is not inversible, 0 is returned. * * NOTE: If you know for sure that n is (big) a prime, it may be cheaper to use Fermat's little theorem and get the * inverse using `Math.modExp(a, n - 2, n)`. See {invModPrime}. */ function invMod(uint256 a, uint256 n) internal pure returns (uint256) { unchecked { if (n == 0) return 0; // The inverse modulo is calculated using the Extended Euclidean Algorithm (iterative version) // Used to compute integers x and y such that: ax + ny = gcd(a, n). // When the gcd is 1, then the inverse of a modulo n exists and it's x. // ax + ny = 1 // ax = 1 + (-y)n // ax ≡ 1 (mod n) # x is the inverse of a modulo n // If the remainder is 0 the gcd is n right away. uint256 remainder = a % n; uint256 gcd = n; // Therefore the initial coefficients are: // ax + ny = gcd(a, n) = n // 0a + 1n = n int256 x = 0; int256 y = 1; while (remainder != 0) { uint256 quotient = gcd / remainder; (gcd, remainder) = ( // The old remainder is the next gcd to try. remainder, // Compute the next remainder. // Can't overflow given that (a % gcd) * (gcd // (a % gcd)) <= gcd // where gcd is at most n (capped to type(uint256).max) gcd - remainder * quotient ); (x, y) = ( // Increment the coefficient of a. y, // Decrement the coefficient of n. // Can overflow, but the result is casted to uint256 so that the // next value of y is "wrapped around" to a value between 0 and n - 1. x - y * int256(quotient) ); } if (gcd != 1) return 0; // No inverse exists. return ternary(x < 0, n - uint256(-x), uint256(x)); // Wrap the result if it's negative. } } /** * @dev Variant of {invMod}. More efficient, but only works if `p` is known to be a prime greater than `2`. * * From https://en.wikipedia.org/wiki/Fermat%27s_little_theorem[Fermat's little theorem], we know that if p is * prime, then `a**(p-1) ≡ 1 mod p`. As a consequence, we have `a * a**(p-2) ≡ 1 mod p`, which means that * `a**(p-2)` is the modular multiplicative inverse of a in Fp. * * NOTE: this function does NOT check that `p` is a prime greater than `2`. */ function invModPrime(uint256 a, uint256 p) internal view returns (uint256) { unchecked { return Math.modExp(a, p - 2, p); } } /** * @dev Returns the modular exponentiation of the specified base, exponent and modulus (b ** e % m) * * Requirements: * - modulus can't be zero * - underlying staticcall to precompile must succeed * * IMPORTANT: The result is only valid if the underlying call succeeds. When using this function, make * sure the chain you're using it on supports the precompiled contract for modular exponentiation * at address 0x05 as specified in https://eips.ethereum.org/EIPS/eip-198[EIP-198]. Otherwise, * the underlying function will succeed given the lack of a revert, but the result may be incorrectly * interpreted as 0. */ function modExp(uint256 b, uint256 e, uint256 m) internal view returns (uint256) { (bool success, uint256 result) = tryModExp(b, e, m); if (!success) { Panic.panic(Panic.DIVISION_BY_ZERO); } return result; } /** * @dev Returns the modular exponentiation of the specified base, exponent and modulus (b ** e % m). * It includes a success flag indicating if the operation succeeded. Operation will be marked as failed if trying * to operate modulo 0 or if the underlying precompile reverted. * * IMPORTANT: The result is only valid if the success flag is true. When using this function, make sure the chain * you're using it on supports the precompiled contract for modular exponentiation at address 0x05 as specified in * https://eips.ethereum.org/EIPS/eip-198[EIP-198]. Otherwise, the underlying function will succeed given the lack * of a revert, but the result may be incorrectly interpreted as 0. */ function tryModExp(uint256 b, uint256 e, uint256 m) internal view returns (bool success, uint256 result) { if (m == 0) return (false, 0); assembly ("memory-safe") { let ptr := mload(0x40) // | Offset | Content | Content (Hex) | // |-----------|------------|--------------------------------------------------------------------| // | 0x00:0x1f | size of b | 0x0000000000000000000000000000000000000000000000000000000000000020 | // | 0x20:0x3f | size of e | 0x0000000000000000000000000000000000000000000000000000000000000020 | // | 0x40:0x5f | size of m | 0x0000000000000000000000000000000000000000000000000000000000000020 | // | 0x60:0x7f | value of b | 0x<.............................................................b> | // | 0x80:0x9f | value of e | 0x<.............................................................e> | // | 0xa0:0xbf | value of m | 0x<.............................................................m> | mstore(ptr, 0x20) mstore(add(ptr, 0x20), 0x20) mstore(add(ptr, 0x40), 0x20) mstore(add(ptr, 0x60), b) mstore(add(ptr, 0x80), e) mstore(add(ptr, 0xa0), m) // Given the result < m, it's guaranteed to fit in 32 bytes, // so we can use the memory scratch space located at offset 0. success := staticcall(gas(), 0x05, ptr, 0xc0, 0x00, 0x20) result := mload(0x00) } } /** * @dev Variant of {modExp} that supports inputs of arbitrary length. */ function modExp(bytes memory b, bytes memory e, bytes memory m) internal view returns (bytes memory) { (bool success, bytes memory result) = tryModExp(b, e, m); if (!success) { Panic.panic(Panic.DIVISION_BY_ZERO); } return result; } /** * @dev Variant of {tryModExp} that supports inputs of arbitrary length. */ function tryModExp( bytes memory b, bytes memory e, bytes memory m ) internal view returns (bool success, bytes memory result) { if (_zeroBytes(m)) return (false, new bytes(0)); uint256 mLen = m.length; // Encode call args in result and move the free memory pointer result = abi.encodePacked(b.length, e.length, mLen, b, e, m); assembly ("memory-safe") { let dataPtr := add(result, 0x20) // Write result on top of args to avoid allocating extra memory. success := staticcall(gas(), 0x05, dataPtr, mload(result), dataPtr, mLen) // Overwrite the length. // result.length > returndatasize() is guaranteed because returndatasize() == m.length mstore(result, mLen) // Set the memory pointer after the returned data. mstore(0x40, add(dataPtr, mLen)) } } /** * @dev Returns whether the provided byte array is zero. */ function _zeroBytes(bytes memory byteArray) private pure returns (bool) { for (uint256 i = 0; i < byteArray.length; ++i) { if (byteArray[i] != 0) { return false; } } return true; } /** * @dev Returns the square root of a number. If the number is not a perfect square, the value is rounded * towards zero. * * This method is based on Newton's method for computing square roots; the algorithm is restricted to only * using integer operations. */ function sqrt(uint256 a) internal pure returns (uint256) { unchecked { // Take care of easy edge cases when a == 0 or a == 1 if (a <= 1) { return a; } // In this function, we use Newton's method to get a root of `f(x) := x² - a`. It involves building a // sequence x_n that converges toward sqrt(a). For each iteration x_n, we also define the error between // the current value as `ε_n = | x_n - sqrt(a) |`. // // For our first estimation, we consider `e` the smallest power of 2 which is bigger than the square root // of the target. (i.e. `2**(e-1) ≤ sqrt(a) < 2**e`). We know that `e ≤ 128` because `(2¹²⁸)² = 2²⁵⁶` is // bigger than any uint256. // // By noticing that // `2**(e-1) ≤ sqrt(a) < 2**e → (2**(e-1))² ≤ a < (2**e)² → 2**(2*e-2) ≤ a < 2**(2*e)` // we can deduce that `e - 1` is `log2(a) / 2`. We can thus compute `x_n = 2**(e-1)` using a method similar // to the msb function. uint256 aa = a; uint256 xn = 1; if (aa >= (1 << 128)) { aa >>= 128; xn <<= 64; } if (aa >= (1 << 64)) { aa >>= 64; xn <<= 32; } if (aa >= (1 << 32)) { aa >>= 32; xn <<= 16; } if (aa >= (1 << 16)) { aa >>= 16; xn <<= 8; } if (aa >= (1 << 8)) { aa >>= 8; xn <<= 4; } if (aa >= (1 << 4)) { aa >>= 4; xn <<= 2; } if (aa >= (1 << 2)) { xn <<= 1; } // We now have x_n such that `x_n = 2**(e-1) ≤ sqrt(a) < 2**e = 2 * x_n`. This implies ε_n ≤ 2**(e-1). // // We can refine our estimation by noticing that the middle of that interval minimizes the error. // If we move x_n to equal 2**(e-1) + 2**(e-2), then we reduce the error to ε_n ≤ 2**(e-2). // This is going to be our x_0 (and ε_0) xn = (3 * xn) >> 1; // ε_0 := | x_0 - sqrt(a) | ≤ 2**(e-2) // From here, Newton's method give us: // x_{n+1} = (x_n + a / x_n) / 2 // // One should note that: // x_{n+1}² - a = ((x_n + a / x_n) / 2)² - a // = ((x_n² + a) / (2 * x_n))² - a // = (x_n⁴ + 2 * a * x_n² + a²) / (4 * x_n²) - a // = (x_n⁴ + 2 * a * x_n² + a² - 4 * a * x_n²) / (4 * x_n²) // = (x_n⁴ - 2 * a * x_n² + a²) / (4 * x_n²) // = (x_n² - a)² / (2 * x_n)² // = ((x_n² - a) / (2 * x_n))² // ≥ 0 // Which proves that for all n ≥ 1, sqrt(a) ≤ x_n // // This gives us the proof of quadratic convergence of the sequence: // ε_{n+1} = | x_{n+1} - sqrt(a) | // = | (x_n + a / x_n) / 2 - sqrt(a) | // = | (x_n² + a - 2*x_n*sqrt(a)) / (2 * x_n) | // = | (x_n - sqrt(a))² / (2 * x_n) | // = | ε_n² / (2 * x_n) | // = ε_n² / | (2 * x_n) | // // For the first iteration, we have a special case where x_0 is known: // ε_1 = ε_0² / | (2 * x_0) | // ≤ (2**(e-2))² / (2 * (2**(e-1) + 2**(e-2))) // ≤ 2**(2*e-4) / (3 * 2**(e-1)) // ≤ 2**(e-3) / 3 // ≤ 2**(e-3-log2(3)) // ≤ 2**(e-4.5) // // For the following iterations, we use the fact that, 2**(e-1) ≤ sqrt(a) ≤ x_n: // ε_{n+1} = ε_n² / | (2 * x_n) | // ≤ (2**(e-k))² / (2 * 2**(e-1)) // ≤ 2**(2*e-2*k) / 2**e // ≤ 2**(e-2*k) xn = (xn + a / xn) >> 1; // ε_1 := | x_1 - sqrt(a) | ≤ 2**(e-4.5) -- special case, see above xn = (xn + a / xn) >> 1; // ε_2 := | x_2 - sqrt(a) | ≤ 2**(e-9) -- general case with k = 4.5 xn = (xn + a / xn) >> 1; // ε_3 := | x_3 - sqrt(a) | ≤ 2**(e-18) -- general case with k = 9 xn = (xn + a / xn) >> 1; // ε_4 := | x_4 - sqrt(a) | ≤ 2**(e-36) -- general case with k = 18 xn = (xn + a / xn) >> 1; // ε_5 := | x_5 - sqrt(a) | ≤ 2**(e-72) -- general case with k = 36 xn = (xn + a / xn) >> 1; // ε_6 := | x_6 - sqrt(a) | ≤ 2**(e-144) -- general case with k = 72 // Because e ≤ 128 (as discussed during the first estimation phase), we know have reached a precision // ε_6 ≤ 2**(e-144) < 1. Given we're operating on integers, then we can ensure that xn is now either // sqrt(a) or sqrt(a) + 1. return xn - SafeCast.toUint(xn > a / xn); } } /** * @dev Calculates sqrt(a), following the selected rounding direction. */ function sqrt(uint256 a, Rounding rounding) internal pure returns (uint256) { unchecked { uint256 result = sqrt(a); return result + SafeCast.toUint(unsignedRoundsUp(rounding) && result * result < a); } } /** * @dev Return the log in base 2 of a positive value rounded towards zero. * Returns 0 if given 0. */ function log2(uint256 value) internal pure returns (uint256) { uint256 result = 0; uint256 exp; unchecked { exp = 128 * SafeCast.toUint(value > (1 << 128) - 1); value >>= exp; result += exp; exp = 64 * SafeCast.toUint(value > (1 << 64) - 1); value >>= exp; result += exp; exp = 32 * SafeCast.toUint(value > (1 << 32) - 1); value >>= exp; result += exp; exp = 16 * SafeCast.toUint(value > (1 << 16) - 1); value >>= exp; result += exp; exp = 8 * SafeCast.toUint(value > (1 << 8) - 1); value >>= exp; result += exp; exp = 4 * SafeCast.toUint(value > (1 << 4) - 1); value >>= exp; result += exp; exp = 2 * SafeCast.toUint(value > (1 << 2) - 1); value >>= exp; result += exp; result += SafeCast.toUint(value > 1); } return result; } /** * @dev Return the log in base 2, following the selected rounding direction, of a positive value. * Returns 0 if given 0. */ function log2(uint256 value, Rounding rounding) internal pure returns (uint256) { unchecked { uint256 result = log2(value); return result + SafeCast.toUint(unsignedRoundsUp(rounding) && 1 << result < value); } } /** * @dev Return the log in base 10 of a positive value rounded towards zero. * Returns 0 if given 0. */ function log10(uint256 value) internal pure returns (uint256) { uint256 result = 0; unchecked { if (value >= 10 ** 64) { value /= 10 ** 64; result += 64; } if (value >= 10 ** 32) { value /= 10 ** 32; result += 32; } if (value >= 10 ** 16) { value /= 10 ** 16; result += 16; } if (value >= 10 ** 8) { value /= 10 ** 8; result += 8; } if (value >= 10 ** 4) { value /= 10 ** 4; result += 4; } if (value >= 10 ** 2) { value /= 10 ** 2; result += 2; } if (value >= 10 ** 1) { result += 1; } } return result; } /** * @dev Return the log in base 10, following the selected rounding direction, of a positive value. * Returns 0 if given 0. */ function log10(uint256 value, Rounding rounding) internal pure returns (uint256) { unchecked { uint256 result = log10(value); return result + SafeCast.toUint(unsignedRoundsUp(rounding) && 10 ** result < value); } } /** * @dev Return the log in base 256 of a positive value rounded towards zero. * Returns 0 if given 0. * * Adding one to the result gives the number of pairs of hex symbols needed to represent `value` as a hex string. */ function log256(uint256 value) internal pure returns (uint256) { uint256 result = 0; uint256 isGt; unchecked { isGt = SafeCast.toUint(value > (1 << 128) - 1); value >>= isGt * 128; result += isGt * 16; isGt = SafeCast.toUint(value > (1 << 64) - 1); value >>= isGt * 64; result += isGt * 8; isGt = SafeCast.toUint(value > (1 << 32) - 1); value >>= isGt * 32; result += isGt * 4; isGt = SafeCast.toUint(value > (1 << 16) - 1); value >>= isGt * 16; result += isGt * 2; result += SafeCast.toUint(value > (1 << 8) - 1); } return result; } /** * @dev Return the log in base 256, following the selected rounding direction, of a positive value. * Returns 0 if given 0. */ function log256(uint256 value, Rounding rounding) internal pure returns (uint256) { unchecked { uint256 result = log256(value); return result + SafeCast.toUint(unsignedRoundsUp(rounding) && 1 << (result << 3) < value); } } /** * @dev Returns whether a provided rounding mode is considered rounding up for unsigned integers. */ function unsignedRoundsUp(Rounding rounding) internal pure returns (bool) { return uint8(rounding) % 2 == 1; } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v5.1.0) (utils/math/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.1.0) (utils/Strings.sol) pragma solidity ^0.8.20; import {Math} from "./math/Math.sol"; import {SignedMath} from "./math/SignedMath.sol"; /** * @dev String operations. */ library Strings { bytes16 private constant HEX_DIGITS = "0123456789abcdef"; uint8 private constant ADDRESS_LENGTH = 20; /** * @dev The `value` string doesn't fit in the specified `length`. */ error StringsInsufficientHexLength(uint256 value, uint256 length); /** * @dev Converts a `uint256` to its ASCII `string` decimal representation. */ function toString(uint256 value) internal pure returns (string memory) { unchecked { uint256 length = Math.log10(value) + 1; string memory buffer = new string(length); uint256 ptr; assembly ("memory-safe") { ptr := add(buffer, add(32, length)) } while (true) { ptr--; assembly ("memory-safe") { mstore8(ptr, byte(mod(value, 10), HEX_DIGITS)) } value /= 10; if (value == 0) break; } return buffer; } } /** * @dev Converts a `int256` to its ASCII `string` decimal representation. */ function toStringSigned(int256 value) internal pure returns (string memory) { return string.concat(value < 0 ? "-" : "", toString(SignedMath.abs(value))); } /** * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation. */ function toHexString(uint256 value) internal pure returns (string memory) { unchecked { return toHexString(value, Math.log256(value) + 1); } } /** * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length. */ function toHexString(uint256 value, uint256 length) internal pure returns (string memory) { uint256 localValue = value; bytes memory buffer = new bytes(2 * length + 2); buffer[0] = "0"; buffer[1] = "x"; for (uint256 i = 2 * length + 1; i > 1; --i) { buffer[i] = HEX_DIGITS[localValue & 0xf]; localValue >>= 4; } if (localValue != 0) { revert StringsInsufficientHexLength(value, length); } return string(buffer); } /** * @dev Converts an `address` with fixed length of 20 bytes to its not checksummed ASCII `string` hexadecimal * representation. */ function toHexString(address addr) internal pure returns (string memory) { return toHexString(uint256(uint160(addr)), ADDRESS_LENGTH); } /** * @dev Converts an `address` with fixed length of 20 bytes to its checksummed ASCII `string` hexadecimal * representation, according to EIP-55. */ function toChecksumHexString(address addr) internal pure returns (string memory) { bytes memory buffer = bytes(toHexString(addr)); // hash the hex part of buffer (skip length + 2 bytes, length 40) uint256 hashValue; assembly ("memory-safe") { hashValue := shr(96, keccak256(add(buffer, 0x22), 40)) } for (uint256 i = 41; i > 1; --i) { // possible values for buffer[i] are 48 (0) to 57 (9) and 97 (a) to 102 (f) if (hashValue & 0xf > 7 && uint8(buffer[i]) > 96) { // case shift by xoring with 0x20 buffer[i] ^= 0x20; } hashValue >>= 4; } return string(buffer); } /** * @dev Returns true if the two strings are equal. */ function equal(string memory a, string memory b) internal pure returns (bool) { return bytes(a).length == bytes(b).length && keccak256(bytes(a)) == keccak256(bytes(b)); } }
// contract to handle the interaction between the delegated claim campaigns and the token lockups // SPDX-License-Identifier: BUSL-1.1 pragma solidity 0.8.28; import './libraries/TransferHelper.sol'; import './interfaces/ITokenLockups.sol'; import '@openzeppelin/contracts/utils/ReentrancyGuard.sol'; /// @title ClaimHandler /// @notice this is an adapter for the ClaimCampaigns.sol contract /// the claim campaigns contract is designed for the Hedgey Voting Token Lockups, but this adapter makes the SingleTokenLockups able to interact with and receive locked token claims /// This contract will temporarily store the delegation and amount values for a specific lockup, and then when the claim contract calls the safeTransferFrom function, it will create the lockup and delegate the tokens /// This contract is ONLY meant to be used with the sepcific type of claim campaign, and if used inappropriately it could result in loss of funds and will revert /// This contract is deployed when the SingleTokenLockups contract is deployed, not meant to be deployed separately on its own /// @dev this contract needs to be whitelisted by the ClaimsCampaign contract after deployment contract ClaimHandler is ReentrancyGuard { /// @notice the id counter for temporary storage of claim items uint256 internal _ids; /// @notice the token lockups contract ITokenLockups public tokenLockup; /// @notice the token address address public token; /// @notice the address of the claim contract address public claimContract; /// @notice the struct for the lockup that temporarily stores the amount, rate and delegatee /// @param amount the amount of tokens that have been claimed and will be locked /// @param rate the rate that the tokens will unlock and is used for calling the create function /// @param delegatee the address tokens are going to be delegated to and used upon creation and delegation struct Lockup { uint256 amount; uint256 rate; address delegatee; uint256 txTimeStamp; } /// @notice the mapping of the lockups to an id mapping(uint256 => Lockup) public lockups; /// @notice the constructor to set the token lockups contract and the token address /// @param _token the address of the token /// @dev the SingleTokenLockups contract is supposed to call this and thus the msg.sender is set as the tokenLockup contract constructor(address _token) { tokenLockup = ITokenLockups(msg.sender); token = _token; } modifier onlyClaimContract() { require(msg.sender == claimContract, '!ClaimContract'); _; } function setClaimContract(address _claimContract) external nonReentrant { require(msg.sender == address(tokenLockup)); require(claimContract == address(0x0), 'already set'); claimContract = _claimContract; } /// @notice function to increment the tokenId counter, and returns the current tokenId after inrecmenting function _incrementId() internal returns (uint256) { _ids++; return _ids; } /// @notice function to get the current running total of tokenId, useful for when totalSupply does not match function currentId() public view returns (uint256) { return _ids; } /// @notice this is the function call that is first received from the ClaimCampaign contract /// this only takes in the claimAmount, and rate and stores those values in the lockup struct /// all other values are ignored as they are not needed for the SingleTokenLockups contract function createPlan( address claimer, address _token, uint256 claimAmount, uint256 start, uint256 cliff, uint256 rate, uint256 period ) external onlyClaimContract nonReentrant returns (uint256 id) { require(_token == token, 'wrong token'); TransferHelper.transferTokens(IERC20(token), msg.sender, address(this), claimAmount); // if the claim contract address is sent - then its doing claim and delegate flow if (claimer == claimContract) { id = _incrementId(); lockups[id] = Lockup(claimAmount, rate, address(0x0), block.timestamp); } else { // if a different recipient address is sent in, then we just simply create the lockup without delegation IERC20(token).approve(address(tokenLockup), claimAmount); tokenLockup.createLockup(claimer, claimAmount, rate); } } /// @notice this function is called by the claim contract to delegate the tokens to the delegatee /// in this case we update the storage of the lockup with this delatee address, but no delegation actually occurs yet function delegate(uint256 id, address delegatee) external nonReentrant onlyClaimContract { require(lockups[id].txTimeStamp == block.timestamp, 'invalid timestamp'); lockups[id].delegatee = delegatee; } /// @notice this function is called by the claim contract, where it would generally have created a lockup and now transferred it to the beneficiary /// @dev this function takes the instruction from the claim contract as the final call and it will now actually create the lockup /// this contact is expected to already have all of the necessary information for creating the lockup stored in the lockup struct from the previous two function calls /// and now it approves the token spend to the lockup contract, and actually creates the lockup itself /// this will pull tokens from this address to the lockup contract, and then perform the delegation in the single contract call /// @dev the lockup is deleted afterwards function safeTransferFrom(address from, address claimer, uint256 id) external nonReentrant onlyClaimContract { Lockup memory lockup = lockups[id]; require(lockup.txTimeStamp == block.timestamp, 'invalid timestamp'); IERC20(token).approve(address(tokenLockup), lockup.amount); tokenLockup.createLockupWithDelegation(claimer, lockup.amount, lockup.rate, lockup.delegatee); delete lockups[id]; } }
// SPDX-License-Identifier: BUSL-1.1 pragma solidity 0.8.28; interface IStaking { function defaultDelegatee() external view returns (address); function stake(uint256 amount) external returns (uint256); function stakeAndDelegate(uint256 amount, address delegatee) external returns (uint256); function transfer(address _to, uint256 _value) external returns (bool); function unstake(uint256 _amount) external returns (uint256); function fetchOrInitializeDepositForDelegatee(address _delegatee) external returns (uint256); function updateDepositOnBehalf( address _account, uint256 _newDepositId, uint256 _nonce, uint256 _deadline, bytes memory _signature ) external; }
// SPDX-License-Identifier: BUSL-1.1 pragma solidity 0.8.28; interface ITokenLockups { function createLockupWithDelegation( address recipient, uint256 amount, uint256 rate, address delegatee ) external returns (uint256 tokenId); function token() external view returns (address); function createLockup(address recipient, uint256 amount, uint256 rate) external returns (uint256 tokenId); }
// SPDX-License-Identifier: BUSL-1.1 pragma solidity 0.8.28; interface IVotes { function delegate(address delegatee) external; function delegates(address wallet) external view returns (address delegate); function delegateBySig(address delegatee, uint256 nonce, uint256 expiry, uint8 v, bytes32 r, bytes32 s) external; }
// SPDX-License-Identifier: BUSL-1.1 pragma solidity 0.8.28; /// @notice Library to assist with calculation methods of the balances, ends, period amounts for a given plan /// used by both the Lockup and Vesting Plans library TimelockLibrary { function min(uint256 a, uint256 b) internal pure returns (uint256 _min) { _min = (a <= b) ? a : b; } /// @notice function to calculate the end date of a plan based on its start, amount, rate and period function endDate(uint256 start, uint256 amount, uint256 rate, uint256 period) internal pure returns (uint256 end) { end = (amount % rate == 0) ? (amount / rate) * period + start : ((amount / rate) * period) + period + start; } function initialUnlock(uint256 start, uint256 cliff, uint256 period) internal pure returns (uint256 unlock) { unlock = ((cliff > start) ? cliff: start) + period; } /// @notice function to calculate the unlocked (claimable) balance, still locked balance, and the most recent timestamp the unlock would take place /// the most recent unlock time is based on the periods, so if the periods are 1, then the unlock time will be the same as the redemption time, /// however if the period more than 1 second, the latest unlock will be a discrete time stamp /// @param start is the start time of the plan /// @param cliffDate is the timestamp of the cliff of the plan /// @param amount is the total unclaimed amount tokens still in the vesting plan /// @param rate is the amount of tokens that unlock per period /// @param period is the seconds in each period, a 1 is a period of 1 second whereby tokens unlock every second /// @param currentTime is the current time being evaluated, typically the block.timestamp, but used just to check the plan is past the start or cliff function balanceAtTime( uint256 start, uint256 cliffDate, uint256 amount, uint256 rate, uint256 period, uint256 currentTime ) internal pure returns (uint256 unlockedBalance, uint256 lockedBalance, uint256 unlockTime) { if (start > currentTime || cliffDate > currentTime) { lockedBalance = amount; unlockTime = start; } else { uint256 periodsElapsed = (currentTime - start) / period; uint256 calculatedBalance = periodsElapsed * rate; unlockedBalance = min(calculatedBalance, amount); lockedBalance = amount - unlockedBalance; unlockTime = start + (period * periodsElapsed); } } }
// SPDX-License-Identifier: BUSL-1.1 pragma solidity 0.8.28; import '@openzeppelin/contracts/token/ERC20/IERC20.sol'; import '@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol'; import '../interfaces/IStaking.sol'; library TransferHelper { using SafeERC20 for IERC20; /// @notice Internal function used for standard ERC20 transferFrom method /// @notice it contains a pre and post balance check /// @notice as well as a check on the msg.senders balance /// @param token is the address of the ERC20 being transferred /// @param from is the remitting address /// @param to is the location where they are being delivered function transferTokens( IERC20 token, address from, address to, uint256 amount ) internal { uint256 priorBalance = token.balanceOf(address(to)); require(token.balanceOf(from) >= amount, 'Insufficient balance'); require(token.allowance(from, address(this)) >= amount, 'Insufficient allowance'); token.safeTransferFrom(from, to, amount); // SafeERC20.safeTransferFrom(IERC20(token), from, to, amount); uint256 postBalance = token.balanceOf(address(to)); require(postBalance - priorBalance == amount, 'Transfer error'); } /// @notice Internal function is used with standard ERC20 transfer method /// @notice this function ensures that the amount received is the amount sent with pre and post balance checking /// @param token is the ERC20 contract address that is being transferred /// @param to is the address of the recipient /// @param amount is the amount of tokens that are being transferred function withdrawTokens( IERC20 token, address to, uint256 amount ) internal { uint256 priorBalance = token.balanceOf(address(to)); token.safeTransfer(to, amount); uint256 postBalance = token.balanceOf(address(to)); require(postBalance - priorBalance == amount, 'Transfer error'); } }
// SPDX-License-Identifier: BUSL-1.1 pragma solidity 0.8.28; import './libraries/TransferHelper.sol'; import './interfaces/IVotes.sol'; /// @title VotingVault /// this contract is used to hold tokens outside and segregated from the main escrow contract for native ERC20Votes support /// Tokens in here are controlled by the SingleTokenStaking contract only - but the onwer of the NFT dictates where tokens are delegated /// and when they are withdrawn or or staked contract VotingVault { /// @notice token is the address of the token address public token; /// @notice controller is the address of the SingleTokenStaking contract address public controller; /// @notice constructor to set the token and the controller /// @param _token the address of the token /// the msg.sender is set as the controller - the SingleTokenStaking contracts constructor(address _token) { controller = msg.sender; token = _token; } modifier onlyController() { require(msg.sender == controller); _; } /// @notice function to delegate the tokens of this address /// @param delegatee the address to delegate to function delegateTokens(address delegatee) external onlyController { address existingDelegate = IVotes(token).delegates(address(this)); if (existingDelegate != delegatee) { uint256 balanceCheck = IERC20(token).balanceOf(address(this)); IVotes(token).delegate(delegatee); // check to make sure delegate function is not malicious require(balanceCheck == IERC20(token).balanceOf(address(this))); } } /// @notice function to withdraw tokens from this address /// @dev only can be called by the Controller - the SingleTokenStaking contract /// this function with transfer tokens directly from this contract to the beneficiary function withdrawTokens(address to, uint256 amount) external onlyController { TransferHelper.withdrawTokens(IERC20(token), to, amount); } /// @notice function to withdraw and stake tokens from this address /// @param stakingContract the address of the staking contract /// @param beneficiary the address of the beneficiary /// @param amount the amount of tokens to withdraw and staked /// @dev only can be called by the Controller - the SingleTokenStaking contract // this first has to create a deposit for delegatee to get / create the delegate depositId /// this function uses the transfer helper library, which is designed to work with the UnisTaker / Tally Liquid Staking contract specifically /// it will stake the tokens, which this contract then receives the staked tokens; then it will transfer the staked tokens to the beneficiary function withdrawAndStake( address stakingContract, address beneficiary, uint256 amount, uint256 nonce, uint256 deadline, bytes memory signature ) external onlyController { address delegatee = IVotes(token).delegates(address(this)); // if the delegatee is set to 0 address or the default delegatee or if the beneficiary has already delegated to the same delegatee, then transferring the LSTs will result in the same delegatee address beneDelegatee = IVotes(token).delegates(beneficiary); address defaultDelegate = IStaking(stakingContract).defaultDelegatee(); if (delegatee == address(0) || delegatee == defaultDelegate || delegatee == beneDelegatee) { stakeTokens(IERC20(token), stakingContract, beneficiary, amount); } else { uint256 depositId = IStaking(stakingContract).fetchOrInitializeDepositForDelegatee(delegatee); stakeTokens(IERC20(token), stakingContract, beneficiary, amount); IStaking(stakingContract).updateDepositOnBehalf(beneficiary, depositId, nonce, deadline, signature); } } /// @notice internal function for staking - this is specifically make for the Tally liquid staking contract /// @param _token is the ERC20 contract address that is being transferred /// @param _stakingContract is the address of the staking contract /// @param _beneficiary is the address of the recipient /// @param _amount is the amount of tokens that are being transferred /// @dev the amount of tokens staked is returned in the function, so mechanically this will stake tokens, then transfer them to the beneficiary, using the stake amount returned in the stake function function stakeTokens( IERC20 _token, address _stakingContract, address _beneficiary, uint256 _amount ) internal { _token.approve(_stakingContract, _amount); uint256 stakedAmount = IStaking(_stakingContract).stake(_amount); require(_token.allowance(address(this), _stakingContract) == 0, 'Allowance error'); IStaking(_stakingContract).transfer(_beneficiary, stakedAmount); } }
{ "optimizer": { "enabled": true, "runs": 200 }, "viaIR": true, "evmVersion": "paris", "outputSelection": { "*": { "*": [ "evm.bytecode", "evm.deployedBytecode", "devdoc", "userdoc", "metadata", "abi" ] } }, "libraries": {} }
Contract Security Audit
- No Contract Security Audit Submitted- Submit Audit Here
[{"inputs":[{"internalType":"address","name":"_token","type":"address"},{"internalType":"address","name":"_admin","type":"address"},{"internalType":"bool","name":"_transferable","type":"bool"},{"internalType":"uint256","name":"_start","type":"uint256"},{"internalType":"uint256","name":"_cliff","type":"uint256"},{"internalType":"uint256","name":"_period","type":"uint256"},{"internalType":"string","name":"_name","type":"string"},{"internalType":"string","name":"_symbol","type":"string"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[],"name":"ERC721EnumerableForbiddenBatchMint","type":"error"},{"inputs":[{"internalType":"address","name":"sender","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"},{"internalType":"address","name":"owner","type":"address"}],"name":"ERC721IncorrectOwner","type":"error"},{"inputs":[{"internalType":"address","name":"operator","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"ERC721InsufficientApproval","type":"error"},{"inputs":[{"internalType":"address","name":"approver","type":"address"}],"name":"ERC721InvalidApprover","type":"error"},{"inputs":[{"internalType":"address","name":"operator","type":"address"}],"name":"ERC721InvalidOperator","type":"error"},{"inputs":[{"internalType":"address","name":"owner","type":"address"}],"name":"ERC721InvalidOwner","type":"error"},{"inputs":[{"internalType":"address","name":"receiver","type":"address"}],"name":"ERC721InvalidReceiver","type":"error"},{"inputs":[{"internalType":"address","name":"sender","type":"address"}],"name":"ERC721InvalidSender","type":"error"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"ERC721NonexistentToken","type":"error"},{"inputs":[{"internalType":"address","name":"owner","type":"address"},{"internalType":"uint256","name":"index","type":"uint256"}],"name":"ERC721OutOfBoundsIndex","type":"error"},{"inputs":[],"name":"ReentrancyGuardReentrantCall","type":"error"},{"inputs":[{"internalType":"address","name":"token","type":"address"}],"name":"SafeERC20FailedOperation","type":"error"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"admin","type":"address"}],"name":"AdminChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":true,"internalType":"address","name":"approved","type":"address"},{"indexed":true,"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"Approval","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":true,"internalType":"address","name":"operator","type":"address"},{"indexed":false,"internalType":"bool","name":"approved","type":"bool"}],"name":"ApprovalForAll","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"claimContract","type":"address"}],"name":"ClaimContractSet","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"LockupCancelled","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"tokenId","type":"uint256"},{"indexed":false,"internalType":"address","name":"recipient","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"rate","type":"uint256"}],"name":"LockupCreated","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"tokenId","type":"uint256"},{"indexed":false,"internalType":"address","name":"delegatee","type":"address"},{"indexed":false,"internalType":"address","name":"votingVault","type":"address"}],"name":"LockupDelegated","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"stakingContract","type":"address"}],"name":"StakingContractSet","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"start","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"cliff","type":"uint256"}],"name":"StartAndCliffSet","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"tokenId","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"stakeAmount","type":"uint256"},{"indexed":false,"internalType":"address","name":"beneficiary","type":"address"}],"name":"TokensStaked","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"tokenId","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"unlockedAmount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"remainingAmount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"resetTime","type":"uint256"}],"name":"TokensUnlocked","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"from","type":"address"},{"indexed":true,"internalType":"address","name":"to","type":"address"},{"indexed":true,"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"Transfer","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"bool","name":"transferable","type":"bool"}],"name":"TransferabilityChanged","type":"event"},{"inputs":[],"name":"admin","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"approve","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"}],"name":"balanceOf","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"},{"internalType":"uint256","name":"timestamp","type":"uint256"}],"name":"balanceOfLockup","outputs":[{"internalType":"uint256","name":"unlockedBalance","type":"uint256"},{"internalType":"uint256","name":"lockedBalance","type":"uint256"},{"internalType":"uint256","name":"unlockTime","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"cancelAllLockups","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256[]","name":"tokenIds","type":"uint256[]"}],"name":"cancelLockups","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bool","name":"_transferable","type":"bool"}],"name":"changeTransferability","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"claimContract","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"claimHandler","outputs":[{"internalType":"contract ClaimHandler","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"cliff","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"recipient","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"uint256","name":"rate","type":"uint256"}],"name":"createLockup","outputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"recipient","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"uint256","name":"rate","type":"uint256"},{"internalType":"address","name":"delegatee","type":"address"}],"name":"createLockupWithDelegation","outputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"},{"internalType":"address","name":"vault","type":"address"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address[]","name":"recipients","type":"address[]"},{"internalType":"uint256[]","name":"amounts","type":"uint256[]"},{"internalType":"uint256[]","name":"rates","type":"uint256[]"}],"name":"createLockups","outputs":[{"internalType":"uint256[]","name":"tokenIds","type":"uint256[]"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address[]","name":"recipients","type":"address[]"},{"internalType":"uint256[]","name":"amounts","type":"uint256[]"},{"internalType":"uint256[]","name":"rates","type":"uint256[]"},{"internalType":"address[]","name":"delegatees","type":"address[]"}],"name":"createLockupsWithDelegation","outputs":[{"internalType":"uint256[]","name":"tokenIds","type":"uint256[]"},{"internalType":"address[]","name":"vaults","type":"address[]"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"currentTokenId","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"},{"internalType":"address","name":"delegatee","type":"address"}],"name":"delegate","outputs":[{"internalType":"address","name":"vault","type":"address"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"getApproved","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"globalLock","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"initialUnlock","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"},{"internalType":"address","name":"operator","type":"address"}],"name":"isApprovedForAll","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"lockups","outputs":[{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"uint256","name":"rate","type":"uint256"},{"internalType":"uint256","name":"resetTime","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"name","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"ownerOf","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"period","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"from","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"safeTransferFrom","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"from","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"},{"internalType":"bytes","name":"data","type":"bytes"}],"name":"safeTransferFrom","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"operator","type":"address"},{"internalType":"bool","name":"approved","type":"bool"}],"name":"setApprovalForAll","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_claimContract","type":"address"}],"name":"setClaimContract","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_stakingContract","type":"address"}],"name":"setStakingContract","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"stakingContract","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"start","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"startCliffSet","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes4","name":"interfaceId","type":"bytes4"}],"name":"supportsInterface","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"symbol","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"token","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"index","type":"uint256"}],"name":"tokenByIndex","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"},{"internalType":"uint256","name":"index","type":"uint256"}],"name":"tokenOfOwnerByIndex","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"tokenURI","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalSupply","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"from","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"transferFrom","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"transferable","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"unlock","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"},{"internalType":"uint256","name":"nonce","type":"uint256"},{"internalType":"uint256","name":"deadline","type":"uint256"},{"internalType":"bytes","name":"signature","type":"bytes"}],"name":"unlockAndStake","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"newStart","type":"uint256"},{"internalType":"uint256","name":"newCliff","type":"uint256"}],"name":"updateStartAndCliff","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"votingVaults","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"}]
Contract Creation Code
6080604052346105a657614c2180380380610019816105ab565b928339810190610100818303126105a657610033816105d0565b91610040602083016105d0565b9260408301518015158091036105a65760608401519160808501519360a08601519560c081015160018060401b0381116105a657826100809183016105e4565b60e08201519092906001600160401b0381116105a6576100a092016105e4565b815190916001600160401b03821161026d5760005490600182811c9216801561059c575b602083101461049c5781601f84931161052d575b50602090601f83116001146104c7576000926104bc575b50508160011b916000199060031b1c1916176000555b8051906001600160401b03821161026d5760015490600182811c921680156104b2575b602083101461049c5781601f84931161042c575b50602090601f83116001146103c4576000926103b9575b50508160011b916000199060031b1c1916176001555b6001600a556001600160a01b0316948515610374576001600160a01b0316801561032f5784156102f5578215801590816102ea575b81156102d4575b501561028357600c80546001600160a01b03199081168817909155600d8054821692909217909155600e8054909116331790556011805460ff60a01b191660a09290921b60ff60a01b1691909117905560125560135560145560405190610b878083016001600160401b0381118482101761026d57602092849261409a843981520301906000f0801561026157601180546001600160a01b0319166001600160a01b0392909216919091179055604051613a4a90816106508239f35b6040513d6000823e3d90fd5b634e487b7160e01b600052604160045260246000fd5b60405162461bcd60e51b8152602060048201526024808201527f537461727420616e6420636c696666206d7573742062652073657420746f67656044820152633a3432b960e11b6064820152608490fd5b9050806102e2575b386101a5565b5083156102dc565b84861015915061019e565b60405162461bcd60e51b81526020600482015260126024820152710506572696f642063616e6e6f7420626520360741b6044820152606490fd5b60405162461bcd60e51b815260206004820152601960248201527f41646d696e2063616e6e6f7420626520302061646472657373000000000000006044820152606490fd5b60405162461bcd60e51b815260206004820152601960248201527f546f6b656e2063616e6e6f7420626520302061646472657373000000000000006044820152606490fd5b015190503880610153565b600160009081528281209350601f198516905b81811061041457509084600195949392106103fb575b505050811b01600155610169565b015160001960f88460031b161c191690553880806103ed565b929360206001819287860151815501950193016103d7565b60016000529091507fb10e2d527612073b26eecdfd717e6a320cf44b4afac2b0732d9fcbe2b7fa0cf6601f840160051c81019160208510610492575b90601f859493920160051c01905b818110610483575061013c565b60008155849350600101610476565b9091508190610468565b634e487b7160e01b600052602260045260246000fd5b91607f1691610128565b0151905038806100ef565b60008080528281209350601f198516905b81811061051557509084600195949392106104fc575b505050811b01600055610105565b015160001960f88460031b161c191690553880806104ee565b929360206001819287860151815501950193016104d8565b600080529091507f290decd9548b62a8d60345a988386fc84ba6bc95484008f6362f93160ef3e563601f840160051c81019160208510610592575b90601f859493920160051c01905b81811061058357506100d8565b60008155849350600101610576565b9091508190610568565b91607f16916100c4565b600080fd5b6040519190601f01601f191682016001600160401b0381118382101761026d57604052565b51906001600160a01b03821682036105a657565b81601f820112156105a6578051906001600160401b03821161026d57610613601f8301601f19166020016105ab565b92828452602083830101116105a65760005b82811061063a57505060206000918301015290565b8060208092840101518282870101520161062556fe608080604052600436101561001357600080fd5b600090813560e01c9081629a9b7b1461174d5750806301ffc9a7146116c457806306fdde0314611609578063081812fc146115cc57806308bbb82414611579578063095ea7b3146114915780630d7955161461138857806313d033c01461136a57806318160ddd1461134c57806323b872dd146113345780632f745c59146112bc5780633808d901146111c357806342842e0e146111935780634a30d3eb14610ffa5780634f6ccce714610faa5780635c546d1f14610f8f57806360b5f69f14610f2d5780636198e33914610e655780636352211e14610e3457806366345da414610e0b57806370a0823114610de75780637ebbec5c14610d6a5780637f2b114414610d4157806381893c7c14610cc657806388a82b7214610c855780638bad00ee14610bff5780638e1f81bb14610bda5780638e6f4fb714610b8e57806392ff0d3114610b6857806395d89b4114610a5b5780639dd373b91461098b578063a22cb465146108eb578063a8713ec7146108b8578063ab2de76e146106bb578063abf4882014610625578063b88d4fde146105c3578063be9a6555146105a5578063c3f368af14610556578063c87b56dd146104fb578063e6239f4214610304578063e985e9c5146102aa578063ee99205c14610281578063ef78d4fd14610263578063f851a4401461023a5763fc0c546a1461020f57600080fd5b34610237578060031936011261023757600c546040516001600160a01b039091168152602090f35b80fd5b5034610237578060031936011261023757600d546040516001600160a01b039091168152602090f35b50346102375780600319360112610237576020601454604051908152f35b5034610237578060031936011261023757600f546040516001600160a01b039091168152602090f35b50346102375760403660031901126102375760406102c66117c5565b916102cf6117aa565b9260018060a01b031681526005602052209060018060a01b0316600052602052602060ff604060002054166040519015158152f35b5034610237576080366003190112610237576004356064356001600160401b0381116104f7576103389036906004016119ae565b90610341611ccc565b61035d61034d82611c95565b6001600160a01b031633146119f5565b600f546001600160a01b0316156104b257808352601660205260408320546001600160a01b03161561047f57826103938261245f565b600f549293926001600160a01b0391821692911690823b156104705761040492849283604051809681958294630fcf4e2760e21b8452600484015260018060a01b03169b8c60248401528a60448401526024356064840152604435608484015260c060a484015260c4830190611769565b03925af1801561047457610453575b507f80fec2f85f5b4366aa375af201362a4a8b18a2633abe222a5aec96abf43a84a3606084868560405192835260208301526040820152a16001600a5580f35b906104609193929361180c565b8360001261047057908338610413565b8380fd5b6040513d84823e3d90fd5b60405162461bcd60e51b815260206004820152600b60248201526a3b30bab63a1032b93937b960a91b6044820152606490fd5b60405162461bcd60e51b815260206004820152601860248201527f5374616b696e6720636f6e7472616374206e6f742073657400000000000000006044820152606490fd5b8280fd5b503461023757602036600319011261023757610518600435611c95565b506020908060405161052a848261180c565b52506040519061053a818361180c565b60008252610552604051928284938452830190611769565b0390f35b503461023757806003193601126102375761059660209161057d610578611b88565b611c49565b50601254601354601454918082111561059e5750612923565b604051908152f35b9050612923565b50346102375780600319360112610237576020601254604051908152f35b5034610237576080366003190112610237576105dd6117c5565b6105e56117aa565b90604435606435926001600160401b0384116106215761060c61061e9436906004016119ae565b92610618838383611ad2565b336129da565b80f35b8480fd5b5034610237576106986105529161063b3661197d565b9190610648610578611b88565b81526015602052604081206040805192610661846117db565b8254938481526002600185015494856020840152015492839101525080156000146106b55750601254915b60135460145493612943565b604080519384526020840192909252908201529081906060820190565b9161068c565b5034610237576080366003190112610237576004356001600160401b0381116108b4576106ec903690600401611844565b906024356001600160401b0381116108b45761070c9036906004016118b2565b916044356001600160401b0381116104f75761072c9036906004016118b2565b926064356001600160401b0381116104705761074c903690600401611844565b90610755611ccc565b8251815180911490816108a9575b508061089e575b61077390611a2a565b61077d8351611a76565b948351936107a361078d8661182d565b9561079b604051978861180c565b80875261182d565b6020860190601f1901368237865b825181101561083b576001906107f06001600160a01b036107d28387611aa8565b51166107de8389611aa8565b516107e98489611aa8565b5191611edb565b6107fa828c611aa8565b52610821610808828c611aa8565b51838060a01b03610819848b611aa8565b511690611d26565b61082b828a611aa8565b90838060a01b03169052016107b1565b61085d89838a8a6001600a55602060405195869560408752604087019061190f565b918583038287015251918281520192915b81811061087c575050500390f35b82516001600160a01b031684528594506020938401939092019160010161086e565b50845182511461076a565b905085511438610763565b5080fd5b503461023757602036600319011261023757602090600435815260168252604060018060a01b0391205416604051908152f35b5034610237576040366003190112610237576109056117c5565b602435908115158092036104f7576001600160a01b03169081156109775733835260056020526040832082600052602052604060002060ff1981541660ff83161790556040519081527f17307eab39ab6107e8899845ad3d59bd9653f200f220920489ca2b5937696c3160203392a380f35b630b61174360e31b83526004829052602483fd5b5034610237576020366003190112610237576109a56117c5565b6109ba60018060a01b03600d54163314611b38565b600f54906001600160a01b038216610a16576001600160a01b03166001600160a01b0319919091168117600f556040519081527f1253844b0fff3da7dd2829de816c9b4f94c238cf2bf6eb72c02c7d6f2b53beac90602090a180f35b60405162461bcd60e51b815260206004820152601c60248201527f5374616b696e6720636f6e747261637420616c726561647920736574000000006044820152606490fd5b50346102375780600319360112610237576040519080600154908160011c91600181168015610b5e575b602084108114610b4a57838652908115610b235750600114610ac6575b61055284610ab28186038261180c565b604051918291602083526020830190611769565b600181527fb10e2d527612073b26eecdfd717e6a320cf44b4afac2b0732d9fcbe2b7fa0cf6939250905b808210610b0957509091508101602001610ab282610aa2565b919260018160209254838588010152019101909291610af0565b60ff191660208087019190915292151560051b85019092019250610ab29150839050610aa2565b634e487b7160e01b83526022600452602483fd5b92607f1692610a85565b5034610237578060031936011261023757602060ff60115460a01c166040519015158152f35b5034610237576020366003190112610237576040906004358152601560205220805461055260026001840154930154604051938493846040919493926060820195825260208201520152565b50346102375780600319360112610237576020610bf5611c14565b6040519015158152f35b5034610237578060031936011261023757610c2560018060a01b03600d54163314611b38565b610c35610c30611c14565b611bd8565b600854815b818110610c45578280f35b60085415610c6e57600190610c68610c5c85611b6d565b90549060031b1c6127ba565b01610c3a565b60448363295f44f760e21b81528060045280602452fd5b5034610237576060366003190112610237576020610cb9610ca46117c5565b610cac611ccc565b6044359060243590611edb565b6001600a55604051908152f35b5034610237576020366003190112610237576004358015158091036108b45760207f11da1b8c0a94a11df636c4bcd3500335a4f11ec00f56b0a425b3354171b2cd9a91610d1e60018060a01b03600d54163314611b38565b6011805460ff60a01b191660a083901b60ff60a01b16179055604051908152a180f35b50346102375780600319360112610237576011546040516001600160a01b039091168152602090f35b5034610237576020366003190112610237576004356001600160401b0381116108b457610d9b9036906004016118b2565b90610db160018060a01b03600d54163314611b38565b610dbc610c30611c14565b805b8251811015610de35780610ddd610dd760019386611aa8565b516127ba565b01610dbe565b5080f35b5034610237576020366003190112610237576020610596610e066117c5565b611ba2565b50346102375780600319360112610237576010546040516001600160a01b039091168152602090f35b5034610237576020366003190112610237576020610e53600435611c95565b6040516001600160a01b039091168152f35b50346102375760203660031901126102375780610e97600435610e86611ccc565b610e9261034d82611c95565b61245f565b6001600160a01b0316918215610f0f57823b15610f0a576040516306b091f960e01b81526001600160a01b0392909216600483015260248201529082908290604490829084905af1801561047457610ef5575b50505b6001600a5580f35b81610eff9161180c565b610237578038610eea565b505050fd5b600c54610f2894509092506001600160a01b031661268c565b610eed565b503461023757608036600319011261023757610f476117c5565b90606435906001600160a01b03821682036102375750610f75610f6e604093610cac611ccc565b9182611d26565b6001600a5582519182526001600160a01b03166020820152f35b50346102375780600319360112610237576020610bf5611b88565b50346102375760203660031901126102375760043590600854821015610fe4576020610fd583611b6d565b90549060031b1c604051908152f35b60449163295f44f760e21b825281600452602452fd5b5034610237576020366003190112610237576110146117c5565b600e546001600160a01b03163314801561117f575b1561114857601054906001600160a01b038216611103576001600160a01b039081166001600160a01b0319929092168217601055601154839116803b156108b4578190602460405180948193634a30d3eb60e01b83528760048401525af180156110f8576110c1575b5060207fbf77f8a166e9bdd137896351a3fea0853166f5ad052c99f89c0e300c5d4f213791604051908152a180f35b826110f07fbf77f8a166e9bdd137896351a3fea0853166f5ad052c99f89c0e300c5d4f2137939460209361180c565b929150611092565b6040513d85823e3d90fd5b60405162461bcd60e51b815260206004820152601a60248201527f436c61696d20636f6e747261637420616c7265616479207365740000000000006044820152606490fd5b60405162461bcd60e51b815260206004820152600f60248201526e10a232b83637bcb2b93e20b236b4b760891b6044820152606490fd5b50600d546001600160a01b03163314611029565b50346102375761061e6111a536611943565b90604051926111b560208561180c565b858452610618838383611ad2565b5034610237576111d23661197d565b6111e760018060a01b03600d54163314611b38565b6111ef611c14565b156112815781156104f75781811061123c57816040917fa766b7584bf930f86ae9902fced6a1da4a23e72e9f33cb4ba20f396800a53c54936012558060135582519182526020820152a180f35b60405162461bcd60e51b815260206004820152601960248201527f436c696666206d757374206265206166746572207374617274000000000000006044820152606490fd5b60405162461bcd60e51b815260206004820152601360248201527210d85b9b9bdd0818da185b99d9481cdd185c9d606a1b6044820152606490fd5b5034610237576040366003190112610237576112d66117c5565b906024356112e383611ba2565b811015611311579060409160209360018060a01b031682526006845282822090825283522054604051908152f35b63295f44f760e21b82526001600160a01b03909216600452602491909152604490fd5b50346102375761061e61134636611943565b91611ad2565b50346102375780600319360112610237576020600854604051908152f35b50346102375780600319360112610237576020601354604051908152f35b5034610237576060366003190112610237576004356001600160401b0381116108b4576113b9903690600401611844565b6024356001600160401b0381116104f7576113d89036906004016118b2565b6044356001600160401b038111610470576113f79036906004016118b2565b6113ff611ccc565b611416835183518091149081611486575b50611a2a565b6114208351611a76565b935b835181101561146b5760019061145a6001600160a01b036114438388611aa8565b511661144f8387611aa8565b516107e98487611aa8565b6114648288611aa8565b5201611422565b6001600a55604051602080825281906105529082018861190f565b905082511438611410565b5034610237576040366003190112610237576114ab6117c5565b6024356114b781611c95565b33151580611566575b8061153b575b6115285781906001600160a01b0384811691167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b9258680a4825260046020526040822080546001600160a01b0319166001600160a01b0390921691909117905580f35b63a9fbf51f60e01b845233600452602484fd5b506001600160a01b038116845260056020908152604080862033875290915284205460ff16156114c6565b506001600160a01b0381163314156114c0565b50346102375760403660031901126102375760206115b560043561159b6117aa565b906115a4611ccc565b6115b061034d82611c95565b611d26565b6001600a556040516001600160a01b039091168152f35b5034610237576020366003190112610237576020906004356115ed81611c95565b50815260048252604060018060a01b0391205416604051908152f35b503461023757806003193601126102375760405190808054908160011c916001811680156116ba575b602084108114610b4a57838652908115610b23575060011461165e5761055284610ab28186038261180c565b8080527f290decd9548b62a8d60345a988386fc84ba6bc95484008f6362f93160ef3e563939250905b8082106116a057509091508101602001610ab282610aa2565b919260018160209254838588010152019101909291611687565b92607f1692611632565b50346102375760203660031901126102375760043563ffffffff60e01b81168091036108b45760209063780e9d6360e01b811490811561170a575b506040519015158152f35b6380ac58cd60e01b81149150811561173c575b811561172b575b50826116ff565b6301ffc9a760e01b14905082611724565b635b5e139f60e01b8114915061171d565b9050346108b457816003193601126108b457602090600b548152f35b919082519283825260005b848110611795575050826000602080949584010152601f8019910116010190565b80602080928401015182828601015201611774565b602435906001600160a01b03821682036117c057565b600080fd5b600435906001600160a01b03821682036117c057565b606081019081106001600160401b038211176117f657604052565b634e487b7160e01b600052604160045260246000fd5b90601f801991011681019081106001600160401b038211176117f657604052565b6001600160401b0381116117f65760051b60200190565b9080601f830112156117c05781359061185c8261182d565b9261186a604051948561180c565b82845260208085019360051b8201019182116117c057602001915b8183106118925750505090565b82356001600160a01b03811681036117c057815260209283019201611885565b9080601f830112156117c05781356118c98161182d565b926118d7604051948561180c565b81845260208085019260051b8201019283116117c057602001905b8282106118ff5750505090565b81358152602091820191016118f2565b906020808351928381520192019060005b81811061192d5750505090565b8251845260209384019390920191600101611920565b60609060031901126117c0576004356001600160a01b03811681036117c057906024356001600160a01b03811681036117c0579060443590565b60409060031901126117c0576004359060243590565b6001600160401b0381116117f657601f01601f191660200190565b81601f820112156117c0578035906119c582611993565b926119d3604051948561180c565b828452602083830101116117c057816000926020809301838601378301015290565b156119fc57565b60405162461bcd60e51b815260206004820152600660248201526510a7bbb732b960d11b6044820152606490fd5b15611a3157565b60405162461bcd60e51b815260206004820152601860248201527f4172726179206c656e67746873206d757374206d6174636800000000000000006044820152606490fd5b90611a808261182d565b611a8d604051918261180c565b8281528092611a9e601f199161182d565b0190602036910137565b8051821015611abc5760209160051b010190565b634e487b7160e01b600052603260045260246000fd5b91906001600160a01b03811615611b2257611aef908233916123f7565b6001600160a01b039081169216808303611b0857505050565b6364283d7b60e01b60005260045260245260445260646000fd5b633250574960e11b600052600060045260246000fd5b15611b3f57565b60405162461bcd60e51b815260206004820152600660248201526510a0b236b4b760d11b6044820152606490fd5b600854811015611abc57600860005260206000200190600090565b6012548015159081611b98575090565b9050601354101590565b6001600160a01b03168015611bc257600052600360205260406000205490565b6322718ad960e21b600052600060045260246000fd5b15611bdf57565b60405162461bcd60e51b815260206004820152600d60248201526c10d85b9b9bdd0818d85b98d95b609a1b6044820152606490fd5b611c316012546013546014549180821160001461059e5750612923565b42108015611c3c5790565b50611c45611b88565b1590565b15611c5057565b60405162461bcd60e51b815260206004820152601760248201527f537461727420616e6420636c696666206e6f74207365740000000000000000006044820152606490fd5b6000818152600260205260409020546001600160a01b0316908115611cb8575090565b637e27328960e01b60005260045260246000fd5b6002600a5414611cdd576002600a55565b633ee5aeb560e01b60005260046000fd5b15611cf557565b60405162461bcd60e51b815260206004820152600960248201526821306164647265737360b81b6044820152606490fd5b6001600160a01b0390911691906000611d40841515611cee565b818152601660205260408120546001600160a01b0316611ebf57818152601660205260408120546001600160a01b031661023757818152601560205260408120600260405191611d8f836117db565b80548352600181015460208401520154604082015260018060a01b03600c541660405190610b2a90818301918383106001600160401b03841117611eab57918391602093612eeb8439815203019083f080156104745783835260166020526040832080546001600160a01b0319166001600160a01b03928316908117909155600c5492519092611e219284911661268c565b935b6001600160a01b03851691823b156102375760405163b1161b8b60e01b815260048101839052818160248183885af1801561047457917f07c8b05a99629c65d5860c1bc71b959cd208f1e3df276e6a88706e704f08368395939160609593611e9b575b505060405192835260208301526040820152a1565b81611ea59161180c565b38611e86565b634e487b7160e01b86526041600452602486fd5b818152601660205260408120546001600160a01b031693611e23565b6001600160a01b03811680159493919290611ef68615611cee565b81156123c757821561239957600c546040516370a0823160e01b81523060048201526001600160a01b0390911690602081602481855afa90811561227757600091612367575b506040516370a0823160e01b8152336004820152602081602481865afa8015612277578591600091612332575b50106122f657604051636eb1769f60e11b8152336004820152306024820152602081604481865afa80156122775785916000916122c1575b5010612283576020602492611fe46040516323b872dd60e01b84820152338682015230604482015287606482015260648152611fde60848261180c565b82612e8f565b6040516370a0823160e01b815230600482015293849182905afa801561227757849260009161223e575b50612023929161201d91612642565b1461264f565b600b546000198114612228576001019384600b55849660125460026040519161204b836117db565b86835260208301888152604084019182528960005260156020526040600020935184555160018401555191015560209160405191612089848461180c565b60008352611b225761209d60008883612b17565b6001600160a01b0316612212573b6120ef575b5091608093917f0d88bbb65a89350823f139de4b4989865fdb4412b90d6fcc93d393c17c178bf8959360405194855284015260408301526060820152a1565b8161213191604099979593989694995180938192630a85bd0160e11b835233600484015260006024840152886044840152608060648401526084830190611769565b038160008c5af180916000916121d4575b50906121995787873d15612192573d61215a81611993565b90612168604051928361180c565b81523d60008383013e5b8051918261218f5783633250574960e11b60005260045260246000fd5b01fd5b6060612172565b630a85bd0160e198939597929496981b9063ffffffff60e01b16036121bf5760806120b0565b50633250574960e11b60005260045260246000fd5b8881813d831161220b575b6121e9818361180c565b810103126108b45751906001600160e01b031982168203610237575038612142565b503d6121df565b6339e3563760e11b600052600060045260246000fd5b634e487b7160e01b600052601160045260246000fd5b9250506020823d60201161226f575b8161225a6020938361180c565b810103126117c057905183919061202361200e565b3d915061224d565b6040513d6000823e3d90fd5b60405162461bcd60e51b8152602060048201526016602482015275496e73756666696369656e7420616c6c6f77616e636560501b6044820152606490fd5b9150506020813d6020116122ee575b816122dd6020938361180c565b810103126117c05784905138611fa1565b3d91506122d0565b60405162461bcd60e51b8152602060048201526014602482015273496e73756666696369656e742062616c616e636560601b6044820152606490fd5b9150506020813d60201161235f575b8161234e6020938361180c565b810103126117c05784905138611f69565b3d9150612341565b90506020813d602011612391575b816123826020938361180c565b810103126117c0575138611f3c565b3d9150612375565b60405162461bcd60e51b815260206004820152600660248201526530207261746560d01b6044820152606490fd5b60405162461bcd60e51b81526020600482015260086024820152670c08185b5bdd5b9d60c21b6044820152606490fd5b91906001600160a01b0382166124135761241092612b17565b90565b60ff60115460a01c161561242a5761241092612b17565b60405162461bcd60e51b815260206004820152600d60248201526c215472616e7366657261626c6560981b6044820152606490fd5b90612468611c14565b61261457816000526015602052600260406000200154156125fa575b81600052601560205260406000206040519161249f836117db565b815483526002600183015492602085019384520154916040840192808452601254116125c757612500906124d286611c95565b9486600052601660205260018060a01b03604060002054169451916013549151905190601454924294612943565b9195861561258c577fe6e434f2e8baea3ea5cef95e4d4bb2a7fadb13e96db47645ff2174c6869a8e9f926080928881612570578360005260156020526000600260408220828155826001820155015561255884612e72565b604051938452602084015260408301526060820152a1565b6000848152601560205260409020828155600201839055612558565b60405162461bcd60e51b81526020600482015260136024820152724e6f20746f6b656e7320746f20756e6c6f636b60681b6044820152606490fd5b60405162461bcd60e51b815260206004820152600b60248201526a3932b9b2ba1032b93937b960a91b6044820152606490fd5b601254826000526015602052600260406000200155612484565b60405162461bcd60e51b8152602060048201526006602482015265131bd8dad95960d21b6044820152606490fd5b9190820391821161222857565b1561265657565b60405162461bcd60e51b815260206004820152600e60248201526d2a3930b739b332b91032b93937b960911b6044820152606490fd5b6040516370a0823160e01b81526001600160a01b03808416600483018190529194939083169290602086602481875afa95861561227757600096612780575b5060405163a9059cbb60e01b6020808301919091526001600160a01b0392909216602482015260448082018790528152909291612713919061270e60648361180c565b612e8f565b6024604051809481936370a0823160e01b835260048301525afa9081156122775760009161274c575b5061274a9261201d91612642565b565b90506020813d602011612778575b816127676020938361180c565b810103126117c0575161274a61273c565b3d915061275a565b92919095506020833d6020116127b2575b8161279e6020938361180c565b810103126117c057915194909190846126cb565b3d9150612791565b6000818152601560205260408120604051906127d5826117db565b600281549182845260018101546020850152015460408301521561291e57828252601660205260408220546001600160a01b031680156128c957600d549151916001600160a01b0316813b15610470576040516306b091f960e01b81526001600160a01b03919091166004820152602481019290925282908290604490829084905af180156104745760026040847f3d14f8a8ee840763e5c7081a8d6ec54d7be72b68268ce135e67e0078e6a15b8296946020966000956128b9575b50505b848152601586522082815582600182015501556128b081612e72565b604051908152a1565b6128c29161180c565b3881612891565b50600c54600d5491517f3d14f8a8ee840763e5c7081a8d6ec54d7be72b68268ce135e67e0078e6a15b8294602094909360009360029360409392612919926001600160a01b03918216911661268c565b612894565b505050565b9190820180921161222857565b8181029291811591840414171561222857565b94959391929095600096818088119182156129d0575b505015612967575050509190565b6129779193965094809295612642565b84156129ba5761241092612991866129aa93049182612930565b8781116129b0576129a4905b8098612642565b95612930565b90612923565b506129a48761299d565b634e487b7160e01b600052601260045260246000fd5b1190508138612959565b823b6129e8575b5050505050565b604051630a85bd0160e11b81526001600160a01b039182166004820152918116602483015260448201939093526080606482015291169160209082908190612a34906084830190611769565b03816000865af18091600091612ad4575b5090612a9e57503d15612a97573d612a5c81611993565b90612a6a604051928361180c565b81523d6000602083013e5b80519081612a925782633250574960e11b60005260045260246000fd5b602001fd5b6060612a75565b6001600160e01b03191663757a42ff60e11b01612ac0575038808080806129e1565b633250574960e11b60005260045260246000fd5b6020813d602011612b0f575b81612aed6020938361180c565b810103126108b45751906001600160e01b031982168203610237575038612a45565b3d9150612ae0565b6000828152600260205260409020546001600160a01b03908116939192911680151580612ddc575b50508215918215612d9e575b6001600160a01b038116928315908115612d84575b8360005260026020526040600020856bffffffffffffffffffffffff60a01b8254161790558385877fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef600080a415612cf95760085483600052600960205280604060002055680100000000000000008110156117f65783612bea826001612c039401600855611b6d565b90919082549060031b91821b91600019901b1916179055565b15612ca457509050600854600019810190811161222857816000526009602052612c3260406000205491611b6d565b90549060031b1c612c4681612bea84611b6d565b60005260096020526040600020556000526009602052600060408120556008548015612c8e5760001901612c7981611b6d565b8154906000199060031b1b1916905560085590565b634e487b7160e01b600052603160045260246000fd5b828403612cb2575b50505090565b612cbb90611ba2565b600019810192908311612228576000526006602052604060002082600052602052806040600020556000526007602052604060002055388080612cac565b848414612c0357612d0985611ba2565b83600052600760205260406000205490866000526006602052604060002091818103612d53575b508460005260076020526000604081205560005260205260006040812055612c03565b8160005282602052604060002054816000528360205280604060002055600052600760205260406000205538612d30565b846000526003602052604060002060018154019055612b60565b81600052600460205260406000206bffffffffffffffffffffffff60a01b815416905583600052600360205260406000206000198154019055612b4b565b80612e1e575b15612ded5780612b3f565b83612e075750637e27328960e01b60005260045260246000fd5b63177e802f60e01b60005260045260245260446000fd5b508084148015612e4e575b80612de257506000828152600460205260409020546001600160a01b03168114612de2565b5083600052600560205260406000208160005260205260ff60406000205416612e29565b612e7e60008281612b17565b6001600160a01b031615611cb85750565b906000602091828151910182855af115612277576000513d612ee157506001600160a01b0381163b155b612ec05750565b635274afe760e01b60009081526001600160a01b0391909116600452602490fd5b60011415612eb956fe608034607e57601f610b2a38819003918201601f19168301916001600160401b03831184841017608357808492602094604052833981010312607e57516001600160a01b03811690819003607e57600180546001600160a01b0319908116331790915560008054909116919091179055604051610a90908161009a8239f35b600080fd5b634e487b7160e01b600052604160045260246000fdfe608080604052600436101561001357600080fd5b600090813560e01c90816306b091f914610610575080633f3d389c146102a0578063b1161b8b146100aa578063f77c4791146100815763fc0c546a1461005857600080fd5b3461007e578060031936011261007e57546040516001600160a01b039091168152602090f35b80fd5b503461007e578060031936011261007e576001546040516001600160a01b039091168152602090f35b503461007e57602036600319011261007e576100c46107ef565b6001546001600160a01b03163303610225578154604051632c3e6f0f60e11b81523060048201529183916001600160a01b031690602084602481855afa93841561020557839461026f575b506001600160a01b039081169316839003610128575080f35b6040516370a0823160e01b815230600482015292602084602481855afa938415610205578394610238575b50813b156102345782916024839260405194859384926317066a5760e21b845260048401525af1801561022957610210575b505081546040516370a0823160e01b81523060048201529190602090839060249082906001600160a01b03165afa9182156102055783926101cc575b500361007e57388180f35b9091506020813d6020116101fd575b816101e860209383610805565b810103126101f8575190386101c1565b600080fd5b3d91506101db565b6040513d85823e3d90fd5b8161021a91610805565b610225578138610185565b5080fd5b6040513d84823e3d90fd5b8280fd5b925092506020823d602011610267575b8161025560209383610805565b810103126101f8578391519238610153565b3d9150610248565b61029291945060203d602011610299575b61028a8183610805565b81019061083d565b923861010f565b503d610280565b503461007e5760c036600319011261007e576102ba6107ef565b6024356001600160a01b038116919082810361060c576044359160a43567ffffffffffffffff81116105f457366023820112156105f45780600401359067ffffffffffffffff82116105f8578690604051926103206020601f19601f8401160185610805565b8084523660248284010111610234578060246020930183860137830101526001546001600160a01b031633036105f4578554604051632c3e6f0f60e11b815230600482015291906001600160a01b0316602083602481845afa9283156105535788936105cf575b50602060249160405192838092632c3e6f0f60e11b82528b60048301525afa9081156105535788916105b0575b506040516303132d5760e21b81526001600160a01b03851693602082600481885afa9182156105a5578a92610584575b506001600160a01b0316918215918215610571575b50811561055e575b5015610423575050855461042095506001600160a01b03169050610874565b80f35b9194909360405192630a79f5b160e41b845260048401526020836024818b8a5af1928315610553578893610519575b5087549293610469936001600160a01b0316610874565b823b1561051557928491604051948592635e1a771160e11b8452600484015260248301526064356044830152608435606483015260a060848301528051908160a4840152835b8281106104fa57505092818360c482878383819a84010152601f801991011681010301925af180156104ed576104e457505080f35b61042091610805565b50604051903d90823e3d90fd5b602081830181015160c48984010152889550879450016104af565b8480fd5b92506020833d60201161054b575b8161053460209383610805565b8101031261054757610469925192610452565b8780fd5b3d9150610527565b6040513d8a823e3d90fd5b6001600160a01b03168214905038610401565b6001600160a01b031683149150386103f9565b61059e91925060203d6020116102995761028a8183610805565b90386103e4565b6040513d8c823e3d90fd5b6105c9915060203d6020116102995761028a8183610805565b386103b4565b60249193506105ec602091823d84116102995761028a8183610805565b939150610387565b8580fd5b634e487b7160e01b87526041600452602487fd5b8380fd5b9050346102255760403660031901126102255761062b6107ef565b60015460243592906001600160a01b0316330361060c5783546370a0823160e01b82526001600160a01b03838116600484018190529116928590602084602481885afa9384156102295782946107b8575b5060405163a9059cbb60e01b60208083019182526001600160a01b0393909316602483015260448083018990528252919291906106ba606482610805565b519082875af1156107905784513d6107af5750823b155b61079b576020906024604051809581936370a0823160e01b835260048301525afa91821561079057849261075c575b50810390811161074857036107125780f35b60405162461bcd60e51b815260206004820152600e60248201526d2a3930b739b332b91032b93937b960911b6044820152606490fd5b634e487b7160e01b83526011600452602483fd5b9091506020813d602011610788575b8161077860209383610805565b8101031261060c57519038610700565b3d915061076b565b6040513d86823e3d90fd5b635274afe760e01b85526004839052602485fd5b600114156106d1565b919093506020823d6020116107e7575b816107d560209383610805565b8101031261007e57905192602061067c565b3d91506107c8565b600435906001600160a01b03821682036101f857565b90601f8019910116810190811067ffffffffffffffff82111761082757604052565b634e487b7160e01b600052604160045260246000fd5b908160209103126101f857516001600160a01b03811681036101f85790565b908160209103126101f8575180151581036101f85790565b60405163095ea7b360e01b81526001600160a01b03838116600483015260248201869052919091169391906020816044816000895af1801561099357610a3d575b5060405163534a7e1d60e11b815260048101929092526001600160a01b0316926020826024816000885af191821561099357600092610a08575b50602060449160405192838092636eb1769f60e11b82523060048301528860248301525afa908115610993576000916109d6575b5061099f5760405163a9059cbb60e01b81526001600160a01b03929092166004830152602482015290602090829060449082906000905af18015610993576109685750565b6109899060203d60201161098c575b6109818183610805565b81019061085c565b50565b503d610977565b6040513d6000823e3d90fd5b60405162461bcd60e51b815260206004820152600f60248201526e20b63637bbb0b731b29032b93937b960891b6044820152606490fd5b90506020813d602011610a00575b816109f160209383610805565b810103126101f8575138610923565b3d91506109e4565b9091506020813d602011610a35575b81610a2460209383610805565b810103126101f857519060206108ef565b3d9150610a17565b610a559060203d60201161098c576109818183610805565b6108b556fea26469706673582212203919338163182d11d9b9089e6ef961fd038bd40e17411756eeacbe4c361cee6264736f6c634300081c0033a26469706673582212202d03b2bfa6b25e09db62096c6d493e550b21ecc6ff8c592af1eb5692ef43517564736f6c634300081c0033608034608357601f610b8738819003918201601f19168301916001600160401b03831184841017608857808492602094604052833981010312608357516001600160a01b038116908190036083576001600055600280546001600160a01b0319908116331790915560038054909116919091179055604051610ae8908161009f8239f35b600080fd5b634e487b7160e01b600052604160045260246000fdfe6080604052600436101561001257600080fd5b60003560e01c806308bbb824146108e15780631d28dc27146108b857806342842e0e146106f65780634a30d3eb1461065d5780634e897e161461014a57806366345da4146101215780638e6f4fb7146100cb578063e00dd161146100ad5763fc0c546a1461007f57600080fd5b346100a85760003660031901126100a8576003546040516001600160a01b039091168152602090f35b600080fd5b346100a85760003660031901126100a8576020600154604051908152f35b346100a85760203660031901126100a857600435600052600560205260806040600020805490600181015490600360018060a01b0360028301541691015491604051938452602084015260408301526060820152f35b346100a85760003660031901126100a8576004546040516001600160a01b039091168152602090f35b346100a85760e03660031901126100a857610163610982565b61016b61096c565b906044359160a4359161018960018060a01b03600454163314610998565b610191610a90565b6003546000926001600160a01b03918216911681900361062a576040516370a0823160e01b815230600482015290602082602481845afa918215610451576000926105f6575b506040516370a0823160e01b8152336004820152602081602481855afa80156104515787916000916105c1575b501061058557604051636eb1769f60e11b8152336004820152306024820152602081604481855afa8015610451578791600091610550575b50106105125760206000604051828101906323b872dd60e01b825233602482015230604482015289606482015260648152610278608482610a47565b519082855af115610451576000513d6105095750803b155b6104f557906020602492604051938480926370a0823160e01b82523060048301525afa918215610451576000926104be575b508103908111610375578403610488576004546001600160a01b039182169116810361038b5750506001549160001983146103755760036001602094018060015580936040519361031285610a15565b84528584019081526000604080860182815242606088019081529483526005895291209451855590516001850155516002840180546001600160a01b0319166001600160a01b0392909216919091179055519101555b6001600055604051908152f35b634e487b7160e01b600052601160045260246000fd5b60035460025460405163095ea7b360e01b81526001600160a01b039182166004820152602481018790529495939493929160209185916044918391600091165af19081156104515760209360649261045d575b50600060018060a01b0360025416604051978895869463445415b960e11b86526004860152602485015260448401525af191821561045157602092610424575b50610368565b61044390833d851161044a575b61043b8183610a47565b810190610a81565b508261041e565b503d610431565b6040513d6000823e3d90fd5b61047c90853d8711610481575b6104748183610a47565b810190610a69565b6103de565b503d61046a565b60405162461bcd60e51b815260206004820152600e60248201526d2a3930b739b332b91032b93937b960911b6044820152606490fd5b90916020823d6020116104ed575b816104d960209383610a47565b810103126104ea57505190866102c2565b80fd5b3d91506104cc565b635274afe760e01b60005260045260246000fd5b60011415610290565b60405162461bcd60e51b8152602060048201526016602482015275496e73756666696369656e7420616c6c6f77616e636560501b6044820152606490fd5b9150506020813d60201161057d575b8161056c60209383610a47565b810103126100a8578690518861023c565b3d915061055f565b60405162461bcd60e51b8152602060048201526014602482015273496e73756666696369656e742062616c616e636560601b6044820152606490fd5b9150506020813d6020116105ee575b816105dd60209383610a47565b810103126100a85786905188610204565b3d91506105d0565b9091506020813d602011610622575b8161061260209383610a47565b810103126100a8575190866101d7565b3d9150610605565b60405162461bcd60e51b815260206004820152600b60248201526a3bb937b733903a37b5b2b760a91b6044820152606490fd5b346100a85760203660031901126100a857610676610982565b61067e610a90565b6002546001600160a01b031633036100a857600454906001600160a01b0382166106c3576001600160a01b03166001600160a01b031991909116176004556001600055005b60405162461bcd60e51b815260206004820152600b60248201526a185b1c9958591e481cd95d60aa1b6044820152606490fd5b346100a85760603660031901126100a85761070f610982565b5061071861096c565b60443590610724610a90565b61073960018060a01b03600454163314610998565b8160005260056020526040600020906040519061075582610a15565b825482526107d560018401549160208401928352610792600360018060a01b036002880154169660408701978852015480606087015242146109d5565b600354600254855160405163095ea7b360e01b81526001600160a01b03928316600482015260248101919091529360209285921690829060009082906044820190565b03925af180156104515760209460849360009261089d575b506002549051945196516040516360b5f69f60e01b81526001600160a01b0394851660048201526024810196909652604486019790975295821660648501529294859384929091165af180156104515761086e575b506000526005602052600060036040822082815582600182015582600282015501556001600055600080f35b6020813d602011610895575b8161088760209383610a47565b810103126100a85751610842565b3d915061087a565b6108b390873d8911610481576104748183610a47565b6107ed565b346100a85760003660031901126100a8576002546040516001600160a01b039091168152602090f35b346100a85760403660031901126100a8576004356108fd61096c565b90610906610a90565b61091b60018060a01b03600454163314610998565b80600052600560205261093760036040600020015442146109d5565b600090815260056020526040812060020180546001600160a01b0319166001600160a01b039093169290921790915560019055005b602435906001600160a01b03821682036100a857565b600435906001600160a01b03821682036100a857565b1561099f57565b60405162461bcd60e51b815260206004820152600e60248201526d0850db185a5b50dbdb9d1c9858dd60921b6044820152606490fd5b156109dc57565b60405162461bcd60e51b81526020600482015260116024820152700696e76616c69642074696d657374616d7607c1b6044820152606490fd5b6080810190811067ffffffffffffffff821117610a3157604052565b634e487b7160e01b600052604160045260246000fd5b90601f8019910116810190811067ffffffffffffffff821117610a3157604052565b908160209103126100a8575180151581036100a85790565b908160209103126100a8575190565b600260005414610aa1576002600055565b633ee5aeb560e01b60005260046000fdfea26469706673582212208180dffb9a18f74801908bfe8c75aaed09ea0a559eb1f5a752ca6c78b1b518e364736f6c634300081c00330000000000000000000000000b010000b7624eb9b3dfbc279673c76e9d29d5f700000000000000000000000042d201cc4d9c1e31c032397f54cace2f48c1fa72000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000140000000000000000000000000000000000000000000000000000000000000000b4f626f6c4c6f636b75707300000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000044f424c5300000000000000000000000000000000000000000000000000000000
Deployed Bytecode
0x608080604052600436101561001357600080fd5b600090813560e01c9081629a9b7b1461174d5750806301ffc9a7146116c457806306fdde0314611609578063081812fc146115cc57806308bbb82414611579578063095ea7b3146114915780630d7955161461138857806313d033c01461136a57806318160ddd1461134c57806323b872dd146113345780632f745c59146112bc5780633808d901146111c357806342842e0e146111935780634a30d3eb14610ffa5780634f6ccce714610faa5780635c546d1f14610f8f57806360b5f69f14610f2d5780636198e33914610e655780636352211e14610e3457806366345da414610e0b57806370a0823114610de75780637ebbec5c14610d6a5780637f2b114414610d4157806381893c7c14610cc657806388a82b7214610c855780638bad00ee14610bff5780638e1f81bb14610bda5780638e6f4fb714610b8e57806392ff0d3114610b6857806395d89b4114610a5b5780639dd373b91461098b578063a22cb465146108eb578063a8713ec7146108b8578063ab2de76e146106bb578063abf4882014610625578063b88d4fde146105c3578063be9a6555146105a5578063c3f368af14610556578063c87b56dd146104fb578063e6239f4214610304578063e985e9c5146102aa578063ee99205c14610281578063ef78d4fd14610263578063f851a4401461023a5763fc0c546a1461020f57600080fd5b34610237578060031936011261023757600c546040516001600160a01b039091168152602090f35b80fd5b5034610237578060031936011261023757600d546040516001600160a01b039091168152602090f35b50346102375780600319360112610237576020601454604051908152f35b5034610237578060031936011261023757600f546040516001600160a01b039091168152602090f35b50346102375760403660031901126102375760406102c66117c5565b916102cf6117aa565b9260018060a01b031681526005602052209060018060a01b0316600052602052602060ff604060002054166040519015158152f35b5034610237576080366003190112610237576004356064356001600160401b0381116104f7576103389036906004016119ae565b90610341611ccc565b61035d61034d82611c95565b6001600160a01b031633146119f5565b600f546001600160a01b0316156104b257808352601660205260408320546001600160a01b03161561047f57826103938261245f565b600f549293926001600160a01b0391821692911690823b156104705761040492849283604051809681958294630fcf4e2760e21b8452600484015260018060a01b03169b8c60248401528a60448401526024356064840152604435608484015260c060a484015260c4830190611769565b03925af1801561047457610453575b507f80fec2f85f5b4366aa375af201362a4a8b18a2633abe222a5aec96abf43a84a3606084868560405192835260208301526040820152a16001600a5580f35b906104609193929361180c565b8360001261047057908338610413565b8380fd5b6040513d84823e3d90fd5b60405162461bcd60e51b815260206004820152600b60248201526a3b30bab63a1032b93937b960a91b6044820152606490fd5b60405162461bcd60e51b815260206004820152601860248201527f5374616b696e6720636f6e7472616374206e6f742073657400000000000000006044820152606490fd5b8280fd5b503461023757602036600319011261023757610518600435611c95565b506020908060405161052a848261180c565b52506040519061053a818361180c565b60008252610552604051928284938452830190611769565b0390f35b503461023757806003193601126102375761059660209161057d610578611b88565b611c49565b50601254601354601454918082111561059e5750612923565b604051908152f35b9050612923565b50346102375780600319360112610237576020601254604051908152f35b5034610237576080366003190112610237576105dd6117c5565b6105e56117aa565b90604435606435926001600160401b0384116106215761060c61061e9436906004016119ae565b92610618838383611ad2565b336129da565b80f35b8480fd5b5034610237576106986105529161063b3661197d565b9190610648610578611b88565b81526015602052604081206040805192610661846117db565b8254938481526002600185015494856020840152015492839101525080156000146106b55750601254915b60135460145493612943565b604080519384526020840192909252908201529081906060820190565b9161068c565b5034610237576080366003190112610237576004356001600160401b0381116108b4576106ec903690600401611844565b906024356001600160401b0381116108b45761070c9036906004016118b2565b916044356001600160401b0381116104f75761072c9036906004016118b2565b926064356001600160401b0381116104705761074c903690600401611844565b90610755611ccc565b8251815180911490816108a9575b508061089e575b61077390611a2a565b61077d8351611a76565b948351936107a361078d8661182d565b9561079b604051978861180c565b80875261182d565b6020860190601f1901368237865b825181101561083b576001906107f06001600160a01b036107d28387611aa8565b51166107de8389611aa8565b516107e98489611aa8565b5191611edb565b6107fa828c611aa8565b52610821610808828c611aa8565b51838060a01b03610819848b611aa8565b511690611d26565b61082b828a611aa8565b90838060a01b03169052016107b1565b61085d89838a8a6001600a55602060405195869560408752604087019061190f565b918583038287015251918281520192915b81811061087c575050500390f35b82516001600160a01b031684528594506020938401939092019160010161086e565b50845182511461076a565b905085511438610763565b5080fd5b503461023757602036600319011261023757602090600435815260168252604060018060a01b0391205416604051908152f35b5034610237576040366003190112610237576109056117c5565b602435908115158092036104f7576001600160a01b03169081156109775733835260056020526040832082600052602052604060002060ff1981541660ff83161790556040519081527f17307eab39ab6107e8899845ad3d59bd9653f200f220920489ca2b5937696c3160203392a380f35b630b61174360e31b83526004829052602483fd5b5034610237576020366003190112610237576109a56117c5565b6109ba60018060a01b03600d54163314611b38565b600f54906001600160a01b038216610a16576001600160a01b03166001600160a01b0319919091168117600f556040519081527f1253844b0fff3da7dd2829de816c9b4f94c238cf2bf6eb72c02c7d6f2b53beac90602090a180f35b60405162461bcd60e51b815260206004820152601c60248201527f5374616b696e6720636f6e747261637420616c726561647920736574000000006044820152606490fd5b50346102375780600319360112610237576040519080600154908160011c91600181168015610b5e575b602084108114610b4a57838652908115610b235750600114610ac6575b61055284610ab28186038261180c565b604051918291602083526020830190611769565b600181527fb10e2d527612073b26eecdfd717e6a320cf44b4afac2b0732d9fcbe2b7fa0cf6939250905b808210610b0957509091508101602001610ab282610aa2565b919260018160209254838588010152019101909291610af0565b60ff191660208087019190915292151560051b85019092019250610ab29150839050610aa2565b634e487b7160e01b83526022600452602483fd5b92607f1692610a85565b5034610237578060031936011261023757602060ff60115460a01c166040519015158152f35b5034610237576020366003190112610237576040906004358152601560205220805461055260026001840154930154604051938493846040919493926060820195825260208201520152565b50346102375780600319360112610237576020610bf5611c14565b6040519015158152f35b5034610237578060031936011261023757610c2560018060a01b03600d54163314611b38565b610c35610c30611c14565b611bd8565b600854815b818110610c45578280f35b60085415610c6e57600190610c68610c5c85611b6d565b90549060031b1c6127ba565b01610c3a565b60448363295f44f760e21b81528060045280602452fd5b5034610237576060366003190112610237576020610cb9610ca46117c5565b610cac611ccc565b6044359060243590611edb565b6001600a55604051908152f35b5034610237576020366003190112610237576004358015158091036108b45760207f11da1b8c0a94a11df636c4bcd3500335a4f11ec00f56b0a425b3354171b2cd9a91610d1e60018060a01b03600d54163314611b38565b6011805460ff60a01b191660a083901b60ff60a01b16179055604051908152a180f35b50346102375780600319360112610237576011546040516001600160a01b039091168152602090f35b5034610237576020366003190112610237576004356001600160401b0381116108b457610d9b9036906004016118b2565b90610db160018060a01b03600d54163314611b38565b610dbc610c30611c14565b805b8251811015610de35780610ddd610dd760019386611aa8565b516127ba565b01610dbe565b5080f35b5034610237576020366003190112610237576020610596610e066117c5565b611ba2565b50346102375780600319360112610237576010546040516001600160a01b039091168152602090f35b5034610237576020366003190112610237576020610e53600435611c95565b6040516001600160a01b039091168152f35b50346102375760203660031901126102375780610e97600435610e86611ccc565b610e9261034d82611c95565b61245f565b6001600160a01b0316918215610f0f57823b15610f0a576040516306b091f960e01b81526001600160a01b0392909216600483015260248201529082908290604490829084905af1801561047457610ef5575b50505b6001600a5580f35b81610eff9161180c565b610237578038610eea565b505050fd5b600c54610f2894509092506001600160a01b031661268c565b610eed565b503461023757608036600319011261023757610f476117c5565b90606435906001600160a01b03821682036102375750610f75610f6e604093610cac611ccc565b9182611d26565b6001600a5582519182526001600160a01b03166020820152f35b50346102375780600319360112610237576020610bf5611b88565b50346102375760203660031901126102375760043590600854821015610fe4576020610fd583611b6d565b90549060031b1c604051908152f35b60449163295f44f760e21b825281600452602452fd5b5034610237576020366003190112610237576110146117c5565b600e546001600160a01b03163314801561117f575b1561114857601054906001600160a01b038216611103576001600160a01b039081166001600160a01b0319929092168217601055601154839116803b156108b4578190602460405180948193634a30d3eb60e01b83528760048401525af180156110f8576110c1575b5060207fbf77f8a166e9bdd137896351a3fea0853166f5ad052c99f89c0e300c5d4f213791604051908152a180f35b826110f07fbf77f8a166e9bdd137896351a3fea0853166f5ad052c99f89c0e300c5d4f2137939460209361180c565b929150611092565b6040513d85823e3d90fd5b60405162461bcd60e51b815260206004820152601a60248201527f436c61696d20636f6e747261637420616c7265616479207365740000000000006044820152606490fd5b60405162461bcd60e51b815260206004820152600f60248201526e10a232b83637bcb2b93e20b236b4b760891b6044820152606490fd5b50600d546001600160a01b03163314611029565b50346102375761061e6111a536611943565b90604051926111b560208561180c565b858452610618838383611ad2565b5034610237576111d23661197d565b6111e760018060a01b03600d54163314611b38565b6111ef611c14565b156112815781156104f75781811061123c57816040917fa766b7584bf930f86ae9902fced6a1da4a23e72e9f33cb4ba20f396800a53c54936012558060135582519182526020820152a180f35b60405162461bcd60e51b815260206004820152601960248201527f436c696666206d757374206265206166746572207374617274000000000000006044820152606490fd5b60405162461bcd60e51b815260206004820152601360248201527210d85b9b9bdd0818da185b99d9481cdd185c9d606a1b6044820152606490fd5b5034610237576040366003190112610237576112d66117c5565b906024356112e383611ba2565b811015611311579060409160209360018060a01b031682526006845282822090825283522054604051908152f35b63295f44f760e21b82526001600160a01b03909216600452602491909152604490fd5b50346102375761061e61134636611943565b91611ad2565b50346102375780600319360112610237576020600854604051908152f35b50346102375780600319360112610237576020601354604051908152f35b5034610237576060366003190112610237576004356001600160401b0381116108b4576113b9903690600401611844565b6024356001600160401b0381116104f7576113d89036906004016118b2565b6044356001600160401b038111610470576113f79036906004016118b2565b6113ff611ccc565b611416835183518091149081611486575b50611a2a565b6114208351611a76565b935b835181101561146b5760019061145a6001600160a01b036114438388611aa8565b511661144f8387611aa8565b516107e98487611aa8565b6114648288611aa8565b5201611422565b6001600a55604051602080825281906105529082018861190f565b905082511438611410565b5034610237576040366003190112610237576114ab6117c5565b6024356114b781611c95565b33151580611566575b8061153b575b6115285781906001600160a01b0384811691167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b9258680a4825260046020526040822080546001600160a01b0319166001600160a01b0390921691909117905580f35b63a9fbf51f60e01b845233600452602484fd5b506001600160a01b038116845260056020908152604080862033875290915284205460ff16156114c6565b506001600160a01b0381163314156114c0565b50346102375760403660031901126102375760206115b560043561159b6117aa565b906115a4611ccc565b6115b061034d82611c95565b611d26565b6001600a556040516001600160a01b039091168152f35b5034610237576020366003190112610237576020906004356115ed81611c95565b50815260048252604060018060a01b0391205416604051908152f35b503461023757806003193601126102375760405190808054908160011c916001811680156116ba575b602084108114610b4a57838652908115610b23575060011461165e5761055284610ab28186038261180c565b8080527f290decd9548b62a8d60345a988386fc84ba6bc95484008f6362f93160ef3e563939250905b8082106116a057509091508101602001610ab282610aa2565b919260018160209254838588010152019101909291611687565b92607f1692611632565b50346102375760203660031901126102375760043563ffffffff60e01b81168091036108b45760209063780e9d6360e01b811490811561170a575b506040519015158152f35b6380ac58cd60e01b81149150811561173c575b811561172b575b50826116ff565b6301ffc9a760e01b14905082611724565b635b5e139f60e01b8114915061171d565b9050346108b457816003193601126108b457602090600b548152f35b919082519283825260005b848110611795575050826000602080949584010152601f8019910116010190565b80602080928401015182828601015201611774565b602435906001600160a01b03821682036117c057565b600080fd5b600435906001600160a01b03821682036117c057565b606081019081106001600160401b038211176117f657604052565b634e487b7160e01b600052604160045260246000fd5b90601f801991011681019081106001600160401b038211176117f657604052565b6001600160401b0381116117f65760051b60200190565b9080601f830112156117c05781359061185c8261182d565b9261186a604051948561180c565b82845260208085019360051b8201019182116117c057602001915b8183106118925750505090565b82356001600160a01b03811681036117c057815260209283019201611885565b9080601f830112156117c05781356118c98161182d565b926118d7604051948561180c565b81845260208085019260051b8201019283116117c057602001905b8282106118ff5750505090565b81358152602091820191016118f2565b906020808351928381520192019060005b81811061192d5750505090565b8251845260209384019390920191600101611920565b60609060031901126117c0576004356001600160a01b03811681036117c057906024356001600160a01b03811681036117c0579060443590565b60409060031901126117c0576004359060243590565b6001600160401b0381116117f657601f01601f191660200190565b81601f820112156117c0578035906119c582611993565b926119d3604051948561180c565b828452602083830101116117c057816000926020809301838601378301015290565b156119fc57565b60405162461bcd60e51b815260206004820152600660248201526510a7bbb732b960d11b6044820152606490fd5b15611a3157565b60405162461bcd60e51b815260206004820152601860248201527f4172726179206c656e67746873206d757374206d6174636800000000000000006044820152606490fd5b90611a808261182d565b611a8d604051918261180c565b8281528092611a9e601f199161182d565b0190602036910137565b8051821015611abc5760209160051b010190565b634e487b7160e01b600052603260045260246000fd5b91906001600160a01b03811615611b2257611aef908233916123f7565b6001600160a01b039081169216808303611b0857505050565b6364283d7b60e01b60005260045260245260445260646000fd5b633250574960e11b600052600060045260246000fd5b15611b3f57565b60405162461bcd60e51b815260206004820152600660248201526510a0b236b4b760d11b6044820152606490fd5b600854811015611abc57600860005260206000200190600090565b6012548015159081611b98575090565b9050601354101590565b6001600160a01b03168015611bc257600052600360205260406000205490565b6322718ad960e21b600052600060045260246000fd5b15611bdf57565b60405162461bcd60e51b815260206004820152600d60248201526c10d85b9b9bdd0818d85b98d95b609a1b6044820152606490fd5b611c316012546013546014549180821160001461059e5750612923565b42108015611c3c5790565b50611c45611b88565b1590565b15611c5057565b60405162461bcd60e51b815260206004820152601760248201527f537461727420616e6420636c696666206e6f74207365740000000000000000006044820152606490fd5b6000818152600260205260409020546001600160a01b0316908115611cb8575090565b637e27328960e01b60005260045260246000fd5b6002600a5414611cdd576002600a55565b633ee5aeb560e01b60005260046000fd5b15611cf557565b60405162461bcd60e51b815260206004820152600960248201526821306164647265737360b81b6044820152606490fd5b6001600160a01b0390911691906000611d40841515611cee565b818152601660205260408120546001600160a01b0316611ebf57818152601660205260408120546001600160a01b031661023757818152601560205260408120600260405191611d8f836117db565b80548352600181015460208401520154604082015260018060a01b03600c541660405190610b2a90818301918383106001600160401b03841117611eab57918391602093612eeb8439815203019083f080156104745783835260166020526040832080546001600160a01b0319166001600160a01b03928316908117909155600c5492519092611e219284911661268c565b935b6001600160a01b03851691823b156102375760405163b1161b8b60e01b815260048101839052818160248183885af1801561047457917f07c8b05a99629c65d5860c1bc71b959cd208f1e3df276e6a88706e704f08368395939160609593611e9b575b505060405192835260208301526040820152a1565b81611ea59161180c565b38611e86565b634e487b7160e01b86526041600452602486fd5b818152601660205260408120546001600160a01b031693611e23565b6001600160a01b03811680159493919290611ef68615611cee565b81156123c757821561239957600c546040516370a0823160e01b81523060048201526001600160a01b0390911690602081602481855afa90811561227757600091612367575b506040516370a0823160e01b8152336004820152602081602481865afa8015612277578591600091612332575b50106122f657604051636eb1769f60e11b8152336004820152306024820152602081604481865afa80156122775785916000916122c1575b5010612283576020602492611fe46040516323b872dd60e01b84820152338682015230604482015287606482015260648152611fde60848261180c565b82612e8f565b6040516370a0823160e01b815230600482015293849182905afa801561227757849260009161223e575b50612023929161201d91612642565b1461264f565b600b546000198114612228576001019384600b55849660125460026040519161204b836117db565b86835260208301888152604084019182528960005260156020526040600020935184555160018401555191015560209160405191612089848461180c565b60008352611b225761209d60008883612b17565b6001600160a01b0316612212573b6120ef575b5091608093917f0d88bbb65a89350823f139de4b4989865fdb4412b90d6fcc93d393c17c178bf8959360405194855284015260408301526060820152a1565b8161213191604099979593989694995180938192630a85bd0160e11b835233600484015260006024840152886044840152608060648401526084830190611769565b038160008c5af180916000916121d4575b50906121995787873d15612192573d61215a81611993565b90612168604051928361180c565b81523d60008383013e5b8051918261218f5783633250574960e11b60005260045260246000fd5b01fd5b6060612172565b630a85bd0160e198939597929496981b9063ffffffff60e01b16036121bf5760806120b0565b50633250574960e11b60005260045260246000fd5b8881813d831161220b575b6121e9818361180c565b810103126108b45751906001600160e01b031982168203610237575038612142565b503d6121df565b6339e3563760e11b600052600060045260246000fd5b634e487b7160e01b600052601160045260246000fd5b9250506020823d60201161226f575b8161225a6020938361180c565b810103126117c057905183919061202361200e565b3d915061224d565b6040513d6000823e3d90fd5b60405162461bcd60e51b8152602060048201526016602482015275496e73756666696369656e7420616c6c6f77616e636560501b6044820152606490fd5b9150506020813d6020116122ee575b816122dd6020938361180c565b810103126117c05784905138611fa1565b3d91506122d0565b60405162461bcd60e51b8152602060048201526014602482015273496e73756666696369656e742062616c616e636560601b6044820152606490fd5b9150506020813d60201161235f575b8161234e6020938361180c565b810103126117c05784905138611f69565b3d9150612341565b90506020813d602011612391575b816123826020938361180c565b810103126117c0575138611f3c565b3d9150612375565b60405162461bcd60e51b815260206004820152600660248201526530207261746560d01b6044820152606490fd5b60405162461bcd60e51b81526020600482015260086024820152670c08185b5bdd5b9d60c21b6044820152606490fd5b91906001600160a01b0382166124135761241092612b17565b90565b60ff60115460a01c161561242a5761241092612b17565b60405162461bcd60e51b815260206004820152600d60248201526c215472616e7366657261626c6560981b6044820152606490fd5b90612468611c14565b61261457816000526015602052600260406000200154156125fa575b81600052601560205260406000206040519161249f836117db565b815483526002600183015492602085019384520154916040840192808452601254116125c757612500906124d286611c95565b9486600052601660205260018060a01b03604060002054169451916013549151905190601454924294612943565b9195861561258c577fe6e434f2e8baea3ea5cef95e4d4bb2a7fadb13e96db47645ff2174c6869a8e9f926080928881612570578360005260156020526000600260408220828155826001820155015561255884612e72565b604051938452602084015260408301526060820152a1565b6000848152601560205260409020828155600201839055612558565b60405162461bcd60e51b81526020600482015260136024820152724e6f20746f6b656e7320746f20756e6c6f636b60681b6044820152606490fd5b60405162461bcd60e51b815260206004820152600b60248201526a3932b9b2ba1032b93937b960a91b6044820152606490fd5b601254826000526015602052600260406000200155612484565b60405162461bcd60e51b8152602060048201526006602482015265131bd8dad95960d21b6044820152606490fd5b9190820391821161222857565b1561265657565b60405162461bcd60e51b815260206004820152600e60248201526d2a3930b739b332b91032b93937b960911b6044820152606490fd5b6040516370a0823160e01b81526001600160a01b03808416600483018190529194939083169290602086602481875afa95861561227757600096612780575b5060405163a9059cbb60e01b6020808301919091526001600160a01b0392909216602482015260448082018790528152909291612713919061270e60648361180c565b612e8f565b6024604051809481936370a0823160e01b835260048301525afa9081156122775760009161274c575b5061274a9261201d91612642565b565b90506020813d602011612778575b816127676020938361180c565b810103126117c0575161274a61273c565b3d915061275a565b92919095506020833d6020116127b2575b8161279e6020938361180c565b810103126117c057915194909190846126cb565b3d9150612791565b6000818152601560205260408120604051906127d5826117db565b600281549182845260018101546020850152015460408301521561291e57828252601660205260408220546001600160a01b031680156128c957600d549151916001600160a01b0316813b15610470576040516306b091f960e01b81526001600160a01b03919091166004820152602481019290925282908290604490829084905af180156104745760026040847f3d14f8a8ee840763e5c7081a8d6ec54d7be72b68268ce135e67e0078e6a15b8296946020966000956128b9575b50505b848152601586522082815582600182015501556128b081612e72565b604051908152a1565b6128c29161180c565b3881612891565b50600c54600d5491517f3d14f8a8ee840763e5c7081a8d6ec54d7be72b68268ce135e67e0078e6a15b8294602094909360009360029360409392612919926001600160a01b03918216911661268c565b612894565b505050565b9190820180921161222857565b8181029291811591840414171561222857565b94959391929095600096818088119182156129d0575b505015612967575050509190565b6129779193965094809295612642565b84156129ba5761241092612991866129aa93049182612930565b8781116129b0576129a4905b8098612642565b95612930565b90612923565b506129a48761299d565b634e487b7160e01b600052601260045260246000fd5b1190508138612959565b823b6129e8575b5050505050565b604051630a85bd0160e11b81526001600160a01b039182166004820152918116602483015260448201939093526080606482015291169160209082908190612a34906084830190611769565b03816000865af18091600091612ad4575b5090612a9e57503d15612a97573d612a5c81611993565b90612a6a604051928361180c565b81523d6000602083013e5b80519081612a925782633250574960e11b60005260045260246000fd5b602001fd5b6060612a75565b6001600160e01b03191663757a42ff60e11b01612ac0575038808080806129e1565b633250574960e11b60005260045260246000fd5b6020813d602011612b0f575b81612aed6020938361180c565b810103126108b45751906001600160e01b031982168203610237575038612a45565b3d9150612ae0565b6000828152600260205260409020546001600160a01b03908116939192911680151580612ddc575b50508215918215612d9e575b6001600160a01b038116928315908115612d84575b8360005260026020526040600020856bffffffffffffffffffffffff60a01b8254161790558385877fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef600080a415612cf95760085483600052600960205280604060002055680100000000000000008110156117f65783612bea826001612c039401600855611b6d565b90919082549060031b91821b91600019901b1916179055565b15612ca457509050600854600019810190811161222857816000526009602052612c3260406000205491611b6d565b90549060031b1c612c4681612bea84611b6d565b60005260096020526040600020556000526009602052600060408120556008548015612c8e5760001901612c7981611b6d565b8154906000199060031b1b1916905560085590565b634e487b7160e01b600052603160045260246000fd5b828403612cb2575b50505090565b612cbb90611ba2565b600019810192908311612228576000526006602052604060002082600052602052806040600020556000526007602052604060002055388080612cac565b848414612c0357612d0985611ba2565b83600052600760205260406000205490866000526006602052604060002091818103612d53575b508460005260076020526000604081205560005260205260006040812055612c03565b8160005282602052604060002054816000528360205280604060002055600052600760205260406000205538612d30565b846000526003602052604060002060018154019055612b60565b81600052600460205260406000206bffffffffffffffffffffffff60a01b815416905583600052600360205260406000206000198154019055612b4b565b80612e1e575b15612ded5780612b3f565b83612e075750637e27328960e01b60005260045260246000fd5b63177e802f60e01b60005260045260245260446000fd5b508084148015612e4e575b80612de257506000828152600460205260409020546001600160a01b03168114612de2565b5083600052600560205260406000208160005260205260ff60406000205416612e29565b612e7e60008281612b17565b6001600160a01b031615611cb85750565b906000602091828151910182855af115612277576000513d612ee157506001600160a01b0381163b155b612ec05750565b635274afe760e01b60009081526001600160a01b0391909116600452602490fd5b60011415612eb956fe608034607e57601f610b2a38819003918201601f19168301916001600160401b03831184841017608357808492602094604052833981010312607e57516001600160a01b03811690819003607e57600180546001600160a01b0319908116331790915560008054909116919091179055604051610a90908161009a8239f35b600080fd5b634e487b7160e01b600052604160045260246000fdfe608080604052600436101561001357600080fd5b600090813560e01c90816306b091f914610610575080633f3d389c146102a0578063b1161b8b146100aa578063f77c4791146100815763fc0c546a1461005857600080fd5b3461007e578060031936011261007e57546040516001600160a01b039091168152602090f35b80fd5b503461007e578060031936011261007e576001546040516001600160a01b039091168152602090f35b503461007e57602036600319011261007e576100c46107ef565b6001546001600160a01b03163303610225578154604051632c3e6f0f60e11b81523060048201529183916001600160a01b031690602084602481855afa93841561020557839461026f575b506001600160a01b039081169316839003610128575080f35b6040516370a0823160e01b815230600482015292602084602481855afa938415610205578394610238575b50813b156102345782916024839260405194859384926317066a5760e21b845260048401525af1801561022957610210575b505081546040516370a0823160e01b81523060048201529190602090839060249082906001600160a01b03165afa9182156102055783926101cc575b500361007e57388180f35b9091506020813d6020116101fd575b816101e860209383610805565b810103126101f8575190386101c1565b600080fd5b3d91506101db565b6040513d85823e3d90fd5b8161021a91610805565b610225578138610185565b5080fd5b6040513d84823e3d90fd5b8280fd5b925092506020823d602011610267575b8161025560209383610805565b810103126101f8578391519238610153565b3d9150610248565b61029291945060203d602011610299575b61028a8183610805565b81019061083d565b923861010f565b503d610280565b503461007e5760c036600319011261007e576102ba6107ef565b6024356001600160a01b038116919082810361060c576044359160a43567ffffffffffffffff81116105f457366023820112156105f45780600401359067ffffffffffffffff82116105f8578690604051926103206020601f19601f8401160185610805565b8084523660248284010111610234578060246020930183860137830101526001546001600160a01b031633036105f4578554604051632c3e6f0f60e11b815230600482015291906001600160a01b0316602083602481845afa9283156105535788936105cf575b50602060249160405192838092632c3e6f0f60e11b82528b60048301525afa9081156105535788916105b0575b506040516303132d5760e21b81526001600160a01b03851693602082600481885afa9182156105a5578a92610584575b506001600160a01b0316918215918215610571575b50811561055e575b5015610423575050855461042095506001600160a01b03169050610874565b80f35b9194909360405192630a79f5b160e41b845260048401526020836024818b8a5af1928315610553578893610519575b5087549293610469936001600160a01b0316610874565b823b1561051557928491604051948592635e1a771160e11b8452600484015260248301526064356044830152608435606483015260a060848301528051908160a4840152835b8281106104fa57505092818360c482878383819a84010152601f801991011681010301925af180156104ed576104e457505080f35b61042091610805565b50604051903d90823e3d90fd5b602081830181015160c48984010152889550879450016104af565b8480fd5b92506020833d60201161054b575b8161053460209383610805565b8101031261054757610469925192610452565b8780fd5b3d9150610527565b6040513d8a823e3d90fd5b6001600160a01b03168214905038610401565b6001600160a01b031683149150386103f9565b61059e91925060203d6020116102995761028a8183610805565b90386103e4565b6040513d8c823e3d90fd5b6105c9915060203d6020116102995761028a8183610805565b386103b4565b60249193506105ec602091823d84116102995761028a8183610805565b939150610387565b8580fd5b634e487b7160e01b87526041600452602487fd5b8380fd5b9050346102255760403660031901126102255761062b6107ef565b60015460243592906001600160a01b0316330361060c5783546370a0823160e01b82526001600160a01b03838116600484018190529116928590602084602481885afa9384156102295782946107b8575b5060405163a9059cbb60e01b60208083019182526001600160a01b0393909316602483015260448083018990528252919291906106ba606482610805565b519082875af1156107905784513d6107af5750823b155b61079b576020906024604051809581936370a0823160e01b835260048301525afa91821561079057849261075c575b50810390811161074857036107125780f35b60405162461bcd60e51b815260206004820152600e60248201526d2a3930b739b332b91032b93937b960911b6044820152606490fd5b634e487b7160e01b83526011600452602483fd5b9091506020813d602011610788575b8161077860209383610805565b8101031261060c57519038610700565b3d915061076b565b6040513d86823e3d90fd5b635274afe760e01b85526004839052602485fd5b600114156106d1565b919093506020823d6020116107e7575b816107d560209383610805565b8101031261007e57905192602061067c565b3d91506107c8565b600435906001600160a01b03821682036101f857565b90601f8019910116810190811067ffffffffffffffff82111761082757604052565b634e487b7160e01b600052604160045260246000fd5b908160209103126101f857516001600160a01b03811681036101f85790565b908160209103126101f8575180151581036101f85790565b60405163095ea7b360e01b81526001600160a01b03838116600483015260248201869052919091169391906020816044816000895af1801561099357610a3d575b5060405163534a7e1d60e11b815260048101929092526001600160a01b0316926020826024816000885af191821561099357600092610a08575b50602060449160405192838092636eb1769f60e11b82523060048301528860248301525afa908115610993576000916109d6575b5061099f5760405163a9059cbb60e01b81526001600160a01b03929092166004830152602482015290602090829060449082906000905af18015610993576109685750565b6109899060203d60201161098c575b6109818183610805565b81019061085c565b50565b503d610977565b6040513d6000823e3d90fd5b60405162461bcd60e51b815260206004820152600f60248201526e20b63637bbb0b731b29032b93937b960891b6044820152606490fd5b90506020813d602011610a00575b816109f160209383610805565b810103126101f8575138610923565b3d91506109e4565b9091506020813d602011610a35575b81610a2460209383610805565b810103126101f857519060206108ef565b3d9150610a17565b610a559060203d60201161098c576109818183610805565b6108b556fea26469706673582212203919338163182d11d9b9089e6ef961fd038bd40e17411756eeacbe4c361cee6264736f6c634300081c0033a26469706673582212202d03b2bfa6b25e09db62096c6d493e550b21ecc6ff8c592af1eb5692ef43517564736f6c634300081c0033
Constructor Arguments (ABI-Encoded and is the last bytes of the Contract Creation Code above)
0000000000000000000000000b010000b7624eb9b3dfbc279673c76e9d29d5f700000000000000000000000042d201cc4d9c1e31c032397f54cace2f48c1fa72000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000140000000000000000000000000000000000000000000000000000000000000000b4f626f6c4c6f636b75707300000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000044f424c5300000000000000000000000000000000000000000000000000000000
-----Decoded View---------------
Arg [0] : _token (address): 0x0B010000b7624eb9B3DfBC279673C76E9D29D5F7
Arg [1] : _admin (address): 0x42D201CC4d9C1e31c032397F54caCE2f48C1FA72
Arg [2] : _transferable (bool): False
Arg [3] : _start (uint256): 0
Arg [4] : _cliff (uint256): 0
Arg [5] : _period (uint256): 1
Arg [6] : _name (string): ObolLockups
Arg [7] : _symbol (string): OBLS
-----Encoded View---------------
12 Constructor Arguments found :
Arg [0] : 0000000000000000000000000b010000b7624eb9b3dfbc279673c76e9d29d5f7
Arg [1] : 00000000000000000000000042d201cc4d9c1e31c032397f54cace2f48c1fa72
Arg [2] : 0000000000000000000000000000000000000000000000000000000000000000
Arg [3] : 0000000000000000000000000000000000000000000000000000000000000000
Arg [4] : 0000000000000000000000000000000000000000000000000000000000000000
Arg [5] : 0000000000000000000000000000000000000000000000000000000000000001
Arg [6] : 0000000000000000000000000000000000000000000000000000000000000100
Arg [7] : 0000000000000000000000000000000000000000000000000000000000000140
Arg [8] : 000000000000000000000000000000000000000000000000000000000000000b
Arg [9] : 4f626f6c4c6f636b757073000000000000000000000000000000000000000000
Arg [10] : 0000000000000000000000000000000000000000000000000000000000000004
Arg [11] : 4f424c5300000000000000000000000000000000000000000000000000000000
Loading...
Loading
Loading...
Loading
[ Download: CSV Export ]
[ Download: CSV Export ]
A token is a representation of an on-chain or off-chain asset. The token page shows information such as price, total supply, holders, transfers and social links. Learn more about this page in our Knowledge Base.