More Info
Private Name Tags
ContractCreator
Latest 25 from a total of 201 transactions
Transaction Hash |
Method
|
Block
|
From
|
To
|
|||||
---|---|---|---|---|---|---|---|---|---|
Get Rewards | 20751868 | 132 days ago | IN | 0 ETH | 0.00013259 | ||||
Exit First Sum O... | 20751856 | 132 days ago | IN | 0 ETH | 0.00035487 | ||||
Exit First Sum O... | 20239372 | 204 days ago | IN | 0 ETH | 0.00166777 | ||||
Get Rewards | 20239365 | 204 days ago | IN | 0 ETH | 0.00178561 | ||||
Get Rewards | 19737201 | 274 days ago | IN | 0 ETH | 0.00061714 | ||||
Withdraw First S... | 19737187 | 274 days ago | IN | 0 ETH | 0.00082901 | ||||
Withdraw First S... | 19737180 | 274 days ago | IN | 0 ETH | 0.00088949 | ||||
Withdraw First S... | 19737171 | 274 days ago | IN | 0 ETH | 0.00137667 | ||||
Exit First Sum O... | 19655777 | 285 days ago | IN | 0 ETH | 0.00229586 | ||||
Get Rewards | 19096076 | 364 days ago | IN | 0 ETH | 0.00082014 | ||||
Exit First Sum O... | 19096074 | 364 days ago | IN | 0 ETH | 0.00206176 | ||||
Exit First Sum O... | 18983233 | 380 days ago | IN | 0 ETH | 0.00471789 | ||||
Exit First Sum O... | 18926330 | 388 days ago | IN | 0 ETH | 0.0037067 | ||||
Get Rewards | 18926277 | 388 days ago | IN | 0 ETH | 0.00192714 | ||||
Get Rewards | 18926275 | 388 days ago | IN | 0 ETH | 0.00337152 | ||||
Exit First Sum O... | 18854749 | 398 days ago | IN | 0 ETH | 0.00304107 | ||||
Exit First Sum O... | 18608817 | 432 days ago | IN | 0 ETH | 0.00609146 | ||||
Exit First Sum O... | 18580081 | 436 days ago | IN | 0 ETH | 0.00700083 | ||||
Exit First Sum O... | 18447829 | 455 days ago | IN | 0 ETH | 0.00326222 | ||||
Exit First Sum O... | 18436720 | 456 days ago | IN | 0 ETH | 0.00380533 | ||||
Get Rewards | 18409543 | 460 days ago | IN | 0 ETH | 0.0012856 | ||||
Get Rewards | 18240832 | 484 days ago | IN | 0 ETH | 0.00055263 | ||||
Exit First Sum O... | 18240830 | 484 days ago | IN | 0 ETH | 0.00167447 | ||||
Get Rewards | 18196540 | 490 days ago | IN | 0 ETH | 0.00116749 | ||||
Get Rewards | 18190960 | 491 days ago | IN | 0 ETH | 0.00063678 |
View more zero value Internal Transactions in Advanced View mode
Advanced mode:
Loading...
Loading
Contract Source Code Verified (Exact Match)
Contract Name:
LsdxTreasury
Compiler Version
v0.8.12+commit.f00d7308
Optimization Enabled:
Yes with 590 runs
Other Settings:
default evmVersion
Contract Source Code (Solidity Standard Json-Input format)
// SPDX-License-Identifier: Apache-2.0 pragma solidity ^0.8.9; import "@openzeppelin/contracts/access/Ownable.sol"; import "@openzeppelin/contracts/security/ReentrancyGuard.sol"; import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol"; import "@openzeppelin/contracts/utils/Counters.sol"; import "@openzeppelin/contracts/utils/math/Math.sol"; import "@openzeppelin/contracts/utils/math/SafeMath.sol"; import "@openzeppelin/contracts/utils/structs/DoubleEndedQueue.sol"; import "@openzeppelin/contracts/utils/structs/EnumerableSet.sol"; import "./veLSD.sol"; contract LsdxTreasury is Ownable, ReentrancyGuard { using SafeMath for uint256; using SafeERC20 for IERC20; using Counters for Counters.Counter; using DoubleEndedQueue for DoubleEndedQueue.Bytes32Deque; using EnumerableSet for EnumerableSet.AddressSet; /* ========== STATE VARIABLES ========== */ IERC20 public lsdToken; veLSD public velsdToken; EnumerableSet.AddressSet private _rewardTokensSet; EnumerableSet.AddressSet private _rewardersSet; mapping(address => uint256) public periodFinish; mapping(address => uint256) public rewardRates; mapping(address => uint256) public rewardsPerTokenStored; mapping(address => uint256) public lastUpdateTime; mapping(address => mapping(address => uint256)) public userRewardsPerTokenPaid; mapping(address => mapping(address => uint256)) public rewards; uint256 private _totalSupply; mapping(address => uint256) private _balances; uint256 private _adminFee; Counters.Counter private _nextLockId; mapping(address => DoubleEndedQueue.Bytes32Deque) private _userVelsdLocked; mapping(uint256 => VelsdLocked) private _allVelsdLocked; struct VelsdLocked { uint256 lockId; uint256 amount; uint256 depositTime; } /* ========== CONSTRUCTOR ========== */ constructor( address _lsdToken, address[] memory _rewardTokens, address _velsdToken ) Ownable() { require(_lsdToken != address(0), "Zero address detected"); require(_rewardTokens.length > 0, "Empty reward token list"); require(_velsdToken != address(0), "Zero address detected"); lsdToken = IERC20(_lsdToken); for (uint256 i = 0; i < _rewardTokens.length; i++) { addRewardToken(_rewardTokens[i]); } addRewarder(_msgSender()); velsdToken = veLSD(_velsdToken); } /* ========== VIEWS ========== */ function totalSupply() external view returns (uint256) { return _totalSupply; } function balanceOf(address account) external view returns (uint256) { return _balances[account]; } function lastTimeRewardsApplicable(address rewardToken) public view onlyValidRewardToken(rewardToken) returns (uint256) { return Math.min(block.timestamp, periodFinish[rewardToken]); } function rewardsPerToken(address rewardToken) public view onlyValidRewardToken(rewardToken) returns (uint256) { if (_totalSupply == 0) { return rewardsPerTokenStored[rewardToken]; } return rewardsPerTokenStored[rewardToken].add( lastTimeRewardsApplicable(rewardToken) .sub(lastUpdateTime[rewardToken]) .mul(rewardRates[rewardToken]) .mul(1e18) .div(_totalSupply) ); } function earned(address account, address rewardToken) public view onlyValidRewardToken(rewardToken) returns (uint256) { return _balances[account] .mul(rewardsPerToken(rewardToken).sub(userRewardsPerTokenPaid[account][rewardToken])) .div(1e18) .add(rewards[account][rewardToken]); } function isSupportedRewardToken(address rewardToken) public view returns (bool) { return _rewardTokensSet.contains(rewardToken); } /// @dev No guarantees are made on the ordering function rewardTokens() public view returns (address[] memory) { return _rewardTokensSet.values(); } /// @dev No guarantees are made on the ordering function rewarders() public view returns (address[] memory) { return _rewardersSet.values(); } function velsdLockedCount(address user) public view returns (uint256) { return _userVelsdLocked[user].length(); } function velsdLockedInfoByIndex(address user, uint256 index) public view returns (VelsdLocked memory) { require(index < velsdLockedCount(user), "Index out of bounds"); DoubleEndedQueue.Bytes32Deque storage userLocked = _userVelsdLocked[user]; uint256 lockId = uint256(userLocked.at(index)); return _allVelsdLocked[lockId]; } /* ========== MUTATIVE FUNCTIONS ========== */ function depositAndLockToken(uint256 amount) external nonReentrant updateAllRewards(_msgSender()) { require(amount > 0, "Cannot deposit 0"); _totalSupply = _totalSupply.add(amount); _balances[_msgSender()] = _balances[_msgSender()].add(amount); lsdToken.safeTransferFrom(_msgSender(), address(this), amount); velsdToken.mint(_msgSender(), amount); _nextLockId.increment(); uint256 lockId = _nextLockId.current(); VelsdLocked memory lock = VelsdLocked({ lockId: lockId, amount: amount, depositTime: block.timestamp }); _allVelsdLocked[lockId] = lock; DoubleEndedQueue.Bytes32Deque storage userLocked = _userVelsdLocked[_msgSender()]; userLocked.pushBack(bytes32(lockId)); emit Deposited(_msgSender(), amount); } function withdrawFirstSumOfLockedToken() public nonReentrant updateAllRewards(_msgSender()) { DoubleEndedQueue.Bytes32Deque storage userLocked = _userVelsdLocked[_msgSender()]; require(!userLocked.empty(), "No deposit to withdraw"); uint256 lockId = uint256(userLocked.front()); VelsdLocked memory lock = _allVelsdLocked[lockId]; uint256 amount = lock.amount; userLocked.popFront(); delete _allVelsdLocked[lockId]; if (amount > 0) { _totalSupply = _totalSupply.sub(amount); _balances[_msgSender()] = _balances[_msgSender()].sub(amount); uint256 fee = calcAdminFee(lock); uint256 netAmount = amount.sub(fee); lsdToken.safeTransfer(_msgSender(), netAmount); velsdToken.burnFrom(_msgSender(), amount); emit Withdrawn(_msgSender(), amount, fee); if (fee > 0) { _adminFee = _adminFee.add(fee); emit AdminFeeAccrued(_msgSender(), amount, fee); } } } function calcAdminFee(VelsdLocked memory lock) public view returns (uint256) { require(lock.depositTime < block.timestamp, "Invalid deposit time"); require(lock.amount > 0, "Invalid deposit amount"); uint256 period = block.timestamp.sub(lock.depositTime); if (period < 7 days) { return lock.amount.mul(90).div(100); } else if (period < 30 days) { return lock.amount.mul(50).div(100); } else if (period < 90 days) { return lock.amount.mul(35).div(100); } else if (period < 180 days) { return lock.amount.mul(20).div(100); } else if (period < 365 days) { return lock.amount.mul(10).div(100); } else { return 0; } } function getRewards() public nonReentrant updateAllRewards(_msgSender()) { for (uint256 i = 0; i < _rewardTokensSet.length(); i++) { address currentToken = _rewardTokensSet.at(i); uint256 reward = rewards[_msgSender()][currentToken]; if (reward > 0) { rewards[_msgSender()][currentToken] = 0; IERC20(currentToken).safeTransfer(_msgSender(), reward); emit RewardsPaid(_msgSender(), currentToken, reward); } } } function exitFirstSumOfLockedToken() external { withdrawFirstSumOfLockedToken(); getRewards(); } /* ========== RESTRICTED FUNCTIONS ========== */ function addRewarder(address rewarder) public nonReentrant onlyOwner { require(rewarder != address(0), "Zero address detected"); require(!_rewardersSet.contains(rewarder), "Already added"); _rewardersSet.add(rewarder); emit RewarderAdded(rewarder); } function removeRewarder(address rewarder) public nonReentrant onlyOwner { require(_rewardersSet.contains(rewarder), "Not a rewarder"); require(_rewardersSet.remove(rewarder), "Failed to remove rewarder"); emit RewarderRemoved(rewarder); } function addRewardToken(address rewardToken) public nonReentrant onlyOwner { require(rewardToken != address(0), "Zero address detected"); require(!_rewardTokensSet.contains(rewardToken), "Already added"); _rewardTokensSet.add(rewardToken); emit RewardTokenAdded(rewardToken); } function addRewards(address rewardToken, uint256 rewardAmount, uint256 durationInDays) external nonReentrant onlyValidRewardToken(rewardToken) onlyRewarder { require(rewardAmount > 0, "Reward amount should be greater than 0"); require(durationInDays > 0, 'Reward duration too short'); uint256 rewardDuration = durationInDays.mul(1 days); IERC20(rewardToken).safeTransferFrom(_msgSender(), address(this), rewardAmount); _notifyRewardsAmount(rewardToken, rewardAmount, rewardDuration); } function _notifyRewardsAmount(address rewardToken, uint256 reward, uint256 rewardDuration) internal virtual onlyRewarder updateRewards(address(0), rewardToken) { if (block.timestamp >= periodFinish[rewardToken]) { rewardRates[rewardToken] = reward.div(rewardDuration); } else { uint256 remaining = periodFinish[rewardToken].sub(block.timestamp); uint256 leftover = remaining.mul(rewardRates[rewardToken]); rewardRates[rewardToken] = reward.add(leftover).div(rewardDuration); } uint balance = IERC20(rewardToken).balanceOf(address(this)); require(rewardRates[rewardToken] <= balance.div(rewardDuration), "Provided reward too high"); lastUpdateTime[rewardToken] = block.timestamp; periodFinish[rewardToken] = block.timestamp.add(rewardDuration); emit RewardsAdded(rewardToken, _msgSender(), reward, rewardDuration); } function adminFee() external view returns (uint256) { return _adminFee; } function withdrawAdminFee(address to) external nonReentrant onlyRewarder { require(_adminFee > 0, 'No admin fee to withdraw'); lsdToken.safeTransfer(to, _adminFee); emit AdminFeeWithdrawn(_msgSender(), to, _adminFee); _adminFee = 0; } /* ========== MODIFIERS ========== */ modifier onlyRewarder() { require(_rewardersSet.contains(_msgSender()), "Not a rewarder"); _; } modifier onlyValidRewardToken(address rewardToken) { require(isSupportedRewardToken(rewardToken), "Reward token not supported"); _; } modifier updateRewards(address account, address rewardToken) { _updateRewards(account, rewardToken); _; } modifier updateAllRewards(address account) { for (uint256 i = 0; i < _rewardTokensSet.length(); i++) { address rewardToken = _rewardTokensSet.at(i); _updateRewards(account, rewardToken); } _; } function _updateRewards(address account, address rewardToken) internal { require(isSupportedRewardToken(rewardToken), "Reward token not supported"); rewardsPerTokenStored[rewardToken] = rewardsPerToken(rewardToken); lastUpdateTime[rewardToken] = lastTimeRewardsApplicable(rewardToken); if (account != address(0)) { rewards[account][rewardToken] = earned(account, rewardToken); userRewardsPerTokenPaid[account][rewardToken] = rewardsPerTokenStored[rewardToken]; } } /* ========== EVENTS ========== */ event Deposited(address indexed user, uint256 amount); event Withdrawn(address indexed user, uint256 totalAmount, uint256 fee); event RewardsPaid(address indexed user, address indexed rewardToken, uint256 reward); event RewardTokenAdded(address indexed rewardToken); event RewardsAdded(address indexed rewardToken, address indexed rewarder, uint256 reward, uint256 rewardDuration); event RewarderAdded(address indexed rewarder); event RewarderRemoved(address indexed rewarder); event AdminFeeAccrued(address indexed user, uint256 totalAmount, uint256 fee); event AdminFeeWithdrawn(address indexed rewarder, address indexed to, uint256 amount); }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.7.0) (access/Ownable.sol) pragma solidity ^0.8.0; import "../utils/Context.sol"; /** * @dev Contract module which provides a basic access control mechanism, where * there is an account (an owner) that can be granted exclusive access to * specific functions. * * By default, the owner account will be the one that deploys the contract. This * can later be changed with {transferOwnership}. * * This module is used through inheritance. It will make available the modifier * `onlyOwner`, which can be applied to your functions to restrict their use to * the owner. */ abstract contract Ownable is Context { address private _owner; event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); /** * @dev Initializes the contract setting the deployer as the initial owner. */ constructor() { _transferOwnership(_msgSender()); } /** * @dev Throws if called by any account other than the owner. */ modifier onlyOwner() { _checkOwner(); _; } /** * @dev Returns the address of the current owner. */ function owner() public view virtual returns (address) { return _owner; } /** * @dev Throws if the sender is not the owner. */ function _checkOwner() internal view virtual { require(owner() == _msgSender(), "Ownable: caller is not the owner"); } /** * @dev Leaves the contract without owner. It will not be possible to call * `onlyOwner` functions anymore. Can only be called by the current owner. * * NOTE: Renouncing ownership will leave the contract without an owner, * thereby removing any functionality that is only available to the owner. */ function renounceOwnership() public virtual onlyOwner { _transferOwnership(address(0)); } /** * @dev Transfers ownership of the contract to a new account (`newOwner`). * Can only be called by the current owner. */ function transferOwnership(address newOwner) public virtual onlyOwner { require(newOwner != address(0), "Ownable: new owner is the zero address"); _transferOwnership(newOwner); } /** * @dev Transfers ownership of the contract to a new account (`newOwner`). * Internal function without access restriction. */ function _transferOwnership(address newOwner) internal virtual { address oldOwner = _owner; _owner = newOwner; emit OwnershipTransferred(oldOwner, newOwner); } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.8.0) (security/ReentrancyGuard.sol) pragma solidity ^0.8.0; /** * @dev Contract module that helps prevent reentrant calls to a function. * * Inheriting from `ReentrancyGuard` will make the {nonReentrant} modifier * available, which can be applied to functions to make sure there are no nested * (reentrant) calls to them. * * Note that because there is a single `nonReentrant` guard, functions marked as * `nonReentrant` may not call one another. This can be worked around by making * those functions `private`, and then adding `external` `nonReentrant` entry * points to them. * * TIP: If you would like to learn more about reentrancy and alternative ways * to protect against it, check out our blog post * https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul]. */ abstract contract 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; 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 require(_status != _ENTERED, "ReentrancyGuard: reentrant call"); // 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; } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.8.0) (token/ERC20/ERC20.sol) pragma solidity ^0.8.0; import "./IERC20.sol"; import "./extensions/IERC20Metadata.sol"; import "../../utils/Context.sol"; /** * @dev Implementation of the {IERC20} interface. * * This implementation is agnostic to the way tokens are created. This means * that a supply mechanism has to be added in a derived contract using {_mint}. * For a generic mechanism see {ERC20PresetMinterPauser}. * * TIP: For a detailed writeup see our guide * https://forum.openzeppelin.com/t/how-to-implement-erc20-supply-mechanisms/226[How * to implement supply mechanisms]. * * We have followed general OpenZeppelin Contracts guidelines: functions revert * instead returning `false` on failure. This behavior is nonetheless * conventional and does not conflict with the expectations of ERC20 * applications. * * Additionally, an {Approval} event is emitted on calls to {transferFrom}. * This allows applications to reconstruct the allowance for all accounts just * by listening to said events. Other implementations of the EIP may not emit * these events, as it isn't required by the specification. * * Finally, the non-standard {decreaseAllowance} and {increaseAllowance} * functions have been added to mitigate the well-known issues around setting * allowances. See {IERC20-approve}. */ contract ERC20 is Context, IERC20, IERC20Metadata { mapping(address => uint256) private _balances; mapping(address => mapping(address => uint256)) private _allowances; uint256 private _totalSupply; string private _name; string private _symbol; /** * @dev Sets the values for {name} and {symbol}. * * The default value of {decimals} is 18. To select a different value for * {decimals} you should overload it. * * All two of these values are immutable: they can only be set once during * construction. */ constructor(string memory name_, string memory symbol_) { _name = name_; _symbol = symbol_; } /** * @dev Returns the name of the token. */ function name() public view virtual override returns (string memory) { return _name; } /** * @dev Returns the symbol of the token, usually a shorter version of the * name. */ function symbol() public view virtual override returns (string memory) { return _symbol; } /** * @dev Returns the number of decimals used to get its user representation. * For example, if `decimals` equals `2`, a balance of `505` tokens should * be displayed to a user as `5.05` (`505 / 10 ** 2`). * * Tokens usually opt for a value of 18, imitating the relationship between * Ether and Wei. This is the value {ERC20} uses, unless this function is * overridden; * * NOTE: This information is only used for _display_ purposes: it in * no way affects any of the arithmetic of the contract, including * {IERC20-balanceOf} and {IERC20-transfer}. */ function decimals() public view virtual override returns (uint8) { return 18; } /** * @dev See {IERC20-totalSupply}. */ function totalSupply() public view virtual override returns (uint256) { return _totalSupply; } /** * @dev See {IERC20-balanceOf}. */ function balanceOf(address account) public view virtual override returns (uint256) { return _balances[account]; } /** * @dev See {IERC20-transfer}. * * Requirements: * * - `to` cannot be the zero address. * - the caller must have a balance of at least `amount`. */ function transfer(address to, uint256 amount) public virtual override returns (bool) { address owner = _msgSender(); _transfer(owner, to, amount); return true; } /** * @dev See {IERC20-allowance}. */ function allowance(address owner, address spender) public view virtual override returns (uint256) { return _allowances[owner][spender]; } /** * @dev See {IERC20-approve}. * * NOTE: If `amount` is the maximum `uint256`, the allowance is not updated on * `transferFrom`. This is semantically equivalent to an infinite approval. * * Requirements: * * - `spender` cannot be the zero address. */ function approve(address spender, uint256 amount) public virtual override returns (bool) { address owner = _msgSender(); _approve(owner, spender, amount); return true; } /** * @dev See {IERC20-transferFrom}. * * Emits an {Approval} event indicating the updated allowance. This is not * required by the EIP. See the note at the beginning of {ERC20}. * * NOTE: Does not update the allowance if the current allowance * is the maximum `uint256`. * * Requirements: * * - `from` and `to` cannot be the zero address. * - `from` must have a balance of at least `amount`. * - the caller must have allowance for ``from``'s tokens of at least * `amount`. */ function transferFrom( address from, address to, uint256 amount ) public virtual override returns (bool) { address spender = _msgSender(); _spendAllowance(from, spender, amount); _transfer(from, to, amount); return true; } /** * @dev Atomically increases the allowance granted to `spender` by the caller. * * This is an alternative to {approve} that can be used as a mitigation for * problems described in {IERC20-approve}. * * Emits an {Approval} event indicating the updated allowance. * * Requirements: * * - `spender` cannot be the zero address. */ function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { address owner = _msgSender(); _approve(owner, spender, allowance(owner, spender) + addedValue); return true; } /** * @dev Atomically decreases the allowance granted to `spender` by the caller. * * This is an alternative to {approve} that can be used as a mitigation for * problems described in {IERC20-approve}. * * Emits an {Approval} event indicating the updated allowance. * * Requirements: * * - `spender` cannot be the zero address. * - `spender` must have allowance for the caller of at least * `subtractedValue`. */ function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { address owner = _msgSender(); uint256 currentAllowance = allowance(owner, spender); require(currentAllowance >= subtractedValue, "ERC20: decreased allowance below zero"); unchecked { _approve(owner, spender, currentAllowance - subtractedValue); } return true; } /** * @dev Moves `amount` of tokens from `from` to `to`. * * This internal function is equivalent to {transfer}, and can be used to * e.g. implement automatic token fees, slashing mechanisms, etc. * * Emits a {Transfer} event. * * Requirements: * * - `from` cannot be the zero address. * - `to` cannot be the zero address. * - `from` must have a balance of at least `amount`. */ function _transfer( address from, address to, uint256 amount ) internal virtual { require(from != address(0), "ERC20: transfer from the zero address"); require(to != address(0), "ERC20: transfer to the zero address"); _beforeTokenTransfer(from, to, amount); uint256 fromBalance = _balances[from]; require(fromBalance >= amount, "ERC20: transfer amount exceeds balance"); unchecked { _balances[from] = fromBalance - amount; // Overflow not possible: the sum of all balances is capped by totalSupply, and the sum is preserved by // decrementing then incrementing. _balances[to] += amount; } emit Transfer(from, to, amount); _afterTokenTransfer(from, to, amount); } /** @dev Creates `amount` tokens and assigns them to `account`, increasing * the total supply. * * Emits a {Transfer} event with `from` set to the zero address. * * Requirements: * * - `account` cannot be the zero address. */ function _mint(address account, uint256 amount) internal virtual { require(account != address(0), "ERC20: mint to the zero address"); _beforeTokenTransfer(address(0), account, amount); _totalSupply += amount; unchecked { // Overflow not possible: balance + amount is at most totalSupply + amount, which is checked above. _balances[account] += amount; } emit Transfer(address(0), account, amount); _afterTokenTransfer(address(0), account, amount); } /** * @dev Destroys `amount` tokens from `account`, reducing the * total supply. * * Emits a {Transfer} event with `to` set to the zero address. * * Requirements: * * - `account` cannot be the zero address. * - `account` must have at least `amount` tokens. */ function _burn(address account, uint256 amount) internal virtual { require(account != address(0), "ERC20: burn from the zero address"); _beforeTokenTransfer(account, address(0), amount); uint256 accountBalance = _balances[account]; require(accountBalance >= amount, "ERC20: burn amount exceeds balance"); unchecked { _balances[account] = accountBalance - amount; // Overflow not possible: amount <= accountBalance <= totalSupply. _totalSupply -= amount; } emit Transfer(account, address(0), amount); _afterTokenTransfer(account, address(0), amount); } /** * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens. * * This internal function is equivalent to `approve`, and can be used to * e.g. set automatic allowances for certain subsystems, etc. * * Emits an {Approval} event. * * Requirements: * * - `owner` cannot be the zero address. * - `spender` cannot be the zero address. */ function _approve( address owner, address spender, uint256 amount ) internal virtual { require(owner != address(0), "ERC20: approve from the zero address"); require(spender != address(0), "ERC20: approve to the zero address"); _allowances[owner][spender] = amount; emit Approval(owner, spender, amount); } /** * @dev Updates `owner` s allowance for `spender` based on spent `amount`. * * Does not update the allowance amount in case of infinite allowance. * Revert if not enough allowance is available. * * Might emit an {Approval} event. */ function _spendAllowance( address owner, address spender, uint256 amount ) internal virtual { uint256 currentAllowance = allowance(owner, spender); if (currentAllowance != type(uint256).max) { require(currentAllowance >= amount, "ERC20: insufficient allowance"); unchecked { _approve(owner, spender, currentAllowance - amount); } } } /** * @dev Hook that is called before any transfer of tokens. This includes * minting and burning. * * Calling conditions: * * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens * will be transferred to `to`. * - when `from` is zero, `amount` tokens will be minted for `to`. * - when `to` is zero, `amount` of ``from``'s tokens will be burned. * - `from` and `to` are never both zero. * * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. */ function _beforeTokenTransfer( address from, address to, uint256 amount ) internal virtual {} /** * @dev Hook that is called after any transfer of tokens. This includes * minting and burning. * * Calling conditions: * * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens * has been transferred to `to`. * - when `from` is zero, `amount` tokens have been minted for `to`. * - when `to` is zero, `amount` of ``from``'s tokens have been burned. * - `from` and `to` are never both zero. * * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. */ function _afterTokenTransfer( address from, address to, uint256 amount ) internal virtual {} }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (token/ERC20/extensions/draft-IERC20Permit.sol) pragma solidity ^0.8.0; /** * @dev Interface of the ERC20 Permit extension allowing approvals to be made via signatures, as defined in * https://eips.ethereum.org/EIPS/eip-2612[EIP-2612]. * * Adds the {permit} method, which can be used to change an account's ERC20 allowance (see {IERC20-allowance}) by * presenting a message signed by the account. By not relying on {IERC20-approve}, the token holder account doesn't * need to send a transaction, and thus is not required to hold Ether at all. */ interface IERC20Permit { /** * @dev Sets `value` as the allowance of `spender` over ``owner``'s tokens, * given ``owner``'s signed approval. * * IMPORTANT: The same issues {IERC20-approve} has related to transaction * ordering also apply here. * * Emits an {Approval} event. * * Requirements: * * - `spender` cannot be the zero address. * - `deadline` must be a timestamp in the future. * - `v`, `r` and `s` must be a valid `secp256k1` signature from `owner` * over the EIP712-formatted function arguments. * - the signature must use ``owner``'s current nonce (see {nonces}). * * For more information on the signature format, see the * https://eips.ethereum.org/EIPS/eip-2612#specification[relevant EIP * section]. */ function permit( address owner, address spender, uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s ) external; /** * @dev Returns the current nonce for `owner`. This value must be * included whenever a signature is generated for {permit}. * * Every successful call to {permit} increases ``owner``'s nonce by one. This * prevents a signature from being used multiple times. */ function nonces(address owner) external view returns (uint256); /** * @dev Returns the domain separator used in the encoding of the signature for {permit}, as defined by {EIP712}. */ // solhint-disable-next-line func-name-mixedcase function DOMAIN_SEPARATOR() external view returns (bytes32); }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (token/ERC20/extensions/IERC20Metadata.sol) pragma solidity ^0.8.0; import "../IERC20.sol"; /** * @dev Interface for the optional metadata functions from the ERC20 standard. * * _Available since v4.1._ */ interface IERC20Metadata is IERC20 { /** * @dev Returns the name of the token. */ function name() external view returns (string memory); /** * @dev Returns the symbol of the token. */ function symbol() external view returns (string memory); /** * @dev Returns the decimals places of the token. */ function decimals() external view returns (uint8); }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.6.0) (token/ERC20/IERC20.sol) pragma solidity ^0.8.0; /** * @dev Interface of the ERC20 standard as defined in the EIP. */ 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 amount of tokens in existence. */ function totalSupply() external view returns (uint256); /** * @dev Returns the amount of tokens owned by `account`. */ function balanceOf(address account) external view returns (uint256); /** * @dev Moves `amount` 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 amount) 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 `amount` 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 amount) external returns (bool); /** * @dev Moves `amount` tokens from `from` to `to` using the * allowance mechanism. `amount` 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 amount ) external returns (bool); }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.8.0) (token/ERC20/utils/SafeERC20.sol) pragma solidity ^0.8.0; import "../IERC20.sol"; import "../extensions/draft-IERC20Permit.sol"; import "../../../utils/Address.sol"; /** * @title SafeERC20 * @dev Wrappers around ERC20 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 { using Address for address; function safeTransfer( IERC20 token, address to, uint256 value ) internal { _callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value)); } function safeTransferFrom( IERC20 token, address from, address to, uint256 value ) internal { _callOptionalReturn(token, abi.encodeWithSelector(token.transferFrom.selector, from, to, value)); } /** * @dev Deprecated. This function has issues similar to the ones found in * {IERC20-approve}, and its usage is discouraged. * * Whenever possible, use {safeIncreaseAllowance} and * {safeDecreaseAllowance} instead. */ function safeApprove( IERC20 token, address spender, uint256 value ) internal { // safeApprove should only be called when setting an initial allowance, // or when resetting it to zero. To increase and decrease it, use // 'safeIncreaseAllowance' and 'safeDecreaseAllowance' require( (value == 0) || (token.allowance(address(this), spender) == 0), "SafeERC20: approve from non-zero to non-zero allowance" ); _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, value)); } function safeIncreaseAllowance( IERC20 token, address spender, uint256 value ) internal { uint256 newAllowance = token.allowance(address(this), spender) + value; _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance)); } function safeDecreaseAllowance( IERC20 token, address spender, uint256 value ) internal { unchecked { uint256 oldAllowance = token.allowance(address(this), spender); require(oldAllowance >= value, "SafeERC20: decreased allowance below zero"); uint256 newAllowance = oldAllowance - value; _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance)); } } function safePermit( IERC20Permit token, address owner, address spender, uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s ) internal { uint256 nonceBefore = token.nonces(owner); token.permit(owner, spender, value, deadline, v, r, s); uint256 nonceAfter = token.nonces(owner); require(nonceAfter == nonceBefore + 1, "SafeERC20: permit did not succeed"); } /** * @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). */ function _callOptionalReturn(IERC20 token, bytes memory data) private { // We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since // we're implementing it ourselves. We use {Address-functionCall} to perform this call, which verifies that // the target address contains contract code and also asserts for success in the low-level call. bytes memory returndata = address(token).functionCall(data, "SafeERC20: low-level call failed"); if (returndata.length > 0) { // Return data is optional require(abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation did not succeed"); } } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.8.0) (utils/Address.sol) pragma solidity ^0.8.1; /** * @dev Collection of functions related to the address type */ library Address { /** * @dev Returns true if `account` is a contract. * * [IMPORTANT] * ==== * It is unsafe to assume that an address for which this function returns * false is an externally-owned account (EOA) and not a contract. * * Among others, `isContract` will return false for the following * types of addresses: * * - an externally-owned account * - a contract in construction * - an address where a contract will be created * - an address where a contract lived, but was destroyed * ==== * * [IMPORTANT] * ==== * You shouldn't rely on `isContract` to protect against flash loan attacks! * * Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets * like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract * constructor. * ==== */ function isContract(address account) internal view returns (bool) { // This method relies on extcodesize/address.code.length, which returns 0 // for contracts in construction, since the code is only stored at the end // of the constructor execution. return account.code.length > 0; } /** * @dev Replacement for Solidity's `transfer`: sends `amount` wei to * `recipient`, forwarding all available gas and reverting on errors. * * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost * of certain opcodes, possibly making contracts go over the 2300 gas limit * imposed by `transfer`, making them unable to receive funds via * `transfer`. {sendValue} removes this limitation. * * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. * * IMPORTANT: because control is transferred to `recipient`, care must be * taken to not create reentrancy vulnerabilities. Consider using * {ReentrancyGuard} or the * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. */ function sendValue(address payable recipient, uint256 amount) internal { require(address(this).balance >= amount, "Address: insufficient balance"); (bool success, ) = recipient.call{value: amount}(""); require(success, "Address: unable to send value, recipient may have reverted"); } /** * @dev Performs a Solidity function call using a low level `call`. A * plain `call` is an unsafe replacement for a function call: use this * function instead. * * If `target` reverts with a revert reason, it is bubbled up by this * function (like regular Solidity function calls). * * Returns the raw returned data. To convert to the expected return value, * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. * * Requirements: * * - `target` must be a contract. * - calling `target` with `data` must not revert. * * _Available since v3.1._ */ function functionCall(address target, bytes memory data) internal returns (bytes memory) { return functionCallWithValue(target, data, 0, "Address: low-level call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with * `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCall( address target, bytes memory data, string memory errorMessage ) internal returns (bytes memory) { return functionCallWithValue(target, data, 0, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but also transferring `value` wei to `target`. * * Requirements: * * - the calling contract must have an ETH balance of at least `value`. * - the called Solidity function must be `payable`. * * _Available since v3.1._ */ function functionCallWithValue( address target, bytes memory data, uint256 value ) internal returns (bytes memory) { return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); } /** * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but * with `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCallWithValue( address target, bytes memory data, uint256 value, string memory errorMessage ) internal returns (bytes memory) { require(address(this).balance >= value, "Address: insufficient balance for call"); (bool success, bytes memory returndata) = target.call{value: value}(data); return verifyCallResultFromTarget(target, success, returndata, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but performing a static call. * * _Available since v3.3._ */ function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) { return functionStaticCall(target, data, "Address: low-level static call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`], * but performing a static call. * * _Available since v3.3._ */ function functionStaticCall( address target, bytes memory data, string memory errorMessage ) internal view returns (bytes memory) { (bool success, bytes memory returndata) = target.staticcall(data); return verifyCallResultFromTarget(target, success, returndata, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but performing a delegate call. * * _Available since v3.4._ */ function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) { return functionDelegateCall(target, data, "Address: low-level delegate call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`], * but performing a delegate call. * * _Available since v3.4._ */ function functionDelegateCall( address target, bytes memory data, string memory errorMessage ) internal returns (bytes memory) { (bool success, bytes memory returndata) = target.delegatecall(data); return verifyCallResultFromTarget(target, success, returndata, errorMessage); } /** * @dev Tool to verify that a low level call to smart-contract was successful, and revert (either by bubbling * the revert reason or using the provided one) in case of unsuccessful call or if target was not a contract. * * _Available since v4.8._ */ function verifyCallResultFromTarget( address target, bool success, bytes memory returndata, string memory errorMessage ) internal view returns (bytes memory) { if (success) { if (returndata.length == 0) { // only check isContract if the call was successful and the return data is empty // otherwise we already know that it was a contract require(isContract(target), "Address: call to non-contract"); } return returndata; } else { _revert(returndata, errorMessage); } } /** * @dev Tool to verify that a low level call was successful, and revert if it wasn't, either by bubbling the * revert reason or using the provided one. * * _Available since v4.3._ */ function verifyCallResult( bool success, bytes memory returndata, string memory errorMessage ) internal pure returns (bytes memory) { if (success) { return returndata; } else { _revert(returndata, errorMessage); } } function _revert(bytes memory returndata, string memory errorMessage) 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 /// @solidity memory-safe-assembly assembly { let returndata_size := mload(returndata) revert(add(32, returndata), returndata_size) } } else { revert(errorMessage); } } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (utils/Context.sol) pragma solidity ^0.8.0; /** * @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; } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (utils/Counters.sol) pragma solidity ^0.8.0; /** * @title Counters * @author Matt Condon (@shrugs) * @dev Provides counters that can only be incremented, decremented or reset. This can be used e.g. to track the number * of elements in a mapping, issuing ERC721 ids, or counting request ids. * * Include with `using Counters for Counters.Counter;` */ library Counters { struct Counter { // This variable should never be directly accessed by users of the library: interactions must be restricted to // the library's function. As of Solidity v0.5.2, this cannot be enforced, though there is a proposal to add // this feature: see https://github.com/ethereum/solidity/issues/4637 uint256 _value; // default: 0 } function current(Counter storage counter) internal view returns (uint256) { return counter._value; } function increment(Counter storage counter) internal { unchecked { counter._value += 1; } } function decrement(Counter storage counter) internal { uint256 value = counter._value; require(value > 0, "Counter: decrement overflow"); unchecked { counter._value = value - 1; } } function reset(Counter storage counter) internal { counter._value = 0; } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.8.0) (utils/math/Math.sol) pragma solidity ^0.8.0; /** * @dev Standard math utilities missing in the Solidity language. */ library Math { enum Rounding { Down, // Toward negative infinity Up, // Toward infinity Zero // Toward zero } /** * @dev Returns the largest of two numbers. */ function max(uint256 a, uint256 b) internal pure returns (uint256) { return a > b ? a : b; } /** * @dev Returns the smallest of two numbers. */ function min(uint256 a, uint256 b) internal pure returns (uint256) { return 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 up instead * of rounding down. */ function ceilDiv(uint256 a, uint256 b) internal pure returns (uint256) { // (a + b - 1) / b can overflow on addition, so we distribute. return a == 0 ? 0 : (a - 1) / b + 1; } /** * @notice Calculates floor(x * y / denominator) with full precision. Throws if result overflows a uint256 or denominator == 0 * @dev 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^256 and mod 2^256 - 1, then use // use the Chinese Remainder Theorem to reconstruct the 512 bit result. The result is stored in two 256 // variables such that product = prod1 * 2^256 + prod0. uint256 prod0; // Least significant 256 bits of the product uint256 prod1; // Most significant 256 bits of the product assembly { let mm := mulmod(x, y, not(0)) prod0 := mul(x, y) prod1 := sub(sub(mm, prod0), lt(mm, prod0)) } // Handle non-overflow cases, 256 by 256 division. if (prod1 == 0) { return prod0 / denominator; } // Make sure the result is less than 2^256. Also prevents denominator == 0. require(denominator > prod1); /////////////////////////////////////////////// // 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. // Does not overflow because the denominator cannot be zero at this stage in the function. uint256 twos = denominator & (~denominator + 1); 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^256 / 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^256. Now that denominator is an odd number, it has an inverse modulo 2^256 such // that denominator * inv = 1 mod 2^256. Compute the inverse by starting with a seed that is correct for // four bits. That is, denominator * inv = 1 mod 2^4. 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^8 inverse *= 2 - denominator * inverse; // inverse mod 2^16 inverse *= 2 - denominator * inverse; // inverse mod 2^32 inverse *= 2 - denominator * inverse; // inverse mod 2^64 inverse *= 2 - denominator * inverse; // inverse mod 2^128 inverse *= 2 - denominator * inverse; // inverse mod 2^256 // 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^256. Since the preconditions guarantee that the outcome is // less than 2^256, 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; } } /** * @notice 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) { uint256 result = mulDiv(x, y, denominator); if (rounding == Rounding.Up && mulmod(x, y, denominator) > 0) { result += 1; } return result; } /** * @dev Returns the square root of a number. If the number is not a perfect square, the value is rounded down. * * Inspired by Henry S. Warren, Jr.'s "Hacker's Delight" (Chapter 11). */ function sqrt(uint256 a) internal pure returns (uint256) { if (a == 0) { return 0; } // For our first guess, we get the biggest power of 2 which is smaller than the square root of the target. // // We know that the "msb" (most significant bit) of our target number `a` is a power of 2 such that we have // `msb(a) <= a < 2*msb(a)`. This value can be written `msb(a)=2**k` with `k=log2(a)`. // // This can be rewritten `2**log2(a) <= a < 2**(log2(a) + 1)` // → `sqrt(2**k) <= sqrt(a) < sqrt(2**(k+1))` // → `2**(k/2) <= sqrt(a) < 2**((k+1)/2) <= 2**(k/2 + 1)` // // Consequently, `2**(log2(a) / 2)` is a good first approximation of `sqrt(a)` with at least 1 correct bit. uint256 result = 1 << (log2(a) >> 1); // At this point `result` is an estimation with one bit of precision. We know the true value is a uint128, // since it is the square root of a uint256. Newton's method converges quadratically (precision doubles at // every iteration). We thus need at most 7 iteration to turn our partial result with one bit of precision // into the expected uint128 result. unchecked { result = (result + a / result) >> 1; result = (result + a / result) >> 1; result = (result + a / result) >> 1; result = (result + a / result) >> 1; result = (result + a / result) >> 1; result = (result + a / result) >> 1; result = (result + a / result) >> 1; return min(result, a / result); } } /** * @notice 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 + (rounding == Rounding.Up && result * result < a ? 1 : 0); } } /** * @dev Return the log in base 2, rounded down, of a positive value. * Returns 0 if given 0. */ function log2(uint256 value) internal pure returns (uint256) { uint256 result = 0; unchecked { if (value >> 128 > 0) { value >>= 128; result += 128; } if (value >> 64 > 0) { value >>= 64; result += 64; } if (value >> 32 > 0) { value >>= 32; result += 32; } if (value >> 16 > 0) { value >>= 16; result += 16; } if (value >> 8 > 0) { value >>= 8; result += 8; } if (value >> 4 > 0) { value >>= 4; result += 4; } if (value >> 2 > 0) { value >>= 2; result += 2; } if (value >> 1 > 0) { result += 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 + (rounding == Rounding.Up && 1 << result < value ? 1 : 0); } } /** * @dev Return the log in base 10, rounded down, of a positive value. * 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 + (rounding == Rounding.Up && 10**result < value ? 1 : 0); } } /** * @dev Return the log in base 256, rounded down, of a positive value. * 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; unchecked { if (value >> 128 > 0) { value >>= 128; result += 16; } if (value >> 64 > 0) { value >>= 64; result += 8; } if (value >> 32 > 0) { value >>= 32; result += 4; } if (value >> 16 > 0) { value >>= 16; result += 2; } if (value >> 8 > 0) { 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 log256(uint256 value, Rounding rounding) internal pure returns (uint256) { unchecked { uint256 result = log256(value); return result + (rounding == Rounding.Up && 1 << (result * 8) < value ? 1 : 0); } } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.8.0) (utils/math/SafeCast.sol) // This file was procedurally generated from scripts/generate/templates/SafeCast.js. pragma solidity ^0.8.0; /** * @dev Wrappers over Solidity's uintXX/intXX 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. * * Can be combined with {SafeMath} and {SignedSafeMath} to extend it to smaller types, by performing * all math on `uint256` and `int256` and then downcasting. */ library SafeCast { /** * @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 * * _Available since v4.7._ */ function toUint248(uint256 value) internal pure returns (uint248) { require(value <= type(uint248).max, "SafeCast: value doesn't fit in 248 bits"); 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 * * _Available since v4.7._ */ function toUint240(uint256 value) internal pure returns (uint240) { require(value <= type(uint240).max, "SafeCast: value doesn't fit in 240 bits"); 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 * * _Available since v4.7._ */ function toUint232(uint256 value) internal pure returns (uint232) { require(value <= type(uint232).max, "SafeCast: value doesn't fit in 232 bits"); 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 * * _Available since v4.2._ */ function toUint224(uint256 value) internal pure returns (uint224) { require(value <= type(uint224).max, "SafeCast: value doesn't fit in 224 bits"); 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 * * _Available since v4.7._ */ function toUint216(uint256 value) internal pure returns (uint216) { require(value <= type(uint216).max, "SafeCast: value doesn't fit in 216 bits"); 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 * * _Available since v4.7._ */ function toUint208(uint256 value) internal pure returns (uint208) { require(value <= type(uint208).max, "SafeCast: value doesn't fit in 208 bits"); 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 * * _Available since v4.7._ */ function toUint200(uint256 value) internal pure returns (uint200) { require(value <= type(uint200).max, "SafeCast: value doesn't fit in 200 bits"); 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 * * _Available since v4.7._ */ function toUint192(uint256 value) internal pure returns (uint192) { require(value <= type(uint192).max, "SafeCast: value doesn't fit in 192 bits"); 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 * * _Available since v4.7._ */ function toUint184(uint256 value) internal pure returns (uint184) { require(value <= type(uint184).max, "SafeCast: value doesn't fit in 184 bits"); 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 * * _Available since v4.7._ */ function toUint176(uint256 value) internal pure returns (uint176) { require(value <= type(uint176).max, "SafeCast: value doesn't fit in 176 bits"); 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 * * _Available since v4.7._ */ function toUint168(uint256 value) internal pure returns (uint168) { require(value <= type(uint168).max, "SafeCast: value doesn't fit in 168 bits"); 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 * * _Available since v4.7._ */ function toUint160(uint256 value) internal pure returns (uint160) { require(value <= type(uint160).max, "SafeCast: value doesn't fit in 160 bits"); 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 * * _Available since v4.7._ */ function toUint152(uint256 value) internal pure returns (uint152) { require(value <= type(uint152).max, "SafeCast: value doesn't fit in 152 bits"); 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 * * _Available since v4.7._ */ function toUint144(uint256 value) internal pure returns (uint144) { require(value <= type(uint144).max, "SafeCast: value doesn't fit in 144 bits"); 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 * * _Available since v4.7._ */ function toUint136(uint256 value) internal pure returns (uint136) { require(value <= type(uint136).max, "SafeCast: value doesn't fit in 136 bits"); 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 * * _Available since v2.5._ */ function toUint128(uint256 value) internal pure returns (uint128) { require(value <= type(uint128).max, "SafeCast: value doesn't fit in 128 bits"); 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 * * _Available since v4.7._ */ function toUint120(uint256 value) internal pure returns (uint120) { require(value <= type(uint120).max, "SafeCast: value doesn't fit in 120 bits"); 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 * * _Available since v4.7._ */ function toUint112(uint256 value) internal pure returns (uint112) { require(value <= type(uint112).max, "SafeCast: value doesn't fit in 112 bits"); 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 * * _Available since v4.7._ */ function toUint104(uint256 value) internal pure returns (uint104) { require(value <= type(uint104).max, "SafeCast: value doesn't fit in 104 bits"); 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 * * _Available since v4.2._ */ function toUint96(uint256 value) internal pure returns (uint96) { require(value <= type(uint96).max, "SafeCast: value doesn't fit in 96 bits"); 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 * * _Available since v4.7._ */ function toUint88(uint256 value) internal pure returns (uint88) { require(value <= type(uint88).max, "SafeCast: value doesn't fit in 88 bits"); 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 * * _Available since v4.7._ */ function toUint80(uint256 value) internal pure returns (uint80) { require(value <= type(uint80).max, "SafeCast: value doesn't fit in 80 bits"); 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 * * _Available since v4.7._ */ function toUint72(uint256 value) internal pure returns (uint72) { require(value <= type(uint72).max, "SafeCast: value doesn't fit in 72 bits"); 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 * * _Available since v2.5._ */ function toUint64(uint256 value) internal pure returns (uint64) { require(value <= type(uint64).max, "SafeCast: value doesn't fit in 64 bits"); 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 * * _Available since v4.7._ */ function toUint56(uint256 value) internal pure returns (uint56) { require(value <= type(uint56).max, "SafeCast: value doesn't fit in 56 bits"); 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 * * _Available since v4.7._ */ function toUint48(uint256 value) internal pure returns (uint48) { require(value <= type(uint48).max, "SafeCast: value doesn't fit in 48 bits"); 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 * * _Available since v4.7._ */ function toUint40(uint256 value) internal pure returns (uint40) { require(value <= type(uint40).max, "SafeCast: value doesn't fit in 40 bits"); 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 * * _Available since v2.5._ */ function toUint32(uint256 value) internal pure returns (uint32) { require(value <= type(uint32).max, "SafeCast: value doesn't fit in 32 bits"); 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 * * _Available since v4.7._ */ function toUint24(uint256 value) internal pure returns (uint24) { require(value <= type(uint24).max, "SafeCast: value doesn't fit in 24 bits"); 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 * * _Available since v2.5._ */ function toUint16(uint256 value) internal pure returns (uint16) { require(value <= type(uint16).max, "SafeCast: value doesn't fit in 16 bits"); 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 * * _Available since v2.5._ */ function toUint8(uint256 value) internal pure returns (uint8) { require(value <= type(uint8).max, "SafeCast: value doesn't fit in 8 bits"); return uint8(value); } /** * @dev Converts a signed int256 into an unsigned uint256. * * Requirements: * * - input must be greater than or equal to 0. * * _Available since v3.0._ */ function toUint256(int256 value) internal pure returns (uint256) { require(value >= 0, "SafeCast: value must be positive"); 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 * * _Available since v4.7._ */ function toInt248(int256 value) internal pure returns (int248 downcasted) { downcasted = int248(value); require(downcasted == value, "SafeCast: value doesn't fit in 248 bits"); } /** * @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 * * _Available since v4.7._ */ function toInt240(int256 value) internal pure returns (int240 downcasted) { downcasted = int240(value); require(downcasted == value, "SafeCast: value doesn't fit in 240 bits"); } /** * @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 * * _Available since v4.7._ */ function toInt232(int256 value) internal pure returns (int232 downcasted) { downcasted = int232(value); require(downcasted == value, "SafeCast: value doesn't fit in 232 bits"); } /** * @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 * * _Available since v4.7._ */ function toInt224(int256 value) internal pure returns (int224 downcasted) { downcasted = int224(value); require(downcasted == value, "SafeCast: value doesn't fit in 224 bits"); } /** * @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 * * _Available since v4.7._ */ function toInt216(int256 value) internal pure returns (int216 downcasted) { downcasted = int216(value); require(downcasted == value, "SafeCast: value doesn't fit in 216 bits"); } /** * @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 * * _Available since v4.7._ */ function toInt208(int256 value) internal pure returns (int208 downcasted) { downcasted = int208(value); require(downcasted == value, "SafeCast: value doesn't fit in 208 bits"); } /** * @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 * * _Available since v4.7._ */ function toInt200(int256 value) internal pure returns (int200 downcasted) { downcasted = int200(value); require(downcasted == value, "SafeCast: value doesn't fit in 200 bits"); } /** * @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 * * _Available since v4.7._ */ function toInt192(int256 value) internal pure returns (int192 downcasted) { downcasted = int192(value); require(downcasted == value, "SafeCast: value doesn't fit in 192 bits"); } /** * @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 * * _Available since v4.7._ */ function toInt184(int256 value) internal pure returns (int184 downcasted) { downcasted = int184(value); require(downcasted == value, "SafeCast: value doesn't fit in 184 bits"); } /** * @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 * * _Available since v4.7._ */ function toInt176(int256 value) internal pure returns (int176 downcasted) { downcasted = int176(value); require(downcasted == value, "SafeCast: value doesn't fit in 176 bits"); } /** * @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 * * _Available since v4.7._ */ function toInt168(int256 value) internal pure returns (int168 downcasted) { downcasted = int168(value); require(downcasted == value, "SafeCast: value doesn't fit in 168 bits"); } /** * @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 * * _Available since v4.7._ */ function toInt160(int256 value) internal pure returns (int160 downcasted) { downcasted = int160(value); require(downcasted == value, "SafeCast: value doesn't fit in 160 bits"); } /** * @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 * * _Available since v4.7._ */ function toInt152(int256 value) internal pure returns (int152 downcasted) { downcasted = int152(value); require(downcasted == value, "SafeCast: value doesn't fit in 152 bits"); } /** * @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 * * _Available since v4.7._ */ function toInt144(int256 value) internal pure returns (int144 downcasted) { downcasted = int144(value); require(downcasted == value, "SafeCast: value doesn't fit in 144 bits"); } /** * @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 * * _Available since v4.7._ */ function toInt136(int256 value) internal pure returns (int136 downcasted) { downcasted = int136(value); require(downcasted == value, "SafeCast: value doesn't fit in 136 bits"); } /** * @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 * * _Available since v3.1._ */ function toInt128(int256 value) internal pure returns (int128 downcasted) { downcasted = int128(value); require(downcasted == value, "SafeCast: value doesn't fit in 128 bits"); } /** * @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 * * _Available since v4.7._ */ function toInt120(int256 value) internal pure returns (int120 downcasted) { downcasted = int120(value); require(downcasted == value, "SafeCast: value doesn't fit in 120 bits"); } /** * @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 * * _Available since v4.7._ */ function toInt112(int256 value) internal pure returns (int112 downcasted) { downcasted = int112(value); require(downcasted == value, "SafeCast: value doesn't fit in 112 bits"); } /** * @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 * * _Available since v4.7._ */ function toInt104(int256 value) internal pure returns (int104 downcasted) { downcasted = int104(value); require(downcasted == value, "SafeCast: value doesn't fit in 104 bits"); } /** * @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 * * _Available since v4.7._ */ function toInt96(int256 value) internal pure returns (int96 downcasted) { downcasted = int96(value); require(downcasted == value, "SafeCast: value doesn't fit in 96 bits"); } /** * @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 * * _Available since v4.7._ */ function toInt88(int256 value) internal pure returns (int88 downcasted) { downcasted = int88(value); require(downcasted == value, "SafeCast: value doesn't fit in 88 bits"); } /** * @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 * * _Available since v4.7._ */ function toInt80(int256 value) internal pure returns (int80 downcasted) { downcasted = int80(value); require(downcasted == value, "SafeCast: value doesn't fit in 80 bits"); } /** * @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 * * _Available since v4.7._ */ function toInt72(int256 value) internal pure returns (int72 downcasted) { downcasted = int72(value); require(downcasted == value, "SafeCast: value doesn't fit in 72 bits"); } /** * @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 * * _Available since v3.1._ */ function toInt64(int256 value) internal pure returns (int64 downcasted) { downcasted = int64(value); require(downcasted == value, "SafeCast: value doesn't fit in 64 bits"); } /** * @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 * * _Available since v4.7._ */ function toInt56(int256 value) internal pure returns (int56 downcasted) { downcasted = int56(value); require(downcasted == value, "SafeCast: value doesn't fit in 56 bits"); } /** * @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 * * _Available since v4.7._ */ function toInt48(int256 value) internal pure returns (int48 downcasted) { downcasted = int48(value); require(downcasted == value, "SafeCast: value doesn't fit in 48 bits"); } /** * @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 * * _Available since v4.7._ */ function toInt40(int256 value) internal pure returns (int40 downcasted) { downcasted = int40(value); require(downcasted == value, "SafeCast: value doesn't fit in 40 bits"); } /** * @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 * * _Available since v3.1._ */ function toInt32(int256 value) internal pure returns (int32 downcasted) { downcasted = int32(value); require(downcasted == value, "SafeCast: value doesn't fit in 32 bits"); } /** * @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 * * _Available since v4.7._ */ function toInt24(int256 value) internal pure returns (int24 downcasted) { downcasted = int24(value); require(downcasted == value, "SafeCast: value doesn't fit in 24 bits"); } /** * @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 * * _Available since v3.1._ */ function toInt16(int256 value) internal pure returns (int16 downcasted) { downcasted = int16(value); require(downcasted == value, "SafeCast: value doesn't fit in 16 bits"); } /** * @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 * * _Available since v3.1._ */ function toInt8(int256 value) internal pure returns (int8 downcasted) { downcasted = int8(value); require(downcasted == value, "SafeCast: value doesn't fit in 8 bits"); } /** * @dev Converts an unsigned uint256 into a signed int256. * * Requirements: * * - input must be less than or equal to maxInt256. * * _Available since v3.0._ */ function toInt256(uint256 value) internal pure returns (int256) { // Note: Unsafe cast below is okay because `type(int256).max` is guaranteed to be positive require(value <= uint256(type(int256).max), "SafeCast: value doesn't fit in an int256"); return int256(value); } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.6.0) (utils/math/SafeMath.sol) pragma solidity ^0.8.0; // CAUTION // This version of SafeMath should only be used with Solidity 0.8 or later, // because it relies on the compiler's built in overflow checks. /** * @dev Wrappers over Solidity's arithmetic operations. * * NOTE: `SafeMath` is generally not needed starting with Solidity 0.8, since the compiler * now has built in overflow checking. */ library SafeMath { /** * @dev Returns the addition of two unsigned integers, with an overflow flag. * * _Available since v3.4._ */ function tryAdd(uint256 a, uint256 b) internal pure returns (bool, uint256) { unchecked { uint256 c = a + b; if (c < a) return (false, 0); return (true, c); } } /** * @dev Returns the subtraction of two unsigned integers, with an overflow flag. * * _Available since v3.4._ */ function trySub(uint256 a, uint256 b) internal pure returns (bool, uint256) { unchecked { if (b > a) return (false, 0); return (true, a - b); } } /** * @dev Returns the multiplication of two unsigned integers, with an overflow flag. * * _Available since v3.4._ */ function tryMul(uint256 a, uint256 b) internal pure returns (bool, uint256) { 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 division by zero flag. * * _Available since v3.4._ */ function tryDiv(uint256 a, uint256 b) internal pure returns (bool, uint256) { unchecked { if (b == 0) return (false, 0); return (true, a / b); } } /** * @dev Returns the remainder of dividing two unsigned integers, with a division by zero flag. * * _Available since v3.4._ */ function tryMod(uint256 a, uint256 b) internal pure returns (bool, uint256) { unchecked { if (b == 0) return (false, 0); return (true, a % b); } } /** * @dev Returns the addition of two unsigned integers, reverting on * overflow. * * Counterpart to Solidity's `+` operator. * * Requirements: * * - Addition cannot overflow. */ function add(uint256 a, uint256 b) internal pure returns (uint256) { return a + b; } /** * @dev Returns the subtraction of two unsigned integers, reverting on * overflow (when the result is negative). * * Counterpart to Solidity's `-` operator. * * Requirements: * * - Subtraction cannot overflow. */ function sub(uint256 a, uint256 b) internal pure returns (uint256) { return a - b; } /** * @dev Returns the multiplication of two unsigned integers, reverting on * overflow. * * Counterpart to Solidity's `*` operator. * * Requirements: * * - Multiplication cannot overflow. */ function mul(uint256 a, uint256 b) internal pure returns (uint256) { return a * b; } /** * @dev Returns the integer division of two unsigned integers, reverting on * division by zero. The result is rounded towards zero. * * Counterpart to Solidity's `/` operator. * * Requirements: * * - The divisor cannot be zero. */ function div(uint256 a, uint256 b) internal pure returns (uint256) { return a / b; } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * reverting when dividing by zero. * * Counterpart to Solidity's `%` operator. This function uses a `revert` * opcode (which leaves remaining gas untouched) while Solidity uses an * invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function mod(uint256 a, uint256 b) internal pure returns (uint256) { return a % b; } /** * @dev Returns the subtraction of two unsigned integers, reverting with custom message on * overflow (when the result is negative). * * CAUTION: This function is deprecated because it requires allocating memory for the error * message unnecessarily. For custom revert reasons use {trySub}. * * Counterpart to Solidity's `-` operator. * * Requirements: * * - Subtraction cannot overflow. */ function sub( uint256 a, uint256 b, string memory errorMessage ) internal pure returns (uint256) { unchecked { require(b <= a, errorMessage); return a - b; } } /** * @dev Returns the integer division of two unsigned integers, reverting with custom message on * division by zero. The result is rounded towards zero. * * Counterpart to Solidity's `/` operator. Note: this function uses a * `revert` opcode (which leaves remaining gas untouched) while Solidity * uses an invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function div( uint256 a, uint256 b, string memory errorMessage ) internal pure returns (uint256) { unchecked { require(b > 0, errorMessage); return a / b; } } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * reverting with custom message when dividing by zero. * * CAUTION: This function is deprecated because it requires allocating memory for the error * message unnecessarily. For custom revert reasons use {tryMod}. * * Counterpart to Solidity's `%` operator. This function uses a `revert` * opcode (which leaves remaining gas untouched) while Solidity uses an * invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function mod( uint256 a, uint256 b, string memory errorMessage ) internal pure returns (uint256) { unchecked { require(b > 0, errorMessage); return a % b; } } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.6.0) (utils/structs/DoubleEndedQueue.sol) pragma solidity ^0.8.4; import "../math/SafeCast.sol"; /** * @dev A sequence of items with the ability to efficiently push and pop items (i.e. insert and remove) on both ends of * the sequence (called front and back). Among other access patterns, it can be used to implement efficient LIFO and * FIFO queues. Storage use is optimized, and all operations are O(1) constant time. This includes {clear}, given that * the existing queue contents are left in storage. * * The struct is called `Bytes32Deque`. Other types can be cast to and from `bytes32`. This data structure can only be * used in storage, and not in memory. * ``` * DoubleEndedQueue.Bytes32Deque queue; * ``` * * _Available since v4.6._ */ library DoubleEndedQueue { /** * @dev An operation (e.g. {front}) couldn't be completed due to the queue being empty. */ error Empty(); /** * @dev An operation (e.g. {at}) couldn't be completed due to an index being out of bounds. */ error OutOfBounds(); /** * @dev Indices are signed integers because the queue can grow in any direction. They are 128 bits so begin and end * are packed in a single storage slot for efficient access. Since the items are added one at a time we can safely * assume that these 128-bit indices will not overflow, and use unchecked arithmetic. * * Struct members have an underscore prefix indicating that they are "private" and should not be read or written to * directly. Use the functions provided below instead. Modifying the struct manually may violate assumptions and * lead to unexpected behavior. * * Indices are in the range [begin, end) which means the first item is at data[begin] and the last item is at * data[end - 1]. */ struct Bytes32Deque { int128 _begin; int128 _end; mapping(int128 => bytes32) _data; } /** * @dev Inserts an item at the end of the queue. */ function pushBack(Bytes32Deque storage deque, bytes32 value) internal { int128 backIndex = deque._end; deque._data[backIndex] = value; unchecked { deque._end = backIndex + 1; } } /** * @dev Removes the item at the end of the queue and returns it. * * Reverts with `Empty` if the queue is empty. */ function popBack(Bytes32Deque storage deque) internal returns (bytes32 value) { if (empty(deque)) revert Empty(); int128 backIndex; unchecked { backIndex = deque._end - 1; } value = deque._data[backIndex]; delete deque._data[backIndex]; deque._end = backIndex; } /** * @dev Inserts an item at the beginning of the queue. */ function pushFront(Bytes32Deque storage deque, bytes32 value) internal { int128 frontIndex; unchecked { frontIndex = deque._begin - 1; } deque._data[frontIndex] = value; deque._begin = frontIndex; } /** * @dev Removes the item at the beginning of the queue and returns it. * * Reverts with `Empty` if the queue is empty. */ function popFront(Bytes32Deque storage deque) internal returns (bytes32 value) { if (empty(deque)) revert Empty(); int128 frontIndex = deque._begin; value = deque._data[frontIndex]; delete deque._data[frontIndex]; unchecked { deque._begin = frontIndex + 1; } } /** * @dev Returns the item at the beginning of the queue. * * Reverts with `Empty` if the queue is empty. */ function front(Bytes32Deque storage deque) internal view returns (bytes32 value) { if (empty(deque)) revert Empty(); int128 frontIndex = deque._begin; return deque._data[frontIndex]; } /** * @dev Returns the item at the end of the queue. * * Reverts with `Empty` if the queue is empty. */ function back(Bytes32Deque storage deque) internal view returns (bytes32 value) { if (empty(deque)) revert Empty(); int128 backIndex; unchecked { backIndex = deque._end - 1; } return deque._data[backIndex]; } /** * @dev Return the item at a position in the queue given by `index`, with the first item at 0 and last item at * `length(deque) - 1`. * * Reverts with `OutOfBounds` if the index is out of bounds. */ function at(Bytes32Deque storage deque, uint256 index) internal view returns (bytes32 value) { // int256(deque._begin) is a safe upcast int128 idx = SafeCast.toInt128(int256(deque._begin) + SafeCast.toInt256(index)); if (idx >= deque._end) revert OutOfBounds(); return deque._data[idx]; } /** * @dev Resets the queue back to being empty. * * NOTE: The current items are left behind in storage. This does not affect the functioning of the queue, but misses * out on potential gas refunds. */ function clear(Bytes32Deque storage deque) internal { deque._begin = 0; deque._end = 0; } /** * @dev Returns the number of items in the queue. */ function length(Bytes32Deque storage deque) internal view returns (uint256) { // The interface preserves the invariant that begin <= end so we assume this will not overflow. // We also assume there are at most int256.max items in the queue. unchecked { return uint256(int256(deque._end) - int256(deque._begin)); } } /** * @dev Returns true if the queue is empty. */ function empty(Bytes32Deque storage deque) internal view returns (bool) { return deque._end <= deque._begin; } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.8.0) (utils/structs/EnumerableSet.sol) // This file was procedurally generated from scripts/generate/templates/EnumerableSet.js. pragma solidity ^0.8.0; /** * @dev Library for managing * https://en.wikipedia.org/wiki/Set_(abstract_data_type)[sets] of primitive * types. * * Sets have the following properties: * * - Elements are added, removed, and checked for existence in constant time * (O(1)). * - Elements are enumerated in O(n). No guarantees are made on the ordering. * * ``` * contract Example { * // Add the library methods * using EnumerableSet for EnumerableSet.AddressSet; * * // Declare a set state variable * EnumerableSet.AddressSet private mySet; * } * ``` * * As of v3.3.0, sets of type `bytes32` (`Bytes32Set`), `address` (`AddressSet`) * and `uint256` (`UintSet`) are supported. * * [WARNING] * ==== * Trying to delete such a structure from storage will likely result in data corruption, rendering the structure * unusable. * See https://github.com/ethereum/solidity/pull/11843[ethereum/solidity#11843] for more info. * * In order to clean an EnumerableSet, you can either remove all elements one by one or create a fresh instance using an * array of EnumerableSet. * ==== */ library EnumerableSet { // To implement this library for multiple types with as little code // repetition as possible, we write it in terms of a generic Set type with // bytes32 values. // The Set implementation uses private functions, and user-facing // implementations (such as AddressSet) are just wrappers around the // underlying Set. // This means that we can only create new EnumerableSets for types that fit // in bytes32. struct Set { // Storage of set values bytes32[] _values; // Position of the value in the `values` array, plus 1 because index 0 // means a value is not in the set. mapping(bytes32 => uint256) _indexes; } /** * @dev Add a value to a set. O(1). * * Returns true if the value was added to the set, that is if it was not * already present. */ function _add(Set storage set, bytes32 value) private returns (bool) { if (!_contains(set, value)) { set._values.push(value); // The value is stored at length-1, but we add 1 to all indexes // and use 0 as a sentinel value set._indexes[value] = set._values.length; return true; } else { return false; } } /** * @dev Removes a value from a set. O(1). * * Returns true if the value was removed from the set, that is if it was * present. */ function _remove(Set storage set, bytes32 value) private returns (bool) { // We read and store the value's index to prevent multiple reads from the same storage slot uint256 valueIndex = set._indexes[value]; if (valueIndex != 0) { // Equivalent to contains(set, value) // To delete an element from the _values array in O(1), we swap the element to delete with the last one in // the array, and then remove the last element (sometimes called as 'swap and pop'). // This modifies the order of the array, as noted in {at}. uint256 toDeleteIndex = valueIndex - 1; uint256 lastIndex = set._values.length - 1; if (lastIndex != toDeleteIndex) { bytes32 lastValue = set._values[lastIndex]; // Move the last value to the index where the value to delete is set._values[toDeleteIndex] = lastValue; // Update the index for the moved value set._indexes[lastValue] = valueIndex; // Replace lastValue's index to valueIndex } // Delete the slot where the moved value was stored set._values.pop(); // Delete the index for the deleted slot delete set._indexes[value]; return true; } else { return false; } } /** * @dev Returns true if the value is in the set. O(1). */ function _contains(Set storage set, bytes32 value) private view returns (bool) { return set._indexes[value] != 0; } /** * @dev Returns the number of values on the set. O(1). */ function _length(Set storage set) private view returns (uint256) { return set._values.length; } /** * @dev Returns the value stored at position `index` in the set. O(1). * * Note that there are no guarantees on the ordering of values inside the * array, and it may change when more values are added or removed. * * Requirements: * * - `index` must be strictly less than {length}. */ function _at(Set storage set, uint256 index) private view returns (bytes32) { return set._values[index]; } /** * @dev Return the entire set in an array * * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that * this function has an unbounded cost, and using it as part of a state-changing function may render the function * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block. */ function _values(Set storage set) private view returns (bytes32[] memory) { return set._values; } // Bytes32Set struct Bytes32Set { Set _inner; } /** * @dev Add a value to a set. O(1). * * Returns true if the value was added to the set, that is if it was not * already present. */ function add(Bytes32Set storage set, bytes32 value) internal returns (bool) { return _add(set._inner, value); } /** * @dev Removes a value from a set. O(1). * * Returns true if the value was removed from the set, that is if it was * present. */ function remove(Bytes32Set storage set, bytes32 value) internal returns (bool) { return _remove(set._inner, value); } /** * @dev Returns true if the value is in the set. O(1). */ function contains(Bytes32Set storage set, bytes32 value) internal view returns (bool) { return _contains(set._inner, value); } /** * @dev Returns the number of values in the set. O(1). */ function length(Bytes32Set storage set) internal view returns (uint256) { return _length(set._inner); } /** * @dev Returns the value stored at position `index` in the set. O(1). * * Note that there are no guarantees on the ordering of values inside the * array, and it may change when more values are added or removed. * * Requirements: * * - `index` must be strictly less than {length}. */ function at(Bytes32Set storage set, uint256 index) internal view returns (bytes32) { return _at(set._inner, index); } /** * @dev Return the entire set in an array * * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that * this function has an unbounded cost, and using it as part of a state-changing function may render the function * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block. */ function values(Bytes32Set storage set) internal view returns (bytes32[] memory) { bytes32[] memory store = _values(set._inner); bytes32[] memory result; /// @solidity memory-safe-assembly assembly { result := store } return result; } // AddressSet struct AddressSet { Set _inner; } /** * @dev Add a value to a set. O(1). * * Returns true if the value was added to the set, that is if it was not * already present. */ function add(AddressSet storage set, address value) internal returns (bool) { return _add(set._inner, bytes32(uint256(uint160(value)))); } /** * @dev Removes a value from a set. O(1). * * Returns true if the value was removed from the set, that is if it was * present. */ function remove(AddressSet storage set, address value) internal returns (bool) { return _remove(set._inner, bytes32(uint256(uint160(value)))); } /** * @dev Returns true if the value is in the set. O(1). */ function contains(AddressSet storage set, address value) internal view returns (bool) { return _contains(set._inner, bytes32(uint256(uint160(value)))); } /** * @dev Returns the number of values in the set. O(1). */ function length(AddressSet storage set) internal view returns (uint256) { return _length(set._inner); } /** * @dev Returns the value stored at position `index` in the set. O(1). * * Note that there are no guarantees on the ordering of values inside the * array, and it may change when more values are added or removed. * * Requirements: * * - `index` must be strictly less than {length}. */ function at(AddressSet storage set, uint256 index) internal view returns (address) { return address(uint160(uint256(_at(set._inner, index)))); } /** * @dev Return the entire set in an array * * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that * this function has an unbounded cost, and using it as part of a state-changing function may render the function * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block. */ function values(AddressSet storage set) internal view returns (address[] memory) { bytes32[] memory store = _values(set._inner); address[] memory result; /// @solidity memory-safe-assembly assembly { result := store } return result; } // UintSet struct UintSet { Set _inner; } /** * @dev Add a value to a set. O(1). * * Returns true if the value was added to the set, that is if it was not * already present. */ function add(UintSet storage set, uint256 value) internal returns (bool) { return _add(set._inner, bytes32(value)); } /** * @dev Removes a value from a set. O(1). * * Returns true if the value was removed from the set, that is if it was * present. */ function remove(UintSet storage set, uint256 value) internal returns (bool) { return _remove(set._inner, bytes32(value)); } /** * @dev Returns true if the value is in the set. O(1). */ function contains(UintSet storage set, uint256 value) internal view returns (bool) { return _contains(set._inner, bytes32(value)); } /** * @dev Returns the number of values in the set. O(1). */ function length(UintSet storage set) internal view returns (uint256) { return _length(set._inner); } /** * @dev Returns the value stored at position `index` in the set. O(1). * * Note that there are no guarantees on the ordering of values inside the * array, and it may change when more values are added or removed. * * Requirements: * * - `index` must be strictly less than {length}. */ function at(UintSet storage set, uint256 index) internal view returns (uint256) { return uint256(_at(set._inner, index)); } /** * @dev Return the entire set in an array * * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that * this function has an unbounded cost, and using it as part of a state-changing function may render the function * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block. */ function values(UintSet storage set) internal view returns (uint256[] memory) { bytes32[] memory store = _values(set._inner); uint256[] memory result; /// @solidity memory-safe-assembly assembly { result := store } return result; } }
// SPDX-License-Identifier: Apache-2.0 pragma solidity ^0.8.9; import "@openzeppelin/contracts/token/ERC20/ERC20.sol"; contract veLSD is ERC20 { address public minter; constructor() ERC20("veLSD Coin", "veLSD") { minter = _msgSender(); } /// @dev Disable normal token transfer function _transfer(address, address, uint256) internal pure override { revert Unsupported(); } /// @dev Only the minter (aka LsdxTreasury) could mint veLSD tokens on user deposit function mint(address to, uint256 amount) public onlyMinter { _mint(to, amount); } /// @dev Only the minter (aka LsdxTreasury) could burn veLSD tokens on user withdraw function burnFrom(address account, uint256 amount) public onlyMinter { _burn(account, amount); } /// @dev Should transfer mintership to LsdxTreasury right after deployment function setMinter(address newMinter) public onlyMinter { require(newMinter != address(0), "New minter is the zero address"); require(newMinter != minter, "Same minter"); address oldMinter = minter; minter = newMinter; emit MintershipTransferred(oldMinter, newMinter); } modifier onlyMinter() { require(minter == _msgSender(), "Caller is not the minter"); _; } error Unsupported(); event MintershipTransferred(address indexed previousMinter, address indexed newMinter); }
{ "metadata": { "bytecodeHash": "ipfs" }, "optimizer": { "enabled": true, "runs": 590 }, "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":"_lsdToken","type":"address"},{"internalType":"address[]","name":"_rewardTokens","type":"address[]"},{"internalType":"address","name":"_velsdToken","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[],"name":"Empty","type":"error"},{"inputs":[],"name":"OutOfBounds","type":"error"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"user","type":"address"},{"indexed":false,"internalType":"uint256","name":"totalAmount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"fee","type":"uint256"}],"name":"AdminFeeAccrued","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"rewarder","type":"address"},{"indexed":true,"internalType":"address","name":"to","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"AdminFeeWithdrawn","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"user","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"Deposited","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"rewardToken","type":"address"}],"name":"RewardTokenAdded","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"rewarder","type":"address"}],"name":"RewarderAdded","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"rewarder","type":"address"}],"name":"RewarderRemoved","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"rewardToken","type":"address"},{"indexed":true,"internalType":"address","name":"rewarder","type":"address"},{"indexed":false,"internalType":"uint256","name":"reward","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"rewardDuration","type":"uint256"}],"name":"RewardsAdded","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"user","type":"address"},{"indexed":true,"internalType":"address","name":"rewardToken","type":"address"},{"indexed":false,"internalType":"uint256","name":"reward","type":"uint256"}],"name":"RewardsPaid","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"user","type":"address"},{"indexed":false,"internalType":"uint256","name":"totalAmount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"fee","type":"uint256"}],"name":"Withdrawn","type":"event"},{"inputs":[{"internalType":"address","name":"rewardToken","type":"address"}],"name":"addRewardToken","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"rewarder","type":"address"}],"name":"addRewarder","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"rewardToken","type":"address"},{"internalType":"uint256","name":"rewardAmount","type":"uint256"},{"internalType":"uint256","name":"durationInDays","type":"uint256"}],"name":"addRewards","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"adminFee","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"balanceOf","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"components":[{"internalType":"uint256","name":"lockId","type":"uint256"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"uint256","name":"depositTime","type":"uint256"}],"internalType":"struct LsdxTreasury.VelsdLocked","name":"lock","type":"tuple"}],"name":"calcAdminFee","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"depositAndLockToken","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"},{"internalType":"address","name":"rewardToken","type":"address"}],"name":"earned","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"exitFirstSumOfLockedToken","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"getRewards","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"rewardToken","type":"address"}],"name":"isSupportedRewardToken","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"rewardToken","type":"address"}],"name":"lastTimeRewardsApplicable","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"lastUpdateTime","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"lsdToken","outputs":[{"internalType":"contract IERC20","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"periodFinish","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"rewarder","type":"address"}],"name":"removeRewarder","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"renounceOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"rewardRates","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"rewardTokens","outputs":[{"internalType":"address[]","name":"","type":"address[]"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"rewarders","outputs":[{"internalType":"address[]","name":"","type":"address[]"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"},{"internalType":"address","name":"","type":"address"}],"name":"rewards","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"rewardToken","type":"address"}],"name":"rewardsPerToken","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"rewardsPerTokenStored","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalSupply","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"},{"internalType":"address","name":"","type":"address"}],"name":"userRewardsPerTokenPaid","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"user","type":"address"}],"name":"velsdLockedCount","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"user","type":"address"},{"internalType":"uint256","name":"index","type":"uint256"}],"name":"velsdLockedInfoByIndex","outputs":[{"components":[{"internalType":"uint256","name":"lockId","type":"uint256"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"uint256","name":"depositTime","type":"uint256"}],"internalType":"struct LsdxTreasury.VelsdLocked","name":"","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"velsdToken","outputs":[{"internalType":"contract veLSD","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"to","type":"address"}],"name":"withdrawAdminFee","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"withdrawFirstSumOfLockedToken","outputs":[],"stateMutability":"nonpayable","type":"function"}]
Contract Creation Code
60806040523480156200001157600080fd5b5060405162002ce138038062002ce18339810160408190526200003491620005af565b6200003f33620001c7565b600180556001600160a01b0383166200008e5760405162461bcd60e51b8152602060048201526015602482015260008051602062002cc183398151915260448201526064015b60405180910390fd5b6000825111620000e15760405162461bcd60e51b815260206004820152601760248201527f456d7074792072657761726420746f6b656e206c697374000000000000000000604482015260640162000085565b6001600160a01b038116620001285760405162461bcd60e51b8152602060048201526015602482015260008051602062002cc1833981519152604482015260640162000085565b600280546001600160a01b0319166001600160a01b03851617905560005b825181101562000192576200017d838281518110620001695762000169620006aa565b60200260200101516200021760201b60201c565b806200018981620006c0565b91505062000146565b506200019e3362000329565b600380546001600160a01b0319166001600160a01b039290921691909117905550620006ea9050565b600080546001600160a01b038381166001600160a01b0319831681178455604051919092169283917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09190a35050565b6200022162000438565b6200022b62000494565b6001600160a01b038116620002725760405162461bcd60e51b8152602060048201526015602482015260008051602062002cc1833981519152604482015260640162000085565b6200028d816004620004f260201b6200166d1790919060201c565b15620002cc5760405162461bcd60e51b815260206004820152600d60248201526c105b1c9958591e481859191959609a1b604482015260640162000085565b620002e78160046200051960201b620016921790919060201c565b506040516001600160a01b038216907ff3e4c2c64e71e6ba2eaab9a599bced62f9eb91d2cda610bf41aa8c80ff2cf82690600090a26200032660018055565b50565b6200033362000438565b6200033d62000494565b6001600160a01b038116620003845760405162461bcd60e51b8152602060048201526015602482015260008051602062002cc1833981519152604482015260640162000085565b6200039f816006620004f260201b6200166d1790919060201c565b15620003de5760405162461bcd60e51b815260206004820152600d60248201526c105b1c9958591e481859191959609a1b604482015260640162000085565b620003f98160066200051960201b620016921790919060201c565b506040516001600160a01b038216907f9dfd431959d2d3358e3eb909555ad574123ea5881ff0e05a80f66d4984710c1b90600090a26200032660018055565b600260015414156200048d5760405162461bcd60e51b815260206004820152601f60248201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c00604482015260640162000085565b6002600155565b6000546001600160a01b03163314620004f05760405162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604482015260640162000085565b565b6001600160a01b038116600090815260018301602052604081205415155b90505b92915050565b600062000510836001600160a01b0384166000818152600183016020526040812054620005735750815460018181018455600084815260208082209093018490558454848252828601909352604090209190915562000513565b50600062000513565b80516001600160a01b03811681146200059457600080fd5b919050565b634e487b7160e01b600052604160045260246000fd5b600080600060608486031215620005c557600080fd5b620005d0846200057c565b602085810151919450906001600160401b0380821115620005f057600080fd5b818701915087601f8301126200060557600080fd5b8151818111156200061a576200061a62000599565b8060051b604051601f19603f8301168101818110858211171562000642576200064262000599565b60405291825284820192508381018501918a8311156200066157600080fd5b938501935b828510156200068a576200067a856200057c565b8452938501939285019262000666565b809750505050505050620006a1604085016200057c565b90509250925092565b634e487b7160e01b600052603260045260246000fd5b6000600019821415620006e357634e487b7160e01b600052601160045260246000fd5b5060010190565b6125c780620006fa6000396000f3fe608060405234801561001057600080fd5b50600436106101f05760003560e01c8063a0be06f91161010f578063da09d19d116100a2578063e72215d111610071578063e72215d114610470578063f24c2a1a14610483578063f2fde38b146104a3578063f7384d50146104b657600080fd5b8063da09d19d146103dd578063e12f1dc2146103fd578063e3bd00c314610410578063e70b9e271461044557600080fd5b8063c2b18aa0116100de578063c2b18aa0146103a7578063cb908b9d146103af578063d2d83ec9146103c2578063d883c43d146103ca57600080fd5b8063a0be06f914610366578063a57ce09f1461036e578063a6645fdd14610381578063c1aaa53c1461039457600080fd5b806356d3590b116101875780638da5cb5b116101565780638da5cb5b146102f0578063927b8c15146103155780639470b443146103285780639790d3c11461033b57600080fd5b806356d3590b146102995780635e658955146102ac57806370a08231146102bf578063715018a6146102e857600080fd5b80632ce9aead116101c35780632ce9aead1461023c57806339a8bba61461025c5780633d3b2603146102645780634fb2eeed1461028457600080fd5b80630572b0cc146101f557806318160ddd146101ff5780631c03e6cc14610216578063211dc32d14610229575b600080fd5b6101fd6104d9565b005b600e545b6040519081526020015b60405180910390f35b6101fd610224366004612253565b610605565b61020361023736600461226e565b610704565b61020361024a366004612253565b600b6020526000908152604090205481565b6101fd6107f7565b610203610272366004612253565b60096020526000908152604090205481565b61028c610807565b60405161020d91906122a1565b6101fd6102a7366004612253565b610818565b6102036102ba366004612253565b61090f565b6102036102cd366004612253565b6001600160a01b03166000908152600f602052604090205490565b6101fd610994565b6000546001600160a01b03165b6040516001600160a01b03909116815260200161020d565b6003546102fd906001600160a01b031681565b6102036103363660046122ee565b6109a6565b61020361034936600461226e565b600c60209081526000928352604080842090915290825290205481565b601054610203565b6101fd61037c366004612358565b610b3c565b6002546102fd906001600160a01b031681565b6101fd6103a2366004612371565b610d88565b61028c610f20565b6101fd6103bd366004612253565b610f2c565b6101fd611018565b6101fd6103d8366004612253565b6112d4565b6102036103eb366004612253565b60086020526000908152604090205481565b61020361040b366004612253565b6113ee565b61042361041e3660046123a4565b6114e2565b604080518251815260208084015190820152918101519082015260600161020d565b61020361045336600461226e565b600d60209081526000928352604080842090915290825290205481565b61020361047e366004612253565b6115c0565b610203610491366004612253565b600a6020526000908152604090205481565b6101fd6104b1366004612253565b6115ee565b6104c96104c4366004612253565b611664565b604051901515815260200161020d565b6104e16116a7565b3360005b6104ef6004611701565b81101561052257600061050360048361170b565b905061050f8382611717565b508061051a816123e4565b9150506104e5565b5060005b6105306004611701565b8110156105f857600061054460048361170b565b336000908152600d602090815260408083206001600160a01b038516845290915290205490915080156105e357336000818152600d602090815260408083206001600160a01b03871680855292528220919091556105a29183611813565b6040518181526001600160a01b0383169033907f626f8f3c00d88f1688098a6dbcbe3aadbe1543112d7d46abb7b0201e83b492fb9060200160405180910390a35b505080806105f0906123e4565b915050610526565b505061060360018055565b565b61060d6116a7565b61061561188b565b6001600160a01b0381166106705760405162461bcd60e51b815260206004820152601560248201527f5a65726f2061646472657373206465746563746564000000000000000000000060448201526064015b60405180910390fd5b61067b60048261166d565b156106b85760405162461bcd60e51b815260206004820152600d60248201526c105b1c9958591e481859191959609a1b6044820152606401610667565b6106c3600482611692565b506040516001600160a01b038216907ff3e4c2c64e71e6ba2eaab9a599bced62f9eb91d2cda610bf41aa8c80ff2cf82690600090a261070160018055565b50565b60008161071081611664565b61075c5760405162461bcd60e51b815260206004820152601a60248201527f52657761726420746f6b656e206e6f7420737570706f727465640000000000006044820152606401610667565b6001600160a01b038085166000818152600d6020908152604080832094881680845294825280832054938352600c825280832094835293905291909120546107ef91906107e990670de0b6b3a7640000906107e3906107c4906107be8a6113ee565b906118e5565b6001600160a01b038a166000908152600f6020526040902054906118f1565b906118fd565b90611909565b949350505050565b6107ff611018565b6106036104d9565b60606108136006611915565b905090565b6108206116a7565b61082861188b565b6001600160a01b03811661087e5760405162461bcd60e51b815260206004820152601560248201527f5a65726f206164647265737320646574656374656400000000000000000000006044820152606401610667565b61088960068261166d565b156108c65760405162461bcd60e51b815260206004820152600d60248201526c105b1c9958591e481859191959609a1b6044820152606401610667565b6108d1600682611692565b506040516001600160a01b038216907f9dfd431959d2d3358e3eb909555ad574123ea5881ff0e05a80f66d4984710c1b90600090a261070160018055565b60008161091b81611664565b6109675760405162461bcd60e51b815260206004820152601a60248201527f52657761726420746f6b656e206e6f7420737570706f727465640000000000006044820152606401610667565b6001600160a01b03831660009081526008602052604090205461098b904290611922565b91505b50919050565b61099c61188b565b6106036000611938565b6000428260400151106109fb5760405162461bcd60e51b815260206004820152601460248201527f496e76616c6964206465706f7369742074696d650000000000000000000000006044820152606401610667565b6000826020015111610a4f5760405162461bcd60e51b815260206004820152601660248201527f496e76616c6964206465706f73697420616d6f756e74000000000000000000006044820152606401610667565b6000610a688360400151426118e590919063ffffffff16565b905062093a80811015610a925761098b60646107e3605a86602001516118f190919063ffffffff16565b62278d00811015610aba5761098b60646107e3603286602001516118f190919063ffffffff16565b6276a700811015610ae25761098b60646107e3602386602001516118f190919063ffffffff16565b62ed4e00811015610b0a5761098b60646107e3601486602001516118f190919063ffffffff16565b6301e13380811015610b335761098b60646107e3600a86602001516118f190919063ffffffff16565b50600092915050565b610b446116a7565b3360005b610b526004611701565b811015610b85576000610b6660048361170b565b9050610b728382611717565b5080610b7d816123e4565b915050610b48565b5060008211610bd65760405162461bcd60e51b815260206004820152601060248201527f43616e6e6f74206465706f7369742030000000000000000000000000000000006044820152606401610667565b600e54610be39083611909565b600e55336000908152600f6020526040902054610c009083611909565b336000818152600f6020526040902091909155600254610c2d916001600160a01b03909116903085611995565b6003546001600160a01b03166340c10f19336040516001600160e01b031960e084901b1681526001600160a01b03909116600482015260248101859052604401600060405180830381600087803b158015610c8757600080fd5b505af1158015610c9b573d6000803e3d6000fd5b50505050610cad601180546001019055565b6000610cb860115490565b604080516060810182528281526020808201878152428385019081526000868152601384528581208551815592516001808501919091559151600290930192909255338252601283528482208054600160801b90819004600f0b8085528284019095529590922086905581546fffffffffffffffffffffffffffffffff908116939091011690930217825591925060405185815233907f2da466a7b24304f47e87fa2e1e5a81b9831ce54fec19055ce277ca2f39ba42c49060200160405180910390a25050505061070160018055565b610d906116a7565b82610d9a81611664565b610de65760405162461bcd60e51b815260206004820152601a60248201527f52657761726420746f6b656e206e6f7420737570706f727465640000000000006044820152606401610667565b610df3335b60069061166d565b610e305760405162461bcd60e51b815260206004820152600e60248201526d2737ba1030903932bbb0b93232b960911b6044820152606401610667565b60008311610e8f5760405162461bcd60e51b815260206004820152602660248201527f52657761726420616d6f756e742073686f756c6420626520677265617465722060448201526507468616e20360d41b6064820152608401610667565b60008211610edf5760405162461bcd60e51b815260206004820152601960248201527f526577617264206475726174696f6e20746f6f2073686f7274000000000000006044820152606401610667565b6000610eee83620151806118f1565b9050610f056001600160a01b038616333087611995565b610f108585836119d3565b5050610f1b60018055565b505050565b60606108136004611915565b610f346116a7565b610f3c61188b565b610f4760068261166d565b610f845760405162461bcd60e51b815260206004820152600e60248201526d2737ba1030903932bbb0b93232b960911b6044820152606401610667565b610f8f600682611c49565b610fdb5760405162461bcd60e51b815260206004820152601960248201527f4661696c656420746f2072656d6f7665207265776172646572000000000000006044820152606401610667565b6040516001600160a01b038216907fce699c579f0b70ea4ccd6a4b38be26726a2c248b89c7102ccbc5d0f3060ef6d090600090a261070160018055565b6110206116a7565b3360005b61102e6004611701565b81101561106157600061104260048361170b565b905061104e8382611717565b5080611059816123e4565b915050611024565b503360009081526012602052604090208054600f81810b600160801b909204900b136110cf5760405162461bcd60e51b815260206004820152601660248201527f4e6f206465706f73697420746f207769746864726177000000000000000000006044820152606401610667565b60006110da82611c5e565b6000818152601360209081526040918290208251606081018452815481526001820154928101839052600290910154928101929092529192509061111d84611cb2565b506000838152601360205260408120818155600181018290556002015580156112c657600e5461114d90826118e5565b600e55336000908152600f602052604090205461116a90826118e5565b336000908152600f6020526040812091909155611186836109a6565b9050600061119483836118e5565b90506111ad336002546001600160a01b03169083611813565b6003546001600160a01b03166379cc6790336040516001600160e01b031960e084901b1681526001600160a01b03909116600482015260248101869052604401600060405180830381600087803b15801561120757600080fd5b505af115801561121b573d6000803e3d6000fd5b505050506112263390565b6001600160a01b03167f92ccf450a286a957af52509bc1c9939d1a6a481783e142e41e2499f0bb66ebc68484604051611269929190918252602082015260400190565b60405180910390a281156112c3576010546112849083611909565b601055604080518481526020810184905233917fcaf5e96b430c9e7a869bfca8b7ee6effbfd2166be120be294538e37301ae67db910160405180910390a25b50505b505050505061060360018055565b6112dc6116a7565b6112e533610deb565b6113225760405162461bcd60e51b815260206004820152600e60248201526d2737ba1030903932bbb0b93232b960911b6044820152606401610667565b6000601054116113745760405162461bcd60e51b815260206004820152601860248201527f4e6f2061646d696e2066656520746f20776974686472617700000000000000006044820152606401610667565b601054600254611391916001600160a01b03909116908390611813565b6001600160a01b038116336001600160a01b03167f0f91ec7dc481b98d4bad468bb4a67d8b6e1323ab76c3dce57f4a9f943bf817716010546040516113d891815260200190565b60405180910390a3600060105561070160018055565b6000816113fa81611664565b6114465760405162461bcd60e51b815260206004820152601a60248201527f52657761726420746f6b656e206e6f7420737570706f727465640000000000006044820152606401610667565b600e5461146d576001600160a01b0383166000908152600a6020526040902054915061098e565b600e546001600160a01b038416600090815260096020908152604080832054600b9092529091205461098b926114c39290916107e391670de0b6b3a7640000916114bd919082906107be8c61090f565b906118f1565b6001600160a01b0385166000908152600a602052604090205490611909565b61150660405180606001604052806000815260200160008152602001600081525090565b61150f836115c0565b821061155d5760405162461bcd60e51b815260206004820152601360248201527f496e646578206f7574206f6620626f756e6473000000000000000000000000006044820152606401610667565b6001600160a01b0383166000908152601260205260408120906115808285611d3a565b6000908152601360209081526040918290208251606081018452815481526001820154928101929092526002015491810191909152925050505b92915050565b6001600160a01b038116600090815260126020526040812054600f81810b600160801b909204900b036115ba565b6115f661188b565b6001600160a01b03811661165b5760405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201526564647265737360d01b6064820152608401610667565b61070181611938565b60006115ba6004835b6001600160a01b038116600090815260018301602052604081205415155b9392505050565b600061168b836001600160a01b038416611dab565b600260015414156116fa5760405162461bcd60e51b815260206004820152601f60248201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c006044820152606401610667565b6002600155565b60006115ba825490565b600061168b8383611dfa565b61172081611664565b61176c5760405162461bcd60e51b815260206004820152601a60248201527f52657761726420746f6b656e206e6f7420737570706f727465640000000000006044820152606401610667565b611775816113ee565b6001600160a01b0382166000908152600a60205260409020556117978161090f565b6001600160a01b038083166000908152600b602052604090209190915582161561180f576117c58282610704565b6001600160a01b038084166000818152600d6020908152604080832094871680845294825280832095909555600a815284822054928252600c815284822093825292909252919020555b5050565b6040516001600160a01b038316602482015260448101829052610f1b90849063a9059cbb60e01b906064015b60408051601f198184030181529190526020810180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff166001600160e01b031990931692909217909152611e24565b6000546001600160a01b031633146106035760405162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e65726044820152606401610667565b600061168b82846123ff565b600061168b8284612416565b600061168b8284612435565b600061168b8284612457565b6060600061168b83611ef6565b6000818310611931578161168b565b5090919050565b600080546001600160a01b0383811673ffffffffffffffffffffffffffffffffffffffff19831681178455604051919092169283917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09190a35050565b6040516001600160a01b03808516602483015283166044820152606481018290526119cd9085906323b872dd60e01b9060840161183f565b50505050565b6119dc33610deb565b611a195760405162461bcd60e51b815260206004820152600e60248201526d2737ba1030903932bbb0b93232b960911b6044820152606401610667565b600083611a268282611717565b6001600160a01b0385166000908152600860205260409020544210611a6d57611a4f84846118fd565b6001600160a01b038616600090815260096020526040902055611ae4565b6001600160a01b038516600090815260086020526040812054611a9090426118e5565b6001600160a01b03871660009081526009602052604081205491925090611ab89083906118f1565b9050611ac8856107e38884611909565b6001600160a01b03881660009081526009602052604090205550505b6040516370a0823160e01b81523060048201526000906001600160a01b038716906370a0823190602401602060405180830381865afa158015611b2b573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611b4f919061246f565b9050611b5b81856118fd565b6001600160a01b0387166000908152600960205260409020541115611bc25760405162461bcd60e51b815260206004820152601860248201527f50726f76696465642072657761726420746f6f206869676800000000000000006044820152606401610667565b6001600160a01b0386166000908152600b602052604090204290819055611be99085611909565b6001600160a01b03871660008181526008602090815260409182902093909355805188815292830187905233927fbdfd07c4944984536c4cb47c9ced23a77b0407b07e5ac1577835d02c1303c8ba910160405180910390a3505050505050565b600061168b836001600160a01b038416611f52565b6000611c798254600f81810b600160801b909204900b131590565b15611c9757604051631ed9509560e11b815260040160405180910390fd5b508054600f0b60009081526001909101602052604090205490565b6000611ccd8254600f81810b600160801b909204900b131590565b15611ceb57604051631ed9509560e11b815260040160405180910390fd5b508054600f0b6000818152600180840160205260408220805492905583546fffffffffffffffffffffffffffffffff191692016fffffffffffffffffffffffffffffffff169190911790915590565b600080611d5d611d4984612045565b8554611d589190600f0b612488565b6120b3565b8454909150600160801b9004600f90810b9082900b12611d9057604051632d0483c560e21b815260040160405180910390fd5b600f0b60009081526001939093016020525050604090205490565b6000818152600183016020526040812054611df2575081546001818101845560008481526020808220909301849055845484825282860190935260409020919091556115ba565b5060006115ba565b6000826000018281548110611e1157611e116124c8565b9060005260206000200154905092915050565b6000611e79826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b031661211c9092919063ffffffff16565b805190915015610f1b5780806020019051810190611e9791906124de565b610f1b5760405162461bcd60e51b815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e6044820152691bdd081cdd58d8d9595960b21b6064820152608401610667565b606081600001805480602002602001604051908101604052809291908181526020018280548015611f4657602002820191906000526020600020905b815481526020019060010190808311611f32575b50505050509050919050565b6000818152600183016020526040812054801561203b576000611f766001836123ff565b8554909150600090611f8a906001906123ff565b9050818114611fef576000866000018281548110611faa57611faa6124c8565b9060005260206000200154905080876000018481548110611fcd57611fcd6124c8565b6000918252602080832090910192909255918252600188019052604090208390555b855486908061200057612000612500565b6001900381819060005260206000200160009055905585600101600086815260200190815260200160002060009055600193505050506115ba565b60009150506115ba565b60006001600160ff1b038211156120af5760405162461bcd60e51b815260206004820152602860248201527f53616665436173743a2076616c756520646f65736e27742066697420696e2061604482015267371034b73a191a9b60c11b6064820152608401610667565b5090565b80600f81900b81146121175760405162461bcd60e51b815260206004820152602760248201527f53616665436173743a2076616c756520646f65736e27742066697420696e20316044820152663238206269747360c81b6064820152608401610667565b919050565b60606107ef848460008585600080866001600160a01b031685876040516121439190612542565b60006040518083038185875af1925050503d8060008114612180576040519150601f19603f3d011682016040523d82523d6000602084013e612185565b606091505b5091509150612196878383876121a1565b979650505050505050565b6060831561220d578251612206576001600160a01b0385163b6122065760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e74726163740000006044820152606401610667565b50816107ef565b6107ef83838151156122225781518083602001fd5b8060405162461bcd60e51b8152600401610667919061255e565b80356001600160a01b038116811461211757600080fd5b60006020828403121561226557600080fd5b61168b8261223c565b6000806040838503121561228157600080fd5b61228a8361223c565b91506122986020840161223c565b90509250929050565b6020808252825182820181905260009190848201906040850190845b818110156122e25783516001600160a01b0316835292840192918401916001016122bd565b50909695505050505050565b60006060828403121561230057600080fd5b6040516060810181811067ffffffffffffffff8211171561233157634e487b7160e01b600052604160045260246000fd5b80604052508235815260208301356020820152604083013560408201528091505092915050565b60006020828403121561236a57600080fd5b5035919050565b60008060006060848603121561238657600080fd5b61238f8461223c565b95602085013595506040909401359392505050565b600080604083850312156123b757600080fd5b6123c08361223c565b946020939093013593505050565b634e487b7160e01b600052601160045260246000fd5b60006000198214156123f8576123f86123ce565b5060010190565b600082821015612411576124116123ce565b500390565b6000816000190483118215151615612430576124306123ce565b500290565b60008261245257634e487b7160e01b600052601260045260246000fd5b500490565b6000821982111561246a5761246a6123ce565b500190565b60006020828403121561248157600080fd5b5051919050565b6000808212826001600160ff1b03038413811516156124a9576124a96123ce565b600160ff1b83900384128116156124c2576124c26123ce565b50500190565b634e487b7160e01b600052603260045260246000fd5b6000602082840312156124f057600080fd5b8151801515811461168b57600080fd5b634e487b7160e01b600052603160045260246000fd5b60005b83811015612531578181015183820152602001612519565b838111156119cd5750506000910152565b60008251612554818460208701612516565b9190910192915050565b602081526000825180602084015261257d816040850160208701612516565b601f01601f1916919091016040019291505056fea2646970667358221220c85980b0708285dba2735bb4eb420619ab2ac1e71f9104470d1ea82213a80a8164736f6c634300080c00335a65726f20616464726573732064657465637465640000000000000000000000000000000000000000000000fac77a24e52b463ba9857d6b758ba41ae20e31ff000000000000000000000000000000000000000000000000000000000000006000000000000000000000000072e003ea1fa945de91a1426ea96ac3feec91d6540000000000000000000000000000000000000000000000000000000000000002000000000000000000000000fac77a24e52b463ba9857d6b758ba41ae20e31ff00000000000000000000000021ead867c8c5181854f6f8ce71f75b173d2bc16a
Deployed Bytecode
0x608060405234801561001057600080fd5b50600436106101f05760003560e01c8063a0be06f91161010f578063da09d19d116100a2578063e72215d111610071578063e72215d114610470578063f24c2a1a14610483578063f2fde38b146104a3578063f7384d50146104b657600080fd5b8063da09d19d146103dd578063e12f1dc2146103fd578063e3bd00c314610410578063e70b9e271461044557600080fd5b8063c2b18aa0116100de578063c2b18aa0146103a7578063cb908b9d146103af578063d2d83ec9146103c2578063d883c43d146103ca57600080fd5b8063a0be06f914610366578063a57ce09f1461036e578063a6645fdd14610381578063c1aaa53c1461039457600080fd5b806356d3590b116101875780638da5cb5b116101565780638da5cb5b146102f0578063927b8c15146103155780639470b443146103285780639790d3c11461033b57600080fd5b806356d3590b146102995780635e658955146102ac57806370a08231146102bf578063715018a6146102e857600080fd5b80632ce9aead116101c35780632ce9aead1461023c57806339a8bba61461025c5780633d3b2603146102645780634fb2eeed1461028457600080fd5b80630572b0cc146101f557806318160ddd146101ff5780631c03e6cc14610216578063211dc32d14610229575b600080fd5b6101fd6104d9565b005b600e545b6040519081526020015b60405180910390f35b6101fd610224366004612253565b610605565b61020361023736600461226e565b610704565b61020361024a366004612253565b600b6020526000908152604090205481565b6101fd6107f7565b610203610272366004612253565b60096020526000908152604090205481565b61028c610807565b60405161020d91906122a1565b6101fd6102a7366004612253565b610818565b6102036102ba366004612253565b61090f565b6102036102cd366004612253565b6001600160a01b03166000908152600f602052604090205490565b6101fd610994565b6000546001600160a01b03165b6040516001600160a01b03909116815260200161020d565b6003546102fd906001600160a01b031681565b6102036103363660046122ee565b6109a6565b61020361034936600461226e565b600c60209081526000928352604080842090915290825290205481565b601054610203565b6101fd61037c366004612358565b610b3c565b6002546102fd906001600160a01b031681565b6101fd6103a2366004612371565b610d88565b61028c610f20565b6101fd6103bd366004612253565b610f2c565b6101fd611018565b6101fd6103d8366004612253565b6112d4565b6102036103eb366004612253565b60086020526000908152604090205481565b61020361040b366004612253565b6113ee565b61042361041e3660046123a4565b6114e2565b604080518251815260208084015190820152918101519082015260600161020d565b61020361045336600461226e565b600d60209081526000928352604080842090915290825290205481565b61020361047e366004612253565b6115c0565b610203610491366004612253565b600a6020526000908152604090205481565b6101fd6104b1366004612253565b6115ee565b6104c96104c4366004612253565b611664565b604051901515815260200161020d565b6104e16116a7565b3360005b6104ef6004611701565b81101561052257600061050360048361170b565b905061050f8382611717565b508061051a816123e4565b9150506104e5565b5060005b6105306004611701565b8110156105f857600061054460048361170b565b336000908152600d602090815260408083206001600160a01b038516845290915290205490915080156105e357336000818152600d602090815260408083206001600160a01b03871680855292528220919091556105a29183611813565b6040518181526001600160a01b0383169033907f626f8f3c00d88f1688098a6dbcbe3aadbe1543112d7d46abb7b0201e83b492fb9060200160405180910390a35b505080806105f0906123e4565b915050610526565b505061060360018055565b565b61060d6116a7565b61061561188b565b6001600160a01b0381166106705760405162461bcd60e51b815260206004820152601560248201527f5a65726f2061646472657373206465746563746564000000000000000000000060448201526064015b60405180910390fd5b61067b60048261166d565b156106b85760405162461bcd60e51b815260206004820152600d60248201526c105b1c9958591e481859191959609a1b6044820152606401610667565b6106c3600482611692565b506040516001600160a01b038216907ff3e4c2c64e71e6ba2eaab9a599bced62f9eb91d2cda610bf41aa8c80ff2cf82690600090a261070160018055565b50565b60008161071081611664565b61075c5760405162461bcd60e51b815260206004820152601a60248201527f52657761726420746f6b656e206e6f7420737570706f727465640000000000006044820152606401610667565b6001600160a01b038085166000818152600d6020908152604080832094881680845294825280832054938352600c825280832094835293905291909120546107ef91906107e990670de0b6b3a7640000906107e3906107c4906107be8a6113ee565b906118e5565b6001600160a01b038a166000908152600f6020526040902054906118f1565b906118fd565b90611909565b949350505050565b6107ff611018565b6106036104d9565b60606108136006611915565b905090565b6108206116a7565b61082861188b565b6001600160a01b03811661087e5760405162461bcd60e51b815260206004820152601560248201527f5a65726f206164647265737320646574656374656400000000000000000000006044820152606401610667565b61088960068261166d565b156108c65760405162461bcd60e51b815260206004820152600d60248201526c105b1c9958591e481859191959609a1b6044820152606401610667565b6108d1600682611692565b506040516001600160a01b038216907f9dfd431959d2d3358e3eb909555ad574123ea5881ff0e05a80f66d4984710c1b90600090a261070160018055565b60008161091b81611664565b6109675760405162461bcd60e51b815260206004820152601a60248201527f52657761726420746f6b656e206e6f7420737570706f727465640000000000006044820152606401610667565b6001600160a01b03831660009081526008602052604090205461098b904290611922565b91505b50919050565b61099c61188b565b6106036000611938565b6000428260400151106109fb5760405162461bcd60e51b815260206004820152601460248201527f496e76616c6964206465706f7369742074696d650000000000000000000000006044820152606401610667565b6000826020015111610a4f5760405162461bcd60e51b815260206004820152601660248201527f496e76616c6964206465706f73697420616d6f756e74000000000000000000006044820152606401610667565b6000610a688360400151426118e590919063ffffffff16565b905062093a80811015610a925761098b60646107e3605a86602001516118f190919063ffffffff16565b62278d00811015610aba5761098b60646107e3603286602001516118f190919063ffffffff16565b6276a700811015610ae25761098b60646107e3602386602001516118f190919063ffffffff16565b62ed4e00811015610b0a5761098b60646107e3601486602001516118f190919063ffffffff16565b6301e13380811015610b335761098b60646107e3600a86602001516118f190919063ffffffff16565b50600092915050565b610b446116a7565b3360005b610b526004611701565b811015610b85576000610b6660048361170b565b9050610b728382611717565b5080610b7d816123e4565b915050610b48565b5060008211610bd65760405162461bcd60e51b815260206004820152601060248201527f43616e6e6f74206465706f7369742030000000000000000000000000000000006044820152606401610667565b600e54610be39083611909565b600e55336000908152600f6020526040902054610c009083611909565b336000818152600f6020526040902091909155600254610c2d916001600160a01b03909116903085611995565b6003546001600160a01b03166340c10f19336040516001600160e01b031960e084901b1681526001600160a01b03909116600482015260248101859052604401600060405180830381600087803b158015610c8757600080fd5b505af1158015610c9b573d6000803e3d6000fd5b50505050610cad601180546001019055565b6000610cb860115490565b604080516060810182528281526020808201878152428385019081526000868152601384528581208551815592516001808501919091559151600290930192909255338252601283528482208054600160801b90819004600f0b8085528284019095529590922086905581546fffffffffffffffffffffffffffffffff908116939091011690930217825591925060405185815233907f2da466a7b24304f47e87fa2e1e5a81b9831ce54fec19055ce277ca2f39ba42c49060200160405180910390a25050505061070160018055565b610d906116a7565b82610d9a81611664565b610de65760405162461bcd60e51b815260206004820152601a60248201527f52657761726420746f6b656e206e6f7420737570706f727465640000000000006044820152606401610667565b610df3335b60069061166d565b610e305760405162461bcd60e51b815260206004820152600e60248201526d2737ba1030903932bbb0b93232b960911b6044820152606401610667565b60008311610e8f5760405162461bcd60e51b815260206004820152602660248201527f52657761726420616d6f756e742073686f756c6420626520677265617465722060448201526507468616e20360d41b6064820152608401610667565b60008211610edf5760405162461bcd60e51b815260206004820152601960248201527f526577617264206475726174696f6e20746f6f2073686f7274000000000000006044820152606401610667565b6000610eee83620151806118f1565b9050610f056001600160a01b038616333087611995565b610f108585836119d3565b5050610f1b60018055565b505050565b60606108136004611915565b610f346116a7565b610f3c61188b565b610f4760068261166d565b610f845760405162461bcd60e51b815260206004820152600e60248201526d2737ba1030903932bbb0b93232b960911b6044820152606401610667565b610f8f600682611c49565b610fdb5760405162461bcd60e51b815260206004820152601960248201527f4661696c656420746f2072656d6f7665207265776172646572000000000000006044820152606401610667565b6040516001600160a01b038216907fce699c579f0b70ea4ccd6a4b38be26726a2c248b89c7102ccbc5d0f3060ef6d090600090a261070160018055565b6110206116a7565b3360005b61102e6004611701565b81101561106157600061104260048361170b565b905061104e8382611717565b5080611059816123e4565b915050611024565b503360009081526012602052604090208054600f81810b600160801b909204900b136110cf5760405162461bcd60e51b815260206004820152601660248201527f4e6f206465706f73697420746f207769746864726177000000000000000000006044820152606401610667565b60006110da82611c5e565b6000818152601360209081526040918290208251606081018452815481526001820154928101839052600290910154928101929092529192509061111d84611cb2565b506000838152601360205260408120818155600181018290556002015580156112c657600e5461114d90826118e5565b600e55336000908152600f602052604090205461116a90826118e5565b336000908152600f6020526040812091909155611186836109a6565b9050600061119483836118e5565b90506111ad336002546001600160a01b03169083611813565b6003546001600160a01b03166379cc6790336040516001600160e01b031960e084901b1681526001600160a01b03909116600482015260248101869052604401600060405180830381600087803b15801561120757600080fd5b505af115801561121b573d6000803e3d6000fd5b505050506112263390565b6001600160a01b03167f92ccf450a286a957af52509bc1c9939d1a6a481783e142e41e2499f0bb66ebc68484604051611269929190918252602082015260400190565b60405180910390a281156112c3576010546112849083611909565b601055604080518481526020810184905233917fcaf5e96b430c9e7a869bfca8b7ee6effbfd2166be120be294538e37301ae67db910160405180910390a25b50505b505050505061060360018055565b6112dc6116a7565b6112e533610deb565b6113225760405162461bcd60e51b815260206004820152600e60248201526d2737ba1030903932bbb0b93232b960911b6044820152606401610667565b6000601054116113745760405162461bcd60e51b815260206004820152601860248201527f4e6f2061646d696e2066656520746f20776974686472617700000000000000006044820152606401610667565b601054600254611391916001600160a01b03909116908390611813565b6001600160a01b038116336001600160a01b03167f0f91ec7dc481b98d4bad468bb4a67d8b6e1323ab76c3dce57f4a9f943bf817716010546040516113d891815260200190565b60405180910390a3600060105561070160018055565b6000816113fa81611664565b6114465760405162461bcd60e51b815260206004820152601a60248201527f52657761726420746f6b656e206e6f7420737570706f727465640000000000006044820152606401610667565b600e5461146d576001600160a01b0383166000908152600a6020526040902054915061098e565b600e546001600160a01b038416600090815260096020908152604080832054600b9092529091205461098b926114c39290916107e391670de0b6b3a7640000916114bd919082906107be8c61090f565b906118f1565b6001600160a01b0385166000908152600a602052604090205490611909565b61150660405180606001604052806000815260200160008152602001600081525090565b61150f836115c0565b821061155d5760405162461bcd60e51b815260206004820152601360248201527f496e646578206f7574206f6620626f756e6473000000000000000000000000006044820152606401610667565b6001600160a01b0383166000908152601260205260408120906115808285611d3a565b6000908152601360209081526040918290208251606081018452815481526001820154928101929092526002015491810191909152925050505b92915050565b6001600160a01b038116600090815260126020526040812054600f81810b600160801b909204900b036115ba565b6115f661188b565b6001600160a01b03811661165b5760405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201526564647265737360d01b6064820152608401610667565b61070181611938565b60006115ba6004835b6001600160a01b038116600090815260018301602052604081205415155b9392505050565b600061168b836001600160a01b038416611dab565b600260015414156116fa5760405162461bcd60e51b815260206004820152601f60248201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c006044820152606401610667565b6002600155565b60006115ba825490565b600061168b8383611dfa565b61172081611664565b61176c5760405162461bcd60e51b815260206004820152601a60248201527f52657761726420746f6b656e206e6f7420737570706f727465640000000000006044820152606401610667565b611775816113ee565b6001600160a01b0382166000908152600a60205260409020556117978161090f565b6001600160a01b038083166000908152600b602052604090209190915582161561180f576117c58282610704565b6001600160a01b038084166000818152600d6020908152604080832094871680845294825280832095909555600a815284822054928252600c815284822093825292909252919020555b5050565b6040516001600160a01b038316602482015260448101829052610f1b90849063a9059cbb60e01b906064015b60408051601f198184030181529190526020810180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff166001600160e01b031990931692909217909152611e24565b6000546001600160a01b031633146106035760405162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e65726044820152606401610667565b600061168b82846123ff565b600061168b8284612416565b600061168b8284612435565b600061168b8284612457565b6060600061168b83611ef6565b6000818310611931578161168b565b5090919050565b600080546001600160a01b0383811673ffffffffffffffffffffffffffffffffffffffff19831681178455604051919092169283917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09190a35050565b6040516001600160a01b03808516602483015283166044820152606481018290526119cd9085906323b872dd60e01b9060840161183f565b50505050565b6119dc33610deb565b611a195760405162461bcd60e51b815260206004820152600e60248201526d2737ba1030903932bbb0b93232b960911b6044820152606401610667565b600083611a268282611717565b6001600160a01b0385166000908152600860205260409020544210611a6d57611a4f84846118fd565b6001600160a01b038616600090815260096020526040902055611ae4565b6001600160a01b038516600090815260086020526040812054611a9090426118e5565b6001600160a01b03871660009081526009602052604081205491925090611ab89083906118f1565b9050611ac8856107e38884611909565b6001600160a01b03881660009081526009602052604090205550505b6040516370a0823160e01b81523060048201526000906001600160a01b038716906370a0823190602401602060405180830381865afa158015611b2b573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611b4f919061246f565b9050611b5b81856118fd565b6001600160a01b0387166000908152600960205260409020541115611bc25760405162461bcd60e51b815260206004820152601860248201527f50726f76696465642072657761726420746f6f206869676800000000000000006044820152606401610667565b6001600160a01b0386166000908152600b602052604090204290819055611be99085611909565b6001600160a01b03871660008181526008602090815260409182902093909355805188815292830187905233927fbdfd07c4944984536c4cb47c9ced23a77b0407b07e5ac1577835d02c1303c8ba910160405180910390a3505050505050565b600061168b836001600160a01b038416611f52565b6000611c798254600f81810b600160801b909204900b131590565b15611c9757604051631ed9509560e11b815260040160405180910390fd5b508054600f0b60009081526001909101602052604090205490565b6000611ccd8254600f81810b600160801b909204900b131590565b15611ceb57604051631ed9509560e11b815260040160405180910390fd5b508054600f0b6000818152600180840160205260408220805492905583546fffffffffffffffffffffffffffffffff191692016fffffffffffffffffffffffffffffffff169190911790915590565b600080611d5d611d4984612045565b8554611d589190600f0b612488565b6120b3565b8454909150600160801b9004600f90810b9082900b12611d9057604051632d0483c560e21b815260040160405180910390fd5b600f0b60009081526001939093016020525050604090205490565b6000818152600183016020526040812054611df2575081546001818101845560008481526020808220909301849055845484825282860190935260409020919091556115ba565b5060006115ba565b6000826000018281548110611e1157611e116124c8565b9060005260206000200154905092915050565b6000611e79826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b031661211c9092919063ffffffff16565b805190915015610f1b5780806020019051810190611e9791906124de565b610f1b5760405162461bcd60e51b815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e6044820152691bdd081cdd58d8d9595960b21b6064820152608401610667565b606081600001805480602002602001604051908101604052809291908181526020018280548015611f4657602002820191906000526020600020905b815481526020019060010190808311611f32575b50505050509050919050565b6000818152600183016020526040812054801561203b576000611f766001836123ff565b8554909150600090611f8a906001906123ff565b9050818114611fef576000866000018281548110611faa57611faa6124c8565b9060005260206000200154905080876000018481548110611fcd57611fcd6124c8565b6000918252602080832090910192909255918252600188019052604090208390555b855486908061200057612000612500565b6001900381819060005260206000200160009055905585600101600086815260200190815260200160002060009055600193505050506115ba565b60009150506115ba565b60006001600160ff1b038211156120af5760405162461bcd60e51b815260206004820152602860248201527f53616665436173743a2076616c756520646f65736e27742066697420696e2061604482015267371034b73a191a9b60c11b6064820152608401610667565b5090565b80600f81900b81146121175760405162461bcd60e51b815260206004820152602760248201527f53616665436173743a2076616c756520646f65736e27742066697420696e20316044820152663238206269747360c81b6064820152608401610667565b919050565b60606107ef848460008585600080866001600160a01b031685876040516121439190612542565b60006040518083038185875af1925050503d8060008114612180576040519150601f19603f3d011682016040523d82523d6000602084013e612185565b606091505b5091509150612196878383876121a1565b979650505050505050565b6060831561220d578251612206576001600160a01b0385163b6122065760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e74726163740000006044820152606401610667565b50816107ef565b6107ef83838151156122225781518083602001fd5b8060405162461bcd60e51b8152600401610667919061255e565b80356001600160a01b038116811461211757600080fd5b60006020828403121561226557600080fd5b61168b8261223c565b6000806040838503121561228157600080fd5b61228a8361223c565b91506122986020840161223c565b90509250929050565b6020808252825182820181905260009190848201906040850190845b818110156122e25783516001600160a01b0316835292840192918401916001016122bd565b50909695505050505050565b60006060828403121561230057600080fd5b6040516060810181811067ffffffffffffffff8211171561233157634e487b7160e01b600052604160045260246000fd5b80604052508235815260208301356020820152604083013560408201528091505092915050565b60006020828403121561236a57600080fd5b5035919050565b60008060006060848603121561238657600080fd5b61238f8461223c565b95602085013595506040909401359392505050565b600080604083850312156123b757600080fd5b6123c08361223c565b946020939093013593505050565b634e487b7160e01b600052601160045260246000fd5b60006000198214156123f8576123f86123ce565b5060010190565b600082821015612411576124116123ce565b500390565b6000816000190483118215151615612430576124306123ce565b500290565b60008261245257634e487b7160e01b600052601260045260246000fd5b500490565b6000821982111561246a5761246a6123ce565b500190565b60006020828403121561248157600080fd5b5051919050565b6000808212826001600160ff1b03038413811516156124a9576124a96123ce565b600160ff1b83900384128116156124c2576124c26123ce565b50500190565b634e487b7160e01b600052603260045260246000fd5b6000602082840312156124f057600080fd5b8151801515811461168b57600080fd5b634e487b7160e01b600052603160045260246000fd5b60005b83811015612531578181015183820152602001612519565b838111156119cd5750506000910152565b60008251612554818460208701612516565b9190910192915050565b602081526000825180602084015261257d816040850160208701612516565b601f01601f1916919091016040019291505056fea2646970667358221220c85980b0708285dba2735bb4eb420619ab2ac1e71f9104470d1ea82213a80a8164736f6c634300080c0033
Constructor Arguments (ABI-Encoded and is the last bytes of the Contract Creation Code above)
000000000000000000000000fac77a24e52b463ba9857d6b758ba41ae20e31ff000000000000000000000000000000000000000000000000000000000000006000000000000000000000000072e003ea1fa945de91a1426ea96ac3feec91d6540000000000000000000000000000000000000000000000000000000000000002000000000000000000000000fac77a24e52b463ba9857d6b758ba41ae20e31ff00000000000000000000000021ead867c8c5181854f6f8ce71f75b173d2bc16a
-----Decoded View---------------
Arg [0] : _lsdToken (address): 0xfAC77A24E52B463bA9857d6b758ba41aE20e31FF
Arg [1] : _rewardTokens (address[]): 0xfAC77A24E52B463bA9857d6b758ba41aE20e31FF,0x21eAD867C8c5181854f6f8Ce71f75b173d2Bc16A
Arg [2] : _velsdToken (address): 0x72e003ea1FA945De91A1426eA96Ac3FeEc91D654
-----Encoded View---------------
6 Constructor Arguments found :
Arg [0] : 000000000000000000000000fac77a24e52b463ba9857d6b758ba41ae20e31ff
Arg [1] : 0000000000000000000000000000000000000000000000000000000000000060
Arg [2] : 00000000000000000000000072e003ea1fa945de91a1426ea96ac3feec91d654
Arg [3] : 0000000000000000000000000000000000000000000000000000000000000002
Arg [4] : 000000000000000000000000fac77a24e52b463ba9857d6b758ba41ae20e31ff
Arg [5] : 00000000000000000000000021ead867c8c5181854f6f8ce71f75b173d2bc16a
Loading...
Loading
Loading...
Loading
Multichain Portfolio | 30 Chains
Chain | Token | Portfolio % | Price | Amount | Value |
---|---|---|---|---|---|
ETH | 100.00% | $0.002332 | 15,079,819.6543 | $35,165.54 |
Loading...
Loading
[ Download: CSV Export ]
A contract address hosts a smart contract, which is a set of code stored on the blockchain that runs when predetermined conditions are met. Learn more about addresses in our Knowledge Base.