Transactions
Token Transfers
Tokens
Internal Transactions
Coin Balance History
Logs
Code
Read Contract
Write Contract
Warning! Contract bytecode has been changed and doesn't match the verified one. Therefore, interaction with this smart contract may be risky.
This contract has been verified via Sourcify.
View contract in Sourcify repository
- Contract name:
- RewardToken
- Optimization enabled
- true
- Compiler version
- v0.8.20+commit.a1b79de6
- Optimization runs
- 200
- EVM Version
- paris
- Verified at
- 2026-02-03T08:02:08.906960Z
Constructor Arguments
0000000000000000000000003c4ec5a8d291609b757f22459baa99465306c76a
Arg [0] (address) : 0x3c4ec5a8d291609b757f22459baa99465306c76a
contracts/RewardToken.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/utils/math/SafeMath.sol";
import "@openzeppelin/contracts/token/ERC721/IERC721.sol";
import "./interfaces/IUniswapV2Router02.sol";
import "./interfaces/IUniswapV2Factory.sol";
import "./interfaces/IStakingRewards.sol";
import "./interfaces/IVotingToken.sol";
contract RewardToken is ERC20, Ownable {
using SafeMath for uint256;
struct Proposal {
uint256 id;
string description;
uint256 forVotes;
uint256 againstVotes;
uint256 startTime;
uint256 endTime;
bool executed;
address proposer;
mapping(address => bool) hasVoted;
}
uint256 public votingPeriod = 3 days;
uint256 public PROPOSAL_THRESHOLD_BPS = 100; //1%
uint256 public QUORUM_BPS = 1000; //10%
uint256 public constant BPS_DENOMINATOR = 10000;
address public masterchef;
address public stakingRewards;
address public votingToken;
address public nftAddress;
mapping (address => bool) public isWhitelisted;
uint256 public totalBurned;
address public pair;
IUniswapV2Router02 public pulseXRouter = IUniswapV2Router02(0x165C3410fC91EF562C50559f7d2289fEbed552d9);
bool public swapEnabled = true;
uint256 public swapThreshold = 10 ether;
uint256 public stakeThreshold = 50000 ether;
bool inSwap;
mapping(uint256 => Proposal) public proposals;
uint256 public proposalCount;
uint256 stakeFee = 500;
modifier swapping() { inSwap = true; _; inSwap = false; }
event ProposalCreated(uint256 indexed proposalId, address indexed proposer, string description, uint256 startTime, uint256 endTime);
event VoteCast(address indexed voter, uint256 indexed proposalId, bool support, uint256 weight);
event ProposalExecuted(uint256 indexed proposalId);
event VotingParametersUpdated(uint256 votingPeriod, uint256 proposalThresholdBps, uint256 quorumBps);
event Burned(uint256 amount);
constructor(address _nftAddress) ERC20("TruFarm", "TruFarm") {
pair = IUniswapV2Factory(pulseXRouter.factory()).createPair(
address(this),
pulseXRouter.WPLS()
);
nftAddress = _nftAddress;
isWhitelisted[address(this)] = true;
isWhitelisted[msg.sender] = true;
_mint(msg.sender, 1_100_000 * 10**18);
_approve(address(this), address(pulseXRouter), type(uint256).max);
}
receive() external payable {}
function shouldSwapBack() internal view returns (bool) {
return msg.sender != pair
&& !inSwap
&& swapEnabled
&& balanceOf(address(this)) >= swapThreshold;
}
function swapBack() internal swapping {
address[] memory path = new address[](2);
path[0] = address(this);
path[1] = pulseXRouter.WPLS();
pulseXRouter.swapExactTokensForETHSupportingFeeOnTransferTokens(
swapThreshold,
0,
path,
address(this),
block.timestamp
);
uint256 balance = address(this).balance;
if (balance >= stakeThreshold) {
try IStakingRewards(stakingRewards).topUp{value: balance}() {} catch {}
}
}
function _transfer(address sender, address recipient, uint256 amount) internal override(ERC20){
if (isWhitelisted[recipient] || isWhitelisted[sender]) {
super._transfer(sender, recipient, amount);
} else {
if(inSwap) { return super._transfer(sender, recipient, amount); }
if(shouldSwapBack()) {swapBack();}
uint256 toStake = amount * stakeFee / 10000;
uint256 afterFees = amount - toStake;
super._transfer(sender, address(this), toStake);
super._transfer(sender, recipient, afterFees);
}
}
function mint(uint256 _amount) public onlyMasterchef returns (bool) {
return mintFor(address(this), _amount);
}
function burn(uint256 _amount) public {
totalBurned += _amount;
_burn(msg.sender, _amount);
emit Burned(_amount);
}
function setMasterchef(address _masterchef) external onlyOwner {
masterchef = _masterchef;
}
function getProposalThreshold() public view returns (uint256) {
return IVotingToken(votingToken).totalSupply().mul(PROPOSAL_THRESHOLD_BPS).div(BPS_DENOMINATOR);
}
function getQuorum() public view returns (uint256) {
return IVotingToken(votingToken).totalSupply().mul(QUORUM_BPS).div(BPS_DENOMINATOR);
}
modifier onlyMasterchef() {
require(msg.sender == masterchef, "Caller is not the Masterchef");
_;
}
function safeTokenTransfer(address _to, uint256 _amount) public onlyMasterchef {
uint256 balance = balanceOf(address(this));
if (_amount > balance) {
_transfer(address(this), _to, balance);
} else {
_transfer(address(this), _to, _amount);
}
}
function createProposal(string memory description) external returns (uint256) {
require(IVotingToken(votingToken).balanceOf(msg.sender) >= getProposalThreshold(), "proposer votes below threshold");
require(IERC721(nftAddress).balanceOf(msg.sender) > 0, "must hold nft");
proposalCount++;
Proposal storage proposal = proposals[proposalCount];
proposal.id = proposalCount;
proposal.description = description;
proposal.proposer = msg.sender;
proposal.startTime = block.timestamp;
proposal.endTime = block.timestamp + votingPeriod;
emit ProposalCreated(proposalCount, msg.sender, description, proposal.startTime, proposal.endTime);
return proposalCount;
}
function castVote(uint256 proposalId, bool support) external {
Proposal storage proposal = proposals[proposalId];
require(block.timestamp <= proposal.endTime, "voting is closed");
require(!proposal.hasVoted[msg.sender], "already voted");
require(IERC721(nftAddress).balanceOf(msg.sender) > 0, "must hold nft");
uint256 votes = IVotingToken(votingToken).balanceOf(msg.sender);
require(votes > 0, "no voting power");
proposal.hasVoted[msg.sender] = true;
if (support) {
proposal.forVotes = proposal.forVotes.add(votes);
} else {
proposal.againstVotes = proposal.againstVotes.add(votes);
}
emit VoteCast(msg.sender, proposalId, support, votes);
}
function executeProposal(uint256 proposalId) external {
Proposal storage proposal = proposals[proposalId];
require(block.timestamp > proposal.endTime, "voting still active");
require(!proposal.executed, "proposal already executed");
uint256 totalVotes = proposal.forVotes.add(proposal.againstVotes);
require(totalVotes >= getQuorum(), "quorum not reached");
require(proposal.forVotes > proposal.againstVotes, "proposal defeated");
proposal.executed = true;
emit ProposalExecuted(proposalId);
}
function hasVoted(uint256 proposalId, address voter) external view returns (bool) {
return proposals[proposalId].hasVoted[voter];
}
function getProposalState(uint256 proposalId) external view returns (
uint256 forVotes,
uint256 againstVotes,
bool active,
bool passed
) {
Proposal storage proposal = proposals[proposalId];
forVotes = proposal.forVotes;
againstVotes = proposal.againstVotes;
active = block.timestamp <= proposal.endTime;
if (!active) {
uint256 totalVotes = forVotes.add(againstVotes);
passed = totalVotes >= getQuorum() && forVotes > againstVotes;
}
}
function setNftAddress(address _nftAddress) external onlyOwner {
nftAddress = _nftAddress;
}
function setVotingToken(address _votingToken) external onlyOwner {
votingToken = _votingToken;
}
function setVotingParameters(
uint256 _votingPeriod,
uint256 _proposalThresholdBps,
uint256 _quorumBps
) external onlyOwner {
require(_proposalThresholdBps <= BPS_DENOMINATOR, "threshold BPS exceeds denominator");
require(_quorumBps <= BPS_DENOMINATOR, "quorum BPS exceeds denominator");
votingPeriod = _votingPeriod;
PROPOSAL_THRESHOLD_BPS = _proposalThresholdBps;
QUORUM_BPS = _quorumBps;
emit VotingParametersUpdated(_votingPeriod, _proposalThresholdBps, _quorumBps);
}
function mintFor(
address _address,
uint256 _amount
) public onlyMasterchef returns (bool) {
_mint(_address, _amount);
return true;
}
function addWhitelist(address account) external onlyOwner {
isWhitelisted[account] = true;
}
function removeWhitelist(address account) external onlyOwner {
isWhitelisted[account] = false;
}
function updateStakingRewards(address _stakingRewards) external onlyOwner {
stakingRewards = _stakingRewards;
}
function updateStakeThreshold(uint256 _amount) external onlyOwner {
stakeThreshold = _amount;
}
function updateSwapThreshold(uint256 _amount) external onlyOwner {
swapThreshold = _amount;
}
}
/
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (utils/Strings.sol)
pragma solidity ^0.8.0;
import "./math/Math.sol";
import "./math/SignedMath.sol";
/**
* @dev String operations.
*/
library Strings {
bytes16 private constant _SYMBOLS = "0123456789abcdef";
uint8 private constant _ADDRESS_LENGTH = 20;
/**
* @dev Converts a `uint256` to its ASCII `string` decimal representation.
*/
function toString(uint256 value) internal pure returns (string memory) {
unchecked {
uint256 length = Math.log10(value) + 1;
string memory buffer = new string(length);
uint256 ptr;
/// @solidity memory-safe-assembly
assembly {
ptr := add(buffer, add(32, length))
}
while (true) {
ptr--;
/// @solidity memory-safe-assembly
assembly {
mstore8(ptr, byte(mod(value, 10), _SYMBOLS))
}
value /= 10;
if (value == 0) break;
}
return buffer;
}
}
/**
* @dev Converts a `int256` to its ASCII `string` decimal representation.
*/
function toString(int256 value) internal pure returns (string memory) {
return string(abi.encodePacked(value < 0 ? "-" : "", toString(SignedMath.abs(value))));
}
/**
* @dev Converts a `uint256` to its ASCII `string` hexadecimal representation.
*/
function toHexString(uint256 value) internal pure returns (string memory) {
unchecked {
return toHexString(value, Math.log256(value) + 1);
}
}
/**
* @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length.
*/
function toHexString(uint256 value, uint256 length) internal pure returns (string memory) {
bytes memory buffer = new bytes(2 * length + 2);
buffer[0] = "0";
buffer[1] = "x";
for (uint256 i = 2 * length + 1; i > 1; --i) {
buffer[i] = _SYMBOLS[value & 0xf];
value >>= 4;
}
require(value == 0, "Strings: hex length insufficient");
return string(buffer);
}
/**
* @dev Converts an `address` with fixed length of 20 bytes to its not checksummed ASCII `string` hexadecimal representation.
*/
function toHexString(address addr) internal pure returns (string memory) {
return toHexString(uint256(uint160(addr)), _ADDRESS_LENGTH);
}
/**
* @dev Returns true if the two strings are equal.
*/
function equal(string memory a, string memory b) internal pure returns (bool) {
return keccak256(bytes(a)) == keccak256(bytes(b));
}
}
/
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (interfaces/IERC4906.sol)
pragma solidity ^0.8.0;
import "./IERC165.sol";
import "./IERC721.sol";
/// @title EIP-721 Metadata Update Extension
interface IERC4906 is IERC165, IERC721 {
/// @dev This event emits when the metadata of a token is changed.
/// So that the third-party platforms such as NFT market could
/// timely update the images and related attributes of the NFT.
event MetadataUpdate(uint256 _tokenId);
/// @dev This event emits when the metadata of a range of tokens is changed.
/// So that the third-party platforms such as NFT market could
/// timely update the images and related attributes of the NFTs.
event BatchMetadataUpdate(uint256 _fromTokenId, uint256 _toTokenId);
}
/
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (interfaces/IERC165.sol)
pragma solidity ^0.8.0;
import "../utils/introspection/IERC165.sol";
/
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
interface IERC20 {
event Approval(address, address, uint256);
event Transfer(address, address, uint256);
function name() external view returns (string memory);
function decimals() external view returns (uint8);
function transferFrom(
address,
address,
uint256
) external returns (bool);
function allowance(address, address) external view returns (uint256);
function approve(address, uint256) external returns (bool);
function transfer(address, uint256) external returns (bool);
function balanceOf(address) external view returns (uint256);
function nonces(address) external view returns (uint256); // Only tokens that support permit
function permit(
address,
address,
uint256,
uint256,
uint8,
bytes32,
bytes32
) external; // Only tokens that support permit
function swap(address, uint256) external; // Only Avalanche bridge tokens
function swapSupply(address) external view returns (uint256); // Only Avalanche bridge tokens
function totalSupply() external view returns (uint256);
}
/
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
import "./interfaces/IEMISSIONS.sol";
import "./interfaces/IUniswapV2Router02.sol";
import "./interfaces/IPair.sol";
import "./interfaces/IWPLS.sol";
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
contract Zapper is Ownable {
using SafeERC20 for IERC20;
IEMISSIONS public emissionsContract;
IUniswapV2Router02 public router;
IWPLS public wpls;
address public pulseXv2 = address(0x165C3410fC91EF562C50559f7d2289fEbed552d9);
address public wplsAddress = address(0xA1077a294dDE1B09bB078844df40758a5D0f9a27);
address public feeAddress = address(0xC96399730784acD98Bb42B51397Ed5fF71BaE0ae);
event Zap(uint256 poolId, uint256 amountPLS, uint256 amountLPAdded);
constructor(address _emissions) {
emissionsContract = IEMISSIONS(_emissions);
router = IUniswapV2Router02(pulseXv2);
wpls = IWPLS(wplsAddress);
}
function zap(uint256 poolId) external payable {
require(msg.value > 0, "Zapper: No PLS provided");
IEMISSIONS.PoolView memory poolView = emissionsContract.getPoolView(
poolId
);
address lpTokenAddress = poolView.token;
require(lpTokenAddress != address(0), "Zapper: Invalid pool");
IPair lpPair = IPair(lpTokenAddress);
address token0 = lpPair.token0();
address token1 = lpPair.token1();
IERC20(token0).approve(address(router), type(uint256).max);
IERC20(token1).approve(address(router), type(uint256).max);
uint256 amountPLS = msg.value;
wpls.deposit{value: amountPLS}();
uint256 halfAmountWPLS = amountPLS / 2;
address[] memory wplsToToken0Path = new address[](2);
wplsToToken0Path[0] = wplsAddress;
wplsToToken0Path[1] = token0;
address[] memory wplsToToken1Path = new address[](2);
wplsToToken1Path[0] = wplsAddress;
wplsToToken1Path[1] = token1;
if (token0 == wplsAddress) {
router.swapExactTokensForTokensSupportingFeeOnTransferTokens(halfAmountWPLS, 0, wplsToToken1Path, address(this), block.timestamp + 120);
} else if (token1 == wplsAddress) {
router.swapExactTokensForTokensSupportingFeeOnTransferTokens(halfAmountWPLS, 0, wplsToToken0Path, address(this), block.timestamp + 120);
} else {
router.swapExactTokensForTokensSupportingFeeOnTransferTokens(halfAmountWPLS, 0, wplsToToken0Path, address(this), block.timestamp + 120);
router.swapExactTokensForTokensSupportingFeeOnTransferTokens(halfAmountWPLS, 0, wplsToToken1Path, address(this), block.timestamp + 120);
}
uint256 balanceToken0 = IERC20(token0).balanceOf(address(this));
uint256 balanceToken1 = IERC20(token1).balanceOf(address(this));
uint256 previousBalanceLPinSystem = IERC20(lpTokenAddress).balanceOf(address(this));
(,, uint256 amountLP) = router.addLiquidity(token0, token1, balanceToken0, balanceToken1, 0, 0, address(this), block.timestamp + 120);
uint256 newBalanceLPinSystem = IERC20(lpTokenAddress).balanceOf(address(this));
uint256 amountLPAdded = newBalanceLPinSystem - previousBalanceLPinSystem;
IERC20(lpTokenAddress).approve(address(emissionsContract), amountLPAdded);
emissionsContract.depositOnBehalfOf(poolId, amountLPAdded, feeAddress, msg.sender);
emit Zap(poolId, amountPLS, amountLPAdded);
}
function emergencyWithdrawERC20(address token, uint256 amount) external onlyOwner {
IERC20(token).safeTransfer(msg.sender, amount);
}
function emergencyWithdrawPLS() external onlyOwner {
wpls.withdraw(wpls.balanceOf(address(this)));
}
}
/
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
contract VotingToken is ERC20, Ownable {
address public stakingRewards;
constructor() ERC20("Voting TRU", "vTRU") {}
function setStakingRewards(address _stakingRewards) external onlyOwner {
stakingRewards = _stakingRewards;
}
function mint(address to, uint256 amount) external {
require(msg.sender == stakingRewards, "Only stakingRewards can mint");
_mint(to, amount);
}
function burn(address from, uint256 amount) external {
require(msg.sender == stakingRewards, "Only stakingRewards can burn");
_burn(from, amount);
}
function _beforeTokenTransfer(
address from,
address to,
uint256 amount
) internal override {
require(from == address(0) || to == address(0), "vTRU is non-transferable");
super._beforeTokenTransfer(from, to, amount);
}
}
/
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
import "@openzeppelin/contracts/utils/math/Math.sol";
import "@openzeppelin/contracts/token/ERC721/extensions/IERC721Enumerable.sol";
import "@openzeppelin/contracts/security/ReentrancyGuard.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/security/Pausable.sol";
import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import "@openzeppelin/contracts/utils/math/SafeMath.sol";
import "./interfaces/IUniswapV2Router02.sol";
import "./interfaces/IWPLS.sol";
import "./interfaces/IVotingToken.sol";
contract StakingRewards is ReentrancyGuard, Ownable, Pausable {
using SafeMath for uint256;
using SafeERC20 for IERC20;
/* ========== STATE VARIABLES ========== */
IERC20 public rewardsToken;
IERC20 public stakingToken;
IVotingToken public votingToken;
uint256 public periodFinish = 0;
uint256 public rewardRate = 0;
uint256 public rewardsDuration = 7 days;
uint256 public lastUpdateTime;
uint256 public rewardPerTokenStored;
IUniswapV2Router02 public router;
mapping(address => uint256) public userRewardPerTokenPaid;
mapping(address => uint256) public rewards;
uint256 private _totalSupply;
mapping(address => uint256) private _balances;
/* ========== CONSTRUCTOR ========== */
constructor(
address _rewardsToken,
address _stakingToken,
address _votingToken
) {
rewardsToken = IERC20(_rewardsToken);
stakingToken = IERC20(_stakingToken);
votingToken = IVotingToken(_votingToken);
router = IUniswapV2Router02(0x165C3410fC91EF562C50559f7d2289fEbed552d9);
}
/* ========== VIEWS ========== */
function totalSupply() external view returns (uint256) {
return _totalSupply;
}
function balanceOf(address account) external view returns (uint256) {
return _balances[account];
}
function lastTimeRewardApplicable() public view returns (uint256) {
return Math.min(block.timestamp, periodFinish);
}
function checkPeriodFinish() public view returns (bool) {
return block.timestamp > periodFinish;
}
function rewardPerToken() public view returns (uint256) {
if (_totalSupply == 0) {
return rewardPerTokenStored;
}
return
rewardPerTokenStored.add(
lastTimeRewardApplicable()
.sub(lastUpdateTime)
.mul(rewardRate)
.mul(1e18)
.div(_totalSupply)
);
}
function earned(address account) public view returns (uint256) {
return
_balances[account]
.mul(rewardPerToken().sub(userRewardPerTokenPaid[account]))
.div(1e18)
.add(rewards[account]);
}
function getRewardForDuration() external view returns (uint256) {
return rewardRate.mul(rewardsDuration);
}
/* ========== MUTATIVE FUNCTIONS ========== */
function stake(uint256 amount) external nonReentrant whenNotPaused updateReward(msg.sender) {
require(amount > 0, "Cannot stake 0");
_totalSupply = _totalSupply.add(amount);
_balances[msg.sender] = _balances[msg.sender].add(amount);
stakingToken.safeTransferFrom(msg.sender, address(this), amount);
votingToken.mint(msg.sender, amount);
emit Staked(msg.sender, amount);
}
function withdraw(uint256 amount) public nonReentrant updateReward(msg.sender) {
require(amount > 0, "Cannot withdraw 0");
_totalSupply = _totalSupply.sub(amount);
_balances[msg.sender] = _balances[msg.sender].sub(amount);
stakingToken.safeTransfer(msg.sender, amount);
votingToken.burn(msg.sender, amount);
emit Withdrawn(msg.sender, amount);
}
function getReward() public nonReentrant updateReward(msg.sender) {
uint256 reward = rewards[msg.sender];
if (reward > 0) {
rewards[msg.sender] = 0;
rewardsToken.safeTransfer(msg.sender, reward);
emit RewardPaid(msg.sender, reward);
}
}
function exit() external {
withdraw(_balances[msg.sender]);
getReward();
}
function topUp() external payable {
uint256 amountToSpend = msg.value;
uint256 balanceBefore = rewardsToken.balanceOf(address(this));
address[] memory path = new address[](2);
path[0] = router.WPLS();
path[1] = address(rewardsToken);
router.swapExactETHForTokens{value: amountToSpend}(
0,
path,
address(this),
block.timestamp
);
uint256 balanceAfter = rewardsToken.balanceOf(address(this));
uint256 rewardAmount = balanceAfter - balanceBefore;
if (rewardAmount > 0) {
notifyRewardAmount(rewardAmount);
}
}
function notifyRewardAmount(uint256 reward) internal updateReward(address(0)) {
if (block.timestamp >= periodFinish) {
rewardRate = reward.div(rewardsDuration);
} else {
uint256 remaining = periodFinish.sub(block.timestamp);
uint256 leftover = remaining.mul(rewardRate);
rewardRate = reward.add(leftover).div(rewardsDuration);
}
uint256 balance = rewardsToken.balanceOf(address(this));
require(rewardRate <= balance.div(rewardsDuration), "Provided reward too high");
lastUpdateTime = block.timestamp;
periodFinish = block.timestamp.add(rewardsDuration);
emit RewardAdded(reward);
}
/* ========== RESTRICTED FUNCTIONS ========== */
function recoverERC20(address tokenAddress, uint256 tokenAmount) external onlyOwner {
require(tokenAddress != address(stakingToken) && tokenAddress != address(rewardsToken), "Cannot withdraw the staking or rewards tokens");
IERC20(tokenAddress).safeTransfer(owner(), tokenAmount);
emit Recovered(tokenAddress, tokenAmount);
}
function updatePeriodFinish(uint timestamp) external onlyOwner updateReward(address(0)) {
periodFinish = timestamp;
}
function setRewardsDuration(uint256 _rewardsDuration) external onlyOwner {
require(block.timestamp > periodFinish,"Previous rewards period must be complete before changing the duration for the new period");
rewardsDuration = _rewardsDuration;
emit RewardsDurationUpdated(rewardsDuration);
}
function setVotingToken(address _votingToken) external onlyOwner {
votingToken = IVotingToken(_votingToken);
}
/* ========== MODIFIERS ========== */
modifier updateReward(address account) {
rewardPerTokenStored = rewardPerToken();
lastUpdateTime = lastTimeRewardApplicable();
if (account != address(0)) {
rewards[account] = earned(account);
userRewardPerTokenPaid[account] = rewardPerTokenStored;
}
_;
}
/* ========== EVENTS ========== */
event RewardAdded(uint256 reward);
event Staked(address indexed user, uint256 amount);
event Withdrawn(address indexed user, uint256 amount);
event RewardPaid(address indexed user, uint256 reward);
event RewardsDurationUpdated(uint256 newDuration);
event Recovered(address token, uint256 amount);
}
/
// SPDX-License-Identifier: MIT
pragma solidity 0.8.20;
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
interface IEMISSIONS {
// ========= Structs =========
struct PoolView {
uint256 pid;
address token;
uint256 allocPoint;
uint256 lastRewardTime;
uint16 depositFeeBP;
uint16 withdrawFeeBP;
uint256 accTokensPerShare;
bool isStarted;
uint256 lpBalance;
uint256 rewardsPerSecond;
}
struct UserView {
uint256 pid;
uint256 stakedAmount;
uint256 unclaimedRewards;
uint256 lpBalance;
uint256 allowance;
}
// ========= Events =========
event Deposit(address indexed user, uint256 indexed pid, uint256 amount);
event Withdraw(address indexed user, uint256 indexed pid, uint256 amount);
event EmergencyWithdraw(address indexed user, uint256 indexed pid, uint256 amount);
event RewardPaid(address indexed user, uint256 amount);
// ========= Public state getters =========
// poolInfo(uint256)
function poolInfo(uint256)
external
view
returns (
IERC20 token,
uint256 allocPoint,
uint256 lastRewardTime,
uint16 depositFeeBP,
uint16 withdrawFeeBP,
uint256 accTokensPerShare,
bool isStarted,
uint256 lpBalance
);
// userInfo(pid, user)
function userInfo(uint256, address)
external
view
returns (uint256 amount, uint256 rewardDebt);
function totalAllocPoint() external view returns (uint256);
function startTime() external view returns (uint256);
function feeAddress() external view returns (address);
function devAddress() external view returns (address);
function feePercent() external view returns (uint256);
function devPercent() external view returns (uint256);
function rewardsPerSec() external view returns (uint256);
function referralRate() external view returns (uint256);
function referral(address) external view returns (address referrer);
function referralEarned(address) external view returns (uint256 amount);
function emittersNft() external view returns (address);
// Ownable (commonly useful; inherited)
function owner() external view returns (address);
// ========= Views / pure =========
function poolLength() external view returns (uint256);
function getMultiplier(uint256 _from, uint256 _to) external view returns (uint256);
function pendingShare(uint256 _pid, address _user) external view returns (uint256);
function getPoolView(uint256 pid) external view returns (PoolView memory);
function getAllPoolViews() external view returns (PoolView[] memory);
function getUserView(uint256 pid, address account) external view returns (UserView memory);
function getUserViews(address account) external view returns (UserView[] memory);
// ========= Admin (onlyOwner in implementation) =========
function add(
uint256 _allocPoint,
IERC20 _token,
bool _withUpdate,
uint256 _lastRewardTime,
uint16 _depositFeeBP,
uint16 _withdrawFeeBP
) external;
function set(
uint256 _pid,
uint256 _allocPoint,
uint16 _depositFeeBP,
uint16 _withdrawFeeBP
) external;
function massUpdatePools() external;
function updatePool(uint256 _pid) external;
function setFeeAddress(address _feeAddress) external;
function setFeePercent(uint256 _feePercent) external;
function setDevAddress(address _devAddress) external;
function setDevPercent(uint256 _devPercent) external;
function setReferralRate(uint256 _referralRate) external;
function updateEmissionRate(uint256 _rewardsPerSec) external;
// ========= User actions =========
function deposit(uint256 _pid, uint256 _amount, address _referrer) external;
function depositOnBehalfOf(uint256 _pid, uint256 _amount, address _referrer, address _staker) external;
function withdraw(uint256 _pid, uint256 _amount) external;
function emergencyWithdraw(uint256 _pid) external;
}
/
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
import "@openzeppelin/contracts/token/ERC721/extensions/ERC721Enumerable.sol";
import "@openzeppelin/contracts/token/ERC721/extensions/ERC721URIStorage.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/utils/Counters.sol";
import '@openzeppelin/contracts/security/ReentrancyGuard.sol';
contract NFT is ERC721, ERC721Enumerable, ERC721URIStorage, Ownable, ReentrancyGuard {
using Counters for Counters.Counter;
using Strings for uint256;
Counters.Counter private _tokenIdCounter;
string public uri = 'ipfs://bafybeibw3bgwl2nh4dkemide3g6ejb5lr2fyfkpynlmcgydxc5ccpeplju/data.json';
uint256 public cost = 1_000_000 ether;
uint256 public maxSupply = 1000;
uint256 public maxMintAmountPerTx = 10;
uint256 public preMint = 100;
bool public paused = true;
bool public initialized = false;
constructor() ERC721("TruFarm Membership Card", "TruFarm Membership Card") {
}
modifier mintCompliance(uint256 _mintAmount) {
require(_mintAmount > 0 && _mintAmount <= maxMintAmountPerTx, 'Invalid mint amount!');
require(totalSupply() + _mintAmount <= maxSupply, 'Max supply exceeded!');
_;
}
modifier mintPriceCompliance(uint256 _mintAmount) {
require(msg.value >= cost * _mintAmount, 'Insufficient funds!');
_;
}
function setCost(uint256 _cost) public onlyOwner {
cost = _cost;
}
function setPaused(bool _paused) public onlyOwner {
paused = _paused;
}
function init() public onlyOwner {
if (!initialized) {
for(uint i = 0;i<preMint;i++) {
uint256 tokenId = _tokenIdCounter.current();
_tokenIdCounter.increment();
_safeMint(owner(), tokenId);
}
}
initialized = true;
paused = false;
}
function mint(uint256 _mintAmount) public payable mintCompliance(_mintAmount) mintPriceCompliance(_mintAmount) {
require(!paused, 'The contract is paused!');
for(uint i = 0;i<_mintAmount;i++) {
uint256 tokenId = _tokenIdCounter.current();
_tokenIdCounter.increment();
_safeMint(_msgSender(), tokenId);
}
}
// The following functions are overrides required by Solidity.
function _beforeTokenTransfer(address from, address to, uint256 tokenId, uint256 batchSize)
internal
override(ERC721, ERC721Enumerable)
{
super._beforeTokenTransfer(from, to, tokenId, batchSize);
}
function _burn(uint256 tokenId) internal override(ERC721, ERC721URIStorage) {
super._burn(tokenId);
}
function tokenURI(uint256 _tokenId) public view virtual override(ERC721, ERC721URIStorage) returns (string memory) {
require(_exists(_tokenId), 'ERC721Metadata: URI query for nonexistent token');
return _baseURI();
}
function setUri(string memory _uri) public onlyOwner {
uri = _uri;
}
function _baseURI() internal view virtual override returns (string memory) {
return uri;
}
function withdraw() public onlyOwner nonReentrant {
(bool os, ) = payable(owner()).call{value: address(this).balance}('');
require(os);
}
function supportsInterface(bytes4 interfaceId)
public
view
override(ERC721, ERC721Enumerable, ERC721URIStorage)
returns (bool)
{
return super.supportsInterface(interfaceId);
}
}
/
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
interface IWPLS {
function deposit() external payable;
function withdraw(uint wad) external;
function transfer(address dst, uint wad) external returns (bool);
function transferFrom(address src, address dst, uint wad) external returns (bool);
function approve(address usr, uint wad) external returns (bool);
function allowance(address, address) external view returns (uint);
function balanceOf(address) external view returns (uint);
}
/
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
interface IVotingToken {
function mint(address to, uint256 amount) external;
function burn(address from, uint256 amount) external;
function balanceOf(address account) external view returns (uint256);
function totalSupply() external view returns (uint256);
}
/
/*
* SPDX-License-Identifier: MIT
*/
pragma solidity >=0.6.2;
import './IUniswapV2Router01.sol';
interface IUniswapV2Router02 is IUniswapV2Router01 {
function removeLiquidityETHSupportingFeeOnTransferTokens(
address token,
uint liquidity,
uint amountTokenMin,
uint amountETHMin,
address to,
uint deadline
) external returns (uint amountETH);
function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens(
address token,
uint liquidity,
uint amountTokenMin,
uint amountETHMin,
address to,
uint deadline,
bool approveMax, uint8 v, bytes32 r, bytes32 s
) external returns (uint amountETH);
function swapExactTokensForTokensSupportingFeeOnTransferTokens(
uint amountIn,
uint amountOutMin,
address[] calldata path,
address to,
uint deadline
) external;
function swapExactETHForTokensSupportingFeeOnTransferTokens(
uint amountOutMin,
address[] calldata path,
address to,
uint deadline
) external payable;
function swapExactTokensForETHSupportingFeeOnTransferTokens(
uint amountIn,
uint amountOutMin,
address[] calldata path,
address to,
uint deadline
) external;
}
/
/*
* SPDX-License-Identifier: MIT
*/
pragma solidity >=0.6.2;
interface IUniswapV2Router01 {
function factory() external pure returns (address);
// function WETH() external pure returns (address);
function WPLS() external pure returns (address);
function addLiquidity(
address tokenA,
address tokenB,
uint amountADesired,
uint amountBDesired,
uint amountAMin,
uint amountBMin,
address to,
uint deadline
) external returns (uint amountA, uint amountB, uint liquidity);
function addLiquidityETH(
address token,
uint amountTokenDesired,
uint amountTokenMin,
uint amountETHMin,
address to,
uint deadline
) external payable returns (uint amountToken, uint amountETH, uint liquidity);
function removeLiquidity(
address tokenA,
address tokenB,
uint liquidity,
uint amountAMin,
uint amountBMin,
address to,
uint deadline
) external returns (uint amountA, uint amountB);
function removeLiquidityETH(
address token,
uint liquidity,
uint amountTokenMin,
uint amountETHMin,
address to,
uint deadline
) external returns (uint amountToken, uint amountETH);
function removeLiquidityWithPermit(
address tokenA,
address tokenB,
uint liquidity,
uint amountAMin,
uint amountBMin,
address to,
uint deadline,
bool approveMax, uint8 v, bytes32 r, bytes32 s
) external returns (uint amountA, uint amountB);
function removeLiquidityETHWithPermit(
address token,
uint liquidity,
uint amountTokenMin,
uint amountETHMin,
address to,
uint deadline,
bool approveMax, uint8 v, bytes32 r, bytes32 s
) external returns (uint amountToken, uint amountETH);
function swapExactTokensForTokens(
uint amountIn,
uint amountOutMin,
address[] calldata path,
address to,
uint deadline
) external returns (uint[] memory amounts);
function swapTokensForExactTokens(
uint amountOut,
uint amountInMax,
address[] calldata path,
address to,
uint deadline
) external returns (uint[] memory amounts);
function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline)
external
payable
returns (uint[] memory amounts);
function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline)
external
returns (uint[] memory amounts);
function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline)
external
returns (uint[] memory amounts);
function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline)
external
payable
returns (uint[] memory amounts);
function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB);
function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut);
function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external pure returns (uint amountIn);
function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts);
function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts);
}
/
/*
* SPDX-License-Identifier: MIT
*/
pragma solidity >=0.5.0;
interface IUniswapV2Pair {
event Approval(address indexed owner, address indexed spender, uint value);
event Transfer(address indexed from, address indexed to, uint value);
function name() external pure returns (string memory);
function symbol() external pure returns (string memory);
function decimals() external pure returns (uint8);
function totalSupply() external view returns (uint);
function balanceOf(address owner) external view returns (uint);
function allowance(address owner, address spender) external view returns (uint);
function approve(address spender, uint value) external returns (bool);
function transfer(address to, uint value) external returns (bool);
function transferFrom(address from, address to, uint value) external returns (bool);
function DOMAIN_SEPARATOR() external view returns (bytes32);
function PERMIT_TYPEHASH() external pure returns (bytes32);
function nonces(address owner) external view returns (uint);
function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external;
event Mint(address indexed sender, uint amount0, uint amount1);
event Burn(address indexed sender, uint amount0, uint amount1, address indexed to);
event Swap(
address indexed sender,
uint amount0In,
uint amount1In,
uint amount0Out,
uint amount1Out,
address indexed to
);
event Sync(uint112 reserve0, uint112 reserve1);
function MINIMUM_LIQUIDITY() external pure returns (uint);
function factory() external view returns (address);
function token0() external view returns (address);
function token1() external view returns (address);
function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast);
function price0CumulativeLast() external view returns (uint);
function price1CumulativeLast() external view returns (uint);
function kLast() external view returns (uint);
function mint(address to) external returns (uint liquidity);
function burn(address to) external returns (uint amount0, uint amount1);
function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external;
function skim(address to) external;
function sync() external;
function initialize(address, address) external;
}
/
/*
* SPDX-License-Identifier: MIT
*/
pragma solidity >=0.5.0;
interface IUniswapV2Factory {
event PairCreated(address indexed token0, address indexed token1, address pair, uint);
function feeTo() external view returns (address);
function feeToSetter() external view returns (address);
function getPair(address tokenA, address tokenB) external view returns (address pair);
function allPairs(uint) external view returns (address pair);
function allPairsLength() external view returns (uint);
function createPair(address tokenA, address tokenB) external returns (address pair);
function setFeeTo(address) external;
function setFeeToSetter(address) external;
}
/
// SPDX-License-Identifier: MIT
pragma solidity 0.8.20;
interface IStakingRewards {
function periodFinish() external view returns(uint256);
function notifyRewardAmount(uint256) external;
function topUp() external payable;
function owner() external view returns(address);
function transferOwnership(address) external;
}
/
// SPDX-License-Identifier: MIT
pragma solidity 0.8.20;
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
interface IRewardToken is IERC20 {
function mintFor(address _address, uint256 _amount) external returns (bool);
function safeTokenTransfer(address _to, uint256 _amount) external;
}
/
// SPDX-License-Identifier: MIT
pragma solidity 0.8.20;
interface IPair {
function token0() external view returns (address);
function token1() external view returns (address);
}
/
// SPDX-License-Identifier: MIT
pragma solidity 0.8.20;
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "@openzeppelin/contracts/token/ERC721/IERC721.sol";
import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import "@openzeppelin/contracts/utils/math/SafeMath.sol";
import "@openzeppelin/contracts/security/ReentrancyGuard.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/utils/structs/EnumerableSet.sol";
import "@openzeppelin/contracts/utils/Address.sol";
import "@openzeppelin/contracts/utils/Multicall.sol";
// Import interfaces
import "./interfaces/IRewardToken.sol";
import "./interfaces/IPair.sol";
contract Emissions is ReentrancyGuard, Ownable, Multicall {
using SafeMath for uint256;
using SafeERC20 for IERC20;
using SafeERC20 for IRewardToken;
using EnumerableSet for EnumerableSet.AddressSet;
// Info of each user.
struct UserInfo {
uint256 amount; // How many LP tokens the user has provided.
uint256 rewardDebt; // Reward debt. See explanation below.
}
// Info of each pool.
struct PoolInfo {
IERC20 token; // Address of LP token contract.
uint256 allocPoint; // How many allocation points assigned to this pool. rewardToken to distribute per block.
uint256 lastRewardTime; // Last time that rewardToken distribution occurs.
uint16 depositFeeBP; //depositfee
uint16 withdrawFeeBP; //withdrawfee
uint256 accTokensPerShare; // Accumulated rewardToken per share, times 1e18. See below.
bool isStarted; // if lastRewardTime has passed
uint256 lpBalance;
}
struct PoolView {
uint256 pid;
address token;
uint256 allocPoint;
uint256 lastRewardTime;
uint16 depositFeeBP;
uint16 withdrawFeeBP;
uint256 accTokensPerShare;
bool isStarted;
uint256 lpBalance;
uint256 rewardsPerSecond;
}
struct UserView {
uint256 pid;
uint256 stakedAmount;
uint256 unclaimedRewards;
uint256 lpBalance;
uint256 allowance;
}
IRewardToken public rewardToken;
// Info of each pool.W
PoolInfo[] public poolInfo;
EnumerableSet.AddressSet private lpTokens;
// Info of each user that stakes LP tokens.
mapping(uint256 => mapping(address => UserInfo)) public userInfo;
// Total allocation points. Must be the sum of all allocation points in all pools.
uint256 public totalAllocPoint = 0;
// The time when rewardToken mining starts.
uint256 public startTime;
address public feeAddress;
address public devAddress;
uint256 public feePercent;
uint256 public devPercent;
uint256 public rewardsPerSec;
uint256 public constant MAX_REWARDS_PER_SEC = 25 ether;
uint256 public referralRate = 500;
mapping(address => address) public referral; // referral => referrer
mapping(address => uint256) public referralEarned; // for stats
address public nftAddress;
event Deposit(address indexed user, uint256 indexed pid, uint256 amount);
event Withdraw(address indexed user, uint256 indexed pid, uint256 amount);
event EmergencyWithdraw(
address indexed user,
uint256 indexed pid,
uint256 amount
);
event RewardPaid(address indexed user, uint256 amount);
constructor(
IRewardToken _rewardToken,
address _feeAddress,
address _devAddress,
uint256 _feePercent,
uint256 _devPercent,
uint256 _rewardsPerSec,
uint256 _startTime,
address _nftAddress
) {
require(_rewardsPerSec <= MAX_REWARDS_PER_SEC, "too high");
require(block.timestamp < _startTime, "EMISSIONS: late");
require(
_feeAddress != address(0) &&
_devAddress != address(0) &&
address(_rewardToken) != address(0),
"EMISSIONS: Zero address not allowed"
);
require(
_devPercent <= 1000 && _feePercent <= 1000,
"EMISSIONS: Invalid percentages"
);
rewardToken = _rewardToken;
feeAddress = _feeAddress;
devAddress = _devAddress;
feePercent = _feePercent;
devPercent = _devPercent;
rewardsPerSec = _rewardsPerSec;
startTime = _startTime;
nftAddress = _nftAddress;
}
function poolLength() external view returns (uint256) {
return poolInfo.length;
}
// Add a new lp to the pool
function add(
uint256 _allocPoint,
IERC20 _token,
bool _withUpdate,
uint256 _lastRewardTime,
uint16 _depositFeeBP,
uint16 _withdrawFeeBP
) external onlyOwner {
IPair pool_lp = IPair(address(_token));
IERC20 token0 = IERC20(pool_lp.token0());
IERC20 token1 = IERC20(pool_lp.token1());
require(
address(token0) != address(0) && address(token1) != address(0),
"EMISSIONS: Only LP tokens "
);
require(
Address.isContract(address(_token)),
"EMISSIONS: LP token must be a valid contract"
);
require(
_depositFeeBP <= 400 && _withdrawFeeBP <= 400,
"EMISSIONS: Invalid deposit or withdraw fee basis points"
);
require(
!lpTokens.contains(address(_token)),
"EMISSIONS: LP already added"
);
if (_withUpdate) {
massUpdatePools();
}
if (block.timestamp < startTime) {
// chef is sleeping
if (_lastRewardTime < startTime) {
_lastRewardTime = startTime;
}
} else {
// chef is cooking
if (_lastRewardTime < block.timestamp) {
_lastRewardTime = block.timestamp;
}
}
bool _isStarted = (block.timestamp >= startTime) &&
(block.timestamp >= _lastRewardTime);
poolInfo.push(
PoolInfo({
token: _token,
allocPoint: _allocPoint,
lastRewardTime: _lastRewardTime,
accTokensPerShare: 0,
isStarted: _isStarted,
depositFeeBP: _depositFeeBP,
withdrawFeeBP: _withdrawFeeBP,
lpBalance: 0
})
);
if (_isStarted) {
totalAllocPoint = totalAllocPoint.add(_allocPoint);
}
lpTokens.add(address(_token));
}
// Update the given pool's allocation point. Can only be called by the owner.
function set(
uint256 _pid,
uint256 _allocPoint,
uint16 _depositFeeBP,
uint16 _withdrawFeeBP
) external onlyOwner {
require(
_depositFeeBP <= 400 && _withdrawFeeBP <= 400,
"EMISSIONS: Invalid deposit or withdraw fee basis points"
);
massUpdatePools();
PoolInfo storage pool = poolInfo[_pid];
if (pool.isStarted) {
totalAllocPoint = totalAllocPoint.sub(pool.allocPoint).add(
_allocPoint
);
}
pool.allocPoint = _allocPoint;
poolInfo[_pid].depositFeeBP = _depositFeeBP;
poolInfo[_pid].withdrawFeeBP = _withdrawFeeBP;
}
// Return accumulate rewards over the given _from to _to block.
function getMultiplier(
uint256 _from,
uint256 _to
) public view returns (uint256) {
if (_from >= _to) return 0;
if (_to <= startTime) return 0;
if (_from >= startTime) {
return _to.sub(_from);
} else {
return _to.sub(startTime);
}
}
// View function to see pending rewards
function pendingShare(
uint256 _pid,
address _user
) public view returns (uint256) {
PoolInfo storage pool = poolInfo[_pid];
UserInfo storage user = userInfo[_pid][_user];
uint256 accTokensPerShare = pool.accTokensPerShare;
uint256 tokenSupply = pool.lpBalance;
if (block.timestamp > pool.lastRewardTime && tokenSupply != 0) {
uint256 multiplier = getMultiplier(
pool.lastRewardTime,
block.timestamp
);
uint256 lpPercent = 10000 - devPercent - feePercent;
uint256 _generatedReward = multiplier.mul(rewardsPerSec);
uint256 _rewards = _generatedReward
.mul(pool.allocPoint)
.div(totalAllocPoint)
.mul(lpPercent)
.div(10000);
accTokensPerShare = accTokensPerShare.add(
_rewards.mul(1e18).div(tokenSupply)
);
}
return
user.amount.mul(accTokensPerShare).div(1e18).sub(user.rewardDebt);
}
// Update reward variables for all pools. Be careful of gas spending!
function massUpdatePools() public {
uint256 length = poolInfo.length;
for (uint256 pid = 0; pid < length; ++pid) {
updatePool(pid);
}
}
// Update reward variables of the given pool to be up-to-date.
function updatePool(uint256 _pid) public {
PoolInfo storage pool = poolInfo[_pid];
if (block.timestamp <= pool.lastRewardTime) {
return;
}
if (!pool.isStarted) {
pool.isStarted = true;
totalAllocPoint = totalAllocPoint.add(pool.allocPoint);
}
uint256 tokenSupply = pool.lpBalance;
if (tokenSupply == 0) {
pool.lastRewardTime = block.timestamp;
return;
}
if (totalAllocPoint > 0) {
uint256 multiplier = getMultiplier(
pool.lastRewardTime,
block.timestamp
);
uint256 _generatedReward = multiplier.mul(rewardsPerSec);
uint256 _rewards = _generatedReward
.mul(pool.allocPoint)
.div(totalAllocPoint);
uint256 lpPercent = 10000 - devPercent - feePercent;
rewardToken.mintFor(
devAddress,
_rewards.mul(devPercent).div(10000)
);
rewardToken.mintFor(
feeAddress,
_rewards.mul(feePercent).div(10000)
);
rewardToken.mintFor(
address(this),
_rewards.mul(lpPercent).div(10000) + _rewards.mul(referralRate).div(10000)
);
pool.accTokensPerShare = pool.accTokensPerShare.add(
_rewards.mul(1e18).div(tokenSupply).mul(lpPercent).div(
10000
)
);
}
pool.lastRewardTime = block.timestamp;
}
function deposit(
uint256 _pid,
uint256 _amount,
address _referrer
) external nonReentrant {
address staker = _msgSender();
_deposit(_pid, _amount, _referrer, staker);
}
function depositOnBehalfOf(
uint256 _pid,
uint256 _amount,
address _referrer,
address _staker
) external nonReentrant {
_deposit(_pid, _amount, _referrer, _staker);
}
function withdraw(uint256 _pid, uint256 _amount) external nonReentrant {
_withdraw(_pid, _amount);
}
function _deposit(
uint256 _pid,
uint256 _amount,
address _referrer,
address _staker
) private {
if (referral[_staker] == address(0)) {
require(
_referrer != address(0) &&
_referrer != _staker &&
_referrer != address(this),
"EMISSIONS: Invalid referrer"
);
referral[_staker] = _referrer;
} else {
_referrer = referral[_staker];
}
PoolInfo storage pool = poolInfo[_pid];
UserInfo storage user = userInfo[_pid][_staker];
updatePool(_pid);
if (user.amount > 0) {
uint256 _pending = user
.amount
.mul(pool.accTokensPerShare)
.div(1e18)
.sub(user.rewardDebt);
if (_pending > 0) {
uint256 referralAmount = ((_pending) * referralRate) / 10000;
if (referralAmount > 0) {
referralEarned[_referrer] =
referralEarned[_referrer] +
referralAmount;
safeRewardTransfer(_referrer, referralAmount);
}
safeRewardTransfer(_staker, _pending);
emit RewardPaid(_staker, _pending);
}
}
if (_amount > 0) {
pool.token.safeTransferFrom(_msgSender(), address(this), _amount);
}
bool hasNft = IERC721(nftAddress).balanceOf(_staker) > 0;
if (pool.depositFeeBP > 0 && !hasNft) {
uint256 depositFee = _amount.mul(pool.depositFeeBP).div(10000);
pool.token.safeTransfer(feeAddress, depositFee);
user.amount = user.amount.add(_amount).sub(depositFee);
pool.lpBalance = pool.lpBalance.add(_amount).sub(depositFee);
} else {
user.amount = user.amount.add(_amount);
pool.lpBalance = pool.lpBalance.add(_amount);
}
user.rewardDebt = user.amount.mul(pool.accTokensPerShare).div(1e18);
emit Deposit(_staker, _pid, _amount);
}
function _withdraw(uint256 _pid, uint256 _amount) private {
address _sender = _msgSender();
PoolInfo storage pool = poolInfo[_pid];
UserInfo storage user = userInfo[_pid][_sender];
require(
user.amount >= _amount,
"EMISSIONS: User amount too low"
);
updatePool(_pid);
address referrer = referral[_sender];
uint256 _pending = user
.amount
.mul(pool.accTokensPerShare)
.div(1e18)
.sub(user.rewardDebt);
if (_pending > 0) {
uint256 referralAmount = ((_pending) * referralRate) / 10000;
if (referralAmount > 0) {
referralEarned[referrer] =
referralEarned[referrer] +
referralAmount;
safeRewardTransfer(referrer, referralAmount);
}
safeRewardTransfer(_sender, _pending);
emit RewardPaid(_sender, _pending);
}
if (_amount > 0) {
user.amount = user.amount.sub(_amount);
bool hasNft = IERC721(nftAddress).balanceOf(_sender) > 0;
if (pool.withdrawFeeBP > 0 && !hasNft) {
uint256 withdrawFee = _amount.mul(pool.withdrawFeeBP).div(
10000
);
pool.token.safeTransfer(feeAddress, withdrawFee);
pool.token.safeTransfer(_sender, _amount.sub(withdrawFee));
} else {
pool.token.safeTransfer(_sender, _amount);
}
}
user.rewardDebt = user.amount.mul(pool.accTokensPerShare).div(1e18);
pool.lpBalance -= _amount;
emit Withdraw(_sender, _pid, _amount);
}
// Withdraw without caring about rewards. EMERGENCY ONLY.
function emergencyWithdraw(uint256 _pid) public nonReentrant {
PoolInfo storage pool = poolInfo[_pid];
UserInfo storage user = userInfo[_pid][_msgSender()];
uint256 _amount = user.amount;
require(_amount > 0, "EMISSIONS: User has no amount");
user.amount = 0;
user.rewardDebt = 0;
bool hasNft = IERC721(nftAddress).balanceOf(_msgSender()) > 0;
if (pool.withdrawFeeBP > 0 && !hasNft) {
uint256 withdrawFee = _amount.mul(pool.withdrawFeeBP).div(10000);
pool.token.safeTransfer(feeAddress, withdrawFee);
pool.token.safeTransfer(_msgSender(), _amount.sub(withdrawFee));
} else {
pool.token.safeTransfer(_msgSender(), _amount);
}
pool.lpBalance -= _amount;
emit EmergencyWithdraw(_msgSender(), _pid, _amount);
}
// Safe rewardToken transfer function, just in case if rounding error causes pool to not have enough rewardToken.
function safeRewardTransfer(address _to, uint256 _amount) internal {
uint256 _balance = rewardToken.balanceOf(address(this));
if (_balance > 0) {
if (_amount > _balance) {
rewardToken.safeTransfer(_to, _balance);
} else {
rewardToken.safeTransfer(_to, _amount);
}
}
}
function setFeeAddress(address _feeAddress) external onlyOwner {
require(
_feeAddress != address(0),
"EMISSIONS: Zero address not allowed"
);
feeAddress = _feeAddress;
}
function setFeePercent(uint256 _feePercent) external onlyOwner {
require(
_feePercent <= 1000,
"EMISSIONS: invalid fee"
);
feePercent = _feePercent;
}
function setDevAddress(address _devAddress) external onlyOwner {
require(
_devAddress != address(0),
"EMISSIONS: Invalid percentages"
);
devAddress = _devAddress;
}
function setDevPercent(uint256 _devPercent) external onlyOwner {
require(
_devPercent <= 1000,
"EMISSIONS: Zero address not allowed"
);
devPercent = _devPercent;
}
function setReferralRate(uint256 _referralRate) external onlyOwner {
require(_referralRate <= 500, "EMISSIONS: Too high");
referralRate = _referralRate;
}
function updateEmissionRate(uint256 _rewardsPerSec) public onlyOwner {
require(_rewardsPerSec <= MAX_REWARDS_PER_SEC, "too high");
massUpdatePools();
rewardsPerSec = _rewardsPerSec;
}
function updateNftAddress(address _nftAddress) public onlyOwner {
require(
_nftAddress != address(0),
"EMISSIONS: Zero address not allowed"
);
nftAddress = _nftAddress;
}
function getPoolView(uint256 pid) public view returns (PoolView memory) {
require(pid < poolInfo.length, "EMISSIONS: pid out of range");
PoolInfo memory pool = poolInfo[pid];
uint256 lpPercent = 10000 - devPercent - feePercent;
uint256 rewardsPerSecond;
if(totalAllocPoint == 0){
rewardsPerSecond = 0;
}
else {
rewardsPerSecond = pool
.allocPoint
.mul(rewardsPerSec)
.div(totalAllocPoint)
.mul(lpPercent)
.div(10000);
}
return
PoolView({
pid: pid,
token: address(pool.token),
allocPoint: pool.allocPoint,
lastRewardTime: pool.lastRewardTime,
depositFeeBP: pool.depositFeeBP,
withdrawFeeBP: pool.withdrawFeeBP,
accTokensPerShare: pool.accTokensPerShare,
isStarted: pool.isStarted,
lpBalance: pool.lpBalance,
rewardsPerSecond: rewardsPerSecond
});
}
function getAllPoolViews() external view returns (PoolView[] memory) {
PoolView[] memory views = new PoolView[](poolInfo.length);
for (uint256 i = 0; i < poolInfo.length; i++) {
views[i] = getPoolView(i);
}
return views;
}
function getUserView(
uint256 pid,
address account
) public view returns (UserView memory) {
PoolInfo memory pool = poolInfo[pid];
UserInfo memory user = userInfo[pid][account];
uint256 unclaimedRewards = pendingShare(pid, account);
uint256 lpBalance = pool.token.balanceOf(account);
return
UserView({
pid: pid,
stakedAmount: user.amount,
unclaimedRewards: unclaimedRewards,
lpBalance: lpBalance,
allowance: pool.token.allowance(account, address(this))
});
}
function getUserViews(
address account
) external view returns (UserView[] memory) {
UserView[] memory views = new UserView[](poolInfo.length);
for (uint256 i = 0; i < poolInfo.length; i++) {
views[i] = getUserView(i, account);
}
return views;
}
}
/EnumerableSet.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.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.
*
* ```solidity
* contract Example {
* // Add the library methods
* using EnumerableSet for EnumerableSet.AddressSet;
*
* // Declare a set state variable
* EnumerableSet.AddressSet private mySet;
* }
* ```
*
* As of v3.3.0, sets of type `bytes32` (`Bytes32Set`), `address` (`AddressSet`)
* and `uint256` (`UintSet`) are supported.
*
* [WARNING]
* ====
* Trying to delete such a structure from storage will likely result in data corruption, rendering the structure
* unusable.
* See https://github.com/ethereum/solidity/pull/11843[ethereum/solidity#11843] for more info.
*
* In order to clean an EnumerableSet, you can either remove all elements one by one or create a fresh instance using an
* array of EnumerableSet.
* ====
*/
library EnumerableSet {
// To implement this library for multiple types with as little code
// repetition as possible, we write it in terms of a generic Set type with
// bytes32 values.
// The Set implementation uses private functions, and user-facing
// implementations (such as AddressSet) are just wrappers around the
// underlying Set.
// This means that we can only create new EnumerableSets for types that fit
// in bytes32.
struct Set {
// Storage of set values
bytes32[] _values;
// Position 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: MIT
// OpenZeppelin Contracts (last updated v4.9.5) (utils/Multicall.sol)
pragma solidity ^0.8.0;
import "./Address.sol";
import "./Context.sol";
/**
* @dev Provides a function to batch together multiple calls in a single external call.
*
* Consider any assumption about calldata validation performed by the sender may be violated if it's not especially
* careful about sending transactions invoking {multicall}. For example, a relay address that filters function
* selectors won't filter calls nested within a {multicall} operation.
*
* NOTE: Since 5.0.1 and 4.9.4, this contract identifies non-canonical contexts (i.e. `msg.sender` is not {_msgSender}).
* If a non-canonical context is identified, the following self `delegatecall` appends the last bytes of `msg.data`
* to the subcall. This makes it safe to use with {ERC2771Context}. Contexts that don't affect the resolution of
* {_msgSender} are not propagated to subcalls.
*
* _Available since v4.1._
*/
abstract contract Multicall is Context {
/**
* @dev Receives and executes a batch of function calls on this contract.
* @custom:oz-upgrades-unsafe-allow-reachable delegatecall
*/
function multicall(bytes[] calldata data) external virtual returns (bytes[] memory results) {
bytes memory context = msg.sender == _msgSender()
? new bytes(0)
: msg.data[msg.data.length - _contextSuffixLength():];
results = new bytes[](data.length);
for (uint256 i = 0; i < data.length; i++) {
results[i] = Address.functionDelegateCall(address(this), bytes.concat(data[i], context));
}
return results;
}
}
/SignedMath.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (utils/math/SignedMath.sol)
pragma solidity ^0.8.0;
/**
* @dev Standard signed math utilities missing in the Solidity language.
*/
library SignedMath {
/**
* @dev Returns the largest of two signed numbers.
*/
function max(int256 a, int256 b) internal pure returns (int256) {
return a > b ? a : b;
}
/**
* @dev Returns the smallest of two signed numbers.
*/
function min(int256 a, int256 b) internal pure returns (int256) {
return a < b ? a : b;
}
/**
* @dev Returns the average of two signed numbers without overflow.
* The result is rounded towards zero.
*/
function average(int256 a, int256 b) internal pure returns (int256) {
// Formula from the book "Hacker's Delight"
int256 x = (a & b) + ((a ^ b) >> 1);
return x + (int256(uint256(x) >> 255) & (a ^ b));
}
/**
* @dev Returns the absolute unsigned value of a signed value.
*/
function abs(int256 n) internal pure returns (uint256) {
unchecked {
// must be unchecked in order to support `n = type(int256).min`
return uint256(n >= 0 ? n : -n);
}
}
}
/SafeMath.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.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;
}
}
}
/Math.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.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) {
// Solidity will revert if denominator == 0, unlike the div opcode on its own.
// The surrounding unchecked block does not change this fact.
// See https://docs.soliditylang.org/en/latest/control-structures.html#checked-or-unchecked-arithmetic.
return prod0 / denominator;
}
// Make sure the result is less than 2^256. Also prevents denominator == 0.
require(denominator > prod1, "Math: mulDiv overflow");
///////////////////////////////////////////////
// 512 by 256 division.
///////////////////////////////////////////////
// Make division exact by subtracting the remainder from [prod1 prod0].
uint256 remainder;
assembly {
// Compute remainder using mulmod.
remainder := mulmod(x, y, denominator)
// Subtract 256 bit number from 512 bit number.
prod1 := sub(prod1, gt(remainder, prod0))
prod0 := sub(prod0, remainder)
}
// Factor powers of two out of denominator and compute largest power of two divisor of denominator. Always >= 1.
// See https://cs.stackexchange.com/q/138556/92363.
// 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 256, following the selected rounding direction, of a positive value.
* Returns 0 if given 0.
*/
function log256(uint256 value, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = log256(value);
return result + (rounding == Rounding.Up && 1 << (result << 3) < value ? 1 : 0);
}
}
}
/IERC165.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/introspection/IERC165.sol)
pragma solidity ^0.8.0;
/**
* @dev Interface of the ERC165 standard, as defined in the
* https://eips.ethereum.org/EIPS/eip-165[EIP].
*
* Implementers can declare support of contract interfaces, which can then be
* queried by others ({ERC165Checker}).
*
* For an implementation, see {ERC165}.
*/
interface IERC165 {
/**
* @dev Returns true if this contract implements the interface defined by
* `interfaceId`. See the corresponding
* https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section]
* to learn more about how these ids are created.
*
* This function call must use less than 30 000 gas.
*/
function supportsInterface(bytes4 interfaceId) external view returns (bool);
}
/ERC165.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/introspection/ERC165.sol)
pragma solidity ^0.8.0;
import "./IERC165.sol";
/**
* @dev Implementation of the {IERC165} interface.
*
* Contracts that want to implement ERC165 should inherit from this contract and override {supportsInterface} to check
* for the additional interface id that will be supported. For example:
*
* ```solidity
* function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
* return interfaceId == type(MyInterface).interfaceId || super.supportsInterface(interfaceId);
* }
* ```
*
* Alternatively, {ERC165Storage} provides an easier to use but more expensive implementation.
*/
abstract contract ERC165 is IERC165 {
/**
* @dev See {IERC165-supportsInterface}.
*/
function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
return interfaceId == type(IERC165).interfaceId;
}
}
/
// 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.9.4) (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;
}
function _contextSuffixLength() internal view virtual returns (uint256) {
return 0;
}
}
/
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.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
*
* Furthermore, `isContract` will also return true if the target contract within
* the same transaction is already scheduled for destruction by `SELFDESTRUCT`,
* which only has an effect at the end of a transaction.
* ====
*
* [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://consensys.net/diligence/blog/2019/09/stop-using-soliditys-transfer-now/[Learn more].
*
* IMPORTANT: because control is transferred to `recipient`, care must be
* taken to not create reentrancy vulnerabilities. Consider using
* {ReentrancyGuard} or the
* https://solidity.readthedocs.io/en/v0.8.0/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);
}
}
}
/IERC721Receiver.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.6.0) (token/ERC721/IERC721Receiver.sol)
pragma solidity ^0.8.0;
/**
* @title ERC721 token receiver interface
* @dev Interface for any contract that wants to support safeTransfers
* from ERC721 asset contracts.
*/
interface IERC721Receiver {
/**
* @dev Whenever an {IERC721} `tokenId` token is transferred to this contract via {IERC721-safeTransferFrom}
* by `operator` from `from`, this function is called.
*
* It must return its Solidity selector to confirm the token transfer.
* If any other value is returned or the interface is not implemented by the recipient, the transfer will be reverted.
*
* The selector can be obtained in Solidity with `IERC721Receiver.onERC721Received.selector`.
*/
function onERC721Received(
address operator,
address from,
uint256 tokenId,
bytes calldata data
) external returns (bytes4);
}
/IERC721.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (token/ERC721/IERC721.sol)
pragma solidity ^0.8.0;
import "../../utils/introspection/IERC165.sol";
/**
* @dev Required interface of an ERC721 compliant contract.
*/
interface IERC721 is IERC165 {
/**
* @dev Emitted when `tokenId` token is transferred from `from` to `to`.
*/
event Transfer(address indexed from, address indexed to, uint256 indexed tokenId);
/**
* @dev Emitted when `owner` enables `approved` to manage the `tokenId` token.
*/
event Approval(address indexed owner, address indexed approved, uint256 indexed tokenId);
/**
* @dev Emitted when `owner` enables or disables (`approved`) `operator` to manage all of its assets.
*/
event ApprovalForAll(address indexed owner, address indexed operator, bool approved);
/**
* @dev Returns the number of tokens in ``owner``'s account.
*/
function balanceOf(address owner) external view returns (uint256 balance);
/**
* @dev Returns the owner of the `tokenId` token.
*
* Requirements:
*
* - `tokenId` must exist.
*/
function ownerOf(uint256 tokenId) external view returns (address owner);
/**
* @dev Safely transfers `tokenId` token from `from` to `to`.
*
* Requirements:
*
* - `from` cannot be the zero address.
* - `to` cannot be the zero address.
* - `tokenId` token must exist and be owned by `from`.
* - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}.
* - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.
*
* Emits a {Transfer} event.
*/
function safeTransferFrom(address from, address to, uint256 tokenId, bytes calldata data) external;
/**
* @dev Safely transfers `tokenId` token from `from` to `to`, checking first that contract recipients
* are aware of the ERC721 protocol to prevent tokens from being forever locked.
*
* Requirements:
*
* - `from` cannot be the zero address.
* - `to` cannot be the zero address.
* - `tokenId` token must exist and be owned by `from`.
* - If the caller is not `from`, it must have been allowed to move this token by either {approve} or {setApprovalForAll}.
* - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.
*
* Emits a {Transfer} event.
*/
function safeTransferFrom(address from, address to, uint256 tokenId) external;
/**
* @dev Transfers `tokenId` token from `from` to `to`.
*
* WARNING: Note that the caller is responsible to confirm that the recipient is capable of receiving ERC721
* or else they may be permanently lost. Usage of {safeTransferFrom} prevents loss, though the caller must
* understand this adds an external call which potentially creates a reentrancy vulnerability.
*
* Requirements:
*
* - `from` cannot be the zero address.
* - `to` cannot be the zero address.
* - `tokenId` token must be owned by `from`.
* - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}.
*
* Emits a {Transfer} event.
*/
function transferFrom(address from, address to, uint256 tokenId) external;
/**
* @dev Gives permission to `to` to transfer `tokenId` token to another account.
* The approval is cleared when the token is transferred.
*
* Only a single account can be approved at a time, so approving the zero address clears previous approvals.
*
* Requirements:
*
* - The caller must own the token or be an approved operator.
* - `tokenId` must exist.
*
* Emits an {Approval} event.
*/
function approve(address to, uint256 tokenId) external;
/**
* @dev Approve or remove `operator` as an operator for the caller.
* Operators can call {transferFrom} or {safeTransferFrom} for any token owned by the caller.
*
* Requirements:
*
* - The `operator` cannot be the caller.
*
* Emits an {ApprovalForAll} event.
*/
function setApprovalForAll(address operator, bool approved) external;
/**
* @dev Returns the account approved for `tokenId` token.
*
* Requirements:
*
* - `tokenId` must exist.
*/
function getApproved(uint256 tokenId) external view returns (address operator);
/**
* @dev Returns if the `operator` is allowed to manage all of the assets of `owner`.
*
* See {setApprovalForAll}
*/
function isApprovedForAll(address owner, address operator) external view returns (bool);
}
/extensions/IERC721Metadata.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (token/ERC721/extensions/IERC721Metadata.sol)
pragma solidity ^0.8.0;
import "../IERC721.sol";
/**
* @title ERC-721 Non-Fungible Token Standard, optional metadata extension
* @dev See https://eips.ethereum.org/EIPS/eip-721
*/
interface IERC721Metadata is IERC721 {
/**
* @dev Returns the token collection name.
*/
function name() external view returns (string memory);
/**
* @dev Returns the token collection symbol.
*/
function symbol() external view returns (string memory);
/**
* @dev Returns the Uniform Resource Identifier (URI) for `tokenId` token.
*/
function tokenURI(uint256 tokenId) external view returns (string memory);
}
/extensions/IERC721Enumerable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.5.0) (token/ERC721/extensions/IERC721Enumerable.sol)
pragma solidity ^0.8.0;
import "../IERC721.sol";
/**
* @title ERC-721 Non-Fungible Token Standard, optional enumeration extension
* @dev See https://eips.ethereum.org/EIPS/eip-721
*/
interface IERC721Enumerable is IERC721 {
/**
* @dev Returns the total amount of tokens stored by the contract.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns a token ID owned by `owner` at a given `index` of its token list.
* Use along with {balanceOf} to enumerate all of ``owner``'s tokens.
*/
function tokenOfOwnerByIndex(address owner, uint256 index) external view returns (uint256);
/**
* @dev Returns a token ID at a given `index` of all the tokens stored by the contract.
* Use along with {totalSupply} to enumerate all tokens.
*/
function tokenByIndex(uint256 index) external view returns (uint256);
}
/extensions/ERC721URIStorage.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (token/ERC721/extensions/ERC721URIStorage.sol)
pragma solidity ^0.8.0;
import "../ERC721.sol";
import "../../../interfaces/IERC4906.sol";
/**
* @dev ERC721 token with storage based token URI management.
*/
abstract contract ERC721URIStorage is IERC4906, ERC721 {
using Strings for uint256;
// Optional mapping for token URIs
mapping(uint256 => string) private _tokenURIs;
/**
* @dev See {IERC165-supportsInterface}
*/
function supportsInterface(bytes4 interfaceId) public view virtual override(ERC721, IERC165) returns (bool) {
return interfaceId == bytes4(0x49064906) || super.supportsInterface(interfaceId);
}
/**
* @dev See {IERC721Metadata-tokenURI}.
*/
function tokenURI(uint256 tokenId) public view virtual override returns (string memory) {
_requireMinted(tokenId);
string memory _tokenURI = _tokenURIs[tokenId];
string memory base = _baseURI();
// If there is no base URI, return the token URI.
if (bytes(base).length == 0) {
return _tokenURI;
}
// If both are set, concatenate the baseURI and tokenURI (via abi.encodePacked).
if (bytes(_tokenURI).length > 0) {
return string(abi.encodePacked(base, _tokenURI));
}
return super.tokenURI(tokenId);
}
/**
* @dev Sets `_tokenURI` as the tokenURI of `tokenId`.
*
* Emits {MetadataUpdate}.
*
* Requirements:
*
* - `tokenId` must exist.
*/
function _setTokenURI(uint256 tokenId, string memory _tokenURI) internal virtual {
require(_exists(tokenId), "ERC721URIStorage: URI set of nonexistent token");
_tokenURIs[tokenId] = _tokenURI;
emit MetadataUpdate(tokenId);
}
/**
* @dev See {ERC721-_burn}. This override additionally checks to see if a
* token-specific URI was set for the token, and if so, it deletes the token URI from
* the storage mapping.
*/
function _burn(uint256 tokenId) internal virtual override {
super._burn(tokenId);
if (bytes(_tokenURIs[tokenId]).length != 0) {
delete _tokenURIs[tokenId];
}
}
}
/extensions/ERC721Enumerable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (token/ERC721/extensions/ERC721Enumerable.sol)
pragma solidity ^0.8.0;
import "../ERC721.sol";
import "./IERC721Enumerable.sol";
/**
* @dev This implements an optional extension of {ERC721} defined in the EIP that adds
* enumerability of all the token ids in the contract as well as all token ids owned by each
* account.
*/
abstract contract ERC721Enumerable is ERC721, IERC721Enumerable {
// Mapping from owner to list of owned token IDs
mapping(address => mapping(uint256 => uint256)) private _ownedTokens;
// Mapping from token ID to index of the owner tokens list
mapping(uint256 => uint256) private _ownedTokensIndex;
// Array with all token ids, used for enumeration
uint256[] private _allTokens;
// Mapping from token id to position in the allTokens array
mapping(uint256 => uint256) private _allTokensIndex;
/**
* @dev See {IERC165-supportsInterface}.
*/
function supportsInterface(bytes4 interfaceId) public view virtual override(IERC165, ERC721) returns (bool) {
return interfaceId == type(IERC721Enumerable).interfaceId || super.supportsInterface(interfaceId);
}
/**
* @dev See {IERC721Enumerable-tokenOfOwnerByIndex}.
*/
function tokenOfOwnerByIndex(address owner, uint256 index) public view virtual override returns (uint256) {
require(index < ERC721.balanceOf(owner), "ERC721Enumerable: owner index out of bounds");
return _ownedTokens[owner][index];
}
/**
* @dev See {IERC721Enumerable-totalSupply}.
*/
function totalSupply() public view virtual override returns (uint256) {
return _allTokens.length;
}
/**
* @dev See {IERC721Enumerable-tokenByIndex}.
*/
function tokenByIndex(uint256 index) public view virtual override returns (uint256) {
require(index < ERC721Enumerable.totalSupply(), "ERC721Enumerable: global index out of bounds");
return _allTokens[index];
}
/**
* @dev See {ERC721-_beforeTokenTransfer}.
*/
function _beforeTokenTransfer(
address from,
address to,
uint256 firstTokenId,
uint256 batchSize
) internal virtual override {
super._beforeTokenTransfer(from, to, firstTokenId, batchSize);
if (batchSize > 1) {
// Will only trigger during construction. Batch transferring (minting) is not available afterwards.
revert("ERC721Enumerable: consecutive transfers not supported");
}
uint256 tokenId = firstTokenId;
if (from == address(0)) {
_addTokenToAllTokensEnumeration(tokenId);
} else if (from != to) {
_removeTokenFromOwnerEnumeration(from, tokenId);
}
if (to == address(0)) {
_removeTokenFromAllTokensEnumeration(tokenId);
} else if (to != from) {
_addTokenToOwnerEnumeration(to, tokenId);
}
}
/**
* @dev Private function to add a token to this extension's ownership-tracking data structures.
* @param to address representing the new owner of the given token ID
* @param tokenId uint256 ID of the token to be added to the tokens list of the given address
*/
function _addTokenToOwnerEnumeration(address to, uint256 tokenId) private {
uint256 length = ERC721.balanceOf(to);
_ownedTokens[to][length] = tokenId;
_ownedTokensIndex[tokenId] = length;
}
/**
* @dev Private function to add a token to this extension's token tracking data structures.
* @param tokenId uint256 ID of the token to be added to the tokens list
*/
function _addTokenToAllTokensEnumeration(uint256 tokenId) private {
_allTokensIndex[tokenId] = _allTokens.length;
_allTokens.push(tokenId);
}
/**
* @dev Private function to remove a token from this extension's ownership-tracking data structures. Note that
* while the token is not assigned a new owner, the `_ownedTokensIndex` mapping is _not_ updated: this allows for
* gas optimizations e.g. when performing a transfer operation (avoiding double writes).
* This has O(1) time complexity, but alters the order of the _ownedTokens array.
* @param from address representing the previous owner of the given token ID
* @param tokenId uint256 ID of the token to be removed from the tokens list of the given address
*/
function _removeTokenFromOwnerEnumeration(address from, uint256 tokenId) private {
// To prevent a gap in from's tokens array, we store the last token in the index of the token to delete, and
// then delete the last slot (swap and pop).
uint256 lastTokenIndex = ERC721.balanceOf(from) - 1;
uint256 tokenIndex = _ownedTokensIndex[tokenId];
// When the token to delete is the last token, the swap operation is unnecessary
if (tokenIndex != lastTokenIndex) {
uint256 lastTokenId = _ownedTokens[from][lastTokenIndex];
_ownedTokens[from][tokenIndex] = lastTokenId; // Move the last token to the slot of the to-delete token
_ownedTokensIndex[lastTokenId] = tokenIndex; // Update the moved token's index
}
// This also deletes the contents at the last position of the array
delete _ownedTokensIndex[tokenId];
delete _ownedTokens[from][lastTokenIndex];
}
/**
* @dev Private function to remove a token from this extension's token tracking data structures.
* This has O(1) time complexity, but alters the order of the _allTokens array.
* @param tokenId uint256 ID of the token to be removed from the tokens list
*/
function _removeTokenFromAllTokensEnumeration(uint256 tokenId) private {
// To prevent a gap in the tokens array, we store the last token in the index of the token to delete, and
// then delete the last slot (swap and pop).
uint256 lastTokenIndex = _allTokens.length - 1;
uint256 tokenIndex = _allTokensIndex[tokenId];
// When the token to delete is the last token, the swap operation is unnecessary. However, since this occurs so
// rarely (when the last minted token is burnt) that we still do the swap here to avoid the gas cost of adding
// an 'if' statement (like in _removeTokenFromOwnerEnumeration)
uint256 lastTokenId = _allTokens[lastTokenIndex];
_allTokens[tokenIndex] = lastTokenId; // Move the last token to the slot of the to-delete token
_allTokensIndex[lastTokenId] = tokenIndex; // Update the moved token's index
// This also deletes the contents at the last position of the array
delete _allTokensIndex[tokenId];
_allTokens.pop();
}
}
/ERC721.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (token/ERC721/ERC721.sol)
pragma solidity ^0.8.0;
import "./IERC721.sol";
import "./IERC721Receiver.sol";
import "./extensions/IERC721Metadata.sol";
import "../../utils/Address.sol";
import "../../utils/Context.sol";
import "../../utils/Strings.sol";
import "../../utils/introspection/ERC165.sol";
/**
* @dev Implementation of https://eips.ethereum.org/EIPS/eip-721[ERC721] Non-Fungible Token Standard, including
* the Metadata extension, but not including the Enumerable extension, which is available separately as
* {ERC721Enumerable}.
*/
contract ERC721 is Context, ERC165, IERC721, IERC721Metadata {
using Address for address;
using Strings for uint256;
// Token name
string private _name;
// Token symbol
string private _symbol;
// Mapping from token ID to owner address
mapping(uint256 => address) private _owners;
// Mapping owner address to token count
mapping(address => uint256) private _balances;
// Mapping from token ID to approved address
mapping(uint256 => address) private _tokenApprovals;
// Mapping from owner to operator approvals
mapping(address => mapping(address => bool)) private _operatorApprovals;
/**
* @dev Initializes the contract by setting a `name` and a `symbol` to the token collection.
*/
constructor(string memory name_, string memory symbol_) {
_name = name_;
_symbol = symbol_;
}
/**
* @dev See {IERC165-supportsInterface}.
*/
function supportsInterface(bytes4 interfaceId) public view virtual override(ERC165, IERC165) returns (bool) {
return
interfaceId == type(IERC721).interfaceId ||
interfaceId == type(IERC721Metadata).interfaceId ||
super.supportsInterface(interfaceId);
}
/**
* @dev See {IERC721-balanceOf}.
*/
function balanceOf(address owner) public view virtual override returns (uint256) {
require(owner != address(0), "ERC721: address zero is not a valid owner");
return _balances[owner];
}
/**
* @dev See {IERC721-ownerOf}.
*/
function ownerOf(uint256 tokenId) public view virtual override returns (address) {
address owner = _ownerOf(tokenId);
require(owner != address(0), "ERC721: invalid token ID");
return owner;
}
/**
* @dev See {IERC721Metadata-name}.
*/
function name() public view virtual override returns (string memory) {
return _name;
}
/**
* @dev See {IERC721Metadata-symbol}.
*/
function symbol() public view virtual override returns (string memory) {
return _symbol;
}
/**
* @dev See {IERC721Metadata-tokenURI}.
*/
function tokenURI(uint256 tokenId) public view virtual override returns (string memory) {
_requireMinted(tokenId);
string memory baseURI = _baseURI();
return bytes(baseURI).length > 0 ? string(abi.encodePacked(baseURI, tokenId.toString())) : "";
}
/**
* @dev Base URI for computing {tokenURI}. If set, the resulting URI for each
* token will be the concatenation of the `baseURI` and the `tokenId`. Empty
* by default, can be overridden in child contracts.
*/
function _baseURI() internal view virtual returns (string memory) {
return "";
}
/**
* @dev See {IERC721-approve}.
*/
function approve(address to, uint256 tokenId) public virtual override {
address owner = ERC721.ownerOf(tokenId);
require(to != owner, "ERC721: approval to current owner");
require(
_msgSender() == owner || isApprovedForAll(owner, _msgSender()),
"ERC721: approve caller is not token owner or approved for all"
);
_approve(to, tokenId);
}
/**
* @dev See {IERC721-getApproved}.
*/
function getApproved(uint256 tokenId) public view virtual override returns (address) {
_requireMinted(tokenId);
return _tokenApprovals[tokenId];
}
/**
* @dev See {IERC721-setApprovalForAll}.
*/
function setApprovalForAll(address operator, bool approved) public virtual override {
_setApprovalForAll(_msgSender(), operator, approved);
}
/**
* @dev See {IERC721-isApprovedForAll}.
*/
function isApprovedForAll(address owner, address operator) public view virtual override returns (bool) {
return _operatorApprovals[owner][operator];
}
/**
* @dev See {IERC721-transferFrom}.
*/
function transferFrom(address from, address to, uint256 tokenId) public virtual override {
//solhint-disable-next-line max-line-length
require(_isApprovedOrOwner(_msgSender(), tokenId), "ERC721: caller is not token owner or approved");
_transfer(from, to, tokenId);
}
/**
* @dev See {IERC721-safeTransferFrom}.
*/
function safeTransferFrom(address from, address to, uint256 tokenId) public virtual override {
safeTransferFrom(from, to, tokenId, "");
}
/**
* @dev See {IERC721-safeTransferFrom}.
*/
function safeTransferFrom(address from, address to, uint256 tokenId, bytes memory data) public virtual override {
require(_isApprovedOrOwner(_msgSender(), tokenId), "ERC721: caller is not token owner or approved");
_safeTransfer(from, to, tokenId, data);
}
/**
* @dev Safely transfers `tokenId` token from `from` to `to`, checking first that contract recipients
* are aware of the ERC721 protocol to prevent tokens from being forever locked.
*
* `data` is additional data, it has no specified format and it is sent in call to `to`.
*
* This internal function is equivalent to {safeTransferFrom}, and can be used to e.g.
* implement alternative mechanisms to perform token transfer, such as signature-based.
*
* Requirements:
*
* - `from` cannot be the zero address.
* - `to` cannot be the zero address.
* - `tokenId` token must exist and be owned by `from`.
* - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.
*
* Emits a {Transfer} event.
*/
function _safeTransfer(address from, address to, uint256 tokenId, bytes memory data) internal virtual {
_transfer(from, to, tokenId);
require(_checkOnERC721Received(from, to, tokenId, data), "ERC721: transfer to non ERC721Receiver implementer");
}
/**
* @dev Returns the owner of the `tokenId`. Does NOT revert if token doesn't exist
*/
function _ownerOf(uint256 tokenId) internal view virtual returns (address) {
return _owners[tokenId];
}
/**
* @dev Returns whether `tokenId` exists.
*
* Tokens can be managed by their owner or approved accounts via {approve} or {setApprovalForAll}.
*
* Tokens start existing when they are minted (`_mint`),
* and stop existing when they are burned (`_burn`).
*/
function _exists(uint256 tokenId) internal view virtual returns (bool) {
return _ownerOf(tokenId) != address(0);
}
/**
* @dev Returns whether `spender` is allowed to manage `tokenId`.
*
* Requirements:
*
* - `tokenId` must exist.
*/
function _isApprovedOrOwner(address spender, uint256 tokenId) internal view virtual returns (bool) {
address owner = ERC721.ownerOf(tokenId);
return (spender == owner || isApprovedForAll(owner, spender) || getApproved(tokenId) == spender);
}
/**
* @dev Safely mints `tokenId` and transfers it to `to`.
*
* Requirements:
*
* - `tokenId` must not exist.
* - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.
*
* Emits a {Transfer} event.
*/
function _safeMint(address to, uint256 tokenId) internal virtual {
_safeMint(to, tokenId, "");
}
/**
* @dev Same as {xref-ERC721-_safeMint-address-uint256-}[`_safeMint`], with an additional `data` parameter which is
* forwarded in {IERC721Receiver-onERC721Received} to contract recipients.
*/
function _safeMint(address to, uint256 tokenId, bytes memory data) internal virtual {
_mint(to, tokenId);
require(
_checkOnERC721Received(address(0), to, tokenId, data),
"ERC721: transfer to non ERC721Receiver implementer"
);
}
/**
* @dev Mints `tokenId` and transfers it to `to`.
*
* WARNING: Usage of this method is discouraged, use {_safeMint} whenever possible
*
* Requirements:
*
* - `tokenId` must not exist.
* - `to` cannot be the zero address.
*
* Emits a {Transfer} event.
*/
function _mint(address to, uint256 tokenId) internal virtual {
require(to != address(0), "ERC721: mint to the zero address");
require(!_exists(tokenId), "ERC721: token already minted");
_beforeTokenTransfer(address(0), to, tokenId, 1);
// Check that tokenId was not minted by `_beforeTokenTransfer` hook
require(!_exists(tokenId), "ERC721: token already minted");
unchecked {
// Will not overflow unless all 2**256 token ids are minted to the same owner.
// Given that tokens are minted one by one, it is impossible in practice that
// this ever happens. Might change if we allow batch minting.
// The ERC fails to describe this case.
_balances[to] += 1;
}
_owners[tokenId] = to;
emit Transfer(address(0), to, tokenId);
_afterTokenTransfer(address(0), to, tokenId, 1);
}
/**
* @dev Destroys `tokenId`.
* The approval is cleared when the token is burned.
* This is an internal function that does not check if the sender is authorized to operate on the token.
*
* Requirements:
*
* - `tokenId` must exist.
*
* Emits a {Transfer} event.
*/
function _burn(uint256 tokenId) internal virtual {
address owner = ERC721.ownerOf(tokenId);
_beforeTokenTransfer(owner, address(0), tokenId, 1);
// Update ownership in case tokenId was transferred by `_beforeTokenTransfer` hook
owner = ERC721.ownerOf(tokenId);
// Clear approvals
delete _tokenApprovals[tokenId];
unchecked {
// Cannot overflow, as that would require more tokens to be burned/transferred
// out than the owner initially received through minting and transferring in.
_balances[owner] -= 1;
}
delete _owners[tokenId];
emit Transfer(owner, address(0), tokenId);
_afterTokenTransfer(owner, address(0), tokenId, 1);
}
/**
* @dev Transfers `tokenId` from `from` to `to`.
* As opposed to {transferFrom}, this imposes no restrictions on msg.sender.
*
* Requirements:
*
* - `to` cannot be the zero address.
* - `tokenId` token must be owned by `from`.
*
* Emits a {Transfer} event.
*/
function _transfer(address from, address to, uint256 tokenId) internal virtual {
require(ERC721.ownerOf(tokenId) == from, "ERC721: transfer from incorrect owner");
require(to != address(0), "ERC721: transfer to the zero address");
_beforeTokenTransfer(from, to, tokenId, 1);
// Check that tokenId was not transferred by `_beforeTokenTransfer` hook
require(ERC721.ownerOf(tokenId) == from, "ERC721: transfer from incorrect owner");
// Clear approvals from the previous owner
delete _tokenApprovals[tokenId];
unchecked {
// `_balances[from]` cannot overflow for the same reason as described in `_burn`:
// `from`'s balance is the number of token held, which is at least one before the current
// transfer.
// `_balances[to]` could overflow in the conditions described in `_mint`. That would require
// all 2**256 token ids to be minted, which in practice is impossible.
_balances[from] -= 1;
_balances[to] += 1;
}
_owners[tokenId] = to;
emit Transfer(from, to, tokenId);
_afterTokenTransfer(from, to, tokenId, 1);
}
/**
* @dev Approve `to` to operate on `tokenId`
*
* Emits an {Approval} event.
*/
function _approve(address to, uint256 tokenId) internal virtual {
_tokenApprovals[tokenId] = to;
emit Approval(ERC721.ownerOf(tokenId), to, tokenId);
}
/**
* @dev Approve `operator` to operate on all of `owner` tokens
*
* Emits an {ApprovalForAll} event.
*/
function _setApprovalForAll(address owner, address operator, bool approved) internal virtual {
require(owner != operator, "ERC721: approve to caller");
_operatorApprovals[owner][operator] = approved;
emit ApprovalForAll(owner, operator, approved);
}
/**
* @dev Reverts if the `tokenId` has not been minted yet.
*/
function _requireMinted(uint256 tokenId) internal view virtual {
require(_exists(tokenId), "ERC721: invalid token ID");
}
/**
* @dev Internal function to invoke {IERC721Receiver-onERC721Received} on a target address.
* The call is not executed if the target address is not a contract.
*
* @param from address representing the previous owner of the given token ID
* @param to target address that will receive the tokens
* @param tokenId uint256 ID of the token to be transferred
* @param data bytes optional data to send along with the call
* @return bool whether the call correctly returned the expected magic value
*/
function _checkOnERC721Received(
address from,
address to,
uint256 tokenId,
bytes memory data
) private returns (bool) {
if (to.isContract()) {
try IERC721Receiver(to).onERC721Received(_msgSender(), from, tokenId, data) returns (bytes4 retval) {
return retval == IERC721Receiver.onERC721Received.selector;
} catch (bytes memory reason) {
if (reason.length == 0) {
revert("ERC721: transfer to non ERC721Receiver implementer");
} else {
/// @solidity memory-safe-assembly
assembly {
revert(add(32, reason), mload(reason))
}
}
}
} else {
return true;
}
}
/**
* @dev Hook that is called before any token transfer. This includes minting and burning. If {ERC721Consecutive} is
* used, the hook may be called as part of a consecutive (batch) mint, as indicated by `batchSize` greater than 1.
*
* Calling conditions:
*
* - When `from` and `to` are both non-zero, ``from``'s tokens will be transferred to `to`.
* - When `from` is zero, the tokens will be minted for `to`.
* - When `to` is zero, ``from``'s tokens will be burned.
* - `from` and `to` are never both zero.
* - `batchSize` is non-zero.
*
* To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
*/
function _beforeTokenTransfer(address from, address to, uint256 firstTokenId, uint256 batchSize) internal virtual {}
/**
* @dev Hook that is called after any token transfer. This includes minting and burning. If {ERC721Consecutive} is
* used, the hook may be called as part of a consecutive (batch) mint, as indicated by `batchSize` greater than 1.
*
* Calling conditions:
*
* - When `from` and `to` are both non-zero, ``from``'s tokens were transferred to `to`.
* - When `from` is zero, the tokens were minted for `to`.
* - When `to` is zero, ``from``'s tokens were burned.
* - `from` and `to` are never both zero.
* - `batchSize` is non-zero.
*
* To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
*/
function _afterTokenTransfer(address from, address to, uint256 firstTokenId, uint256 batchSize) internal virtual {}
/**
* @dev Unsafe write access to the balances, used by extensions that "mint" tokens using an {ownerOf} override.
*
* WARNING: Anyone calling this MUST ensure that the balances remain consistent with the ownership. The invariant
* being that for any address `a` the value returned by `balanceOf(a)` must be equal to the number of tokens such
* that `ownerOf(tokenId)` is `a`.
*/
// solhint-disable-next-line func-name-mixedcase
function __unsafe_increaseBalance(address account, uint256 amount) internal {
_balances[account] += amount;
}
}
/utils/SafeERC20.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.3) (token/ERC20/utils/SafeERC20.sol)
pragma solidity ^0.8.0;
import "../IERC20.sol";
import "../extensions/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;
/**
* @dev Transfer `value` amount of `token` from the calling contract to `to`. If `token` returns no value,
* non-reverting calls are assumed to be successful.
*/
function safeTransfer(IERC20 token, address to, uint256 value) internal {
_callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value));
}
/**
* @dev Transfer `value` amount of `token` from `from` to `to`, spending the approval given by `from` to the
* calling contract. If `token` returns no value, non-reverting calls are assumed to be successful.
*/
function safeTransferFrom(IERC20 token, address from, address to, uint256 value) internal {
_callOptionalReturn(token, abi.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));
}
/**
* @dev Increase the calling contract's allowance toward `spender` by `value`. If `token` returns no value,
* non-reverting calls are assumed to be successful.
*/
function safeIncreaseAllowance(IERC20 token, address spender, uint256 value) internal {
uint256 oldAllowance = token.allowance(address(this), spender);
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, oldAllowance + value));
}
/**
* @dev Decrease the calling contract's allowance toward `spender` by `value`. If `token` returns no value,
* non-reverting calls are assumed to be successful.
*/
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");
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, oldAllowance - value));
}
}
/**
* @dev Set the calling contract's allowance toward `spender` to `value`. If `token` returns no value,
* non-reverting calls are assumed to be successful. Meant to be used with tokens that require the approval
* to be set to zero before setting it to a non-zero value, such as USDT.
*/
function forceApprove(IERC20 token, address spender, uint256 value) internal {
bytes memory approvalCall = abi.encodeWithSelector(token.approve.selector, spender, value);
if (!_callOptionalReturnBool(token, approvalCall)) {
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, 0));
_callOptionalReturn(token, approvalCall);
}
}
/**
* @dev Use a ERC-2612 signature to set the `owner` approval toward `spender` on `token`.
* Revert on invalid signature.
*/
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");
require(returndata.length == 0 || abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation 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).
*
* This is a variant of {_callOptionalReturn} that silents catches all reverts and returns a bool instead.
*/
function _callOptionalReturnBool(IERC20 token, bytes memory data) private returns (bool) {
// 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 cannot use {Address-functionCall} here since this should return false
// and not revert is the subcall reverts.
(bool success, bytes memory returndata) = address(token).call(data);
return
success && (returndata.length == 0 || abi.decode(returndata, (bool))) && Address.isContract(address(token));
}
}
/IERC20.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.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);
}
/extensions/IERC20Permit.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.4) (token/ERC20/extensions/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.
*
* ==== Security Considerations
*
* There are two important considerations concerning the use of `permit`. The first is that a valid permit signature
* expresses an allowance, and it should not be assumed to convey additional meaning. In particular, it should not be
* considered as an intention to spend the allowance in any specific way. The second is that because permits have
* built-in replay protection and can be submitted by anyone, they can be frontrun. A protocol that uses permits should
* take this into consideration and allow a `permit` call to fail. Combining these two aspects, a pattern that may be
* generally recommended is:
*
* ```solidity
* function doThingWithPermit(..., uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s) public {
* try token.permit(msg.sender, address(this), value, deadline, v, r, s) {} catch {}
* doThing(..., value);
* }
*
* function doThing(..., uint256 value) public {
* token.safeTransferFrom(msg.sender, address(this), value);
* ...
* }
* ```
*
* Observe that: 1) `msg.sender` is used as the owner, leaving no ambiguity as to the signer intent, and 2) the use of
* `try/catch` allows the permit to fail and makes the code tolerant to frontrunning. (See also
* {SafeERC20-safeTransferFrom}).
*
* Additionally, note that smart contract wallets (such as Argent or Safe) are not able to produce permit signatures, so
* contracts should have entry points that don't rely on permit.
*/
interface IERC20Permit {
/**
* @dev Sets `value` as the allowance of `spender` over ``owner``'s tokens,
* given ``owner``'s signed approval.
*
* IMPORTANT: The same issues {IERC20-approve} has related to transaction
* ordering also apply here.
*
* Emits an {Approval} event.
*
* Requirements:
*
* - `spender` cannot be the zero address.
* - `deadline` must be a timestamp in the future.
* - `v`, `r` and `s` must be a valid `secp256k1` signature from `owner`
* over the EIP712-formatted function arguments.
* - the signature must use ``owner``'s current nonce (see {nonces}).
*
* For more information on the signature format, see the
* https://eips.ethereum.org/EIPS/eip-2612#specification[relevant EIP
* section].
*
* CAUTION: See Security Considerations above.
*/
function permit(
address owner,
address spender,
uint256 value,
uint256 deadline,
uint8 v,
bytes32 r,
bytes32 s
) external;
/**
* @dev Returns the current nonce for `owner`. This value must be
* included whenever a signature is generated for {permit}.
*
* Every successful call to {permit} increases ``owner``'s nonce by one. This
* prevents a signature from being used multiple times.
*/
function nonces(address owner) external view returns (uint256);
/**
* @dev Returns the domain separator used in the encoding of the signature for {permit}, as defined by {EIP712}.
*/
// solhint-disable-next-line func-name-mixedcase
function DOMAIN_SEPARATOR() external view returns (bytes32);
}
/extensions/IERC20Metadata.sol
// 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);
}
/ERC20.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.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].
*
* The default value of {decimals} is 18. To change this, you should override
* this function so it returns a different value.
*
* 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}.
*
* 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 default value returned by this function, unless
* it's 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 (last updated v4.9.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;
}
/**
* @dev Returns true if the reentrancy guard is currently set to "entered", which indicates there is a
* `nonReentrant` function in the call stack.
*/
function _reentrancyGuardEntered() internal view returns (bool) {
return _status == _ENTERED;
}
}
/
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.7.0) (security/Pausable.sol)
pragma solidity ^0.8.0;
import "../utils/Context.sol";
/**
* @dev Contract module which allows children to implement an emergency stop
* mechanism that can be triggered by an authorized account.
*
* This module is used through inheritance. It will make available the
* modifiers `whenNotPaused` and `whenPaused`, which can be applied to
* the functions of your contract. Note that they will not be pausable by
* simply including this module, only once the modifiers are put in place.
*/
abstract contract Pausable is Context {
/**
* @dev Emitted when the pause is triggered by `account`.
*/
event Paused(address account);
/**
* @dev Emitted when the pause is lifted by `account`.
*/
event Unpaused(address account);
bool private _paused;
/**
* @dev Initializes the contract in unpaused state.
*/
constructor() {
_paused = false;
}
/**
* @dev Modifier to make a function callable only when the contract is not paused.
*
* Requirements:
*
* - The contract must not be paused.
*/
modifier whenNotPaused() {
_requireNotPaused();
_;
}
/**
* @dev Modifier to make a function callable only when the contract is paused.
*
* Requirements:
*
* - The contract must be paused.
*/
modifier whenPaused() {
_requirePaused();
_;
}
/**
* @dev Returns true if the contract is paused, and false otherwise.
*/
function paused() public view virtual returns (bool) {
return _paused;
}
/**
* @dev Throws if the contract is paused.
*/
function _requireNotPaused() internal view virtual {
require(!paused(), "Pausable: paused");
}
/**
* @dev Throws if the contract is not paused.
*/
function _requirePaused() internal view virtual {
require(paused(), "Pausable: not paused");
}
/**
* @dev Triggers stopped state.
*
* Requirements:
*
* - The contract must not be paused.
*/
function _pause() internal virtual whenNotPaused {
_paused = true;
emit Paused(_msgSender());
}
/**
* @dev Returns to normal state.
*
* Requirements:
*
* - The contract must be paused.
*/
function _unpause() internal virtual whenPaused {
_paused = false;
emit Unpaused(_msgSender());
}
}
/
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (interfaces/IERC721.sol)
pragma solidity ^0.8.0;
import "../token/ERC721/IERC721.sol";
/
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.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. Can only be called by the current owner.
*
* NOTE: Renouncing ownership will leave the contract without an owner,
* thereby disabling any functionality that is only available to the owner.
*/
function renounceOwnership() public virtual onlyOwner {
_transferOwnership(address(0));
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Can only be called by the current owner.
*/
function transferOwnership(address newOwner) public virtual onlyOwner {
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);
}
}
Compiler Settings
{"viaIR":true,"remappings":[],"optimizer":{"runs":200,"enabled":true},"metadata":{"bytecodeHash":"ipfs"},"libraries":{},"evmVersion":"paris","compilationTarget":{"contracts/RewardToken.sol":"RewardToken"}}
Contract ABI
[{"type":"constructor","stateMutability":"nonpayable","inputs":[{"type":"address","name":"_nftAddress","internalType":"address"}]},{"type":"event","name":"Approval","inputs":[{"type":"address","name":"owner","internalType":"address","indexed":true},{"type":"address","name":"spender","internalType":"address","indexed":true},{"type":"uint256","name":"value","internalType":"uint256","indexed":false}],"anonymous":false},{"type":"event","name":"Burned","inputs":[{"type":"uint256","name":"amount","internalType":"uint256","indexed":false}],"anonymous":false},{"type":"event","name":"OwnershipTransferred","inputs":[{"type":"address","name":"previousOwner","internalType":"address","indexed":true},{"type":"address","name":"newOwner","internalType":"address","indexed":true}],"anonymous":false},{"type":"event","name":"ProposalCreated","inputs":[{"type":"uint256","name":"proposalId","internalType":"uint256","indexed":true},{"type":"address","name":"proposer","internalType":"address","indexed":true},{"type":"string","name":"description","internalType":"string","indexed":false},{"type":"uint256","name":"startTime","internalType":"uint256","indexed":false},{"type":"uint256","name":"endTime","internalType":"uint256","indexed":false}],"anonymous":false},{"type":"event","name":"ProposalExecuted","inputs":[{"type":"uint256","name":"proposalId","internalType":"uint256","indexed":true}],"anonymous":false},{"type":"event","name":"Transfer","inputs":[{"type":"address","name":"from","internalType":"address","indexed":true},{"type":"address","name":"to","internalType":"address","indexed":true},{"type":"uint256","name":"value","internalType":"uint256","indexed":false}],"anonymous":false},{"type":"event","name":"VoteCast","inputs":[{"type":"address","name":"voter","internalType":"address","indexed":true},{"type":"uint256","name":"proposalId","internalType":"uint256","indexed":true},{"type":"bool","name":"support","internalType":"bool","indexed":false},{"type":"uint256","name":"weight","internalType":"uint256","indexed":false}],"anonymous":false},{"type":"event","name":"VotingParametersUpdated","inputs":[{"type":"uint256","name":"votingPeriod","internalType":"uint256","indexed":false},{"type":"uint256","name":"proposalThresholdBps","internalType":"uint256","indexed":false},{"type":"uint256","name":"quorumBps","internalType":"uint256","indexed":false}],"anonymous":false},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"BPS_DENOMINATOR","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"PROPOSAL_THRESHOLD_BPS","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"QUORUM_BPS","inputs":[]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"addWhitelist","inputs":[{"type":"address","name":"account","internalType":"address"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"allowance","inputs":[{"type":"address","name":"owner","internalType":"address"},{"type":"address","name":"spender","internalType":"address"}]},{"type":"function","stateMutability":"nonpayable","outputs":[{"type":"bool","name":"","internalType":"bool"}],"name":"approve","inputs":[{"type":"address","name":"spender","internalType":"address"},{"type":"uint256","name":"amount","internalType":"uint256"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"balanceOf","inputs":[{"type":"address","name":"account","internalType":"address"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"burn","inputs":[{"type":"uint256","name":"_amount","internalType":"uint256"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"castVote","inputs":[{"type":"uint256","name":"proposalId","internalType":"uint256"},{"type":"bool","name":"support","internalType":"bool"}]},{"type":"function","stateMutability":"nonpayable","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"createProposal","inputs":[{"type":"string","name":"description","internalType":"string"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint8","name":"","internalType":"uint8"}],"name":"decimals","inputs":[]},{"type":"function","stateMutability":"nonpayable","outputs":[{"type":"bool","name":"","internalType":"bool"}],"name":"decreaseAllowance","inputs":[{"type":"address","name":"spender","internalType":"address"},{"type":"uint256","name":"subtractedValue","internalType":"uint256"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"executeProposal","inputs":[{"type":"uint256","name":"proposalId","internalType":"uint256"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"forVotes","internalType":"uint256"},{"type":"uint256","name":"againstVotes","internalType":"uint256"},{"type":"bool","name":"active","internalType":"bool"},{"type":"bool","name":"passed","internalType":"bool"}],"name":"getProposalState","inputs":[{"type":"uint256","name":"proposalId","internalType":"uint256"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"getProposalThreshold","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"getQuorum","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"bool","name":"","internalType":"bool"}],"name":"hasVoted","inputs":[{"type":"uint256","name":"proposalId","internalType":"uint256"},{"type":"address","name":"voter","internalType":"address"}]},{"type":"function","stateMutability":"nonpayable","outputs":[{"type":"bool","name":"","internalType":"bool"}],"name":"increaseAllowance","inputs":[{"type":"address","name":"spender","internalType":"address"},{"type":"uint256","name":"addedValue","internalType":"uint256"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"bool","name":"","internalType":"bool"}],"name":"isWhitelisted","inputs":[{"type":"address","name":"","internalType":"address"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"address","name":"","internalType":"address"}],"name":"masterchef","inputs":[]},{"type":"function","stateMutability":"nonpayable","outputs":[{"type":"bool","name":"","internalType":"bool"}],"name":"mint","inputs":[{"type":"uint256","name":"_amount","internalType":"uint256"}]},{"type":"function","stateMutability":"nonpayable","outputs":[{"type":"bool","name":"","internalType":"bool"}],"name":"mintFor","inputs":[{"type":"address","name":"_address","internalType":"address"},{"type":"uint256","name":"_amount","internalType":"uint256"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"string","name":"","internalType":"string"}],"name":"name","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"address","name":"","internalType":"address"}],"name":"nftAddress","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"address","name":"","internalType":"address"}],"name":"owner","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"address","name":"","internalType":"address"}],"name":"pair","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"proposalCount","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"id","internalType":"uint256"},{"type":"string","name":"description","internalType":"string"},{"type":"uint256","name":"forVotes","internalType":"uint256"},{"type":"uint256","name":"againstVotes","internalType":"uint256"},{"type":"uint256","name":"startTime","internalType":"uint256"},{"type":"uint256","name":"endTime","internalType":"uint256"},{"type":"bool","name":"executed","internalType":"bool"},{"type":"address","name":"proposer","internalType":"address"}],"name":"proposals","inputs":[{"type":"uint256","name":"","internalType":"uint256"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"address","name":"","internalType":"contract IUniswapV2Router02"}],"name":"pulseXRouter","inputs":[]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"removeWhitelist","inputs":[{"type":"address","name":"account","internalType":"address"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"renounceOwnership","inputs":[]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"safeTokenTransfer","inputs":[{"type":"address","name":"_to","internalType":"address"},{"type":"uint256","name":"_amount","internalType":"uint256"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"setMasterchef","inputs":[{"type":"address","name":"_masterchef","internalType":"address"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"setNftAddress","inputs":[{"type":"address","name":"_nftAddress","internalType":"address"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"setVotingParameters","inputs":[{"type":"uint256","name":"_votingPeriod","internalType":"uint256"},{"type":"uint256","name":"_proposalThresholdBps","internalType":"uint256"},{"type":"uint256","name":"_quorumBps","internalType":"uint256"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"setVotingToken","inputs":[{"type":"address","name":"_votingToken","internalType":"address"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"stakeThreshold","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"address","name":"","internalType":"address"}],"name":"stakingRewards","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"bool","name":"","internalType":"bool"}],"name":"swapEnabled","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"swapThreshold","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"string","name":"","internalType":"string"}],"name":"symbol","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"totalBurned","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"totalSupply","inputs":[]},{"type":"function","stateMutability":"nonpayable","outputs":[{"type":"bool","name":"","internalType":"bool"}],"name":"transfer","inputs":[{"type":"address","name":"to","internalType":"address"},{"type":"uint256","name":"amount","internalType":"uint256"}]},{"type":"function","stateMutability":"nonpayable","outputs":[{"type":"bool","name":"","internalType":"bool"}],"name":"transferFrom","inputs":[{"type":"address","name":"from","internalType":"address"},{"type":"address","name":"to","internalType":"address"},{"type":"uint256","name":"amount","internalType":"uint256"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"transferOwnership","inputs":[{"type":"address","name":"newOwner","internalType":"address"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"updateStakeThreshold","inputs":[{"type":"uint256","name":"_amount","internalType":"uint256"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"updateStakingRewards","inputs":[{"type":"address","name":"_stakingRewards","internalType":"address"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"updateSwapThreshold","inputs":[{"type":"uint256","name":"_amount","internalType":"uint256"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"votingPeriod","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"address","name":"","internalType":"address"}],"name":"votingToken","inputs":[]},{"type":"receive","stateMutability":"payable"}]
Contract Creation Code
0x608060409080825234620006cb57620000329062002a158038038091620000278285620006d0565b8339810190620006f4565b6200003c62000715565b6200004662000715565b815190926001600160401b03808311620005cb576003908154916001948584811c9416968715620006c0575b60209788861014620006aa578190601f9586811162000654575b508890868311600114620005ed57600092620005e1575b505060001982841b1c191690861b1781555b8651918211620005cb5760049687548681811c91168015620005c0575b88821014620005ab579081858594931162000553575b508790858411600114620004e857600093620004dc575b505082861b92600019911b1c19161785555b60058054336001600160a01b031980831682179093558851946001600160a01b0394939290919085167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0600080a36203f48060065560646007556103e8600855601080546001600160a81b0319167401165c3410fc91ef562c50559f7d2289febed552d9179055678ac7230489e80000601155690a968163f0a57b4000006012556101f460165563c45a015560e01b855273165c3410fc91ef562c50559f7d2289febed552d99487818a81895afa908115620004835789968991600093620004b8575b508b5163ef8ef56f60e01b81529a8b9182905afa98891562000483576000996200048e575b50908785928b519384916364e329cb60e11b8352308a8401528160249d168d84015216815a604492600091f19182156200048357859283916000916200044f575b501683600f541617600f551690600c541617600c5530600052600d85528660002060ff199085828254161790553360005284886000209182541617905533156200040f575060025469e8ef1e96ae389780000090818101809111620003fb57600255336000526000855286600020818154019055865190815260007fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef863393a360105416933015620003ad57841562000360575050306000528152826000208260005281527f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b9256000199182856000205584519283523092a3516122cb90816200074a8239f35b855162461bcd60e51b81529182018490526022908201527f45524332303a20617070726f766520746f20746865207a65726f206164647265604482015261737360f01b6064820152608490fd5b855162461bcd60e51b8152918201849052808201527f45524332303a20617070726f76652066726f6d20746865207a65726f206164646044820152637265737360e01b606482015260849150fd5b86601185634e487b7160e01b600052526000fd5b8260649187878a519362461bcd60e51b85528401528201527f45524332303a206d696e7420746f20746865207a65726f2061646472657373006044820152fd5b6200047491508a3d8c116200047b575b6200046b8183620006d0565b810190620006f4565b386200025a565b503d6200045f565b8a513d6000823e3d90fd5b8592919950620004ae8991823d84116200047b576200046b8183620006d0565b9991925062000219565b620004d4919350823d84116200047b576200046b8183620006d0565b9138620001f4565b015191503880620000ff565b9190879450601f198416928a600052896000209360005b8b8282106200053c575050851162000521575b50505050811b01855562000111565b01519060f884600019921b161c191690553880808062000512565b8385015187558b98909601959384019301620004ff565b9091925088600052876000208580860160051c8201928a8710620005a1575b91899187969594930160051c01915b82811062000591575050620000e8565b6000815586955089910162000581565b9250819262000572565b602289634e487b7160e01b6000525260246000fd5b90607f1690620000d2565b634e487b7160e01b600052604160045260246000fd5b015190503880620000a3565b90889350601f19831691856000528a6000209260005b8c8282106200063d575050841162000624575b505050811b018155620000b5565b015160001983861b60f8161c1916905538808062000616565b8385015186558c9790950194938401930162000603565b90915083600052886000208680850160051c8201928b8610620006a0575b918a91869594930160051c01915b828110620006905750506200008c565b600081558594508a910162000680565b9250819262000672565b634e487b7160e01b600052602260045260246000fd5b93607f169362000072565b600080fd5b601f909101601f19168101906001600160401b03821190821017620005cb57604052565b90816020910312620006cb57516001600160a01b0381168103620006cb5790565b60408051919082016001600160401b03811183821017620005cb5760405260078252665472754661726d60c81b602083015256fe6080604081815260049182361015610022575b505050361561002057600080fd5b005b600092833560e01c918263013cf08b146118205750816302a251a3146118015781630445b667146117e257816306fdde031461170f578163095ea7b3146116e55781630b102d1a146116a55781630d61b5191461152057816315373e3d146112c857816318160ddd146112a957816323b872dd146111df578163301d29db1461117c578163313ce5671461116057816339509351146111105781633af32abf146110d257816342966c6814610f8b5781634385963214610f4157816349c2a1a614610b87578163555f186014610a7d5781635bf8633a14610a545781635ef5332914610a3257816364b87a7014610a095781636ddd1713146109e257816370a08231146109ab578163715018a61461094e57816378c8cda71461090e57816385a21b19146108f15781638da5cb5b146108c85781639080936f14610849578163933baa861461080957816395d89b411461071e578163a0712d68146106e8578163a457c2d714610643578163a7d54d3f14610624578163a8aa1b31146105fb578163a8b21c1b146105dc578163a9059cbb146105ab578163aec9b6f414610582578163b034012314610559578163c26c12eb14610535578163cc274b2914610513578163d89135cd146104f4578163da1919b3146104c2578163da35c664146104a3578163dd62ed3e1461045a578163e1a452181461043d578163e2d74628146103fd578163eeca9a31146103ba578163f11f77f91461039b578163f2fde38b146102d057508063f80f5dd51461028e5763fb1db278146102635780610012565b3461028a578160031936011261028a5760095490516001600160a01b039091168152602090f35b5080fd5b503461028a57602036600319011261028a576102a8611a11565b6102b0611a42565b6001600160a01b03168252600d6020528120805460ff1916600117905580f35b905034610397576020366003190112610397576102eb611a11565b906102f4611a42565b6001600160a01b03918216928315610345575050600554826001600160601b0360a01b821617600555167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e08380a380f35b906020608492519162461bcd60e51b8352820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201526564647265737360d01b6064820152fd5b8280fd5b50503461028a578160031936011261028a576020906012549051908152f35b83346103fa5760203660031901126103fa576103d4611a11565b6103dc611a42565b60018060a01b03166001600160601b0360a01b600a541617600a5580f35b80fd5b83346103fa5760203660031901126103fa57610417611a11565b61041f611a42565b60018060a01b03166001600160601b0360a01b600b541617600b5580f35b50503461028a578160031936011261028a57602090516127108152f35b50503461028a578060031936011261028a5780602092610478611a11565b610480611a2c565b6001600160a01b0391821683526001865283832091168252845220549051908152f35b50503461028a578160031936011261028a576020906015549051908152f35b50503461028a578060031936011261028a576020906104eb6104e2611a11565b602435906121dd565b90519015158152f35b50503461028a578160031936011261028a57602090600e549051908152f35b83903461028a57602036600319011261028a5761052e611a42565b3560115580f35b50503461028a578160031936011261028a57602090610552612128565b9051908152f35b50503461028a578160031936011261028a57600b5490516001600160a01b039091168152602090f35b50503461028a578160031936011261028a5760105490516001600160a01b039091168152602090f35b50503461028a578060031936011261028a576020906105d56105cb611a11565b6024359033611bd2565b5160018152f35b50503461028a578160031936011261028a576020906008549051908152f35b50503461028a578160031936011261028a57600f5490516001600160a01b039091168152602090f35b50503461028a578160031936011261028a576020906007549051908152f35b905082346103fa57826003193601126103fa5761065e611a11565b918360243592338152600160205281812060018060a01b0386168252602052205490828210610697576020856105d58585038733611abd565b608490602086519162461bcd60e51b8352820152602560248201527f45524332303a2064656372656173656420616c6c6f77616e63652062656c6f77604482015264207a65726f60d81b6064820152fd5b8284346103fa5760203660031901126103fa57506104eb60209261071760018060a01b03600954163314612053565b35306121dd565b91905034610397578260031936011261039757805191838154906107418261194b565b808652926001928084169081156107de5750600114610782575b61077e868661076c828b03836119af565b519182916020835260208301906119d1565b0390f35b815294507f8a35acfbc15ff81a39ae7d344fd709f28e8600b4aa8c65c6b64bfe7fe36bd19b5b8286106107c65750505061076c82602061077e95820101943861075b565b805460208787018101919091529095019481016107a8565b905061077e97508693506020925061076c94915060ff191682840152151560051b820101943861075b565b83346103fa5760203660031901126103fa57610823611a11565b61082b611a42565b60018060a01b03166001600160601b0360a01b600954161760095580f35b9050346103975760203660031901126103975781836080949235815260146020522091600283015492600560038201549101544211908161089d575b82519485526020850152159083015215156060820152f35b92506108a98385611a9a565b6108b1612128565b1115806108bf575b92610885565b508284116108b9565b50503461028a578160031936011261028a5760055490516001600160a01b039091168152602090f35b50503461028a578160031936011261028a5760209061055261209f565b50503461028a57602036600319011261028a57610929611a11565b610931611a42565b6001600160a01b03168252600d6020528120805460ff1916905580f35b83346103fa57806003193601126103fa57610967611a42565b600580546001600160a01b0319811690915581906001600160a01b03167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e08280a380f35b50503461028a57602036600319011261028a5760209181906001600160a01b036109d3611a11565b16815280845220549051908152f35b50503461028a578160031936011261028a5760209060ff60105460a01c1690519015158152f35b50503461028a578160031936011261028a57600a5490516001600160a01b039091168152602090f35b83903461028a57602036600319011261028a57610a4d611a42565b3560125580f35b50503461028a578160031936011261028a57600c5490516001600160a01b039091168152602090f35b9050346103975760603660031901126103975780359160243560443592610aa2611a42565b612710808311610b3a578411610af757509183916060937f2f887d9c32f7cc3cbf806949310a3afdd85b147705550dde55deb4af1ab582f995600655806007558260085581519384526020840152820152a180f35b606490602084519162461bcd60e51b8352820152601e60248201527f71756f72756d2042505320657863656564732064656e6f6d696e61746f7200006044820152fd5b835162461bcd60e51b8152602081840152602160248201527f7468726573686f6c642042505320657863656564732064656e6f6d696e61746f6044820152603960f91b6064820152608490fd5b9190503461039757602092836003193601126103fa5767ffffffffffffffff9280358481116103975736602382011215610397578082013594808611610f2e57845195601f1990610bdf601f820183168a01896119af565b80885260249336858383010111610f2a57818792868c9301838c013789010152600b5486516370a0823160e01b8082523387830152916001600160a01b0391908b9082908890829086165afa908115610f20578891610eef575b50610c4261209f565b11610ead578990600c541691858951809481938252338a8301525afa8015610ea3578690610e70575b610c77915015156121a1565b60155460001991828214610e5e576001809201968760155587815260148b52888120978855828801958a51958611610e4d5750610cb4865461194b565b601f8111610e07575b508a91601f8611600114610d815750928480937f6c98a8c940418b35614f0cd02412d5c9606faff474cbb6cdd6640ba5d1a9f06b9b98969360059a989694610d76575b501b9260031b1c19161790555b60068281018054610100600160a81b0319163360081b610100600160a81b03161790554291830182905554610d4191611a9a565b9283910155601554938491610d608551916060835260608301906119d1565b934288830152858201528033940390a351908152f35b890151935038610d00565b859492919395168684528b8420935b8c828210610df3575050917f6c98a8c940418b35614f0cd02412d5c9606faff474cbb6cdd6640ba5d1a9f06b9a979593918560059a98969410610ddb575b505050811b019055610d0d565b8801519060f88460031b161c19169055388080610dce565b8c8401518655948701949283019201610d90565b8682528b8220601f870160051c8101918d8810610e43575b601f0160051c019084905b828110610e38575050610cbd565b838155018490610e2a565b9091508190610e1f565b634e487b7160e01b82526041885290fd5b634e487b7160e01b8752601186528487fd5b508881813d8311610e9c575b610e8681836119af565b81010312610e9857610c779051610c6b565b8580fd5b503d610e7c565b87513d88823e3d90fd5b875162461bcd60e51b81528087018b9052601e818701527f70726f706f73657220766f7465732062656c6f77207468726573686f6c6400006044820152606490fd5b90508a81813d8311610f19575b610f0681836119af565b81010312610f15575138610c39565b8780fd5b503d610efc565b89513d8a823e3d90fd5b8680fd5b634e487b7160e01b845260418352602484fd5b9050346103975781600319360112610397578160209360ff92610f62611a2c565b90358252601486528282206001600160a01b039091168252600701855220549151911615158152f35b8391503461028a576020908160031936011261039757803590610fb082600e54611a9a565b600e553315611085573384528383528484205490828210611037575093817fd83c63197e8e676d80ab0122beba9a9d20f3828839e9a1d6fe81d242e9cd7e6e9495338752868552038186205581600254036002558481518381527fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef853392a351908152a180f35b855162461bcd60e51b8152908101849052602260248201527f45524332303a206275726e20616d6f756e7420657863656564732062616c616e604482015261636560f01b6064820152608490fd5b845162461bcd60e51b8152908101839052602160248201527f45524332303a206275726e2066726f6d20746865207a65726f206164647265736044820152607360f81b6064820152608490fd5b50503461028a57602036600319011261028a5760209160ff9082906001600160a01b036110fd611a11565b168152600d855220541690519015158152f35b50503461028a578060031936011261028a576105d5602092611159611133611a11565b338352600186528483206001600160a01b03821684528652918490205460243590611a9a565b9033611abd565b50503461028a578160031936011261028a576020905160128152f35b50503461028a578060031936011261028a57611196611a11565b90602435906111b060018060a01b03600954163314612053565b30845283602052832054908181116000146111d357506111d09130611bd2565b80f35b90506111d09130611bd2565b8391503461028a57606036600319011261028a576111fb611a11565b611203611a2c565b91846044359460018060a01b03841681526001602052818120338252602052205490600019820361123d575b6020866105d5878787611bd2565b848210611266575091839161125b602096956105d595033383611abd565b91939481935061122f565b606490602087519162461bcd60e51b8352820152601d60248201527f45524332303a20696e73756666696369656e7420616c6c6f77616e63650000006044820152fd5b50503461028a578160031936011261028a576020906002549051908152f35b83833461028a578060031936011261028a5782359060249081359182151592838103610e98578486526020906014825283872090600582015442116114eb57600782019833895289845260ff868a2054166114b957600c5486516370a0823160e01b808252338483015296916001600160a01b039190879082908590829086165afa9081156114af57908792918d91611478575b506113689015156121a1565b600b54169682895180998193825233878301525afa95861561146e578a9661143b575b5085156114075750507f877856338e13f63d0c36822ff0ef736b80934cd90574a3a5bc9262c39d217c4695969798338a528352848920600160ff198254161790556000146113f2576002016113e1838254611a9a565b90555b82519485528401523392a380f35b600301611400838254611a9a565b90556113e4565b865162461bcd60e51b8152918201859052600f908201526e3737903b37ba34b733903837bbb2b960891b6044820152606490fd5b9095508481813d8311611467575b61145381836119af565b810103126114635751948b61138b565b8980fd5b503d611449565b87513d8c823e3d90fd5b8381939492503d83116114a8575b61149081836119af565b810103126114a4575186919061136861135c565b8b80fd5b503d611486565b89513d8e823e3d90fd5b855162461bcd60e51b8152908101849052600d818601526c185b1c9958591e481d9bdd1959609a1b6044820152606490fd5b845162461bcd60e51b8152808a018490526010818601526f1d9bdd1a5b99c81a5cc818db1bdcd95960821b6044820152606490fd5b91905034610397576020806003193601126116a1578235928385526014825282852091600583015442111561166957600683019384549360ff85166116275760036002820154910154906115748282611a9a565b61157c612128565b116115ef5711156115ba5750505060ff191660011790557f712ae1383f79ac853f8d882153778e0260ef8f03b504e2866e0593e04d2b291f8280a280f35b5162461bcd60e51b81529182015260116024820152701c1c9bdc1bdcd85b0819195999585d1959607a1b604482015260649150fd5b50505162461bcd60e51b81529182015260126024820152711c5d5bdc9d5b481b9bdd081c995858da195960721b604482015260649150fd5b505162461bcd60e51b815291820152601960248201527f70726f706f73616c20616c726561647920657865637574656400000000000000604482015260649150fd5b835162461bcd60e51b8152918201526013602482015272766f74696e67207374696c6c2061637469766560681b604482015260649150fd5b8380fd5b83346103fa5760203660031901126103fa576116bf611a11565b6116c7611a42565b60018060a01b03166001600160601b0360a01b600c541617600c5580f35b50503461028a578060031936011261028a576020906105d5611705611a11565b6024359033611abd565b50503461028a578160031936011261028a57805190826003546117318161194b565b808552916001918083169081156117ba575060011461175d575b50505061076c8261077e9403836119af565b9450600385527fc2575a0e9e593c00f959f8c92f12db2869c3395a3b0502d05e2516446f71f85b5b8286106117a25750505061076c82602061077e958201019461174b565b80546020878701810191909152909501948101611785565b61077e97508693506020925061076c94915060ff191682840152151560051b8201019461174b565b50503461028a578160031936011261028a576020906011549051908152f35b50503461028a578160031936011261028a576020906006549051908152f35b8385913461039757602093846003193601126116a15780358452601485528284209085838354966001808601908282549261185a8461194b565b8087529383811690811561192657506001146118e9575b50505050611881925003846119af565b600282015490600383015490830154916118b660066005860154950154958751998a998a5261010080918b01528901906119d1565b958701526060860152608085015260a084015260ff8116151560c084015260081c6001600160a01b031660e08301520390f35b815285812095935091905b81831061190e57508a9450508201016118818a8080611871565b855489840185015294850194889450918301916118f4565b935050505061188194925060ff191682840152151560051b82010188928a8080611871565b90600182811c9216801561197b575b602083101461196557565b634e487b7160e01b600052602260045260246000fd5b91607f169161195a565b67ffffffffffffffff811161199957604052565b634e487b7160e01b600052604160045260246000fd5b90601f8019910116810190811067ffffffffffffffff82111761199957604052565b919082519283825260005b8481106119fd575050826000602080949584010152601f8019910116010190565b6020818301810151848301820152016119dc565b600435906001600160a01b0382168203611a2757565b600080fd5b602435906001600160a01b0382168203611a2757565b6005546001600160a01b03163303611a5657565b606460405162461bcd60e51b815260206004820152602060248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e65726044820152fd5b91908201809211611aa757565b634e487b7160e01b600052601160045260246000fd5b6001600160a01b03908116918215611b6e5716918215611b1e5760207f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925918360005260018252604060002085600052825280604060002055604051908152a3565b60405162461bcd60e51b815260206004820152602260248201527f45524332303a20617070726f766520746f20746865207a65726f206164647265604482015261737360f01b6064820152608490fd5b60405162461bcd60e51b8152602060048201526024808201527f45524332303a20617070726f76652066726f6d20746865207a65726f206164646044820152637265737360e01b6064820152608490fd5b81810292918115918404141715611aa757565b92919060009360018060a01b0380831686526020600d815260409160ff83892054168015611ed3575b15611c1057505050611c0e939450611ee5565b565b60139260ff845416611ec45781600f541633141580611eb8575b80611ea9575b80611e94575b611c83575b50505050612710611c4e60165485611bbf565b0494858403938411611c6f5750611c6a611c0e94953083611ee5565b611ee5565b634e487b7160e01b81526011600452602490fd5b60ff199260018486541617855581516060810181811067ffffffffffffffff821117611e80578352600281528181019083368337805115611e6c573082528460105416928c855163ef8ef56f60e01b81528281600481895afa918215611e615791611e27575b50825160011015611e135790868e95949392168683015260115491843b15610e9857865163791ac94760e01b815260048101939093526024830186905260a060448401525160a483018190529194938593909260c4850192865b828110611def57505050508383809230606483015242608483015203925af18015611de557611dd0575b509088914791601254831015611d90575b50505050815416905538808080611c3b565b600a5416803b156116a157600484925180948193636e14f8ef60e11b83525af1611dbc575b8080611d7e565b611dc590611985565b610f2a578638611db5565b611ddd9099919299611985565b979038611d6d565b82513d8c823e3d90fd5b9295506001919496508080948b88511681520195019101928f959392879593611d43565b634e487b7160e01b8e52603260045260248efd5b90508181813d8311611e5a575b611e3e81836119af565b81010312611e5657518681168103611e565738611ce9565b8d80fd5b503d611e34565b8751903d90823e3d90fd5b634e487b7160e01b8c52603260045260248cfd5b634e487b7160e01b8c52604160045260248cfd5b50308952888352808920546011541115611c36565b5060ff60105460a01c16611c30565b5060ff84541615611c2a565b50505050611c0e939450611ee5565b50808416885260ff8389205416611bfb565b6001600160a01b039081169182156120005716918215611faf57600082815280602052604081205491808310611f5b57604082827fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef958760209652828652038282205586815220818154019055604051908152a3565b60405162461bcd60e51b815260206004820152602660248201527f45524332303a207472616e7366657220616d6f756e7420657863656564732062604482015265616c616e636560d01b6064820152608490fd5b60405162461bcd60e51b815260206004820152602360248201527f45524332303a207472616e7366657220746f20746865207a65726f206164647260448201526265737360e81b6064820152608490fd5b60405162461bcd60e51b815260206004820152602560248201527f45524332303a207472616e736665722066726f6d20746865207a65726f206164604482015264647265737360d81b6064820152608490fd5b1561205a57565b60405162461bcd60e51b815260206004820152601c60248201527f43616c6c6572206973206e6f7420746865204d617374657263686566000000006044820152606490fd5b600b546040516318160ddd60e01b815290602090829060049082906001600160a01b03165afa90811561211c576000916120e9575b506120e56127109160075490611bbf565b0490565b906020823d8211612114575b81612102602093836119af565b810103126103fa5750516120e56120d4565b3d91506120f5565b6040513d6000823e3d90fd5b600b546040516318160ddd60e01b815290602090829060049082906001600160a01b03165afa90811561211c5760009161216e575b506120e56127109160085490611bbf565b906020823d8211612199575b81612187602093836119af565b810103126103fa5750516120e561215d565b3d915061217a565b156121a857565b60405162461bcd60e51b815260206004820152600d60248201526c1b5d5cdd081a1bdb19081b999d609a1b6044820152606490fd5b6009546001600160a01b0391906121f79083163314612053565b16908115612250577fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef602082612231600094600254611a9a565b60025584845283825260408420818154019055604051908152a3600190565b60405162461bcd60e51b815260206004820152601f60248201527f45524332303a206d696e7420746f20746865207a65726f2061646472657373006044820152606490fdfea2646970667358221220e2dd1e67a631419e0af5688eafb27b312470bc58c979e6d5aa8089b8d5dc83eb64736f6c634300081400330000000000000000000000003c4ec5a8d291609b757f22459baa99465306c76a
Deployed ByteCode
0x6080604081815260049182361015610022575b505050361561002057600080fd5b005b600092833560e01c918263013cf08b146118205750816302a251a3146118015781630445b667146117e257816306fdde031461170f578163095ea7b3146116e55781630b102d1a146116a55781630d61b5191461152057816315373e3d146112c857816318160ddd146112a957816323b872dd146111df578163301d29db1461117c578163313ce5671461116057816339509351146111105781633af32abf146110d257816342966c6814610f8b5781634385963214610f4157816349c2a1a614610b87578163555f186014610a7d5781635bf8633a14610a545781635ef5332914610a3257816364b87a7014610a095781636ddd1713146109e257816370a08231146109ab578163715018a61461094e57816378c8cda71461090e57816385a21b19146108f15781638da5cb5b146108c85781639080936f14610849578163933baa861461080957816395d89b411461071e578163a0712d68146106e8578163a457c2d714610643578163a7d54d3f14610624578163a8aa1b31146105fb578163a8b21c1b146105dc578163a9059cbb146105ab578163aec9b6f414610582578163b034012314610559578163c26c12eb14610535578163cc274b2914610513578163d89135cd146104f4578163da1919b3146104c2578163da35c664146104a3578163dd62ed3e1461045a578163e1a452181461043d578163e2d74628146103fd578163eeca9a31146103ba578163f11f77f91461039b578163f2fde38b146102d057508063f80f5dd51461028e5763fb1db278146102635780610012565b3461028a578160031936011261028a5760095490516001600160a01b039091168152602090f35b5080fd5b503461028a57602036600319011261028a576102a8611a11565b6102b0611a42565b6001600160a01b03168252600d6020528120805460ff1916600117905580f35b905034610397576020366003190112610397576102eb611a11565b906102f4611a42565b6001600160a01b03918216928315610345575050600554826001600160601b0360a01b821617600555167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e08380a380f35b906020608492519162461bcd60e51b8352820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201526564647265737360d01b6064820152fd5b8280fd5b50503461028a578160031936011261028a576020906012549051908152f35b83346103fa5760203660031901126103fa576103d4611a11565b6103dc611a42565b60018060a01b03166001600160601b0360a01b600a541617600a5580f35b80fd5b83346103fa5760203660031901126103fa57610417611a11565b61041f611a42565b60018060a01b03166001600160601b0360a01b600b541617600b5580f35b50503461028a578160031936011261028a57602090516127108152f35b50503461028a578060031936011261028a5780602092610478611a11565b610480611a2c565b6001600160a01b0391821683526001865283832091168252845220549051908152f35b50503461028a578160031936011261028a576020906015549051908152f35b50503461028a578060031936011261028a576020906104eb6104e2611a11565b602435906121dd565b90519015158152f35b50503461028a578160031936011261028a57602090600e549051908152f35b83903461028a57602036600319011261028a5761052e611a42565b3560115580f35b50503461028a578160031936011261028a57602090610552612128565b9051908152f35b50503461028a578160031936011261028a57600b5490516001600160a01b039091168152602090f35b50503461028a578160031936011261028a5760105490516001600160a01b039091168152602090f35b50503461028a578060031936011261028a576020906105d56105cb611a11565b6024359033611bd2565b5160018152f35b50503461028a578160031936011261028a576020906008549051908152f35b50503461028a578160031936011261028a57600f5490516001600160a01b039091168152602090f35b50503461028a578160031936011261028a576020906007549051908152f35b905082346103fa57826003193601126103fa5761065e611a11565b918360243592338152600160205281812060018060a01b0386168252602052205490828210610697576020856105d58585038733611abd565b608490602086519162461bcd60e51b8352820152602560248201527f45524332303a2064656372656173656420616c6c6f77616e63652062656c6f77604482015264207a65726f60d81b6064820152fd5b8284346103fa5760203660031901126103fa57506104eb60209261071760018060a01b03600954163314612053565b35306121dd565b91905034610397578260031936011261039757805191838154906107418261194b565b808652926001928084169081156107de5750600114610782575b61077e868661076c828b03836119af565b519182916020835260208301906119d1565b0390f35b815294507f8a35acfbc15ff81a39ae7d344fd709f28e8600b4aa8c65c6b64bfe7fe36bd19b5b8286106107c65750505061076c82602061077e95820101943861075b565b805460208787018101919091529095019481016107a8565b905061077e97508693506020925061076c94915060ff191682840152151560051b820101943861075b565b83346103fa5760203660031901126103fa57610823611a11565b61082b611a42565b60018060a01b03166001600160601b0360a01b600954161760095580f35b9050346103975760203660031901126103975781836080949235815260146020522091600283015492600560038201549101544211908161089d575b82519485526020850152159083015215156060820152f35b92506108a98385611a9a565b6108b1612128565b1115806108bf575b92610885565b508284116108b9565b50503461028a578160031936011261028a5760055490516001600160a01b039091168152602090f35b50503461028a578160031936011261028a5760209061055261209f565b50503461028a57602036600319011261028a57610929611a11565b610931611a42565b6001600160a01b03168252600d6020528120805460ff1916905580f35b83346103fa57806003193601126103fa57610967611a42565b600580546001600160a01b0319811690915581906001600160a01b03167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e08280a380f35b50503461028a57602036600319011261028a5760209181906001600160a01b036109d3611a11565b16815280845220549051908152f35b50503461028a578160031936011261028a5760209060ff60105460a01c1690519015158152f35b50503461028a578160031936011261028a57600a5490516001600160a01b039091168152602090f35b83903461028a57602036600319011261028a57610a4d611a42565b3560125580f35b50503461028a578160031936011261028a57600c5490516001600160a01b039091168152602090f35b9050346103975760603660031901126103975780359160243560443592610aa2611a42565b612710808311610b3a578411610af757509183916060937f2f887d9c32f7cc3cbf806949310a3afdd85b147705550dde55deb4af1ab582f995600655806007558260085581519384526020840152820152a180f35b606490602084519162461bcd60e51b8352820152601e60248201527f71756f72756d2042505320657863656564732064656e6f6d696e61746f7200006044820152fd5b835162461bcd60e51b8152602081840152602160248201527f7468726573686f6c642042505320657863656564732064656e6f6d696e61746f6044820152603960f91b6064820152608490fd5b9190503461039757602092836003193601126103fa5767ffffffffffffffff9280358481116103975736602382011215610397578082013594808611610f2e57845195601f1990610bdf601f820183168a01896119af565b80885260249336858383010111610f2a57818792868c9301838c013789010152600b5486516370a0823160e01b8082523387830152916001600160a01b0391908b9082908890829086165afa908115610f20578891610eef575b50610c4261209f565b11610ead578990600c541691858951809481938252338a8301525afa8015610ea3578690610e70575b610c77915015156121a1565b60155460001991828214610e5e576001809201968760155587815260148b52888120978855828801958a51958611610e4d5750610cb4865461194b565b601f8111610e07575b508a91601f8611600114610d815750928480937f6c98a8c940418b35614f0cd02412d5c9606faff474cbb6cdd6640ba5d1a9f06b9b98969360059a989694610d76575b501b9260031b1c19161790555b60068281018054610100600160a81b0319163360081b610100600160a81b03161790554291830182905554610d4191611a9a565b9283910155601554938491610d608551916060835260608301906119d1565b934288830152858201528033940390a351908152f35b890151935038610d00565b859492919395168684528b8420935b8c828210610df3575050917f6c98a8c940418b35614f0cd02412d5c9606faff474cbb6cdd6640ba5d1a9f06b9a979593918560059a98969410610ddb575b505050811b019055610d0d565b8801519060f88460031b161c19169055388080610dce565b8c8401518655948701949283019201610d90565b8682528b8220601f870160051c8101918d8810610e43575b601f0160051c019084905b828110610e38575050610cbd565b838155018490610e2a565b9091508190610e1f565b634e487b7160e01b82526041885290fd5b634e487b7160e01b8752601186528487fd5b508881813d8311610e9c575b610e8681836119af565b81010312610e9857610c779051610c6b565b8580fd5b503d610e7c565b87513d88823e3d90fd5b875162461bcd60e51b81528087018b9052601e818701527f70726f706f73657220766f7465732062656c6f77207468726573686f6c6400006044820152606490fd5b90508a81813d8311610f19575b610f0681836119af565b81010312610f15575138610c39565b8780fd5b503d610efc565b89513d8a823e3d90fd5b8680fd5b634e487b7160e01b845260418352602484fd5b9050346103975781600319360112610397578160209360ff92610f62611a2c565b90358252601486528282206001600160a01b039091168252600701855220549151911615158152f35b8391503461028a576020908160031936011261039757803590610fb082600e54611a9a565b600e553315611085573384528383528484205490828210611037575093817fd83c63197e8e676d80ab0122beba9a9d20f3828839e9a1d6fe81d242e9cd7e6e9495338752868552038186205581600254036002558481518381527fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef853392a351908152a180f35b855162461bcd60e51b8152908101849052602260248201527f45524332303a206275726e20616d6f756e7420657863656564732062616c616e604482015261636560f01b6064820152608490fd5b845162461bcd60e51b8152908101839052602160248201527f45524332303a206275726e2066726f6d20746865207a65726f206164647265736044820152607360f81b6064820152608490fd5b50503461028a57602036600319011261028a5760209160ff9082906001600160a01b036110fd611a11565b168152600d855220541690519015158152f35b50503461028a578060031936011261028a576105d5602092611159611133611a11565b338352600186528483206001600160a01b03821684528652918490205460243590611a9a565b9033611abd565b50503461028a578160031936011261028a576020905160128152f35b50503461028a578060031936011261028a57611196611a11565b90602435906111b060018060a01b03600954163314612053565b30845283602052832054908181116000146111d357506111d09130611bd2565b80f35b90506111d09130611bd2565b8391503461028a57606036600319011261028a576111fb611a11565b611203611a2c565b91846044359460018060a01b03841681526001602052818120338252602052205490600019820361123d575b6020866105d5878787611bd2565b848210611266575091839161125b602096956105d595033383611abd565b91939481935061122f565b606490602087519162461bcd60e51b8352820152601d60248201527f45524332303a20696e73756666696369656e7420616c6c6f77616e63650000006044820152fd5b50503461028a578160031936011261028a576020906002549051908152f35b83833461028a578060031936011261028a5782359060249081359182151592838103610e98578486526020906014825283872090600582015442116114eb57600782019833895289845260ff868a2054166114b957600c5486516370a0823160e01b808252338483015296916001600160a01b039190879082908590829086165afa9081156114af57908792918d91611478575b506113689015156121a1565b600b54169682895180998193825233878301525afa95861561146e578a9661143b575b5085156114075750507f877856338e13f63d0c36822ff0ef736b80934cd90574a3a5bc9262c39d217c4695969798338a528352848920600160ff198254161790556000146113f2576002016113e1838254611a9a565b90555b82519485528401523392a380f35b600301611400838254611a9a565b90556113e4565b865162461bcd60e51b8152918201859052600f908201526e3737903b37ba34b733903837bbb2b960891b6044820152606490fd5b9095508481813d8311611467575b61145381836119af565b810103126114635751948b61138b565b8980fd5b503d611449565b87513d8c823e3d90fd5b8381939492503d83116114a8575b61149081836119af565b810103126114a4575186919061136861135c565b8b80fd5b503d611486565b89513d8e823e3d90fd5b855162461bcd60e51b8152908101849052600d818601526c185b1c9958591e481d9bdd1959609a1b6044820152606490fd5b845162461bcd60e51b8152808a018490526010818601526f1d9bdd1a5b99c81a5cc818db1bdcd95960821b6044820152606490fd5b91905034610397576020806003193601126116a1578235928385526014825282852091600583015442111561166957600683019384549360ff85166116275760036002820154910154906115748282611a9a565b61157c612128565b116115ef5711156115ba5750505060ff191660011790557f712ae1383f79ac853f8d882153778e0260ef8f03b504e2866e0593e04d2b291f8280a280f35b5162461bcd60e51b81529182015260116024820152701c1c9bdc1bdcd85b0819195999585d1959607a1b604482015260649150fd5b50505162461bcd60e51b81529182015260126024820152711c5d5bdc9d5b481b9bdd081c995858da195960721b604482015260649150fd5b505162461bcd60e51b815291820152601960248201527f70726f706f73616c20616c726561647920657865637574656400000000000000604482015260649150fd5b835162461bcd60e51b8152918201526013602482015272766f74696e67207374696c6c2061637469766560681b604482015260649150fd5b8380fd5b83346103fa5760203660031901126103fa576116bf611a11565b6116c7611a42565b60018060a01b03166001600160601b0360a01b600c541617600c5580f35b50503461028a578060031936011261028a576020906105d5611705611a11565b6024359033611abd565b50503461028a578160031936011261028a57805190826003546117318161194b565b808552916001918083169081156117ba575060011461175d575b50505061076c8261077e9403836119af565b9450600385527fc2575a0e9e593c00f959f8c92f12db2869c3395a3b0502d05e2516446f71f85b5b8286106117a25750505061076c82602061077e958201019461174b565b80546020878701810191909152909501948101611785565b61077e97508693506020925061076c94915060ff191682840152151560051b8201019461174b565b50503461028a578160031936011261028a576020906011549051908152f35b50503461028a578160031936011261028a576020906006549051908152f35b8385913461039757602093846003193601126116a15780358452601485528284209085838354966001808601908282549261185a8461194b565b8087529383811690811561192657506001146118e9575b50505050611881925003846119af565b600282015490600383015490830154916118b660066005860154950154958751998a998a5261010080918b01528901906119d1565b958701526060860152608085015260a084015260ff8116151560c084015260081c6001600160a01b031660e08301520390f35b815285812095935091905b81831061190e57508a9450508201016118818a8080611871565b855489840185015294850194889450918301916118f4565b935050505061188194925060ff191682840152151560051b82010188928a8080611871565b90600182811c9216801561197b575b602083101461196557565b634e487b7160e01b600052602260045260246000fd5b91607f169161195a565b67ffffffffffffffff811161199957604052565b634e487b7160e01b600052604160045260246000fd5b90601f8019910116810190811067ffffffffffffffff82111761199957604052565b919082519283825260005b8481106119fd575050826000602080949584010152601f8019910116010190565b6020818301810151848301820152016119dc565b600435906001600160a01b0382168203611a2757565b600080fd5b602435906001600160a01b0382168203611a2757565b6005546001600160a01b03163303611a5657565b606460405162461bcd60e51b815260206004820152602060248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e65726044820152fd5b91908201809211611aa757565b634e487b7160e01b600052601160045260246000fd5b6001600160a01b03908116918215611b6e5716918215611b1e5760207f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925918360005260018252604060002085600052825280604060002055604051908152a3565b60405162461bcd60e51b815260206004820152602260248201527f45524332303a20617070726f766520746f20746865207a65726f206164647265604482015261737360f01b6064820152608490fd5b60405162461bcd60e51b8152602060048201526024808201527f45524332303a20617070726f76652066726f6d20746865207a65726f206164646044820152637265737360e01b6064820152608490fd5b81810292918115918404141715611aa757565b92919060009360018060a01b0380831686526020600d815260409160ff83892054168015611ed3575b15611c1057505050611c0e939450611ee5565b565b60139260ff845416611ec45781600f541633141580611eb8575b80611ea9575b80611e94575b611c83575b50505050612710611c4e60165485611bbf565b0494858403938411611c6f5750611c6a611c0e94953083611ee5565b611ee5565b634e487b7160e01b81526011600452602490fd5b60ff199260018486541617855581516060810181811067ffffffffffffffff821117611e80578352600281528181019083368337805115611e6c573082528460105416928c855163ef8ef56f60e01b81528281600481895afa918215611e615791611e27575b50825160011015611e135790868e95949392168683015260115491843b15610e9857865163791ac94760e01b815260048101939093526024830186905260a060448401525160a483018190529194938593909260c4850192865b828110611def57505050508383809230606483015242608483015203925af18015611de557611dd0575b509088914791601254831015611d90575b50505050815416905538808080611c3b565b600a5416803b156116a157600484925180948193636e14f8ef60e11b83525af1611dbc575b8080611d7e565b611dc590611985565b610f2a578638611db5565b611ddd9099919299611985565b979038611d6d565b82513d8c823e3d90fd5b9295506001919496508080948b88511681520195019101928f959392879593611d43565b634e487b7160e01b8e52603260045260248efd5b90508181813d8311611e5a575b611e3e81836119af565b81010312611e5657518681168103611e565738611ce9565b8d80fd5b503d611e34565b8751903d90823e3d90fd5b634e487b7160e01b8c52603260045260248cfd5b634e487b7160e01b8c52604160045260248cfd5b50308952888352808920546011541115611c36565b5060ff60105460a01c16611c30565b5060ff84541615611c2a565b50505050611c0e939450611ee5565b50808416885260ff8389205416611bfb565b6001600160a01b039081169182156120005716918215611faf57600082815280602052604081205491808310611f5b57604082827fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef958760209652828652038282205586815220818154019055604051908152a3565b60405162461bcd60e51b815260206004820152602660248201527f45524332303a207472616e7366657220616d6f756e7420657863656564732062604482015265616c616e636560d01b6064820152608490fd5b60405162461bcd60e51b815260206004820152602360248201527f45524332303a207472616e7366657220746f20746865207a65726f206164647260448201526265737360e81b6064820152608490fd5b60405162461bcd60e51b815260206004820152602560248201527f45524332303a207472616e736665722066726f6d20746865207a65726f206164604482015264647265737360d81b6064820152608490fd5b1561205a57565b60405162461bcd60e51b815260206004820152601c60248201527f43616c6c6572206973206e6f7420746865204d617374657263686566000000006044820152606490fd5b600b546040516318160ddd60e01b815290602090829060049082906001600160a01b03165afa90811561211c576000916120e9575b506120e56127109160075490611bbf565b0490565b906020823d8211612114575b81612102602093836119af565b810103126103fa5750516120e56120d4565b3d91506120f5565b6040513d6000823e3d90fd5b600b546040516318160ddd60e01b815290602090829060049082906001600160a01b03165afa90811561211c5760009161216e575b506120e56127109160085490611bbf565b906020823d8211612199575b81612187602093836119af565b810103126103fa5750516120e561215d565b3d915061217a565b156121a857565b60405162461bcd60e51b815260206004820152600d60248201526c1b5d5cdd081a1bdb19081b999d609a1b6044820152606490fd5b6009546001600160a01b0391906121f79083163314612053565b16908115612250577fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef602082612231600094600254611a9a565b60025584845283825260408420818154019055604051908152a3600190565b60405162461bcd60e51b815260206004820152601f60248201527f45524332303a206d696e7420746f20746865207a65726f2061646472657373006044820152606490fdfea2646970667358221220e2dd1e67a631419e0af5688eafb27b312470bc58c979e6d5aa8089b8d5dc83eb64736f6c63430008140033